How to identify and resolve the issue causing the task to miss its deadline?
@Middleware & OS
Hey guys In my FreeRTOS application, a specific task occasionally misses its deadline, causing system instability. I would like to know what tools or techniques I can use to monitor, profile, or adjust the priority of this task to identify the root cause and prevent these deadline misses from happening.
Here is the code for the task with the deadline misses:
void vTask1(void *pvParameters) {
for(;;) {
// Simulate work
vTaskDelay(pdMS_TO_TICKS(200));
}
}
here is how I created and started the tasks:
void main(void) {
xTaskCreate(vTask1, "Task 1", 1000, NULL, 1, NULL);
xTaskCreate(vTaskMonitor, "Task Monitor", 1000, NULL, 2, NULL);
vTaskStartScheduler();
}
Can anyone please provide guidance on how to identify and resolve the issue causing the task to miss its deadline?
4 Replies
Hi @Boss lady You can use an RTOS profiler to measure the execution time of each function within your task. This will help you analyze any code sections that are taking longer than expected and potentially causing delays.
you can monitor task execution time like you have already implemented a task vTaskMonitor to monitor the execution time. However, the implementation is not correct for deadline monitoring. Instead of using
xLastWakeTime you should use xTaskGetTickCount() to compare with the deadline.
@Boss lady
@Enthernet Code
Thanks I tried it out
void vTaskMonitor(void *pvParameters) {
TickType_t xLastDeadline = 0;
for (;;) {
vTaskDelay(pdMS_TO_TICKS(1000));
TickType_t xCurrentTime = xTaskGetTickCount();
if (xCurrentTime > xLastDeadline) {
printf("Task missed its deadline\n");
}
xLastDeadline = xCurrentTime + pdMS_TO_TICKS(1000);
}
}
what device are you using ?