Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of gr-peach-opencv-project-sd-card by
Timer.h
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #ifndef MBED_TIMER_H 00017 #define MBED_TIMER_H 00018 00019 #include "platform/platform.h" 00020 #include "hal/ticker_api.h" 00021 00022 namespace mbed { 00023 /** \addtogroup drivers */ 00024 00025 /** A general purpose timer 00026 * 00027 * @note Synchronization level: Interrupt safe 00028 * 00029 * Example: 00030 * @code 00031 * // Count the time to toggle a LED 00032 * 00033 * #include "mbed.h" 00034 * 00035 * Timer timer; 00036 * DigitalOut led(LED1); 00037 * int begin, end; 00038 * 00039 * int main() { 00040 * timer.start(); 00041 * begin = timer.read_us(); 00042 * led = !led; 00043 * end = timer.read_us(); 00044 * printf("Toggle the led takes %d us", end - begin); 00045 * } 00046 * @endcode 00047 * @ingroup drivers 00048 */ 00049 class Timer { 00050 00051 public: 00052 Timer(); 00053 Timer(const ticker_data_t *data); 00054 00055 /** Start the timer 00056 */ 00057 void start(); 00058 00059 /** Stop the timer 00060 */ 00061 void stop(); 00062 00063 /** Reset the timer to 0. 00064 * 00065 * If it was already counting, it will continue 00066 */ 00067 void reset(); 00068 00069 /** Get the time passed in seconds 00070 */ 00071 float read(); 00072 00073 /** Get the time passed in mili-seconds 00074 */ 00075 int read_ms(); 00076 00077 /** Get the time passed in micro-seconds 00078 */ 00079 int read_us(); 00080 00081 /** An operator shorthand for read() 00082 */ 00083 operator float(); 00084 00085 /** Get in a high resolution type the time passed in micro-seconds. 00086 */ 00087 us_timestamp_t read_high_resolution_us(); 00088 00089 protected: 00090 us_timestamp_t slicetime(); 00091 int _running; // whether the timer is running 00092 us_timestamp_t _start; // the start time of the latest slice 00093 us_timestamp_t _time; // any accumulated time from previous slices 00094 const ticker_data_t *_ticker_data; 00095 }; 00096 00097 } // namespace mbed 00098 00099 #endif 00100
Generated on Tue Jul 12 2022 14:47:41 by
