mbed libraries for KL25Z

Dependents:   FRDM_RGBLED

Committer:
emilmont
Date:
Fri Oct 05 09:16:41 2012 +0000
Revision:
0:8024c367e29f
Child:
2:e9a661555b58
First release of the mbed libraries for KL25Z

Who changed what in which revision?

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