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_TIMER_H
MACRUM 6:40e873bbc5f7 17 #define MBED_TIMER_H
MACRUM 6:40e873bbc5f7 18
MACRUM 6:40e873bbc5f7 19 #include "platform/platform.h"
MACRUM 6:40e873bbc5f7 20 #include "hal/ticker_api.h"
MACRUM 6:40e873bbc5f7 21
MACRUM 6:40e873bbc5f7 22 namespace mbed {
MACRUM 6:40e873bbc5f7 23 /** \addtogroup drivers */
MACRUM 6:40e873bbc5f7 24 /** @{*/
MACRUM 6:40e873bbc5f7 25
MACRUM 6:40e873bbc5f7 26 /** A general purpose timer
MACRUM 6:40e873bbc5f7 27 *
MACRUM 6:40e873bbc5f7 28 * @Note Synchronization level: Interrupt safe
MACRUM 6:40e873bbc5f7 29 *
MACRUM 6:40e873bbc5f7 30 * Example:
MACRUM 6:40e873bbc5f7 31 * @code
MACRUM 6:40e873bbc5f7 32 * // Count the time to toggle a LED
MACRUM 6:40e873bbc5f7 33 *
MACRUM 6:40e873bbc5f7 34 * #include "mbed.h"
MACRUM 6:40e873bbc5f7 35 *
MACRUM 6:40e873bbc5f7 36 * Timer timer;
MACRUM 6:40e873bbc5f7 37 * DigitalOut led(LED1);
MACRUM 6:40e873bbc5f7 38 * int begin, end;
MACRUM 6:40e873bbc5f7 39 *
MACRUM 6:40e873bbc5f7 40 * int main() {
MACRUM 6:40e873bbc5f7 41 * timer.start();
MACRUM 6:40e873bbc5f7 42 * begin = timer.read_us();
MACRUM 6:40e873bbc5f7 43 * led = !led;
MACRUM 6:40e873bbc5f7 44 * end = timer.read_us();
MACRUM 6:40e873bbc5f7 45 * printf("Toggle the led takes %d us", end - begin);
MACRUM 6:40e873bbc5f7 46 * }
MACRUM 6:40e873bbc5f7 47 * @endcode
MACRUM 6:40e873bbc5f7 48 */
MACRUM 6:40e873bbc5f7 49 class Timer {
MACRUM 6:40e873bbc5f7 50
MACRUM 6:40e873bbc5f7 51 public:
MACRUM 6:40e873bbc5f7 52 Timer();
MACRUM 6:40e873bbc5f7 53 Timer(const ticker_data_t *data);
MACRUM 6:40e873bbc5f7 54
MACRUM 6:40e873bbc5f7 55 /** Start the timer
MACRUM 6:40e873bbc5f7 56 */
MACRUM 6:40e873bbc5f7 57 void start();
MACRUM 6:40e873bbc5f7 58
MACRUM 6:40e873bbc5f7 59 /** Stop the timer
MACRUM 6:40e873bbc5f7 60 */
MACRUM 6:40e873bbc5f7 61 void stop();
MACRUM 6:40e873bbc5f7 62
MACRUM 6:40e873bbc5f7 63 /** Reset the timer to 0.
MACRUM 6:40e873bbc5f7 64 *
MACRUM 6:40e873bbc5f7 65 * If it was already counting, it will continue
MACRUM 6:40e873bbc5f7 66 */
MACRUM 6:40e873bbc5f7 67 void reset();
MACRUM 6:40e873bbc5f7 68
MACRUM 6:40e873bbc5f7 69 /** Get the time passed in seconds
MACRUM 6:40e873bbc5f7 70 */
MACRUM 6:40e873bbc5f7 71 float read();
MACRUM 6:40e873bbc5f7 72
MACRUM 6:40e873bbc5f7 73 /** Get the time passed in mili-seconds
MACRUM 6:40e873bbc5f7 74 */
MACRUM 6:40e873bbc5f7 75 int read_ms();
MACRUM 6:40e873bbc5f7 76
MACRUM 6:40e873bbc5f7 77 /** Get the time passed in micro-seconds
MACRUM 6:40e873bbc5f7 78 */
MACRUM 6:40e873bbc5f7 79 int read_us();
MACRUM 6:40e873bbc5f7 80
MACRUM 6:40e873bbc5f7 81 /** An operator shorthand for read()
MACRUM 6:40e873bbc5f7 82 */
MACRUM 6:40e873bbc5f7 83 operator float();
MACRUM 6:40e873bbc5f7 84
MACRUM 6:40e873bbc5f7 85 protected:
MACRUM 6:40e873bbc5f7 86 int slicetime();
MACRUM 6:40e873bbc5f7 87 int _running; // whether the timer is running
MACRUM 6:40e873bbc5f7 88 unsigned int _start; // the start time of the latest slice
MACRUM 6:40e873bbc5f7 89 int _time; // any accumulated time from previous slices
MACRUM 6:40e873bbc5f7 90 const ticker_data_t *_ticker_data;
MACRUM 6:40e873bbc5f7 91 };
MACRUM 6:40e873bbc5f7 92
MACRUM 6:40e873bbc5f7 93 } // namespace mbed
MACRUM 6:40e873bbc5f7 94
MACRUM 6:40e873bbc5f7 95 #endif
MACRUM 6:40e873bbc5f7 96
MACRUM 6:40e873bbc5f7 97 /** @}*/