I am a relatively new OpenRTOS user and so far I’m amazed by the possibilities it offer you when dealing with a larger embedded project. However, I got into a problem and would like to ask for some advice on the best way to handle it.
I am trying to implement a CAN based communication protocol and part of it is to send streams of CAN messages separated by time intervals of 100uS. It is ok if the interval is a bit longer, but it should never be shorter than 100uS. I am running an ARM Cortex M4F at 120MHz and my OS ticks are set to 1000Hz.
One of the first solutions I thought about was to increase the tick rate to 10kHz and use vTaskDelay(1) to create the intervals, while giving the other tasks a chance to run. However, I’ve read that it’s best to avoid such high tick rates, due to the context switching delays.
A second solution would be to give my task a higher priority and use a while loop to wait for the 100uS interval. However, this would prevent other tasks from running and this could be a real problem if the message sequence is longer.
The third option would be to block the task with a semaphore as soon as it finishes sending a message. The semaphore would be released in a hardware timer ISR after 100uS. However, I wasn’t able to get the task to wake up multiple times during a tick period. I tried using the xSemaphoreGiveFromISR function follwed by a taskYIELD if the woken parameter gets set, but my task was still executed only once per milisecond.
Do you have any ideas about this problem? I feel like there should be a way to get it done nicely, but I am missing something.