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