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

Contains API prototypes for the Watchdog Manager. More...

Files

file  midware_watchdog_manager.c
 Implements APIs for the Watchdog Manager.
file  midware_watchdog_manager.h
 Contains API prototypes for the Watchdog Manager.
file  midware_watchdog_manager_asm.h
 Contains assembly API for the Watchdog Manager.
file  midware_watchdog_manager_diag.c
 Implements APIs for the Watchdog Manager diagnostics.
file  midware_watchdog_manager_diag.h
 Contains API prototypes for the Watchdog Manager diagnostics.

Macros

#define UINT24_MAX   0x00FFFFFFUL
 Defines max value for 24-bit registers.
#define UINT24_MAX   0x00FFFFFFUL
 Defines max value for 24-bit registers.

Enumerations

enum  wdtTimeout_t
 Defines available timeout configurations for the Watchdog Timer (WDT). More...

Functions

errFlag_t MW_GetSwdtPreclearError (void)
 Reads the error flag indicating a non-preclear command received while expecting a preclear command in the Synchronous Watchdog Timer (SWDT).
errFlag_t MW_GetSwdtClearError (void)
 Reads the error flag indicating a non-clear command received while expecting a clear command in the Synchronous Watchdog Timer (SWDT).
errFlag_t MW_GetSwdtUnexpectedCmdError (void)
 Reads the error flag indicating a clear command received in the closed window after a preclear command in the Synchronous Watchdog Timer (SWDT).
errFlag_t MW_GetSwdtCounterExpiredError (void)
 Reads the error flag indicating that the Synchronous Watchdog Timer (SWDT) counter expired.
void MW_ClearSwdtErrors (void)
 Clears all the error interrupt flags in the Synchronous Watchdog Timer (SWDT).
void MW_PreClearSwdt (void)
 Issues a PRECLEAR command to the Synchronous Watchdog Timer (SWDT).
errFlag_t MW_ClearSwdt (void)
 Issues a CLEAR command to the Synchronous Watchdog Timer (SWDT).
errFlag_t MW_SetSwdtResetValue (uint32_t resetVal)
 Sets the Synchronous Watchdog Timer (SWDT) countdown reset value.
errFlag_t MW_SetSwdtWindowValue (uint16_t window)
 Sets the Synchronous Watchdog Timer (SWDT) open window value.
void MW_EnableSwdtInterrupts (void)
 Enables all Synchronous Watchdog Timer (SWDT) error interrupts.
errFlag_t MW_EnableSwdt (bool useCcp, bool useLock, bool useInstrMode)
 Enables the Synchronous Watchdog Timer (SWDT) with the provided configurations.
void MW_ClearWdt (void)
 Clears the Watchdog Timer (WDT) by issuing a Watchdog Reset (WDR) instruction.
errFlag_t MW_SetWdtTimeout (wdtTimeout_t window, wdtTimeout_t period, bool useLock)
 Configures and enables the Watchdog Timer (WDT) in either Normal or Window mode.
void ASM_IssueWdrInstruction (void)
 Issues a Watchdog Reset instruction (WDR) to clear the WDT using assembly.
errFlag_t MW_DiagSwdtCount (void)
 Performs diagnostic to detect faults in the Synchronous Watchdog Timer (SWDT) Counter mechanism.
errFlag_t MW_DiagSwdtExpire (uint32_t newReset)
 Performs error injection diagnostic to detect faults in the Synchronous Watchdog Timer (SWDT) Expire mechanism.
void MW_DiagWdtCountBegin (void)
 Begins diagnostic to detect faults in the Watchdog Timer (WDT) Counter mechanism.
bool MW_IsDiagWdtCountOngoing (void)
 Checks whether the Watchdog Timer (WDT) Count diagnostic is ongoing.
errFlag_t MW_DiagWdtCountEnd (void)
 Completes diagnostic to detect faults in the Watchdog Timer (WDT) Counter mechanism.
errFlag_t MW_DiagWdtExpire (void)
 Performs error injection diagnostic to detect faults in the Watchdog Timer (WDT) Expire mechanism.

Detailed Description

Contains API prototypes for the Watchdog Manager.

The Watchdog Manager provides services to Tasks to ensure correct interaction with features of the WDT and SWDT peripherals.

UML Class Diagrams

UML Activity Diagrams

Macro Definition Documentation

◆ UINT24_MAX [1/2]

#define UINT24_MAX   0x00FFFFFFUL

Defines max value for 24-bit registers.

◆ UINT24_MAX [2/2]

#define UINT24_MAX   0x00FFFFFFUL

Defines max value for 24-bit registers.

Enumeration Type Documentation

◆ wdtTimeout_t

Defines available timeout configurations for the Watchdog Timer (WDT).

Note
The WDT clock source frequency variation should be accounted for when configuring the WDT timeout.
Enumerator
WDT_TIMEOUT_OFF 

Off

WDT_TIMEOUT_CLK8 

8 WDT clock cycles

WDT_TIMEOUT_CLK16 

16 WDT clock cycles

WDT_TIMEOUT_CLK32 

32 WDT clock cycles

WDT_TIMEOUT_CLK64 

64 WDT clock cycles

WDT_TIMEOUT_CLK128 

128 WDT clock cycles

WDT_TIMEOUT_CLK256 

256 WDT clock cycles

WDT_TIMEOUT_CLK512 

512 WDT clock cycles

WDT_TIMEOUT_CLK1K 

1024 WDT clock cycles

WDT_TIMEOUT_CLK2K 

2048 WDT clock cycles

WDT_TIMEOUT_CLK4K 

4096 WDT clock cycles

WDT_TIMEOUT_CLK8K 

8192 WDT clock cycles

WDT_TIMEOUT_MAX 

Reserved/invalid, used as sentinel value for WDT timeout.

Function Documentation

◆ ASM_IssueWdrInstruction()

void ASM_IssueWdrInstruction ( void )

Issues a Watchdog Reset instruction (WDR) to clear the WDT using assembly.

Here is the caller graph for this function:

◆ MW_ClearSwdt()

errFlag_t MW_ClearSwdt ( void )

Issues a CLEAR command to the Synchronous Watchdog Timer (SWDT).

This function waits until the SWDT is ready to receive a CLEAR command using polling. A PRECLEAR command should be issued by calling MW_PreClearSwdt before this function is called to ensure the correct clear sequence.

Warning

The function busy waits until the CLEAR-ready bit in the INTFLAGS register is set. It is assumed that the PRECLEAR command was sent first. Otherwise, the CLEAR-ready bit will not be set and the SWDT will eventually expire. If the SWDT expires while waiting, or it has expired before calling this function, waiting is aborted and an error is returned.

Return values
ERRORSWDT already expired or expired while waiting for the CLEAR-ready bit.
NO_ERRORCLEAR command issued after exiting the closed window.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MW_ClearSwdtErrors()

void MW_ClearSwdtErrors ( void )

Clears all the error interrupt flags in the Synchronous Watchdog Timer (SWDT).

This function clears all SWDT interrupt flags. Use MW_GetSwdtPreclearError, MW_GetSwdtClearError, MW_GetSwdtUnexpectedCmdError and MW_GetSwdtCounterExpiredError to read the error flags before they are cleared simultaneously in this function.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MW_ClearWdt()

void MW_ClearWdt ( void )

Clears the Watchdog Timer (WDT) by issuing a Watchdog Reset (WDR) instruction.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MW_DiagSwdtCount()

errFlag_t MW_DiagSwdtCount ( void )

Performs diagnostic to detect faults in the Synchronous Watchdog Timer (SWDT) Counter mechanism.

This function reads and compares two samples of the SWDT counter. If the sampled counter values are different, the counter is counting and the diagnostic returns no error.

Note

This diagnostic will not necessarily detect stuck bits in the register, just whether the least significant byte of the counter register is updated as expected.

Return values
ERRORFault detected in SWDT count functionality.
NO_ERRORNo fault detected in SWDT count functionality.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MW_DiagSwdtExpire()

errFlag_t MW_DiagSwdtExpire ( uint32_t newReset)

Performs error injection diagnostic to detect faults in the Synchronous Watchdog Timer (SWDT) Expire mechanism.

This function performs a diagnostic of the SWDT Expire mechanism by starting an error injection and observing the response. The error injection makes the countdown skip to zero, which normally triggers the expire error mechanism. If an expire error is reported, the diagnostic returns no error.

Warning

After completing the diagnostic, the SWDT will remain enabled even if it was previously disabled and begins a countdown from the specified 24-bit new reset value right after the injection. If the SWDT is already enabled, the new reset can be set to the current SWDT count when calling the diagnostic, minus a small delta that accounts for the time until the new reset is loaded, effectively restoring the count value and minimizing the impact of the error injection.

Warning

If the SWDT register lock feature is enabled, the new reset value cannot be loaded and the diagnostic is aborted.

Note

Error injection will not be initiated if an invalid new reset value is used.

Note

Error injection will not be initiated if the Error Controller is not in NORMAL state or the SWDT error channel is already set.

Note

This function disables global interrupts during its execution to ensure atomic execution and that accidental interrupts are not triggered by initiating the error injection.

Parameters
newResetThe 24-bit reset value to be loaded after completing the error injection. The value needs to be larger than zero.
Return values
ERRORFault detected in the SWDT expire mechanism, provided reset value is invalid or SWDT is locked, or error injection did not start.
NO_ERRORNo fault detected in the SWDT expire mechanism.
Here is the call graph for this function:

◆ MW_DiagWdtCountBegin()

void MW_DiagWdtCountBegin ( void )

Begins diagnostic to detect faults in the Watchdog Timer (WDT) Counter mechanism.

This function reads and stores the current counter register value of the WDT for later comparison. If the counter register value has not changed when calling MW_DiagWdtCountEnd(), the diagnostic will report an error. After calling this function, MW_IsDiagWdtCountOngoing will return true until MW_DiagWdtCountEnd() is called.

Note

The WDT runs on the internal OSC32K clock source, which is significantly slower than the typical main clock frequency. Since it counts asynchronously to the main clock, it takes up to 4 WDT clock cycles for the readable counter register to update to a new value. For this reason, begin and end diagnostic APIs are provided to avoid busy-waiting for the count to update.

Warning
It is the responsibility of the calling function to ensure sufficient time separation of at least 4 WDT clock cycles between starting and completing the diagnostic. It is recommended to account for clock source frequency variations.
Here is the call graph for this function:

◆ MW_DiagWdtCountEnd()

errFlag_t MW_DiagWdtCountEnd ( void )

Completes diagnostic to detect faults in the Watchdog Timer (WDT) Counter mechanism.

This function reads and stores the current counter register value of the WDT and compares it to the previous sample stored when calling MW_DiagWdtCountBegin. If the two samples are identical, it indicates that the WDT counter is stuck and the diagnostic returns an error. If the diagnostic was not started by calling MW_DiagWdtCountBegin, the diagnostic will automatically fail. It is recommended to call MW_IsDiagWdtCountOngoing to check this before calling this function.

Note

The WDT runs on the internal OSC32K clock source, which is significantly slower than the typical main clock frequency. Since it counts asynchronously to the main clock, it takes up to 4 WDT clock cycles for the readable counter register to update to a new value. For this reason, begin and end diagnostic APIs are provided to avoid busy-waiting for the count to update.

Warning

It is the responsibility of the calling function to ensure sufficient time separation of at least 4 WDT clock cycles between starting and completing the diagnostic. It is recommended to account for clock source frequency variations.

Note

Global interrupts are disabled during the diagnostic, and restored before returning the result.

Return values
ERRORWDT Counter is stuck or diagnostic was not started.
NO_ERRORWDT Counter is not stuck.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MW_DiagWdtExpire()

errFlag_t MW_DiagWdtExpire ( void )

Performs error injection diagnostic to detect faults in the Watchdog Timer (WDT) Expire mechanism.

This function performs a diagnostic of the WDT Expire reset mechanism by setting the watchdog timeout period to the lowest possible value and waiting for it to expire and reset the device. If the WDT expire reset was not successful, an error is returned.

Warning

The diagnostics assumes that the WDT is not enabled (either through fuses or otherwise) when called, and will enable the WDT during execution. If already enabled, a false ERROR may be reported.

Warning

After a successful diagnosis, the device is reset. It is the responsibility of the calling function to determine the result of the diagnostic by reading the WDRF flag in the reset controller and the CAUSE bit in the WDT STATUS register.

Warning

This diagnostic reads the WDT counter register to determine if the count has passed the configured expire threshold of 8 WDT Clock cycles before returning. Should the counter register be stuck, the diagnostic will never return. For this reason, it is recommended that the Synchronous Watchdog Timer (SWDT) is enabled during execution, which should expire in this scenario and ultimately reset the device through the Error Controller (ERRCTRL).

Return values
ERRORFault detected in the WDT expire mechanism.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MW_EnableSwdt()

errFlag_t MW_EnableSwdt ( bool useCcp,
bool useLock,
bool useInstrMode )

Enables the Synchronous Watchdog Timer (SWDT) with the provided configurations.

Warning

MW_SetSwdtResetValue and MW_SetSwdtWindowValue must be called to set the Reset and Window values before enabling the SWDT to ensure correct operation.

Note

Once the SWDT is enabled, it can only be disabled by a device reset.

Parameters
useCcpEnable Configuration Change Protection for all SWDT registers
useLockEnable locking of certain SWDT registers, preventing modification of the Reset and Window values, performing error injection and enabling/disabling error interrupts.
useInstrModeEnable counting executed CPU instructions instead of number of main clock cycles.
Return values
ERRORSWDT is already locked and cannot be configured properly, SWDT is not enabled.
NO_ERRORSWDT enabled successfully.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MW_EnableSwdtInterrupts()

void MW_EnableSwdtInterrupts ( void )

Enables all Synchronous Watchdog Timer (SWDT) error interrupts.

Warning
This function has no effect if the SWDT register lock feature is enabled.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MW_GetSwdtClearError()

errFlag_t MW_GetSwdtClearError ( void )

Reads the error flag indicating a non-clear command received while expecting a clear command in the Synchronous Watchdog Timer (SWDT).

Note

The flag is cleared by calling MW_ClearSwdtErrors.

Return values
ERRORBad clear error flag is set.
NO_ERRORBad clear error flag is not set.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MW_GetSwdtCounterExpiredError()

errFlag_t MW_GetSwdtCounterExpiredError ( void )

Reads the error flag indicating that the Synchronous Watchdog Timer (SWDT) counter expired.

Note

The flag is cleared by calling MW_ClearSwdtErrors.

Return values
ERRORCounter expired error flag is set.
NO_ERRORCounter expired error flag is not set.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MW_GetSwdtPreclearError()

errFlag_t MW_GetSwdtPreclearError ( void )

Reads the error flag indicating a non-preclear command received while expecting a preclear command in the Synchronous Watchdog Timer (SWDT).

Note

The flag is cleared by calling MW_ClearSwdtErrors.

Return values
ERRORBad preclear error flag is set.
NO_ERRORBad preclear error flag is not set.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MW_GetSwdtUnexpectedCmdError()

errFlag_t MW_GetSwdtUnexpectedCmdError ( void )

Reads the error flag indicating a clear command received in the closed window after a preclear command in the Synchronous Watchdog Timer (SWDT).

Note

The flag is cleared by calling MW_ClearSwdtErrors.

Return values
ERRORUnexpected command error flag is set.
NO_ERRORUnexpected command flag is not set.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MW_IsDiagWdtCountOngoing()

bool MW_IsDiagWdtCountOngoing ( void )

Checks whether the Watchdog Timer (WDT) Count diagnostic is ongoing.

This function returns true if MW_DiagWdtCountBegin was called and MW_DiagWdtCountEnd has not yet been called, and false otherwise. It does not check whether sufficiently long time has passed to complete the diagnostic, just that it has been started.

Return values
trueWDT Count diagnostic is ongoing.
falseWDT Count diagnostic is not ongoing.

◆ MW_PreClearSwdt()

void MW_PreClearSwdt ( void )

Issues a PRECLEAR command to the Synchronous Watchdog Timer (SWDT).

Note

A PRECLEAR command must be sent before a CLEAR command to avoid hardware reporting a bad preclear error.

Warning
It is assumed that the PRECLEAR command can be received. If the PRECLEAR-ready bit in the INTFLAGS register is not set, the hardware error is reported.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MW_SetSwdtResetValue()

errFlag_t MW_SetSwdtResetValue ( uint32_t resetVal)

Sets the Synchronous Watchdog Timer (SWDT) countdown reset value.

This function sets the 24-bit reset value that is loaded into the countdown register after each SWDT clear.

Note

The watchdog can only be cleared in the open window, see MW_SetSwdtWindowValue.

Parameters
resetValThe 24-bit reset value to be set which has to be larger than zero.
Return values
ERRORProvided reset value is invalid or SWDT is locked, reset value not set.
NO_ERRORProvided reset value successfully set.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MW_SetSwdtWindowValue()

errFlag_t MW_SetSwdtWindowValue ( uint16_t window)

Sets the Synchronous Watchdog Timer (SWDT) open window value.

This function sets the 16-bit open window value for the SWDT. The SWDT counts down from the configured reset value (see MW_SetSwdtResetValue). While the countdown register value is above the configured window value, the SWDT is in the closed window and a CLEAR command is not accepted. Once the countdown register value reaches the configured window value, the SWDT is in the open window and a CLEAR command can be received after a PRECLEAR command (see MW_PreClearSwdt and MW_ClearSwdt).

Parameters
windowThe 16-bit open window value to be set.
Return values
ERRORProvided window value is set to 0 or SWDT is locked, window value not set.
NO_ERRORProvided window value successfully set.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MW_SetWdtTimeout()

errFlag_t MW_SetWdtTimeout ( wdtTimeout_t window,
wdtTimeout_t period,
bool useLock )

Configures and enables the Watchdog Timer (WDT) in either Normal or Window mode.

This function enables the WDT by writing the provided window and period values. If the WDT is already enabled, the new values are applied after the next WDT clear. The provided values select either Normal mode, where the WDT can be cleared at any time before it expires, or Window mode (WWDT), where the WDT can only be cleared within the open window. In Window mode, the sum of the window and period values defines the total timeout duration.

Warning

If enabled, Window mode is only activated after the first WDR instruction is issued, regardless of whether the WDT was initially enabled or not (see MW_ClearWdt).

Warning

If the WDT configuration registers are locked, this function aborts and returns an error. When useLock is enabled, the configuration registers are locked after the write. Setting the period and window values through user fuses automatically enables the register lock feature.

Warning

After writing the window and period values, the WDT synchronizes the configuration to the WDT clock domain. Calling this function while synchronization is in progress aborts and returns an error. The caller is expected to avoid requesting WDT reconfiguration more frequently than the hardware can synchronize configuration updates.

Parameters
windowClosed window duration in Window mode. Set to WDT_TIMEOUT_OFF to select Normal mode.
periodOpen window duration in Window mode. Timeout duration in Normal mode.
useLockEnable locking of the WDT configuration registers, preventing further modification of the WDT configuration except through a device reset.
Return values
ERRORThe WDT is locked, busy synchronizing, or the provided window or period value is invalid, configuration values not written.
NO_ERRORConfiguration values written successfully.
Here is the call graph for this function:
Here is the caller graph for this function: