Detailed Description

Watchdog Timer Peripheral Driver.

How to use the WDOG driver in your application

In order to be able to use the Watchdog in your application, the first thing to do is initializing it with the desired configuration. This is done by calling the WDOG_DRV_Init function. One of the arguments passed to this function is the configuration which will be used for the Watchdog, specified by the wdog_user_config_t structure.

The wdog_user_config_t structure allows you to configure the following:

Please note that if the updates are disabled the Watchdog cannot be later modified without forcing a reset (this implies that further calls of the WDOG_DRV_Init, WDOG_DRV_Deinit or WDOG_DRV_SetInt functions will lead to a reset).

As mentioned before, a timeout interrupt may be enabled by specifying it at the module initialization. The WDOG_DRV_Init only allows enabling/disabling the interrupt, and it does not set up the ISR to be used for the interrupt request. In order to set up a function to be called after a reset-triggering event (and also enable/disable the interrupt), the WDOG_DRV_SetInt function may be used. Please note that, due to the 128 bus clocks delay before the reset, a limited amount of job can be done in the ISR.

Basic Operations of WDOG

  1. To initialize WDOG, call WDOG_DRV_Init() with an user configuration structure. In the following code, WDOG is initialized with default settings.
    #define INST_WDOG1 (0U)
    wdog_user_config_t userConfigPtr = {
    .WDOG_LPO_CLOCK, /* Use the LPO clock as source */
    .opMode = { /* WDOG not functional in Wait/Debug/Stop mode */
    false,
    false,
    false
    },
    .true, /* Enable further updates of the WDOG configuration */
    .false, /* Timeout interrupt disabled */
    .false, /* Window mode disabled */
    .0U, /* Window value */
    .0x400, /* Timeout value */
    .false /* Prescaler disabled */
    };
    /* Initialize WDOG module */
    WDOG_DRV_Init(INST_WDOG1, &userConfigPtr);
  2. To get default configuration of WDOG module, just call the function WDOG_DRV_GetDefaultConfig(). Make sure that the operation before WDOG timeout executing.
    wdog_user_config_t userConfigPtr;
    /* Get default configuration of WDOG module */
    WDOG_DRV_GetDefaultConfig(&userConfigPtr);
  3. To refresh WDOG counter of WDOG module, just call the function WDOG_DRV_Trigger(). Make sure that the operation before WDOG timeout executing.
    /* Refresh counter of WDOG counter */
    WDOG_DRV_Trigger(INST_WDOG1);
  4. To de-initialize WDOG module, just call the function WDOG_DRV_Deinit(). Make sure that the operation before WDOG timeout executing.
    /* De-initialize WDOG module */
    WDOG_DRV_Deinit(INST_WDOG1);

Example:

#define INST_WDOG1 (0U)
wdog_user_config_t userConfigPtr = {
.WDOG_LPO_CLOCK, /* Use the LPO clock as source */
.opMode = { /* WDOG not functional in Wait/Debug/Stop mode */
false,
false,
false
},
.true, /* Enable further updates of the WDOG configuration */
.false, /* Timeout interrupt disabled */
.false, /* Window mode disabled */
.0U, /* Window value */
.0x400, /* Timeout value */
.false /* Prescaler disabled */
};
/* Initialize WDOG module */
WDOG_DRV_Init(INST_WDOG1, &userConfigPtr);
/* Enable the timeout interrupt and set the ISR */
WDOG_DRV_SetInt(INST_WDOG1, true);
while (1) {
/* Do something that takes between 0x100 and 0x400 clock cycles */
/* Refresh the counter */
WDOG_DRV_Trigger(INST_WDOG1);
}
/* De-initialize WDOG module */
WDOG_DRV_Deinit(INST_WDOG1);

Data Structures

struct  wdog_op_mode_t
 WDOG option mode configuration structure Implements : wdog_op_mode_t_Class. More...
 
struct  wdog_user_config_t
 WDOG user configuration structure Implements : wdog_user_config_t_Class. More...
 

Enumerations

enum  wdog_clk_source_t { WDOG_BUS_CLOCK = 0x00U, WDOG_LPO_CLOCK = 0x01U, WDOG_SOSC_CLOCK = 0x02U, WDOG_SIRC_CLOCK = 0x03U }
 Clock sources for the WDOG. Implements : wdog_clk_source_t_Class. More...
 
enum  wdog_test_mode_t { WDOG_TST_DISABLED = 0x00U, WDOG_TST_USER = 0x01U, WDOG_TST_LOW = 0x02U, WDOG_TST_HIGH = 0x03U }
 Test modes for the WDOG. Implements : wdog_test_mode_t_Class. More...
 
enum  wdog_set_mode_t { WDOG_DEBUG_MODE = 0x00U, WDOG_WAIT_MODE = 0x01U, WDOG_STOP_MODE = 0x02U }
 set modes for the WDOG. Implements : wdog_set_mode_t_Class More...
 

WDOG Driver API

status_t WDOG_DRV_Init (uint32_t instance, const wdog_user_config_t *userConfigPtr)
 Initializes the WDOG driver. More...
 
status_t WDOG_DRV_Deinit (uint32_t instance)
 De-initializes the WDOG driver. More...
 
void WDOG_DRV_GetConfig (uint32_t instance, wdog_user_config_t *const config)
 Gets the current configuration of the WDOG. More...
 
void WDOG_DRV_GetDefaultConfig (wdog_user_config_t *const config)
 Gets default configuration of the WDOG. More...
 
status_t WDOG_DRV_SetInt (uint32_t instance, bool enable)
 Enables/Disables the WDOG timeout interrupt and sets a function to be called when a timeout interrupt is received, before reset. More...
 
void WDOG_DRV_ClearIntFlag (uint32_t instance)
 Clear interrupt flag of the WDOG. More...
 
void WDOG_DRV_Trigger (uint32_t instance)
 Refreshes the WDOG counter. More...
 
uint16_t WDOG_DRV_GetCounter (uint32_t instance)
 Gets the value of the WDOG counter. More...
 
status_t WDOG_DRV_SetWindow (uint32_t instance, bool enable, uint16_t windowvalue)
 Set window mode and window value of the WDOG. More...
 
status_t WDOG_DRV_SetMode (uint32_t instance, bool enable, wdog_set_mode_t Setmode)
 Sets the mode operation of the WDOG. More...
 
status_t WDOG_DRV_SetTimeout (uint32_t instance, uint16_t timeout)
 Sets the value of the WDOG timeout. More...
 
status_t WDOG_DRV_SetTestMode (uint32_t instance, wdog_test_mode_t testMode)
 Changes the WDOG test mode. More...
 
wdog_test_mode_t WDOG_DRV_GetTestMode (uint32_t instance)
 Gets the WDOG test mode. More...
 

Enumeration Type Documentation

Clock sources for the WDOG. Implements : wdog_clk_source_t_Class.

Enumerator
WDOG_BUS_CLOCK 

Bus clock

WDOG_LPO_CLOCK 

LPO clock

WDOG_SOSC_CLOCK 

SOSC clock

WDOG_SIRC_CLOCK 

SIRC clock

Definition at line 52 of file wdog_driver.h.

set modes for the WDOG. Implements : wdog_set_mode_t_Class

Enumerator
WDOG_DEBUG_MODE 

Debug mode

WDOG_WAIT_MODE 

Wait mode

WDOG_STOP_MODE 

Stop mode

Definition at line 76 of file wdog_driver.h.

Test modes for the WDOG. Implements : wdog_test_mode_t_Class.

Enumerator
WDOG_TST_DISABLED 

Test mode disabled

WDOG_TST_USER 

User mode enabled. (Test mode disabled.)

WDOG_TST_LOW 

Test mode enabled, only the low byte is used.

WDOG_TST_HIGH 

Test mode enabled, only the high byte is used.

Definition at line 64 of file wdog_driver.h.

Function Documentation

void WDOG_DRV_ClearIntFlag ( uint32_t  instance)

Clear interrupt flag of the WDOG.

Parameters
[in]instanceWDOG peripheral instance number

Definition at line 273 of file wdog_driver.c.

status_t WDOG_DRV_Deinit ( uint32_t  instance)

De-initializes the WDOG driver.

Parameters
[in]instanceWDOG peripheral instance number
Returns
operation status
  • STATUS_SUCCESS: if allowed reconfigures WDOG module and de-initializes successful.
  • STATUS_ERROR: Operation failed. Possible causes: failed to WDOG configuration updates not allowed.

Definition at line 163 of file wdog_driver.c.

void WDOG_DRV_GetConfig ( uint32_t  instance,
wdog_user_config_t *const  config 
)

Gets the current configuration of the WDOG.

Parameters
[in]instanceWDOG peripheral instance number
[out]configuresthe current configuration

Definition at line 198 of file wdog_driver.c.

uint16_t WDOG_DRV_GetCounter ( uint32_t  instance)

Gets the value of the WDOG counter.

Parameters
[in]instanceWDOG peripheral instance number.
Returns
the value of the WDOG counter.

Definition at line 304 of file wdog_driver.c.

void WDOG_DRV_GetDefaultConfig ( wdog_user_config_t *const  config)

Gets default configuration of the WDOG.

Parameters
[out]configuresthe default configuration

Definition at line 215 of file wdog_driver.c.

wdog_test_mode_t WDOG_DRV_GetTestMode ( uint32_t  instance)

Gets the WDOG test mode.

This function verifies the test mode of the WDOG.

Parameters
[in]instanceWDOG peripheral instance number
Returns
Test modes for the WDOG

Definition at line 462 of file wdog_driver.c.

status_t WDOG_DRV_Init ( uint32_t  instance,
const wdog_user_config_t userConfigPtr 
)

Initializes the WDOG driver.

Parameters
[in]instanceWDOG peripheral instance number
[in]userConfigPtrpointer to the WDOG user configuration structure
Returns
operation status
  • STATUS_SUCCESS: Operation was successful.
  • STATUS_ERROR: Operation failed. Possible causes: previous clock source or the one specified in the configuration structure is disabled; WDOG configuration updates are not allowed; WDOG instance has been initialized before; If window mode enabled and window value greater than or equal to the timeout value.

Definition at line 105 of file wdog_driver.c.

status_t WDOG_DRV_SetInt ( uint32_t  instance,
bool  enable 
)

Enables/Disables the WDOG timeout interrupt and sets a function to be called when a timeout interrupt is received, before reset.

Parameters
[in]instanceWDOG peripheral instance number
[in]enableenable/disable interrupt
Returns
operation status
  • STATUS_SUCCESS: if allowed reconfigures WDOG timeout interrupt.
  • STATUS_ERROR: Operation failed. Possible causes: failed to WDOG configuration updates not allowed.

Definition at line 241 of file wdog_driver.c.

status_t WDOG_DRV_SetMode ( uint32_t  instance,
bool  enable,
wdog_set_mode_t  Setmode 
)

Sets the mode operation of the WDOG.

This function changes the mode operation of the WDOG.

Parameters
[in]instanceWDOG peripheral instance number.
[in]enableenable/disable mode of the WDOG.
[in]Setmodeselect mode of the WDOG.
Returns
operation status
  • STATUS_SUCCESS: if allowed reconfigures mode operation of the WDOG.
  • STATUS_ERROR: Operation failed. Possible causes: failed to WDOG configuration updates not allowed.

Definition at line 355 of file wdog_driver.c.

status_t WDOG_DRV_SetTestMode ( uint32_t  instance,
wdog_test_mode_t  testMode 
)

Changes the WDOG test mode.

This function changes the test mode of the WDOG. If the WDOG is tested in mode, software should set this field to 0x01U in order to indicate that the WDOG is functioning normally.

Parameters
[in]instanceWDOG peripheral instance number
[in]testModeTest modes for the WDOG.
Returns
operation status
  • STATUS_SUCCESS: if allowed reconfigures WDOG test mode.
  • STATUS_ERROR: Operation failed. Possible causes: failed to WDOG configuration updates not allowed.

Definition at line 429 of file wdog_driver.c.

status_t WDOG_DRV_SetTimeout ( uint32_t  instance,
uint16_t  timeout 
)

Sets the value of the WDOG timeout.

This function sets the value of the WDOG timeout.

Parameters
[in]instanceWDOG peripheral instance number.
[in]timeoutthe value of the WDOG timeout.
Returns
operation status
  • STATUS_SUCCESS: if allowed reconfigures WDOG timeout.
  • STATUS_ERROR: Operation failed. Possible causes: failed to WDOG configuration updates not allowed.

Definition at line 400 of file wdog_driver.c.

status_t WDOG_DRV_SetWindow ( uint32_t  instance,
bool  enable,
uint16_t  windowvalue 
)

Set window mode and window value of the WDOG.

This function set window mode, window value is set when window mode enabled.

Parameters
[in]instanceWDOG peripheral instance number.
[in]enableenable/disable window mode and window value.
[in]windowvaluethe value of the WDOG window.
Returns
operation status
  • STATUS_SUCCESS: if allowed reconfigures window value success.
  • STATUS_ERROR: Operation failed. Possible causes: failed to WDOG configuration updates not allowed.

Definition at line 319 of file wdog_driver.c.

void WDOG_DRV_Trigger ( uint32_t  instance)

Refreshes the WDOG counter.

Parameters
[in]instanceWDOG peripheral instance number

Definition at line 289 of file wdog_driver.c.