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
 

Enumerations

enum  ewm_in_assert_logic_t { EWM_IN_ASSERT_DISABLED = 0x00U, EWM_IN_ASSERT_ON_LOGIC_ZERO = 0x01U, EWM_IN_ASSERT_ON_LOGIC_ONE = 0x02U }
 

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...
 
ewm_in_assert_logic_t EWM_DRV_GetInputPinAssertLogic (uint32_t instance)
 Get the Input pin assert logic. More...
 

Enumeration Type Documentation

Enumerator
EWM_IN_ASSERT_DISABLED 

Input pin disabled

EWM_IN_ASSERT_ON_LOGIC_ZERO 

Input pin asserts EWM when on logic 0

EWM_IN_ASSERT_ON_LOGIC_ONE 

Input pin asserts EWM when on logic 1

Definition at line 43 of file ewm_driver.h.

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 131 of file ewm_driver.c.

ewm_in_assert_logic_t EWM_DRV_GetInputPinAssertLogic ( uint32_t  instance)

Get the Input pin assert logic.

Parameters
[in]instanceEWM instance number
Returns
The input pin assert logic:
  • EWM_IN_ASSERT_DISABLED - EWM in disabled
  • EWM_IN_ASSERT_ON_LOGIC_ZERO - EWM is asserted when EWM_in is logic 0
  • EWM_IN_ASSERT_ON_LOGIC_ONE - EWM is asserted when EWM_in is logic 1

Definition at line 175 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 63 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 153 of file ewm_driver.c.