Daniel Vizcaya
/
04_RTOS_Embebidos
Entrega 3er corte - sistemas embebidos
mbed-os/drivers/Timer.h@1:fcdb45ee95b9, 2018-05-30 (annotated)
- Committer:
- Bethory
- Date:
- Wed May 30 04:46:28 2018 +0000
- Revision:
- 1:fcdb45ee95b9
- Parent:
- 0:6ad07c9019fd
Entrega Final
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Bethory | 0:6ad07c9019fd | 1 | /* mbed Microcontroller Library |
Bethory | 0:6ad07c9019fd | 2 | * Copyright (c) 2006-2013 ARM Limited |
Bethory | 0:6ad07c9019fd | 3 | * |
Bethory | 0:6ad07c9019fd | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Bethory | 0:6ad07c9019fd | 5 | * you may not use this file except in compliance with the License. |
Bethory | 0:6ad07c9019fd | 6 | * You may obtain a copy of the License at |
Bethory | 0:6ad07c9019fd | 7 | * |
Bethory | 0:6ad07c9019fd | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Bethory | 0:6ad07c9019fd | 9 | * |
Bethory | 0:6ad07c9019fd | 10 | * Unless required by applicable law or agreed to in writing, software |
Bethory | 0:6ad07c9019fd | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Bethory | 0:6ad07c9019fd | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Bethory | 0:6ad07c9019fd | 13 | * See the License for the specific language governing permissions and |
Bethory | 0:6ad07c9019fd | 14 | * limitations under the License. |
Bethory | 0:6ad07c9019fd | 15 | */ |
Bethory | 0:6ad07c9019fd | 16 | #ifndef MBED_TIMER_H |
Bethory | 0:6ad07c9019fd | 17 | #define MBED_TIMER_H |
Bethory | 0:6ad07c9019fd | 18 | |
Bethory | 0:6ad07c9019fd | 19 | #include "platform/platform.h" |
Bethory | 0:6ad07c9019fd | 20 | #include "hal/ticker_api.h" |
Bethory | 0:6ad07c9019fd | 21 | #include "platform/NonCopyable.h" |
Bethory | 0:6ad07c9019fd | 22 | #include "platform/mbed_power_mgmt.h" |
Bethory | 0:6ad07c9019fd | 23 | |
Bethory | 0:6ad07c9019fd | 24 | namespace mbed { |
Bethory | 0:6ad07c9019fd | 25 | /** \addtogroup drivers */ |
Bethory | 0:6ad07c9019fd | 26 | |
Bethory | 0:6ad07c9019fd | 27 | /** A general purpose timer |
Bethory | 0:6ad07c9019fd | 28 | * |
Bethory | 0:6ad07c9019fd | 29 | * @note Synchronization level: Interrupt safe |
Bethory | 0:6ad07c9019fd | 30 | * |
Bethory | 0:6ad07c9019fd | 31 | * Example: |
Bethory | 0:6ad07c9019fd | 32 | * @code |
Bethory | 0:6ad07c9019fd | 33 | * // Count the time to toggle a LED |
Bethory | 0:6ad07c9019fd | 34 | * |
Bethory | 0:6ad07c9019fd | 35 | * #include "mbed.h" |
Bethory | 0:6ad07c9019fd | 36 | * |
Bethory | 0:6ad07c9019fd | 37 | * Timer timer; |
Bethory | 0:6ad07c9019fd | 38 | * DigitalOut led(LED1); |
Bethory | 0:6ad07c9019fd | 39 | * int begin, end; |
Bethory | 0:6ad07c9019fd | 40 | * |
Bethory | 0:6ad07c9019fd | 41 | * int main() { |
Bethory | 0:6ad07c9019fd | 42 | * timer.start(); |
Bethory | 0:6ad07c9019fd | 43 | * begin = timer.read_us(); |
Bethory | 0:6ad07c9019fd | 44 | * led = !led; |
Bethory | 0:6ad07c9019fd | 45 | * end = timer.read_us(); |
Bethory | 0:6ad07c9019fd | 46 | * printf("Toggle the led takes %d us", end - begin); |
Bethory | 0:6ad07c9019fd | 47 | * } |
Bethory | 0:6ad07c9019fd | 48 | * @endcode |
Bethory | 0:6ad07c9019fd | 49 | * @ingroup drivers |
Bethory | 0:6ad07c9019fd | 50 | */ |
Bethory | 0:6ad07c9019fd | 51 | class Timer : private NonCopyable<Timer> { |
Bethory | 0:6ad07c9019fd | 52 | |
Bethory | 0:6ad07c9019fd | 53 | public: |
Bethory | 0:6ad07c9019fd | 54 | Timer(); |
Bethory | 0:6ad07c9019fd | 55 | Timer(const ticker_data_t *data); |
Bethory | 0:6ad07c9019fd | 56 | ~Timer(); |
Bethory | 0:6ad07c9019fd | 57 | |
Bethory | 0:6ad07c9019fd | 58 | /** Start the timer |
Bethory | 0:6ad07c9019fd | 59 | */ |
Bethory | 0:6ad07c9019fd | 60 | void start(); |
Bethory | 0:6ad07c9019fd | 61 | |
Bethory | 0:6ad07c9019fd | 62 | /** Stop the timer |
Bethory | 0:6ad07c9019fd | 63 | */ |
Bethory | 0:6ad07c9019fd | 64 | void stop(); |
Bethory | 0:6ad07c9019fd | 65 | |
Bethory | 0:6ad07c9019fd | 66 | /** Reset the timer to 0. |
Bethory | 0:6ad07c9019fd | 67 | * |
Bethory | 0:6ad07c9019fd | 68 | * If it was already counting, it will continue |
Bethory | 0:6ad07c9019fd | 69 | */ |
Bethory | 0:6ad07c9019fd | 70 | void reset(); |
Bethory | 0:6ad07c9019fd | 71 | |
Bethory | 0:6ad07c9019fd | 72 | /** Get the time passed in seconds |
Bethory | 0:6ad07c9019fd | 73 | * |
Bethory | 0:6ad07c9019fd | 74 | * @returns Time passed in seconds |
Bethory | 0:6ad07c9019fd | 75 | */ |
Bethory | 0:6ad07c9019fd | 76 | float read(); |
Bethory | 0:6ad07c9019fd | 77 | |
Bethory | 0:6ad07c9019fd | 78 | /** Get the time passed in milli-seconds |
Bethory | 0:6ad07c9019fd | 79 | * |
Bethory | 0:6ad07c9019fd | 80 | * @returns Time passed in milli seconds |
Bethory | 0:6ad07c9019fd | 81 | */ |
Bethory | 0:6ad07c9019fd | 82 | int read_ms(); |
Bethory | 0:6ad07c9019fd | 83 | |
Bethory | 0:6ad07c9019fd | 84 | /** Get the time passed in micro-seconds |
Bethory | 0:6ad07c9019fd | 85 | * |
Bethory | 0:6ad07c9019fd | 86 | * @returns Time passed in micro seconds |
Bethory | 0:6ad07c9019fd | 87 | */ |
Bethory | 0:6ad07c9019fd | 88 | int read_us(); |
Bethory | 0:6ad07c9019fd | 89 | |
Bethory | 0:6ad07c9019fd | 90 | /** An operator shorthand for read() |
Bethory | 0:6ad07c9019fd | 91 | */ |
Bethory | 0:6ad07c9019fd | 92 | operator float(); |
Bethory | 0:6ad07c9019fd | 93 | |
Bethory | 0:6ad07c9019fd | 94 | /** Get in a high resolution type the time passed in micro-seconds. |
Bethory | 0:6ad07c9019fd | 95 | */ |
Bethory | 0:6ad07c9019fd | 96 | us_timestamp_t read_high_resolution_us(); |
Bethory | 0:6ad07c9019fd | 97 | |
Bethory | 0:6ad07c9019fd | 98 | protected: |
Bethory | 0:6ad07c9019fd | 99 | us_timestamp_t slicetime(); |
Bethory | 0:6ad07c9019fd | 100 | int _running; // whether the timer is running |
Bethory | 0:6ad07c9019fd | 101 | us_timestamp_t _start; // the start time of the latest slice |
Bethory | 0:6ad07c9019fd | 102 | us_timestamp_t _time; // any accumulated time from previous slices |
Bethory | 0:6ad07c9019fd | 103 | const ticker_data_t *_ticker_data; |
Bethory | 0:6ad07c9019fd | 104 | bool _lock_deepsleep; // flag which indicates if deep-sleep should be disabled |
Bethory | 0:6ad07c9019fd | 105 | }; |
Bethory | 0:6ad07c9019fd | 106 | |
Bethory | 0:6ad07c9019fd | 107 | } // namespace mbed |
Bethory | 0:6ad07c9019fd | 108 | |
Bethory | 0:6ad07c9019fd | 109 | #endif |