Scheduling of periodic tasks starting at t0


I’m trying to implement Rate Monotonic Scheduling using the FreeRTOS priority based preemptive scheduler. One of the requirements of the RMS is that all tasks are started at t=0.

My problem is the following: I have a high priority task A that starts at time t=0 and executes for 2ms.

When done the next task is task B of a lower priority. It needs to execute every 20ms starting from t=0. The problem is that by using vTaskDelayUntil() I can only schedule it to run at its next period (20) + its last wakeup time (2 in this case) which equals t=22.

What I would like is that vTaskDelayUntil counts from the start time of the RTOS at t=0. Therefor it would schedule task B at t=20 and t=40, 60, 80, 100 not depending of the actual task run time but only depending on its period.

Would it be possible to do that using FreeRTOS ?


You could use a hardware timer to unblock tasks at a given time, rather than use vTaskDelayUntil(). You could probably do something awkward like inverse the priorities as a starting condition, the have the tasks set their correct priority before they block for the first time (so the lowest priority task runs first to get its for run time set correctly.

Are you sure what you are attempting is RMS? Above may not be necessary if you initialize the second parameter of vTaskDelayUntil() to zero.

1 Like

That could do it but I would have to start the timer along with the first task and then care about overflow conditions. I did something pretty similar in fact.

In the highest priority task (Task A) I set a global variable called starting_time_tick with current Kernel tick count before the real task code begins. I then use starting_time_tick in other tasks to schedule the next run that will only be dependent to the start time of task A and not execution of Task A. However, using this trick I need to care about overflow conditions. I don’t know if there is a better method.

Yes that could work however as you said it’s a bit akward and counter intuitive and I would like to avoid that.

Yes, why ? In Rate Monotonic Scheduling all tasks are released as soon as they arrive and in this context (at the beginning of the program) they’re all ready to execute. But without thinking about RMS, what’s the best way to schedule a task precisely every 20ms starting at the beginning of the Kernel execution even if it’s not the highest priority task ?

You meant the first one *pxPreviousWakeTime right ? That would work only if the Tick count was assured to be 0 at the kernel start but the systick counts before that, doesn’t it ?

The timer counter generally starts at 0, but if you want to be more general, have your highest priority task save its starting time in a global, so all the other task can initialize there starting time to it,

1 Like

Yes I also think it’s the best solution. Thank you.