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