Modified WakeUp program to run on STM32L152RE
Dependencies: mbed LPC1114_WakeInterruptIn
Fork of WakeUp by
WakeUp.h@0:fc439458a359, 2013-11-23 (annotated)
- Committer:
- Sissors
- Date:
- Sat Nov 23 11:35:14 2013 +0000
- Revision:
- 0:fc439458a359
- Child:
- 1:92f4c2b52771
v1.0
;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Sissors | 0:fc439458a359 | 1 | #include "mbed.h" |
Sissors | 0:fc439458a359 | 2 | |
Sissors | 0:fc439458a359 | 3 | /** |
Sissors | 0:fc439458a359 | 4 | * Class to make use of the LPC81x's low power wake-up timer. |
Sissors | 0:fc439458a359 | 5 | * |
Sissors | 0:fc439458a359 | 6 | * One of the methods of waking up from deepsleep/powerdown is using the wake-up timer. |
Sissors | 0:fc439458a359 | 7 | * This is an ultra low-power timer that can run from an always-on 10kHz clock source. |
Sissors | 0:fc439458a359 | 8 | * So while normal timers are shut-down, this one still runs, consuming only roughly 1uA. |
Sissors | 0:fc439458a359 | 9 | * If the timer does not need to run everything is shut down again by the library. |
Sissors | 0:fc439458a359 | 10 | * |
Sissors | 0:fc439458a359 | 11 | * This class can also be used as general purpose interrupt timer, although just using |
Sissors | 0:fc439458a359 | 12 | * the default Timer library is probably a better idea for that. |
Sissors | 0:fc439458a359 | 13 | * |
Sissors | 0:fc439458a359 | 14 | * Example program: http://mbed.org/users/Sissors/code/LPC812_Sleep_HelloWorld/ |
Sissors | 0:fc439458a359 | 15 | */ |
Sissors | 0:fc439458a359 | 16 | class WakeUp |
Sissors | 0:fc439458a359 | 17 | { |
Sissors | 0:fc439458a359 | 18 | public: |
Sissors | 0:fc439458a359 | 19 | /** |
Sissors | 0:fc439458a359 | 20 | * Set the timeout |
Sissors | 0:fc439458a359 | 21 | * |
Sissors | 0:fc439458a359 | 22 | * @param s - required time in seconds |
Sissors | 0:fc439458a359 | 23 | */ |
Sissors | 0:fc439458a359 | 24 | static void set(uint32_t s) { |
Sissors | 0:fc439458a359 | 25 | set_ms(1000 * s); |
Sissors | 0:fc439458a359 | 26 | } |
Sissors | 0:fc439458a359 | 27 | |
Sissors | 0:fc439458a359 | 28 | /** |
Sissors | 0:fc439458a359 | 29 | * Set the timeout |
Sissors | 0:fc439458a359 | 30 | * |
Sissors | 0:fc439458a359 | 31 | * @param ms - required time in milliseconds |
Sissors | 0:fc439458a359 | 32 | */ |
Sissors | 0:fc439458a359 | 33 | static void set_ms(uint32_t ms); |
Sissors | 0:fc439458a359 | 34 | |
Sissors | 0:fc439458a359 | 35 | /** |
Sissors | 0:fc439458a359 | 36 | * Attach a function to be called after timeout |
Sissors | 0:fc439458a359 | 37 | * |
Sissors | 0:fc439458a359 | 38 | * This is optional, if you just want to wake up you |
Sissors | 0:fc439458a359 | 39 | * do not need to attach a function. |
Sissors | 0:fc439458a359 | 40 | * |
Sissors | 0:fc439458a359 | 41 | * Also supports normal way to attach member functions |
Sissors | 0:fc439458a359 | 42 | * (not documented for simplicity) |
Sissors | 0:fc439458a359 | 43 | * |
Sissors | 0:fc439458a359 | 44 | * @param *function - function to call |
Sissors | 0:fc439458a359 | 45 | */ |
Sissors | 0:fc439458a359 | 46 | static void attach(void (*function)(void)) { |
Sissors | 0:fc439458a359 | 47 | callback.attach(function); |
Sissors | 0:fc439458a359 | 48 | } |
Sissors | 0:fc439458a359 | 49 | |
Sissors | 0:fc439458a359 | 50 | template<typename T> |
Sissors | 0:fc439458a359 | 51 | static void attach(T *object, void (T::*member)(void)) { |
Sissors | 0:fc439458a359 | 52 | callback.attach(object, member); |
Sissors | 0:fc439458a359 | 53 | } |
Sissors | 0:fc439458a359 | 54 | |
Sissors | 0:fc439458a359 | 55 | /** |
Sissors | 0:fc439458a359 | 56 | * Calibrate the timer |
Sissors | 0:fc439458a359 | 57 | * |
Sissors | 0:fc439458a359 | 58 | * The 10kHz timer has a very bad accuracy: +/- 45%. |
Sissors | 0:fc439458a359 | 59 | * This function calibrates it for 100ms against the main clock. |
Sissors | 0:fc439458a359 | 60 | * So you get almost that accuracy by calling this function. |
Sissors | 0:fc439458a359 | 61 | * |
Sissors | 0:fc439458a359 | 62 | * Warning: Blocks for 100ms! |
Sissors | 0:fc439458a359 | 63 | */ |
Sissors | 0:fc439458a359 | 64 | static void calibrate(void); |
Sissors | 0:fc439458a359 | 65 | |
Sissors | 0:fc439458a359 | 66 | |
Sissors | 0:fc439458a359 | 67 | private: |
Sissors | 0:fc439458a359 | 68 | static FunctionPointer callback; |
Sissors | 0:fc439458a359 | 69 | static void irq_handler(void); |
Sissors | 0:fc439458a359 | 70 | static float cycles_per_ms; |
Sissors | 0:fc439458a359 | 71 | }; |