Recommended way to create variable wait times

hillridge wrote on Tuesday, May 21, 2019:

Is there a recommended way to add the “until” functionality to other calls that use a wait time as a parameter?

For example, if I want a task to have a 1 second period, I can use this at the end of the infinite loop, assuming I set up xLAstWakeTime and the loop takes less than a second to execute:
vTaskDelayUntil(&xLastWakeTime, pdMS_TO_TICKS( 1000 ));

Instead, I would like to create a task with a one second period that will wake early if a notification is sent. Basically use a non-existant call to:
ulTaskNotifyTakeUntil(pdTRUE, pdMS_TO_TICKS( 1000 ));

I could technically do this by getting the tick count at the top of the loop as well as the bottom of the loop, subtract the difference from 1000ms worth of ticks, and use that as the delay parameter for ulTaskNotifyTake(), but then I need to account for overflows in the tick counter and the whole thing gets messy very quickly.

Should I be using a different method alltogether?

rtel wrote on Tuesday, May 21, 2019:

No easy way of doing it but one possibility would be to have the tick
hook function send a notification to the task at a regular period to
unblock the task in a way that it knows the real event didn’t occur.
Possibly even just use an abort delay call rather than send a
notification, although I can’t recall if that can be done from inside an
ISR or not.

hillridge wrote on Tuesday, May 21, 2019:

Thanks, that actually gave me an easier way to do it.

I left my ulTaskNotifyTake() call with a timeout of 0, and put the vTaskDelayUntil(&xLastWakeTime, pdMS_TO_TICKS( 1000 )); right before it.
In the task that sends the notification, I added the xTaskAbortDelay right after I sent the notification.