Skip to content

Commit

Permalink
tsch: fix dumb bugs, allow 32-bit duration_us
Browse files Browse the repository at this point in the history
  • Loading branch information
geonnave committed Jan 6, 2025
1 parent 7b1e098 commit 78c379f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion drv/scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion drv/scheduler/all_schedules.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions drv/scheduler/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ typedef struct {
// counters and indexes
uint64_t asn; // absolute slot number

uint8_t active_schedule_id; // id of the active schedule in available_schedules
schedule_t *active_schedule_ptr; // pointer to the currently active schedule
uint32_t slotframe_counter; // used to cycle beacon frequencies through slotframes (when listening for beacons at uplink slots)
size_t current_beacon_cell_index;

Expand All @@ -68,22 +68,22 @@ void db_scheduler_init(schedule_t *application_schedule) {
_schedule_vars.available_schedules[_schedule_vars.available_schedules_len++] = schedule_tiny;
if (application_schedule != NULL) {
_schedule_vars.available_schedules[_schedule_vars.available_schedules_len++] = *application_schedule;
_schedule_vars.active_schedule_id = application_schedule->id;
_schedule_vars.active_schedule_ptr = 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_ptr = &_schedule_vars.available_schedules[i];
return true;
}
}
return false;
}

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 = *_schedule_vars.active_schedule_ptr;

// increment ASN so that nodes are in sync
_schedule_vars.asn++;
Expand Down
2 changes: 1 addition & 1 deletion drv/tsch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ==========================================
Expand Down
6 changes: 3 additions & 3 deletions projects/01drv_scheduler/01drv_scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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();
}
}

0 comments on commit 78c379f

Please sign in to comment.