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