The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.
Dependents: hello SerialTestv11 SerialTestv12 Sierpinski ... more
mbed 2
This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.
TARGET_K66F/TOOLCHAIN_IAR/fsl_rtc.h@172:65be27845400, 2019-02-20 (annotated)
- Committer:
- AnnaBridge
- Date:
- Wed Feb 20 20:53:29 2019 +0000
- Revision:
- 172:65be27845400
- Parent:
- 171:3a7713b1edbc
mbed library release version 165
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AnnaBridge | 143:86740a56073b | 1 | /* |
AnnaBridge | 143:86740a56073b | 2 | * Copyright (c) 2015, Freescale Semiconductor, Inc. |
AnnaBridge | 143:86740a56073b | 3 | * Copyright 2016-2017 NXP |
AnnaBridge | 143:86740a56073b | 4 | * |
AnnaBridge | 143:86740a56073b | 5 | * Redistribution and use in source and binary forms, with or without modification, |
AnnaBridge | 143:86740a56073b | 6 | * are permitted provided that the following conditions are met: |
AnnaBridge | 143:86740a56073b | 7 | * |
AnnaBridge | 143:86740a56073b | 8 | * o Redistributions of source code must retain the above copyright notice, this list |
AnnaBridge | 143:86740a56073b | 9 | * of conditions and the following disclaimer. |
AnnaBridge | 143:86740a56073b | 10 | * |
AnnaBridge | 143:86740a56073b | 11 | * o Redistributions in binary form must reproduce the above copyright notice, this |
AnnaBridge | 143:86740a56073b | 12 | * list of conditions and the following disclaimer in the documentation and/or |
AnnaBridge | 143:86740a56073b | 13 | * other materials provided with the distribution. |
AnnaBridge | 143:86740a56073b | 14 | * |
AnnaBridge | 143:86740a56073b | 15 | * o Neither the name of the copyright holder nor the names of its |
AnnaBridge | 143:86740a56073b | 16 | * contributors may be used to endorse or promote products derived from this |
AnnaBridge | 143:86740a56073b | 17 | * software without specific prior written permission. |
AnnaBridge | 143:86740a56073b | 18 | * |
AnnaBridge | 143:86740a56073b | 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
AnnaBridge | 143:86740a56073b | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
AnnaBridge | 143:86740a56073b | 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
AnnaBridge | 143:86740a56073b | 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
AnnaBridge | 143:86740a56073b | 23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
AnnaBridge | 143:86740a56073b | 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
AnnaBridge | 143:86740a56073b | 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
AnnaBridge | 143:86740a56073b | 26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
AnnaBridge | 143:86740a56073b | 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
AnnaBridge | 143:86740a56073b | 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
AnnaBridge | 143:86740a56073b | 29 | */ |
AnnaBridge | 143:86740a56073b | 30 | #ifndef _FSL_RTC_H_ |
AnnaBridge | 143:86740a56073b | 31 | #define _FSL_RTC_H_ |
AnnaBridge | 143:86740a56073b | 32 | |
AnnaBridge | 143:86740a56073b | 33 | #include "fsl_common.h" |
AnnaBridge | 143:86740a56073b | 34 | |
AnnaBridge | 143:86740a56073b | 35 | /*! |
AnnaBridge | 143:86740a56073b | 36 | * @addtogroup rtc |
AnnaBridge | 143:86740a56073b | 37 | * @{ |
AnnaBridge | 143:86740a56073b | 38 | */ |
AnnaBridge | 143:86740a56073b | 39 | |
AnnaBridge | 143:86740a56073b | 40 | |
AnnaBridge | 143:86740a56073b | 41 | /******************************************************************************* |
AnnaBridge | 143:86740a56073b | 42 | * Definitions |
AnnaBridge | 143:86740a56073b | 43 | ******************************************************************************/ |
AnnaBridge | 143:86740a56073b | 44 | |
AnnaBridge | 143:86740a56073b | 45 | /*! @name Driver version */ |
AnnaBridge | 143:86740a56073b | 46 | /*@{*/ |
AnnaBridge | 143:86740a56073b | 47 | #define FSL_RTC_DRIVER_VERSION (MAKE_VERSION(2, 0, 0)) /*!< Version 2.0.0 */ |
AnnaBridge | 143:86740a56073b | 48 | /*@}*/ |
AnnaBridge | 143:86740a56073b | 49 | |
AnnaBridge | 143:86740a56073b | 50 | /*! @brief List of RTC interrupts */ |
AnnaBridge | 143:86740a56073b | 51 | typedef enum _rtc_interrupt_enable |
AnnaBridge | 143:86740a56073b | 52 | { |
AnnaBridge | 143:86740a56073b | 53 | kRTC_TimeInvalidInterruptEnable = RTC_IER_TIIE_MASK, /*!< Time invalid interrupt.*/ |
AnnaBridge | 143:86740a56073b | 54 | kRTC_TimeOverflowInterruptEnable = RTC_IER_TOIE_MASK, /*!< Time overflow interrupt.*/ |
AnnaBridge | 143:86740a56073b | 55 | kRTC_AlarmInterruptEnable = RTC_IER_TAIE_MASK, /*!< Alarm interrupt.*/ |
AnnaBridge | 143:86740a56073b | 56 | kRTC_SecondsInterruptEnable = RTC_IER_TSIE_MASK /*!< Seconds interrupt.*/ |
AnnaBridge | 143:86740a56073b | 57 | } rtc_interrupt_enable_t; |
AnnaBridge | 143:86740a56073b | 58 | |
AnnaBridge | 143:86740a56073b | 59 | /*! @brief List of RTC flags */ |
AnnaBridge | 143:86740a56073b | 60 | typedef enum _rtc_status_flags |
AnnaBridge | 143:86740a56073b | 61 | { |
AnnaBridge | 143:86740a56073b | 62 | kRTC_TimeInvalidFlag = RTC_SR_TIF_MASK, /*!< Time invalid flag */ |
AnnaBridge | 143:86740a56073b | 63 | kRTC_TimeOverflowFlag = RTC_SR_TOF_MASK, /*!< Time overflow flag */ |
AnnaBridge | 143:86740a56073b | 64 | kRTC_AlarmFlag = RTC_SR_TAF_MASK /*!< Alarm flag*/ |
AnnaBridge | 143:86740a56073b | 65 | } rtc_status_flags_t; |
AnnaBridge | 143:86740a56073b | 66 | |
AnnaBridge | 143:86740a56073b | 67 | #if (defined(FSL_FEATURE_RTC_HAS_OSC_SCXP) && FSL_FEATURE_RTC_HAS_OSC_SCXP) |
AnnaBridge | 143:86740a56073b | 68 | |
AnnaBridge | 143:86740a56073b | 69 | /*! @brief List of RTC Oscillator capacitor load settings */ |
AnnaBridge | 143:86740a56073b | 70 | typedef enum _rtc_osc_cap_load |
AnnaBridge | 143:86740a56073b | 71 | { |
AnnaBridge | 143:86740a56073b | 72 | kRTC_Capacitor_2p = RTC_CR_SC2P_MASK, /*!< 2 pF capacitor load */ |
AnnaBridge | 143:86740a56073b | 73 | kRTC_Capacitor_4p = RTC_CR_SC4P_MASK, /*!< 4 pF capacitor load */ |
AnnaBridge | 143:86740a56073b | 74 | kRTC_Capacitor_8p = RTC_CR_SC8P_MASK, /*!< 8 pF capacitor load */ |
AnnaBridge | 143:86740a56073b | 75 | kRTC_Capacitor_16p = RTC_CR_SC16P_MASK /*!< 16 pF capacitor load */ |
AnnaBridge | 143:86740a56073b | 76 | } rtc_osc_cap_load_t; |
AnnaBridge | 143:86740a56073b | 77 | |
AnnaBridge | 143:86740a56073b | 78 | #endif /* FSL_FEATURE_SCG_HAS_OSC_SCXP */ |
AnnaBridge | 143:86740a56073b | 79 | |
AnnaBridge | 143:86740a56073b | 80 | /*! @brief Structure is used to hold the date and time */ |
AnnaBridge | 143:86740a56073b | 81 | typedef struct _rtc_datetime |
AnnaBridge | 143:86740a56073b | 82 | { |
AnnaBridge | 143:86740a56073b | 83 | uint16_t year; /*!< Range from 1970 to 2099.*/ |
AnnaBridge | 143:86740a56073b | 84 | uint8_t month; /*!< Range from 1 to 12.*/ |
AnnaBridge | 143:86740a56073b | 85 | uint8_t day; /*!< Range from 1 to 31 (depending on month).*/ |
AnnaBridge | 143:86740a56073b | 86 | uint8_t hour; /*!< Range from 0 to 23.*/ |
AnnaBridge | 143:86740a56073b | 87 | uint8_t minute; /*!< Range from 0 to 59.*/ |
AnnaBridge | 143:86740a56073b | 88 | uint8_t second; /*!< Range from 0 to 59.*/ |
AnnaBridge | 143:86740a56073b | 89 | } rtc_datetime_t; |
AnnaBridge | 143:86740a56073b | 90 | |
AnnaBridge | 143:86740a56073b | 91 | /*! |
AnnaBridge | 143:86740a56073b | 92 | * @brief RTC config structure |
AnnaBridge | 143:86740a56073b | 93 | * |
AnnaBridge | 143:86740a56073b | 94 | * This structure holds the configuration settings for the RTC peripheral. To initialize this |
AnnaBridge | 143:86740a56073b | 95 | * structure to reasonable defaults, call the RTC_GetDefaultConfig() function and pass a |
AnnaBridge | 143:86740a56073b | 96 | * pointer to your config structure instance. |
AnnaBridge | 143:86740a56073b | 97 | * |
AnnaBridge | 143:86740a56073b | 98 | * The config struct can be made const so it resides in flash |
AnnaBridge | 143:86740a56073b | 99 | */ |
AnnaBridge | 143:86740a56073b | 100 | typedef struct _rtc_config |
AnnaBridge | 143:86740a56073b | 101 | { |
AnnaBridge | 143:86740a56073b | 102 | bool wakeupSelect; /*!< true: Wakeup pin outputs the 32 KHz clock; |
AnnaBridge | 143:86740a56073b | 103 | false:Wakeup pin used to wakeup the chip */ |
AnnaBridge | 143:86740a56073b | 104 | bool updateMode; /*!< true: Registers can be written even when locked under certain |
AnnaBridge | 143:86740a56073b | 105 | conditions, false: No writes allowed when registers are locked */ |
AnnaBridge | 143:86740a56073b | 106 | bool supervisorAccess; /*!< true: Non-supervisor accesses are allowed; |
AnnaBridge | 143:86740a56073b | 107 | false: Non-supervisor accesses are not supported */ |
AnnaBridge | 143:86740a56073b | 108 | uint32_t compensationInterval; /*!< Compensation interval that is written to the CIR field in RTC TCR Register */ |
AnnaBridge | 143:86740a56073b | 109 | uint32_t compensationTime; /*!< Compensation time that is written to the TCR field in RTC TCR Register */ |
AnnaBridge | 143:86740a56073b | 110 | } rtc_config_t; |
AnnaBridge | 143:86740a56073b | 111 | |
AnnaBridge | 143:86740a56073b | 112 | /******************************************************************************* |
AnnaBridge | 143:86740a56073b | 113 | * API |
AnnaBridge | 143:86740a56073b | 114 | ******************************************************************************/ |
AnnaBridge | 143:86740a56073b | 115 | |
AnnaBridge | 143:86740a56073b | 116 | #if defined(__cplusplus) |
AnnaBridge | 143:86740a56073b | 117 | extern "C" { |
AnnaBridge | 143:86740a56073b | 118 | #endif |
AnnaBridge | 143:86740a56073b | 119 | |
AnnaBridge | 143:86740a56073b | 120 | /*! |
AnnaBridge | 143:86740a56073b | 121 | * @name Initialization and deinitialization |
AnnaBridge | 143:86740a56073b | 122 | * @{ |
AnnaBridge | 143:86740a56073b | 123 | */ |
AnnaBridge | 143:86740a56073b | 124 | |
AnnaBridge | 143:86740a56073b | 125 | /*! |
AnnaBridge | 143:86740a56073b | 126 | * @brief Ungates the RTC clock and configures the peripheral for basic operation. |
AnnaBridge | 143:86740a56073b | 127 | * |
AnnaBridge | 143:86740a56073b | 128 | * This function issues a software reset if the timer invalid flag is set. |
AnnaBridge | 143:86740a56073b | 129 | * |
AnnaBridge | 143:86740a56073b | 130 | * @note This API should be called at the beginning of the application using the RTC driver. |
AnnaBridge | 143:86740a56073b | 131 | * |
AnnaBridge | 143:86740a56073b | 132 | * @param base RTC peripheral base address |
AnnaBridge | 143:86740a56073b | 133 | * @param config Pointer to the user's RTC configuration structure. |
AnnaBridge | 143:86740a56073b | 134 | */ |
AnnaBridge | 143:86740a56073b | 135 | void RTC_Init(RTC_Type *base, const rtc_config_t *config); |
AnnaBridge | 143:86740a56073b | 136 | |
AnnaBridge | 143:86740a56073b | 137 | /*! |
AnnaBridge | 143:86740a56073b | 138 | * @brief Stops the timer and gate the RTC clock. |
AnnaBridge | 143:86740a56073b | 139 | * |
AnnaBridge | 143:86740a56073b | 140 | * @param base RTC peripheral base address |
AnnaBridge | 143:86740a56073b | 141 | */ |
AnnaBridge | 143:86740a56073b | 142 | static inline void RTC_Deinit(RTC_Type *base) |
AnnaBridge | 143:86740a56073b | 143 | { |
AnnaBridge | 143:86740a56073b | 144 | /* Stop the RTC timer */ |
AnnaBridge | 143:86740a56073b | 145 | base->SR &= ~RTC_SR_TCE_MASK; |
AnnaBridge | 143:86740a56073b | 146 | |
AnnaBridge | 143:86740a56073b | 147 | #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) |
AnnaBridge | 143:86740a56073b | 148 | /* Gate the module clock */ |
AnnaBridge | 143:86740a56073b | 149 | CLOCK_DisableClock(kCLOCK_Rtc0); |
AnnaBridge | 143:86740a56073b | 150 | #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */ |
AnnaBridge | 143:86740a56073b | 151 | } |
AnnaBridge | 143:86740a56073b | 152 | |
AnnaBridge | 143:86740a56073b | 153 | /*! |
AnnaBridge | 143:86740a56073b | 154 | * @brief Fills in the RTC config struct with the default settings. |
AnnaBridge | 143:86740a56073b | 155 | * |
AnnaBridge | 143:86740a56073b | 156 | * The default values are as follows. |
AnnaBridge | 143:86740a56073b | 157 | * @code |
AnnaBridge | 143:86740a56073b | 158 | * config->wakeupSelect = false; |
AnnaBridge | 143:86740a56073b | 159 | * config->updateMode = false; |
AnnaBridge | 143:86740a56073b | 160 | * config->supervisorAccess = false; |
AnnaBridge | 143:86740a56073b | 161 | * config->compensationInterval = 0; |
AnnaBridge | 143:86740a56073b | 162 | * config->compensationTime = 0; |
AnnaBridge | 143:86740a56073b | 163 | * @endcode |
AnnaBridge | 143:86740a56073b | 164 | * @param config Pointer to the user's RTC configuration structure. |
AnnaBridge | 143:86740a56073b | 165 | */ |
AnnaBridge | 143:86740a56073b | 166 | void RTC_GetDefaultConfig(rtc_config_t *config); |
AnnaBridge | 143:86740a56073b | 167 | |
AnnaBridge | 143:86740a56073b | 168 | /*! @}*/ |
AnnaBridge | 143:86740a56073b | 169 | |
AnnaBridge | 143:86740a56073b | 170 | /*! |
AnnaBridge | 143:86740a56073b | 171 | * @name Current Time & Alarm |
AnnaBridge | 143:86740a56073b | 172 | * @{ |
AnnaBridge | 143:86740a56073b | 173 | */ |
AnnaBridge | 143:86740a56073b | 174 | |
AnnaBridge | 143:86740a56073b | 175 | /*! |
AnnaBridge | 143:86740a56073b | 176 | * @brief Sets the RTC date and time according to the given time structure. |
AnnaBridge | 143:86740a56073b | 177 | * |
AnnaBridge | 143:86740a56073b | 178 | * The RTC counter must be stopped prior to calling this function because writes to the RTC |
AnnaBridge | 143:86740a56073b | 179 | * seconds register fail if the RTC counter is running. |
AnnaBridge | 143:86740a56073b | 180 | * |
AnnaBridge | 143:86740a56073b | 181 | * @param base RTC peripheral base address |
AnnaBridge | 143:86740a56073b | 182 | * @param datetime Pointer to the structure where the date and time details are stored. |
AnnaBridge | 143:86740a56073b | 183 | * |
AnnaBridge | 143:86740a56073b | 184 | * @return kStatus_Success: Success in setting the time and starting the RTC |
AnnaBridge | 143:86740a56073b | 185 | * kStatus_InvalidArgument: Error because the datetime format is incorrect |
AnnaBridge | 143:86740a56073b | 186 | */ |
AnnaBridge | 143:86740a56073b | 187 | status_t RTC_SetDatetime(RTC_Type *base, const rtc_datetime_t *datetime); |
AnnaBridge | 143:86740a56073b | 188 | |
AnnaBridge | 143:86740a56073b | 189 | /*! |
AnnaBridge | 143:86740a56073b | 190 | * @brief Gets the RTC time and stores it in the given time structure. |
AnnaBridge | 143:86740a56073b | 191 | * |
AnnaBridge | 143:86740a56073b | 192 | * @param base RTC peripheral base address |
AnnaBridge | 143:86740a56073b | 193 | * @param datetime Pointer to the structure where the date and time details are stored. |
AnnaBridge | 143:86740a56073b | 194 | */ |
AnnaBridge | 143:86740a56073b | 195 | void RTC_GetDatetime(RTC_Type *base, rtc_datetime_t *datetime); |
AnnaBridge | 143:86740a56073b | 196 | |
AnnaBridge | 143:86740a56073b | 197 | /*! |
AnnaBridge | 143:86740a56073b | 198 | * @brief Sets the RTC alarm time. |
AnnaBridge | 143:86740a56073b | 199 | * |
AnnaBridge | 143:86740a56073b | 200 | * The function checks whether the specified alarm time is greater than the present |
AnnaBridge | 143:86740a56073b | 201 | * time. If not, the function does not set the alarm and returns an error. |
AnnaBridge | 143:86740a56073b | 202 | * |
AnnaBridge | 143:86740a56073b | 203 | * @param base RTC peripheral base address |
AnnaBridge | 143:86740a56073b | 204 | * @param alarmTime Pointer to the structure where the alarm time is stored. |
AnnaBridge | 143:86740a56073b | 205 | * |
AnnaBridge | 143:86740a56073b | 206 | * @return kStatus_Success: success in setting the RTC alarm |
AnnaBridge | 143:86740a56073b | 207 | * kStatus_InvalidArgument: Error because the alarm datetime format is incorrect |
AnnaBridge | 143:86740a56073b | 208 | * kStatus_Fail: Error because the alarm time has already passed |
AnnaBridge | 143:86740a56073b | 209 | */ |
AnnaBridge | 143:86740a56073b | 210 | status_t RTC_SetAlarm(RTC_Type *base, const rtc_datetime_t *alarmTime); |
AnnaBridge | 143:86740a56073b | 211 | |
AnnaBridge | 143:86740a56073b | 212 | /*! |
AnnaBridge | 143:86740a56073b | 213 | * @brief Returns the RTC alarm time. |
AnnaBridge | 143:86740a56073b | 214 | * |
AnnaBridge | 143:86740a56073b | 215 | * @param base RTC peripheral base address |
AnnaBridge | 143:86740a56073b | 216 | * @param datetime Pointer to the structure where the alarm date and time details are stored. |
AnnaBridge | 143:86740a56073b | 217 | */ |
AnnaBridge | 143:86740a56073b | 218 | void RTC_GetAlarm(RTC_Type *base, rtc_datetime_t *datetime); |
AnnaBridge | 143:86740a56073b | 219 | |
AnnaBridge | 143:86740a56073b | 220 | /*! @}*/ |
AnnaBridge | 143:86740a56073b | 221 | |
AnnaBridge | 143:86740a56073b | 222 | /*! |
AnnaBridge | 143:86740a56073b | 223 | * @name Interrupt Interface |
AnnaBridge | 143:86740a56073b | 224 | * @{ |
AnnaBridge | 143:86740a56073b | 225 | */ |
AnnaBridge | 143:86740a56073b | 226 | |
AnnaBridge | 143:86740a56073b | 227 | /*! |
AnnaBridge | 143:86740a56073b | 228 | * @brief Enables the selected RTC interrupts. |
AnnaBridge | 143:86740a56073b | 229 | * |
AnnaBridge | 143:86740a56073b | 230 | * @param base RTC peripheral base address |
AnnaBridge | 143:86740a56073b | 231 | * @param mask The interrupts to enable. This is a logical OR of members of the |
AnnaBridge | 143:86740a56073b | 232 | * enumeration ::rtc_interrupt_enable_t |
AnnaBridge | 143:86740a56073b | 233 | */ |
AnnaBridge | 143:86740a56073b | 234 | static inline void RTC_EnableInterrupts(RTC_Type *base, uint32_t mask) |
AnnaBridge | 143:86740a56073b | 235 | { |
AnnaBridge | 143:86740a56073b | 236 | base->IER |= mask; |
AnnaBridge | 143:86740a56073b | 237 | } |
AnnaBridge | 143:86740a56073b | 238 | |
AnnaBridge | 143:86740a56073b | 239 | /*! |
AnnaBridge | 143:86740a56073b | 240 | * @brief Disables the selected RTC interrupts. |
AnnaBridge | 143:86740a56073b | 241 | * |
AnnaBridge | 143:86740a56073b | 242 | * @param base RTC peripheral base address |
AnnaBridge | 143:86740a56073b | 243 | * @param mask The interrupts to enable. This is a logical OR of members of the |
AnnaBridge | 143:86740a56073b | 244 | * enumeration ::rtc_interrupt_enable_t |
AnnaBridge | 143:86740a56073b | 245 | */ |
AnnaBridge | 143:86740a56073b | 246 | static inline void RTC_DisableInterrupts(RTC_Type *base, uint32_t mask) |
AnnaBridge | 143:86740a56073b | 247 | { |
AnnaBridge | 143:86740a56073b | 248 | base->IER &= ~mask; |
AnnaBridge | 143:86740a56073b | 249 | } |
AnnaBridge | 143:86740a56073b | 250 | |
AnnaBridge | 143:86740a56073b | 251 | /*! |
AnnaBridge | 143:86740a56073b | 252 | * @brief Gets the enabled RTC interrupts. |
AnnaBridge | 143:86740a56073b | 253 | * |
AnnaBridge | 143:86740a56073b | 254 | * @param base RTC peripheral base address |
AnnaBridge | 143:86740a56073b | 255 | * |
AnnaBridge | 143:86740a56073b | 256 | * @return The enabled interrupts. This is the logical OR of members of the |
AnnaBridge | 143:86740a56073b | 257 | * enumeration ::rtc_interrupt_enable_t |
AnnaBridge | 143:86740a56073b | 258 | */ |
AnnaBridge | 143:86740a56073b | 259 | static inline uint32_t RTC_GetEnabledInterrupts(RTC_Type *base) |
AnnaBridge | 143:86740a56073b | 260 | { |
AnnaBridge | 143:86740a56073b | 261 | return (base->IER & (RTC_IER_TIIE_MASK | RTC_IER_TOIE_MASK | RTC_IER_TAIE_MASK | RTC_IER_TSIE_MASK)); |
AnnaBridge | 143:86740a56073b | 262 | } |
AnnaBridge | 143:86740a56073b | 263 | |
AnnaBridge | 143:86740a56073b | 264 | /*! @}*/ |
AnnaBridge | 143:86740a56073b | 265 | |
AnnaBridge | 143:86740a56073b | 266 | /*! |
AnnaBridge | 143:86740a56073b | 267 | * @name Status Interface |
AnnaBridge | 143:86740a56073b | 268 | * @{ |
AnnaBridge | 143:86740a56073b | 269 | */ |
AnnaBridge | 143:86740a56073b | 270 | |
AnnaBridge | 143:86740a56073b | 271 | /*! |
AnnaBridge | 143:86740a56073b | 272 | * @brief Gets the RTC status flags. |
AnnaBridge | 143:86740a56073b | 273 | * |
AnnaBridge | 143:86740a56073b | 274 | * @param base RTC peripheral base address |
AnnaBridge | 143:86740a56073b | 275 | * |
AnnaBridge | 143:86740a56073b | 276 | * @return The status flags. This is the logical OR of members of the |
AnnaBridge | 143:86740a56073b | 277 | * enumeration ::rtc_status_flags_t |
AnnaBridge | 143:86740a56073b | 278 | */ |
AnnaBridge | 143:86740a56073b | 279 | static inline uint32_t RTC_GetStatusFlags(RTC_Type *base) |
AnnaBridge | 143:86740a56073b | 280 | { |
AnnaBridge | 143:86740a56073b | 281 | return (base->SR & (RTC_SR_TIF_MASK | RTC_SR_TOF_MASK | RTC_SR_TAF_MASK)); |
AnnaBridge | 143:86740a56073b | 282 | } |
AnnaBridge | 143:86740a56073b | 283 | |
AnnaBridge | 143:86740a56073b | 284 | /*! |
AnnaBridge | 143:86740a56073b | 285 | * @brief Clears the RTC status flags. |
AnnaBridge | 143:86740a56073b | 286 | * |
AnnaBridge | 143:86740a56073b | 287 | * @param base RTC peripheral base address |
AnnaBridge | 143:86740a56073b | 288 | * @param mask The status flags to clear. This is a logical OR of members of the |
AnnaBridge | 143:86740a56073b | 289 | * enumeration ::rtc_status_flags_t |
AnnaBridge | 143:86740a56073b | 290 | */ |
AnnaBridge | 143:86740a56073b | 291 | void RTC_ClearStatusFlags(RTC_Type *base, uint32_t mask); |
AnnaBridge | 143:86740a56073b | 292 | |
AnnaBridge | 143:86740a56073b | 293 | /*! @}*/ |
AnnaBridge | 143:86740a56073b | 294 | |
AnnaBridge | 143:86740a56073b | 295 | /*! |
AnnaBridge | 143:86740a56073b | 296 | * @name Timer Start and Stop |
AnnaBridge | 143:86740a56073b | 297 | * @{ |
AnnaBridge | 143:86740a56073b | 298 | */ |
AnnaBridge | 143:86740a56073b | 299 | |
AnnaBridge | 143:86740a56073b | 300 | /*! |
AnnaBridge | 143:86740a56073b | 301 | * @brief Starts the RTC time counter. |
AnnaBridge | 143:86740a56073b | 302 | * |
AnnaBridge | 143:86740a56073b | 303 | * After calling this function, the timer counter increments once a second provided SR[TOF] or |
AnnaBridge | 143:86740a56073b | 304 | * SR[TIF] are not set. |
AnnaBridge | 143:86740a56073b | 305 | * |
AnnaBridge | 143:86740a56073b | 306 | * @param base RTC peripheral base address |
AnnaBridge | 143:86740a56073b | 307 | */ |
AnnaBridge | 143:86740a56073b | 308 | static inline void RTC_StartTimer(RTC_Type *base) |
AnnaBridge | 143:86740a56073b | 309 | { |
AnnaBridge | 143:86740a56073b | 310 | base->SR |= RTC_SR_TCE_MASK; |
AnnaBridge | 143:86740a56073b | 311 | } |
AnnaBridge | 143:86740a56073b | 312 | |
AnnaBridge | 143:86740a56073b | 313 | /*! |
AnnaBridge | 143:86740a56073b | 314 | * @brief Stops the RTC time counter. |
AnnaBridge | 143:86740a56073b | 315 | * |
AnnaBridge | 143:86740a56073b | 316 | * RTC's seconds register can be written to only when the timer is stopped. |
AnnaBridge | 143:86740a56073b | 317 | * |
AnnaBridge | 143:86740a56073b | 318 | * @param base RTC peripheral base address |
AnnaBridge | 143:86740a56073b | 319 | */ |
AnnaBridge | 143:86740a56073b | 320 | static inline void RTC_StopTimer(RTC_Type *base) |
AnnaBridge | 143:86740a56073b | 321 | { |
AnnaBridge | 143:86740a56073b | 322 | base->SR &= ~RTC_SR_TCE_MASK; |
AnnaBridge | 143:86740a56073b | 323 | } |
AnnaBridge | 143:86740a56073b | 324 | |
AnnaBridge | 143:86740a56073b | 325 | /*! @}*/ |
AnnaBridge | 143:86740a56073b | 326 | |
AnnaBridge | 143:86740a56073b | 327 | #if (defined(FSL_FEATURE_RTC_HAS_OSC_SCXP) && FSL_FEATURE_RTC_HAS_OSC_SCXP) |
AnnaBridge | 143:86740a56073b | 328 | |
AnnaBridge | 143:86740a56073b | 329 | /*! |
AnnaBridge | 143:86740a56073b | 330 | * @brief This function sets the specified capacitor configuration for the RTC oscillator. |
AnnaBridge | 143:86740a56073b | 331 | * |
AnnaBridge | 143:86740a56073b | 332 | * @param base RTC peripheral base address |
AnnaBridge | 143:86740a56073b | 333 | * @param capLoad Oscillator loads to enable. This is a logical OR of members of the |
AnnaBridge | 143:86740a56073b | 334 | * enumeration ::rtc_osc_cap_load_t |
AnnaBridge | 143:86740a56073b | 335 | */ |
AnnaBridge | 143:86740a56073b | 336 | static inline void RTC_SetOscCapLoad(RTC_Type *base, uint32_t capLoad) |
AnnaBridge | 143:86740a56073b | 337 | { |
AnnaBridge | 143:86740a56073b | 338 | uint32_t reg = base->CR; |
AnnaBridge | 143:86740a56073b | 339 | |
AnnaBridge | 143:86740a56073b | 340 | reg &= ~(RTC_CR_SC2P_MASK | RTC_CR_SC4P_MASK | RTC_CR_SC8P_MASK | RTC_CR_SC16P_MASK); |
AnnaBridge | 143:86740a56073b | 341 | reg |= capLoad; |
AnnaBridge | 143:86740a56073b | 342 | |
AnnaBridge | 143:86740a56073b | 343 | base->CR = reg; |
AnnaBridge | 143:86740a56073b | 344 | } |
AnnaBridge | 143:86740a56073b | 345 | |
AnnaBridge | 143:86740a56073b | 346 | #endif /* FSL_FEATURE_SCG_HAS_OSC_SCXP */ |
AnnaBridge | 143:86740a56073b | 347 | |
AnnaBridge | 143:86740a56073b | 348 | /*! |
AnnaBridge | 143:86740a56073b | 349 | * @brief Performs a software reset on the RTC module. |
AnnaBridge | 143:86740a56073b | 350 | * |
AnnaBridge | 143:86740a56073b | 351 | * This resets all RTC registers except for the SWR bit and the RTC_WAR and RTC_RAR |
AnnaBridge | 143:86740a56073b | 352 | * registers. The SWR bit is cleared by software explicitly clearing it. |
AnnaBridge | 143:86740a56073b | 353 | * |
AnnaBridge | 143:86740a56073b | 354 | * @param base RTC peripheral base address |
AnnaBridge | 143:86740a56073b | 355 | */ |
AnnaBridge | 143:86740a56073b | 356 | static inline void RTC_Reset(RTC_Type *base) |
AnnaBridge | 143:86740a56073b | 357 | { |
AnnaBridge | 143:86740a56073b | 358 | base->CR |= RTC_CR_SWR_MASK; |
AnnaBridge | 143:86740a56073b | 359 | base->CR &= ~RTC_CR_SWR_MASK; |
AnnaBridge | 143:86740a56073b | 360 | |
AnnaBridge | 143:86740a56073b | 361 | /* Set TSR register to 0x1 to avoid the timer invalid (TIF) bit being set in the SR register */ |
AnnaBridge | 143:86740a56073b | 362 | base->TSR = 1U; |
AnnaBridge | 143:86740a56073b | 363 | } |
AnnaBridge | 143:86740a56073b | 364 | |
AnnaBridge | 143:86740a56073b | 365 | #if defined(FSL_FEATURE_RTC_HAS_MONOTONIC) && (FSL_FEATURE_RTC_HAS_MONOTONIC) |
AnnaBridge | 143:86740a56073b | 366 | |
AnnaBridge | 143:86740a56073b | 367 | /*! |
AnnaBridge | 143:86740a56073b | 368 | * @name Monotonic counter functions |
AnnaBridge | 143:86740a56073b | 369 | * @{ |
AnnaBridge | 143:86740a56073b | 370 | */ |
AnnaBridge | 143:86740a56073b | 371 | |
AnnaBridge | 143:86740a56073b | 372 | /*! |
AnnaBridge | 143:86740a56073b | 373 | * @brief Reads the values of the Monotonic Counter High and Monotonic Counter Low and returns |
AnnaBridge | 143:86740a56073b | 374 | * them as a single value. |
AnnaBridge | 143:86740a56073b | 375 | * |
AnnaBridge | 143:86740a56073b | 376 | * @param base RTC peripheral base address |
AnnaBridge | 143:86740a56073b | 377 | * @param counter Pointer to variable where the value is stored. |
AnnaBridge | 143:86740a56073b | 378 | */ |
AnnaBridge | 143:86740a56073b | 379 | void RTC_GetMonotonicCounter(RTC_Type *base, uint64_t *counter); |
AnnaBridge | 143:86740a56073b | 380 | |
AnnaBridge | 143:86740a56073b | 381 | /*! |
AnnaBridge | 143:86740a56073b | 382 | * @brief Writes values Monotonic Counter High and Monotonic Counter Low by decomposing |
AnnaBridge | 143:86740a56073b | 383 | * the given single value. |
AnnaBridge | 143:86740a56073b | 384 | * |
AnnaBridge | 143:86740a56073b | 385 | * @param base RTC peripheral base address |
AnnaBridge | 143:86740a56073b | 386 | * @param counter Counter value |
AnnaBridge | 143:86740a56073b | 387 | */ |
AnnaBridge | 143:86740a56073b | 388 | void RTC_SetMonotonicCounter(RTC_Type *base, uint64_t counter); |
AnnaBridge | 143:86740a56073b | 389 | |
AnnaBridge | 143:86740a56073b | 390 | /*! |
AnnaBridge | 143:86740a56073b | 391 | * @brief Increments the Monotonic Counter by one. |
AnnaBridge | 143:86740a56073b | 392 | * |
AnnaBridge | 143:86740a56073b | 393 | * Increments the Monotonic Counter (registers RTC_MCLR and RTC_MCHR accordingly) by setting |
AnnaBridge | 143:86740a56073b | 394 | * the monotonic counter enable (MER[MCE]) and then writing to the RTC_MCLR register. A write to the |
AnnaBridge | 143:86740a56073b | 395 | * monotonic counter low that causes it to overflow also increments the monotonic counter high. |
AnnaBridge | 143:86740a56073b | 396 | * |
AnnaBridge | 143:86740a56073b | 397 | * @param base RTC peripheral base address |
AnnaBridge | 143:86740a56073b | 398 | * |
AnnaBridge | 143:86740a56073b | 399 | * @return kStatus_Success: success |
AnnaBridge | 143:86740a56073b | 400 | * kStatus_Fail: error occurred, either time invalid or monotonic overflow flag was found |
AnnaBridge | 143:86740a56073b | 401 | */ |
AnnaBridge | 143:86740a56073b | 402 | status_t RTC_IncrementMonotonicCounter(RTC_Type *base); |
AnnaBridge | 143:86740a56073b | 403 | |
AnnaBridge | 143:86740a56073b | 404 | /*! @}*/ |
AnnaBridge | 143:86740a56073b | 405 | |
AnnaBridge | 143:86740a56073b | 406 | #endif /* FSL_FEATURE_RTC_HAS_MONOTONIC */ |
AnnaBridge | 143:86740a56073b | 407 | |
AnnaBridge | 143:86740a56073b | 408 | #if defined(__cplusplus) |
AnnaBridge | 143:86740a56073b | 409 | } |
AnnaBridge | 143:86740a56073b | 410 | #endif |
AnnaBridge | 143:86740a56073b | 411 | |
AnnaBridge | 143:86740a56073b | 412 | /*! @}*/ |
AnnaBridge | 143:86740a56073b | 413 | |
AnnaBridge | 143:86740a56073b | 414 | #endif /* _FSL_RTC_H_ */ |