mbed library sources. Supersedes mbed-src.

Dependents:   BREAK_SENSOR_LED

Fork of mbed-dev by mbed official

Committer:
Anythingconnected
Date:
Mon Dec 18 10:14:27 2017 +0000
Revision:
180:d79f997829d6
Parent:
175:af195413fb11
Getting byte by byte read to work

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 149:156823d33999 1 /* mbed Microcontroller Library
<> 149:156823d33999 2 * Copyright (c) 2006-2013 ARM Limited
<> 149:156823d33999 3 *
<> 149:156823d33999 4 * Licensed under the Apache License, Version 2.0 (the "License");
<> 149:156823d33999 5 * you may not use this file except in compliance with the License.
<> 149:156823d33999 6 * You may obtain a copy of the License at
<> 149:156823d33999 7 *
<> 149:156823d33999 8 * http://www.apache.org/licenses/LICENSE-2.0
<> 149:156823d33999 9 *
<> 149:156823d33999 10 * Unless required by applicable law or agreed to in writing, software
<> 149:156823d33999 11 * distributed under the License is distributed on an "AS IS" BASIS,
<> 149:156823d33999 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<> 149:156823d33999 13 * See the License for the specific language governing permissions and
<> 149:156823d33999 14 * limitations under the License.
<> 149:156823d33999 15 */
<> 149:156823d33999 16 #include "hal/rtc_api.h"
<> 149:156823d33999 17
<> 160:d5399cc887bb 18 #include "platform/mbed_critical.h"
<> 160:d5399cc887bb 19 #include "platform/mbed_rtc_time.h"
<> 149:156823d33999 20 #include "platform/SingletonPtr.h"
<> 149:156823d33999 21 #include "platform/PlatformMutex.h"
<> 149:156823d33999 22
<> 149:156823d33999 23 static SingletonPtr<PlatformMutex> _mutex;
<> 149:156823d33999 24
<> 149:156823d33999 25 #if DEVICE_RTC
<> 149:156823d33999 26 static void (*_rtc_init)(void) = rtc_init;
<> 149:156823d33999 27 static int (*_rtc_isenabled)(void) = rtc_isenabled;
<> 149:156823d33999 28 static time_t (*_rtc_read)(void) = rtc_read;
<> 149:156823d33999 29 static void (*_rtc_write)(time_t t) = rtc_write;
<> 149:156823d33999 30 #else
<> 149:156823d33999 31 static void (*_rtc_init)(void) = NULL;
<> 149:156823d33999 32 static int (*_rtc_isenabled)(void) = NULL;
<> 149:156823d33999 33 static time_t (*_rtc_read)(void) = NULL;
<> 149:156823d33999 34 static void (*_rtc_write)(time_t t) = NULL;
<> 149:156823d33999 35 #endif
<> 149:156823d33999 36
<> 149:156823d33999 37 #ifdef __cplusplus
<> 149:156823d33999 38 extern "C" {
<> 149:156823d33999 39 #endif
<> 149:156823d33999 40 #if defined (__ICCARM__)
<> 149:156823d33999 41 time_t __time32(time_t *timer)
<> 149:156823d33999 42 #else
<> 149:156823d33999 43 time_t time(time_t *timer)
<> 149:156823d33999 44 #endif
<> 149:156823d33999 45
<> 149:156823d33999 46 {
<> 149:156823d33999 47 _mutex->lock();
<> 149:156823d33999 48 if (_rtc_isenabled != NULL) {
<> 149:156823d33999 49 if (!(_rtc_isenabled())) {
<> 149:156823d33999 50 set_time(0);
<> 149:156823d33999 51 }
<> 149:156823d33999 52 }
<> 149:156823d33999 53
Kojto 169:e3b6fe271b81 54 time_t t = (time_t)-1;
<> 149:156823d33999 55 if (_rtc_read != NULL) {
<> 149:156823d33999 56 t = _rtc_read();
<> 149:156823d33999 57 }
<> 149:156823d33999 58
<> 149:156823d33999 59 if (timer != NULL) {
<> 149:156823d33999 60 *timer = t;
<> 149:156823d33999 61 }
<> 149:156823d33999 62 _mutex->unlock();
<> 149:156823d33999 63 return t;
<> 149:156823d33999 64 }
<> 149:156823d33999 65
<> 149:156823d33999 66 void set_time(time_t t) {
<> 149:156823d33999 67 _mutex->lock();
<> 149:156823d33999 68 if (_rtc_init != NULL) {
<> 149:156823d33999 69 _rtc_init();
<> 149:156823d33999 70 }
<> 149:156823d33999 71 if (_rtc_write != NULL) {
<> 149:156823d33999 72 _rtc_write(t);
<> 149:156823d33999 73 }
<> 149:156823d33999 74 _mutex->unlock();
<> 149:156823d33999 75 }
<> 149:156823d33999 76
<> 149:156823d33999 77 void attach_rtc(time_t (*read_rtc)(void), void (*write_rtc)(time_t), void (*init_rtc)(void), int (*isenabled_rtc)(void)) {
<> 149:156823d33999 78 _mutex->lock();
<> 149:156823d33999 79 _rtc_read = read_rtc;
<> 149:156823d33999 80 _rtc_write = write_rtc;
<> 149:156823d33999 81 _rtc_init = init_rtc;
<> 149:156823d33999 82 _rtc_isenabled = isenabled_rtc;
<> 149:156823d33999 83 _mutex->unlock();
<> 149:156823d33999 84 }
<> 149:156823d33999 85
<> 149:156823d33999 86
<> 149:156823d33999 87
<> 149:156823d33999 88 #ifdef __cplusplus
<> 149:156823d33999 89 }
<> 149:156823d33999 90 #endif