diff options
author | Lorenz Meier <lm@inf.ethz.ch> | 2013-12-21 19:07:24 +0100 |
---|---|---|
committer | Lorenz Meier <lm@inf.ethz.ch> | 2013-12-21 19:07:24 +0100 |
commit | b84c9f962b5c3c4d94e21aeb148dec8ffb42b0c9 (patch) | |
tree | ed00e4ce697f96763964267a9dc5870b06a1ffa4 /src/drivers/stm32/drv_hrt.c | |
parent | c033443208666d6972d99fe5a7b8e0c3fa5050b5 (diff) | |
parent | 831f153b7385fecb180c977727eb6b2f8bef1317 (diff) | |
download | px4-firmware-b84c9f962b5c3c4d94e21aeb148dec8ffb42b0c9.tar.gz px4-firmware-b84c9f962b5c3c4d94e21aeb148dec8ffb42b0c9.tar.bz2 px4-firmware-b84c9f962b5c3c4d94e21aeb148dec8ffb42b0c9.zip |
Merged master
Diffstat (limited to 'src/drivers/stm32/drv_hrt.c')
-rw-r--r-- | src/drivers/stm32/drv_hrt.c | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/drivers/stm32/drv_hrt.c b/src/drivers/stm32/drv_hrt.c index e79d7e10a..1bd251bc2 100644 --- a/src/drivers/stm32/drv_hrt.c +++ b/src/drivers/stm32/drv_hrt.c @@ -733,6 +733,13 @@ hrt_call_internal(struct hrt_call *entry, hrt_abstime deadline, hrt_abstime inte irqstate_t flags = irqsave(); /* if the entry is currently queued, remove it */ + /* note that we are using a potentially uninitialised + entry->link here, but it is safe as sq_rem() doesn't + dereference the passed node unless it is found in the + list. So we potentially waste a bit of time searching the + queue for the uninitialised entry->link but we don't do + anything actually unsafe. + */ if (entry->deadline != 0) sq_rem(&entry->link, &callout_queue); @@ -839,7 +846,12 @@ hrt_call_invoke(void) /* if the callout has a non-zero period, it has to be re-entered */ if (call->period != 0) { - call->deadline = deadline + call->period; + // re-check call->deadline to allow for + // callouts to re-schedule themselves + // using hrt_call_delay() + if (call->deadline <= now) { + call->deadline = deadline + call->period; + } hrt_call_enter(call); } } @@ -906,5 +918,16 @@ hrt_latency_update(void) latency_counters[index]++; } +void +hrt_call_init(struct hrt_call *entry) +{ + memset(entry, 0, sizeof(*entry)); +} + +void +hrt_call_delay(struct hrt_call *entry, hrt_abstime delay) +{ + entry->deadline = hrt_absolute_time() + delay; +} #endif /* HRT_TIMER */ |