Describes predefine macros for mbed online compiler (armcc)

Committer:
MACRUM
Date:
Thu Mar 16 21:58:09 2017 +0900
Revision:
6:40e873bbc5f7
Add licence header info

Who changed what in which revision?

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