mbed libraries for KL25Z

Dependents:   FRDM_RGBLED

Committer:
emilmont
Date:
Wed Oct 10 14:14:12 2012 +0000
Revision:
2:e9a661555b58
Parent:
0:8024c367e29f
Child:
8:c14af7958ef5
Add PWM and I2C implementation;

Who changed what in which revision?

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