This repository provides an implementation of a Rate Monotonic Scheduler (RMS) layer built on top of the standard FreeRTOS kernel. This layer simplifies the creation and management of periodic tasks, automatically enforcing the Rate Monotonic Priority Assignment policy (shorter period = higher priority).
- Rate Monotonic Priority Assignment: Tasks are automatically assigned priorities based on their period; tasks with shorter periods receive higher priorities.
- Dynamic Priority Update: Priorities of all tasks are automatically re-calculated and updated within the RTOS kernel whenever a task is created or deleted.
- Harmonic Task Scheduling: Utilizes
vTaskDelayUntil()for high-precision, periodic execution. - MISRA C Compliance: The implementation strives to adhere to standard MISRA C guidelines for safety-critical embedded systems.
- A working FreeRTOS environment (tested with FreeRTOS V10.x and newer).
- For Schedulability Analysis Script: Python 3.x is required.
Integrate rm_scheduler.c and rm_scheduler.h into your project's source path.
Tasks must be created using the RMS API function before calling vSchedulerStart().
#include "rm_scheduler.h"
/* Define periods in ticks (e.g., 100ms, 200ms, 500ms) */
#define TASK_1_PERIOD_MS ( 100U )
#define TASK_2_PERIOD_MS ( 200U )
#define TASK_3_PERIOD_MS ( 500U )
/* Convert milliseconds to ticks */
#define MS_TO_TICKS(ms) ( pdMS_TO_TICKS( (ms) ) )
/* Task Handles (Optional) */
TaskHandle_t xHandleTask1 = NULL;
/* Task function prototypes */
void vTaskCode1( void *pvParameters );
void vMainTaskCreation( void )
{
/* Priority will be assigned automatically:
T1 (100ms) -> Highest, T2 (200ms) -> Medium, T3 (500ms) -> Lowest */
// Task 1: Period 100ms
vSchedulerPeriodicTaskCreate(
vTaskCode1,
"Task_100ms",
configMINIMAL_STACK_SIZE,
(void*)0,
&xHandleTask1,
MS_TO_TICKS(TASK_1_PERIOD_MS) );
// ... create other tasks
// Start the scheduler
vSchedulerStart();
}Periodic tasks can be deleted dynamically using the API. The internal linked list and priorities of remaining tasks will be updated automatically.
/* Delete Task 1 using its handle */
vSchedulerPeriodicTaskDelete( xHandleTask1 );
/* To self-delete from within a periodic task: */
// vSchedulerPeriodicTaskDelete( NULL );Before deploying a Rate Monotonic schedule, it is critical to confirm its feasibility. The included Python script performs the fundamental Liu & Layland Utilization Bound Test.
Include schedulability_analyzer.py in your project's root directory or analysis tools folder.
Execute the script using Python 3:
python schedulability_analyzer.pyThe script will analyze predefined example task sets and output the results.
The Liu & Layland test checks if the total utilization (
| Condition | Conclusion | Action Required |
|---|---|---|
| Guaranteed Schedulable. | Proceed with implementation. | |
| Not Guaranteed. | Must perform a stricter test (like Response Time Analysis, RTA) to confirm. The simple test failed. | |
| Inherently Unschedulable. | The task set requires more CPU time than available. Must reduce WCETs or increase periods. |
Important Note: The utilization bound test is sufficient but not necessary. Failing the test does not definitively mean the system will miss deadlines, but it requires further, more complex analysis to prove schedulability.
The code in this project is licensed under the MIT License.