1
votes

I have taking an online course on real time systems where FreeRTOS is used to demonstrate the various functionalities of an RTOS. The problem I am facing right now is as follows:

  • There are two tasks (A and B) created in the main function and the real time scheduler is started.
  • The task B has a lower priority than task A. Task B needs to be given scheduled every n ms but since the priority of task A is higher than that of B, B does not get scheduled every n ms.
  • So, we need to write a new function that takes the task handles of A and B and measures the execution time of task B.
  • If the execution time of B is more than n ms, it increases the priority.

I understood the functionality of the function to increase the priority but could not understand how to measure the task execution time. The problem specifically asks us to use the vApplicationTickHook( void ) function to do so. Any hint would be appreciated. I posted in the course's discussion forum as well but didn't get any reply, hence posted here.

1
There's a sample already for that in the FreeRTOS documentation IIRC.πάντα ῥεῖ
Hi, I went through the FreeRTOS documentation but could not figure it out. Thanksdwd
Don't you mean that the other way round? If the time taken by task A (higher priority) is more than n, the priority of A needs to be increased?Weather Vane
Edited, thanks. The problem specifically asks for task B. So, task B needs to be scheduled every n ms, and we need to see if the execution time is more than n ms, then it needs to given higher priority. I am a bit confused here about the execution time and scheduling period but this is what the problem says.dwd
You are at bare metal level, so think bare metal: use a timer if you want to assure a specific timing, not a low priority scheduled task.LPs

1 Answers

1
votes

First let me preface my answer with a comment that the requirements of this question are bizarre and not something that I've ever come across in practice. This might be useful as an exercise to get familiar with FreeRTOS. But it's not something I would ever do on a real project. Instead I would design the tasks more sensibly.

vApplicationTickHook() runs periodically, once every tick. It runs from the context of the timer ISR so it preempts even the high-priority task A. Since it runs periodically we can use it to poll for the information we need. FreeRTOS includes many Task Utilities, one of these probably provides some relevant information.

The first thing I found that looks useful is vTaskGetInfo() returns a pointer to TaskStatus_t structure, which contains ulRunTimeCounter, the total run time allotted to the task so far. So, from vApplicationTickHook() you can call vTaskGetInfo() to poll for Task B's total run time. Remember Task B's previous runtime in a local static variable and when its runtime hasn't increased for n ms then you will know that it's time to raise the priority of Task B.