![]() |
|
|||
File indexing completed on 2025-05-11 08:23:01
0001 /* 0002 * Copyright (c) 2016, Freescale Semiconductor, Inc. 0003 * Copyright 2016-2020 NXP 0004 * All rights reserved. 0005 * 0006 * SPDX-License-Identifier: BSD-3-Clause 0007 */ 0008 #ifndef _FSL_RTWDOG_H_ 0009 #define _FSL_RTWDOG_H_ 0010 0011 #include "fsl_common.h" 0012 0013 /*! 0014 * @addtogroup rtwdog 0015 * @{ 0016 */ 0017 0018 /******************************************************************************* 0019 * Definitions 0020 *******************************************************************************/ 0021 /*! @name Unlock sequence */ 0022 /*@{*/ 0023 #define WDOG_FIRST_WORD_OF_UNLOCK (RTWDOG_UPDATE_KEY & 0xFFFFU) /*!< First word of unlock sequence */ 0024 #define WDOG_SECOND_WORD_OF_UNLOCK ((RTWDOG_UPDATE_KEY >> 16U) & 0xFFFFU) /*!< Second word of unlock sequence */ 0025 /*@}*/ 0026 0027 /*! @name Refresh sequence */ 0028 /*@{*/ 0029 #define WDOG_FIRST_WORD_OF_REFRESH (RTWDOG_REFRESH_KEY & 0xFFFFU) /*!< First word of refresh sequence */ 0030 #define WDOG_SECOND_WORD_OF_REFRESH ((RTWDOG_REFRESH_KEY >> 16U) & 0xFFFFU) /*!< Second word of refresh sequence */ 0031 /*@}*/ 0032 /*! @name Driver version */ 0033 /*@{*/ 0034 /*! @brief RTWDOG driver version 2.1.2. */ 0035 #define FSL_RTWDOG_DRIVER_VERSION (MAKE_VERSION(2, 1, 2)) 0036 /*@}*/ 0037 0038 /*! @brief Describes RTWDOG clock source. */ 0039 typedef enum _rtwdog_clock_source 0040 { 0041 kRTWDOG_ClockSource0 = 0U, /*!< Clock source 0 */ 0042 kRTWDOG_ClockSource1 = 1U, /*!< Clock source 1 */ 0043 kRTWDOG_ClockSource2 = 2U, /*!< Clock source 2 */ 0044 kRTWDOG_ClockSource3 = 3U, /*!< Clock source 3 */ 0045 } rtwdog_clock_source_t; 0046 0047 /*! @brief Describes the selection of the clock prescaler. */ 0048 typedef enum _rtwdog_clock_prescaler 0049 { 0050 kRTWDOG_ClockPrescalerDivide1 = 0x0U, /*!< Divided by 1 */ 0051 kRTWDOG_ClockPrescalerDivide256 = 0x1U, /*!< Divided by 256 */ 0052 } rtwdog_clock_prescaler_t; 0053 0054 /*! @brief Defines RTWDOG work mode. */ 0055 typedef struct _rtwdog_work_mode 0056 { 0057 bool enableWait; /*!< Enables or disables RTWDOG in wait mode */ 0058 bool enableStop; /*!< Enables or disables RTWDOG in stop mode */ 0059 bool enableDebug; /*!< Enables or disables RTWDOG in debug mode */ 0060 } rtwdog_work_mode_t; 0061 0062 /*! @brief Describes RTWDOG test mode. */ 0063 typedef enum _rtwdog_test_mode 0064 { 0065 kRTWDOG_TestModeDisabled = 0U, /*!< Test Mode disabled */ 0066 kRTWDOG_UserModeEnabled = 1U, /*!< User Mode enabled */ 0067 kRTWDOG_LowByteTest = 2U, /*!< Test Mode enabled, only low byte is used */ 0068 kRTWDOG_HighByteTest = 3U, /*!< Test Mode enabled, only high byte is used */ 0069 } rtwdog_test_mode_t; 0070 0071 /*! @brief Describes RTWDOG configuration structure. */ 0072 typedef struct _rtwdog_config 0073 { 0074 bool enableRtwdog; /*!< Enables or disables RTWDOG */ 0075 rtwdog_clock_source_t clockSource; /*!< Clock source select */ 0076 rtwdog_clock_prescaler_t prescaler; /*!< Clock prescaler value */ 0077 rtwdog_work_mode_t workMode; /*!< Configures RTWDOG work mode in debug stop and wait mode */ 0078 rtwdog_test_mode_t testMode; /*!< Configures RTWDOG test mode */ 0079 bool enableUpdate; /*!< Update write-once register enable */ 0080 bool enableInterrupt; /*!< Enables or disables RTWDOG interrupt */ 0081 bool enableWindowMode; /*!< Enables or disables RTWDOG window mode */ 0082 uint16_t windowValue; /*!< Window value */ 0083 uint16_t timeoutValue; /*!< Timeout value */ 0084 } rtwdog_config_t; 0085 0086 /*! 0087 * @brief RTWDOG interrupt configuration structure. 0088 * 0089 * This structure contains the settings for all of the RTWDOG interrupt configurations. 0090 */ 0091 enum _rtwdog_interrupt_enable_t 0092 { 0093 kRTWDOG_InterruptEnable = RTWDOG_CS_INT_MASK, /*!< Interrupt is generated before forcing a reset */ 0094 }; 0095 0096 /*! 0097 * @brief RTWDOG status flags. 0098 * 0099 * This structure contains the RTWDOG status flags for use in the RTWDOG functions. 0100 */ 0101 enum _rtwdog_status_flags_t 0102 { 0103 kRTWDOG_RunningFlag = RTWDOG_CS_EN_MASK, /*!< Running flag, set when RTWDOG is enabled */ 0104 kRTWDOG_InterruptFlag = RTWDOG_CS_FLG_MASK, /*!< Interrupt flag, set when interrupt occurs */ 0105 }; 0106 0107 /******************************************************************************* 0108 * API 0109 *******************************************************************************/ 0110 0111 #if defined(__cplusplus) 0112 extern "C" { 0113 #endif /* __cplusplus */ 0114 0115 /*! 0116 * @name RTWDOG Initialization and De-initialization 0117 * @{ 0118 */ 0119 0120 /*! 0121 * @brief Initializes the RTWDOG configuration structure. 0122 * 0123 * This function initializes the RTWDOG configuration structure to default values. The default 0124 * values are: 0125 * @code 0126 * rtwdogConfig->enableRtwdog = true; 0127 * rtwdogConfig->clockSource = kRTWDOG_ClockSource1; 0128 * rtwdogConfig->prescaler = kRTWDOG_ClockPrescalerDivide1; 0129 * rtwdogConfig->workMode.enableWait = true; 0130 * rtwdogConfig->workMode.enableStop = false; 0131 * rtwdogConfig->workMode.enableDebug = false; 0132 * rtwdogConfig->testMode = kRTWDOG_TestModeDisabled; 0133 * rtwdogConfig->enableUpdate = true; 0134 * rtwdogConfig->enableInterrupt = false; 0135 * rtwdogConfig->enableWindowMode = false; 0136 * rtwdogConfig->windowValue = 0U; 0137 * rtwdogConfig->timeoutValue = 0xFFFFU; 0138 * @endcode 0139 * 0140 * @param config Pointer to the RTWDOG configuration structure. 0141 * @see rtwdog_config_t 0142 */ 0143 void RTWDOG_GetDefaultConfig(rtwdog_config_t *config); 0144 0145 /*! 0146 * @brief Initializes the RTWDOG module. 0147 * 0148 * This function initializes the RTWDOG. 0149 * To reconfigure the RTWDOG without forcing a reset first, enableUpdate must be set to true 0150 * in the configuration. 0151 * 0152 * Example: 0153 * @code 0154 * rtwdog_config_t config; 0155 * RTWDOG_GetDefaultConfig(&config); 0156 * config.timeoutValue = 0x7ffU; 0157 * config.enableUpdate = true; 0158 * RTWDOG_Init(wdog_base,&config); 0159 * @endcode 0160 * 0161 * @param base RTWDOG peripheral base address. 0162 * @param config The configuration of the RTWDOG. 0163 */ 0164 0165 #if defined(DOXYGEN_OUTPUT) && DOXYGEN_OUTPUT 0166 void RTWDOG_Init(RTWDOG_Type *base, const rtwdog_config_t *config); 0167 #else 0168 AT_QUICKACCESS_SECTION_CODE(void RTWDOG_Init(RTWDOG_Type *base, const rtwdog_config_t *config)); 0169 #endif 0170 0171 /*! 0172 * @brief De-initializes the RTWDOG module. 0173 * 0174 * This function shuts down the RTWDOG. 0175 * Ensure that the WDOG_CS.UPDATE is 1, which means that the register update is enabled. 0176 * 0177 * @param base RTWDOG peripheral base address. 0178 */ 0179 void RTWDOG_Deinit(RTWDOG_Type *base); 0180 0181 /* @} */ 0182 0183 /*! 0184 * @name RTWDOG functional Operation 0185 * @{ 0186 */ 0187 0188 /*! 0189 * @brief Enables the RTWDOG module. 0190 * 0191 * This function writes a value into the WDOG_CS register to enable the RTWDOG. 0192 * The WDOG_CS register is a write-once register. Ensure that the WCT window is still open and 0193 * this register has not been written in this WCT while the function is called. 0194 * 0195 * @param base RTWDOG peripheral base address. 0196 */ 0197 static inline void RTWDOG_Enable(RTWDOG_Type *base) 0198 { 0199 base->CS |= RTWDOG_CS_EN_MASK; 0200 } 0201 0202 /*! 0203 * @brief Disables the RTWDOG module. 0204 * 0205 * This function writes a value into the WDOG_CS register to disable the RTWDOG. 0206 * The WDOG_CS register is a write-once register. Ensure that the WCT window is still open and 0207 * this register has not been written in this WCT while the function is called. 0208 * 0209 * @param base RTWDOG peripheral base address 0210 */ 0211 static inline void RTWDOG_Disable(RTWDOG_Type *base) 0212 { 0213 base->CS &= ~RTWDOG_CS_EN_MASK; 0214 } 0215 0216 /*! 0217 * @brief Enables the RTWDOG interrupt. 0218 * 0219 * This function writes a value into the WDOG_CS register to enable the RTWDOG interrupt. 0220 * The WDOG_CS register is a write-once register. Ensure that the WCT window is still open and 0221 * this register has not been written in this WCT while the function is called. 0222 * 0223 * @param base RTWDOG peripheral base address. 0224 * @param mask The interrupts to enable. 0225 * The parameter can be a combination of the following source if defined: 0226 * @arg kRTWDOG_InterruptEnable 0227 */ 0228 static inline void RTWDOG_EnableInterrupts(RTWDOG_Type *base, uint32_t mask) 0229 { 0230 base->CS |= mask; 0231 } 0232 0233 /*! 0234 * @brief Disables the RTWDOG interrupt. 0235 * 0236 * This function writes a value into the WDOG_CS register to disable the RTWDOG interrupt. 0237 * The WDOG_CS register is a write-once register. Ensure that the WCT window is still open and 0238 * this register has not been written in this WCT while the function is called. 0239 * 0240 * @param base RTWDOG peripheral base address. 0241 * @param mask The interrupts to disabled. 0242 * The parameter can be a combination of the following source if defined: 0243 * @arg kRTWDOG_InterruptEnable 0244 */ 0245 static inline void RTWDOG_DisableInterrupts(RTWDOG_Type *base, uint32_t mask) 0246 { 0247 base->CS &= ~mask; 0248 } 0249 0250 /*! 0251 * @brief Gets the RTWDOG all status flags. 0252 * 0253 * This function gets all status flags. 0254 * 0255 * Example to get the running flag: 0256 * @code 0257 * uint32_t status; 0258 * status = RTWDOG_GetStatusFlags(wdog_base) & kRTWDOG_RunningFlag; 0259 * @endcode 0260 * @param base RTWDOG peripheral base address 0261 * @return State of the status flag: asserted (true) or not-asserted (false). @see _rtwdog_status_flags_t 0262 * - true: related status flag has been set. 0263 * - false: related status flag is not set. 0264 */ 0265 static inline uint32_t RTWDOG_GetStatusFlags(RTWDOG_Type *base) 0266 { 0267 return (base->CS & (RTWDOG_CS_EN_MASK | RTWDOG_CS_FLG_MASK)); 0268 } 0269 0270 /*! 0271 * @brief Enables/disables the window mode. 0272 * 0273 * @param base RTWDOG peripheral base address. 0274 * @param enable Enables(true) or disables(false) the feature. 0275 */ 0276 static inline void RTWDOG_EnableWindowMode(RTWDOG_Type *base, bool enable) 0277 { 0278 if (enable) 0279 { 0280 base->CS |= RTWDOG_CS_WIN_MASK; 0281 } 0282 else 0283 { 0284 base->CS &= ~RTWDOG_CS_WIN_MASK; 0285 } 0286 } 0287 0288 /*! 0289 * @brief Converts raw count value to millisecond. 0290 * 0291 * Note that if the clock frequency is too high the timeout period can be less than 1 ms. 0292 * In this case this api will return 0 value. 0293 * 0294 * @param base RTWDOG peripheral base address. 0295 * @param count Raw count value. 0296 * @param clockFreqInHz The frequency of the clock source RTWDOG uses. 0297 */ 0298 static inline uint32_t RTWDOG_CountToMesec(RTWDOG_Type *base, uint32_t count, uint32_t clockFreqInHz) 0299 { 0300 if ((base->CS & RTWDOG_CS_PRES_MASK) != 0U) 0301 { 0302 clockFreqInHz /= 256U; 0303 } 0304 return count * 1000U / clockFreqInHz; 0305 } 0306 0307 /*! 0308 * @brief Clears the RTWDOG flag. 0309 * 0310 * This function clears the RTWDOG status flag. 0311 * 0312 * Example to clear an interrupt flag: 0313 * @code 0314 * RTWDOG_ClearStatusFlags(wdog_base,kRTWDOG_InterruptFlag); 0315 * @endcode 0316 * @param base RTWDOG peripheral base address. 0317 * @param mask The status flags to clear. 0318 * The parameter can be any combination of the following values: 0319 * @arg kRTWDOG_InterruptFlag 0320 */ 0321 void RTWDOG_ClearStatusFlags(RTWDOG_Type *base, uint32_t mask); 0322 0323 /*! 0324 * @brief Sets the RTWDOG timeout value. 0325 * 0326 * This function writes a timeout value into the WDOG_TOVAL register. 0327 * The WDOG_TOVAL register is a write-once register. Ensure that the WCT window is still open and 0328 * this register has not been written in this WCT while the function is called. 0329 * 0330 * @param base RTWDOG peripheral base address 0331 * @param timeoutCount RTWDOG timeout value, count of RTWDOG clock ticks. 0332 */ 0333 static inline void RTWDOG_SetTimeoutValue(RTWDOG_Type *base, uint16_t timeoutCount) 0334 { 0335 base->TOVAL = timeoutCount; 0336 } 0337 0338 /*! 0339 * @brief Sets the RTWDOG window value. 0340 * 0341 * This function writes a window value into the WDOG_WIN register. 0342 * The WDOG_WIN register is a write-once register. Ensure that the WCT window is still open and 0343 * this register has not been written in this WCT while the function is called. 0344 * 0345 * @param base RTWDOG peripheral base address. 0346 * @param windowValue RTWDOG window value. 0347 */ 0348 static inline void RTWDOG_SetWindowValue(RTWDOG_Type *base, uint16_t windowValue) 0349 { 0350 base->WIN = windowValue; 0351 } 0352 0353 /*! 0354 * @brief Unlocks the RTWDOG register written. 0355 * 0356 * This function unlocks the RTWDOG register written. 0357 * 0358 * Before starting the unlock sequence and following the configuration, disable the global interrupts. 0359 * Otherwise, an interrupt could effectively invalidate the unlock sequence and the WCT may expire. 0360 * After the configuration finishes, re-enable the global interrupts. 0361 * 0362 * @param base RTWDOG peripheral base address 0363 */ 0364 __STATIC_FORCEINLINE void RTWDOG_Unlock(RTWDOG_Type *base) 0365 { 0366 if (((base->CS) & RTWDOG_CS_CMD32EN_MASK) != 0U) 0367 { 0368 base->CNT = RTWDOG_UPDATE_KEY; 0369 } 0370 else 0371 { 0372 base->CNT = WDOG_FIRST_WORD_OF_UNLOCK; 0373 base->CNT = WDOG_SECOND_WORD_OF_UNLOCK; 0374 } 0375 while ((base->CS & RTWDOG_CS_ULK_MASK) == 0U) 0376 { 0377 } 0378 } 0379 0380 /*! 0381 * @brief Refreshes the RTWDOG timer. 0382 * 0383 * This function feeds the RTWDOG. 0384 * This function should be called before the Watchdog timer is in timeout. Otherwise, a reset is asserted. 0385 * 0386 * @param base RTWDOG peripheral base address 0387 */ 0388 static inline void RTWDOG_Refresh(RTWDOG_Type *base) 0389 { 0390 uint32_t primaskValue = 0U; 0391 primaskValue = DisableGlobalIRQ(); 0392 if (((base->CS) & RTWDOG_CS_CMD32EN_MASK) != 0U) 0393 { 0394 base->CNT = RTWDOG_REFRESH_KEY; 0395 } 0396 else 0397 { 0398 base->CNT = WDOG_FIRST_WORD_OF_REFRESH; 0399 base->CNT = WDOG_SECOND_WORD_OF_REFRESH; 0400 } 0401 EnableGlobalIRQ(primaskValue); 0402 } 0403 0404 /*! 0405 * @brief Gets the RTWDOG counter value. 0406 * 0407 * This function gets the RTWDOG counter value. 0408 * 0409 * @param base RTWDOG peripheral base address. 0410 * @return Current RTWDOG counter value. 0411 */ 0412 static inline uint16_t RTWDOG_GetCounterValue(RTWDOG_Type *base) 0413 { 0414 return (uint16_t)base->CNT; 0415 } 0416 0417 /*@}*/ 0418 0419 #if defined(__cplusplus) 0420 } 0421 #endif /* __cplusplus */ 0422 0423 /*! @}*/ 0424 0425 #endif /* _FSL_RTWDOG_H_ */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |