AVR SD Safety Framework 1.0.0
Loading...
Searching...
No Matches

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.

Detailed Description

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.

UML Class Diagrams

UML Sequence Diagrams

Function Documentation

◆ TM_Shutdown()

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.

Note

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.

Note

See SHUTDOWN_CRCSCAN to configure whether to perform a Flash integrity check before entering shutdown sleep.

Note

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.

Warning
This function is intended to be called right after completing a call to

TM_Scheduler in order to ensure Watchdog synchronization. This function assumes the Watchdog is in its open window when called.

Warning

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.

Warning
The Tasks called in this function have side effects and configurations documented in

T_InitSafeShutdown and T_EnterShutdownSleep.

Warning

This function will reset the device as part of normal execution.

Warning

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.

Parameters
appShutdownTaskCallback 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.
Warning

An invalid Task function pointer in appShutdownTask leads to undefined behavior.

Note
The Task in appShutdownTask is intended to be responsible for ensuring a well behaved transition into sleep for the application context. This can include responsibilities such as disabling internal or external systems to further reduce power consumption, messaging a different system to notify it about the sleep entry or enabling wake-up interrupt sources such as the Periodic Interrupt Timer (PIT) or an external pin interrupt. See SHUTDOWN_SAFE_STATE if the application requires driving any outputs from pins while in shutdown sleep.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TM_ShutdownRequestExit()

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.

Note
An exit can be requested at any time, but will only take effect after the system has transitioned into a Safe State before entering shutdown sleep. In this scenario, if

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.

Warning
If this function is called after the request flag has already been read in

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.

Warning
Calling this function while executing TM_Shutdown will lead to a device reset.

◆ TM_ShutdownRequestWatchdogs()

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.

Note
During shutdown sleep, both the WDT and SWDT are configured to not use windowed mode, so they can be cleared at any time before they expire. The WDT will time out after the configured

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.

Note

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.

Warning
If this function is called after the request flag has already been read in

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.