Reputation: 39
I've noticed that in the state transition diagram from [-1-]. Exists the possibility to switch from the blocked state to the suspended state employing vTaskSuspend()
. My question is, when could be that possible, in which situations this is useful?. Also, I want to notice that other authors do not cover this possibility as in the case from [-2,3-]. However, in CMSIS-RTOS2 [-4-] it does exist this same behaviour from blocked to Inactive/terminated state.
Here the diagrams:
[1,p.93]-> FreeRTOS Barry, Richard. 2016. Mastering The FreeRTOS Real Time Kernel. A Hands-on Tutorial Guide. avaliable in https://freertos.org/Documentation/RTOS_book.html
[2,p.352]-> Xiacong Xiacong, Fan. 2015. Real-Time Embedded Systems Design principles and Engineering Practices
[3,p.149]-> Qian Qian, Kai et al. 2009 Embedded Software development
[4]CMSIS-RTOS2 online available. https://www.keil.com/pack/doc/CMSIS/RTOS2/html/group__CMSIS__RTOS__ThreadMgmt.html
Upvotes: 2
Views: 1068
Reputation: 7057
In FreeRTOS, a suspended task will not be considered/eligible to run until it is explicitly resumed. Suspended tasks remain suspended indefinitely, whereas blocked tasks remain blocked until an event occurs or a timer expires. vTaskSuspend() takes the task handle as input so it's possible for the running task to suspend a different task, which could be blocked. (A task would have to be running in order to suspend itself.)
Here is one example use case for using suspend (there are probably many more use cases). Imagine a device which a user can switch between two modes, run or program. In run mode the device has a task that periodically performs a measurement. When the user switches to program mode the periodic measurement task is suspended. When the user switches to run mode the periodic measurement task gets resumed. The period that the device is in program mode is indefinite because it depends on the unpredictable user.
The Sleeping and Inactive/Terminated states in those other RTOS are not directly analogous to FreeRTOS's Suspended state. For 2 and 3, it looks like Sleeping means the task will become Ready when a timer expires. That behavior is combined into FreeRTOS's Blocked state. For 4, the Inactive/Terminated state requires the task to be recreated. That seems more analogous to FreeRTOSs vTaskDelete()/xTaskCreate(). The inactive/terminated/deleted state is simply not shown in the diagrams of the other RTOSs.
Upvotes: 2