![]() |
Synergy Software Package User's Manual
|
The WDT (Watchdog Timer) HAL module provides a high-level API for critical timing applications and uses the WDT peripheral on the Synergy MCU. A user-defined callback can be created to respond to event notifications.
The WDT HAL module has the following key features:
The following hardware features are, or are not, supported by SSP for WDT:
Legend:
| Symbol | Meaning |
|---|---|
| ✓ | Available (Tested) |
| ⌧ | Not Available (Not tested/not functional or both) |
| N/A | Not supported by MCU |
| MCU Group | Clock Divide by 4, 64, 128, 512, 2,048, or 8,192 | Count down | Register start mode | Auto start mode | Reset output | Interrupt request output |
|---|---|---|---|---|---|---|
| S124 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| S128 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| S1JA | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| S3A1 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| S3A3 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| S3A6 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| S3A7 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| S5D3 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| S5D5 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| S5D9 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| S7G2 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| MCU Group | Sleep mode count stop control output | Event link function through ELC HAL driver | Window function | Conditions for stopping the Counter – reset/under flow refresh error | Refresh error and under flow error detect | Reading the counter value |
|---|---|---|---|---|---|---|
| S124 | ⌧ | ⌧ | ✓ | ✓ | ✓ | ✓ |
| S128 | ⌧ | ⌧ | ✓ | ✓ | ✓ | ✓ |
| S1JA | ⌧ | ⌧ | ✓ | ✓ | ✓ | ✓ |
| S3A1 | ⌧ | ⌧ | ✓ | ✓ | ✓ | ✓ |
| S3A3 | ⌧ | ⌧ | ✓ | ✓ | ✓ | ✓ |
| S3A6 | ⌧ | ⌧ | ✓ | ✓ | ✓ | ✓ |
| S3A7 | ⌧ | ⌧ | ✓ | ✓ | ✓ | ✓ |
| S5D3 | ⌧ | ⌧ | ✓ | ✓ | ✓ | ✓ |
| S5D5 | ⌧ | ⌧ | ✓ | ✓ | ✓ | ✓ |
| S5D9 | ⌧ | ⌧ | ✓ | ✓ | ✓ | ✓ |
| S7G2 | ⌧ | ⌧ | ✓ | ✓ | ✓ | ✓ |
The WDT HAL module defines APIs for opening, refreshing, reading and getting status. A complete list of the available APIs, an example API call and a short description of each can be found in the following table. A table of status return values follows the API summary table.
Watchdog Timer HAL Module API Summary
| Function Name | Example API Call and Description |
|---|---|
| cfgGet | g_wdt0.p_api->cfgGet(g_wdt0.p_ctrl, g_wdt0.p_cfg);Initialize the WDT in register start mode. In auto-start mode with NMI output it registers the NMI callback. |
| open | g_wdt0.p_api->open(g_wdt0.p_ctrl, g_wdt0.p_cfg);Initialize the WDT in register start mode. In auto-start mode with NMI output it registers the NMI callback. |
| refresh | g_wdt0.p_api->refresh(g_wdt0.p_ctrl);Refresh the watchdog timer. |
| statusGet | g_wdt0.p_api->statusGet( g_wdt0.p_ctrl, &status);Read the status of the WDT. |
| statusClear | g_wdt0.p_api->statusClear( g_wdt0.p_ctrl, clear);Clear the status flags of the WDT. |
| counterGet | g_wdt0.p_api->counterGet(g_wdt0.p_ctrl, &counter);Read the current WDT counter value. |
| timeoutGet | g_wdt0.p_api->timeoutGet(g_wdt0.p_ctrl, &timeout);Read the watchdog timeout values. |
| versionGet | g_wdt0.p_api->versionGet(&version);Retrieve the API version using the version pointer. |
Status Return Values
| Name | Description |
|---|---|
| SSP_SUCCESS | Function successfully executed. |
| SSP_ERR_ASSERTION | Null Pointer(s). |
| SSP_ERR_INVALID_ARGUMENT | One or more configuration options is invalid. |
| SSP_ERR_INVALID_MODE | An attempt to open the WDT in register-start mode when the OFS0 register is configured for auto-start mode. Or to open the WDT in auto-start mode when the OSF0 is configured for register start mode. |
| SSP_ERR_ABORTED | Invalid clock divider for this watchdog |
Synergy MCUs have two watchdog peripherals- the watchdog timer (WDT) and the independent watchdog timer (IWDT). When selecting between them, consider these factors:
The WDT HAL module configures the WDT Interface. When the WDT underflows or is refreshed outside of the permitted refresh window, one of the following events can occur:
The following figure shows an example of the operation of the WDT. When refreshed in the valid refresh period of the counter the timer count value is reset. If the count is allowed to underflow or refresh occurs outside of the valid refresh period, the WDT resets the device or generates an NMI.
The WDT can be configured in register start mode through the WDT registers. The WDT can also be configured by hardware automatically after reset using parameters stored in Option Function Select Register 0 (OFS0) as displayed in the following table.
All series of Synergy microcontrollers have an option-setting Memory which can be used to set the operating state of peripherals after a reset. The OFS can be used to set the state of the IWDT, WDT, LVD and CGC HOCO.
The following table details which parameters of the IWDT can be configured by the OFS registers.
| Control | Description |
|---|---|
| IWDT Start Mode Select | Automatically starts the IWDT after a Reset, if enabled. |
| IWDT Timeout Period | Specifies the IWDT timeout (number of clock cycles) 128 cycles 512 cycles 1024 cycles 2048 cycles |
| IWDT-Dedicated Clock Frequency Division Ratio | 1 1/16 1/32 1/64 1/128 1/256 |
| IWDT Window End Position | 25% 50% 75% 100% (no window end position set) |
| IWDT Window Start Position | 25% 50% 75% 100% (no window start position set) |
| IWDT Reset Interrupt Request | The IWDT can either generate an Interrupt Signal or a Reset signal. |
| IWDT Stop Control | The IWDT can continue to count or Stop counting in Low Power Mode. |
The OFS register values are set via the properties dialog of the BSP tab of Synergy Configuration editor as shown in the figures below.
WDT HAL Module Period Calculation
The WDT operates from PCLKB. Assuming largest parameters for the WDT and a PCLKB of 60 MHz, the time from the last refresh to device reset or NMI generation will be just over 2.2 seconds as detailed below.
PLCKB = 60 MHz
Clock division ratio = PCLKB/8192
Timeout period = 16384 cycles
WDT clock frequency = 60 MHz / 8192 = 7.324 kHz
Cycle time = 1 / 7.324 kHz = 136.53 us
Timeout = 136.53 us x 16384 cycles = 2.23 seconds
Triggering DMAC/DTC with the WDT HAL Module
To trigger a transfer of data using the DMAC or DTC peripheral when the WDT counter underflows or when a refresh is attempted outside of the valid refresh period, configure the WDT to generate an NMI and configure the DMAC/DTC transfer with activation_source set to ELC_EVENT_WDT_UNDERFLOW. See the associated User Guide (DMAC, DTC) for further information.
Triggering Event Link Controller Events with the WDT HAL Module
The WDT can trigger the start of another peripheral using the Event Link Controller (ELC). Refer to the ELC User Guide for a complete list of available peripherals.
This section describes how to include the Watchdog Timer HAL Module in an application using the SSP configurator.
To add the Watchdog Timer Driver to an application, simply add it to a thread using the stacks selection sequence given in the following table. (The default name for the Watchdog Timer Driver is g_wdt0. This name can be changed in the associated Properties window.)
Watchdog Timer HAL Module Selection Sequence
| Resource | ISDE Tab | Stacks Selection Sequence |
|---|---|---|
| g_wdt0 Watchdog Driver on r_wdt | Threads | New Stack>Driver> Monitoring> Watchdog Driver on r_wdt |
When the Watchdog Timer Driver on r_wdt is added to the thread stack as shown in the following figure, the configurator automatically adds any needed lower‑level modules. Any modules needing additional configuration information have the box text highlighted in Red. Modules with a Gray band are individual modules that stand alone. Modules with a Blue band are shared or common; they need only be added once and can be used by multiple stacks. Modules with a Pink band can require the selection of lower-level modules; these are either optional or recommended. (This is indicated in the block with the inclusion of this text.) If the addition of lower-level modules is required, the module description include Add in the text. Clicking on any Pink banded modules brings up the New icon and displays possible choices.
The Watchdog Timer HAL Module must be configured by the user for the desired operation. The available configuration settings and defaults for all the user-accessible properties are given in the properties tab within the SSP configurator and are shown in the following tables for easy reference. Only properties that can be changed without causing conflicts are available for modification. Other properties are locked and not available for changes and are identified with a lock icon for the locked property in the Properties window in the ISDE. This approach simplifies the configuration process and makes it much less error-prone than previous manual approaches to configuration. The available configuration settings and defaults for all the user-accessible properties are given in the Properties tab within the SSP Configurator and are shown in the following tables for easy reference.
Configuration Settings for the Watchdog Timer HAL Module on r_wdt
| ISDE Property | Value | Description |
|---|---|---|
| Parameter Checking | BSP, Enabled, Disabled Default: BSP | Enables or disables the parameter checking. |
| Name | g_wdt0 | Module name. |
| Start Mode | Register, Auto Default: Register | Configures the start mode as register start or auto-start. |
| Start Watchdog After Configuration | True, False Default: True | Controls whether WDT is started during initialization. |
| Timeout | 1024 cycles, 4096 cycles, 8192 cycles, 16384 cycles Default: 16384 cycles | WDT timeout period. |
| Clock Division Ratio | PCLK/4, PCLK/64, PCLK/128, PCLK/512, PCLK/2048, PCLK/8192 Default: PCLK/8192 | WDT clock divider. |
| Window Start Position | 100% (Window Position Not Specified), 75%, 50%, 25% Default: 100% (Window Position Not Specified) | Permitted refresh period start postion. |
| Window End Position | 0% (Window Position Not Specified), 25%, 50%, 75% Default: 0% (Window Position Not Specified) | Permitted refresh period end postion. |
| Reset Control | Reset Outpout, NMI Generated Default: Reset Output | Select whether WDT should reset the MCU or generate an NMI. |
| Stop Control | WDT Count Enabled in Low Power Mode, WDT Count Disabled in Low Power Mode Default: WDT Count Disabled in Low Power Mode | Select whether the WDT should stop counting in low power modes. |
| NMI Callback | NULL | Callback. A user callback function can be registered in open. If this callback function is provided, it will be called from the interrupt service routine (ISR) each time the IRQn triggers. Warning: Since the callback is called from an ISR, care should be taken not to use blocking calls or lengthy processing. Spending excessive time in an ISR can affect the responsiveness of the system. |
All series of Synergy microcontrollers have an Option-Setting Memory which can be used to set the operating state of peripherals after a reset. The OFS can be used to set the state of the IWDT, WDT, LVD and CGC HOCO. See the description in the operational overview section earlier in this document.
Configure the WDT interrupts in the same way as configuring the other options for the WDT module. If the WDT is configured to generate an NMI interrupt on underflow or invalid refresh, the interrupt must be enabled in the BSP.
To enable interrupts, set the priority of the CWDT> CWDT NMIUNDF N n. This sets BSP_IRQ_CFG_WDT_UNDERFLOW in ssp_cfg/bsp/bsp_irq_cfg.h to the priority level selected.
When the CWDT NMIUNDF N interrupt is enabled in the BSP, the corresponding ISR will be defined. The ISR will call a user callback function if one was registered in the wdt_api_t::open API.
The WDT clock is based on the PCLKB frequency. You can set the PCLKB frequency using the clock configurator in the ISDE or using the CGC Interface at run-time. The maximum timeout period with PCLKB running at 60 MHz is approximately 2.2 seconds.
The WDT does not require pins for its operation.
The typical steps in using the Watchdog Timer HAL module in an application are:
These common steps are illustrated in a typical operational flow diagram in the following figure: