mbed library sources. Supersedes mbed-src. Edited target satm32f446 for user USART3 pins

Dependents:   IGLOO_board

Fork of mbed-dev by mbed official

Committer:
Anna Bridge
Date:
Fri Jun 22 16:45:37 2018 +0100
Revision:
186:707f6e361f3e
mbed-dev library. Release version 162

Who changed what in which revision?

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