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.

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?

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