The watchdog unit (WDT) improves the system integrity, by triggering the system reset request to bring the system back from the unresponsive state to normal operation.
This LLD provides the Configuration structure XMC_WDT_CONFIG_t and initialization function XMC_WDT_Init().
It can be used to:
- Start or Stop the watchdog timer. (XMC_WDT_Start() and XMC_WDT_Stop())
- Service the watchdog timer. (XMC_WDT_Service())
- Configure the service window upper bound and lower bound timing values. (XMC_WDT_SetWindowBounds())
- Enable the generation of the pre-warning event for the first overflow of the timer. (XMC_WDT_SetMode())
- Clear the pre-warning alarm event. It is mandatory to clear the flag during pre-warning alarm ISR, to stop generating reset request for the second overflow of the timer. (XMC_WDT_ClearAlarm())
- Suspend the watchdog timer during Debug HALT mode. (XMC_WDT_SetDebugMode())
- Configure service indication pulse width.(XMC_WDT_SetServicePulseWidth())
Defines debug behaviour of watchdog when the CPU enters HALT mode. Use type XMC_WDT_DEBUG_MODE_t for this enum.
Enumerator |
---|
XMC_WDT_DEBUG_MODE_STOP |
Watchdog counter is paused during debug halt.
|
XMC_WDT_DEBUG_MODE_RUN |
Watchdog counter is not paused during debug halt.
|
Defines working modes for watchdog. Use type XMC_WDT_MODE_t for this enum.
Enumerator |
---|
XMC_WDT_MODE_TIMEOUT |
Generates reset request as soon as the timer overflow occurs.
|
XMC_WDT_MODE_PREWARNING |
Generates an alarm event for the first overflow. And reset request after subsequent overflow, if not serviced after first overflow.
|
void XMC_WDT_ClearAlarm |
( |
void |
| ) |
|
- Parameters
-
- Returns
- None
- Description:
- Clears pre-warning alarm by setting ALMC bit in WDTCLR register.
- In pre-warning mode, first overflow of the timer upper window bound fires the pre-warning alarm. XMC_WDT_ClearAlarm() must be invoked to clear the alarm alarm. After clearing of the alarm, watchdog timer must be serviced within valid time window. Otherwise watchdog timer triggers the reset request up on crossing the upper bound value in a subsequent cycle.
- Related APIs:
- XMC_WDT_Service(), XMC_WDT_SetMode()
void XMC_WDT_Disable |
( |
void |
| ) |
|
- Parameters
-
- Returns
- None
- Description:
- Disables the clock and resets watchdog timer.
- Note:
- Resets the registers with default values. So XMC_WDT_Init() has to be invoked again to configure the watchdog.
- Related APIs:
- XMC_WDT_Enable()
void XMC_WDT_Enable |
( |
void |
| ) |
|
- Parameters
-
- Returns
- None
- Description:
- Enables watchdog clock and releases watchdog reset.
- This API is invoked by XMC_WDT_Init() and therefore no need to call it explicitly during watchdog initialization sequence. Invoke this API to enable watchdog once again if the watchdog is disabled by invoking XMC_WDT_Disable().
- Note:
- It is required to configure the watchdog, again after invoking XMC_WDT_Disable(). Since all the registers are reset with default values.
- Related APIs:
- XMC_WDT_Init(), XMC_WDT_Disable()
uint32_t XMC_WDT_GetCounter |
( |
void |
| ) |
|
- Parameters
-
- Returns
- uint32_t Current count value of watchdog timer register (TIM). Range: [0H to FFFFFFFFH]
- Description:
- Reads current count of timer register (TIM).
- Invoke this API before servicing or feeding the watchdog to check whether count is between lower and upper window bounds.
- Related APIs:
- XMC_WDT_Service()
- Parameters
-
config | pointer to a constant watchdog configuration data structure. Refer data structure XMC_WDT_CONFIG_t for detail. |
- Returns
- None
- Description:
- Initializes and configures watchdog with configuration data pointed by config.
- It invokes XMC_WDT_Enable() to enable clock and release reset. Then configures the lower and upper window bounds, working mode (timeout/pre-warning), debug behaviour and service request indication pulse width.
- Note:
- With out invoking this XMC_WDT_Init() or XMC_WDT_Enable(), invocation of other APIs like XMC_WDT_SetWindowBounds(), XMC_WDT_SetMode(), XMC_WDT_SetServicePulseWidth(), XMC_WDT_SetDebugMode(), XMC_WDT_Start(), XMC_WDT_GetCounter(), XMC_WDT_Service(), XMC_WDT_ClearAlarm() has no affect.
void XMC_WDT_Service |
( |
void |
| ) |
|
- Parameters
-
- Returns
- None
- Description:
- Services or feeds the watchdog by writing the Magic word in SRV register.
- Service watchdog when count value of watchdog timer is between lower and upper window bounds. Successful servicing will reset watchdog timer (TIM register) to 0H and generate service indication pulse.
- Note:
- invoking this API when count value of watchdog timer is less than window lower bound results wrong servicing and immediately triggers reset request.
- Related APIs:
- XMC_WDT_GetCounter(), XMC_WDT_SetWindowBounds(), XMC_WDT_SetServicePulseWidth()
- Parameters
-
debug_mode | running state of watchdog during debug halt mode. Refer XMC_WDT_DEBUG_MODE_t for valid values. |
- Returns
- None
- Description:
- Sets debug behaviour of watchdog by modifying DSP bit of CTR register.
- Depending upon DSP bit, the watchdog timer stops when CPU is in HALT mode. The debug behaviour is initially set as XMC_WDT_DEBUG_MODE_STOP during initialization in XMC_WDT_Init(). Invoke this API to change the debug behaviour as needed later in the program.
- Parameters
-
mode | is one of the working modes of the watchdog timer, i.e timeout or pre-warning. Refer XMC_WDT_MODE_t for valid values. |
- Returns
- None
- Description:
- Sets watchdog working mode (timeout or pre-warning) by updating PRE bit of CTR register.
- The working mode is set during initialization in XMC_WDT_Init(). Invoke this API to alter the mode as needed later in the program.
void XMC_WDT_SetServicePulseWidth |
( |
uint8_t |
service_pulse_width | ) |
|
- Parameters
-
service_pulse_width | specifies Service indication pulse width in terms of fwdt. Range: [0H – FFH]. |
- Returns
- None
- Description:
- Sets service indication pulse width by updating SPW bit field of CTR register.
- The service indication pulse (with width service_pulse_width + 1 in fwdt cycles) is generated on successful servicing or feeding of watchdog. The pulse width is initially set during initialization in XMC_WDT_Init(). Invoke this API to alter the width as needed later in the program.
void XMC_WDT_SetWindowBounds |
( |
uint32_t |
lower_bound, |
|
|
uint32_t |
upper_bound |
|
) |
| |
- Parameters
-
lower_bound | specifies watchdog window lower bound in terms of watchdog clock (fWDT) cycles. Range: [0H to FFFFFFFFH]. |
upper_bound | specifies watchdog window upper bound in terms of watchdog clock (fWDT) cycles. Range: [0H to FFFFFFFFH]. |
- Returns
- None
- Description:
- Sets watchdog window lower and upper bounds by updating WLB and WUB registers.
- Window lower and upper bounds are set during initialization in XMC_WDT_Init(). Invoke this API to alter the values as needed later in the program. This upper bound and lower bound can be calculated by using the below formula
upper_bound or lower_bound = desired_boundary_time(sec) * fwdt(hz)
- Note:
- Always ensure that upper_bound is greater than the lower_bound value. If not, whenever timer crosses the upper_bound value it triggers the reset(wdt_rst_req) of the controller.
void XMC_WDT_Start |
( |
void |
| ) |
|
- Parameters
-
- Returns
- None
- Description:
- Start the watchdog timer by setting ENB bit of CTR register.
- Invoke this API to start the watchdog after initialization, or to resume the watchdog when paused by invoking XMC_WDT_Stop().
- Related APIs:
- XMC_WDT_Init(), XMC_WDT_Stop()
void XMC_WDT_Stop |
( |
void |
| ) |
|
- Parameters
-
- Returns
- None
- Description:
- Pauses watchdog timer by resetting ENB bit of CTR register.
- Invoke this API to pause the watchdog as needed in the program e.g. debugging through software control.
- Related APIs:
- XMC_WDT_Init(), XMC_WDT_Stop()