ads1115 only
Fork of mbed by
Timer.h@98:8ab26030e058, 2015-04-29 (annotated)
- Committer:
- Kojto
- Date:
- Wed Apr 29 10:16:23 2015 +0100
- Revision:
- 98:8ab26030e058
- Parent:
- 65:5798e58a58b1
- Child:
- 100:cbbeb26dbd92
Release 98 of the mbed library
Changes:
- Silabs new targets (Giant, Zero, Happy, Leopard, Wonder Geckos)
- Asynchronous SPI, I2C, Serial
- LowPower classes
- Nordic - nordic SDK v8.0 update
- Teensy - gcc arm fix for startup
- Nucleo F411 - usb freq fix
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bogdanm | 65:5798e58a58b1 | 1 | /* mbed Microcontroller Library |
bogdanm | 65:5798e58a58b1 | 2 | * Copyright (c) 2006-2013 ARM Limited |
bogdanm | 65:5798e58a58b1 | 3 | * |
bogdanm | 65:5798e58a58b1 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
bogdanm | 65:5798e58a58b1 | 5 | * you may not use this file except in compliance with the License. |
bogdanm | 65:5798e58a58b1 | 6 | * You may obtain a copy of the License at |
bogdanm | 65:5798e58a58b1 | 7 | * |
bogdanm | 65:5798e58a58b1 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
bogdanm | 65:5798e58a58b1 | 9 | * |
bogdanm | 65:5798e58a58b1 | 10 | * Unless required by applicable law or agreed to in writing, software |
bogdanm | 65:5798e58a58b1 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
bogdanm | 65:5798e58a58b1 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
bogdanm | 65:5798e58a58b1 | 13 | * See the License for the specific language governing permissions and |
bogdanm | 65:5798e58a58b1 | 14 | * limitations under the License. |
bogdanm | 65:5798e58a58b1 | 15 | */ |
bogdanm | 65:5798e58a58b1 | 16 | #ifndef MBED_TIMER_H |
bogdanm | 65:5798e58a58b1 | 17 | #define MBED_TIMER_H |
bogdanm | 65:5798e58a58b1 | 18 | |
bogdanm | 65:5798e58a58b1 | 19 | #include "platform.h" |
Kojto | 98:8ab26030e058 | 20 | #include "ticker_api.h" |
bogdanm | 65:5798e58a58b1 | 21 | |
bogdanm | 65:5798e58a58b1 | 22 | namespace mbed { |
bogdanm | 65:5798e58a58b1 | 23 | |
bogdanm | 65:5798e58a58b1 | 24 | /** A general purpose timer |
bogdanm | 65:5798e58a58b1 | 25 | * |
bogdanm | 65:5798e58a58b1 | 26 | * Example: |
bogdanm | 65:5798e58a58b1 | 27 | * @code |
bogdanm | 65:5798e58a58b1 | 28 | * // Count the time to toggle a LED |
bogdanm | 65:5798e58a58b1 | 29 | * |
bogdanm | 65:5798e58a58b1 | 30 | * #include "mbed.h" |
bogdanm | 65:5798e58a58b1 | 31 | * |
bogdanm | 65:5798e58a58b1 | 32 | * Timer timer; |
bogdanm | 65:5798e58a58b1 | 33 | * DigitalOut led(LED1); |
bogdanm | 65:5798e58a58b1 | 34 | * int begin, end; |
bogdanm | 65:5798e58a58b1 | 35 | * |
bogdanm | 65:5798e58a58b1 | 36 | * int main() { |
bogdanm | 65:5798e58a58b1 | 37 | * timer.start(); |
bogdanm | 65:5798e58a58b1 | 38 | * begin = timer.read_us(); |
bogdanm | 65:5798e58a58b1 | 39 | * led = !led; |
bogdanm | 65:5798e58a58b1 | 40 | * end = timer.read_us(); |
bogdanm | 65:5798e58a58b1 | 41 | * printf("Toggle the led takes %d us", end - begin); |
bogdanm | 65:5798e58a58b1 | 42 | * } |
bogdanm | 65:5798e58a58b1 | 43 | * @endcode |
bogdanm | 65:5798e58a58b1 | 44 | */ |
bogdanm | 65:5798e58a58b1 | 45 | class Timer { |
bogdanm | 65:5798e58a58b1 | 46 | |
bogdanm | 65:5798e58a58b1 | 47 | public: |
bogdanm | 65:5798e58a58b1 | 48 | Timer(); |
Kojto | 98:8ab26030e058 | 49 | Timer(const ticker_data_t *const data); |
bogdanm | 65:5798e58a58b1 | 50 | |
bogdanm | 65:5798e58a58b1 | 51 | /** Start the timer |
bogdanm | 65:5798e58a58b1 | 52 | */ |
bogdanm | 65:5798e58a58b1 | 53 | void start(); |
bogdanm | 65:5798e58a58b1 | 54 | |
bogdanm | 65:5798e58a58b1 | 55 | /** Stop the timer |
bogdanm | 65:5798e58a58b1 | 56 | */ |
bogdanm | 65:5798e58a58b1 | 57 | void stop(); |
bogdanm | 65:5798e58a58b1 | 58 | |
bogdanm | 65:5798e58a58b1 | 59 | /** Reset the timer to 0. |
bogdanm | 65:5798e58a58b1 | 60 | * |
bogdanm | 65:5798e58a58b1 | 61 | * If it was already counting, it will continue |
bogdanm | 65:5798e58a58b1 | 62 | */ |
bogdanm | 65:5798e58a58b1 | 63 | void reset(); |
bogdanm | 65:5798e58a58b1 | 64 | |
bogdanm | 65:5798e58a58b1 | 65 | /** Get the time passed in seconds |
bogdanm | 65:5798e58a58b1 | 66 | */ |
bogdanm | 65:5798e58a58b1 | 67 | float read(); |
bogdanm | 65:5798e58a58b1 | 68 | |
bogdanm | 65:5798e58a58b1 | 69 | /** Get the time passed in mili-seconds |
bogdanm | 65:5798e58a58b1 | 70 | */ |
bogdanm | 65:5798e58a58b1 | 71 | int read_ms(); |
bogdanm | 65:5798e58a58b1 | 72 | |
bogdanm | 65:5798e58a58b1 | 73 | /** Get the time passed in micro-seconds |
bogdanm | 65:5798e58a58b1 | 74 | */ |
bogdanm | 65:5798e58a58b1 | 75 | int read_us(); |
bogdanm | 65:5798e58a58b1 | 76 | |
bogdanm | 65:5798e58a58b1 | 77 | #ifdef MBED_OPERATORS |
bogdanm | 65:5798e58a58b1 | 78 | operator float(); |
bogdanm | 65:5798e58a58b1 | 79 | #endif |
bogdanm | 65:5798e58a58b1 | 80 | |
bogdanm | 65:5798e58a58b1 | 81 | protected: |
bogdanm | 65:5798e58a58b1 | 82 | int slicetime(); |
bogdanm | 65:5798e58a58b1 | 83 | int _running; // whether the timer is running |
bogdanm | 65:5798e58a58b1 | 84 | unsigned int _start; // the start time of the latest slice |
bogdanm | 65:5798e58a58b1 | 85 | int _time; // any accumulated time from previous slices |
Kojto | 98:8ab26030e058 | 86 | const ticker_data_t *const _ticker_data; |
bogdanm | 65:5798e58a58b1 | 87 | }; |
bogdanm | 65:5798e58a58b1 | 88 | |
bogdanm | 65:5798e58a58b1 | 89 | } // namespace mbed |
bogdanm | 65:5798e58a58b1 | 90 | |
bogdanm | 65:5798e58a58b1 | 91 | #endif |