123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437 |
- #ifndef _FSL_WDOG_H_
- #define _FSL_WDOG_H_
- #include "fsl_common.h"
- #define FSL_WDOG_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
- #define WDOG_FIRST_WORD_OF_UNLOCK (0xC520U)
- #define WDOG_SECOND_WORD_OF_UNLOCK (0xD928U)
- #define WDOG_FIRST_WORD_OF_REFRESH (0xA602U)
- #define WDOG_SECOND_WORD_OF_REFRESH (0xB480U)
- typedef enum _wdog_clock_source
- {
- kWDOG_LpoClockSource = 0U,
- kWDOG_AlternateClockSource = 1U,
- } wdog_clock_source_t;
- typedef struct _wdog_work_mode
- {
- #if defined(FSL_FEATURE_WDOG_HAS_WAITEN) && FSL_FEATURE_WDOG_HAS_WAITEN
- bool enableWait;
- #endif
- bool enableStop;
- bool enableDebug;
- } wdog_work_mode_t;
- typedef enum _wdog_clock_prescaler
- {
- kWDOG_ClockPrescalerDivide1 = 0x0U,
- kWDOG_ClockPrescalerDivide2 = 0x1U,
- kWDOG_ClockPrescalerDivide3 = 0x2U,
- kWDOG_ClockPrescalerDivide4 = 0x3U,
- kWDOG_ClockPrescalerDivide5 = 0x4U,
- kWDOG_ClockPrescalerDivide6 = 0x5U,
- kWDOG_ClockPrescalerDivide7 = 0x6U,
- kWDOG_ClockPrescalerDivide8 = 0x7U,
- } wdog_clock_prescaler_t;
- typedef struct _wdog_config
- {
- bool enableWdog;
- wdog_clock_source_t clockSource;
- wdog_clock_prescaler_t prescaler;
- wdog_work_mode_t workMode;
- bool enableUpdate;
- bool enableInterrupt;
- bool enableWindowMode;
- uint32_t windowValue;
- uint32_t timeoutValue;
- } wdog_config_t;
- typedef enum _wdog_test_mode
- {
- kWDOG_QuickTest = 0U,
- kWDOG_ByteTest = 1U,
- } wdog_test_mode_t;
- typedef enum _wdog_tested_byte
- {
- kWDOG_TestByte0 = 0U,
- kWDOG_TestByte1 = 1U,
- kWDOG_TestByte2 = 2U,
- kWDOG_TestByte3 = 3U,
- } wdog_tested_byte_t;
- typedef struct _wdog_test_config
- {
- wdog_test_mode_t testMode;
- wdog_tested_byte_t testedByte;
- uint32_t timeoutValue;
- } wdog_test_config_t;
- enum _wdog_interrupt_enable_t
- {
- kWDOG_InterruptEnable = WDOG_STCTRLH_IRQRSTEN_MASK,
- };
- enum _wdog_status_flags_t
- {
- kWDOG_RunningFlag = WDOG_STCTRLH_WDOGEN_MASK,
- kWDOG_TimeoutFlag = WDOG_STCTRLL_INTFLG_MASK,
- };
- #if defined(__cplusplus)
- extern "C" {
- #endif
- void WDOG_GetDefaultConfig(wdog_config_t *config);
- void WDOG_Init(WDOG_Type *base, const wdog_config_t *config);
- void WDOG_Deinit(WDOG_Type *base);
- void WDOG_SetTestModeConfig(WDOG_Type *base, wdog_test_config_t *config);
- static inline void WDOG_Enable(WDOG_Type *base)
- {
- base->STCTRLH |= WDOG_STCTRLH_WDOGEN_MASK;
- }
- static inline void WDOG_Disable(WDOG_Type *base)
- {
- base->STCTRLH &= ~WDOG_STCTRLH_WDOGEN_MASK;
- }
- static inline void WDOG_EnableInterrupts(WDOG_Type *base, uint32_t mask)
- {
- base->STCTRLH |= mask;
- }
- static inline void WDOG_DisableInterrupts(WDOG_Type *base, uint32_t mask)
- {
- base->STCTRLH &= ~mask;
- }
- uint32_t WDOG_GetStatusFlags(WDOG_Type *base);
- void WDOG_ClearStatusFlags(WDOG_Type *base, uint32_t mask);
- static inline void WDOG_SetTimeoutValue(WDOG_Type *base, uint32_t timeoutCount)
- {
- base->TOVALH = (uint16_t)((timeoutCount >> 16U) & 0xFFFFU);
- base->TOVALL = (uint16_t)((timeoutCount)&0xFFFFU);
- }
- static inline void WDOG_SetWindowValue(WDOG_Type *base, uint32_t windowValue)
- {
- base->WINH = (uint16_t)((windowValue >> 16U) & 0xFFFFU);
- base->WINL = (uint16_t)((windowValue)&0xFFFFU);
- }
- static inline void WDOG_Unlock(WDOG_Type *base)
- {
- base->UNLOCK = WDOG_FIRST_WORD_OF_UNLOCK;
- base->UNLOCK = WDOG_SECOND_WORD_OF_UNLOCK;
- }
- void WDOG_Refresh(WDOG_Type *base);
- static inline uint16_t WDOG_GetResetCount(WDOG_Type *base)
- {
- return base->RSTCNT;
- }
- static inline void WDOG_ClearResetCount(WDOG_Type *base)
- {
- base->RSTCNT |= UINT16_MAX;
- }
- #if defined(__cplusplus)
- }
- #endif
- #endif
|