How to measure timeouts?

Hello,

I have been implementing a control software on the FreeRTOS base and I have been looking for how to implement timeout measurements in the application layer. I need to measure timeouts e.g. for contactor closing/opening operation and stuff like that. My requirement is that the measurement of timeouts is not based on knowledge of task execution period (i.e. I don´t want to use some variable which is incremented on a task).

I have thought about usage of the FreeRTOS timer objects but the way how to work with them does not fit into the architecture of my application layer. Another approach which is in my mind is to use the hardware timer from which the FreeRTOS scheduler is triggered
(let´s say system timer). As far as this approach I have three questions:

a) Is the status of the system timer available via some FreeRTOS function?
b) If so, is it recommended practise to use it for those purposes?
c) One more thing related to the system timer is whether it is possible to use it also in interrupt service routines (ISR) i.e. whether it is incremented also in case the ISR is executed?

Could anybody give me an advice how is that solved in standard manner?

Thanks in advance for any suggestions.

You can get the current value of the tick counter with a simple call (xTaskGetTickCount), which will give you time to the resolution of a tick.

If you need a higher resolution, if you have enabled Run Time Stats, then there will be a higher resolution timer value available via the macro portGET_RUN_TIME_COUNTER_VALUE() (you will have to look at your code to figure out what rate that is counting)

If you want to add code to the tick interrupt, there is the vApplicationTickHook() function that you can enable with configUSE_TICK_HOOK