![]() |
AVR SD Safety Framework 1.0.0
|
Contains API prototypes for the Shutdown Task Manager. More...
Files | |
| file | task_manager_shutdown.c |
| Implements APIs for the Shutdown Task Manager. | |
| file | task_manager_shutdown.h |
| Contains API prototypes for the Shutdown Task Manager. | |
Functions | |
| void | TM_ShutdownRequestWatchdogs (void) |
| Sets a request flag for the Shutdown Task Manager to clear both Watchdogs on the next shutdown cycle. | |
| void | TM_ShutdownRequestExit (void) |
| Sets a request flag for the Shutdown Task Manager to exit the shutdown sequence by issuing a device reset. | |
| void | TM_Shutdown (scheduleEntry_t appShutdownTask) |
| Manages Tasks that ensure safe execution of device sleeping in Standby or Power-Down mode. | |
Contains API prototypes for the Shutdown Task Manager.
The Shutdown Task Manager is responsible for executing the Shutdown sequence to safely enter, maintain and exit the Standby or Power-Down sleep modes.
| void TM_Shutdown | ( | scheduleEntry_t | appShutdownTask | ) |
Manages Tasks that ensure safe execution of device sleeping in Standby or Power-Down mode.
This function executes Tasks for completing a safe shutdown sequence in order for the system to reduce power consumption while the application is not active. It is intended to run after finishing the last application schedule.
To ensure a safe transition into either Standby or Power-Down sleep, the provided application-specific shutdown Task is called before transitioning into the Safe State by floating all I/O pins and re-configuring the Watchdogs to be easier to handle in sleep. Before entering the selected sleep mode, the Flash integrity can be verified by performing an optional CRCSCAN in Idle sleep. The device will remain in the sleep state until any interrupt occurs. In the application-specific interrupt handler(s), TM_ShutdownRequestWatchdogs can be called to request clearing the Watchdogs before re-entering sleep. Once an application-specific interrupt handler calls TM_ShutdownRequestExit, the Shutdown procedure will end by issuing a device reset.
In order to go into deep sleep modes, which disables most hardware safety mechanisms, it is recommended to enter a Safe State and reset the device afterwards in order to properly re-initialize the Safety Mechanisms and run startup diagnostics. This Task Manager ensures compliance with this recommendation and is thus designed to never return.
See SHUTDOWN_CRCSCAN to configure whether to perform a Flash integrity check before entering shutdown sleep.
The Shutdown Task Manager is designed to accommodate different wake-up and Watchdog configurations. See Tips and Tricks for information on using one or multiple periodic or asynchronous wake-up sources and Watchdog configurations.
TM_Scheduler in order to ensure Watchdog synchronization. This function assumes the Watchdog is in its open window when called.
In order to reconfigure a new Watchdog timeout and disable windowed mode, the Watchdog has to be cleared a final time while in the open window. The Synchronous Watchdog is used to facilitate correct timing by first ensuring a fixed execution time of the application-specific shutdown Task and then waiting DUR_UNTIL_SAFE_SHUTDOWN clock cycles before clearing it. An incorrect configuration will lead to a Watchdog reset.
T_InitSafeShutdown and T_EnterShutdownSleep.
This function will reset the device as part of normal execution.
The T_HandleNotificationErrors Task is not scheduled in this Task Manager because the application is considered inactive. As a result, all errors reported with NOTIFICATION criticality will remain unhandled during shutdown unless explicitly handled by the application.
| appShutdownTask | Callback to application-specific Shutdown Task with the expected duration in system clock cycles. Duration is limited to a 24-bit value. If the Task is set to a NULL pointer, it is skipped. |
An invalid Task function pointer in appShutdownTask leads to undefined behavior.
| void TM_ShutdownRequestExit | ( | void | ) |
Sets a request flag for the Shutdown Task Manager to exit the shutdown sequence by issuing a device reset.
This function is intended to be called inside an application-specific ISR to request that the system exits shutdown by restarting the device. This function does not reset the device directly; it only sets a flag which is read by TM_Shutdown. Once observed, the shutdown sequence ends by calling T_RestartDevice, which never returns.
SHUTDOWN_CRCSCAN is enabled, the CRCSCAN of the selected Flash sections will complete before the reset occurs. Once the shutdown loop is entered, the device will reset immediately once the request is detected. See Tips and Tricks for more information on exit timing with different wake-up configurations.
TM_Shutdown, the request will not take effect until the device wakes again. This potential race condition can occur if multiple wake-up sources are active and the ISR is invoked while the device is already awake. See Tips and Tricks for more information on how to mitigate this scenario.
| void TM_ShutdownRequestWatchdogs | ( | void | ) |
Sets a request flag for the Shutdown Task Manager to clear both Watchdogs on the next shutdown cycle.
This function is intended to be called inside an application-specific ISR to request that both the Watchdog (WDT) and Synchronous Watchdog (SWDT) are cleared after waking up from shutdown sleep in TM_Shutdown, before re-entering sleep. This function does not clear the Watchdogs directly; it only sets a flag which is read and cleared by TM_Shutdown, which then calls T_HandleShutdownWatchdogs.
SHUTDOWN_WDT_DURATION. The SWDT does not count in any sleep mode, but will resume counting each time the device wakes up. However, once the SWDT is enabled, it cannot be turned off. It is therefore set to the maximum non-window timeout of 0xFFFF. See Tips and Tricks for more information on how to manage the Watchdogs with different wake-up configurations.
If the WDT is disabled by setting SHUTDOWN_WDT_DURATION to WDT_TIMEOUT_OFF, calling T_HandleShutdownWatchdogs will still clear both Watchdogs, but the WDT clear will have no effect.
TM_Shutdown, the request will not take effect until the device wakes again. This potential race condition can occur if multiple wake-up sources are active and the ISR is invoked while the device is already awake.