mbed library sources. Supersedes mbed-src.

Fork of mbed-dev by mbed official

Committer:
pmcorreia
Date:
Tue Oct 09 14:42:37 2018 +0000
Revision:
187:fa51feb62426
Parent:
184:08ed48f1de7f
Updated version to work with F446RE

Who changed what in which revision?

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