This is my quadcopter prototype software, still in development!

Committer:
Anaesthetix
Date:
Wed Jan 30 13:14:44 2013 +0000
Revision:
0:978110f7f027
My quadcopter prototype software, still in development.

Who changed what in which revision?

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