mbed SDK library sources
Fork of mbed-src by
Embed:
(wiki syntax)
Show/hide line numbers
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.h" 00020 00021 namespace mbed { 00022 00023 /** A general purpose timer 00024 * 00025 * Example: 00026 * @code 00027 * // Count the time to toggle a LED 00028 * 00029 * #include "mbed.h" 00030 * 00031 * Timer timer; 00032 * DigitalOut led(LED1); 00033 * int begin, end; 00034 * 00035 * int main() { 00036 * timer.start(); 00037 * begin = timer.read_us(); 00038 * led = !led; 00039 * end = timer.read_us(); 00040 * printf("Toggle the led takes %d us", end - begin); 00041 * } 00042 * @endcode 00043 */ 00044 class Timer { 00045 00046 public: 00047 Timer(); 00048 00049 /** Start the timer 00050 */ 00051 void start(); 00052 00053 /** Stop the timer 00054 */ 00055 void stop(); 00056 00057 /** Reset the timer to 0. 00058 * 00059 * If it was already counting, it will continue 00060 */ 00061 void reset(); 00062 00063 /** Get the time passed in seconds 00064 */ 00065 float read(); 00066 00067 /** Get the time passed in mili-seconds 00068 */ 00069 int read_ms(); 00070 00071 /** Get the time passed in micro-seconds 00072 */ 00073 int read_us(); 00074 00075 #ifdef MBED_OPERATORS 00076 operator float(); 00077 #endif 00078 00079 protected: 00080 int slicetime(); 00081 int _running; // whether the timer is running 00082 unsigned int _start; // the start time of the latest slice 00083 int _time; // any accumulated time from previous slices 00084 }; 00085 00086 } // namespace mbed 00087 00088 #endif
Generated on Tue Jul 12 2022 18:13:44 by 1.7.2