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