1 /* mbed Microcontroller Library
2 * Copyright (c) 2006-2013 ARM Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include "us_ticker_api.h"
23 static void (*_rtc_init)(void) = rtc_init;
24 static int (*_rtc_isenabled)(void) = rtc_isenabled;
25 static time_t (*_rtc_read)(void) = rtc_read;
26 static void (*_rtc_write)(time_t t) = rtc_write;
28 static void (*_rtc_init)(void) = NULL;
29 static int (*_rtc_isenabled)(void) = NULL;
30 static time_t (*_rtc_read)(void) = NULL;
31 static void (*_rtc_write)(time_t t) = NULL;
37 #if defined (__ICCARM__)
38 time_t __time32(time_t *timer)
40 time_t time(time_t *timer)
44 if (_rtc_isenabled != NULL) {
45 if (!(_rtc_isenabled())) {
51 if (_rtc_read != NULL) {
61 void set_time(time_t t) {
62 if (_rtc_init != NULL) {
65 if (_rtc_write != NULL) {
71 clock_t t = us_ticker_read();
72 t /= 1000000 / CLOCKS_PER_SEC; // convert to processor time
76 void attach_rtc(time_t (*read_rtc)(void), void (*write_rtc)(time_t), void (*init_rtc)(void), int (*isenabled_rtc)(void)) {
79 _rtc_write = write_rtc;
81 _rtc_isenabled = isenabled_rtc;