Fork of the official mbed C/C++ SDK provides the software platform and libraries to build your applications. The fork has the documentation converted to Doxygen format

Dependents:   NervousPuppySprintOne NervousPuppySprint2602 Robot WarehouseBot1 ... more

Fork of mbed by mbed official

Committer:
screamer
Date:
Wed Oct 24 10:44:49 2012 +0000
Revision:
43:aff670d0d510
Parent:
27:7110ebee3484
Conversion of the classes documentation to Doxygen format

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rolf.meyer@arm.com 11:1c1ebd0324fa 1 /* mbed Microcontroller Library - Timer
rolf.meyer@arm.com 11:1c1ebd0324fa 2 * Copyright (c) 2007-2009 ARM Limited. All rights reserved.
rolf.meyer@arm.com 11:1c1ebd0324fa 3 */
rolf.meyer@arm.com 11:1c1ebd0324fa 4
rolf.meyer@arm.com 11:1c1ebd0324fa 5 #ifndef MBED_TIMER_H
rolf.meyer@arm.com 11:1c1ebd0324fa 6 #define MBED_TIMER_H
rolf.meyer@arm.com 11:1c1ebd0324fa 7
rolf.meyer@arm.com 11:1c1ebd0324fa 8 #include "platform.h"
rolf.meyer@arm.com 11:1c1ebd0324fa 9 #include "PinNames.h"
rolf.meyer@arm.com 11:1c1ebd0324fa 10 #include "PeripheralNames.h"
rolf.meyer@arm.com 11:1c1ebd0324fa 11 #include "Base.h"
rolf.meyer@arm.com 11:1c1ebd0324fa 12
rolf.meyer@arm.com 11:1c1ebd0324fa 13 namespace mbed {
rolf.meyer@arm.com 11:1c1ebd0324fa 14
screamer 43:aff670d0d510 15 /** A general purpose timer
rolf.meyer@arm.com 11:1c1ebd0324fa 16 *
rolf.meyer@arm.com 11:1c1ebd0324fa 17 * Example:
screamer 43:aff670d0d510 18 * @code
screamer 43:aff670d0d510 19 * // Count the time to toggle a LED
screamer 43:aff670d0d510 20 *
screamer 43:aff670d0d510 21 * #include "mbed.h"
screamer 43:aff670d0d510 22 *
screamer 43:aff670d0d510 23 * Timer timer;
screamer 43:aff670d0d510 24 * DigitalOut led(LED1);
screamer 43:aff670d0d510 25 * int begin, end;
screamer 43:aff670d0d510 26 *
screamer 43:aff670d0d510 27 * int main() {
screamer 43:aff670d0d510 28 * timer.start();
screamer 43:aff670d0d510 29 * begin = timer.read_us();
screamer 43:aff670d0d510 30 * led = !led;
screamer 43:aff670d0d510 31 * end = timer.read_us();
screamer 43:aff670d0d510 32 * printf("Toggle the led takes %d us", end - begin);
screamer 43:aff670d0d510 33 * }
screamer 43:aff670d0d510 34 * @endcode
rolf.meyer@arm.com 11:1c1ebd0324fa 35 */
rolf.meyer@arm.com 11:1c1ebd0324fa 36 class Timer : public Base {
rolf.meyer@arm.com 11:1c1ebd0324fa 37
rolf.meyer@arm.com 11:1c1ebd0324fa 38 public:
rolf.meyer@arm.com 11:1c1ebd0324fa 39
rolf.meyer@arm.com 11:1c1ebd0324fa 40 Timer(const char *name = NULL);
rolf.meyer@arm.com 11:1c1ebd0324fa 41
screamer 43:aff670d0d510 42 /** Start the timer
rolf.meyer@arm.com 11:1c1ebd0324fa 43 */
rolf.meyer@arm.com 11:1c1ebd0324fa 44 void start();
rolf.meyer@arm.com 11:1c1ebd0324fa 45
screamer 43:aff670d0d510 46 /** Stop the timer
rolf.meyer@arm.com 11:1c1ebd0324fa 47 */
rolf.meyer@arm.com 11:1c1ebd0324fa 48 void stop();
rolf.meyer@arm.com 11:1c1ebd0324fa 49
screamer 43:aff670d0d510 50 /** Reset the timer to 0.
rolf.meyer@arm.com 11:1c1ebd0324fa 51 *
rolf.meyer@arm.com 11:1c1ebd0324fa 52 * If it was already counting, it will continue
rolf.meyer@arm.com 11:1c1ebd0324fa 53 */
rolf.meyer@arm.com 11:1c1ebd0324fa 54 void reset();
rolf.meyer@arm.com 11:1c1ebd0324fa 55
screamer 43:aff670d0d510 56 /** Get the time passed in seconds
rolf.meyer@arm.com 11:1c1ebd0324fa 57 */
rolf.meyer@arm.com 11:1c1ebd0324fa 58 float read();
rolf.meyer@arm.com 11:1c1ebd0324fa 59
screamer 43:aff670d0d510 60 /** Get the time passed in mili-seconds
rolf.meyer@arm.com 11:1c1ebd0324fa 61 */
rolf.meyer@arm.com 11:1c1ebd0324fa 62 int read_ms();
rolf.meyer@arm.com 11:1c1ebd0324fa 63
screamer 43:aff670d0d510 64 /** Get the time passed in micro-seconds
rolf.meyer@arm.com 11:1c1ebd0324fa 65 */
rolf.meyer@arm.com 11:1c1ebd0324fa 66 int read_us();
rolf.meyer@arm.com 11:1c1ebd0324fa 67
rolf.meyer@arm.com 11:1c1ebd0324fa 68 #ifdef MBED_OPERATORS
rolf.meyer@arm.com 11:1c1ebd0324fa 69 operator float();
rolf.meyer@arm.com 11:1c1ebd0324fa 70 #endif
rolf.meyer@arm.com 11:1c1ebd0324fa 71
rolf.meyer@arm.com 11:1c1ebd0324fa 72 #ifdef MBED_RPC
rolf.meyer@arm.com 11:1c1ebd0324fa 73 virtual const struct rpc_method *get_rpc_methods();
rolf.meyer@arm.com 11:1c1ebd0324fa 74 static struct rpc_class *get_rpc_class();
rolf.meyer@arm.com 11:1c1ebd0324fa 75 #endif
rolf.meyer@arm.com 11:1c1ebd0324fa 76
rolf.meyer@arm.com 11:1c1ebd0324fa 77 protected:
rolf.meyer@arm.com 11:1c1ebd0324fa 78
rolf.meyer@arm.com 11:1c1ebd0324fa 79 int slicetime();
rolf.meyer@arm.com 11:1c1ebd0324fa 80 int _running; // whether the timer is running
rolf.meyer@arm.com 11:1c1ebd0324fa 81 unsigned int _start; // the start time of the latest slice
rolf.meyer@arm.com 11:1c1ebd0324fa 82 int _time; // any accumulated time from previous slices
rolf.meyer@arm.com 11:1c1ebd0324fa 83
rolf.meyer@arm.com 11:1c1ebd0324fa 84 };
rolf.meyer@arm.com 11:1c1ebd0324fa 85
rolf.meyer@arm.com 11:1c1ebd0324fa 86 } // namespace mbed
rolf.meyer@arm.com 11:1c1ebd0324fa 87
rolf.meyer@arm.com 11:1c1ebd0324fa 88 #endif
rolf.meyer@arm.com 11:1c1ebd0324fa 89