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