Periodic Task that also call from interrupt.

valeriv wrote on Tuesday, July 26, 2016:

Hello to all.
I have GUI task that it’s main purpose to redraw windows and to react on pressing buttons.
So I thought that the best way redraw window every 200 miliseconds (vTaskDelay(200)), and also I want to call it from Keyboard Interrupt.
I redraw window periodicly, because the data on it can be changed. So, I can’t use vTaskSuspend.

Help me, please, how can i do this ?
Thanks in advance
Valerie

valeriv wrote on Tuesday, July 26, 2016:

I think, may be, the gui task after redraw window will set itself to suspend state.
And resume it from timer every 200 mili and from the keyboard interrupt.
???

valeriv wrote on Tuesday, July 26, 2016:

If I will run the gui Task in loop with Delay(200) , how can I break the DELAING state from keyboard interrupt ?

davedoors wrote on Tuesday, July 26, 2016:

From a task you can use http://www.freertos.org/xTaskAbortDelay.html but I’m not sure if there is a FromISR version.

rasty1 wrote on Tuesday, July 26, 2016:

I’d recoment to use semaphore with Delay option instead of vTaskDelay.
If you need to interrupt, just give a semaphore.

valeriv wrote on Tuesday, July 26, 2016:

Hi Dave, thanks for your answer. But I really don’t see FromISR version.
How I can check if it is right solution for my problem ?

valeriv wrote on Tuesday, July 26, 2016:

Hi, Rasty.
Can you, please, give me an example of your solution.
If I understand right, the gui task take semaphore in the end of it’s loop…
In keyboard interrupt I can give semaphore back.
What about call gui task every 200 mili ? Return semaphore from timer ?

Can you explain your solution again ?

rasty1 wrote on Tuesday, July 26, 2016:

I hope that I understand correcly the problem.
You have to redraw screen each 200 ms. Sometimes trigger extra redraw from Interrupt or other context.

while (1)
{
xSemaphoreTake(sem, 200);
// will leave xSemaphoreTake after 200 msecs (with error) or earlier if sem is given.
redraw();
}

from other task/interrupt
xSemaphoreGive(sem)

valeriv wrote on Wednesday, July 27, 2016:

Thanks a lot to you, Rasty

rtel wrote on Wednesday, July 27, 2016:

You can also do the same thing in a more efficient way using a direct to
task notification in place of a semaphore.

http://www.freertos.org/RTOS_Task_Notification_As_Counting_Semaphore.html

valeriv wrote on Thursday, July 28, 2016:

thank you very much