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.
Fork of WakeUp by
WakeUp.h
00001 #include "mbed.h" 00002 00003 /** 00004 * Class to make wake up a microcontroller from deepsleep using a low-power timer. 00005 * 00006 * @code 00007 * // Depending on the LED connections either the LED is off the 2 seconds 00008 * // the target spends in deepsleep(), and on for the other second. Or it is inverted 00009 * 00010 * #include "mbed.h" 00011 * #include "WakeUp.h" 00012 * 00013 * DigitalOut myled(LED1); 00014 * 00015 * int main() { 00016 * wait(5); 00017 * 00018 * //The low-power oscillator can be quite inaccurate on some targets 00019 * //this function calibrates it against the main clock 00020 * WakeUp::calibrate(); 00021 * 00022 * while(1) { 00023 * //Set LED to zero 00024 * myled = 0; 00025 * 00026 * //Set wakeup time for 2 seconds 00027 * WakeUp::set_ms(2000); 00028 * 00029 * //Enter deepsleep, the program won't go beyond this point until it is woken up 00030 * deepsleep(); 00031 * 00032 * //Set LED for 1 second to one 00033 * myled = 1; 00034 * wait(1); 00035 * } 00036 * } 00037 * @endcode 00038 */ 00039 class WakeUp 00040 { 00041 public: 00042 /** 00043 * Resets the internal analog-data-converter. Needs 00044 * to be called after exiting deepsleep. 00045 */ 00046 static void resetADC(); 00047 /** 00048 * Set the timeout 00049 * 00050 * @param s required time in seconds 00051 */ 00052 static void set(uint32_t s) { 00053 set_ms(1000 * s); 00054 } 00055 00056 /** 00057 * Set the timeout 00058 * 00059 * @param ms required time in milliseconds 00060 */ 00061 static void set_ms(uint32_t ms); 00062 00063 /** 00064 * Attach a function to be called after timeout 00065 * 00066 * This is optional, if you just want to wake up you 00067 * do not need to attach a function. 00068 * 00069 * Important: Many targets will run the wake-up routine 00070 * at reduced clock speed, afterwards clock speed is restored. 00071 * This means that clock speed dependent functions, such as printf 00072 * might end up distorted. 00073 * 00074 * Also supports normal way to attach member functions 00075 * (not documented for simplicity) 00076 * 00077 * @param *function function to call 00078 */ 00079 static void attach(void (*function)(void)) { 00080 callback.attach(function); 00081 } 00082 00083 template<typename T> 00084 static void attach(T *object, void (T::*member)(void)) { 00085 callback.attach(object, member); 00086 } 00087 00088 /** 00089 * Calibrate the timer 00090 * 00091 * Some of the low-power timers have very bad accuracy. 00092 * This function calibrates it against the main timer. 00093 * 00094 * Warning: Blocks for 100ms! 00095 */ 00096 static void calibrate(void); 00097 00098 00099 private: 00100 static FunctionPointer callback; 00101 static void irq_handler(void); 00102 static float cycles_per_ms; 00103 };
Generated on Tue Jul 12 2022 21:30:46 by
1.7.2
