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