fft

Dependencies:   BSP_DISCO_F746NG SDFileSystem_Warning_Fixed

Committer:
MikamiUitOpen
Date:
Sun Oct 09 10:11:14 2016 +0000
Revision:
0:3e46577dc273
1

Who changed what in which revision?

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