Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tsch: fix dumb bugs, allow 32-bit duration_us
Browse files Browse the repository at this point in the history
geonnave committed Jan 6, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 7b1e098 commit 9917254
Showing 5 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion drv/scheduler.h
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 2 additions & 1 deletion drv/scheduler/all_schedules.c
Original file line number Diff line number Diff line change
@@ -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.
13 changes: 11 additions & 2 deletions drv/scheduler/scheduler.c
Original file line number Diff line number Diff line change
@@ -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++;
2 changes: 1 addition & 1 deletion drv/tsch.h
Original file line number Diff line number Diff line change
@@ -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 ==========================================
6 changes: 3 additions & 3 deletions projects/01drv_scheduler/01drv_scheduler.c
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit 9917254

Please sign in to comment.