How to create a delay in a task without blocking that task?

Hello, My question is about implementing the functionality of HALDelay(), which is implemented based on the SysTick timer tick count. In my FreeRTOS project, I am using another timer, namely TIM1, therefore using HALDelay() doesn’t give me correct behaviour. I would like to write my own function to create a delay in a FreeRTOS task, without leaving that task, but I am not sure how to start off. Suggestions appreciated, thank you! Note: vTaskDelay() causes the task to be blocked, and therefore does not do what I want. Thank you very much!

How to create a delay in a task without blocking that task?

My first comment is why? The main reason for using something like a RTOS is to get something like task switching so that while one piece of code is waiting for somethng, other parts can run. Second is that generally (you don’t say what processor your using), functions like HALDelay() are fairly easy to change what timer they are using, so making HALDelay work should be that hard, and if you are using other parts of the HAL package, may be important to get to work.

How to create a delay in a task without blocking that task?

You can obtain crude wait using xTaskGetTickCount(); Let’s say, your tick rate is 100Hz. Assuming the task you want to wait on has the highest priority, you can accomplish what you want like that, ~~~ TickTypet currentTick = xTaskGetTickCount(); while(xTaskGetTickCount() – currentTick < pdMSTO_TICKS(1000)) { //… } ~~~