Asynchronous activation of a periodic task

Dear community,
I need to make an periodic task (I’m using a task with vTaskDelayUntil set to 250ms) executable asynchronously by an external software stimulus.
This task enable a display visualization with a costant period, but when a press a button, I want to refresh it immediately, resuming the normal operation after this extra execution.

Could you please help me?

Many thanks

Yours Sincerely

First I want to check I understand the question. You have a task that executes every 250ms, but when a button is pushed you want the task to run immediately rather than wait until the next scheduled run. Is that correct? If so then there are a few things you can do.

First, you could have the button handling code call xTaskAbortDelay() passing the handle of the periodic task. That will remove the periodic task from the blocked state and move it into the ready state - it will then run as soon as it is the highest priority task in the ready state.

Second, if the periodic timing doesn’t have to be exact, you could have the task block on a task notification (or queue, or semaphore, or event group) that uses a block time of 250ms. If no notifications are received the task will leave the blocked state when the 250ms block time expires. If the button handler sends the task a notification it will leave the blocked state immediately (and then likewise execute as soon as it is the highest priority task in the ready state…).

Dear Richard,

you understood perfectly and many thanks for your valuable help.

Tomorrow I’ll looking for some examples on how xTaskAbortDelay() works.

Best regards

Adriano Casarotto