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