Callisto4Bootloader: drivers/fsl_rtwdog.h Source File

Callisto4Bootloader

fsl_rtwdog.h
Go to the documentation of this file.
1 /*
2 * Copyright 2017-2018 NXP
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7 #ifndef _FSL_RTWDOG_H_
8 #define _FSL_RTWDOG_H_
9
10 #include "fsl_common.h"
11
17 /*******************************************************************************
18 * Definitions
19 *******************************************************************************/
22 #define WDOG_FIRST_WORD_OF_UNLOCK (RTWDOG_UPDATE_KEY & 0xFFFFU)
23 #define WDOG_SECOND_WORD_OF_UNLOCK ((RTWDOG_UPDATE_KEY >> 16U) & 0xFFFFU)
28 #define WDOG_FIRST_WORD_OF_REFRESH (RTWDOG_REFRESH_KEY & 0xFFFFU)
29 #define WDOG_SECOND_WORD_OF_REFRESH ((RTWDOG_REFRESH_KEY >> 16U) & 0xFFFFU)
34 #define FSL_RTWDOG_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
35
38 typedef enum _rtwdog_clock_source
39 {
40 kRTWDOG_ClockSource0 = 0U,
41 kRTWDOG_ClockSource1 = 1U,
42 kRTWDOG_ClockSource2 = 2U,
43 kRTWDOG_ClockSource3 = 3U,
44 } rtwdog_clock_source_t;
45
47 typedef enum _rtwdog_clock_prescaler
48 {
49 kRTWDOG_ClockPrescalerDivide1 = 0x0U,
50 kRTWDOG_ClockPrescalerDivide256 = 0x1U,
51 } rtwdog_clock_prescaler_t;
52
54 typedef struct _rtwdog_work_mode
55 {
56 bool enableWait;
57 bool enableStop;
58 bool enableDebug;
59 } rtwdog_work_mode_t;
60
62 typedef enum _rtwdog_test_mode
63 {
64 kRTWDOG_TestModeDisabled = 0U,
65 kRTWDOG_UserModeEnabled = 1U,
66 kRTWDOG_LowByteTest = 2U,
67 kRTWDOG_HighByteTest = 3U,
68 } rtwdog_test_mode_t;
69
71 typedef struct _rtwdog_config
72 {
73 bool enableRtwdog;
74 rtwdog_clock_source_t clockSource;
75 rtwdog_clock_prescaler_t prescaler;
76 rtwdog_work_mode_t workMode;
77 rtwdog_test_mode_t testMode;
78 bool enableUpdate;
79 bool enableInterrupt;
80 bool enableWindowMode;
81 uint16_t windowValue;
82 uint16_t timeoutValue;
83 } rtwdog_config_t;
84
90 enum _rtwdog_interrupt_enable_t
91 {
92 kRTWDOG_InterruptEnable = RTWDOG_CS_INT_MASK,
93 };
94
100 enum _rtwdog_status_flags_t
101 {
102 kRTWDOG_RunningFlag = RTWDOG_CS_EN_MASK,
103 kRTWDOG_InterruptFlag = RTWDOG_CS_FLG_MASK,
104 };
105
106 /*******************************************************************************
107 * API
108 *******************************************************************************/
109
110 #if defined(__cplusplus)
111 extern "C" {
112 #endif /* __cplusplus */
113
142 void RTWDOG_GetDefaultConfig(rtwdog_config_t *config);
143
163 void RTWDOG_Init(RTWDOG_Type *base, const rtwdog_config_t *config);
164
173 void RTWDOG_Deinit(RTWDOG_Type *base);
174
191 static inline void RTWDOG_Enable(RTWDOG_Type *base)
192 {
193 base->CS |= RTWDOG_CS_EN_MASK;
194 }
195
205 static inline void RTWDOG_Disable(RTWDOG_Type *base)
206 {
207 base->CS &= ~RTWDOG_CS_EN_MASK;
208 }
209
222 static inline void RTWDOG_EnableInterrupts(RTWDOG_Type *base, uint32_t mask)
223 {
224 base->CS |= mask;
225 }
226
239 static inline void RTWDOG_DisableInterrupts(RTWDOG_Type *base, uint32_t mask)
240 {
241 base->CS &= ~mask;
242 }
243
259 static inline uint32_t RTWDOG_GetStatusFlags(RTWDOG_Type *base)
260 {
261 return (base->CS & (RTWDOG_CS_EN_MASK | RTWDOG_CS_FLG_MASK));
262 }
263
278 void RTWDOG_ClearStatusFlags(RTWDOG_Type *base, uint32_t mask);
279
290 static inline void RTWDOG_SetTimeoutValue(RTWDOG_Type *base, uint16_t timeoutCount)
291 {
292 base->TOVAL = timeoutCount;
293 }
294
305 static inline void RTWDOG_SetWindowValue(RTWDOG_Type *base, uint16_t windowValue)
306 {
307 base->WIN = windowValue;
308 }
309
321 static inline void RTWDOG_Unlock(RTWDOG_Type *base)
322 {
323 if ((base->CS) & RTWDOG_CS_CMD32EN_MASK)
324 {
325 base->CNT = RTWDOG_UPDATE_KEY;
326 }
327 else
328 {
329 base->CNT = WDOG_FIRST_WORD_OF_UNLOCK;
330 base->CNT = WDOG_SECOND_WORD_OF_UNLOCK;
331 }
332 }
333
342 static inline void RTWDOG_Refresh(RTWDOG_Type *base)
343 {
344 if ((base->CS) & RTWDOG_CS_CMD32EN_MASK)
345 {
346 base->CNT = RTWDOG_REFRESH_KEY;
347 }
348 else
349 {
350 base->CNT = WDOG_FIRST_WORD_OF_REFRESH;
351 base->CNT = WDOG_SECOND_WORD_OF_REFRESH;
352 }
353 }
354
363 static inline uint16_t RTWDOG_GetCounterValue(RTWDOG_Type *base)
364 {
365 return base->CNT;
366 }
367
370 #if defined(__cplusplus)
371 }
372 #endif /* __cplusplus */
373
376 #endif /* _FSL_RTWDOG_H_ */
_rtwdog_work_mode::enableDebug
bool enableDebug
Definition: fsl_rtwdog.h:57
WDOG_FIRST_WORD_OF_REFRESH
#define WDOG_FIRST_WORD_OF_REFRESH
Definition: fsl_rtwdog.h:27
RTWDOG_Enable
static void RTWDOG_Enable(RTWDOG_Type *base)
Enables the RTWDOG module.
Definition: fsl_rtwdog.h:189
kRTWDOG_ClockPrescalerDivide256
Definition: fsl_rtwdog.h:49
kRTWDOG_ClockSource3
Definition: fsl_rtwdog.h:42
rtwdog_config_t
struct _rtwdog_config rtwdog_config_t
Describes RTWDOG configuration structure.
RTWDOG_Type
Definition: MIMXRT1062.h:36144
_rtwdog_config::clockSource
rtwdog_clock_source_t clockSource
Definition: fsl_rtwdog.h:73
_rtwdog_clock_prescaler
_rtwdog_clock_prescaler
Describes the selection of the clock prescaler.
Definition: fsl_rtwdog.h:46
kRTWDOG_RunningFlag
Definition: fsl_rtwdog.h:101
RTWDOG_CS_INT_MASK
#define RTWDOG_CS_INT_MASK
Definition: MIMXRT1062.h:36200
RTWDOG_CS_FLG_MASK
#define RTWDOG_CS_FLG_MASK
Definition: MIMXRT1062.h:36251
RTWDOG_Deinit
void RTWDOG_Deinit(RTWDOG_Type *base)
De-initializes the RTWDOG module.
Definition: bl_api.c:275
RTWDOG_Type::TOVAL
__IO uint32_t TOVAL
Definition: MIMXRT1062.h:36147
kRTWDOG_InterruptFlag
Definition: fsl_rtwdog.h:102
_rtwdog_work_mode::enableWait
bool enableWait
Definition: fsl_rtwdog.h:55
_rtwdog_config::workMode
rtwdog_work_mode_t workMode
Definition: fsl_rtwdog.h:75
_rtwdog_config::testMode
rtwdog_test_mode_t testMode
Definition: fsl_rtwdog.h:76
_rtwdog_work_mode
Defines RTWDOG work mode.
Definition: fsl_rtwdog.h:53
_rtwdog_config::enableRtwdog
bool enableRtwdog
Definition: fsl_rtwdog.h:72
_rtwdog_config::enableWindowMode
bool enableWindowMode
Definition: fsl_rtwdog.h:79
kRTWDOG_ClockSource2
Definition: fsl_rtwdog.h:41
RTWDOG_DisableInterrupts
static void RTWDOG_DisableInterrupts(RTWDOG_Type *base, uint32_t mask)
Disables the RTWDOG interrupt.
Definition: fsl_rtwdog.h:237
_rtwdog_test_mode
_rtwdog_test_mode
Describes RTWDOG test mode.
Definition: fsl_rtwdog.h:61
RTWDOG_GetCounterValue
static uint16_t RTWDOG_GetCounterValue(RTWDOG_Type *base)
Gets the RTWDOG counter value.
Definition: fsl_rtwdog.h:361
WDOG_SECOND_WORD_OF_REFRESH
#define WDOG_SECOND_WORD_OF_REFRESH
Definition: fsl_rtwdog.h:28
RTWDOG_SetTimeoutValue
static void RTWDOG_SetTimeoutValue(RTWDOG_Type *base, uint16_t timeoutCount)
Sets the RTWDOG timeout value.
Definition: fsl_rtwdog.h:288
kRTWDOG_InterruptEnable
Definition: fsl_rtwdog.h:91
WDOG_SECOND_WORD_OF_UNLOCK
#define WDOG_SECOND_WORD_OF_UNLOCK
Definition: fsl_rtwdog.h:22
kRTWDOG_LowByteTest
Definition: fsl_rtwdog.h:65
_rtwdog_status_flags_t
_rtwdog_status_flags_t
RTWDOG status flags.
Definition: fsl_rtwdog.h:99
kRTWDOG_TestModeDisabled
Definition: fsl_rtwdog.h:63
_rtwdog_config::timeoutValue
uint16_t timeoutValue
Definition: fsl_rtwdog.h:81
RTWDOG_Type::CNT
__IO uint32_t CNT
Definition: MIMXRT1062.h:36146
RTWDOG_CS_CMD32EN_MASK
#define RTWDOG_CS_CMD32EN_MASK
Definition: MIMXRT1062.h:36244
_rtwdog_clock_source
_rtwdog_clock_source
Describes RTWDOG clock source.
Definition: fsl_rtwdog.h:37
RTWDOG_UPDATE_KEY
#define RTWDOG_UPDATE_KEY
Definition: MIMXRT1062.h:36327
_rtwdog_work_mode::enableStop
bool enableStop
Definition: fsl_rtwdog.h:56
RTWDOG_ClearStatusFlags
void RTWDOG_ClearStatusFlags(RTWDOG_Type *base, uint32_t mask)
Clears the RTWDOG flag.
Definition: bl_api.c:260
rtwdog_work_mode_t
struct _rtwdog_work_mode rtwdog_work_mode_t
Defines RTWDOG work mode.
rtwdog_clock_source_t
enum _rtwdog_clock_source rtwdog_clock_source_t
Describes RTWDOG clock source.
kRTWDOG_HighByteTest
Definition: fsl_rtwdog.h:66
_rtwdog_config::windowValue
uint16_t windowValue
Definition: fsl_rtwdog.h:80
RTWDOG_Disable
static void RTWDOG_Disable(RTWDOG_Type *base)
Disables the RTWDOG module.
Definition: fsl_rtwdog.h:203
RTWDOG_Refresh
static void RTWDOG_Refresh(RTWDOG_Type *base)
Refreshes the RTWDOG timer.
Definition: fsl_rtwdog.h:340
kRTWDOG_ClockSource1
Definition: fsl_rtwdog.h:40
RTWDOG_Init
void RTWDOG_Init(RTWDOG_Type *base, const rtwdog_config_t *config)
Initializes the RTWDOG module.
Definition: bl_api.c:270
RTWDOG_GetStatusFlags
static uint32_t RTWDOG_GetStatusFlags(RTWDOG_Type *base)
Gets the RTWDOG all status flags.
Definition: fsl_rtwdog.h:257
RTWDOG_SetWindowValue
static void RTWDOG_SetWindowValue(RTWDOG_Type *base, uint16_t windowValue)
Sets the RTWDOG window value.
Definition: fsl_rtwdog.h:303
RTWDOG_CS_EN_MASK
#define RTWDOG_CS_EN_MASK
Definition: MIMXRT1062.h:36207
RTWDOG_Type::WIN
__IO uint32_t WIN
Definition: MIMXRT1062.h:36148
kRTWDOG_ClockSource0
Definition: fsl_rtwdog.h:39
WDOG_FIRST_WORD_OF_UNLOCK
#define WDOG_FIRST_WORD_OF_UNLOCK
Definition: fsl_rtwdog.h:21
RTWDOG_REFRESH_KEY
#define RTWDOG_REFRESH_KEY
Definition: MIMXRT1062.h:36328
_rtwdog_config::enableInterrupt
bool enableInterrupt
Definition: fsl_rtwdog.h:78
RTWDOG_Unlock
static void RTWDOG_Unlock(RTWDOG_Type *base)
Unlocks the RTWDOG register written.
Definition: fsl_rtwdog.h:319
rtwdog_clock_prescaler_t
enum _rtwdog_clock_prescaler rtwdog_clock_prescaler_t
Describes the selection of the clock prescaler.
RTWDOG_EnableInterrupts
static void RTWDOG_EnableInterrupts(RTWDOG_Type *base, uint32_t mask)
Enables the RTWDOG interrupt.
Definition: fsl_rtwdog.h:220
_rtwdog_config::enableUpdate
bool enableUpdate
Definition: fsl_rtwdog.h:77
kRTWDOG_UserModeEnabled
Definition: fsl_rtwdog.h:64
RTWDOG_GetDefaultConfig
void RTWDOG_GetDefaultConfig(rtwdog_config_t *config)
Initializes the RTWDOG configuration structure.
Definition: bl_api.c:265
_rtwdog_config
Describes RTWDOG configuration structure.
Definition: fsl_rtwdog.h:70
rtwdog_test_mode_t
enum _rtwdog_test_mode rtwdog_test_mode_t
Describes RTWDOG test mode.
_rtwdog_interrupt_enable_t
_rtwdog_interrupt_enable_t
RTWDOG interrupt configuration structure.
Definition: fsl_rtwdog.h:89
RTWDOG_Type::CS
__IO uint32_t CS
Definition: MIMXRT1062.h:36145
_rtwdog_config::prescaler
rtwdog_clock_prescaler_t prescaler
Definition: fsl_rtwdog.h:74
kRTWDOG_ClockPrescalerDivide1
Definition: fsl_rtwdog.h:48