Manh Pham / Mbed OS Nucleo_rtos_basic_ir_controller
Committer:
manhpham
Date:
Sat Apr 07 09:22:54 2018 +0000
Revision:
0:c8673aa96267
Nucleo_rtos_basic_ir_controller

Who changed what in which revision?

UserRevisionLine numberNew contents of line
manhpham 0:c8673aa96267 1 /*
manhpham 0:c8673aa96267 2 * Copyright (c) 2015, Freescale Semiconductor, Inc.
manhpham 0:c8673aa96267 3 * All rights reserved.
manhpham 0:c8673aa96267 4 *
manhpham 0:c8673aa96267 5 * Redistribution and use in source and binary forms, with or without modification,
manhpham 0:c8673aa96267 6 * are permitted provided that the following conditions are met:
manhpham 0:c8673aa96267 7 *
manhpham 0:c8673aa96267 8 * o Redistributions of source code must retain the above copyright notice, this list
manhpham 0:c8673aa96267 9 * of conditions and the following disclaimer.
manhpham 0:c8673aa96267 10 *
manhpham 0:c8673aa96267 11 * o Redistributions in binary form must reproduce the above copyright notice, this
manhpham 0:c8673aa96267 12 * list of conditions and the following disclaimer in the documentation and/or
manhpham 0:c8673aa96267 13 * other materials provided with the distribution.
manhpham 0:c8673aa96267 14 *
manhpham 0:c8673aa96267 15 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
manhpham 0:c8673aa96267 16 * contributors may be used to endorse or promote products derived from this
manhpham 0:c8673aa96267 17 * software without specific prior written permission.
manhpham 0:c8673aa96267 18 *
manhpham 0:c8673aa96267 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
manhpham 0:c8673aa96267 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
manhpham 0:c8673aa96267 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
manhpham 0:c8673aa96267 22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
manhpham 0:c8673aa96267 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
manhpham 0:c8673aa96267 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
manhpham 0:c8673aa96267 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
manhpham 0:c8673aa96267 26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
manhpham 0:c8673aa96267 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
manhpham 0:c8673aa96267 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
manhpham 0:c8673aa96267 29 */
manhpham 0:c8673aa96267 30 #ifndef _FSL_WDOG_H_
manhpham 0:c8673aa96267 31 #define _FSL_WDOG_H_
manhpham 0:c8673aa96267 32
manhpham 0:c8673aa96267 33 #include "fsl_common.h"
manhpham 0:c8673aa96267 34
manhpham 0:c8673aa96267 35 /*!
manhpham 0:c8673aa96267 36 * @addtogroup wdog
manhpham 0:c8673aa96267 37 * @{
manhpham 0:c8673aa96267 38 */
manhpham 0:c8673aa96267 39
manhpham 0:c8673aa96267 40
manhpham 0:c8673aa96267 41 /*******************************************************************************
manhpham 0:c8673aa96267 42 * Definitions
manhpham 0:c8673aa96267 43 *******************************************************************************/
manhpham 0:c8673aa96267 44
manhpham 0:c8673aa96267 45 /*! @name Driver version */
manhpham 0:c8673aa96267 46 /*@{*/
manhpham 0:c8673aa96267 47 /*! @brief Defines WDOG driver version 2.0.0. */
manhpham 0:c8673aa96267 48 #define FSL_WDOG_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
manhpham 0:c8673aa96267 49 /*@}*/
manhpham 0:c8673aa96267 50
manhpham 0:c8673aa96267 51 /*! @name Unlock sequence */
manhpham 0:c8673aa96267 52 /*@{*/
manhpham 0:c8673aa96267 53 #define WDOG_FIRST_WORD_OF_UNLOCK (0xC520U) /*!< First word of unlock sequence */
manhpham 0:c8673aa96267 54 #define WDOG_SECOND_WORD_OF_UNLOCK (0xD928U) /*!< Second word of unlock sequence */
manhpham 0:c8673aa96267 55 /*@}*/
manhpham 0:c8673aa96267 56
manhpham 0:c8673aa96267 57 /*! @name Refresh sequence */
manhpham 0:c8673aa96267 58 /*@{*/
manhpham 0:c8673aa96267 59 #define WDOG_FIRST_WORD_OF_REFRESH (0xA602U) /*!< First word of refresh sequence */
manhpham 0:c8673aa96267 60 #define WDOG_SECOND_WORD_OF_REFRESH (0xB480U) /*!< Second word of refresh sequence */
manhpham 0:c8673aa96267 61 /*@}*/
manhpham 0:c8673aa96267 62
manhpham 0:c8673aa96267 63 /*! @brief Describes WDOG clock source. */
manhpham 0:c8673aa96267 64 typedef enum _wdog_clock_source
manhpham 0:c8673aa96267 65 {
manhpham 0:c8673aa96267 66 kWDOG_LpoClockSource = 0U, /*!< WDOG clock sourced from LPO*/
manhpham 0:c8673aa96267 67 kWDOG_AlternateClockSource = 1U, /*!< WDOG clock sourced from alternate clock source*/
manhpham 0:c8673aa96267 68 } wdog_clock_source_t;
manhpham 0:c8673aa96267 69
manhpham 0:c8673aa96267 70 /*! @brief Defines WDOG work mode. */
manhpham 0:c8673aa96267 71 typedef struct _wdog_work_mode
manhpham 0:c8673aa96267 72 {
manhpham 0:c8673aa96267 73 #if defined(FSL_FEATURE_WDOG_HAS_WAITEN) && FSL_FEATURE_WDOG_HAS_WAITEN
manhpham 0:c8673aa96267 74 bool enableWait; /*!< Enables or disables WDOG in wait mode */
manhpham 0:c8673aa96267 75 #endif /* FSL_FEATURE_WDOG_HAS_WAITEN */
manhpham 0:c8673aa96267 76 bool enableStop; /*!< Enables or disables WDOG in stop mode */
manhpham 0:c8673aa96267 77 bool enableDebug; /*!< Enables or disables WDOG in debug mode */
manhpham 0:c8673aa96267 78 } wdog_work_mode_t;
manhpham 0:c8673aa96267 79
manhpham 0:c8673aa96267 80 /*! @brief Describes the selection of the clock prescaler. */
manhpham 0:c8673aa96267 81 typedef enum _wdog_clock_prescaler
manhpham 0:c8673aa96267 82 {
manhpham 0:c8673aa96267 83 kWDOG_ClockPrescalerDivide1 = 0x0U, /*!< Divided by 1 */
manhpham 0:c8673aa96267 84 kWDOG_ClockPrescalerDivide2 = 0x1U, /*!< Divided by 2 */
manhpham 0:c8673aa96267 85 kWDOG_ClockPrescalerDivide3 = 0x2U, /*!< Divided by 3 */
manhpham 0:c8673aa96267 86 kWDOG_ClockPrescalerDivide4 = 0x3U, /*!< Divided by 4 */
manhpham 0:c8673aa96267 87 kWDOG_ClockPrescalerDivide5 = 0x4U, /*!< Divided by 5 */
manhpham 0:c8673aa96267 88 kWDOG_ClockPrescalerDivide6 = 0x5U, /*!< Divided by 6 */
manhpham 0:c8673aa96267 89 kWDOG_ClockPrescalerDivide7 = 0x6U, /*!< Divided by 7 */
manhpham 0:c8673aa96267 90 kWDOG_ClockPrescalerDivide8 = 0x7U, /*!< Divided by 8 */
manhpham 0:c8673aa96267 91 } wdog_clock_prescaler_t;
manhpham 0:c8673aa96267 92
manhpham 0:c8673aa96267 93 /*! @brief Describes WDOG configuration structure. */
manhpham 0:c8673aa96267 94 typedef struct _wdog_config
manhpham 0:c8673aa96267 95 {
manhpham 0:c8673aa96267 96 bool enableWdog; /*!< Enables or disables WDOG */
manhpham 0:c8673aa96267 97 wdog_clock_source_t clockSource; /*!< Clock source select */
manhpham 0:c8673aa96267 98 wdog_clock_prescaler_t prescaler; /*!< Clock prescaler value */
manhpham 0:c8673aa96267 99 wdog_work_mode_t workMode; /*!< Configures WDOG work mode in debug stop and wait mode */
manhpham 0:c8673aa96267 100 bool enableUpdate; /*!< Update write-once register enable */
manhpham 0:c8673aa96267 101 bool enableInterrupt; /*!< Enables or disables WDOG interrupt */
manhpham 0:c8673aa96267 102 bool enableWindowMode; /*!< Enables or disables WDOG window mode */
manhpham 0:c8673aa96267 103 uint32_t windowValue; /*!< Window value */
manhpham 0:c8673aa96267 104 uint32_t timeoutValue; /*!< Timeout value */
manhpham 0:c8673aa96267 105 } wdog_config_t;
manhpham 0:c8673aa96267 106
manhpham 0:c8673aa96267 107 /*! @brief Describes WDOG test mode. */
manhpham 0:c8673aa96267 108 typedef enum _wdog_test_mode
manhpham 0:c8673aa96267 109 {
manhpham 0:c8673aa96267 110 kWDOG_QuickTest = 0U, /*!< Selects quick test */
manhpham 0:c8673aa96267 111 kWDOG_ByteTest = 1U, /*!< Selects byte test */
manhpham 0:c8673aa96267 112 } wdog_test_mode_t;
manhpham 0:c8673aa96267 113
manhpham 0:c8673aa96267 114 /*! @brief Describes WDOG tested byte selection in byte test mode. */
manhpham 0:c8673aa96267 115 typedef enum _wdog_tested_byte
manhpham 0:c8673aa96267 116 {
manhpham 0:c8673aa96267 117 kWDOG_TestByte0 = 0U, /*!< Byte 0 selected in byte test mode */
manhpham 0:c8673aa96267 118 kWDOG_TestByte1 = 1U, /*!< Byte 1 selected in byte test mode */
manhpham 0:c8673aa96267 119 kWDOG_TestByte2 = 2U, /*!< Byte 2 selected in byte test mode */
manhpham 0:c8673aa96267 120 kWDOG_TestByte3 = 3U, /*!< Byte 3 selected in byte test mode */
manhpham 0:c8673aa96267 121 } wdog_tested_byte_t;
manhpham 0:c8673aa96267 122
manhpham 0:c8673aa96267 123 /*! @brief Describes WDOG test mode configuration structure. */
manhpham 0:c8673aa96267 124 typedef struct _wdog_test_config
manhpham 0:c8673aa96267 125 {
manhpham 0:c8673aa96267 126 wdog_test_mode_t testMode; /*!< Selects test mode */
manhpham 0:c8673aa96267 127 wdog_tested_byte_t testedByte; /*!< Selects tested byte in byte test mode */
manhpham 0:c8673aa96267 128 uint32_t timeoutValue; /*!< Timeout value */
manhpham 0:c8673aa96267 129 } wdog_test_config_t;
manhpham 0:c8673aa96267 130
manhpham 0:c8673aa96267 131 /*!
manhpham 0:c8673aa96267 132 * @brief WDOG interrupt configuration structure, default settings all disabled.
manhpham 0:c8673aa96267 133 *
manhpham 0:c8673aa96267 134 * This structure contains the settings for all of the WDOG interrupt configurations.
manhpham 0:c8673aa96267 135 */
manhpham 0:c8673aa96267 136 enum _wdog_interrupt_enable_t
manhpham 0:c8673aa96267 137 {
manhpham 0:c8673aa96267 138 kWDOG_InterruptEnable = WDOG_STCTRLH_IRQRSTEN_MASK, /*!< WDOG timeout generates an interrupt before reset*/
manhpham 0:c8673aa96267 139 };
manhpham 0:c8673aa96267 140
manhpham 0:c8673aa96267 141 /*!
manhpham 0:c8673aa96267 142 * @brief WDOG status flags.
manhpham 0:c8673aa96267 143 *
manhpham 0:c8673aa96267 144 * This structure contains the WDOG status flags for use in the WDOG functions.
manhpham 0:c8673aa96267 145 */
manhpham 0:c8673aa96267 146 enum _wdog_status_flags_t
manhpham 0:c8673aa96267 147 {
manhpham 0:c8673aa96267 148 kWDOG_RunningFlag = WDOG_STCTRLH_WDOGEN_MASK, /*!< Running flag, set when WDOG is enabled*/
manhpham 0:c8673aa96267 149 kWDOG_TimeoutFlag = WDOG_STCTRLL_INTFLG_MASK, /*!< Interrupt flag, set when an exception occurs*/
manhpham 0:c8673aa96267 150 };
manhpham 0:c8673aa96267 151
manhpham 0:c8673aa96267 152 /*******************************************************************************
manhpham 0:c8673aa96267 153 * API
manhpham 0:c8673aa96267 154 *******************************************************************************/
manhpham 0:c8673aa96267 155
manhpham 0:c8673aa96267 156 #if defined(__cplusplus)
manhpham 0:c8673aa96267 157 extern "C" {
manhpham 0:c8673aa96267 158 #endif /* __cplusplus */
manhpham 0:c8673aa96267 159
manhpham 0:c8673aa96267 160 /*!
manhpham 0:c8673aa96267 161 * @name WDOG Initialization and De-initialization
manhpham 0:c8673aa96267 162 * @{
manhpham 0:c8673aa96267 163 */
manhpham 0:c8673aa96267 164
manhpham 0:c8673aa96267 165 /*!
manhpham 0:c8673aa96267 166 * @brief Initializes WDOG configure sturcture.
manhpham 0:c8673aa96267 167 *
manhpham 0:c8673aa96267 168 * This function initializes the WDOG configuration structure to default value. The default
manhpham 0:c8673aa96267 169 * values are:
manhpham 0:c8673aa96267 170 * @code
manhpham 0:c8673aa96267 171 * wdogConfig->enableWdog = true;
manhpham 0:c8673aa96267 172 * wdogConfig->clockSource = kWDOG_LpoClockSource;
manhpham 0:c8673aa96267 173 * wdogConfig->prescaler = kWDOG_ClockPrescalerDivide1;
manhpham 0:c8673aa96267 174 * wdogConfig->workMode.enableWait = true;
manhpham 0:c8673aa96267 175 * wdogConfig->workMode.enableStop = false;
manhpham 0:c8673aa96267 176 * wdogConfig->workMode.enableDebug = false;
manhpham 0:c8673aa96267 177 * wdogConfig->enableUpdate = true;
manhpham 0:c8673aa96267 178 * wdogConfig->enableInterrupt = false;
manhpham 0:c8673aa96267 179 * wdogConfig->enableWindowMode = false;
manhpham 0:c8673aa96267 180 * wdogConfig->windowValue = 0;
manhpham 0:c8673aa96267 181 * wdogConfig->timeoutValue = 0xFFFFU;
manhpham 0:c8673aa96267 182 * @endcode
manhpham 0:c8673aa96267 183 *
manhpham 0:c8673aa96267 184 * @param config Pointer to WDOG config structure.
manhpham 0:c8673aa96267 185 * @see wdog_config_t
manhpham 0:c8673aa96267 186 */
manhpham 0:c8673aa96267 187 void WDOG_GetDefaultConfig(wdog_config_t *config);
manhpham 0:c8673aa96267 188
manhpham 0:c8673aa96267 189 /*!
manhpham 0:c8673aa96267 190 * @brief Initializes the WDOG.
manhpham 0:c8673aa96267 191 *
manhpham 0:c8673aa96267 192 * This function initializes the WDOG. When called, the WDOG runs according to the configuration.
manhpham 0:c8673aa96267 193 * If user wants to reconfigure WDOG without forcing a reset first, enableUpdate must be set to true
manhpham 0:c8673aa96267 194 * in configuration.
manhpham 0:c8673aa96267 195 *
manhpham 0:c8673aa96267 196 * Example:
manhpham 0:c8673aa96267 197 * @code
manhpham 0:c8673aa96267 198 * wdog_config_t config;
manhpham 0:c8673aa96267 199 * WDOG_GetDefaultConfig(&config);
manhpham 0:c8673aa96267 200 * config.timeoutValue = 0x7ffU;
manhpham 0:c8673aa96267 201 * config.enableUpdate = true;
manhpham 0:c8673aa96267 202 * WDOG_Init(wdog_base,&config);
manhpham 0:c8673aa96267 203 * @endcode
manhpham 0:c8673aa96267 204 *
manhpham 0:c8673aa96267 205 * @param base WDOG peripheral base address
manhpham 0:c8673aa96267 206 * @param config The configuration of WDOG
manhpham 0:c8673aa96267 207 */
manhpham 0:c8673aa96267 208 void WDOG_Init(WDOG_Type *base, const wdog_config_t *config);
manhpham 0:c8673aa96267 209
manhpham 0:c8673aa96267 210 /*!
manhpham 0:c8673aa96267 211 * @brief Shuts down the WDOG.
manhpham 0:c8673aa96267 212 *
manhpham 0:c8673aa96267 213 * This function shuts down the WDOG.
manhpham 0:c8673aa96267 214 * Make sure that the WDOG_STCTRLH.ALLOWUPDATE is 1 which means that the register update is enabled.
manhpham 0:c8673aa96267 215 */
manhpham 0:c8673aa96267 216 void WDOG_Deinit(WDOG_Type *base);
manhpham 0:c8673aa96267 217
manhpham 0:c8673aa96267 218 /*!
manhpham 0:c8673aa96267 219 * @brief Configures WDOG functional test.
manhpham 0:c8673aa96267 220 *
manhpham 0:c8673aa96267 221 * This function is used to configure the WDOG functional test. When called, the WDOG goes into test mode
manhpham 0:c8673aa96267 222 * and runs according to the configuration.
manhpham 0:c8673aa96267 223 * Make sure that the WDOG_STCTRLH.ALLOWUPDATE is 1 which means that the register update is enabled.
manhpham 0:c8673aa96267 224 *
manhpham 0:c8673aa96267 225 * Example:
manhpham 0:c8673aa96267 226 * @code
manhpham 0:c8673aa96267 227 * wdog_test_config_t test_config;
manhpham 0:c8673aa96267 228 * test_config.testMode = kWDOG_QuickTest;
manhpham 0:c8673aa96267 229 * test_config.timeoutValue = 0xfffffu;
manhpham 0:c8673aa96267 230 * WDOG_SetTestModeConfig(wdog_base, &test_config);
manhpham 0:c8673aa96267 231 * @endcode
manhpham 0:c8673aa96267 232 * @param base WDOG peripheral base address
manhpham 0:c8673aa96267 233 * @param config The functional test configuration of WDOG
manhpham 0:c8673aa96267 234 */
manhpham 0:c8673aa96267 235 void WDOG_SetTestModeConfig(WDOG_Type *base, wdog_test_config_t *config);
manhpham 0:c8673aa96267 236
manhpham 0:c8673aa96267 237 /* @} */
manhpham 0:c8673aa96267 238
manhpham 0:c8673aa96267 239 /*!
manhpham 0:c8673aa96267 240 * @name WDOG Functional Operation
manhpham 0:c8673aa96267 241 * @{
manhpham 0:c8673aa96267 242 */
manhpham 0:c8673aa96267 243
manhpham 0:c8673aa96267 244 /*!
manhpham 0:c8673aa96267 245 * @brief Enables the WDOG module.
manhpham 0:c8673aa96267 246 *
manhpham 0:c8673aa96267 247 * This function write value into WDOG_STCTRLH register to enable the WDOG, it is a write-once register,
manhpham 0:c8673aa96267 248 * make sure that the WCT window is still open and this register has not been written in this WCT
manhpham 0:c8673aa96267 249 * while this function is called.
manhpham 0:c8673aa96267 250 *
manhpham 0:c8673aa96267 251 * @param base WDOG peripheral base address
manhpham 0:c8673aa96267 252 */
manhpham 0:c8673aa96267 253 static inline void WDOG_Enable(WDOG_Type *base)
manhpham 0:c8673aa96267 254 {
manhpham 0:c8673aa96267 255 base->STCTRLH |= WDOG_STCTRLH_WDOGEN_MASK;
manhpham 0:c8673aa96267 256 }
manhpham 0:c8673aa96267 257
manhpham 0:c8673aa96267 258 /*!
manhpham 0:c8673aa96267 259 * @brief Disables the WDOG module.
manhpham 0:c8673aa96267 260 *
manhpham 0:c8673aa96267 261 * This function write value into WDOG_STCTRLH register to disable the WDOG, it is a write-once register,
manhpham 0:c8673aa96267 262 * make sure that the WCT window is still open and this register has not been written in this WCT
manhpham 0:c8673aa96267 263 * while this function is called.
manhpham 0:c8673aa96267 264 *
manhpham 0:c8673aa96267 265 * @param base WDOG peripheral base address
manhpham 0:c8673aa96267 266 */
manhpham 0:c8673aa96267 267 static inline void WDOG_Disable(WDOG_Type *base)
manhpham 0:c8673aa96267 268 {
manhpham 0:c8673aa96267 269 base->STCTRLH &= ~WDOG_STCTRLH_WDOGEN_MASK;
manhpham 0:c8673aa96267 270 }
manhpham 0:c8673aa96267 271
manhpham 0:c8673aa96267 272 /*!
manhpham 0:c8673aa96267 273 * @brief Enable WDOG interrupt.
manhpham 0:c8673aa96267 274 *
manhpham 0:c8673aa96267 275 * This function write value into WDOG_STCTRLH register to enable WDOG interrupt, it is a write-once register,
manhpham 0:c8673aa96267 276 * make sure that the WCT window is still open and this register has not been written in this WCT
manhpham 0:c8673aa96267 277 * while this function is called.
manhpham 0:c8673aa96267 278 *
manhpham 0:c8673aa96267 279 * @param base WDOG peripheral base address
manhpham 0:c8673aa96267 280 * @param mask The interrupts to enable
manhpham 0:c8673aa96267 281 * The parameter can be combination of the following source if defined:
manhpham 0:c8673aa96267 282 * @arg kWDOG_InterruptEnable
manhpham 0:c8673aa96267 283 */
manhpham 0:c8673aa96267 284 static inline void WDOG_EnableInterrupts(WDOG_Type *base, uint32_t mask)
manhpham 0:c8673aa96267 285 {
manhpham 0:c8673aa96267 286 base->STCTRLH |= mask;
manhpham 0:c8673aa96267 287 }
manhpham 0:c8673aa96267 288
manhpham 0:c8673aa96267 289 /*!
manhpham 0:c8673aa96267 290 * @brief Disable WDOG interrupt.
manhpham 0:c8673aa96267 291 *
manhpham 0:c8673aa96267 292 * This function write value into WDOG_STCTRLH register to disable WDOG interrupt, it is a write-once register,
manhpham 0:c8673aa96267 293 * make sure that the WCT window is still open and this register has not been written in this WCT
manhpham 0:c8673aa96267 294 * while this function is called.
manhpham 0:c8673aa96267 295 *
manhpham 0:c8673aa96267 296 * @param base WDOG peripheral base address
manhpham 0:c8673aa96267 297 * @param mask The interrupts to disable
manhpham 0:c8673aa96267 298 * The parameter can be combination of the following source if defined:
manhpham 0:c8673aa96267 299 * @arg kWDOG_InterruptEnable
manhpham 0:c8673aa96267 300 */
manhpham 0:c8673aa96267 301 static inline void WDOG_DisableInterrupts(WDOG_Type *base, uint32_t mask)
manhpham 0:c8673aa96267 302 {
manhpham 0:c8673aa96267 303 base->STCTRLH &= ~mask;
manhpham 0:c8673aa96267 304 }
manhpham 0:c8673aa96267 305
manhpham 0:c8673aa96267 306 /*!
manhpham 0:c8673aa96267 307 * @brief Gets WDOG all status flags.
manhpham 0:c8673aa96267 308 *
manhpham 0:c8673aa96267 309 * This function gets all status flags.
manhpham 0:c8673aa96267 310 *
manhpham 0:c8673aa96267 311 * Example for getting Running Flag:
manhpham 0:c8673aa96267 312 * @code
manhpham 0:c8673aa96267 313 * uint32_t status;
manhpham 0:c8673aa96267 314 * status = WDOG_GetStatusFlags(wdog_base) & kWDOG_RunningFlag;
manhpham 0:c8673aa96267 315 * @endcode
manhpham 0:c8673aa96267 316 * @param base WDOG peripheral base address
manhpham 0:c8673aa96267 317 * @return State of the status flag: asserted (true) or not-asserted (false).@see _wdog_status_flags_t
manhpham 0:c8673aa96267 318 * - true: a related status flag has been set.
manhpham 0:c8673aa96267 319 * - false: a related status flag is not set.
manhpham 0:c8673aa96267 320 */
manhpham 0:c8673aa96267 321 uint32_t WDOG_GetStatusFlags(WDOG_Type *base);
manhpham 0:c8673aa96267 322
manhpham 0:c8673aa96267 323 /*!
manhpham 0:c8673aa96267 324 * @brief Clear WDOG flag.
manhpham 0:c8673aa96267 325 *
manhpham 0:c8673aa96267 326 * This function clears WDOG status flag.
manhpham 0:c8673aa96267 327 *
manhpham 0:c8673aa96267 328 * Example for clearing timeout(interrupt) flag:
manhpham 0:c8673aa96267 329 * @code
manhpham 0:c8673aa96267 330 * WDOG_ClearStatusFlags(wdog_base,kWDOG_TimeoutFlag);
manhpham 0:c8673aa96267 331 * @endcode
manhpham 0:c8673aa96267 332 * @param base WDOG peripheral base address
manhpham 0:c8673aa96267 333 * @param mask The status flags to clear.
manhpham 0:c8673aa96267 334 * The parameter could be any combination of the following values:
manhpham 0:c8673aa96267 335 * kWDOG_TimeoutFlag
manhpham 0:c8673aa96267 336 */
manhpham 0:c8673aa96267 337 void WDOG_ClearStatusFlags(WDOG_Type *base, uint32_t mask);
manhpham 0:c8673aa96267 338
manhpham 0:c8673aa96267 339 /*!
manhpham 0:c8673aa96267 340 * @brief Set the WDOG timeout value.
manhpham 0:c8673aa96267 341 *
manhpham 0:c8673aa96267 342 * This function sets the timeout value.
manhpham 0:c8673aa96267 343 * It should be ensured that the time-out value for the WDOG is always greater than
manhpham 0:c8673aa96267 344 * 2xWCT time + 20 bus clock cycles.
manhpham 0:c8673aa96267 345 * This function write value into WDOG_TOVALH and WDOG_TOVALL registers which are wirte-once.
manhpham 0:c8673aa96267 346 * Make sure the WCT window is still open and these two registers have not been written in this WCT
manhpham 0:c8673aa96267 347 * while this function is called.
manhpham 0:c8673aa96267 348 *
manhpham 0:c8673aa96267 349 * @param base WDOG peripheral base address
manhpham 0:c8673aa96267 350 * @param timeoutCount WDOG timeout value, count of WDOG clock tick.
manhpham 0:c8673aa96267 351 */
manhpham 0:c8673aa96267 352 static inline void WDOG_SetTimeoutValue(WDOG_Type *base, uint32_t timeoutCount)
manhpham 0:c8673aa96267 353 {
manhpham 0:c8673aa96267 354 base->TOVALH = (uint16_t)((timeoutCount >> 16U) & 0xFFFFU);
manhpham 0:c8673aa96267 355 base->TOVALL = (uint16_t)((timeoutCount)&0xFFFFU);
manhpham 0:c8673aa96267 356 }
manhpham 0:c8673aa96267 357
manhpham 0:c8673aa96267 358 /*!
manhpham 0:c8673aa96267 359 * @brief Sets the WDOG window value.
manhpham 0:c8673aa96267 360 *
manhpham 0:c8673aa96267 361 * This function sets the WDOG window value.
manhpham 0:c8673aa96267 362 * This function write value into WDOG_WINH and WDOG_WINL registers which are wirte-once.
manhpham 0:c8673aa96267 363 * Make sure the WCT window is still open and these two registers have not been written in this WCT
manhpham 0:c8673aa96267 364 * while this function is called.
manhpham 0:c8673aa96267 365 *
manhpham 0:c8673aa96267 366 * @param base WDOG peripheral base address
manhpham 0:c8673aa96267 367 * @param windowValue WDOG window value.
manhpham 0:c8673aa96267 368 */
manhpham 0:c8673aa96267 369 static inline void WDOG_SetWindowValue(WDOG_Type *base, uint32_t windowValue)
manhpham 0:c8673aa96267 370 {
manhpham 0:c8673aa96267 371 base->WINH = (uint16_t)((windowValue >> 16U) & 0xFFFFU);
manhpham 0:c8673aa96267 372 base->WINL = (uint16_t)((windowValue)&0xFFFFU);
manhpham 0:c8673aa96267 373 }
manhpham 0:c8673aa96267 374
manhpham 0:c8673aa96267 375 /*!
manhpham 0:c8673aa96267 376 * @brief Unlocks the WDOG register written.
manhpham 0:c8673aa96267 377 *
manhpham 0:c8673aa96267 378 * This function unlocks the WDOG register written.
manhpham 0:c8673aa96267 379 * Before starting the unlock sequence and following congfiguration, disable the global interrupts.
manhpham 0:c8673aa96267 380 * Otherwise, an interrupt could effectively invalidate the unlock sequence and the WCT may expire,
manhpham 0:c8673aa96267 381 * After the configuration finishes, re-enable the global interrupts.
manhpham 0:c8673aa96267 382 *
manhpham 0:c8673aa96267 383 * @param base WDOG peripheral base address
manhpham 0:c8673aa96267 384 */
manhpham 0:c8673aa96267 385 static inline void WDOG_Unlock(WDOG_Type *base)
manhpham 0:c8673aa96267 386 {
manhpham 0:c8673aa96267 387 base->UNLOCK = WDOG_FIRST_WORD_OF_UNLOCK;
manhpham 0:c8673aa96267 388 base->UNLOCK = WDOG_SECOND_WORD_OF_UNLOCK;
manhpham 0:c8673aa96267 389 }
manhpham 0:c8673aa96267 390
manhpham 0:c8673aa96267 391 /*!
manhpham 0:c8673aa96267 392 * @brief Refreshes the WDOG timer.
manhpham 0:c8673aa96267 393 *
manhpham 0:c8673aa96267 394 * This function feeds the WDOG.
manhpham 0:c8673aa96267 395 * This function should be called before WDOG timer is in timeout. Otherwise, a reset is asserted.
manhpham 0:c8673aa96267 396 *
manhpham 0:c8673aa96267 397 * @param base WDOG peripheral base address
manhpham 0:c8673aa96267 398 */
manhpham 0:c8673aa96267 399 void WDOG_Refresh(WDOG_Type *base);
manhpham 0:c8673aa96267 400
manhpham 0:c8673aa96267 401 /*!
manhpham 0:c8673aa96267 402 * @brief Gets the WDOG reset count.
manhpham 0:c8673aa96267 403 *
manhpham 0:c8673aa96267 404 * This function gets the WDOG reset count value.
manhpham 0:c8673aa96267 405 *
manhpham 0:c8673aa96267 406 * @param base WDOG peripheral base address
manhpham 0:c8673aa96267 407 * @return WDOG reset count value
manhpham 0:c8673aa96267 408 */
manhpham 0:c8673aa96267 409 static inline uint16_t WDOG_GetResetCount(WDOG_Type *base)
manhpham 0:c8673aa96267 410 {
manhpham 0:c8673aa96267 411 return base->RSTCNT;
manhpham 0:c8673aa96267 412 }
manhpham 0:c8673aa96267 413 /*!
manhpham 0:c8673aa96267 414 * @brief Clears the WDOG reset count.
manhpham 0:c8673aa96267 415 *
manhpham 0:c8673aa96267 416 * This function clears the WDOG reset count value.
manhpham 0:c8673aa96267 417 *
manhpham 0:c8673aa96267 418 * @param base WDOG peripheral base address
manhpham 0:c8673aa96267 419 */
manhpham 0:c8673aa96267 420 static inline void WDOG_ClearResetCount(WDOG_Type *base)
manhpham 0:c8673aa96267 421 {
manhpham 0:c8673aa96267 422 base->RSTCNT |= UINT16_MAX;
manhpham 0:c8673aa96267 423 }
manhpham 0:c8673aa96267 424
manhpham 0:c8673aa96267 425 /*@}*/
manhpham 0:c8673aa96267 426
manhpham 0:c8673aa96267 427 #if defined(__cplusplus)
manhpham 0:c8673aa96267 428 }
manhpham 0:c8673aa96267 429 #endif /* __cplusplus */
manhpham 0:c8673aa96267 430
manhpham 0:c8673aa96267 431 /*! @}*/
manhpham 0:c8673aa96267 432
manhpham 0:c8673aa96267 433 #endif /* _FSL_WDOG_H_ */