Opencv 3.1 project on GR-PEACH board

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

Committer:
thedo
Date:
Tue Jul 04 06:23:13 2017 +0000
Revision:
170:54ff26da7eb6
Parent:
167:1657b442184c
project opencv 3.1 on GR PEACH board, no use SD card.

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 "drivers/Timer.h"
thedo 167:1657b442184c 17 #include "hal/ticker_api.h"
thedo 167:1657b442184c 18 #include "hal/us_ticker_api.h"
thedo 167:1657b442184c 19 #include "platform/mbed_critical.h"
thedo 167:1657b442184c 20
thedo 167:1657b442184c 21 namespace mbed {
thedo 167:1657b442184c 22
thedo 167:1657b442184c 23 Timer::Timer() : _running(), _start(), _time(), _ticker_data(get_us_ticker_data()) {
thedo 167:1657b442184c 24 reset();
thedo 167:1657b442184c 25 }
thedo 167:1657b442184c 26
thedo 167:1657b442184c 27 Timer::Timer(const ticker_data_t *data) : _running(), _start(), _time(), _ticker_data(data) {
thedo 167:1657b442184c 28 reset();
thedo 167:1657b442184c 29 }
thedo 167:1657b442184c 30
thedo 167:1657b442184c 31 void Timer::start() {
thedo 167:1657b442184c 32 core_util_critical_section_enter();
thedo 167:1657b442184c 33 if (!_running) {
thedo 167:1657b442184c 34 _start = ticker_read_us(_ticker_data);
thedo 167:1657b442184c 35 _running = 1;
thedo 167:1657b442184c 36 }
thedo 167:1657b442184c 37 core_util_critical_section_exit();
thedo 167:1657b442184c 38 }
thedo 167:1657b442184c 39
thedo 167:1657b442184c 40 void Timer::stop() {
thedo 167:1657b442184c 41 core_util_critical_section_enter();
thedo 167:1657b442184c 42 _time += slicetime();
thedo 167:1657b442184c 43 _running = 0;
thedo 167:1657b442184c 44 core_util_critical_section_exit();
thedo 167:1657b442184c 45 }
thedo 167:1657b442184c 46
thedo 167:1657b442184c 47 int Timer::read_us() {
thedo 167:1657b442184c 48 return read_high_resolution_us();
thedo 167:1657b442184c 49 }
thedo 167:1657b442184c 50
thedo 167:1657b442184c 51 float Timer::read() {
thedo 167:1657b442184c 52 return (float)read_us() / 1000000.0f;
thedo 167:1657b442184c 53 }
thedo 167:1657b442184c 54
thedo 167:1657b442184c 55 int Timer::read_ms() {
thedo 167:1657b442184c 56 return read_high_resolution_us() / 1000;
thedo 167:1657b442184c 57 }
thedo 167:1657b442184c 58
thedo 167:1657b442184c 59 us_timestamp_t Timer::read_high_resolution_us() {
thedo 167:1657b442184c 60 core_util_critical_section_enter();
thedo 167:1657b442184c 61 us_timestamp_t time = _time + slicetime();
thedo 167:1657b442184c 62 core_util_critical_section_exit();
thedo 167:1657b442184c 63 return time;
thedo 167:1657b442184c 64 }
thedo 167:1657b442184c 65
thedo 167:1657b442184c 66 us_timestamp_t Timer::slicetime() {
thedo 167:1657b442184c 67 us_timestamp_t ret = 0;
thedo 167:1657b442184c 68 core_util_critical_section_enter();
thedo 167:1657b442184c 69 if (_running) {
thedo 167:1657b442184c 70 ret = ticker_read_us(_ticker_data) - _start;
thedo 167:1657b442184c 71 }
thedo 167:1657b442184c 72 core_util_critical_section_exit();
thedo 167:1657b442184c 73 return ret;
thedo 167:1657b442184c 74 }
thedo 167:1657b442184c 75
thedo 167:1657b442184c 76 void Timer::reset() {
thedo 167:1657b442184c 77 core_util_critical_section_enter();
thedo 167:1657b442184c 78 _start = ticker_read_us(_ticker_data);
thedo 167:1657b442184c 79 _time = 0;
thedo 167:1657b442184c 80 core_util_critical_section_exit();
thedo 167:1657b442184c 81 }
thedo 167:1657b442184c 82
thedo 167:1657b442184c 83 Timer::operator float() {
thedo 167:1657b442184c 84 return read();
thedo 167:1657b442184c 85 }
thedo 167:1657b442184c 86
thedo 167:1657b442184c 87 } // namespace mbed
thedo 167:1657b442184c 88