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