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