![](/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_KL43Z/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_driver |
kadonotakashi | 0:8fdf9a60065b | 37 | * @{ |
kadonotakashi | 0:8fdf9a60065b | 38 | */ |
kadonotakashi | 0:8fdf9a60065b | 39 | |
kadonotakashi | 0:8fdf9a60065b | 40 | /*! @file */ |
kadonotakashi | 0:8fdf9a60065b | 41 | |
kadonotakashi | 0:8fdf9a60065b | 42 | /******************************************************************************* |
kadonotakashi | 0:8fdf9a60065b | 43 | * Definitions |
kadonotakashi | 0:8fdf9a60065b | 44 | ******************************************************************************/ |
kadonotakashi | 0:8fdf9a60065b | 45 | |
kadonotakashi | 0:8fdf9a60065b | 46 | /*! @name Driver version */ |
kadonotakashi | 0:8fdf9a60065b | 47 | /*@{*/ |
kadonotakashi | 0:8fdf9a60065b | 48 | #define FSL_RTC_DRIVER_VERSION (MAKE_VERSION(2, 0, 0)) /*!< Version 2.0.0 */ |
kadonotakashi | 0:8fdf9a60065b | 49 | /*@}*/ |
kadonotakashi | 0:8fdf9a60065b | 50 | |
kadonotakashi | 0:8fdf9a60065b | 51 | /*! @brief List of RTC interrupts */ |
kadonotakashi | 0:8fdf9a60065b | 52 | typedef enum _rtc_interrupt_enable |
kadonotakashi | 0:8fdf9a60065b | 53 | { |
kadonotakashi | 0:8fdf9a60065b | 54 | kRTC_TimeInvalidInterruptEnable = RTC_IER_TIIE_MASK, /*!< Time invalid interrupt.*/ |
kadonotakashi | 0:8fdf9a60065b | 55 | kRTC_TimeOverflowInterruptEnable = RTC_IER_TOIE_MASK, /*!< Time overflow interrupt.*/ |
kadonotakashi | 0:8fdf9a60065b | 56 | kRTC_AlarmInterruptEnable = RTC_IER_TAIE_MASK, /*!< Alarm interrupt.*/ |
kadonotakashi | 0:8fdf9a60065b | 57 | kRTC_SecondsInterruptEnable = RTC_IER_TSIE_MASK /*!< Seconds interrupt.*/ |
kadonotakashi | 0:8fdf9a60065b | 58 | } rtc_interrupt_enable_t; |
kadonotakashi | 0:8fdf9a60065b | 59 | |
kadonotakashi | 0:8fdf9a60065b | 60 | /*! @brief List of RTC flags */ |
kadonotakashi | 0:8fdf9a60065b | 61 | typedef enum _rtc_status_flags |
kadonotakashi | 0:8fdf9a60065b | 62 | { |
kadonotakashi | 0:8fdf9a60065b | 63 | kRTC_TimeInvalidFlag = RTC_SR_TIF_MASK, /*!< Time invalid flag */ |
kadonotakashi | 0:8fdf9a60065b | 64 | kRTC_TimeOverflowFlag = RTC_SR_TOF_MASK, /*!< Time overflow flag */ |
kadonotakashi | 0:8fdf9a60065b | 65 | kRTC_AlarmFlag = RTC_SR_TAF_MASK /*!< Alarm flag*/ |
kadonotakashi | 0:8fdf9a60065b | 66 | } rtc_status_flags_t; |
kadonotakashi | 0:8fdf9a60065b | 67 | |
kadonotakashi | 0:8fdf9a60065b | 68 | /*! @brief List of RTC Oscillator capacitor load settings */ |
kadonotakashi | 0:8fdf9a60065b | 69 | typedef enum _rtc_osc_cap_load |
kadonotakashi | 0:8fdf9a60065b | 70 | { |
kadonotakashi | 0:8fdf9a60065b | 71 | kRTC_Capacitor_2p = RTC_CR_SC2P_MASK, /*!< 2pF capacitor load */ |
kadonotakashi | 0:8fdf9a60065b | 72 | kRTC_Capacitor_4p = RTC_CR_SC4P_MASK, /*!< 4pF capacitor load */ |
kadonotakashi | 0:8fdf9a60065b | 73 | kRTC_Capacitor_8p = RTC_CR_SC8P_MASK, /*!< 8pF capacitor load */ |
kadonotakashi | 0:8fdf9a60065b | 74 | kRTC_Capacitor_16p = RTC_CR_SC16P_MASK /*!< 16pF capacitor load */ |
kadonotakashi | 0:8fdf9a60065b | 75 | } rtc_osc_cap_load_t; |
kadonotakashi | 0:8fdf9a60065b | 76 | |
kadonotakashi | 0:8fdf9a60065b | 77 | /*! @brief Structure is used to hold the date and time */ |
kadonotakashi | 0:8fdf9a60065b | 78 | typedef struct _rtc_datetime |
kadonotakashi | 0:8fdf9a60065b | 79 | { |
kadonotakashi | 0:8fdf9a60065b | 80 | uint16_t year; /*!< Range from 1970 to 2099.*/ |
kadonotakashi | 0:8fdf9a60065b | 81 | uint8_t month; /*!< Range from 1 to 12.*/ |
kadonotakashi | 0:8fdf9a60065b | 82 | uint8_t day; /*!< Range from 1 to 31 (depending on month).*/ |
kadonotakashi | 0:8fdf9a60065b | 83 | uint8_t hour; /*!< Range from 0 to 23.*/ |
kadonotakashi | 0:8fdf9a60065b | 84 | uint8_t minute; /*!< Range from 0 to 59.*/ |
kadonotakashi | 0:8fdf9a60065b | 85 | uint8_t second; /*!< Range from 0 to 59.*/ |
kadonotakashi | 0:8fdf9a60065b | 86 | } rtc_datetime_t; |
kadonotakashi | 0:8fdf9a60065b | 87 | |
kadonotakashi | 0:8fdf9a60065b | 88 | /*! |
kadonotakashi | 0:8fdf9a60065b | 89 | * @brief RTC config structure |
kadonotakashi | 0:8fdf9a60065b | 90 | * |
kadonotakashi | 0:8fdf9a60065b | 91 | * This structure holds the configuration settings for the RTC peripheral. To initialize this |
kadonotakashi | 0:8fdf9a60065b | 92 | * structure to reasonable defaults, call the RTC_GetDefaultConfig() function and pass a |
kadonotakashi | 0:8fdf9a60065b | 93 | * pointer to your config structure instance. |
kadonotakashi | 0:8fdf9a60065b | 94 | * |
kadonotakashi | 0:8fdf9a60065b | 95 | * The config struct can be made const so it resides in flash |
kadonotakashi | 0:8fdf9a60065b | 96 | */ |
kadonotakashi | 0:8fdf9a60065b | 97 | typedef struct _rtc_config |
kadonotakashi | 0:8fdf9a60065b | 98 | { |
kadonotakashi | 0:8fdf9a60065b | 99 | bool wakeupSelect; /*!< true: Wakeup pin outputs the 32KHz clock; |
kadonotakashi | 0:8fdf9a60065b | 100 | false:Wakeup pin used to wakeup the chip */ |
kadonotakashi | 0:8fdf9a60065b | 101 | bool updateMode; /*!< true: Registers can be written even when locked under certain |
kadonotakashi | 0:8fdf9a60065b | 102 | conditions, false: No writes allowed when registers are locked */ |
kadonotakashi | 0:8fdf9a60065b | 103 | bool supervisorAccess; /*!< true: Non-supervisor accesses are allowed; |
kadonotakashi | 0:8fdf9a60065b | 104 | false: Non-supervisor accesses are not supported */ |
kadonotakashi | 0:8fdf9a60065b | 105 | uint32_t compensationInterval; /*!< Compensation interval that is written to the CIR field in RTC TCR Register */ |
kadonotakashi | 0:8fdf9a60065b | 106 | uint32_t compensationTime; /*!< Compensation time that is written to the TCR field in RTC TCR Register */ |
kadonotakashi | 0:8fdf9a60065b | 107 | } rtc_config_t; |
kadonotakashi | 0:8fdf9a60065b | 108 | |
kadonotakashi | 0:8fdf9a60065b | 109 | /******************************************************************************* |
kadonotakashi | 0:8fdf9a60065b | 110 | * API |
kadonotakashi | 0:8fdf9a60065b | 111 | ******************************************************************************/ |
kadonotakashi | 0:8fdf9a60065b | 112 | |
kadonotakashi | 0:8fdf9a60065b | 113 | #if defined(__cplusplus) |
kadonotakashi | 0:8fdf9a60065b | 114 | extern "C" { |
kadonotakashi | 0:8fdf9a60065b | 115 | #endif |
kadonotakashi | 0:8fdf9a60065b | 116 | |
kadonotakashi | 0:8fdf9a60065b | 117 | /*! |
kadonotakashi | 0:8fdf9a60065b | 118 | * @name Initialization and deinitialization |
kadonotakashi | 0:8fdf9a60065b | 119 | * @{ |
kadonotakashi | 0:8fdf9a60065b | 120 | */ |
kadonotakashi | 0:8fdf9a60065b | 121 | |
kadonotakashi | 0:8fdf9a60065b | 122 | /*! |
kadonotakashi | 0:8fdf9a60065b | 123 | * @brief Ungates the RTC clock and configures the peripheral for basic operation. |
kadonotakashi | 0:8fdf9a60065b | 124 | * |
kadonotakashi | 0:8fdf9a60065b | 125 | * This function will issue a software reset if the timer invalid flag is set. |
kadonotakashi | 0:8fdf9a60065b | 126 | * |
kadonotakashi | 0:8fdf9a60065b | 127 | * @note This API should be called at the beginning of the application using the RTC driver. |
kadonotakashi | 0:8fdf9a60065b | 128 | * |
kadonotakashi | 0:8fdf9a60065b | 129 | * @param base RTC peripheral base address |
kadonotakashi | 0:8fdf9a60065b | 130 | * @param config Pointer to user's RTC config structure. |
kadonotakashi | 0:8fdf9a60065b | 131 | */ |
kadonotakashi | 0:8fdf9a60065b | 132 | void RTC_Init(RTC_Type *base, const rtc_config_t *config); |
kadonotakashi | 0:8fdf9a60065b | 133 | |
kadonotakashi | 0:8fdf9a60065b | 134 | /*! |
kadonotakashi | 0:8fdf9a60065b | 135 | * @brief Stop the timer and gate the RTC clock |
kadonotakashi | 0:8fdf9a60065b | 136 | * |
kadonotakashi | 0:8fdf9a60065b | 137 | * @param base RTC peripheral base address |
kadonotakashi | 0:8fdf9a60065b | 138 | */ |
kadonotakashi | 0:8fdf9a60065b | 139 | static inline void RTC_Deinit(RTC_Type *base) |
kadonotakashi | 0:8fdf9a60065b | 140 | { |
kadonotakashi | 0:8fdf9a60065b | 141 | /* Stop the RTC timer */ |
kadonotakashi | 0:8fdf9a60065b | 142 | base->SR &= ~RTC_SR_TCE_MASK; |
kadonotakashi | 0:8fdf9a60065b | 143 | |
kadonotakashi | 0:8fdf9a60065b | 144 | /* Gate the module clock */ |
kadonotakashi | 0:8fdf9a60065b | 145 | CLOCK_DisableClock(kCLOCK_Rtc0); |
kadonotakashi | 0:8fdf9a60065b | 146 | } |
kadonotakashi | 0:8fdf9a60065b | 147 | |
kadonotakashi | 0:8fdf9a60065b | 148 | /*! |
kadonotakashi | 0:8fdf9a60065b | 149 | * @brief Fill in the RTC config struct with the default settings |
kadonotakashi | 0:8fdf9a60065b | 150 | * |
kadonotakashi | 0:8fdf9a60065b | 151 | * The default values are: |
kadonotakashi | 0:8fdf9a60065b | 152 | * @code |
kadonotakashi | 0:8fdf9a60065b | 153 | * config->wakeupSelect = false; |
kadonotakashi | 0:8fdf9a60065b | 154 | * config->updateMode = false; |
kadonotakashi | 0:8fdf9a60065b | 155 | * config->supervisorAccess = false; |
kadonotakashi | 0:8fdf9a60065b | 156 | * config->compensationInterval = 0; |
kadonotakashi | 0:8fdf9a60065b | 157 | * config->compensationTime = 0; |
kadonotakashi | 0:8fdf9a60065b | 158 | * @endcode |
kadonotakashi | 0:8fdf9a60065b | 159 | * @param config Pointer to user's RTC config structure. |
kadonotakashi | 0:8fdf9a60065b | 160 | */ |
kadonotakashi | 0:8fdf9a60065b | 161 | void RTC_GetDefaultConfig(rtc_config_t *config); |
kadonotakashi | 0:8fdf9a60065b | 162 | |
kadonotakashi | 0:8fdf9a60065b | 163 | /*! @}*/ |
kadonotakashi | 0:8fdf9a60065b | 164 | |
kadonotakashi | 0:8fdf9a60065b | 165 | /*! |
kadonotakashi | 0:8fdf9a60065b | 166 | * @name Current Time & Alarm |
kadonotakashi | 0:8fdf9a60065b | 167 | * @{ |
kadonotakashi | 0:8fdf9a60065b | 168 | */ |
kadonotakashi | 0:8fdf9a60065b | 169 | |
kadonotakashi | 0:8fdf9a60065b | 170 | /*! |
kadonotakashi | 0:8fdf9a60065b | 171 | * @brief Sets the RTC date and time according to the given time structure. |
kadonotakashi | 0:8fdf9a60065b | 172 | * |
kadonotakashi | 0:8fdf9a60065b | 173 | * The RTC counter must be stopped prior to calling this function as writes to the RTC |
kadonotakashi | 0:8fdf9a60065b | 174 | * seconds register will fail if the RTC counter is running. |
kadonotakashi | 0:8fdf9a60065b | 175 | * |
kadonotakashi | 0:8fdf9a60065b | 176 | * @param base RTC peripheral base address |
kadonotakashi | 0:8fdf9a60065b | 177 | * @param datetime Pointer to structure where the date and time details to set are stored |
kadonotakashi | 0:8fdf9a60065b | 178 | * |
kadonotakashi | 0:8fdf9a60065b | 179 | * @return kStatus_Success: Success in setting the time and starting the RTC |
kadonotakashi | 0:8fdf9a60065b | 180 | * kStatus_InvalidArgument: Error because the datetime format is incorrect |
kadonotakashi | 0:8fdf9a60065b | 181 | */ |
kadonotakashi | 0:8fdf9a60065b | 182 | status_t RTC_SetDatetime(RTC_Type *base, const rtc_datetime_t *datetime); |
kadonotakashi | 0:8fdf9a60065b | 183 | |
kadonotakashi | 0:8fdf9a60065b | 184 | /*! |
kadonotakashi | 0:8fdf9a60065b | 185 | * @brief Gets the RTC time and stores it in the given time structure. |
kadonotakashi | 0:8fdf9a60065b | 186 | * |
kadonotakashi | 0:8fdf9a60065b | 187 | * @param base RTC peripheral base address |
kadonotakashi | 0:8fdf9a60065b | 188 | * @param datetime Pointer to structure where the date and time details are stored. |
kadonotakashi | 0:8fdf9a60065b | 189 | */ |
kadonotakashi | 0:8fdf9a60065b | 190 | void RTC_GetDatetime(RTC_Type *base, rtc_datetime_t *datetime); |
kadonotakashi | 0:8fdf9a60065b | 191 | |
kadonotakashi | 0:8fdf9a60065b | 192 | /*! |
kadonotakashi | 0:8fdf9a60065b | 193 | * @brief Sets the RTC alarm time |
kadonotakashi | 0:8fdf9a60065b | 194 | * |
kadonotakashi | 0:8fdf9a60065b | 195 | * The function checks whether the specified alarm time is greater than the present |
kadonotakashi | 0:8fdf9a60065b | 196 | * time. If not, the function does not set the alarm and returns an error. |
kadonotakashi | 0:8fdf9a60065b | 197 | * |
kadonotakashi | 0:8fdf9a60065b | 198 | * @param base RTC peripheral base address |
kadonotakashi | 0:8fdf9a60065b | 199 | * @param alarmTime Pointer to structure where the alarm time is stored. |
kadonotakashi | 0:8fdf9a60065b | 200 | * |
kadonotakashi | 0:8fdf9a60065b | 201 | * @return kStatus_Success: success in setting the RTC alarm |
kadonotakashi | 0:8fdf9a60065b | 202 | * kStatus_InvalidArgument: Error because the alarm datetime format is incorrect |
kadonotakashi | 0:8fdf9a60065b | 203 | * kStatus_Fail: Error because the alarm time has already passed |
kadonotakashi | 0:8fdf9a60065b | 204 | */ |
kadonotakashi | 0:8fdf9a60065b | 205 | status_t RTC_SetAlarm(RTC_Type *base, const rtc_datetime_t *alarmTime); |
kadonotakashi | 0:8fdf9a60065b | 206 | |
kadonotakashi | 0:8fdf9a60065b | 207 | /*! |
kadonotakashi | 0:8fdf9a60065b | 208 | * @brief Returns the RTC alarm time. |
kadonotakashi | 0:8fdf9a60065b | 209 | * |
kadonotakashi | 0:8fdf9a60065b | 210 | * @param base RTC peripheral base address |
kadonotakashi | 0:8fdf9a60065b | 211 | * @param datetime Pointer to structure where the alarm date and time details are stored. |
kadonotakashi | 0:8fdf9a60065b | 212 | */ |
kadonotakashi | 0:8fdf9a60065b | 213 | void RTC_GetAlarm(RTC_Type *base, rtc_datetime_t *datetime); |
kadonotakashi | 0:8fdf9a60065b | 214 | |
kadonotakashi | 0:8fdf9a60065b | 215 | /*! @}*/ |
kadonotakashi | 0:8fdf9a60065b | 216 | |
kadonotakashi | 0:8fdf9a60065b | 217 | /*! |
kadonotakashi | 0:8fdf9a60065b | 218 | * @name Interrupt Interface |
kadonotakashi | 0:8fdf9a60065b | 219 | * @{ |
kadonotakashi | 0:8fdf9a60065b | 220 | */ |
kadonotakashi | 0:8fdf9a60065b | 221 | |
kadonotakashi | 0:8fdf9a60065b | 222 | /*! |
kadonotakashi | 0:8fdf9a60065b | 223 | * @brief Enables the selected RTC interrupts. |
kadonotakashi | 0:8fdf9a60065b | 224 | * |
kadonotakashi | 0:8fdf9a60065b | 225 | * @param base RTC peripheral base address |
kadonotakashi | 0:8fdf9a60065b | 226 | * @param mask The interrupts to enable. This is a logical OR of members of the |
kadonotakashi | 0:8fdf9a60065b | 227 | * enumeration ::rtc_interrupt_enable_t |
kadonotakashi | 0:8fdf9a60065b | 228 | */ |
kadonotakashi | 0:8fdf9a60065b | 229 | static inline void RTC_EnableInterrupts(RTC_Type *base, uint32_t mask) |
kadonotakashi | 0:8fdf9a60065b | 230 | { |
kadonotakashi | 0:8fdf9a60065b | 231 | base->IER |= mask; |
kadonotakashi | 0:8fdf9a60065b | 232 | } |
kadonotakashi | 0:8fdf9a60065b | 233 | |
kadonotakashi | 0:8fdf9a60065b | 234 | /*! |
kadonotakashi | 0:8fdf9a60065b | 235 | * @brief Disables the selected RTC interrupts. |
kadonotakashi | 0:8fdf9a60065b | 236 | * |
kadonotakashi | 0:8fdf9a60065b | 237 | * @param base RTC peripheral base address |
kadonotakashi | 0:8fdf9a60065b | 238 | * @param mask The interrupts to enable. This is a logical OR of members of the |
kadonotakashi | 0:8fdf9a60065b | 239 | * enumeration ::rtc_interrupt_enable_t |
kadonotakashi | 0:8fdf9a60065b | 240 | */ |
kadonotakashi | 0:8fdf9a60065b | 241 | static inline void RTC_DisableInterrupts(RTC_Type *base, uint32_t mask) |
kadonotakashi | 0:8fdf9a60065b | 242 | { |
kadonotakashi | 0:8fdf9a60065b | 243 | base->IER &= ~mask; |
kadonotakashi | 0:8fdf9a60065b | 244 | } |
kadonotakashi | 0:8fdf9a60065b | 245 | |
kadonotakashi | 0:8fdf9a60065b | 246 | /*! |
kadonotakashi | 0:8fdf9a60065b | 247 | * @brief Gets the enabled RTC interrupts. |
kadonotakashi | 0:8fdf9a60065b | 248 | * |
kadonotakashi | 0:8fdf9a60065b | 249 | * @param base RTC peripheral base address |
kadonotakashi | 0:8fdf9a60065b | 250 | * |
kadonotakashi | 0:8fdf9a60065b | 251 | * @return The enabled interrupts. This is the logical OR of members of the |
kadonotakashi | 0:8fdf9a60065b | 252 | * enumeration ::rtc_interrupt_enable_t |
kadonotakashi | 0:8fdf9a60065b | 253 | */ |
kadonotakashi | 0:8fdf9a60065b | 254 | static inline uint32_t RTC_GetEnabledInterrupts(RTC_Type *base) |
kadonotakashi | 0:8fdf9a60065b | 255 | { |
kadonotakashi | 0:8fdf9a60065b | 256 | return (base->IER & (RTC_IER_TIIE_MASK | RTC_IER_TOIE_MASK | RTC_IER_TAIE_MASK | RTC_IER_TSIE_MASK)); |
kadonotakashi | 0:8fdf9a60065b | 257 | } |
kadonotakashi | 0:8fdf9a60065b | 258 | |
kadonotakashi | 0:8fdf9a60065b | 259 | /*! @}*/ |
kadonotakashi | 0:8fdf9a60065b | 260 | |
kadonotakashi | 0:8fdf9a60065b | 261 | /*! |
kadonotakashi | 0:8fdf9a60065b | 262 | * @name Status Interface |
kadonotakashi | 0:8fdf9a60065b | 263 | * @{ |
kadonotakashi | 0:8fdf9a60065b | 264 | */ |
kadonotakashi | 0:8fdf9a60065b | 265 | |
kadonotakashi | 0:8fdf9a60065b | 266 | /*! |
kadonotakashi | 0:8fdf9a60065b | 267 | * @brief Gets the RTC status flags |
kadonotakashi | 0:8fdf9a60065b | 268 | * |
kadonotakashi | 0:8fdf9a60065b | 269 | * @param base RTC peripheral base address |
kadonotakashi | 0:8fdf9a60065b | 270 | * |
kadonotakashi | 0:8fdf9a60065b | 271 | * @return The status flags. This is the logical OR of members of the |
kadonotakashi | 0:8fdf9a60065b | 272 | * enumeration ::rtc_status_flags_t |
kadonotakashi | 0:8fdf9a60065b | 273 | */ |
kadonotakashi | 0:8fdf9a60065b | 274 | static inline uint32_t RTC_GetStatusFlags(RTC_Type *base) |
kadonotakashi | 0:8fdf9a60065b | 275 | { |
kadonotakashi | 0:8fdf9a60065b | 276 | return (base->SR & (RTC_SR_TIF_MASK | RTC_SR_TOF_MASK | RTC_SR_TAF_MASK)); |
kadonotakashi | 0:8fdf9a60065b | 277 | } |
kadonotakashi | 0:8fdf9a60065b | 278 | |
kadonotakashi | 0:8fdf9a60065b | 279 | /*! |
kadonotakashi | 0:8fdf9a60065b | 280 | * @brief Clears the RTC status flags. |
kadonotakashi | 0:8fdf9a60065b | 281 | * |
kadonotakashi | 0:8fdf9a60065b | 282 | * @param base RTC peripheral base address |
kadonotakashi | 0:8fdf9a60065b | 283 | * @param mask The status flags to clear. This is a logical OR of members of the |
kadonotakashi | 0:8fdf9a60065b | 284 | * enumeration ::rtc_status_flags_t |
kadonotakashi | 0:8fdf9a60065b | 285 | */ |
kadonotakashi | 0:8fdf9a60065b | 286 | void RTC_ClearStatusFlags(RTC_Type *base, uint32_t mask); |
kadonotakashi | 0:8fdf9a60065b | 287 | |
kadonotakashi | 0:8fdf9a60065b | 288 | /*! @}*/ |
kadonotakashi | 0:8fdf9a60065b | 289 | |
kadonotakashi | 0:8fdf9a60065b | 290 | /*! |
kadonotakashi | 0:8fdf9a60065b | 291 | * @name Timer Start and Stop |
kadonotakashi | 0:8fdf9a60065b | 292 | * @{ |
kadonotakashi | 0:8fdf9a60065b | 293 | */ |
kadonotakashi | 0:8fdf9a60065b | 294 | |
kadonotakashi | 0:8fdf9a60065b | 295 | /*! |
kadonotakashi | 0:8fdf9a60065b | 296 | * @brief Starts the RTC time counter. |
kadonotakashi | 0:8fdf9a60065b | 297 | * |
kadonotakashi | 0:8fdf9a60065b | 298 | * After calling this function, the timer counter increments once a second provided SR[TOF] or |
kadonotakashi | 0:8fdf9a60065b | 299 | * SR[TIF] are not set. |
kadonotakashi | 0:8fdf9a60065b | 300 | * |
kadonotakashi | 0:8fdf9a60065b | 301 | * @param base RTC peripheral base address |
kadonotakashi | 0:8fdf9a60065b | 302 | */ |
kadonotakashi | 0:8fdf9a60065b | 303 | static inline void RTC_StartTimer(RTC_Type *base) |
kadonotakashi | 0:8fdf9a60065b | 304 | { |
kadonotakashi | 0:8fdf9a60065b | 305 | base->SR |= RTC_SR_TCE_MASK; |
kadonotakashi | 0:8fdf9a60065b | 306 | } |
kadonotakashi | 0:8fdf9a60065b | 307 | |
kadonotakashi | 0:8fdf9a60065b | 308 | /*! |
kadonotakashi | 0:8fdf9a60065b | 309 | * @brief Stops the RTC time counter. |
kadonotakashi | 0:8fdf9a60065b | 310 | * |
kadonotakashi | 0:8fdf9a60065b | 311 | * RTC's seconds register can be written to only when the timer is stopped. |
kadonotakashi | 0:8fdf9a60065b | 312 | * |
kadonotakashi | 0:8fdf9a60065b | 313 | * @param base RTC peripheral base address |
kadonotakashi | 0:8fdf9a60065b | 314 | */ |
kadonotakashi | 0:8fdf9a60065b | 315 | static inline void RTC_StopTimer(RTC_Type *base) |
kadonotakashi | 0:8fdf9a60065b | 316 | { |
kadonotakashi | 0:8fdf9a60065b | 317 | base->SR &= ~RTC_SR_TCE_MASK; |
kadonotakashi | 0:8fdf9a60065b | 318 | } |
kadonotakashi | 0:8fdf9a60065b | 319 | |
kadonotakashi | 0:8fdf9a60065b | 320 | /*! @}*/ |
kadonotakashi | 0:8fdf9a60065b | 321 | |
kadonotakashi | 0:8fdf9a60065b | 322 | /*! |
kadonotakashi | 0:8fdf9a60065b | 323 | * @brief This function sets the specified capacitor configuration for the RTC oscillator. |
kadonotakashi | 0:8fdf9a60065b | 324 | * |
kadonotakashi | 0:8fdf9a60065b | 325 | * @param base RTC peripheral base address |
kadonotakashi | 0:8fdf9a60065b | 326 | * @param capLoad Oscillator loads to enable. This is a logical OR of members of the |
kadonotakashi | 0:8fdf9a60065b | 327 | * enumeration ::rtc_osc_cap_load_t |
kadonotakashi | 0:8fdf9a60065b | 328 | */ |
kadonotakashi | 0:8fdf9a60065b | 329 | static inline void RTC_SetOscCapLoad(RTC_Type *base, uint32_t capLoad) |
kadonotakashi | 0:8fdf9a60065b | 330 | { |
kadonotakashi | 0:8fdf9a60065b | 331 | uint32_t reg = base->CR; |
kadonotakashi | 0:8fdf9a60065b | 332 | |
kadonotakashi | 0:8fdf9a60065b | 333 | reg &= ~(RTC_CR_SC2P_MASK | RTC_CR_SC4P_MASK | RTC_CR_SC8P_MASK | RTC_CR_SC16P_MASK); |
kadonotakashi | 0:8fdf9a60065b | 334 | reg |= capLoad; |
kadonotakashi | 0:8fdf9a60065b | 335 | |
kadonotakashi | 0:8fdf9a60065b | 336 | base->CR = reg; |
kadonotakashi | 0:8fdf9a60065b | 337 | } |
kadonotakashi | 0:8fdf9a60065b | 338 | |
kadonotakashi | 0:8fdf9a60065b | 339 | /*! |
kadonotakashi | 0:8fdf9a60065b | 340 | * @brief Performs a software reset on the RTC module. |
kadonotakashi | 0:8fdf9a60065b | 341 | * |
kadonotakashi | 0:8fdf9a60065b | 342 | * This resets all RTC registers except for the SWR bit and the RTC_WAR and RTC_RAR |
kadonotakashi | 0:8fdf9a60065b | 343 | * registers. The SWR bit is cleared by software explicitly clearing it. |
kadonotakashi | 0:8fdf9a60065b | 344 | * |
kadonotakashi | 0:8fdf9a60065b | 345 | * @param base RTC peripheral base address |
kadonotakashi | 0:8fdf9a60065b | 346 | */ |
kadonotakashi | 0:8fdf9a60065b | 347 | static inline void RTC_Reset(RTC_Type *base) |
kadonotakashi | 0:8fdf9a60065b | 348 | { |
kadonotakashi | 0:8fdf9a60065b | 349 | base->CR |= RTC_CR_SWR_MASK; |
kadonotakashi | 0:8fdf9a60065b | 350 | base->CR &= ~RTC_CR_SWR_MASK; |
kadonotakashi | 0:8fdf9a60065b | 351 | |
kadonotakashi | 0:8fdf9a60065b | 352 | /* Set TSR register to 0x1 to avoid the timer invalid (TIF) bit being set in the SR register */ |
kadonotakashi | 0:8fdf9a60065b | 353 | base->TSR = 1U; |
kadonotakashi | 0:8fdf9a60065b | 354 | } |
kadonotakashi | 0:8fdf9a60065b | 355 | |
kadonotakashi | 0:8fdf9a60065b | 356 | #if defined(FSL_FEATURE_RTC_HAS_MONOTONIC) && (FSL_FEATURE_RTC_HAS_MONOTONIC) |
kadonotakashi | 0:8fdf9a60065b | 357 | |
kadonotakashi | 0:8fdf9a60065b | 358 | /*! |
kadonotakashi | 0:8fdf9a60065b | 359 | * @name Monotonic counter functions |
kadonotakashi | 0:8fdf9a60065b | 360 | * @{ |
kadonotakashi | 0:8fdf9a60065b | 361 | */ |
kadonotakashi | 0:8fdf9a60065b | 362 | |
kadonotakashi | 0:8fdf9a60065b | 363 | /*! |
kadonotakashi | 0:8fdf9a60065b | 364 | * @brief Reads the values of the Monotonic Counter High and Monotonic Counter Low and returns |
kadonotakashi | 0:8fdf9a60065b | 365 | * them as a single value. |
kadonotakashi | 0:8fdf9a60065b | 366 | * |
kadonotakashi | 0:8fdf9a60065b | 367 | * @param base RTC peripheral base address |
kadonotakashi | 0:8fdf9a60065b | 368 | * @param counter Pointer to variable where the value is stored. |
kadonotakashi | 0:8fdf9a60065b | 369 | */ |
kadonotakashi | 0:8fdf9a60065b | 370 | void RTC_GetMonotonicCounter(RTC_Type *base, uint64_t *counter); |
kadonotakashi | 0:8fdf9a60065b | 371 | |
kadonotakashi | 0:8fdf9a60065b | 372 | /*! |
kadonotakashi | 0:8fdf9a60065b | 373 | * @brief Writes values Monotonic Counter High and Monotonic Counter Low by decomposing |
kadonotakashi | 0:8fdf9a60065b | 374 | * the given single value. |
kadonotakashi | 0:8fdf9a60065b | 375 | * |
kadonotakashi | 0:8fdf9a60065b | 376 | * @param base RTC peripheral base address |
kadonotakashi | 0:8fdf9a60065b | 377 | * @param counter Counter value |
kadonotakashi | 0:8fdf9a60065b | 378 | */ |
kadonotakashi | 0:8fdf9a60065b | 379 | void RTC_SetMonotonicCounter(RTC_Type *base, uint64_t counter); |
kadonotakashi | 0:8fdf9a60065b | 380 | |
kadonotakashi | 0:8fdf9a60065b | 381 | /*! |
kadonotakashi | 0:8fdf9a60065b | 382 | * @brief Increments the Monotonic Counter by one. |
kadonotakashi | 0:8fdf9a60065b | 383 | * |
kadonotakashi | 0:8fdf9a60065b | 384 | * Increments the Monotonic Counter (registers RTC_MCLR and RTC_MCHR accordingly) by setting |
kadonotakashi | 0:8fdf9a60065b | 385 | * the monotonic counter enable (MER[MCE]) and then writing to the RTC_MCLR register. A write to the |
kadonotakashi | 0:8fdf9a60065b | 386 | * monotonic counter low that causes it to overflow also increments the monotonic counter high. |
kadonotakashi | 0:8fdf9a60065b | 387 | * |
kadonotakashi | 0:8fdf9a60065b | 388 | * @param base RTC peripheral base address |
kadonotakashi | 0:8fdf9a60065b | 389 | * |
kadonotakashi | 0:8fdf9a60065b | 390 | * @return kStatus_Success: success |
kadonotakashi | 0:8fdf9a60065b | 391 | * kStatus_Fail: error occurred, either time invalid or monotonic overflow flag was found |
kadonotakashi | 0:8fdf9a60065b | 392 | */ |
kadonotakashi | 0:8fdf9a60065b | 393 | status_t RTC_IncrementMonotonicCounter(RTC_Type *base); |
kadonotakashi | 0:8fdf9a60065b | 394 | |
kadonotakashi | 0:8fdf9a60065b | 395 | /*! @}*/ |
kadonotakashi | 0:8fdf9a60065b | 396 | |
kadonotakashi | 0:8fdf9a60065b | 397 | #endif /* FSL_FEATURE_RTC_HAS_MONOTONIC */ |
kadonotakashi | 0:8fdf9a60065b | 398 | |
kadonotakashi | 0:8fdf9a60065b | 399 | #if defined(__cplusplus) |
kadonotakashi | 0:8fdf9a60065b | 400 | } |
kadonotakashi | 0:8fdf9a60065b | 401 | #endif |
kadonotakashi | 0:8fdf9a60065b | 402 | |
kadonotakashi | 0:8fdf9a60065b | 403 | /*! @}*/ |
kadonotakashi | 0:8fdf9a60065b | 404 | |
kadonotakashi | 0:8fdf9a60065b | 405 | #endif /* _FSL_RTC_H_ */ |