mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Committer:
AnnaBridge
Date:
Wed Feb 20 22:31:08 2019 +0000
Revision:
189:f392fc9709a3
Parent:
186:707f6e361f3e
mbed library release version 165

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 144:ef7eb2e8f9f7 1 /**
<> 144:ef7eb2e8f9f7 2 ******************************************************************************
<> 144:ef7eb2e8f9f7 3 * @file rtc_api.c
<> 144:ef7eb2e8f9f7 4 * @brief Implementation of a RTC driver
<> 144:ef7eb2e8f9f7 5 * @internal
<> 144:ef7eb2e8f9f7 6 * @author ON Semiconductor
<> 144:ef7eb2e8f9f7 7 * $Rev: 0.1 $
<> 144:ef7eb2e8f9f7 8 * $Date: 2016-01-20 12:09:00 +0530 (Wed, 20 Jan 2016) $
<> 144:ef7eb2e8f9f7 9 ******************************************************************************
<> 147:30b64687e01f 10 * Copyright 2016 Semiconductor Components Industries LLC (d/b/a “ON Semiconductor”).
<> 147:30b64687e01f 11 * All rights reserved. This software and/or documentation is licensed by ON Semiconductor
<> 147:30b64687e01f 12 * under limited terms and conditions. The terms and conditions pertaining to the software
<> 147:30b64687e01f 13 * and/or documentation are available at http://www.onsemi.com/site/pdf/ONSEMI_T&C.pdf
<> 147:30b64687e01f 14 * (“ON Semiconductor Standard Terms and Conditions of Sale, Section 8 Software”) and
<> 147:30b64687e01f 15 * if applicable the software license agreement. Do not use this software and/or
<> 147:30b64687e01f 16 * documentation unless you have carefully read and you agree to the limited terms and
<> 147:30b64687e01f 17 * conditions. By using this software and/or documentation, you agree to the limited
<> 147:30b64687e01f 18 * terms and conditions.
<> 144:ef7eb2e8f9f7 19 *
<> 144:ef7eb2e8f9f7 20 * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
<> 144:ef7eb2e8f9f7 21 * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
<> 144:ef7eb2e8f9f7 22 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
<> 144:ef7eb2e8f9f7 23 * ON SEMICONDUCTOR SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL,
<> 144:ef7eb2e8f9f7 24 * INCIDENTAL, OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
<> 144:ef7eb2e8f9f7 25 * @endinternal
<> 144:ef7eb2e8f9f7 26 *
<> 144:ef7eb2e8f9f7 27 * @ingroup rtc
<> 144:ef7eb2e8f9f7 28 *
<> 144:ef7eb2e8f9f7 29 */
<> 144:ef7eb2e8f9f7 30 #include "rtc_api.h"
<> 144:ef7eb2e8f9f7 31 #if DEVICE_RTC
<> 144:ef7eb2e8f9f7 32 #include "device.h"
<> 144:ef7eb2e8f9f7 33
<> 144:ef7eb2e8f9f7 34 #include "cmsis.h"
<> 144:ef7eb2e8f9f7 35 #include "pinmap.h"
<> 144:ef7eb2e8f9f7 36 #include "PeripheralPins.h"
<> 144:ef7eb2e8f9f7 37 #include "mbed_assert.h"
<> 144:ef7eb2e8f9f7 38 #include <string.h>
<> 144:ef7eb2e8f9f7 39 #include "rtc.h"
<> 144:ef7eb2e8f9f7 40 #include "cmsis_nvic.h"
<> 144:ef7eb2e8f9f7 41
Anna Bridge 186:707f6e361f3e 42 #define US_PER_SEC 1000000
Anna Bridge 186:707f6e361f3e 43
Anna Bridge 186:707f6e361f3e 44 static time_t m_time_base;
Anna Bridge 186:707f6e361f3e 45
Anna Bridge 186:707f6e361f3e 46 static uint32_t rtc_seconds_get()
Anna Bridge 186:707f6e361f3e 47 {
Anna Bridge 186:707f6e361f3e 48 return (uint32_t)((fRtcRead() / US_PER_SEC) & 0xFFFFFFFF);
Anna Bridge 186:707f6e361f3e 49 }
Anna Bridge 186:707f6e361f3e 50
<> 144:ef7eb2e8f9f7 51 /* See rtc_apc.h for description */
<> 144:ef7eb2e8f9f7 52
<> 144:ef7eb2e8f9f7 53 void rtc_init(void)
<> 144:ef7eb2e8f9f7 54 {
<> 144:ef7eb2e8f9f7 55 fRtcInit();
<> 144:ef7eb2e8f9f7 56 }
<> 144:ef7eb2e8f9f7 57
<> 144:ef7eb2e8f9f7 58 /* See rtc_apc.h for description */
<> 144:ef7eb2e8f9f7 59 void rtc_free(void)
<> 144:ef7eb2e8f9f7 60 {
<> 144:ef7eb2e8f9f7 61 fRtcFree();
<> 144:ef7eb2e8f9f7 62 }
<> 144:ef7eb2e8f9f7 63
<> 144:ef7eb2e8f9f7 64 /* See rtc_apc.h for description */
<> 144:ef7eb2e8f9f7 65 int rtc_isenabled(void)
<> 144:ef7eb2e8f9f7 66 {
<> 144:ef7eb2e8f9f7 67 return(fIsRtcEnabled());
<> 144:ef7eb2e8f9f7 68 }
<> 144:ef7eb2e8f9f7 69
<> 144:ef7eb2e8f9f7 70 /* See rtc_apc.h for description */
<> 144:ef7eb2e8f9f7 71 time_t rtc_read(void)
<> 144:ef7eb2e8f9f7 72 {
Anna Bridge 186:707f6e361f3e 73 return m_time_base + rtc_seconds_get();
<> 144:ef7eb2e8f9f7 74 }
<> 144:ef7eb2e8f9f7 75
<> 144:ef7eb2e8f9f7 76 /* See rtc_apc.h for description */
<> 144:ef7eb2e8f9f7 77 void rtc_write(time_t t)
<> 144:ef7eb2e8f9f7 78 {
Anna Bridge 186:707f6e361f3e 79 uint32_t seconds;
Anna Bridge 186:707f6e361f3e 80 do {
Anna Bridge 186:707f6e361f3e 81 seconds = rtc_seconds_get();
Anna Bridge 186:707f6e361f3e 82 m_time_base = t - seconds;
Anna Bridge 186:707f6e361f3e 83 /* If the number of seconds indicated by the counter changed during the
Anna Bridge 186:707f6e361f3e 84 update of the time base, just repeat the update, now using the new
Anna Bridge 186:707f6e361f3e 85 number of seconds. */
Anna Bridge 186:707f6e361f3e 86 } while (seconds != rtc_seconds_get());
<> 144:ef7eb2e8f9f7 87 }
<> 144:ef7eb2e8f9f7 88
<> 144:ef7eb2e8f9f7 89 #endif /* DEVICE_RTC */