MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
RTWDOG: 32-bit Watchdog Timer

Overview

The MCUXpresso SDK provides a peripheral driver for the RTWDOG module of MCUXpresso SDK devices.

Typical use case

Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/rtwdog

Data Structures

struct  rtwdog_work_mode_t
 Defines RTWDOG work mode. More...
 
struct  rtwdog_config_t
 Describes RTWDOG configuration structure. More...
 

Enumerations

enum  rtwdog_clock_source_t {
  kRTWDOG_ClockSource0 = 0U,
  kRTWDOG_ClockSource1 = 1U,
  kRTWDOG_ClockSource2 = 2U,
  kRTWDOG_ClockSource3 = 3U
}
 Describes RTWDOG clock source. More...
 
enum  rtwdog_clock_prescaler_t {
  kRTWDOG_ClockPrescalerDivide1 = 0x0U,
  kRTWDOG_ClockPrescalerDivide256 = 0x1U
}
 Describes the selection of the clock prescaler. More...
 
enum  rtwdog_test_mode_t {
  kRTWDOG_TestModeDisabled = 0U,
  kRTWDOG_UserModeEnabled = 1U,
  kRTWDOG_LowByteTest = 2U,
  kRTWDOG_HighByteTest = 3U
}
 Describes RTWDOG test mode. More...
 
enum  _rtwdog_interrupt_enable_t { kRTWDOG_InterruptEnable = RTWDOG_CS_INT_MASK }
 RTWDOG interrupt configuration structure. More...
 
enum  _rtwdog_status_flags_t {
  kRTWDOG_RunningFlag = RTWDOG_CS_EN_MASK,
  kRTWDOG_InterruptFlag = RTWDOG_CS_FLG_MASK
}
 RTWDOG status flags. More...
 

Unlock sequence

#define WDOG_FIRST_WORD_OF_UNLOCK   (RTWDOG_UPDATE_KEY & 0xFFFFU)
 First word of unlock sequence.
 
#define WDOG_SECOND_WORD_OF_UNLOCK   ((RTWDOG_UPDATE_KEY >> 16U) & 0xFFFFU)
 Second word of unlock sequence.
 

Refresh sequence

#define WDOG_FIRST_WORD_OF_REFRESH   (RTWDOG_REFRESH_KEY & 0xFFFFU)
 First word of refresh sequence.
 
#define WDOG_SECOND_WORD_OF_REFRESH   ((RTWDOG_REFRESH_KEY >> 16U) & 0xFFFFU)
 Second word of refresh sequence.
 

Driver version

#define FSL_RTWDOG_DRIVER_VERSION   (MAKE_VERSION(2, 1, 1))
 RTWDOG driver version 2.1.1. More...
 

RTWDOG Initialization and De-initialization

void RTWDOG_GetDefaultConfig (rtwdog_config_t *config)
 Initializes the RTWDOG configuration structure. More...
 
 AT_QUICKACCESS_SECTION_CODE (void RTWDOG_Init(RTWDOG_Type *base, const rtwdog_config_t *config))
 Initializes the RTWDOG module. More...
 
void RTWDOG_Deinit (RTWDOG_Type *base)
 De-initializes the RTWDOG module. More...
 

RTWDOG functional Operation

static void RTWDOG_Enable (RTWDOG_Type *base)
 Enables the RTWDOG module. More...
 
static void RTWDOG_Disable (RTWDOG_Type *base)
 Disables the RTWDOG module. More...
 
static void RTWDOG_EnableInterrupts (RTWDOG_Type *base, uint32_t mask)
 Enables the RTWDOG interrupt. More...
 
static void RTWDOG_DisableInterrupts (RTWDOG_Type *base, uint32_t mask)
 Disables the RTWDOG interrupt. More...
 
static uint32_t RTWDOG_GetStatusFlags (RTWDOG_Type *base)
 Gets the RTWDOG all status flags. More...
 
static void RTWDOG_EnableWindowMode (RTWDOG_Type *base, bool enable)
 Enables/disables the window mode. More...
 
static uint32_t RTWDOG_CountToMesec (RTWDOG_Type *base, uint32_t count, uint32_t clockFreqInHz)
 Converts raw count value to millisecond. More...
 
void RTWDOG_ClearStatusFlags (RTWDOG_Type *base, uint32_t mask)
 Clears the RTWDOG flag. More...
 
static void RTWDOG_SetTimeoutValue (RTWDOG_Type *base, uint16_t timeoutCount)
 Sets the RTWDOG timeout value. More...
 
static void RTWDOG_SetWindowValue (RTWDOG_Type *base, uint16_t windowValue)
 Sets the RTWDOG window value. More...
 
static void RTWDOG_Unlock (RTWDOG_Type *base)
 Unlocks the RTWDOG register written. More...
 
static void RTWDOG_Refresh (RTWDOG_Type *base)
 Refreshes the RTWDOG timer. More...
 
static uint16_t RTWDOG_GetCounterValue (RTWDOG_Type *base)
 Gets the RTWDOG counter value. More...
 

Data Structure Documentation

struct rtwdog_work_mode_t

Data Fields

bool enableWait
 Enables or disables RTWDOG in wait mode.
 
bool enableStop
 Enables or disables RTWDOG in stop mode.
 
bool enableDebug
 Enables or disables RTWDOG in debug mode.
 
struct rtwdog_config_t

Data Fields

bool enableRtwdog
 Enables or disables RTWDOG.
 
rtwdog_clock_source_t clockSource
 Clock source select.
 
rtwdog_clock_prescaler_t prescaler
 Clock prescaler value.
 
rtwdog_work_mode_t workMode
 Configures RTWDOG work mode in debug stop and wait mode.
 
rtwdog_test_mode_t testMode
 Configures RTWDOG test mode.
 
bool enableUpdate
 Update write-once register enable.
 
bool enableInterrupt
 Enables or disables RTWDOG interrupt.
 
bool enableWindowMode
 Enables or disables RTWDOG window mode.
 
uint16_t windowValue
 Window value.
 
uint16_t timeoutValue
 Timeout value.
 

Macro Definition Documentation

#define FSL_RTWDOG_DRIVER_VERSION   (MAKE_VERSION(2, 1, 1))

Enumeration Type Documentation

Enumerator
kRTWDOG_ClockSource0 

Clock source 0.

kRTWDOG_ClockSource1 

Clock source 1.

kRTWDOG_ClockSource2 

Clock source 2.

kRTWDOG_ClockSource3 

Clock source 3.

Enumerator
kRTWDOG_ClockPrescalerDivide1 

Divided by 1.

kRTWDOG_ClockPrescalerDivide256 

Divided by 256.

Enumerator
kRTWDOG_TestModeDisabled 

Test Mode disabled.

kRTWDOG_UserModeEnabled 

User Mode enabled.

kRTWDOG_LowByteTest 

Test Mode enabled, only low byte is used.

kRTWDOG_HighByteTest 

Test Mode enabled, only high byte is used.

This structure contains the settings for all of the RTWDOG interrupt configurations.

Enumerator
kRTWDOG_InterruptEnable 

Interrupt is generated before forcing a reset.

This structure contains the RTWDOG status flags for use in the RTWDOG functions.

Enumerator
kRTWDOG_RunningFlag 

Running flag, set when RTWDOG is enabled.

kRTWDOG_InterruptFlag 

Interrupt flag, set when interrupt occurs.

Function Documentation

void RTWDOG_GetDefaultConfig ( rtwdog_config_t config)

This function initializes the RTWDOG configuration structure to default values. The default values are:

* rtwdogConfig->enableRtwdog = true;
* rtwdogConfig->clockSource = kRTWDOG_ClockSource1;
* rtwdogConfig->prescaler = kRTWDOG_ClockPrescalerDivide1;
* rtwdogConfig->workMode.enableWait = true;
* rtwdogConfig->workMode.enableStop = false;
* rtwdogConfig->workMode.enableDebug = false;
* rtwdogConfig->testMode = kRTWDOG_TestModeDisabled;
* rtwdogConfig->enableUpdate = true;
* rtwdogConfig->enableInterrupt = false;
* rtwdogConfig->enableWindowMode = false;
* rtwdogConfig->windowValue = 0U;
* rtwdogConfig->timeoutValue = 0xFFFFU;
*
Parameters
configPointer to the RTWDOG configuration structure.
See Also
rtwdog_config_t
AT_QUICKACCESS_SECTION_CODE ( void   RTWDOG_InitRTWDOG_Type *base, const rtwdog_config_t *config)

This function initializes the RTWDOG. To reconfigure the RTWDOG without forcing a reset first, enableUpdate must be set to true in the configuration.

Example:

* rtwdog_config_t config;
* config.timeoutValue = 0x7ffU;
* config.enableUpdate = true;
* RTWDOG_Init(wdog_base,&config);
*
Parameters
baseRTWDOG peripheral base address.
configThe configuration of the RTWDOG.
void RTWDOG_Deinit ( RTWDOG_Type *  base)

This function shuts down the RTWDOG. Ensure that the WDOG_CS.UPDATE is 1, which means that the register update is enabled.

Parameters
baseRTWDOG peripheral base address.
static void RTWDOG_Enable ( RTWDOG_Type *  base)
inlinestatic

This function writes a value into the WDOG_CS register to enable the RTWDOG. The WDOG_CS register is a write-once register. Ensure that the WCT window is still open and this register has not been written in this WCT while the function is called.

Parameters
baseRTWDOG peripheral base address.
static void RTWDOG_Disable ( RTWDOG_Type *  base)
inlinestatic

This function writes a value into the WDOG_CS register to disable the RTWDOG. The WDOG_CS register is a write-once register. Ensure that the WCT window is still open and this register has not been written in this WCT while the function is called.

Parameters
baseRTWDOG peripheral base address
static void RTWDOG_EnableInterrupts ( RTWDOG_Type *  base,
uint32_t  mask 
)
inlinestatic

This function writes a value into the WDOG_CS register to enable the RTWDOG interrupt. The WDOG_CS register is a write-once register. Ensure that the WCT window is still open and this register has not been written in this WCT while the function is called.

Parameters
baseRTWDOG peripheral base address.
maskThe interrupts to enable. The parameter can be a combination of the following source if defined:
  • kRTWDOG_InterruptEnable
static void RTWDOG_DisableInterrupts ( RTWDOG_Type *  base,
uint32_t  mask 
)
inlinestatic

This function writes a value into the WDOG_CS register to disable the RTWDOG interrupt. The WDOG_CS register is a write-once register. Ensure that the WCT window is still open and this register has not been written in this WCT while the function is called.

Parameters
baseRTWDOG peripheral base address.
maskThe interrupts to disabled. The parameter can be a combination of the following source if defined:
  • kRTWDOG_InterruptEnable
static uint32_t RTWDOG_GetStatusFlags ( RTWDOG_Type *  base)
inlinestatic

This function gets all status flags.

Example to get the running flag:

* uint32_t status;
*
Parameters
baseRTWDOG peripheral base address
Returns
State of the status flag: asserted (true) or not-asserted (false).
See Also
_rtwdog_status_flags_t
  • true: related status flag has been set.
  • false: related status flag is not set.
static void RTWDOG_EnableWindowMode ( RTWDOG_Type *  base,
bool  enable 
)
inlinestatic
Parameters
baseRTWDOG peripheral base address.
enableEnables(true) or disables(false) the feature.
static uint32_t RTWDOG_CountToMesec ( RTWDOG_Type *  base,
uint32_t  count,
uint32_t  clockFreqInHz 
)
inlinestatic

Note that if the clock frequency is too high the timeout period can be less than 1 ms. In this case this api will return 0 value.

Parameters
baseRTWDOG peripheral base address.
countRaw count value.

clockFreqInHz The frequency of the clock source RTWDOG uses.

void RTWDOG_ClearStatusFlags ( RTWDOG_Type *  base,
uint32_t  mask 
)

This function clears the RTWDOG status flag.

Example to clear an interrupt flag:

Parameters
baseRTWDOG peripheral base address.
maskThe status flags to clear. The parameter can be any combination of the following values:
  • kRTWDOG_InterruptFlag
static void RTWDOG_SetTimeoutValue ( RTWDOG_Type *  base,
uint16_t  timeoutCount 
)
inlinestatic

This function writes a timeout value into the WDOG_TOVAL register. The WDOG_TOVAL register is a write-once register. Ensure that the WCT window is still open and this register has not been written in this WCT while the function is called.

Parameters
baseRTWDOG peripheral base address
timeoutCountRTWDOG timeout value, count of RTWDOG clock ticks.
static void RTWDOG_SetWindowValue ( RTWDOG_Type *  base,
uint16_t  windowValue 
)
inlinestatic

This function writes a window value into the WDOG_WIN register. The WDOG_WIN register is a write-once register. Ensure that the WCT window is still open and this register has not been written in this WCT while the function is called.

Parameters
baseRTWDOG peripheral base address.
windowValueRTWDOG window value.
static void RTWDOG_Unlock ( RTWDOG_Type *  base)
inlinestatic

This function unlocks the RTWDOG register written.

Before starting the unlock sequence and following the configuration, disable the global interrupts. Otherwise, an interrupt could effectively invalidate the unlock sequence and the WCT may expire. After the configuration finishes, re-enable the global interrupts.

Parameters
baseRTWDOG peripheral base address
static void RTWDOG_Refresh ( RTWDOG_Type *  base)
inlinestatic

This function feeds the RTWDOG. This function should be called before the Watchdog timer is in timeout. Otherwise, a reset is asserted.

Parameters
baseRTWDOG peripheral base address
static uint16_t RTWDOG_GetCounterValue ( RTWDOG_Type *  base)
inlinestatic

This function gets the RTWDOG counter value.

Parameters
baseRTWDOG peripheral base address.
Returns
Current RTWDOG counter value.