rtic
rtic copied to clipboard
rtic-monotonic: Is handling intermediate interrupts for housekeeping OK?
From the documentation, I assume that the set_compare method aims to schedule an interruption for a given time instant. However, in my use case, there is a chance that I must do some housekeeping and need two different interrupts to handle timer overflows.
I was thinking about making set_compare and on_interrupt work jointly to handle this particularity. However, I am not sure if RTIC supports "fake" interrupts in intermediate instants that do not correspond to the instant provided when calling set_compare. Is it OK to trigger extra interruptions?
EDIT: I assume you are talking about RTIC 2.
Yes, it is ok. If a spurious interrupt happens, RTIC will simply re-check the timer queue and do another set_compare.
"need two different interrupts to handle timer overflows" - Check out the imxrt-gpt monotonic on how to deal with overflows, it uses one rollover interrupt and one half-period interrupt.
Also check out this new helper utility specifically geared towards implementing a monotonic based on those two interrupts.
Be careful with race conditions - handling timer overflows is very race condition prone, as the timer register is inherently asynchronous. The aforementioned helper utility describes this problem and how to solve it reliably.