Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: LPC1114_WakeInterruptIn
Fork of WakeUp by
WakeUp.h
- Committer:
- Sissors
- Date:
- 2013-12-05
- Revision:
- 1:92f4c2b52771
- Parent:
- 0:fc439458a359
- Child:
- 2:648712aa15b4
File content as of revision 1:92f4c2b52771:
#include "mbed.h"
/**
* Class to make use of the LPC81x's low power wake-up timer.
*
* One of the methods of waking up from deepsleep/powerdown is using the wake-up timer.
* This is an ultra low-power timer that can run from an always-on 10kHz clock source.
* So while normal timers are shut-down, this one still runs, consuming only roughly 1uA.
* If the timer does not need to run everything is shut down again by the library.
*
* This class can also be used as general purpose interrupt timer, although just using
* the default Timer library is probably a better idea for that.
*
* Example program: http://mbed.org/users/Sissors/code/LPC812_Sleep_HelloWorld/
*/
class WakeUp
{
public:
/**
* Set the timeout
*
* @param s - required time in seconds
*/
static void set(uint32_t s) {
set_ms(1000 * s);
}
/**
* Set the timeout
*
* @param ms - required time in milliseconds
*/
static void set_ms(uint32_t ms);
/**
* Attach a function to be called after timeout
*
* This is optional, if you just want to wake up you
* do not need to attach a function.
*
* Also supports normal way to attach member functions
* (not documented for simplicity)
*
* @param *function - function to call
*/
static void attach(void (*function)(void)) {
callback.attach(function);
}
template<typename T>
static void attach(T *object, void (T::*member)(void)) {
callback.attach(object, member);
}
/**
* Calibrate the timer
*
* The LPC812's low-power timer has a very bad accuracy: +/- 45%.
* This function calibrates it for 100ms against the main clock.
* So you get almost that accuracy by calling this function.
*
* For the KL25 it is less of a problem, with an accuracy of +/- 10%
* Still it can be useful for your application
*
* Warning: Blocks for 100ms!
*/
static void calibrate(void);
private:
static FunctionPointer callback;
static void irq_handler(void);
static float cycles_per_ms;
};
