Mouse code for the MacroRat

Dependencies:   ITG3200 QEI

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Timer.h Source File

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 
00026 /** A general purpose timer
00027  *
00028  * @Note Synchronization level: Interrupt safe
00029  *
00030  * Example:
00031  * @code
00032  * // Count the time to toggle a LED
00033  *
00034  * #include "mbed.h"
00035  *
00036  * Timer timer;
00037  * DigitalOut led(LED1);
00038  * int begin, end;
00039  *
00040  * int main() {
00041  *     timer.start();
00042  *     begin = timer.read_us();
00043  *     led = !led;
00044  *     end = timer.read_us();
00045  *     printf("Toggle the led takes %d us", end - begin);
00046  * }
00047  * @endcode
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 protected:
00086     int slicetime();
00087     int _running;          // whether the timer is running
00088     unsigned int _start;   // the start time of the latest slice
00089     int _time;             // any accumulated time from previous slices
00090     const ticker_data_t *_ticker_data;
00091 };
00092 
00093 } // namespace mbed
00094 
00095 #endif
00096 
00097 /** @}*/