ok

Dependencies:   LPC1114_WakeInterruptIn

Fork of WakeUp by Erik -

Committer:
Sissors
Date:
Sat Dec 07 11:21:15 2013 +0000
Revision:
2:648712aa15b4
Parent:
1:92f4c2b52771
Child:
8:8d9a6ac0fba8
KL25 should now play nicely with mbed

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Sissors 0:fc439458a359 1 #include "mbed.h"
Sissors 0:fc439458a359 2
Sissors 0:fc439458a359 3 /**
Sissors 2:648712aa15b4 4 * Class to make use of the LPC81x's and KL25Zs 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 2:648712aa15b4 7 * This is an ultra low-power timer that can run from an always-on 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 2:648712aa15b4 11 * Example program for the LPC812: http://mbed.org/users/Sissors/code/LPC812_Sleep_HelloWorld/
Sissors 0:fc439458a359 12 */
Sissors 0:fc439458a359 13 class WakeUp
Sissors 0:fc439458a359 14 {
Sissors 0:fc439458a359 15 public:
Sissors 0:fc439458a359 16 /**
Sissors 0:fc439458a359 17 * Set the timeout
Sissors 0:fc439458a359 18 *
Sissors 0:fc439458a359 19 * @param s - required time in seconds
Sissors 0:fc439458a359 20 */
Sissors 0:fc439458a359 21 static void set(uint32_t s) {
Sissors 0:fc439458a359 22 set_ms(1000 * s);
Sissors 0:fc439458a359 23 }
Sissors 0:fc439458a359 24
Sissors 0:fc439458a359 25 /**
Sissors 0:fc439458a359 26 * Set the timeout
Sissors 0:fc439458a359 27 *
Sissors 0:fc439458a359 28 * @param ms - required time in milliseconds
Sissors 0:fc439458a359 29 */
Sissors 0:fc439458a359 30 static void set_ms(uint32_t ms);
Sissors 0:fc439458a359 31
Sissors 0:fc439458a359 32 /**
Sissors 0:fc439458a359 33 * Attach a function to be called after timeout
Sissors 0:fc439458a359 34 *
Sissors 0:fc439458a359 35 * This is optional, if you just want to wake up you
Sissors 0:fc439458a359 36 * do not need to attach a function.
Sissors 0:fc439458a359 37 *
Sissors 0:fc439458a359 38 * Also supports normal way to attach member functions
Sissors 0:fc439458a359 39 * (not documented for simplicity)
Sissors 0:fc439458a359 40 *
Sissors 0:fc439458a359 41 * @param *function - function to call
Sissors 0:fc439458a359 42 */
Sissors 0:fc439458a359 43 static void attach(void (*function)(void)) {
Sissors 0:fc439458a359 44 callback.attach(function);
Sissors 0:fc439458a359 45 }
Sissors 0:fc439458a359 46
Sissors 0:fc439458a359 47 template<typename T>
Sissors 0:fc439458a359 48 static void attach(T *object, void (T::*member)(void)) {
Sissors 0:fc439458a359 49 callback.attach(object, member);
Sissors 0:fc439458a359 50 }
Sissors 0:fc439458a359 51
Sissors 0:fc439458a359 52 /**
Sissors 0:fc439458a359 53 * Calibrate the timer
Sissors 0:fc439458a359 54 *
Sissors 1:92f4c2b52771 55 * The LPC812's low-power timer has a very bad accuracy: +/- 45%.
Sissors 0:fc439458a359 56 * This function calibrates it for 100ms against the main clock.
Sissors 1:92f4c2b52771 57 * So you get almost that accuracy by calling this function.
Sissors 1:92f4c2b52771 58 *
Sissors 1:92f4c2b52771 59 * For the KL25 it is less of a problem, with an accuracy of +/- 10%
Sissors 1:92f4c2b52771 60 * Still it can be useful for your application
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 };