-1

I would like to execute a function every 10ms in a task called at 1ms. Do you know if there is a function to do that without blocking the task please ?

Have a good day!

QBKM
  • 3
  • 2

3 Answers3

1
static void app_task(void *arg)
{ 
    int period_ms = 1000; 
    TimeOut_t timeout; 
    TickType_t period_tick = pdMS_TO_TICKS(period_ms); vTaskSetTimeOutState(&timeout);

    for (;;) {
            if(xTaskCheckForTimeOut(&timeout, &period_tick) != pdFALSE) {
            vTaskSetTimeOutState(&timeout);
            period_tick = pdMS_TO_TICKS(period_ms);

            /* task */ 
            }   

   
    }
}
0

I’d use xTaskCheckForTimeOut paired with vTaskSetTimeOutState. See the example in the API docs https://freertos.org/xTaskCheckForTimeOut.html

HS2
  • 164
  • 1
  • 1
  • 4
0

Thanks HS2, it works well. Here a sample of how I proceed for executing some code every 10ms in a 1ms task.

xTimeOutType x_timeout; 
portTickType openTimeout;
 
vTaskSetTimeOutState(&x_timeout);
openTimeout = 10; /*ms*/
 
while(1)
{
    //...
    //...

    if(xTaskCheckForTimeOut(&x_timeout, &openTimeout) == pdTRUE)
    {
        // do some stuff here
        openTimeout = 10; /*reload the 10ms*/
    }

    //...
    //...
}
QBKM
  • 3
  • 2