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