Callisto4Bootloader: drivers/fsl_wdog.c Source File

Callisto4Bootloader

fsl_wdog.c
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2016, Freescale Semiconductor, Inc.
3 * Copyright 2016-2019 NXP
4 * All rights reserved.
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9 #include "fsl_wdog.h"
10
11 /* Component ID definition, used by tools. */
12 #ifndef FSL_COMPONENT_ID
13 #define FSL_COMPONENT_ID "platform.drivers.wdog01"
14 #endif
15
16 /*******************************************************************************
17 * Variables
18 ******************************************************************************/
19 static WDOG_Type *const s_wdogBases[] = WDOG_BASE_PTRS;
20 #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
21 /* Array of WDOG clock name. */
22 static const clock_ip_name_t s_wdogClock[] = WDOG_CLOCKS;
23 #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
24
25 static const IRQn_Type s_wdogIRQ[] = WDOG_IRQS;
26
27 /*******************************************************************************
28 * Code
29 ******************************************************************************/
30 static uint32_t WDOG_GetInstance(WDOG_Type *base)
31 {
32 uint32_t instance;
33
34 /* Find the instance index from base address mappings. */
35 for (instance = 0; instance < ARRAY_SIZE(s_wdogBases); instance++)
36 {
37 if (s_wdogBases[instance] == base)
38 {
39 break;
40 }
41 }
42
43 assert(instance < ARRAY_SIZE(s_wdogBases));
44
45 return instance;
46 }
47 #if 0
48
68 void WDOG_GetDefaultConfig(wdog_config_t *config)
69 {
70 assert(NULL != config);
71
72 /* Initializes the configure structure to zero. */
73 (void)memset(config, 0, sizeof(*config));
74
75 config->enableWdog = true;
76 config->workMode.enableWait = false;
77 config->workMode.enableStop = false;
78 config->workMode.enableDebug = false;
79 config->enableInterrupt = false;
80 config->softwareResetExtension = false;
81 config->enablePowerDown = false;
82 config->timeoutValue = 0xffu;
83 config->interruptTimeValue = 0x04u;
84 config->enableTimeOutAssert = false;
85 }
86
104 void WDOG_Init(WDOG_Type *base, const wdog_config_t *config)
105 {
106 assert(NULL != config);
107
108 uint16_t value = 0u;
109 uint32_t primaskValue = 0U;
110
111 value = WDOG_WCR_WDE(config->enableWdog) | WDOG_WCR_WDW(config->workMode.enableWait) |
112 WDOG_WCR_WDZST(config->workMode.enableStop) | WDOG_WCR_WDBG(config->workMode.enableDebug) |
113 WDOG_WCR_SRE(config->softwareResetExtension) | WDOG_WCR_WT(config->timeoutValue) |
114 WDOG_WCR_WDT(config->enableTimeOutAssert) | WDOG_WCR_SRS_MASK | WDOG_WCR_WDA_MASK;
115
116 #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
117 /* Set configuration */
118 CLOCK_EnableClock(s_wdogClock[WDOG_GetInstance(base)]);
119 #endif
120
121 primaskValue = DisableGlobalIRQ();
122 base->WICR = WDOG_WICR_WICT(config->interruptTimeValue) | WDOG_WICR_WIE(config->enableInterrupt);
123 base->WMCR = WDOG_WMCR_PDE(config->enablePowerDown);
124 base->WCR = value;
125 EnableGlobalIRQ(primaskValue);
126 if (config->enableInterrupt)
127 {
128 (void)EnableIRQ(s_wdogIRQ[WDOG_GetInstance(base)]);
129 }
130 }
131
140 void WDOG_Deinit(WDOG_Type *base)
141 {
142 if (0U != (base->WCR & WDOG_WCR_WDBG_MASK))
143 {
144 WDOG_Disable(base);
145 }
146 }
147
162 uint16_t WDOG_GetStatusFlags(WDOG_Type *base)
163 {
164 uint16_t status_flag = 0U;
165
166 status_flag |= (base->WCR & WDOG_WCR_WDE_MASK);
167 status_flag |= (base->WRSR & WDOG_WRSR_POR_MASK);
168 status_flag |= (base->WRSR & WDOG_WRSR_TOUT_MASK);
169 status_flag |= (base->WRSR & WDOG_WRSR_SFTW_MASK);
170 status_flag |= (base->WICR & WDOG_WICR_WTIS_MASK);
171
172 return status_flag;
173 }
174
189 void WDOG_ClearInterruptStatus(WDOG_Type *base, uint16_t mask)
190 {
191 if (0U != (mask & (uint16_t)kWDOG_InterruptFlag))
192 {
193 base->WICR |= WDOG_WICR_WTIS_MASK;
194 }
195 }
196
205 void WDOG_Refresh(WDOG_Type *base)
206 {
207 uint32_t primaskValue = 0U;
208
209 /* Disable the global interrupt to protect refresh sequence */
210 primaskValue = DisableGlobalIRQ();
211 base->WSR = WDOG_REFRESH_KEY & 0xFFFFU;
212 base->WSR = (WDOG_REFRESH_KEY >> 16U) & 0xFFFFU;
213 EnableGlobalIRQ(primaskValue);
214 }
215 #endif
WDOG_Type::WCR
__IO uint16_t WCR
Definition: MIMXRT1062.h:46322
NULL
#define NULL
Definition: bootloader_common.h:26
WDOG_WCR_WDBG
#define WDOG_WCR_WDBG(x)
Definition: MIMXRT1062.h:46353
_wdog_config::enableTimeOutAssert
bool enableTimeOutAssert
Definition: fsl_wdog.h:48
WDOG_WCR_SRS_MASK
#define WDOG_WCR_SRS_MASK
Definition: MIMXRT1062.h:46368
WDOG_GetStatusFlags
uint16_t WDOG_GetStatusFlags(WDOG_Type *base)
Gets the WDOG all reset status flags.
Definition: bl_api.c:298
WDOG_WICR_WICT
#define WDOG_WICR_WICT(x)
Definition: MIMXRT1062.h:46454
_wdog_config::workMode
wdog_work_mode_t workMode
Definition: fsl_wdog.h:42
WDOG_WMCR_PDE
#define WDOG_WMCR_PDE(x)
Definition: MIMXRT1062.h:46479
s_wdogBases
static WDOG_Type *const s_wdogBases[]
Definition: fsl_wdog.c:18
WDOG_Type::WMCR
__IO uint16_t WMCR
Definition: MIMXRT1062.h:46326
WDOG_WCR_WDA_MASK
#define WDOG_WCR_WDA_MASK
Definition: MIMXRT1062.h:46375
_wdog_work_mode::enableStop
bool enableStop
Definition: fsl_wdog.h:34
WDOG_WCR_WDE_MASK
#define WDOG_WCR_WDE_MASK
Definition: MIMXRT1062.h:46354
WDOG_Type::WRSR
__I uint16_t WRSR
Definition: MIMXRT1062.h:46324
WDOG_Disable
static void WDOG_Disable(WDOG_Type *base)
Disables the WDOG module.
Definition: fsl_wdog.h:159
WDOG_WCR_WT
#define WDOG_WCR_WT(x)
Definition: MIMXRT1062.h:46405
WDOG_WRSR_SFTW_MASK
#define WDOG_WRSR_SFTW_MASK
Definition: MIMXRT1062.h:46421
fsl_wdog.h
WDOG_Type::WSR
__IO uint16_t WSR
Definition: MIMXRT1062.h:46323
_wdog_config::enableInterrupt
bool enableInterrupt
Definition: fsl_wdog.h:43
kWDOG_InterruptFlag
Definition: fsl_wdog.h:72
_wdog_config::enableWdog
bool enableWdog
Definition: fsl_wdog.h:41
ARRAY_SIZE
#define ARRAY_SIZE(x)
Computes the number of elements in an array.
Definition: bootloader_common.h:49
WDOG_Type
Definition: MIMXRT1062.h:46321
IRQn_Type
enum IRQn IRQn_Type
s_wdogClock
static const clock_ip_name_t s_wdogClock[]
Definition: fsl_wdog.c:21
WDOG_GetDefaultConfig
void WDOG_GetDefaultConfig(wdog_config_t *config)
Initializes the WDOG configuration structure.
Definition: bl_api.c:283
WDOG_WCR_WDW
#define WDOG_WCR_WDW(x)
Definition: MIMXRT1062.h:46395
_wdog_config::interruptTimeValue
uint16_t interruptTimeValue
Definition: fsl_wdog.h:45
_wdog_work_mode::enableDebug
bool enableDebug
Definition: fsl_wdog.h:35
WDOG_BASE_PTRS
#define WDOG_BASE_PTRS
Definition: MIMXRT1062.h:46500
_wdog_config::softwareResetExtension
bool softwareResetExtension
Definition: fsl_wdog.h:46
WDOG_GetInstance
static uint32_t WDOG_GetInstance(WDOG_Type *base)
Definition: fsl_wdog.c:28
s_wdogIRQ
static const IRQn_Type s_wdogIRQ[]
Definition: fsl_wdog.c:24
_wdog_config::timeoutValue
uint16_t timeoutValue
Definition: fsl_wdog.h:44
WDOG_REFRESH_KEY
#define WDOG_REFRESH_KEY
Definition: fsl_wdog.h:27
WDOG_ClearInterruptStatus
void WDOG_ClearInterruptStatus(WDOG_Type *base, uint16_t mask)
Clears the WDOG flag.
Definition: bl_api.c:303
_wdog_work_mode::enableWait
bool enableWait
Definition: fsl_wdog.h:33
WDOG_WCR_WDBG_MASK
#define WDOG_WCR_WDBG_MASK
Definition: MIMXRT1062.h:46347
_wdog_config
Describes WDOG configuration structure.
Definition: fsl_wdog.h:39
WDOG_Deinit
void WDOG_Deinit(WDOG_Type *base)
Shuts down the WDOG.
Definition: bl_api.c:293
WDOG_Init
void WDOG_Init(WDOG_Type *base, const wdog_config_t *config)
Initializes the WDOG.
Definition: bl_api.c:288
WDOG_WCR_WDZST
#define WDOG_WCR_WDZST(x)
Definition: MIMXRT1062.h:46346
WDOG_WCR_SRE
#define WDOG_WCR_SRE(x)
Definition: MIMXRT1062.h:46388
WDOG_WCR_WDE
#define WDOG_WCR_WDE(x)
Definition: MIMXRT1062.h:46360
_wdog_config::enablePowerDown
bool enablePowerDown
Definition: fsl_wdog.h:47
WDOG_WRSR_TOUT_MASK
#define WDOG_WRSR_TOUT_MASK
Definition: MIMXRT1062.h:46428
WDOG_WCR_WDT
#define WDOG_WCR_WDT(x)
Definition: MIMXRT1062.h:46367
WDOG_WICR_WIE
#define WDOG_WICR_WIE(x)
Definition: MIMXRT1062.h:46468
WDOG_IRQS
#define WDOG_IRQS
Definition: MIMXRT1062.h:46502
WDOG_Type::WICR
__IO uint16_t WICR
Definition: MIMXRT1062.h:46325
WDOG_WICR_WTIS_MASK
#define WDOG_WICR_WTIS_MASK
Definition: MIMXRT1062.h:46455
WDOG_WRSR_POR_MASK
#define WDOG_WRSR_POR_MASK
Definition: MIMXRT1062.h:46435
WDOG_Refresh
void WDOG_Refresh(WDOG_Type *base)
Refreshes the WDOG timer.
Definition: bl_api.c:308