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!
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 */
}
}
}
I’d use xTaskCheckForTimeOut paired with vTaskSetTimeOutState. See the example in the API docs https://freertos.org/xTaskCheckForTimeOut.html
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*/
}
//...
//...
}