From 2a4c2fd192b3284a7424272c6b9573205ed4f396 Mon Sep 17 00:00:00 2001 From: Geovane Fedrecheski Date: Wed, 8 Jan 2025 16:36:55 +0100 Subject: [PATCH] tsch: refactor and simplify, move asn to tsch --- drv/scheduler.h | 3 +- drv/scheduler/scheduler.c | 11 +- drv/tsch.h | 6 +- drv/tsch/tsch.c | 177 ++++++++----------- projects/01bsp_radio_txrx/01bsp_radio_txrx.c | 75 +++++--- projects/01drv_scheduler/01drv_scheduler.c | 9 +- projects/01drv_tsch/01drv_tsch.c | 2 +- 7 files changed, 142 insertions(+), 141 deletions(-) diff --git a/drv/scheduler.h b/drv/scheduler.h index aa8a9bb4..396c0391 100644 --- a/drv/scheduler.h +++ b/drv/scheduler.h @@ -75,7 +75,8 @@ void db_scheduler_init(node_type_t node_type, schedule_t *application_schedule); * * @return A configuration for the TSCH radio driver to follow in the next slot. */ -tsch_radio_event_t db_scheduler_tick(void); +// tsch_radio_event_t db_scheduler_tick(void); +tsch_radio_event_t db_scheduler_tick(uint64_t asn); /** * @brief Activates a given schedule. diff --git a/drv/scheduler/scheduler.c b/drv/scheduler/scheduler.c index 842d94ad..f944e1cb 100644 --- a/drv/scheduler/scheduler.c +++ b/drv/scheduler/scheduler.c @@ -113,16 +113,16 @@ bool db_scheduler_deassign_uplink_cell(uint64_t node_id) { return false; } -tsch_radio_event_t db_scheduler_tick(void) { +tsch_radio_event_t db_scheduler_tick(uint64_t asn) { schedule_t active_schedule = *_schedule_vars.active_schedule_ptr; // get the current cell - size_t cell_index = _schedule_vars.asn % active_schedule.n_cells; + size_t cell_index = asn % active_schedule.n_cells; cell_t cell = active_schedule.cells[cell_index]; tsch_radio_event_t radio_event = { .radio_action = TSCH_RADIO_ACTION_SLEEP, - .frequency = db_scheduler_get_frequency(cell.type, _schedule_vars.asn, cell.channel_offset), + .frequency = db_scheduler_get_frequency(cell.type, asn, cell.channel_offset), .slot_type = cell.type, // FIXME: only for debugging, remove before merge }; if (_schedule_vars.node_type == NODE_TYPE_GATEWAY) { @@ -132,13 +132,10 @@ tsch_radio_event_t db_scheduler_tick(void) { } // if the slotframe wrapped, keep track of how many slotframes have passed (used to cycle beacon frequencies) - if (_schedule_vars.asn != 0 && cell_index == 0) { + if (asn != 0 && cell_index == 0) { _schedule_vars.slotframe_counter++; } - // increment ASN so that (1) nodes are in sync and (2) next time we get the next cell - _schedule_vars.asn++; - return radio_event; } diff --git a/drv/tsch.h b/drv/tsch.h index ad3bef2f..cd1646bc 100644 --- a/drv/tsch.h +++ b/drv/tsch.h @@ -22,8 +22,9 @@ //=========================== defines ========================================== #define TSCH_TIMER_DEV 2 ///< HF timer device used for the TSCH scheduler -#define TSCH_TIMER_SLOT_CHANNEL 0 -#define TSCH_TIMER_INTRA_SLOT_CHANNEL 1 +#define TSCH_TIMER_INTER_SLOT_CHANNEL 0 ///< Channel for ticking the whole slot +#define TSCH_TIMER_INTRA_SLOT_CHANNEL 1 ///< Channel for ticking intra-slot sections, such as tx offset and tx max +#define TSCH_TIMER_DESYNC_WINDOW_CHANNEL 2 ///< Channel for ticking the desynchronization window // Bytes per millisecond in BLE 2M mode #define BLE_2M (1000 * 1000 * 2) // 2 Mbps @@ -31,6 +32,7 @@ #define BLE_2M_US_PER_BYTE (1000 / BLE_2M_B_MS) // 4 us #define _TSCH_START_GUARD_TIME (200) +#define _TSCH_END_GUARD_TIME (100) #define _TSCH_PACKET_TOA (BLE_2M_US_PER_BYTE * DB_BLE_PAYLOAD_MAX_LENGTH) // Time on air for the maximum payload. #define _TSCH_PACKET_TOA_WITH_PADDING (_TSCH_PACKET_TOA + (BLE_2M_US_PER_BYTE * 32)) // Add some padding just in case. diff --git a/drv/tsch/tsch.c b/drv/tsch/tsch.c index ca8145b1..40844c07 100644 --- a/drv/tsch/tsch.c +++ b/drv/tsch/tsch.c @@ -39,6 +39,7 @@ gpio_t pin3 = { .port = 1, .pin = 5 }; #ifdef DEBUG #define DEBUG_GPIO_TOGGLE(pin) db_gpio_toggle(pin) #define DEBUG_GPIO_SET(pin) db_gpio_set(pin) + #define DEBUG_GPIO_CLEAR(pin) db_gpio_clear(pin) #else // No-op when DEBUG is not defined #define DEBUG_GPIO_TOGGLE(pin) ((void)0)) @@ -54,11 +55,11 @@ tsch_slot_timing_t tsch_default_slot_timing = { .rx_max = _TSCH_START_GUARD_TIME + _TSCH_PACKET_TOA_WITH_PADDING, // Guard time + Enough time to receive the maximum payload. .tx_offset = 40 + 300 + _TSCH_START_GUARD_TIME, // Same as rx_offset, plus the guard time. .tx_max = _TSCH_PACKET_TOA_WITH_PADDING, // Enough to transmit the maximum payload. - .end_guard = 100, // Extra time at the end of the slot + .end_guard = _TSCH_END_GUARD_TIME, // Extra time at the end of the slot // receive slot is: rx_offset / rx_max / end_guard // transmit slot is: tx_offset / tx_max / end_guard - .total_duration = 40 + 100 + _TSCH_START_GUARD_TIME + _TSCH_PACKET_TOA_WITH_PADDING + 100, // Total duration of the slot + .total_duration = 40 + 100 + _TSCH_START_GUARD_TIME + _TSCH_PACKET_TOA_WITH_PADDING + _TSCH_END_GUARD_TIME, // Total duration of the slot }; typedef enum { @@ -81,6 +82,8 @@ typedef struct { node_type_t node_type; // whether the node is a gateway or a dotbot uint64_t device_id; ///< Device ID + uint64_t asn; ///< Absolute slot number + tsch_state_t state; ///< State of the TSCH state machine tsch_radio_event_t event; ///< Current event to process @@ -99,30 +102,26 @@ uint8_t default_packet[] = { //========================== prototypes ======================================== -// /** -// * @brief Interrupt handler for the slot-wise ticking of the TSCH scheduler. -// */ -// static void _timer_tsch_slot_handler(void); +//-------------------------- state machine handlers ---------------------------- + +static void _tsch_state_machine_handler(void); +static void _handler_sm_begin_slot(void); + +/* +* @brief Set TSCH state machine state, to be used after the timer expires. +*/ +static inline void _set_next_state(tsch_state_t state); + +// ------------------------- other functions ------------------------------------ /* * @brief Callback function passed to the radio driver. */ static void _tsch_callback(uint8_t *packet, uint8_t length); -static void _tsch_sm_handler(void); -static void _handler_sm_begin_slot(void); -static void _handler_sm_do_rx(void); -static void _handler_sm_is_rxing(void); -static void _handler_sm_do_tx(void); -static void _handler_sm_is_txing(void); - static inline void _set_timer_and_compensate(uint8_t channel, uint32_t duration, uint32_t start_ts, timer_hf_cb_t cb); -static inline void _set_timer(uint8_t channel, uint32_t duration, timer_hf_cb_t timer_callback); +// static inline void _set_timer(uint8_t channel, uint32_t duration, timer_hf_cb_t timer_callback); -/* -* @brief Set TSCH state machine state, to be used after the timer expires. -*/ -static inline void _set_next_state(tsch_state_t state); //=========================== public =========================================== @@ -147,44 +146,60 @@ void db_tsch_init(node_type_t node_type, tsch_cb_t application_callback) { _tsch_vars.node_type = node_type; _tsch_vars.device_id = db_device_id(); + _tsch_vars.asn = 0; + // NOTE: assume the scheduler has already been initialized by the application // set slot total duration tsch_default_slot_timing.total_duration = tsch_default_slot_timing.rx_offset + tsch_default_slot_timing.rx_max + tsch_default_slot_timing.end_guard; - // start the ticking immediately - // db_timer_hf_set_oneshot_us(TSCH_TIMER_DEV, TSCH_TIMER_SLOT_CHANNEL, 100, _timer_tsch_slot_handler); - // initialize and start the state machine _set_next_state(TSCH_STATE_BEGIN_SLOT); uint32_t time_padding = 10; // account for function call and interrupt latency - db_timer_hf_set_oneshot_us(TSCH_TIMER_DEV, TSCH_TIMER_SLOT_CHANNEL, time_padding, _tsch_sm_handler); // trigger the state machine + db_timer_hf_set_oneshot_us(TSCH_TIMER_DEV, TSCH_TIMER_INTER_SLOT_CHANNEL, time_padding, _tsch_state_machine_handler); // trigger the state machine } //=========================== private ========================================== // state machine handler -void _tsch_sm_handler(void) { +void _tsch_state_machine_handler(void) { + uint32_t start_ts = db_timer_hf_now(TSCH_TIMER_DEV); // printf("State: %d\n", _tsch_vars.state); switch (_tsch_vars.state) { case TSCH_STATE_BEGIN_SLOT: DEBUG_GPIO_TOGGLE(&pin0); + DEBUG_GPIO_SET(&pin1); // set the timer for the next slot TOTAL DURATION - _set_timer(TSCH_TIMER_SLOT_CHANNEL, tsch_default_slot_timing.total_duration, &_tsch_sm_handler); + // _set_timer(TSCH_TIMER_INTER_SLOT_CHANNEL, tsch_default_slot_timing.total_duration, &_tsch_state_machine_handler); + _set_timer_and_compensate(TSCH_TIMER_INTER_SLOT_CHANNEL, tsch_default_slot_timing.total_duration, start_ts, &_tsch_state_machine_handler); _handler_sm_begin_slot(); break; case TSCH_STATE_DO_RX: - _handler_sm_do_rx(); - break; - case TSCH_STATE_IS_RXING: - _handler_sm_is_rxing(); + DEBUG_GPIO_CLEAR(&pin1); + DEBUG_GPIO_SET(&pin2); + // update state + _set_next_state(TSCH_STATE_IS_RXING); + // receive packets + db_radio_rx(); // remember: this always starts with before the actual transmission begins, i.e, rx_offset < tx_offset always holds + _set_timer_and_compensate(TSCH_TIMER_INTRA_SLOT_CHANNEL, tsch_default_slot_timing.rx_max, start_ts, &_tsch_state_machine_handler); break; case TSCH_STATE_DO_TX: - _handler_sm_do_tx(); + DEBUG_GPIO_CLEAR(&pin1); + DEBUG_GPIO_SET(&pin2); + // update state + _set_next_state(TSCH_STATE_IS_TXING); + // send the packet + db_radio_tx(_tsch_vars.packet, _tsch_vars.packet_len); + _set_timer_and_compensate(TSCH_TIMER_INTRA_SLOT_CHANNEL, tsch_default_slot_timing.tx_max, start_ts, &_tsch_state_machine_handler); break; + // in case was receiving or sending, now just finish. timeslot will begin again because of the inter-slot timer + case TSCH_STATE_IS_RXING: case TSCH_STATE_IS_TXING: - _handler_sm_is_txing(); + DEBUG_GPIO_CLEAR(&pin2); + // just disable the radio and set the next state + db_radio_disable(); + _set_next_state(TSCH_STATE_BEGIN_SLOT); break; default: break; @@ -196,7 +211,7 @@ void _handler_sm_begin_slot(void) { uint32_t timer_duration = 0; - tsch_radio_event_t event = db_scheduler_tick(); + tsch_radio_event_t event = db_scheduler_tick(_tsch_vars.asn++); // printf(" Event %c: %c, %d Slot duration: %d\n", event.slot_type, event.radio_action, event.frequency, tsch_default_slot_timing.total_duration); switch (event.radio_action) { @@ -213,11 +228,11 @@ void _handler_sm_begin_slot(void) { // TODO: how to get a packet? decide based on _tsch_vars.node_type and event.slot_type // could the event come with a packet? sometimes maybe? or would it be confusing? _tsch_vars.packet_len = sizeof(default_packet); - memcpy(_tsch_vars.packet, default_packet, _tsch_vars.packet_len); + memcpy(_tsch_vars.packet, default_packet, _tsch_vars.packet_len); // set timer duration to resume again after tx_offset timer_duration = tsch_default_slot_timing.tx_offset; - _set_timer_and_compensate(TSCH_TIMER_INTRA_SLOT_CHANNEL, timer_duration, start_ts, &_tsch_sm_handler); + _set_timer_and_compensate(TSCH_TIMER_INTRA_SLOT_CHANNEL, timer_duration, start_ts, &_tsch_state_machine_handler); break; case TSCH_RADIO_ACTION_RX: // configure radio @@ -230,7 +245,7 @@ void _handler_sm_begin_slot(void) { // set timer duration to resume again after rx_offset timer_duration = tsch_default_slot_timing.rx_offset; - _set_timer_and_compensate(TSCH_TIMER_INTRA_SLOT_CHANNEL, timer_duration, start_ts, &_tsch_sm_handler); + _set_timer_and_compensate(TSCH_TIMER_INTRA_SLOT_CHANNEL, timer_duration, start_ts, &_tsch_state_machine_handler); break; case TSCH_RADIO_ACTION_SLEEP: // just disable the radio and do nothing, then come back for the next slot @@ -240,60 +255,37 @@ void _handler_sm_begin_slot(void) { break; } - // _set_timer_and_compensate(TSCH_TIMER_INTRA_SLOT_CHANNEL, timer_duration, start_ts, &_tsch_sm_handler); + // _set_timer_and_compensate(TSCH_TIMER_INTRA_SLOT_CHANNEL, timer_duration, start_ts, &_tsch_state_machine_handler); } -// --- rx handlers --- -void _handler_sm_do_rx(void) { - uint32_t start_ts = db_timer_hf_now(TSCH_TIMER_DEV); - - // update state - _set_next_state(TSCH_STATE_IS_RXING); - - // receive packets - db_radio_rx(); // remember: this always starts with a guard time before the actual transmission begins +// --------------------- timers --------------------- - _set_timer_and_compensate(TSCH_TIMER_INTRA_SLOT_CHANNEL, tsch_default_slot_timing.rx_max, start_ts, &_tsch_sm_handler); -} -void _handler_sm_is_rxing(void) { - // just disable the radio and do nothing, then come back for the next slot - - //uint32_t start_ts = db_timer_hf_now(TSCH_TIMER_DEV); - - // configure radio - db_radio_disable(); - - // set state for after the timer expires - _set_next_state(TSCH_STATE_BEGIN_SLOT); - - // _set_timer_and_compensate(TSCH_TIMER_INTRA_SLOT_CHANNEL, tsch_default_slot_timing.end_guard, start_ts, &_tsch_sm_handler); +static inline void _set_next_state(tsch_state_t state) { + _tsch_vars.state = state; } -// --- tx handlers --- -void _handler_sm_do_tx(void) { - uint32_t start_ts = db_timer_hf_now(TSCH_TIMER_DEV); - - // update state - _set_next_state(TSCH_STATE_IS_TXING); - - // send the packet - db_radio_tx(_tsch_vars.packet, _tsch_vars.packet_len); - - _set_timer_and_compensate(TSCH_TIMER_INTRA_SLOT_CHANNEL, tsch_default_slot_timing.tx_max, start_ts, &_tsch_sm_handler); +static inline void _set_timer_and_compensate(uint8_t channel, uint32_t duration, uint32_t start_ts, timer_hf_cb_t timer_callback) { + uint32_t elapsed_ts = db_timer_hf_now(TSCH_TIMER_DEV) - start_ts; + // printf("Setting timer for duration %d, compensating for elapsed %d gives: %d\n", duration, elapsed_ts, duration - elapsed_ts); + db_timer_hf_set_oneshot_us( + TSCH_TIMER_DEV, + channel, + duration - elapsed_ts, + timer_callback + ); } -void _handler_sm_is_txing(void) { - // just disable the radio and do nothing, then come back for the next slot - //uint32_t start_ts = db_timer_hf_now(TSCH_TIMER_DEV); +//static inline void _set_timer(uint8_t channel, uint32_t duration, timer_hf_cb_t timer_callback) { +//// printf("Setting timer for duration %d\n", duration); +// db_timer_hf_set_oneshot_us( +// TSCH_TIMER_DEV, +// channel, +// duration, +// timer_callback +// ); +//} - // configure radio - db_radio_disable(); - - // set state for after the timer expires - _set_next_state(TSCH_STATE_BEGIN_SLOT); - - // _set_timer_and_compensate(TSCH_TIMER_SLOT_CHANNEL, tsch_default_slot_timing.end_guard, start_ts, &_tsch_sm_handler); -} +// --------------------- others --------------------- static void _tsch_callback(uint8_t *packet, uint8_t length) { printf("Received packet of length %d\n", length); @@ -310,28 +302,3 @@ static void _tsch_callback(uint8_t *packet, uint8_t length) { _tsch_vars.application_callback(packet, length); } } - -static inline void _set_next_state(tsch_state_t state) { - _tsch_vars.state = state; -} - -static inline void _set_timer_and_compensate(uint8_t channel, uint32_t duration, uint32_t start_ts, timer_hf_cb_t timer_callback) { - uint32_t elapsed_ts = db_timer_hf_now(TSCH_TIMER_DEV) - start_ts; - // printf("Setting timer for duration %d, compensating for elapsed %d gives: %d\n", duration, elapsed_ts, duration - elapsed_ts); - db_timer_hf_set_oneshot_us( - TSCH_TIMER_DEV, - channel, - duration - elapsed_ts, - timer_callback - ); -} - -static inline void _set_timer(uint8_t channel, uint32_t duration, timer_hf_cb_t timer_callback) { -// printf("Setting timer for duration %d\n", duration); - db_timer_hf_set_oneshot_us( - TSCH_TIMER_DEV, - channel, - duration, - timer_callback - ); -} diff --git a/projects/01bsp_radio_txrx/01bsp_radio_txrx.c b/projects/01bsp_radio_txrx/01bsp_radio_txrx.c index 813bd33d..a2514038 100644 --- a/projects/01bsp_radio_txrx/01bsp_radio_txrx.c +++ b/projects/01bsp_radio_txrx/01bsp_radio_txrx.c @@ -13,6 +13,7 @@ #include #include #include +#include // Include BSP packages #include "board.h" #include "board_config.h" @@ -26,24 +27,34 @@ //=========================== variables ========================================= -static const uint8_t packet_tx[] = { - 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, // AAAAAAAA - 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, // -------- - 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, // AAAAAAAA - 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, // -------- - 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, // AAAAAAAA - 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, // -------- - 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, // AAAAAAAA - 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, // -------- - 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, // AAAAAAAA - 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, // -------- - 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, // AAAAAAAA - 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, // -------- - 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, // AAAAAAAA - 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, // -------- - 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, // AAAAAAAA - 0x31, 0x32, 0x33, 0x34, 0x00, // 1234 + null -}; +//static const uint8_t packet_tx[] = { +// 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, // AAAAAAAA +// 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, // -------- +// 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, // AAAAAAAA +// 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, // -------- +// 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, // AAAAAAAA +// 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, // -------- +// 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, // AAAAAAAA +// 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, // -------- +// 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, // AAAAAAAA +// 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, // -------- +// 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, // AAAAAAAA +// 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, // -------- +// 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, // AAAAAAAA +// 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, // -------- +// 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, // AAAAAAAA +// 0x31, 0x32, 0x33, 0x34, 0x00, // 1234 + null +//}; + +//static uint8_t packet_tx[] = { +// 0x08, // size of the packet +// 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 +//}; + +uint8_t packet_tx[255] = { 0 }; +size_t packet_tx_len = 0; +#include "device.h" +#include "tsch.h" static const gpio_t _dbg_pin = { .port = DB_LED1_PORT, .pin = DB_LED1_PIN }; @@ -82,11 +93,31 @@ int main(void) { db_radio_init(&radio_callback, DB_RADIO_BLE_2MBit); db_radio_set_frequency(2); // 2 is one of the BLE advertising frequencies db_radio_rx(); - puts("Receiving on frequency 2..."); + printf("%llx receiving on frequency 2...\n", db_device_id()); + + tsch_beacon_packet_header_t beacon = { 0 }; + beacon.active_schedule_id = 6; // schedule_minuscule + beacon.src = db_device_id(); + packet_tx_len = sizeof(beacon); + memcpy(packet_tx, &beacon, packet_tx_len); + + uint8_t freqs[] = { 2, 26, 80 }; + size_t i = 0; + while (1) { + uint8_t freq = freqs[i++ % 3]; + + db_radio_disable(); + db_radio_set_frequency(freq); // 2 is one of the BLE advertising frequencies + + packet_tx[packet_tx_len-1] = i++ % 10; + db_radio_tx((uint8_t *)packet_tx, packet_tx_len); + + //printf("Sending on frequency %d...\n", freq); + //db_timer_hf_delay_ms(0, 500); + db_timer_hf_delay_us(0, 800); + } while (1) { - //db_radio_disable(); - //db_radio_tx((uint8_t *)packet_tx, sizeof(packet_tx) / sizeof(packet_tx[0])); - db_timer_hf_delay_ms(0, 10); + __WFE(); } } diff --git a/projects/01drv_scheduler/01drv_scheduler.c b/projects/01drv_scheduler/01drv_scheduler.c index 6716d9d5..66f91d6d 100644 --- a/projects/01drv_scheduler/01drv_scheduler.c +++ b/projects/01drv_scheduler/01drv_scheduler.c @@ -19,6 +19,8 @@ #include "protocol.h" #include "device.h" +#define SLOT_DURATION 1000 * 1000 // 1 s + // make some schedules available for testing #include "test_schedules.c" extern schedule_t schedule_minuscule; @@ -37,13 +39,14 @@ int main(void) { // loop n_slotframes*n_cells times and make the scheduler tick // also, try to assign and deassign uplink cell at specific slotframes size_t n_slotframes = 4; + uint64_t asn = 0; for (size_t j = 0; j < n_slotframes; j++) { for (size_t i = 0; i < schedule.n_cells; i++) { - tsch_radio_event_t event = db_scheduler_tick(); - printf("Event %c: %c, %d, %d\n", event.slot_type, event.radio_action, event.frequency, event.duration_us); + tsch_radio_event_t event = db_scheduler_tick(asn++); + printf("Event %c: %c, %d, %d\n", event.slot_type, event.radio_action, event.frequency); // sleep for the duration of the slot - db_timer_hf_delay_us(TSCH_TIMER_DEV, event.duration_us); + db_timer_hf_delay_us(TSCH_TIMER_DEV, SLOT_DURATION); } puts("."); if (j == 0 && !db_scheduler_assign_next_available_uplink_cell(db_device_id())) { // try to assign at the end of first slotframe diff --git a/projects/01drv_tsch/01drv_tsch.c b/projects/01drv_tsch/01drv_tsch.c index 2b02227c..840c2e06 100644 --- a/projects/01drv_tsch/01drv_tsch.c +++ b/projects/01drv_tsch/01drv_tsch.c @@ -53,7 +53,7 @@ static void radio_callback(uint8_t *packet, uint8_t length); int main(void) { // initialize schedule - schedule_t schedule = schedule_test; + schedule_t schedule = schedule_minuscule; node_type_t node_type = NODE_TYPE_DOTBOT; db_scheduler_init(node_type, &schedule); printf("Device of type %c and id %llx is using schedule %d\n\n", node_type, db_device_id(), schedule.id);