mbed library sources, mbed-dev only for TYBLE16
Fork of mbed-dev by
Please refer flowing link.
/users/kenjiArai/notebook/tyble16-module-will-become-a-mbed-family--mbedliza/
drivers/Timer.h@167:e84263d55307, 2017-06-21 (annotated)
- Committer:
- AnnaBridge
- Date:
- Wed Jun 21 17:46:44 2017 +0100
- Revision:
- 167:e84263d55307
- Parent:
- 149:156823d33999
- Child:
- 168:9672193075cf
This updates the lib to the mbed lib v 145
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
<> | 149:156823d33999 | 1 | /* mbed Microcontroller Library |
<> | 149:156823d33999 | 2 | * Copyright (c) 2006-2013 ARM Limited |
<> | 149:156823d33999 | 3 | * |
<> | 149:156823d33999 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
<> | 149:156823d33999 | 5 | * you may not use this file except in compliance with the License. |
<> | 149:156823d33999 | 6 | * You may obtain a copy of the License at |
<> | 149:156823d33999 | 7 | * |
<> | 149:156823d33999 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
<> | 149:156823d33999 | 9 | * |
<> | 149:156823d33999 | 10 | * Unless required by applicable law or agreed to in writing, software |
<> | 149:156823d33999 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
<> | 149:156823d33999 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
<> | 149:156823d33999 | 13 | * See the License for the specific language governing permissions and |
<> | 149:156823d33999 | 14 | * limitations under the License. |
<> | 149:156823d33999 | 15 | */ |
<> | 149:156823d33999 | 16 | #ifndef MBED_TIMER_H |
<> | 149:156823d33999 | 17 | #define MBED_TIMER_H |
<> | 149:156823d33999 | 18 | |
<> | 149:156823d33999 | 19 | #include "platform/platform.h" |
<> | 149:156823d33999 | 20 | #include "hal/ticker_api.h" |
<> | 149:156823d33999 | 21 | |
<> | 149:156823d33999 | 22 | namespace mbed { |
<> | 149:156823d33999 | 23 | /** \addtogroup drivers */ |
<> | 149:156823d33999 | 24 | |
<> | 149:156823d33999 | 25 | /** A general purpose timer |
<> | 149:156823d33999 | 26 | * |
AnnaBridge | 167:e84263d55307 | 27 | * @note Synchronization level: Interrupt safe |
<> | 149:156823d33999 | 28 | * |
<> | 149:156823d33999 | 29 | * Example: |
<> | 149:156823d33999 | 30 | * @code |
<> | 149:156823d33999 | 31 | * // Count the time to toggle a LED |
<> | 149:156823d33999 | 32 | * |
<> | 149:156823d33999 | 33 | * #include "mbed.h" |
<> | 149:156823d33999 | 34 | * |
<> | 149:156823d33999 | 35 | * Timer timer; |
<> | 149:156823d33999 | 36 | * DigitalOut led(LED1); |
<> | 149:156823d33999 | 37 | * int begin, end; |
<> | 149:156823d33999 | 38 | * |
<> | 149:156823d33999 | 39 | * int main() { |
<> | 149:156823d33999 | 40 | * timer.start(); |
<> | 149:156823d33999 | 41 | * begin = timer.read_us(); |
<> | 149:156823d33999 | 42 | * led = !led; |
<> | 149:156823d33999 | 43 | * end = timer.read_us(); |
<> | 149:156823d33999 | 44 | * printf("Toggle the led takes %d us", end - begin); |
<> | 149:156823d33999 | 45 | * } |
<> | 149:156823d33999 | 46 | * @endcode |
AnnaBridge | 167:e84263d55307 | 47 | * @ingroup drivers |
<> | 149:156823d33999 | 48 | */ |
<> | 149:156823d33999 | 49 | class Timer { |
<> | 149:156823d33999 | 50 | |
<> | 149:156823d33999 | 51 | public: |
<> | 149:156823d33999 | 52 | Timer(); |
<> | 149:156823d33999 | 53 | Timer(const ticker_data_t *data); |
<> | 149:156823d33999 | 54 | |
<> | 149:156823d33999 | 55 | /** Start the timer |
<> | 149:156823d33999 | 56 | */ |
<> | 149:156823d33999 | 57 | void start(); |
<> | 149:156823d33999 | 58 | |
<> | 149:156823d33999 | 59 | /** Stop the timer |
<> | 149:156823d33999 | 60 | */ |
<> | 149:156823d33999 | 61 | void stop(); |
<> | 149:156823d33999 | 62 | |
<> | 149:156823d33999 | 63 | /** Reset the timer to 0. |
<> | 149:156823d33999 | 64 | * |
<> | 149:156823d33999 | 65 | * If it was already counting, it will continue |
<> | 149:156823d33999 | 66 | */ |
<> | 149:156823d33999 | 67 | void reset(); |
<> | 149:156823d33999 | 68 | |
<> | 149:156823d33999 | 69 | /** Get the time passed in seconds |
AnnaBridge | 167:e84263d55307 | 70 | * |
AnnaBridge | 167:e84263d55307 | 71 | * @returns Time passed in seconds |
<> | 149:156823d33999 | 72 | */ |
<> | 149:156823d33999 | 73 | float read(); |
<> | 149:156823d33999 | 74 | |
AnnaBridge | 167:e84263d55307 | 75 | /** Get the time passed in milli-seconds |
AnnaBridge | 167:e84263d55307 | 76 | * |
AnnaBridge | 167:e84263d55307 | 77 | * @returns Time passed in milli seconds |
<> | 149:156823d33999 | 78 | */ |
<> | 149:156823d33999 | 79 | int read_ms(); |
<> | 149:156823d33999 | 80 | |
<> | 149:156823d33999 | 81 | /** Get the time passed in micro-seconds |
AnnaBridge | 167:e84263d55307 | 82 | * |
AnnaBridge | 167:e84263d55307 | 83 | * @returns Time passed in micro seconds |
<> | 149:156823d33999 | 84 | */ |
<> | 149:156823d33999 | 85 | int read_us(); |
<> | 149:156823d33999 | 86 | |
<> | 149:156823d33999 | 87 | /** An operator shorthand for read() |
<> | 149:156823d33999 | 88 | */ |
<> | 149:156823d33999 | 89 | operator float(); |
<> | 149:156823d33999 | 90 | |
AnnaBridge | 167:e84263d55307 | 91 | /** Get in a high resolution type the time passed in micro-seconds. |
AnnaBridge | 167:e84263d55307 | 92 | */ |
AnnaBridge | 167:e84263d55307 | 93 | us_timestamp_t read_high_resolution_us(); |
AnnaBridge | 167:e84263d55307 | 94 | |
<> | 149:156823d33999 | 95 | protected: |
AnnaBridge | 167:e84263d55307 | 96 | us_timestamp_t slicetime(); |
AnnaBridge | 167:e84263d55307 | 97 | int _running; // whether the timer is running |
AnnaBridge | 167:e84263d55307 | 98 | us_timestamp_t _start; // the start time of the latest slice |
AnnaBridge | 167:e84263d55307 | 99 | us_timestamp_t _time; // any accumulated time from previous slices |
<> | 149:156823d33999 | 100 | const ticker_data_t *_ticker_data; |
<> | 149:156823d33999 | 101 | }; |
<> | 149:156823d33999 | 102 | |
<> | 149:156823d33999 | 103 | } // namespace mbed |
<> | 149:156823d33999 | 104 | |
<> | 149:156823d33999 | 105 | #endif |