mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Committer:
AnnaBridge
Date:
Wed Feb 20 22:31:08 2019 +0000
Revision:
189:f392fc9709a3
Parent:
188:bcfe06ba3d64
mbed library release version 165

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