diff --git a/drv/scheduler.h b/drv/scheduler.h index 5e049892..46cbf41d 100644 --- a/drv/scheduler.h +++ b/drv/scheduler.h @@ -53,7 +53,7 @@ typedef struct { uint8_t max_nodes; // maximum number of nodes that can be scheduled, equivalent to the number of uplink slots uint8_t backoff_n_min; // minimum exponent for the backoff algorithm uint8_t backoff_n_max; // maximum exponent for the backoff algorithm - uint16_t slot_duration_us; // duration of a slot in microseconds + uint32_t slot_duration_us; // duration of a slot in microseconds size_t n_cells; // number of cells in this schedule cell_t cells[TSCH_N_CELLS_MAX]; // cells in this schedule. NOTE(FIXME?): the first 3 cells must be beacons } schedule_t; diff --git a/drv/scheduler/all_schedules.c b/drv/scheduler/all_schedules.c index e128932a..17ec3e58 100644 --- a/drv/scheduler/all_schedules.c +++ b/drv/scheduler/all_schedules.c @@ -18,7 +18,8 @@ schedule_t schedule_minuscule = { .max_nodes = 5, .backoff_n_min = 5, .backoff_n_max = 9, - .slot_duration_us = 2024, + // .slot_duration_us = 2024, + .slot_duration_us = 1000 * 1000, .n_cells = 11, .cells = { // Begin with beacon cells. They use their own channel offsets and frequencies. diff --git a/drv/scheduler/scheduler.c b/drv/scheduler/scheduler.c index 88d0423f..271689b3 100644 --- a/drv/scheduler/scheduler.c +++ b/drv/scheduler/scheduler.c @@ -75,15 +75,24 @@ void db_scheduler_init(schedule_t *application_schedule) { bool db_scheduler_set_schedule(uint8_t schedule_id) { for (size_t i = 0; i < N_SCHEDULES; i++) { if (_schedule_vars.available_schedules[i].id == schedule_id) { - _schedule_vars.active_schedule_id = i; + _schedule_vars.active_schedule_id = schedule_id; return true; } } return false; } +schedule_t *_get_active_schedule(void) { + for (size_t i = 0; i < N_SCHEDULES; i++) { + if (_schedule_vars.available_schedules[i].id == _schedule_vars.active_schedule_id) { + return &_schedule_vars.available_schedules[i]; + } + } + return NULL; +} + tsch_radio_event_t db_scheduler_tick(void) { - schedule_t active_schedule = _schedule_vars.available_schedules[_schedule_vars.active_schedule_id]; + schedule_t active_schedule = *_get_active_schedule(); // increment ASN so that nodes are in sync _schedule_vars.asn++; diff --git a/drv/tsch.h b/drv/tsch.h index fa366e79..f0ae2506 100644 --- a/drv/tsch.h +++ b/drv/tsch.h @@ -40,7 +40,7 @@ typedef enum { typedef struct { tsch_radio_action_t radio_action; uint8_t frequency; - uint16_t duration_us; + uint32_t duration_us; } tsch_radio_event_t; //=========================== prototypes ========================================== diff --git a/projects/01drv_scheduler/01drv_scheduler.c b/projects/01drv_scheduler/01drv_scheduler.c index df614143..0b029143 100644 --- a/projects/01drv_scheduler/01drv_scheduler.c +++ b/projects/01drv_scheduler/01drv_scheduler.c @@ -26,7 +26,7 @@ schedule_t schedule_test = { .max_nodes = 0, .backoff_n_min = 5, .backoff_n_max = 9, - .slot_duration_us = 2024, + .slot_duration_us = 1000 * 1000, // 1 second .n_cells = 3, .cells = { // Only downlink slots @@ -43,7 +43,7 @@ int main(void) { db_timer_hf_init(TSCH_TIMER_DEV); db_scheduler_init(&schedule_test); - // db_scheduler_set_schedule(5); + db_scheduler_set_schedule(32); uint8_t freq = db_scheduler_get_frequency(SLOT_TYPE_SHARED_UPLINK, 0, 0); printf("Frequency: %d\n", freq); @@ -55,6 +55,6 @@ int main(void) { // sleep for the duration of the slot db_timer_hf_delay_us(TSCH_TIMER_DEV, event.duration_us); - __WFE(); + //__WFE(); } }