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 167:84c0a372a020 1 /**
AnnaBridge 167:84c0a372a020 2 * @file
AnnaBridge 167:84c0a372a020 3 * @brief Real-Time Clock data types, definitions and function prototypes.
AnnaBridge 167:84c0a372a020 4 */
AnnaBridge 167:84c0a372a020 5 /* ****************************************************************************
AnnaBridge 167:84c0a372a020 6 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
AnnaBridge 167:84c0a372a020 7 *
AnnaBridge 167:84c0a372a020 8 * Permission is hereby granted, free of charge, to any person obtaining a
AnnaBridge 167:84c0a372a020 9 * copy of this software and associated documentation files (the "Software"),
AnnaBridge 167:84c0a372a020 10 * to deal in the Software without restriction, including without limitation
AnnaBridge 167:84c0a372a020 11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
AnnaBridge 167:84c0a372a020 12 * and/or sell copies of the Software, and to permit persons to whom the
AnnaBridge 167:84c0a372a020 13 * Software is furnished to do so, subject to the following conditions:
AnnaBridge 167:84c0a372a020 14 *
AnnaBridge 167:84c0a372a020 15 * The above copyright notice and this permission notice shall be included
AnnaBridge 167:84c0a372a020 16 * in all copies or substantial portions of the Software.
AnnaBridge 167:84c0a372a020 17 *
AnnaBridge 167:84c0a372a020 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
AnnaBridge 167:84c0a372a020 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
AnnaBridge 167:84c0a372a020 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
AnnaBridge 167:84c0a372a020 21 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
AnnaBridge 167:84c0a372a020 22 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
AnnaBridge 167:84c0a372a020 23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
AnnaBridge 167:84c0a372a020 24 * OTHER DEALINGS IN THE SOFTWARE.
AnnaBridge 167:84c0a372a020 25 *
AnnaBridge 167:84c0a372a020 26 * Except as contained in this notice, the name of Maxim Integrated
AnnaBridge 167:84c0a372a020 27 * Products, Inc. shall not be used except as stated in the Maxim Integrated
AnnaBridge 167:84c0a372a020 28 * Products, Inc. Branding Policy.
AnnaBridge 167:84c0a372a020 29 *
AnnaBridge 167:84c0a372a020 30 * The mere transfer of this software does not imply any licenses
AnnaBridge 167:84c0a372a020 31 * of trade secrets, proprietary technology, copyrights, patents,
AnnaBridge 167:84c0a372a020 32 * trademarks, maskwork rights, or any other form of intellectual
AnnaBridge 167:84c0a372a020 33 * property whatsoever. Maxim Integrated Products, Inc. retains all
AnnaBridge 167:84c0a372a020 34 * ownership rights.
AnnaBridge 167:84c0a372a020 35 *
AnnaBridge 167:84c0a372a020 36 * $Date: 2017-02-16 12:04:19 -0600 (Thu, 16 Feb 2017) $
AnnaBridge 167:84c0a372a020 37 * $Revision: 26465 $
AnnaBridge 167:84c0a372a020 38 *
AnnaBridge 167:84c0a372a020 39 **************************************************************************** */
AnnaBridge 167:84c0a372a020 40
AnnaBridge 167:84c0a372a020 41 /* Define to prevent redundant inclusion */
AnnaBridge 167:84c0a372a020 42 #ifndef _RTC_H_
AnnaBridge 167:84c0a372a020 43 #define _RTC_H_
AnnaBridge 167:84c0a372a020 44
AnnaBridge 167:84c0a372a020 45 /* **** Includes **** */
AnnaBridge 167:84c0a372a020 46 #include "mxc_config.h"
AnnaBridge 167:84c0a372a020 47 #include "rtc_regs.h"
AnnaBridge 167:84c0a372a020 48
AnnaBridge 167:84c0a372a020 49 #ifdef __cplusplus
AnnaBridge 167:84c0a372a020 50 extern "C" {
AnnaBridge 167:84c0a372a020 51 #endif
AnnaBridge 167:84c0a372a020 52
AnnaBridge 167:84c0a372a020 53 /**
AnnaBridge 167:84c0a372a020 54 * @ingroup periphlibs
AnnaBridge 167:84c0a372a020 55 * @defgroup rtc Real-Time Clock (RTC)
AnnaBridge 167:84c0a372a020 56 * @brief Functions, types, and registers for the Real-Time Clock Peripheral.
AnnaBridge 167:84c0a372a020 57 * @{
AnnaBridge 167:84c0a372a020 58 */
AnnaBridge 167:84c0a372a020 59
AnnaBridge 167:84c0a372a020 60 /* **** Definitions **** */
AnnaBridge 167:84c0a372a020 61 /**
AnnaBridge 167:84c0a372a020 62 * Enumeration type for scaling down the 4096Hz input clock to the RTC.
AnnaBridge 167:84c0a372a020 63 */
AnnaBridge 167:84c0a372a020 64 typedef enum {
AnnaBridge 167:84c0a372a020 65 RTC_PRESCALE_DIV_2_0 = MXC_V_RTC_PRESCALE_DIV_2_0, /**< \f$ f_{RTC} = \frac {4096} {2^{0}} = 4096Hz \f$ */
AnnaBridge 167:84c0a372a020 66 RTC_PRESCALE_DIV_2_1 = MXC_V_RTC_PRESCALE_DIV_2_1, /**< \f$ f_{RTC} = \frac {4096} {2^{1}} = 2048Hz \f$ */
AnnaBridge 167:84c0a372a020 67 RTC_PRESCALE_DIV_2_2 = MXC_V_RTC_PRESCALE_DIV_2_2, /**< \f$ f_{RTC} = \frac {4096} {2^{2}} = 1024Hz \f$ */
AnnaBridge 167:84c0a372a020 68 RTC_PRESCALE_DIV_2_3 = MXC_V_RTC_PRESCALE_DIV_2_3, /**< \f$ f_{RTC} = \frac {4096} {2^{3}} = 512Hz \f$ */
AnnaBridge 167:84c0a372a020 69 RTC_PRESCALE_DIV_2_4 = MXC_V_RTC_PRESCALE_DIV_2_4, /**< \f$ f_{RTC} = \frac {4096} {2^{4}} = 256Hz \f$ */
AnnaBridge 167:84c0a372a020 70 RTC_PRESCALE_DIV_2_5 = MXC_V_RTC_PRESCALE_DIV_2_5, /**< \f$ f_{RTC} = \frac {4096} {2^{5}} = 128Hz \f$ */
AnnaBridge 167:84c0a372a020 71 RTC_PRESCALE_DIV_2_6 = MXC_V_RTC_PRESCALE_DIV_2_6, /**< \f$ f_{RTC} = \frac {4096} {2^{6}} = 64Hz \f$ */
AnnaBridge 167:84c0a372a020 72 RTC_PRESCALE_DIV_2_7 = MXC_V_RTC_PRESCALE_DIV_2_7, /**< \f$ f_{RTC} = \frac {4096} {2^{7}} = 32Hz \f$ */
AnnaBridge 167:84c0a372a020 73 RTC_PRESCALE_DIV_2_8 = MXC_V_RTC_PRESCALE_DIV_2_8, /**< \f$ f_{RTC} = \frac {4096} {2^{8}} = 16Hz \f$ */
AnnaBridge 167:84c0a372a020 74 RTC_PRESCALE_DIV_2_9 = MXC_V_RTC_PRESCALE_DIV_2_9, /**< \f$ f_{RTC} = \frac {4096} {2^{9}} = 8Hz \f$ */
AnnaBridge 167:84c0a372a020 75 RTC_PRESCALE_DIV_2_10 = MXC_V_RTC_PRESCALE_DIV_2_10, /**< \f$ f_{RTC} = \frac {4096} {2^{10}} = 4Hz \f$ */
AnnaBridge 167:84c0a372a020 76 RTC_PRESCALE_DIV_2_11 = MXC_V_RTC_PRESCALE_DIV_2_11, /**< \f$ f_{RTC} = \frac {4096} {2^{11}} = 2Hz \f$ */
AnnaBridge 167:84c0a372a020 77 RTC_PRESCALE_DIV_2_12 = MXC_V_RTC_PRESCALE_DIV_2_12, /**< \f$ f_{RTC} = \frac {4096} {2^{12}} = 1Hz \f$ */
AnnaBridge 167:84c0a372a020 78 } rtc_prescale_t;
AnnaBridge 167:84c0a372a020 79
AnnaBridge 167:84c0a372a020 80 /**
AnnaBridge 167:84c0a372a020 81 * Mask of the RTC Flags for the Active Transaction.
AnnaBridge 167:84c0a372a020 82 */
AnnaBridge 167:84c0a372a020 83 #define RTC_CTRL_ACTIVE_TRANS (MXC_F_RTC_CTRL_RTC_ENABLE_ACTIVE | \
AnnaBridge 167:84c0a372a020 84 MXC_F_RTC_CTRL_OSC_GOTO_LOW_ACTIVE | \
AnnaBridge 167:84c0a372a020 85 MXC_F_RTC_CTRL_OSC_FRCE_SM_EN_ACTIVE | \
AnnaBridge 167:84c0a372a020 86 MXC_F_RTC_CTRL_OSC_FRCE_ST_ACTIVE | \
AnnaBridge 167:84c0a372a020 87 MXC_F_RTC_CTRL_RTC_SET_ACTIVE | \
AnnaBridge 167:84c0a372a020 88 MXC_F_RTC_CTRL_RTC_CLR_ACTIVE | \
AnnaBridge 167:84c0a372a020 89 MXC_F_RTC_CTRL_ROLLOVER_CLR_ACTIVE | \
AnnaBridge 167:84c0a372a020 90 MXC_F_RTC_CTRL_PRESCALE_CMPR0_ACTIVE | \
AnnaBridge 167:84c0a372a020 91 MXC_F_RTC_CTRL_PRESCALE_UPDATE_ACTIVE | \
AnnaBridge 167:84c0a372a020 92 MXC_F_RTC_CTRL_CMPR1_CLR_ACTIVE | \
AnnaBridge 167:84c0a372a020 93 MXC_F_RTC_CTRL_CMPR0_CLR_ACTIVE | \
AnnaBridge 167:84c0a372a020 94 MXC_F_RTC_CTRL_TRIM_ENABLE_ACTIVE | \
AnnaBridge 167:84c0a372a020 95 MXC_F_RTC_CTRL_TRIM_SLOWER_ACTIVE | \
AnnaBridge 167:84c0a372a020 96 MXC_F_RTC_CTRL_TRIM_CLR_ACTIVE | \
AnnaBridge 167:84c0a372a020 97 MXC_F_RTC_CTRL_ACTIVE_TRANS_0)
AnnaBridge 167:84c0a372a020 98
AnnaBridge 167:84c0a372a020 99 /**
AnnaBridge 167:84c0a372a020 100 * Mask used to clear all RTC interrupt flags, see \ref RTC_FLAGS_Register Register.
AnnaBridge 167:84c0a372a020 101 */
AnnaBridge 167:84c0a372a020 102 #define RTC_FLAGS_CLEAR_ALL (MXC_F_RTC_FLAGS_COMP0 | \
AnnaBridge 167:84c0a372a020 103 MXC_F_RTC_FLAGS_COMP1| \
AnnaBridge 167:84c0a372a020 104 MXC_F_RTC_FLAGS_PRESCALE_COMP | \
AnnaBridge 167:84c0a372a020 105 MXC_F_RTC_FLAGS_OVERFLOW | \
AnnaBridge 167:84c0a372a020 106 MXC_F_RTC_FLAGS_TRIM)
AnnaBridge 167:84c0a372a020 107 /**
AnnaBridge 167:84c0a372a020 108 * Enumeration type to select the type of RTC Snooze Mode for an alarm condition.
AnnaBridge 167:84c0a372a020 109 */
AnnaBridge 167:84c0a372a020 110 typedef enum {
AnnaBridge 167:84c0a372a020 111 RTC_SNOOZE_DISABLE = MXC_V_RTC_CTRL_SNOOZE_DISABLE, /**< Snooze Mode Disabled */
AnnaBridge 167:84c0a372a020 112 RTC_SNOOZE_MODE_A = MXC_V_RTC_CTRL_SNOOZE_MODE_A, /**< \f$ COMP1 = COMP1 + RTC\_SNZ\_VALUE \f$ when snooze flag is set */
AnnaBridge 167:84c0a372a020 113 RTC_SNOOZE_MODE_B = MXC_V_RTC_CTRL_SNOOZE_MODE_B, /**< \f$ COMP1 = RTC\_TIMER + RTC\_SNZ\_VALUE \f$ when snooze flag is set */
AnnaBridge 167:84c0a372a020 114 } rtc_snooze_t;
AnnaBridge 167:84c0a372a020 115
AnnaBridge 167:84c0a372a020 116 /**
AnnaBridge 167:84c0a372a020 117 * Number of RTC Compare registers for this peripheral instance.
AnnaBridge 167:84c0a372a020 118 */
AnnaBridge 167:84c0a372a020 119 #define RTC_NUM_COMPARE 2
AnnaBridge 167:84c0a372a020 120
AnnaBridge 167:84c0a372a020 121 /**
AnnaBridge 167:84c0a372a020 122 * Structure type that represents the current configuration of the RTC.
AnnaBridge 167:84c0a372a020 123 */
AnnaBridge 167:84c0a372a020 124
AnnaBridge 167:84c0a372a020 125 typedef struct {
AnnaBridge 167:84c0a372a020 126 rtc_prescale_t prescaler; /**< prescale value for the input 4096Hz clock. */
AnnaBridge 167:84c0a372a020 127 rtc_prescale_t prescalerMask; /**< Mask value used to compare to the rtc prescale value, when the \f$ (Count_{prescaler}\,\&\,Prescale\,Mask) == 0 \f$, the prescale compare flag will be set. */
AnnaBridge 167:84c0a372a020 128 uint32_t compareCount[RTC_NUM_COMPARE]; /**< Values used for setting the RTC alarms. See RTC_SetCompare(uint8_t compareIndex, uint32_t counts) and RTC_GetCompare(). */
AnnaBridge 167:84c0a372a020 129 uint32_t snoozeCount; /**< The number of RTC ticks to snooze if enabled. */
AnnaBridge 167:84c0a372a020 130 rtc_snooze_t snoozeMode; /**< The desired snooze mode, see #rtc_snooze_t. */
AnnaBridge 167:84c0a372a020 131 } rtc_cfg_t;
AnnaBridge 167:84c0a372a020 132
AnnaBridge 167:84c0a372a020 133 /**
AnnaBridge 167:84c0a372a020 134 * @brief Initializes the RTC
AnnaBridge 167:84c0a372a020 135 * @note Must setup clocking and power prior to this function.
AnnaBridge 167:84c0a372a020 136 *
AnnaBridge 167:84c0a372a020 137 * @param cfg RTC configuration object.
AnnaBridge 167:84c0a372a020 138 *
AnnaBridge 167:84c0a372a020 139 * @retval #E_NO_ERROR RTC initialized successfully.
AnnaBridge 167:84c0a372a020 140 * @retval #E_NULL_PTR \p cfg pointer is NULL.
AnnaBridge 167:84c0a372a020 141 * @retval #E_INVALID if comparison index, prescaler mask or snooze mask
AnnaBridge 167:84c0a372a020 142 * are out of bounds, see #rtc_cfg_t.
AnnaBridge 167:84c0a372a020 143 */
AnnaBridge 167:84c0a372a020 144 int RTC_Init(const rtc_cfg_t *cfg);
AnnaBridge 167:84c0a372a020 145
AnnaBridge 167:84c0a372a020 146 /**
AnnaBridge 167:84c0a372a020 147 * @brief Enable and start the real-time clock continuing from its current value.
AnnaBridge 167:84c0a372a020 148 */
AnnaBridge 167:84c0a372a020 149 __STATIC_INLINE void RTC_Start(void)
AnnaBridge 167:84c0a372a020 150 {
AnnaBridge 167:84c0a372a020 151 MXC_RTCTMR->ctrl |= MXC_F_RTC_CTRL_ENABLE;
AnnaBridge 167:84c0a372a020 152
AnnaBridge 167:84c0a372a020 153 //wait for pending actions to complete
AnnaBridge 167:84c0a372a020 154 while(MXC_RTCTMR->ctrl & MXC_F_RTC_CTRL_PENDING);
AnnaBridge 167:84c0a372a020 155 }
AnnaBridge 167:84c0a372a020 156
AnnaBridge 167:84c0a372a020 157 /**
AnnaBridge 167:84c0a372a020 158 * @brief Disable and stop the real-time clock counting.
AnnaBridge 167:84c0a372a020 159 */
AnnaBridge 167:84c0a372a020 160 __STATIC_INLINE void RTC_Stop(void)
AnnaBridge 167:84c0a372a020 161 {
AnnaBridge 167:84c0a372a020 162 MXC_RTCTMR->ctrl &= ~(MXC_F_RTC_CTRL_ENABLE);
AnnaBridge 167:84c0a372a020 163
AnnaBridge 167:84c0a372a020 164 //wait for pending actions to complete
AnnaBridge 167:84c0a372a020 165 while(MXC_RTCTMR->ctrl & MXC_F_RTC_CTRL_PENDING);
AnnaBridge 167:84c0a372a020 166 }
AnnaBridge 167:84c0a372a020 167
AnnaBridge 167:84c0a372a020 168 /**
AnnaBridge 167:84c0a372a020 169 * @brief Returns the state (running or disabled) for the RTC.
AnnaBridge 167:84c0a372a020 170 *
AnnaBridge 167:84c0a372a020 171 * @retval 0 Disabled.
AnnaBridge 167:84c0a372a020 172 * @retval Non-zero Active.
AnnaBridge 167:84c0a372a020 173 */
AnnaBridge 167:84c0a372a020 174 __STATIC_INLINE uint32_t RTC_IsActive(void)
AnnaBridge 167:84c0a372a020 175 {
AnnaBridge 167:84c0a372a020 176 return (MXC_RTCTMR->ctrl & MXC_F_RTC_CTRL_ENABLE);
AnnaBridge 167:84c0a372a020 177 }
AnnaBridge 167:84c0a372a020 178
AnnaBridge 167:84c0a372a020 179 /**
AnnaBridge 167:84c0a372a020 180 * @brief Set the current count of the RTC
AnnaBridge 167:84c0a372a020 181 *
AnnaBridge 167:84c0a372a020 182 * @param count The desired count value to set for the RTC count.
AnnaBridge 167:84c0a372a020 183 */
AnnaBridge 167:84c0a372a020 184 __STATIC_INLINE void RTC_SetCount(uint32_t count)
AnnaBridge 167:84c0a372a020 185 {
AnnaBridge 167:84c0a372a020 186 MXC_RTCTMR->timer = count;
AnnaBridge 167:84c0a372a020 187
AnnaBridge 167:84c0a372a020 188 //wait for pending actions to complete
AnnaBridge 167:84c0a372a020 189 while(MXC_RTCTMR->ctrl & MXC_F_RTC_CTRL_PENDING);
AnnaBridge 167:84c0a372a020 190 }
AnnaBridge 167:84c0a372a020 191
AnnaBridge 167:84c0a372a020 192 /**
AnnaBridge 167:84c0a372a020 193 * @brief Get the current count value of the RTC.
AnnaBridge 167:84c0a372a020 194 *
AnnaBridge 167:84c0a372a020 195 * @retval The value of the RTC counter.
AnnaBridge 167:84c0a372a020 196 */
AnnaBridge 167:84c0a372a020 197 __STATIC_INLINE uint32_t RTC_GetCount(void)
AnnaBridge 167:84c0a372a020 198 {
AnnaBridge 167:84c0a372a020 199 return (MXC_RTCTMR->timer);
AnnaBridge 167:84c0a372a020 200 }
AnnaBridge 167:84c0a372a020 201
AnnaBridge 167:84c0a372a020 202 /**
AnnaBridge 167:84c0a372a020 203 * @brief Sets the compare value for the RTC.
AnnaBridge 167:84c0a372a020 204 *
AnnaBridge 167:84c0a372a020 205 * @param compareIndex Index of comparator to set, see #RTC_NUM_COMPARE
AnnaBridge 167:84c0a372a020 206 * for the total number of compare registers
AnnaBridge 167:84c0a372a020 207 * available.
AnnaBridge 167:84c0a372a020 208 * @param counts The value to set for the compare.
AnnaBridge 167:84c0a372a020 209 * @retval #E_NO_ERROR Compare count register set successfully for
AnnaBridge 167:84c0a372a020 210 * requested comparator.
AnnaBridge 167:84c0a372a020 211 * @retval #E_INVALID compareIndex is @>= RTC_NUM_COMPARE.
AnnaBridge 167:84c0a372a020 212 */
AnnaBridge 167:84c0a372a020 213 int RTC_SetCompare(uint8_t compareIndex, uint32_t counts);
AnnaBridge 167:84c0a372a020 214
AnnaBridge 167:84c0a372a020 215 /**
AnnaBridge 167:84c0a372a020 216 * @brief Gets the compare value for the RTC.
AnnaBridge 167:84c0a372a020 217 *
AnnaBridge 167:84c0a372a020 218 * @param compareIndex Index of the compare value to return. See #RTC_NUM_COMPARE
AnnaBridge 167:84c0a372a020 219 * for the total number of compare registers available.
AnnaBridge 167:84c0a372a020 220 *
AnnaBridge 167:84c0a372a020 221 * @returns The current value of the specified compare register for the RTC.
AnnaBridge 167:84c0a372a020 222 */
AnnaBridge 167:84c0a372a020 223 uint32_t RTC_GetCompare(uint8_t compareIndex);
AnnaBridge 167:84c0a372a020 224
AnnaBridge 167:84c0a372a020 225 /**
AnnaBridge 167:84c0a372a020 226 * @brief Set the prescale reload value for the real-time clock.
AnnaBridge 167:84c0a372a020 227 * @details The prescale reload value determines the number of 4kHz ticks
AnnaBridge 167:84c0a372a020 228 * that will occur before the timer is incremented.
AnnaBridge 167:84c0a372a020 229 * <table>
AnnaBridge 167:84c0a372a020 230 * <caption id="prescaler_val">Prescaler Settings and Corresponding RTC Resolutions</caption>
AnnaBridge 167:84c0a372a020 231 * <tr><th>PRESCALE <th>Prescale Reload <th>4kHz ticks in LSB <th>Min Timer Value (sec) <th> Max Timer Value (sec) <th>Max Timer Value (Days) <th> Max Timer Value (Years)
AnnaBridge 167:84c0a372a020 232 * <tr><td align="right">0h<td align="center">RTC_PRESCALE_DIV_2_0<td align="right">1<td align="right">0.00024<td align="right">1048576<td align="right">12<td align="right">0.0
AnnaBridge 167:84c0a372a020 233 * <tr><td align="right">1h<td align="center">RTC_PRESCALE_DIV_2_1<td align="right">2<td align="right">0.00049<td align="right">2097152<td align="right">24<td align="right">0.1
AnnaBridge 167:84c0a372a020 234 * <tr><td align="right">2h<td align="center">RTC_PRESCALE_DIV_2_2<td align="right">4<td align="right">0.00098<td align="right">4194304<td align="right">49<td align="right">0.1
AnnaBridge 167:84c0a372a020 235 * <tr><td align="right">3h<td align="center">RTC_PRESCALE_DIV_2_3<td align="right">8<td align="right">0.00195<td align="right">8388608<td align="right">97<td align="right">0.3
AnnaBridge 167:84c0a372a020 236 * <tr><td align="right">4h<td align="center">RTC_PRESCALE_DIV_2_4<td align="right">16<td align="right">0.00391<td align="right">16777216<td align="right">194 <td align="right">0.5
AnnaBridge 167:84c0a372a020 237 * <tr><td align="right">5h<td align="center">RTC_PRESCALE_DIV_2_5<td align="right">32<td align="right">0.00781<td align="right">33554432<td align="right">388 <td align="right">1.1
AnnaBridge 167:84c0a372a020 238 * <tr><td align="right">6h<td align="center">RTC_PRESCALE_DIV_2_6<td align="right">64<td align="right">0.01563<td align="right">67108864<td align="right">777 <td align="right">2.2
AnnaBridge 167:84c0a372a020 239 * <tr><td align="right">7h<td align="center">RTC_PRESCALE_DIV_2_7<td align="right">128<td align="right">0.03125<td align="right">134217728<td align="right">1553 <td align="right">4.4
AnnaBridge 167:84c0a372a020 240 * <tr><td align="right">8h<td align="center">RTC_PRESCALE_DIV_2_8<td align="right">256<td align="right">0.06250<td align="right">268435456<td align="right">3107 <td align="right">8.7
AnnaBridge 167:84c0a372a020 241 * <tr><td align="right">9h<td align="center">RTC_PRESCALE_DIV_2_9<td align="right">512<td align="right">0.12500<td align="right">536870912<td align="right">6214 <td align="right">17.5
AnnaBridge 167:84c0a372a020 242 * <tr><td align="right">Ah<td align="center">RTC_PRESCALE_DIV_2_10<td align="right">1024 <td align="right">0.25000<td align="right">1073741824<td align="right">12428<td align="right">34.9
AnnaBridge 167:84c0a372a020 243 * <tr><td align="right">Bh<td align="center">RTC_PRESCALE_DIV_2_11<td align="right">2048 <td align="right">0.50000<td align="right">2147483648<td align="right">24855<td align="right">69.8
AnnaBridge 167:84c0a372a020 244 * <tr><td align="right">Ch<td align="center">RTC_PRESCALE_DIV_2_12<td align="right">4096 <td align="right">1.00000<td align="right">4294967296<td align="right">49710<td align="right">139.6
AnnaBridge 167:84c0a372a020 245 * </table>
AnnaBridge 167:84c0a372a020 246 *
AnnaBridge 167:84c0a372a020 247 * @param prescaler Prescale value to set, see #rtc_prescale_t.
AnnaBridge 167:84c0a372a020 248 */
AnnaBridge 167:84c0a372a020 249 __STATIC_INLINE void RTC_SetPrescaler(rtc_prescale_t prescaler)
AnnaBridge 167:84c0a372a020 250 {
AnnaBridge 167:84c0a372a020 251 MXC_RTCTMR->prescale = prescaler;
AnnaBridge 167:84c0a372a020 252
AnnaBridge 167:84c0a372a020 253 //wait for pending actions to complete
AnnaBridge 167:84c0a372a020 254 while(MXC_RTCTMR->ctrl & MXC_F_RTC_CTRL_PENDING);
AnnaBridge 167:84c0a372a020 255 }
AnnaBridge 167:84c0a372a020 256
AnnaBridge 167:84c0a372a020 257 /**
AnnaBridge 167:84c0a372a020 258 * @brief Get the current value of the real-time clock prescaler.
AnnaBridge 167:84c0a372a020 259 *
AnnaBridge 167:84c0a372a020 260 * @retval rtc_prescale_t Returns the current RTC prescaler setting,
AnnaBridge 167:84c0a372a020 261 * See #rtc_prescale_t for values of the prescaler.
AnnaBridge 167:84c0a372a020 262 */
AnnaBridge 167:84c0a372a020 263 __STATIC_INLINE rtc_prescale_t RTC_GetPrescaler(void)
AnnaBridge 167:84c0a372a020 264 {
AnnaBridge 167:84c0a372a020 265 return (rtc_prescale_t)(MXC_RTCTMR->prescale);
AnnaBridge 167:84c0a372a020 266 }
AnnaBridge 167:84c0a372a020 267
AnnaBridge 167:84c0a372a020 268 /**
AnnaBridge 167:84c0a372a020 269 * @brief Set the prescaler mask, which is used to set the RTC prescale counter
AnnaBridge 167:84c0a372a020 270 * compare flag when the prescaler timer matches the bits indicated
AnnaBridge 167:84c0a372a020 271 * by the mask.
AnnaBridge 167:84c0a372a020 272 * @param mask A bit mask that is used to set the prescale compare flag if the
AnnaBridge 167:84c0a372a020 273 * prescale timer has the corresponding bits set. @note This mask must
AnnaBridge 167:84c0a372a020 274 * be less than or equal to the prescaler reload value.
AnnaBridge 167:84c0a372a020 275 * See RTC_SetPrescaler()
AnnaBridge 167:84c0a372a020 276 * @details When \f$ Count_{prescaler}\,\&\,Prescale\,Mask = 0 \f$, the prescale compare flag is set
AnnaBridge 167:84c0a372a020 277 * @retval int Returns #E_NO_ERROR if prescale value is valid and is set.
AnnaBridge 167:84c0a372a020 278 * @retval int Returns #E_INVALID if mask is \> than prescaler value
AnnaBridge 167:84c0a372a020 279 */
AnnaBridge 167:84c0a372a020 280 __STATIC_INLINE int RTC_SetPrescalerMask(rtc_prescale_t mask)
AnnaBridge 167:84c0a372a020 281 {
AnnaBridge 167:84c0a372a020 282 if (mask > ((rtc_prescale_t)(MXC_RTCTMR->prescale)))
AnnaBridge 167:84c0a372a020 283 {
AnnaBridge 167:84c0a372a020 284 return E_INVALID;
AnnaBridge 167:84c0a372a020 285 }
AnnaBridge 167:84c0a372a020 286 MXC_RTCTMR->prescale_mask = mask;
AnnaBridge 167:84c0a372a020 287
AnnaBridge 167:84c0a372a020 288 //wait for pending actions to complete
AnnaBridge 167:84c0a372a020 289 while(MXC_RTCTMR->ctrl & MXC_F_RTC_CTRL_PENDING);
AnnaBridge 167:84c0a372a020 290 return E_NO_ERROR;
AnnaBridge 167:84c0a372a020 291 }
AnnaBridge 167:84c0a372a020 292
AnnaBridge 167:84c0a372a020 293 /**
AnnaBridge 167:84c0a372a020 294 * @brief Set the count for snooze mode. See RTC_Snooze().
AnnaBridge 167:84c0a372a020 295 * @details This value is used to set the snooze count. The meaning of this value is dependant on the snooze mode. p
AnnaBridge 167:84c0a372a020 296 * See RTC_SetSnoozeMode() for details of calculating the snooze time period based on the mode and snooze count.
AnnaBridge 167:84c0a372a020 297 * @param count Sets the count used for snooze when snooze mode is
AnnaBridge 167:84c0a372a020 298 * enabled and the snooze flag is set.
AnnaBridge 167:84c0a372a020 299 * @retval #E_NO_ERROR Snooze value is set correctly and value is valid.
AnnaBridge 167:84c0a372a020 300 * @retval #E_INVALID SnoozeCount exceeds maximum supported, see
AnnaBridge 167:84c0a372a020 301 * MXC_F_RTC_SNZ_VAL_VALUE
AnnaBridge 167:84c0a372a020 302 */
AnnaBridge 167:84c0a372a020 303 __STATIC_INLINE int RTC_SetSnoozeCount(uint32_t count)
AnnaBridge 167:84c0a372a020 304 {
AnnaBridge 167:84c0a372a020 305 // Check to make sure max value is not being exceeded
AnnaBridge 167:84c0a372a020 306 if (count > MXC_F_RTC_SNZ_VAL_VALUE)
AnnaBridge 167:84c0a372a020 307 return E_INVALID;
AnnaBridge 167:84c0a372a020 308
AnnaBridge 167:84c0a372a020 309 MXC_RTCTMR->snz_val = count;
AnnaBridge 167:84c0a372a020 310
AnnaBridge 167:84c0a372a020 311 //wait for pending actions to complete
AnnaBridge 167:84c0a372a020 312 while(MXC_RTCTMR->ctrl & MXC_F_RTC_CTRL_PENDING);
AnnaBridge 167:84c0a372a020 313 return E_NO_ERROR;
AnnaBridge 167:84c0a372a020 314 }
AnnaBridge 167:84c0a372a020 315
AnnaBridge 167:84c0a372a020 316 /**
AnnaBridge 167:84c0a372a020 317 * @brief Gets the current Snooze Count value.
AnnaBridge 167:84c0a372a020 318 * @details Returns the current value for the Snooze Count. This value is
AnnaBridge 167:84c0a372a020 319 * used as part of the snooze calculation depending on the snooze
AnnaBridge 167:84c0a372a020 320 * mode. See RTC_SetSnoozeMode() for details of calculating the
AnnaBridge 167:84c0a372a020 321 * snooze time period based on the mode and count.
AnnaBridge 167:84c0a372a020 322 * @return Value of the snooze register.
AnnaBridge 167:84c0a372a020 323 */
AnnaBridge 167:84c0a372a020 324 __STATIC_INLINE uint32_t RTC_GetSnoozeCount(void)
AnnaBridge 167:84c0a372a020 325 {
AnnaBridge 167:84c0a372a020 326 return MXC_RTCTMR->snz_val;
AnnaBridge 167:84c0a372a020 327 }
AnnaBridge 167:84c0a372a020 328
AnnaBridge 167:84c0a372a020 329 /**
AnnaBridge 167:84c0a372a020 330 * @brief Activates snooze mode.
AnnaBridge 167:84c0a372a020 331 * @details Begins a snooze of the RTC. When this function is called
AnnaBridge 167:84c0a372a020 332 * the snooze time period is determined based on the snooze mode and the count.
AnnaBridge 167:84c0a372a020 333 * See RTC_GetCount() and RTC_SetSnoozeMode()
AnnaBridge 167:84c0a372a020 334 */
AnnaBridge 167:84c0a372a020 335 __STATIC_INLINE void RTC_Snooze(void)
AnnaBridge 167:84c0a372a020 336 {
AnnaBridge 167:84c0a372a020 337 MXC_RTCTMR->flags = MXC_F_RTC_FLAGS_SNOOZE_A | MXC_F_RTC_FLAGS_SNOOZE_B;
AnnaBridge 167:84c0a372a020 338
AnnaBridge 167:84c0a372a020 339 //wait for pending actions to complete
AnnaBridge 167:84c0a372a020 340 while(MXC_RTCTMR->ctrl & MXC_F_RTC_CTRL_PENDING);
AnnaBridge 167:84c0a372a020 341 }
AnnaBridge 167:84c0a372a020 342
AnnaBridge 167:84c0a372a020 343 /**
AnnaBridge 167:84c0a372a020 344 * @brief Sets the Snooze Mode.
AnnaBridge 167:84c0a372a020 345 * @details <table> <caption id="snoozeModesTable">Snooze Modes</caption>
AnnaBridge 167:84c0a372a020 346 * <tr><th>Mode<th>Snooze Time Calculation
AnnaBridge 167:84c0a372a020 347 * <tr><td>RTC_SNOOZE_DISABLE<td>Snooze Disabled
AnnaBridge 167:84c0a372a020 348 * <tr><td>RTC_SNOOZE_MODE_A<td>\f$ compare1 = compare1 + snoozeCount \f$
AnnaBridge 167:84c0a372a020 349 * <tr><td>RTC_SNOOZE_MODE_B<td>\f$ compare1 = count + snoozeCount \f$
AnnaBridge 167:84c0a372a020 350 * </table>
AnnaBridge 167:84c0a372a020 351 * @note @a count is the value of the RTC counter when RTC_Snooze()
AnnaBridge 167:84c0a372a020 352 * is called to start a snooze cycle and @a snoozeCount is the value set by the RTC_SetSnoozeCount(uint32_t count) function.
AnnaBridge 167:84c0a372a020 353 *
AnnaBridge 167:84c0a372a020 354 * @param mode Specifies the desired snooze mode, see #rtc_snooze_t.
AnnaBridge 167:84c0a372a020 355 *
AnnaBridge 167:84c0a372a020 356 */
AnnaBridge 167:84c0a372a020 357 __STATIC_INLINE void RTC_SetSnoozeMode(rtc_snooze_t mode)
AnnaBridge 167:84c0a372a020 358 {
AnnaBridge 167:84c0a372a020 359 uint32_t ctrl;
AnnaBridge 167:84c0a372a020 360 // Get the control register and mask off the non-snooze bits
AnnaBridge 167:84c0a372a020 361 ctrl = (MXC_RTCTMR->ctrl & ~(MXC_F_RTC_CTRL_SNOOZE_ENABLE));
AnnaBridge 167:84c0a372a020 362 // set the requested snooze mode bits and save the settings
AnnaBridge 167:84c0a372a020 363 MXC_RTCTMR->ctrl = (ctrl | (mode << MXC_F_RTC_CTRL_SNOOZE_ENABLE_POS));
AnnaBridge 167:84c0a372a020 364
AnnaBridge 167:84c0a372a020 365 //wait for pending actions to complete
AnnaBridge 167:84c0a372a020 366 while(MXC_RTCTMR->ctrl & MXC_F_RTC_CTRL_PENDING);
AnnaBridge 167:84c0a372a020 367 }
AnnaBridge 167:84c0a372a020 368
AnnaBridge 167:84c0a372a020 369 /**
AnnaBridge 167:84c0a372a020 370 * @brief Enables the interrupts specified for the RTC.
AnnaBridge 167:84c0a372a020 371 * @details <table>
AnnaBridge 167:84c0a372a020 372 * <caption id="RTC_interrupts">RTC Interrupts</caption>
AnnaBridge 167:84c0a372a020 373 * <tr><th>Interrupt<th>Mask
AnnaBridge 167:84c0a372a020 374 * <tr><td>Compare 0<td>#MXC_F_RTC_INTEN_COMP0
AnnaBridge 167:84c0a372a020 375 * <tr><td>Compare 1 and Snooze<td>#MXC_F_RTC_INTEN_COMP1
AnnaBridge 167:84c0a372a020 376 * <tr><td>Prescale Comp<td>#MXC_F_RTC_INTEN_PRESCALE_COMP
AnnaBridge 167:84c0a372a020 377 * <tr><td>RTC Count Overflow<td>#MXC_F_RTC_INTEN_OVERFLOW
AnnaBridge 167:84c0a372a020 378 * <tr><td>Trim<td>#MXC_F_RTC_INTEN_TRIM
AnnaBridge 167:84c0a372a020 379 * </table>
AnnaBridge 167:84c0a372a020 380 * @param mask A mask of the RTC interrupts to enable, 1 = Enable. See
AnnaBridge 167:84c0a372a020 381 * @ref RTC_FLAGS_Register Register for the RTC interrupt enable bit masks and positions.
AnnaBridge 167:84c0a372a020 382 */
AnnaBridge 167:84c0a372a020 383 __STATIC_INLINE void RTC_EnableINT(uint32_t mask)
AnnaBridge 167:84c0a372a020 384 {
AnnaBridge 167:84c0a372a020 385 MXC_RTCTMR->inten |= mask;
AnnaBridge 167:84c0a372a020 386 }
AnnaBridge 167:84c0a372a020 387
AnnaBridge 167:84c0a372a020 388 /**
AnnaBridge 167:84c0a372a020 389 * @brief Disable the interrupts specified for the RTC. See the
AnnaBridge 167:84c0a372a020 390 * @ref RTC_INTEN_Register Register for the RTC interrupt enable bit masks and positions.
AnnaBridge 167:84c0a372a020 391 *
AnnaBridge 167:84c0a372a020 392 * @param mask A mask of the RTC interrupts to disable, 1 = Disable.
AnnaBridge 167:84c0a372a020 393 */
AnnaBridge 167:84c0a372a020 394 __STATIC_INLINE void RTC_DisableINT(uint32_t mask)
AnnaBridge 167:84c0a372a020 395 {
AnnaBridge 167:84c0a372a020 396 MXC_RTCTMR->inten &= ~mask;
AnnaBridge 167:84c0a372a020 397 }
AnnaBridge 167:84c0a372a020 398
AnnaBridge 167:84c0a372a020 399 /**
AnnaBridge 167:84c0a372a020 400 * @brief Returns the current interrupt flags that are set.
AnnaBridge 167:84c0a372a020 401 *
AnnaBridge 167:84c0a372a020 402 * @return A mask of the current interrupt flags, see the
AnnaBridge 167:84c0a372a020 403 * @ref RTC_FLAGS_Register Register for the details of the RTC interrupt
AnnaBridge 167:84c0a372a020 404 * flags.
AnnaBridge 167:84c0a372a020 405 */
AnnaBridge 167:84c0a372a020 406 __STATIC_INLINE uint32_t RTC_GetFlags(void)
AnnaBridge 167:84c0a372a020 407 {
AnnaBridge 167:84c0a372a020 408 return (MXC_RTCTMR->flags);
AnnaBridge 167:84c0a372a020 409 }
AnnaBridge 167:84c0a372a020 410
AnnaBridge 167:84c0a372a020 411 /**
AnnaBridge 167:84c0a372a020 412 * @brief Clears the interrupt flags specified.
AnnaBridge 167:84c0a372a020 413 *
AnnaBridge 167:84c0a372a020 414 * @param mask A mask of interrupts to clear, see the @ref RTC_FLAGS_Register
AnnaBridge 167:84c0a372a020 415 * Register for the interrupt flag bit masks and positions.
AnnaBridge 167:84c0a372a020 416 */
AnnaBridge 167:84c0a372a020 417 __STATIC_INLINE void RTC_ClearFlags(uint32_t mask)
AnnaBridge 167:84c0a372a020 418 {
AnnaBridge 167:84c0a372a020 419 MXC_RTCTMR->flags = mask;
AnnaBridge 167:84c0a372a020 420
AnnaBridge 167:84c0a372a020 421 //wait for pending actions to complete
AnnaBridge 167:84c0a372a020 422 while(MXC_RTCTMR->ctrl & MXC_F_RTC_CTRL_PENDING);
AnnaBridge 167:84c0a372a020 423 }
AnnaBridge 167:84c0a372a020 424
AnnaBridge 167:84c0a372a020 425 /**
AnnaBridge 167:84c0a372a020 426 * @brief Gets the active transaction flags, see @ref RTC_CTRL_Register Register for the list of ACTIVE flags.
AnnaBridge 167:84c0a372a020 427 *
AnnaBridge 167:84c0a372a020 428 * @retval 0 No active transactions.
AnnaBridge 167:84c0a372a020 429 * @retval nonzero A mask of active transaction bits.
AnnaBridge 167:84c0a372a020 430 */
AnnaBridge 167:84c0a372a020 431 __STATIC_INLINE uint32_t RTC_GetActiveTrans(void)
AnnaBridge 167:84c0a372a020 432 {
AnnaBridge 167:84c0a372a020 433 return (MXC_RTCTMR->ctrl & RTC_CTRL_ACTIVE_TRANS);
AnnaBridge 167:84c0a372a020 434 }
AnnaBridge 167:84c0a372a020 435
AnnaBridge 167:84c0a372a020 436 /**
AnnaBridge 167:84c0a372a020 437 * @brief Sets the trim value and trim slow/fast option.
AnnaBridge 167:84c0a372a020 438 * @warning The RTC must be disabled prior to calling this function, see RTC_Stop(void) to disable the RTC.
AnnaBridge 167:84c0a372a020 439 *
AnnaBridge 167:84c0a372a020 440 * @param trim The desired trim value. @note The maximum trim value setting is 0x03FFFF.
AnnaBridge 167:84c0a372a020 441 * @param trimSlow 1 = trim slow, 0 = trim fast
AnnaBridge 167:84c0a372a020 442 *
AnnaBridge 167:84c0a372a020 443 * @return #E_NO_ERROR Trim value is valid and set.
AnnaBridge 167:84c0a372a020 444 * @return #E_INVALID Trim value exceeds max trim.
AnnaBridge 167:84c0a372a020 445 * @return #E_BAD_STATE RTC is active.
AnnaBridge 167:84c0a372a020 446 */
AnnaBridge 167:84c0a372a020 447 int RTC_SetTrim(uint32_t trim, uint8_t trimSlow);
AnnaBridge 167:84c0a372a020 448
AnnaBridge 167:84c0a372a020 449 /**
AnnaBridge 167:84c0a372a020 450 * @brief Gets the current trim value.
AnnaBridge 167:84c0a372a020 451 * @note Ensure RTC is disabled prior to calling this function, see RTC_Stop(void).
AnnaBridge 167:84c0a372a020 452 *
AnnaBridge 167:84c0a372a020 453 * @retval uint32_t Current trim value of RTC.
AnnaBridge 167:84c0a372a020 454 */
AnnaBridge 167:84c0a372a020 455 uint32_t RTC_GetTrim(void);
AnnaBridge 167:84c0a372a020 456
AnnaBridge 167:84c0a372a020 457 /**
AnnaBridge 167:84c0a372a020 458 * @brief Enable the trim.
AnnaBridge 167:84c0a372a020 459 * @warning The RTC must be disabled prior to calling this function, see RTC_Stop(void) to disable the RTC.
AnnaBridge 167:84c0a372a020 460 * @retval #E_NO_ERROR Trim is enabled.
AnnaBridge 167:84c0a372a020 461 * @retval #E_INVALID RTC is active, see RTC_Stop(void).
AnnaBridge 167:84c0a372a020 462 */
AnnaBridge 167:84c0a372a020 463 int RTC_TrimEnable(void);
AnnaBridge 167:84c0a372a020 464
AnnaBridge 167:84c0a372a020 465 /**
AnnaBridge 167:84c0a372a020 466 * @brief Disable the trim.
AnnaBridge 167:84c0a372a020 467 */
AnnaBridge 167:84c0a372a020 468 void RTC_TrimDisable(void);
AnnaBridge 167:84c0a372a020 469
AnnaBridge 167:84c0a372a020 470 /**@}*/
AnnaBridge 167:84c0a372a020 471
AnnaBridge 167:84c0a372a020 472 #ifdef __cplusplus
AnnaBridge 167:84c0a372a020 473 }
AnnaBridge 167:84c0a372a020 474 #endif
AnnaBridge 167:84c0a372a020 475
AnnaBridge 167:84c0a372a020 476 #endif /* _RTC_H */