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