This repository is a modified version of the FreeRTOS component from Espressif's ESP-IDF, tailored to support development of industrial applications requiring safety mechanisms aligned with the IEC 61508 standard (Safety Integrity Level 1 - SIL1).
To integrate lightweight safety mechanisms into the FreeRTOS kernel for ESP32/ESP32-S3 targets, enabling the detection and handling of critical task failures in real-time systems.
-
βοΈ All tasks forced to be treated as critical:
- A task must be explicitly registered with the monitor system.
-
π‘οΈ Stack Overflow Protection enabled:
configCHECK_FOR_STACK_OVERFLOWforced to2for every task.
-
π‘οΈ Custom Scheduler Hook:
- Implemented
traceTASK_SWITCHED_IN()to monitor task context switches and auto-report task activity.
- Implemented
-
π‘οΈ Safety Monitor Task:
- Added a new high-priority task that checks the liveness of all registered critical tasks and triggers a restart if any fail to respond.
-
π‘οΈ Added xTaskCreateSafe Macro for xTaskCreate:
- Improve automated task registration as critical task
- Avoid xTaskCreate to be used
- Disallow the usage of hooks inside xTaskCreateSafe (like jump or goto)
-
π Configurable Recovery Policy:
- Add support for secure Fallback flow with eFUSE instead only rebooting.
-
π Runtime Task Diagnostics:
- Report CPU load and uptime per task to console.
-
π Memory Safety Enhancements:
- Integration with ESP32 built-in watchdog.
- Detection of memory corruption.
- Usage of MISRA-C static analysis tool.
Clone the repo and add the freertos folder into your ESP-IDF projectβs components/ directory.
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "safety_wrappers.h" //SHOULDNT BE NEEDED ANYMORE. INCLUDED IN freertos/FreeRTOS.h
void vTaskA(void *pvParameters) {
// A TASK DECLARATIONS
while (1) {
// A TASK LOGIC
}
}
void vTaskB(void *pvParameters) {
// B TASK DECLARATIONS
while (1) {
// B TASK LOGIC
}
}
void app_main(void) {
TaskHandle_t taskHandle;
// DEFINE TASKS (LIMITED TO 31 TASKS)
xTaskCreateSafe(vTaskA, "TaskA", 2048, NULL, 5, &taskHandle);
xTaskCreateSafe(vTaskB, "TaskB", 2048, NULL, 5, &taskHandle);
// SAFETY MONITOR TASK
xTaskCreate(vSafetyMonitorTask, "SafetyMonitor", 2048, NULL, 10, NULL);
}