Renesas GR-PEACH OpenCV Development / gr-peach-opencv-project-sd-card_update

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

Committer:
thedo
Date:
Fri Jul 21 01:26:54 2017 +0000
Revision:
167:2ee3e82cb6f5
gr-peach-opencv-project-sd-card

Who changed what in which revision?

UserRevisionLine numberNew contents of line
thedo 167:2ee3e82cb6f5 1 /* mbed Microcontroller Library
thedo 167:2ee3e82cb6f5 2 * Copyright (c) 2006-2013 ARM Limited
thedo 167:2ee3e82cb6f5 3 *
thedo 167:2ee3e82cb6f5 4 * Licensed under the Apache License, Version 2.0 (the "License");
thedo 167:2ee3e82cb6f5 5 * you may not use this file except in compliance with the License.
thedo 167:2ee3e82cb6f5 6 * You may obtain a copy of the License at
thedo 167:2ee3e82cb6f5 7 *
thedo 167:2ee3e82cb6f5 8 * http://www.apache.org/licenses/LICENSE-2.0
thedo 167:2ee3e82cb6f5 9 *
thedo 167:2ee3e82cb6f5 10 * Unless required by applicable law or agreed to in writing, software
thedo 167:2ee3e82cb6f5 11 * distributed under the License is distributed on an "AS IS" BASIS,
thedo 167:2ee3e82cb6f5 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
thedo 167:2ee3e82cb6f5 13 * See the License for the specific language governing permissions and
thedo 167:2ee3e82cb6f5 14 * limitations under the License.
thedo 167:2ee3e82cb6f5 15 */
thedo 167:2ee3e82cb6f5 16 #ifndef MBED_TICKER_H
thedo 167:2ee3e82cb6f5 17 #define MBED_TICKER_H
thedo 167:2ee3e82cb6f5 18
thedo 167:2ee3e82cb6f5 19 #include "drivers/TimerEvent.h"
thedo 167:2ee3e82cb6f5 20 #include "platform/Callback.h"
thedo 167:2ee3e82cb6f5 21 #include "platform/mbed_toolchain.h"
thedo 167:2ee3e82cb6f5 22
thedo 167:2ee3e82cb6f5 23 namespace mbed {
thedo 167:2ee3e82cb6f5 24 /** \addtogroup drivers */
thedo 167:2ee3e82cb6f5 25
thedo 167:2ee3e82cb6f5 26 /** A Ticker is used to call a function at a recurring interval
thedo 167:2ee3e82cb6f5 27 *
thedo 167:2ee3e82cb6f5 28 * You can use as many seperate Ticker objects as you require.
thedo 167:2ee3e82cb6f5 29 *
thedo 167:2ee3e82cb6f5 30 * @note Synchronization level: Interrupt safe
thedo 167:2ee3e82cb6f5 31 *
thedo 167:2ee3e82cb6f5 32 * Example:
thedo 167:2ee3e82cb6f5 33 * @code
thedo 167:2ee3e82cb6f5 34 * // Toggle the blinking led after 5 seconds
thedo 167:2ee3e82cb6f5 35 *
thedo 167:2ee3e82cb6f5 36 * #include "mbed.h"
thedo 167:2ee3e82cb6f5 37 *
thedo 167:2ee3e82cb6f5 38 * Ticker timer;
thedo 167:2ee3e82cb6f5 39 * DigitalOut led1(LED1);
thedo 167:2ee3e82cb6f5 40 * DigitalOut led2(LED2);
thedo 167:2ee3e82cb6f5 41 *
thedo 167:2ee3e82cb6f5 42 * int flip = 0;
thedo 167:2ee3e82cb6f5 43 *
thedo 167:2ee3e82cb6f5 44 * void attime() {
thedo 167:2ee3e82cb6f5 45 * flip = !flip;
thedo 167:2ee3e82cb6f5 46 * }
thedo 167:2ee3e82cb6f5 47 *
thedo 167:2ee3e82cb6f5 48 * int main() {
thedo 167:2ee3e82cb6f5 49 * timer.attach(&attime, 5);
thedo 167:2ee3e82cb6f5 50 * while(1) {
thedo 167:2ee3e82cb6f5 51 * if(flip == 0) {
thedo 167:2ee3e82cb6f5 52 * led1 = !led1;
thedo 167:2ee3e82cb6f5 53 * } else {
thedo 167:2ee3e82cb6f5 54 * led2 = !led2;
thedo 167:2ee3e82cb6f5 55 * }
thedo 167:2ee3e82cb6f5 56 * wait(0.2);
thedo 167:2ee3e82cb6f5 57 * }
thedo 167:2ee3e82cb6f5 58 * }
thedo 167:2ee3e82cb6f5 59 * @endcode
thedo 167:2ee3e82cb6f5 60 * @ingroup drivers
thedo 167:2ee3e82cb6f5 61 */
thedo 167:2ee3e82cb6f5 62 class Ticker : public TimerEvent {
thedo 167:2ee3e82cb6f5 63
thedo 167:2ee3e82cb6f5 64 public:
thedo 167:2ee3e82cb6f5 65 Ticker() : TimerEvent() {
thedo 167:2ee3e82cb6f5 66 }
thedo 167:2ee3e82cb6f5 67
thedo 167:2ee3e82cb6f5 68 Ticker(const ticker_data_t *data) : TimerEvent(data) {
thedo 167:2ee3e82cb6f5 69 data->interface->init();
thedo 167:2ee3e82cb6f5 70 }
thedo 167:2ee3e82cb6f5 71
thedo 167:2ee3e82cb6f5 72 /** Attach a function to be called by the Ticker, specifiying the interval in seconds
thedo 167:2ee3e82cb6f5 73 *
thedo 167:2ee3e82cb6f5 74 * @param func pointer to the function to be called
thedo 167:2ee3e82cb6f5 75 * @param t the time between calls in seconds
thedo 167:2ee3e82cb6f5 76 */
thedo 167:2ee3e82cb6f5 77 void attach(Callback<void()> func, float t) {
thedo 167:2ee3e82cb6f5 78 attach_us(func, t * 1000000.0f);
thedo 167:2ee3e82cb6f5 79 }
thedo 167:2ee3e82cb6f5 80
thedo 167:2ee3e82cb6f5 81 /** Attach a member function to be called by the Ticker, specifiying the interval in seconds
thedo 167:2ee3e82cb6f5 82 *
thedo 167:2ee3e82cb6f5 83 * @param obj pointer to the object to call the member function on
thedo 167:2ee3e82cb6f5 84 * @param method pointer to the member function to be called
thedo 167:2ee3e82cb6f5 85 * @param t the time between calls in seconds
thedo 167:2ee3e82cb6f5 86 * @deprecated
thedo 167:2ee3e82cb6f5 87 * The attach function does not support cv-qualifiers. Replaced by
thedo 167:2ee3e82cb6f5 88 * attach(callback(obj, method), t).
thedo 167:2ee3e82cb6f5 89 */
thedo 167:2ee3e82cb6f5 90 template<typename T, typename M>
thedo 167:2ee3e82cb6f5 91 MBED_DEPRECATED_SINCE("mbed-os-5.1",
thedo 167:2ee3e82cb6f5 92 "The attach function does not support cv-qualifiers. Replaced by "
thedo 167:2ee3e82cb6f5 93 "attach(callback(obj, method), t).")
thedo 167:2ee3e82cb6f5 94 void attach(T *obj, M method, float t) {
thedo 167:2ee3e82cb6f5 95 attach(callback(obj, method), t);
thedo 167:2ee3e82cb6f5 96 }
thedo 167:2ee3e82cb6f5 97
thedo 167:2ee3e82cb6f5 98 /** Attach a function to be called by the Ticker, specifiying the interval in micro-seconds
thedo 167:2ee3e82cb6f5 99 *
thedo 167:2ee3e82cb6f5 100 * @param func pointer to the function to be called
thedo 167:2ee3e82cb6f5 101 * @param t the time between calls in micro-seconds
thedo 167:2ee3e82cb6f5 102 */
thedo 167:2ee3e82cb6f5 103 void attach_us(Callback<void()> func, us_timestamp_t t) {
thedo 167:2ee3e82cb6f5 104 _function = func;
thedo 167:2ee3e82cb6f5 105 setup(t);
thedo 167:2ee3e82cb6f5 106 }
thedo 167:2ee3e82cb6f5 107
thedo 167:2ee3e82cb6f5 108 /** Attach a member function to be called by the Ticker, specifiying the interval in micro-seconds
thedo 167:2ee3e82cb6f5 109 *
thedo 167:2ee3e82cb6f5 110 * @param obj pointer to the object to call the member function on
thedo 167:2ee3e82cb6f5 111 * @param method pointer to the member function to be called
thedo 167:2ee3e82cb6f5 112 * @param t the time between calls in micro-seconds
thedo 167:2ee3e82cb6f5 113 * @deprecated
thedo 167:2ee3e82cb6f5 114 * The attach_us function does not support cv-qualifiers. Replaced by
thedo 167:2ee3e82cb6f5 115 * attach_us(callback(obj, method), t).
thedo 167:2ee3e82cb6f5 116 */
thedo 167:2ee3e82cb6f5 117 template<typename T, typename M>
thedo 167:2ee3e82cb6f5 118 MBED_DEPRECATED_SINCE("mbed-os-5.1",
thedo 167:2ee3e82cb6f5 119 "The attach_us function does not support cv-qualifiers. Replaced by "
thedo 167:2ee3e82cb6f5 120 "attach_us(callback(obj, method), t).")
thedo 167:2ee3e82cb6f5 121 void attach_us(T *obj, M method, us_timestamp_t t) {
thedo 167:2ee3e82cb6f5 122 attach_us(Callback<void()>(obj, method), t);
thedo 167:2ee3e82cb6f5 123 }
thedo 167:2ee3e82cb6f5 124
thedo 167:2ee3e82cb6f5 125 virtual ~Ticker() {
thedo 167:2ee3e82cb6f5 126 detach();
thedo 167:2ee3e82cb6f5 127 }
thedo 167:2ee3e82cb6f5 128
thedo 167:2ee3e82cb6f5 129 /** Detach the function
thedo 167:2ee3e82cb6f5 130 */
thedo 167:2ee3e82cb6f5 131 void detach();
thedo 167:2ee3e82cb6f5 132
thedo 167:2ee3e82cb6f5 133 protected:
thedo 167:2ee3e82cb6f5 134 void setup(us_timestamp_t t);
thedo 167:2ee3e82cb6f5 135 virtual void handler();
thedo 167:2ee3e82cb6f5 136
thedo 167:2ee3e82cb6f5 137 protected:
thedo 167:2ee3e82cb6f5 138 us_timestamp_t _delay; /**< Time delay (in microseconds) for re-setting the multi-shot callback. */
thedo 167:2ee3e82cb6f5 139 Callback<void()> _function; /**< Callback. */
thedo 167:2ee3e82cb6f5 140 };
thedo 167:2ee3e82cb6f5 141
thedo 167:2ee3e82cb6f5 142 } // namespace mbed
thedo 167:2ee3e82cb6f5 143
thedo 167:2ee3e82cb6f5 144 #endif
thedo 167:2ee3e82cb6f5 145