Ben Katz / mbed-dev-f303

Dependents:   Hobbyking_Cheetah_Compact Hobbyking_Cheetah_Compact_DRV8323_14bit Hobbyking_Cheetah_Compact_DRV8323_V51_201907 HKC_MiniCheetah ... more

Fork of mbed-dev by mbed official

Committer:
benkatz
Date:
Mon Jul 30 20:31:44 2018 +0000
Revision:
181:36facd806e4a
Parent:
154:37f96f9d4de2
going on the robot.  fixed a dumb bug in float_to_uint

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 154:37f96f9d4de2 1 /*
<> 154:37f96f9d4de2 2 * Copyright (c) 2015, Freescale Semiconductor, Inc.
<> 154:37f96f9d4de2 3 * All rights reserved.
<> 154:37f96f9d4de2 4 *
<> 154:37f96f9d4de2 5 * Redistribution and use in source and binary forms, with or without modification,
<> 154:37f96f9d4de2 6 * are permitted provided that the following conditions are met:
<> 154:37f96f9d4de2 7 *
<> 154:37f96f9d4de2 8 * o Redistributions of source code must retain the above copyright notice, this list
<> 154:37f96f9d4de2 9 * of conditions and the following disclaimer.
<> 154:37f96f9d4de2 10 *
<> 154:37f96f9d4de2 11 * o Redistributions in binary form must reproduce the above copyright notice, this
<> 154:37f96f9d4de2 12 * list of conditions and the following disclaimer in the documentation and/or
<> 154:37f96f9d4de2 13 * other materials provided with the distribution.
<> 154:37f96f9d4de2 14 *
<> 154:37f96f9d4de2 15 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
<> 154:37f96f9d4de2 16 * contributors may be used to endorse or promote products derived from this
<> 154:37f96f9d4de2 17 * software without specific prior written permission.
<> 154:37f96f9d4de2 18 *
<> 154:37f96f9d4de2 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
<> 154:37f96f9d4de2 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
<> 154:37f96f9d4de2 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
<> 154:37f96f9d4de2 22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
<> 154:37f96f9d4de2 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
<> 154:37f96f9d4de2 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
<> 154:37f96f9d4de2 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
<> 154:37f96f9d4de2 26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
<> 154:37f96f9d4de2 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
<> 154:37f96f9d4de2 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<> 154:37f96f9d4de2 29 */
<> 154:37f96f9d4de2 30
<> 154:37f96f9d4de2 31 #include "fsl_rtc.h"
<> 154:37f96f9d4de2 32
<> 154:37f96f9d4de2 33 /*******************************************************************************
<> 154:37f96f9d4de2 34 * Definitions
<> 154:37f96f9d4de2 35 ******************************************************************************/
<> 154:37f96f9d4de2 36 #define SECONDS_IN_A_DAY (86400U)
<> 154:37f96f9d4de2 37 #define SECONDS_IN_A_HOUR (3600U)
<> 154:37f96f9d4de2 38 #define SECONDS_IN_A_MINUTE (60U)
<> 154:37f96f9d4de2 39 #define DAYS_IN_A_YEAR (365U)
<> 154:37f96f9d4de2 40 #define YEAR_RANGE_START (1970U)
<> 154:37f96f9d4de2 41 #define YEAR_RANGE_END (2099U)
<> 154:37f96f9d4de2 42
<> 154:37f96f9d4de2 43 /*******************************************************************************
<> 154:37f96f9d4de2 44 * Prototypes
<> 154:37f96f9d4de2 45 ******************************************************************************/
<> 154:37f96f9d4de2 46 /*!
<> 154:37f96f9d4de2 47 * @brief Checks whether the date and time passed in is valid
<> 154:37f96f9d4de2 48 *
<> 154:37f96f9d4de2 49 * @param datetime Pointer to structure where the date and time details are stored
<> 154:37f96f9d4de2 50 *
<> 154:37f96f9d4de2 51 * @return Returns false if the date & time details are out of range; true if in range
<> 154:37f96f9d4de2 52 */
<> 154:37f96f9d4de2 53 static bool RTC_CheckDatetimeFormat(const rtc_datetime_t *datetime);
<> 154:37f96f9d4de2 54
<> 154:37f96f9d4de2 55 /*!
<> 154:37f96f9d4de2 56 * @brief Converts time data from datetime to seconds
<> 154:37f96f9d4de2 57 *
<> 154:37f96f9d4de2 58 * @param datetime Pointer to datetime structure where the date and time details are stored
<> 154:37f96f9d4de2 59 *
<> 154:37f96f9d4de2 60 * @return The result of the conversion in seconds
<> 154:37f96f9d4de2 61 */
<> 154:37f96f9d4de2 62 static uint32_t RTC_ConvertDatetimeToSeconds(const rtc_datetime_t *datetime);
<> 154:37f96f9d4de2 63
<> 154:37f96f9d4de2 64 /*!
<> 154:37f96f9d4de2 65 * @brief Converts time data from seconds to a datetime structure
<> 154:37f96f9d4de2 66 *
<> 154:37f96f9d4de2 67 * @param seconds Seconds value that needs to be converted to datetime format
<> 154:37f96f9d4de2 68 * @param datetime Pointer to the datetime structure where the result of the conversion is stored
<> 154:37f96f9d4de2 69 */
<> 154:37f96f9d4de2 70 static void RTC_ConvertSecondsToDatetime(uint32_t seconds, rtc_datetime_t *datetime);
<> 154:37f96f9d4de2 71
<> 154:37f96f9d4de2 72 /*******************************************************************************
<> 154:37f96f9d4de2 73 * Code
<> 154:37f96f9d4de2 74 ******************************************************************************/
<> 154:37f96f9d4de2 75 static bool RTC_CheckDatetimeFormat(const rtc_datetime_t *datetime)
<> 154:37f96f9d4de2 76 {
<> 154:37f96f9d4de2 77 /* Table of days in a month for a non leap year. First entry in the table is not used,
<> 154:37f96f9d4de2 78 * valid months start from 1
<> 154:37f96f9d4de2 79 */
<> 154:37f96f9d4de2 80 uint8_t daysPerMonth[] = {0U, 31U, 28U, 31U, 30U, 31U, 30U, 31U, 31U, 30U, 31U, 30U, 31U};
<> 154:37f96f9d4de2 81
<> 154:37f96f9d4de2 82 /* Check year, month, hour, minute, seconds */
<> 154:37f96f9d4de2 83 if ((datetime->year < YEAR_RANGE_START) || (datetime->year > YEAR_RANGE_END) || (datetime->month > 12U) ||
<> 154:37f96f9d4de2 84 (datetime->month < 1U) || (datetime->hour >= 24U) || (datetime->minute >= 60U) || (datetime->second >= 60U))
<> 154:37f96f9d4de2 85 {
<> 154:37f96f9d4de2 86 /* If not correct then error*/
<> 154:37f96f9d4de2 87 return false;
<> 154:37f96f9d4de2 88 }
<> 154:37f96f9d4de2 89
<> 154:37f96f9d4de2 90 /* Adjust the days in February for a leap year */
<> 154:37f96f9d4de2 91 if (!(datetime->year & 3U))
<> 154:37f96f9d4de2 92 {
<> 154:37f96f9d4de2 93 daysPerMonth[2] = 29U;
<> 154:37f96f9d4de2 94 }
<> 154:37f96f9d4de2 95
<> 154:37f96f9d4de2 96 /* Check the validity of the day */
<> 154:37f96f9d4de2 97 if (datetime->day > daysPerMonth[datetime->month])
<> 154:37f96f9d4de2 98 {
<> 154:37f96f9d4de2 99 return false;
<> 154:37f96f9d4de2 100 }
<> 154:37f96f9d4de2 101
<> 154:37f96f9d4de2 102 return true;
<> 154:37f96f9d4de2 103 }
<> 154:37f96f9d4de2 104
<> 154:37f96f9d4de2 105 static uint32_t RTC_ConvertDatetimeToSeconds(const rtc_datetime_t *datetime)
<> 154:37f96f9d4de2 106 {
<> 154:37f96f9d4de2 107 /* Number of days from begin of the non Leap-year*/
<> 154:37f96f9d4de2 108 uint16_t monthDays[] = {0U, 0U, 31U, 59U, 90U, 120U, 151U, 181U, 212U, 243U, 273U, 304U, 334U};
<> 154:37f96f9d4de2 109 uint32_t seconds;
<> 154:37f96f9d4de2 110
<> 154:37f96f9d4de2 111 /* Compute number of days from 1970 till given year*/
<> 154:37f96f9d4de2 112 seconds = (datetime->year - 1970U) * DAYS_IN_A_YEAR;
<> 154:37f96f9d4de2 113 /* Add leap year days */
<> 154:37f96f9d4de2 114 seconds += ((datetime->year / 4) - (1970U / 4));
<> 154:37f96f9d4de2 115 /* Add number of days till given month*/
<> 154:37f96f9d4de2 116 seconds += monthDays[datetime->month];
<> 154:37f96f9d4de2 117 /* Add days in given month. We subtract the current day as it is
<> 154:37f96f9d4de2 118 * represented in the hours, minutes and seconds field*/
<> 154:37f96f9d4de2 119 seconds += (datetime->day - 1);
<> 154:37f96f9d4de2 120 /* For leap year if month less than or equal to Febraury, decrement day counter*/
<> 154:37f96f9d4de2 121 if ((!(datetime->year & 3U)) && (datetime->month <= 2U))
<> 154:37f96f9d4de2 122 {
<> 154:37f96f9d4de2 123 seconds--;
<> 154:37f96f9d4de2 124 }
<> 154:37f96f9d4de2 125
<> 154:37f96f9d4de2 126 seconds = (seconds * SECONDS_IN_A_DAY) + (datetime->hour * SECONDS_IN_A_HOUR) +
<> 154:37f96f9d4de2 127 (datetime->minute * SECONDS_IN_A_MINUTE) + datetime->second;
<> 154:37f96f9d4de2 128
<> 154:37f96f9d4de2 129 return seconds;
<> 154:37f96f9d4de2 130 }
<> 154:37f96f9d4de2 131
<> 154:37f96f9d4de2 132 static void RTC_ConvertSecondsToDatetime(uint32_t seconds, rtc_datetime_t *datetime)
<> 154:37f96f9d4de2 133 {
<> 154:37f96f9d4de2 134 uint32_t x;
<> 154:37f96f9d4de2 135 uint32_t secondsRemaining, days;
<> 154:37f96f9d4de2 136 uint16_t daysInYear;
<> 154:37f96f9d4de2 137 /* Table of days in a month for a non leap year. First entry in the table is not used,
<> 154:37f96f9d4de2 138 * valid months start from 1
<> 154:37f96f9d4de2 139 */
<> 154:37f96f9d4de2 140 uint8_t daysPerMonth[] = {0U, 31U, 28U, 31U, 30U, 31U, 30U, 31U, 31U, 30U, 31U, 30U, 31U};
<> 154:37f96f9d4de2 141
<> 154:37f96f9d4de2 142 /* Start with the seconds value that is passed in to be converted to date time format */
<> 154:37f96f9d4de2 143 secondsRemaining = seconds;
<> 154:37f96f9d4de2 144
<> 154:37f96f9d4de2 145 /* Calcuate the number of days, we add 1 for the current day which is represented in the
<> 154:37f96f9d4de2 146 * hours and seconds field
<> 154:37f96f9d4de2 147 */
<> 154:37f96f9d4de2 148 days = secondsRemaining / SECONDS_IN_A_DAY + 1;
<> 154:37f96f9d4de2 149
<> 154:37f96f9d4de2 150 /* Update seconds left*/
<> 154:37f96f9d4de2 151 secondsRemaining = secondsRemaining % SECONDS_IN_A_DAY;
<> 154:37f96f9d4de2 152
<> 154:37f96f9d4de2 153 /* Calculate the datetime hour, minute and second fields */
<> 154:37f96f9d4de2 154 datetime->hour = secondsRemaining / SECONDS_IN_A_HOUR;
<> 154:37f96f9d4de2 155 secondsRemaining = secondsRemaining % SECONDS_IN_A_HOUR;
<> 154:37f96f9d4de2 156 datetime->minute = secondsRemaining / 60U;
<> 154:37f96f9d4de2 157 datetime->second = secondsRemaining % SECONDS_IN_A_MINUTE;
<> 154:37f96f9d4de2 158
<> 154:37f96f9d4de2 159 /* Calculate year */
<> 154:37f96f9d4de2 160 daysInYear = DAYS_IN_A_YEAR;
<> 154:37f96f9d4de2 161 datetime->year = YEAR_RANGE_START;
<> 154:37f96f9d4de2 162 while (days > daysInYear)
<> 154:37f96f9d4de2 163 {
<> 154:37f96f9d4de2 164 /* Decrease day count by a year and increment year by 1 */
<> 154:37f96f9d4de2 165 days -= daysInYear;
<> 154:37f96f9d4de2 166 datetime->year++;
<> 154:37f96f9d4de2 167
<> 154:37f96f9d4de2 168 /* Adjust the number of days for a leap year */
<> 154:37f96f9d4de2 169 if (datetime->year & 3U)
<> 154:37f96f9d4de2 170 {
<> 154:37f96f9d4de2 171 daysInYear = DAYS_IN_A_YEAR;
<> 154:37f96f9d4de2 172 }
<> 154:37f96f9d4de2 173 else
<> 154:37f96f9d4de2 174 {
<> 154:37f96f9d4de2 175 daysInYear = DAYS_IN_A_YEAR + 1;
<> 154:37f96f9d4de2 176 }
<> 154:37f96f9d4de2 177 }
<> 154:37f96f9d4de2 178
<> 154:37f96f9d4de2 179 /* Adjust the days in February for a leap year */
<> 154:37f96f9d4de2 180 if (!(datetime->year & 3U))
<> 154:37f96f9d4de2 181 {
<> 154:37f96f9d4de2 182 daysPerMonth[2] = 29U;
<> 154:37f96f9d4de2 183 }
<> 154:37f96f9d4de2 184
<> 154:37f96f9d4de2 185 for (x = 1U; x <= 12U; x++)
<> 154:37f96f9d4de2 186 {
<> 154:37f96f9d4de2 187 if (days <= daysPerMonth[x])
<> 154:37f96f9d4de2 188 {
<> 154:37f96f9d4de2 189 datetime->month = x;
<> 154:37f96f9d4de2 190 break;
<> 154:37f96f9d4de2 191 }
<> 154:37f96f9d4de2 192 else
<> 154:37f96f9d4de2 193 {
<> 154:37f96f9d4de2 194 days -= daysPerMonth[x];
<> 154:37f96f9d4de2 195 }
<> 154:37f96f9d4de2 196 }
<> 154:37f96f9d4de2 197
<> 154:37f96f9d4de2 198 datetime->day = days;
<> 154:37f96f9d4de2 199 }
<> 154:37f96f9d4de2 200
<> 154:37f96f9d4de2 201 void RTC_Init(RTC_Type *base, const rtc_config_t *config)
<> 154:37f96f9d4de2 202 {
<> 154:37f96f9d4de2 203 assert(config);
<> 154:37f96f9d4de2 204
<> 154:37f96f9d4de2 205 uint32_t reg;
<> 154:37f96f9d4de2 206
<> 154:37f96f9d4de2 207 CLOCK_EnableClock(kCLOCK_Rtc0);
<> 154:37f96f9d4de2 208
<> 154:37f96f9d4de2 209 /* Issue a software reset if timer is invalid */
<> 154:37f96f9d4de2 210 if (RTC_GetStatusFlags(RTC) & kRTC_TimeInvalidFlag)
<> 154:37f96f9d4de2 211 {
<> 154:37f96f9d4de2 212 RTC_Reset(RTC);
<> 154:37f96f9d4de2 213 }
<> 154:37f96f9d4de2 214
<> 154:37f96f9d4de2 215 reg = base->CR;
<> 154:37f96f9d4de2 216 /* Setup the update mode and supervisor access mode */
<> 154:37f96f9d4de2 217 reg &= ~(RTC_CR_UM_MASK | RTC_CR_SUP_MASK);
<> 154:37f96f9d4de2 218 reg |= RTC_CR_UM(config->updateMode) | RTC_CR_SUP(config->supervisorAccess);
<> 154:37f96f9d4de2 219 #if defined(FSL_FEATURE_RTC_HAS_WAKEUP_PIN) && FSL_FEATURE_RTC_HAS_WAKEUP_PIN
<> 154:37f96f9d4de2 220 /* Setup the wakeup pin select */
<> 154:37f96f9d4de2 221 reg &= ~(RTC_CR_WPS_MASK);
<> 154:37f96f9d4de2 222 reg |= RTC_CR_WPS(config->wakeupSelect);
<> 154:37f96f9d4de2 223 #endif /* FSL_FEATURE_RTC_HAS_WAKEUP_PIN */
<> 154:37f96f9d4de2 224 base->CR = reg;
<> 154:37f96f9d4de2 225
<> 154:37f96f9d4de2 226 /* Configure the RTC time compensation register */
<> 154:37f96f9d4de2 227 base->TCR = (RTC_TCR_CIR(config->compensationInterval) | RTC_TCR_TCR(config->compensationTime));
<> 154:37f96f9d4de2 228 }
<> 154:37f96f9d4de2 229
<> 154:37f96f9d4de2 230 void RTC_GetDefaultConfig(rtc_config_t *config)
<> 154:37f96f9d4de2 231 {
<> 154:37f96f9d4de2 232 assert(config);
<> 154:37f96f9d4de2 233
<> 154:37f96f9d4de2 234 /* Wakeup pin will assert if the RTC interrupt asserts or if the wakeup pin is turned on */
<> 154:37f96f9d4de2 235 config->wakeupSelect = false;
<> 154:37f96f9d4de2 236 /* Registers cannot be written when locked */
<> 154:37f96f9d4de2 237 config->updateMode = false;
<> 154:37f96f9d4de2 238 /* Non-supervisor mode write accesses are not supported and will generate a bus error */
<> 154:37f96f9d4de2 239 config->supervisorAccess = false;
<> 154:37f96f9d4de2 240 /* Compensation interval used by the crystal compensation logic */
<> 154:37f96f9d4de2 241 config->compensationInterval = 0;
<> 154:37f96f9d4de2 242 /* Compensation time used by the crystal compensation logic */
<> 154:37f96f9d4de2 243 config->compensationTime = 0;
<> 154:37f96f9d4de2 244 }
<> 154:37f96f9d4de2 245
<> 154:37f96f9d4de2 246 status_t RTC_SetDatetime(RTC_Type *base, const rtc_datetime_t *datetime)
<> 154:37f96f9d4de2 247 {
<> 154:37f96f9d4de2 248 assert(datetime);
<> 154:37f96f9d4de2 249
<> 154:37f96f9d4de2 250 /* Return error if the time provided is not valid */
<> 154:37f96f9d4de2 251 if (!(RTC_CheckDatetimeFormat(datetime)))
<> 154:37f96f9d4de2 252 {
<> 154:37f96f9d4de2 253 return kStatus_InvalidArgument;
<> 154:37f96f9d4de2 254 }
<> 154:37f96f9d4de2 255
<> 154:37f96f9d4de2 256 /* Set time in seconds */
<> 154:37f96f9d4de2 257 base->TSR = RTC_ConvertDatetimeToSeconds(datetime);
<> 154:37f96f9d4de2 258
<> 154:37f96f9d4de2 259 return kStatus_Success;
<> 154:37f96f9d4de2 260 }
<> 154:37f96f9d4de2 261
<> 154:37f96f9d4de2 262 void RTC_GetDatetime(RTC_Type *base, rtc_datetime_t *datetime)
<> 154:37f96f9d4de2 263 {
<> 154:37f96f9d4de2 264 assert(datetime);
<> 154:37f96f9d4de2 265
<> 154:37f96f9d4de2 266 uint32_t seconds = 0;
<> 154:37f96f9d4de2 267
<> 154:37f96f9d4de2 268 seconds = base->TSR;
<> 154:37f96f9d4de2 269 RTC_ConvertSecondsToDatetime(seconds, datetime);
<> 154:37f96f9d4de2 270 }
<> 154:37f96f9d4de2 271
<> 154:37f96f9d4de2 272 status_t RTC_SetAlarm(RTC_Type *base, const rtc_datetime_t *alarmTime)
<> 154:37f96f9d4de2 273 {
<> 154:37f96f9d4de2 274 assert(alarmTime);
<> 154:37f96f9d4de2 275
<> 154:37f96f9d4de2 276 uint32_t alarmSeconds = 0;
<> 154:37f96f9d4de2 277 uint32_t currSeconds = 0;
<> 154:37f96f9d4de2 278
<> 154:37f96f9d4de2 279 /* Return error if the alarm time provided is not valid */
<> 154:37f96f9d4de2 280 if (!(RTC_CheckDatetimeFormat(alarmTime)))
<> 154:37f96f9d4de2 281 {
<> 154:37f96f9d4de2 282 return kStatus_InvalidArgument;
<> 154:37f96f9d4de2 283 }
<> 154:37f96f9d4de2 284
<> 154:37f96f9d4de2 285 alarmSeconds = RTC_ConvertDatetimeToSeconds(alarmTime);
<> 154:37f96f9d4de2 286
<> 154:37f96f9d4de2 287 /* Get the current time */
<> 154:37f96f9d4de2 288 currSeconds = base->TSR;
<> 154:37f96f9d4de2 289
<> 154:37f96f9d4de2 290 /* Return error if the alarm time has passed */
<> 154:37f96f9d4de2 291 if (alarmSeconds < currSeconds)
<> 154:37f96f9d4de2 292 {
<> 154:37f96f9d4de2 293 return kStatus_Fail;
<> 154:37f96f9d4de2 294 }
<> 154:37f96f9d4de2 295
<> 154:37f96f9d4de2 296 /* Set alarm in seconds*/
<> 154:37f96f9d4de2 297 base->TAR = alarmSeconds;
<> 154:37f96f9d4de2 298
<> 154:37f96f9d4de2 299 return kStatus_Success;
<> 154:37f96f9d4de2 300 }
<> 154:37f96f9d4de2 301
<> 154:37f96f9d4de2 302 void RTC_GetAlarm(RTC_Type *base, rtc_datetime_t *datetime)
<> 154:37f96f9d4de2 303 {
<> 154:37f96f9d4de2 304 assert(datetime);
<> 154:37f96f9d4de2 305
<> 154:37f96f9d4de2 306 uint32_t alarmSeconds = 0;
<> 154:37f96f9d4de2 307
<> 154:37f96f9d4de2 308 /* Get alarm in seconds */
<> 154:37f96f9d4de2 309 alarmSeconds = base->TAR;
<> 154:37f96f9d4de2 310
<> 154:37f96f9d4de2 311 RTC_ConvertSecondsToDatetime(alarmSeconds, datetime);
<> 154:37f96f9d4de2 312 }
<> 154:37f96f9d4de2 313
<> 154:37f96f9d4de2 314 void RTC_ClearStatusFlags(RTC_Type *base, uint32_t mask)
<> 154:37f96f9d4de2 315 {
<> 154:37f96f9d4de2 316 /* The alarm flag is cleared by writing to the TAR register */
<> 154:37f96f9d4de2 317 if (mask & kRTC_AlarmFlag)
<> 154:37f96f9d4de2 318 {
<> 154:37f96f9d4de2 319 base->TAR = 0U;
<> 154:37f96f9d4de2 320 }
<> 154:37f96f9d4de2 321
<> 154:37f96f9d4de2 322 /* The timer overflow flag is cleared by initializing the TSR register.
<> 154:37f96f9d4de2 323 * The time counter should be disabled for this write to be successful
<> 154:37f96f9d4de2 324 */
<> 154:37f96f9d4de2 325 if (mask & kRTC_TimeOverflowFlag)
<> 154:37f96f9d4de2 326 {
<> 154:37f96f9d4de2 327 base->TSR = 1U;
<> 154:37f96f9d4de2 328 }
<> 154:37f96f9d4de2 329
<> 154:37f96f9d4de2 330 /* The timer overflow flag is cleared by initializing the TSR register.
<> 154:37f96f9d4de2 331 * The time counter should be disabled for this write to be successful
<> 154:37f96f9d4de2 332 */
<> 154:37f96f9d4de2 333 if (mask & kRTC_TimeInvalidFlag)
<> 154:37f96f9d4de2 334 {
<> 154:37f96f9d4de2 335 base->TSR = 1U;
<> 154:37f96f9d4de2 336 }
<> 154:37f96f9d4de2 337 }
<> 154:37f96f9d4de2 338
<> 154:37f96f9d4de2 339 #if defined(FSL_FEATURE_RTC_HAS_MONOTONIC) && (FSL_FEATURE_RTC_HAS_MONOTONIC)
<> 154:37f96f9d4de2 340
<> 154:37f96f9d4de2 341 void RTC_GetMonotonicCounter(RTC_Type *base, uint64_t *counter)
<> 154:37f96f9d4de2 342 {
<> 154:37f96f9d4de2 343 *counter = (((uint64_t)base->MCHR << 32) | ((uint64_t)base->MCLR));
<> 154:37f96f9d4de2 344 }
<> 154:37f96f9d4de2 345
<> 154:37f96f9d4de2 346 void RTC_SetMonotonicCounter(RTC_Type *base, uint64_t counter)
<> 154:37f96f9d4de2 347 {
<> 154:37f96f9d4de2 348 /* Prepare to initialize the register with the new value written */
<> 154:37f96f9d4de2 349 base->MER &= ~RTC_MER_MCE_MASK;
<> 154:37f96f9d4de2 350
<> 154:37f96f9d4de2 351 base->MCHR = (uint32_t)((counter) >> 32);
<> 154:37f96f9d4de2 352 base->MCLR = (uint32_t)(counter);
<> 154:37f96f9d4de2 353 }
<> 154:37f96f9d4de2 354
<> 154:37f96f9d4de2 355 status_t RTC_IncrementMonotonicCounter(RTC_Type *base)
<> 154:37f96f9d4de2 356 {
<> 154:37f96f9d4de2 357 if (base->SR & (RTC_SR_MOF_MASK | RTC_SR_TIF_MASK))
<> 154:37f96f9d4de2 358 {
<> 154:37f96f9d4de2 359 return kStatus_Fail;
<> 154:37f96f9d4de2 360 }
<> 154:37f96f9d4de2 361
<> 154:37f96f9d4de2 362 /* Prepare to switch to increment mode */
<> 154:37f96f9d4de2 363 base->MER |= RTC_MER_MCE_MASK;
<> 154:37f96f9d4de2 364 /* Write anything so the counter increments*/
<> 154:37f96f9d4de2 365 base->MCLR = 1U;
<> 154:37f96f9d4de2 366
<> 154:37f96f9d4de2 367 return kStatus_Success;
<> 154:37f96f9d4de2 368 }
<> 154:37f96f9d4de2 369
<> 154:37f96f9d4de2 370 #endif /* FSL_FEATURE_RTC_HAS_MONOTONIC */