Skip to content

AbanoubSalah/freertos-rms-scheduler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚀 Rate Monotonic Scheduler (RMS) Library for FreeRTOS

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).

🌟 Features

  • 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.

🛠️ Prerequisites

  • A working FreeRTOS environment (tested with FreeRTOS V10.x and newer).
  • For Schedulability Analysis Script: Python 3.x is required.

⚙️ C Library Usage and Integration

1. Add Files

Integrate rm_scheduler.c and rm_scheduler.h into your project's source path.

2. Create Tasks

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();
}

3. Delete Tasks

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 );

📊 Schedulability Analysis Script (Python)

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.

1. Add Script File

Include schedulability_analyzer.py in your project's root directory or analysis tools folder.

2. Run the Analysis

Execute the script using Python 3:

python schedulability_analyzer.py

The script will analyze predefined example task sets and output the results.

3. Interpretation (Liu & Layland Test)

The Liu & Layland test checks if the total utilization ($U$) is below the theoretical bound ($U_{LL}$) for $n$ tasks: $$U = \sum_{i=1}^{n} \frac{C_i}{T_i} \le U_{LL}(n) = n \left(2^{1/n} - 1\right)$$

Condition Conclusion Action Required
$U \le U_{LL}(n)$ Guaranteed Schedulable. Proceed with implementation.
$U_{LL}(n) < U \le 1.0$ Not Guaranteed. Must perform a stricter test (like Response Time Analysis, RTA) to confirm. The simple test failed.
$U > 1.0$ 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.

License

The code in this project is licensed under the MIT License.

About

Provides an implementation of Rate Monotonic Scheduler (RMS) layer built on top of the standard FreeRTOS kernel

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors