Opencv 3.1 project on GR-PEACH board

Fork of gr-peach-opencv-project by the do

Committer:
thedo
Date:
Thu Jun 29 11:01:39 2017 +0000
Revision:
167:1657b442184c
Opencv 3.1 project on GR-PEACH board, 4 apps

Who changed what in which revision?

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