Modified WakeUp program to run on STM32L152RE

Dependencies:   mbed LPC1114_WakeInterruptIn

Fork of WakeUp by Erik -

Committer:
Sissors
Date:
Thu Dec 05 21:32:11 2013 +0000
Revision:
1:92f4c2b52771
Parent:
0:fc439458a359
Child:
2:648712aa15b4
Added KL25, doesn't play nice with mbed yet

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 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 1:92f4c2b52771 58 * The LPC812's low-power timer has a very bad accuracy: +/- 45%.
Sissors 0:fc439458a359 59 * This function calibrates it for 100ms against the main clock.
Sissors 1:92f4c2b52771 60 * So you get almost that accuracy by calling this function.
Sissors 1:92f4c2b52771 61 *
Sissors 1:92f4c2b52771 62 * For the KL25 it is less of a problem, with an accuracy of +/- 10%
Sissors 1:92f4c2b52771 63 * Still it can be useful for your application
Sissors 0:fc439458a359 64 *
Sissors 0:fc439458a359 65 * Warning: Blocks for 100ms!
Sissors 0:fc439458a359 66 */
Sissors 0:fc439458a359 67 static void calibrate(void);
Sissors 0:fc439458a359 68
Sissors 0:fc439458a359 69
Sissors 0:fc439458a359 70 private:
Sissors 0:fc439458a359 71 static FunctionPointer callback;
Sissors 0:fc439458a359 72 static void irq_handler(void);
Sissors 0:fc439458a359 73 static float cycles_per_ms;
Sissors 0:fc439458a359 74 };