Commit 262ab08e authored by Reto Da Forno's avatar Reto Da Forno
Browse files

startup delay removed from LWB and guard time 2 added

parent c611ff66
Subproject commit 683f1be179de52e257d6555f425bc5d61d14ccaf
Subproject commit 5c75752fee23683f20dbcd1a855f893d4718a8a7
......@@ -363,7 +363,7 @@ static void lwb_send_schedule(lwb_time_t start_of_round)
static void lwb_receive_schedule(lwb_time_t start_of_round)
{
gloria_start(false, (uint8_t*)&schedule, 0, n_tx, 1);
lwb_wait_until(start_of_round + t_sched + LWB_T_GUARD_ROUND);
lwb_wait_until(start_of_round + t_sched + ((sync_state == SYNCED) ? LWB_T_GUARD_ROUND : LWB_T_GUARD_ROUND_2));
gloria_stop();
if (slot_cb) {
......@@ -848,12 +848,12 @@ static void lwb_run(void)
}
/* drift compensation */
int32_t drift_comp = lwb_calc_drift_comp(schedule.period);
int32_t drift_comp = lwb_calc_drift_comp(schedule.period);
/* schedule the wakeup for the next round */
start_of_round += schedule.period + drift_comp;
if (!is_host) {
start_of_round -= LWB_T_GUARD_ROUND; /* add guard time on a source node */
start_of_round -= (sync_state == SYNCED) ? LWB_T_GUARD_ROUND : LWB_T_GUARD_ROUND_2; /* add guard time on a source node */
}
if (LWB_T_PREPROCESS) {
start_of_round -= LWB_T_PREPROCESS; /* wake up earlier such that the pre task can run */
......@@ -933,17 +933,6 @@ void lwb_start(void)
lwb_running = true;
/* instead of calling lwb_run(), schedule the start */
#if LWB_STARTUP_DELAY > 0
lwb_time_t starttime = LWB_MS_TO_TICKS(LWB_STARTUP_DELAY);
if (is_host) {
starttime += LWB_T_GUARD_ROUND; /* delay the host by LWB_T_GUARD_ROUND */
}
if (LWB_TIMER_NOW() < starttime) {
lwb_wait_until(starttime);
}
#endif /* LWB_STARTUP_DELAY */
lwb_run();
}
......
......@@ -100,6 +100,11 @@
#define LWB_T_GUARD_ROUND (LWB_TIMER_FREQUENCY / 1000) /* 1ms */
#endif /* LWB_T_GUARD_ROUND */
/* longer guard time before a round in LF ticks, used if a schedule is missed or the drift has not yet been estimated */
#ifndef LWB_T_GUARD_ROUND_2
#define LWB_T_GUARD_ROUND_2 (LWB_TIMER_FREQUENCY / 5000) /* 5ms */
#endif /* LWB_T_GUARD_ROUND_2 */
/* time reserved for the preprocess task (before a round) in LF ticks */
#ifndef LWB_T_PREPROCESS
#define LWB_T_PREPROCESS (LWB_TIMER_FREQUENCY / 10) /* 100ms */
......@@ -136,10 +141,6 @@
#define LWB_MAX_CLOCK_DRIFT 100 /* in ppm */
#endif /* LWB_MAX_CLOCK_DRIFT */
#ifndef LWB_STARTUP_DELAY
#define LWB_STARTUP_DELAY 1000 /* delay in milliseconds from the start of the MCU */
#endif /* LWB_STARTUP_DELAY */
/* use more accurate high frequency reference clock to schedule the contention slot
* (requires an implementation of LWB_GLORIA_GET_T_REF_HF()) */
#ifndef LWB_CONT_USE_HSTIMER
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment