S32 SDK

Detailed Description

External Watchdog Monitor Peripheral Driver.

Hardware background

Features:

The EWM can be initialized only once as all the configuration registers are write once per reset

Clocking and pin configuration

The EWM Driver does not handle clock setup (from PCC) or any kind of pin configuration (done by PORT module). This is handled by the Clock Manager and PORT module, respectively. The driver assumes that correct clock configurations have been made, so it is the user's responsibility to set up clocking and pin configurations correctly.

Interrupts

The EWM module can generate interrupts, if enabled on EWM_DRV_Init() but they are not handled by the driver. The EWM shares the interrupt vector with the Watchdog Timer. The following code snippet is an example of how enable the interrupt and assign a handler:

/* EWM and watchdog interrupt service routine */
void EWM_Watchdog_ISR()
{
/* Do something(e.g perform a clean reset) */
...
}
int main()
{
/* Init clocks, pins, other modules */
...
/* Install interrupt handler for EWM and Watchdog */
INT_SYS_InstallHandler(WDOG_EWM_IRQn, &EWM_Watchdog_ISR, (isr_t *)0);
/* Enable the interrupt */
/* Init EWM */
...
/* Infinite loop*/
while(1)
{
/* Do something until the counter needs to be refreshed */
...
/* Refresh the counter */
EWM_DRV_Refresh(EWM_INSTANCE);
}
}

Using the EWM driver in your application

/* Declare the EWM instance you want to use */
#define EWM_INSTANCE 0UL
int main()
{
/* Declare the EWM configuration structure */
ewm_init_config_t ewmConfig;
/* Variable where to store the init status */
status_t ewmStatus;
/* Init clocks, pins, other modules */
...
/* Get the default configuration values */
/* Init the module instance */
ewmStatus = EWM_DRV_Init(EWM_INSTANCE, &ewmConfig);
/* Infinite loop*/
while(1)
{
/* Do something until the counter needs to be refreshed */
...
/* Refresh the counter */
EWM_DRV_Refresh(EWM_INSTANCE);
}
}

Data Structures

struct  ewm_init_config_t
 

EWM Driver API

status_t EWM_DRV_Init (uint32_t instance, const ewm_init_config_t *config)
 Init EWM. This method initializes EWM instance to the configuration from the passed structure. The user must make sure that the clock is enabled. This is the only method needed to be called to start the module. More...
 
void EWM_DRV_GetDefaultConfig (ewm_init_config_t *config)
 Init configuration structure to default values. More...
 
void EWM_DRV_Refresh (uint32_t instance)
 Refresh EWM. This method needs to be called within the window period specified by the Compare Low and Compare High registers. More...
 

Function Documentation

void EWM_DRV_GetDefaultConfig ( ewm_init_config_t config)

Init configuration structure to default values.

Parameters
[out]configPointer to the configuration structure to initialize
Returns
None

Definition at line 107 of file ewm_driver.c.

status_t EWM_DRV_Init ( uint32_t  instance,
const ewm_init_config_t config 
)

Init EWM. This method initializes EWM instance to the configuration from the passed structure. The user must make sure that the clock is enabled. This is the only method needed to be called to start the module.

Example configuration structure:

1 ewm_init_config_t ewmUserCfg = {
2  .assertLogic = EWM_IN_ASSERT_ON_LOGIC_ZERO,
3  .interruptEnable = true,
4  .prescaler = 128,
5  .compareLow = 0,
6  .compareHigh = 254
7 };

This configuration will enable the peripheral, with input pin configured to assert on logic low, interrupt enabled, prescaler 128 and maximum refresh window.

The EWM can be initialized only once per CPU reset as the registers are write once.

Parameters
[in]instanceEWM instance number
[in]configPointer to the module configuration structure.
Returns
status_t Will return the status of the operation:
  • STATUS_SUCCESS if the operation is successful
  • STATUS_ERROR if the windows values are not correct or if the instance is already enabled

Definition at line 61 of file ewm_driver.c.

void EWM_DRV_Refresh ( uint32_t  instance)

Refresh EWM. This method needs to be called within the window period specified by the Compare Low and Compare High registers.

Parameters
[in]instanceEWM instance number
Returns
None

Definition at line 129 of file ewm_driver.c.