Class similar to InterruptIn which allows the LPC1114 to wake from deepsleep. (For other targets you can use InterruptIn).
Dependents: WakeUp WakeUp WakeUp WakeUp ... more
WakeInterruptIn.h@0:d726461bd0af, 2014-07-26 (annotated)
- Committer:
- Sissors
- Date:
- Sat Jul 26 15:02:43 2014 +0000
- Revision:
- 0:d726461bd0af
- Child:
- 1:128f3fe79240
v1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Sissors | 0:d726461bd0af | 1 | /* |
Sissors | 0:d726461bd0af | 2 | Most mbed targets can be woken up from deepsleep by regular InterruptIn. |
Sissors | 0:d726461bd0af | 3 | On the LPC1114 this has to be done by different interrupts. This |
Sissors | 0:d726461bd0af | 4 | simple library helps with that |
Sissors | 0:d726461bd0af | 5 | */ |
Sissors | 0:d726461bd0af | 6 | |
Sissors | 0:d726461bd0af | 7 | #include "mbed.h" |
Sissors | 0:d726461bd0af | 8 | #define NUM_CHANNEL 13 |
Sissors | 0:d726461bd0af | 9 | |
Sissors | 0:d726461bd0af | 10 | /** Class to wake LPC1114 from deepsleep |
Sissors | 0:d726461bd0af | 11 | * |
Sissors | 0:d726461bd0af | 12 | * Use like regular InterruptIn, it works not only |
Sissors | 0:d726461bd0af | 13 | * to wake up from sleep but also just like InterruptIn. |
Sissors | 0:d726461bd0af | 14 | * Only you can NOT attach both rising and falling edge interrupts. |
Sissors | 0:d726461bd0af | 15 | */ |
Sissors | 0:d726461bd0af | 16 | class WakeInterruptIn : DigitalIn { |
Sissors | 0:d726461bd0af | 17 | public: |
Sissors | 0:d726461bd0af | 18 | |
Sissors | 0:d726461bd0af | 19 | /** Constructor |
Sissors | 0:d726461bd0af | 20 | * |
Sissors | 0:d726461bd0af | 21 | * Pins which are allowed are all pins from Port 0 and P1_0 |
Sissors | 0:d726461bd0af | 22 | * |
Sissors | 0:d726461bd0af | 23 | * @param pin Pin to use as WakeInterruptIn pin |
Sissors | 0:d726461bd0af | 24 | */ |
Sissors | 0:d726461bd0af | 25 | WakeInterruptIn(PinName pin); |
Sissors | 0:d726461bd0af | 26 | |
Sissors | 0:d726461bd0af | 27 | ~WakeInterruptIn() { |
Sissors | 0:d726461bd0af | 28 | disable(); |
Sissors | 0:d726461bd0af | 29 | objects[channel] = NULL; |
Sissors | 0:d726461bd0af | 30 | } |
Sissors | 0:d726461bd0af | 31 | |
Sissors | 0:d726461bd0af | 32 | /* Attach rising edge interrupt |
Sissors | 0:d726461bd0af | 33 | * |
Sissors | 0:d726461bd0af | 34 | * Attaching a member function can be done the regular way too |
Sissors | 0:d726461bd0af | 35 | * |
Sissors | 0:d726461bd0af | 36 | * @argument fptr Pointer to function to call, NULL to disable interrupt |
Sissors | 0:d726461bd0af | 37 | */ |
Sissors | 0:d726461bd0af | 38 | void rise(void (*fptr)(void)) { |
Sissors | 0:d726461bd0af | 39 | fpointer.attach(fptr); |
Sissors | 0:d726461bd0af | 40 | LPC_SYSCON->STARTAPRP0 |= (1 << channel); |
Sissors | 0:d726461bd0af | 41 | if (fptr == NULL) |
Sissors | 0:d726461bd0af | 42 | disable(); |
Sissors | 0:d726461bd0af | 43 | else |
Sissors | 0:d726461bd0af | 44 | enable(); |
Sissors | 0:d726461bd0af | 45 | } |
Sissors | 0:d726461bd0af | 46 | template<typename T> |
Sissors | 0:d726461bd0af | 47 | void rise(T* tptr, void (T::*mptr)(void)) { |
Sissors | 0:d726461bd0af | 48 | fpointer.attach(tptr, mptr); |
Sissors | 0:d726461bd0af | 49 | LPC_SYSCON->STARTAPRP0 |= (1 << channel); |
Sissors | 0:d726461bd0af | 50 | if (fptr == NULL) |
Sissors | 0:d726461bd0af | 51 | disable(); |
Sissors | 0:d726461bd0af | 52 | else |
Sissors | 0:d726461bd0af | 53 | enable(); |
Sissors | 0:d726461bd0af | 54 | } |
Sissors | 0:d726461bd0af | 55 | |
Sissors | 0:d726461bd0af | 56 | /* Attach falling edge interrupt |
Sissors | 0:d726461bd0af | 57 | * |
Sissors | 0:d726461bd0af | 58 | * Attaching a member function can be done the regular way too |
Sissors | 0:d726461bd0af | 59 | * |
Sissors | 0:d726461bd0af | 60 | * @argument fptr Pointer to function to call, NULL to disable interrupt |
Sissors | 0:d726461bd0af | 61 | */ |
Sissors | 0:d726461bd0af | 62 | void fall(void (*fptr)(void)) { |
Sissors | 0:d726461bd0af | 63 | fpointer.attach(fptr); |
Sissors | 0:d726461bd0af | 64 | LPC_SYSCON->STARTAPRP0 &= ~(1 << channel); |
Sissors | 0:d726461bd0af | 65 | if (fptr == NULL) |
Sissors | 0:d726461bd0af | 66 | disable(); |
Sissors | 0:d726461bd0af | 67 | else |
Sissors | 0:d726461bd0af | 68 | enable(); |
Sissors | 0:d726461bd0af | 69 | } |
Sissors | 0:d726461bd0af | 70 | template<typename T> |
Sissors | 0:d726461bd0af | 71 | void fall(T* tptr, void (T::*mptr)(void)) { |
Sissors | 0:d726461bd0af | 72 | fpointer.attach(tptr, mptr); |
Sissors | 0:d726461bd0af | 73 | LPC_SYSCON->STARTAPRP0 &= ~(1 << channel); |
Sissors | 0:d726461bd0af | 74 | if (fptr == NULL) |
Sissors | 0:d726461bd0af | 75 | disable(); |
Sissors | 0:d726461bd0af | 76 | else |
Sissors | 0:d726461bd0af | 77 | enable(); |
Sissors | 0:d726461bd0af | 78 | } |
Sissors | 0:d726461bd0af | 79 | |
Sissors | 0:d726461bd0af | 80 | |
Sissors | 0:d726461bd0af | 81 | |
Sissors | 0:d726461bd0af | 82 | private: |
Sissors | 0:d726461bd0af | 83 | uint8_t channel; |
Sissors | 0:d726461bd0af | 84 | FunctionPointer fpointer; |
Sissors | 0:d726461bd0af | 85 | |
Sissors | 0:d726461bd0af | 86 | void enable(void) { |
Sissors | 0:d726461bd0af | 87 | LPC_SYSCON->STARTERP0 |= (1 << channel); |
Sissors | 0:d726461bd0af | 88 | NVIC_EnableIRQ((IRQn_Type)channel); |
Sissors | 0:d726461bd0af | 89 | } |
Sissors | 0:d726461bd0af | 90 | |
Sissors | 0:d726461bd0af | 91 | void disable(void) { |
Sissors | 0:d726461bd0af | 92 | LPC_SYSCON->STARTERP0 &= ~(1 << channel); |
Sissors | 0:d726461bd0af | 93 | NVIC_DisableIRQ((IRQn_Type)channel); |
Sissors | 0:d726461bd0af | 94 | } |
Sissors | 0:d726461bd0af | 95 | |
Sissors | 0:d726461bd0af | 96 | void handle( void ) { |
Sissors | 0:d726461bd0af | 97 | LPC_SYSCON->STARTRSRP0CLR = 1 << channel; |
Sissors | 0:d726461bd0af | 98 | fpointer.call(); |
Sissors | 0:d726461bd0af | 99 | } |
Sissors | 0:d726461bd0af | 100 | |
Sissors | 0:d726461bd0af | 101 | static WakeInterruptIn* objects[NUM_CHANNEL]; |
Sissors | 0:d726461bd0af | 102 | static void handler0(void) { objects[0]->handle(); } |
Sissors | 0:d726461bd0af | 103 | static void handler1(void) { objects[1]->handle(); } |
Sissors | 0:d726461bd0af | 104 | static void handler2(void) { objects[2]->handle(); } |
Sissors | 0:d726461bd0af | 105 | static void handler3(void) { objects[3]->handle(); } |
Sissors | 0:d726461bd0af | 106 | static void handler4(void) { objects[4]->handle(); } |
Sissors | 0:d726461bd0af | 107 | static void handler5(void) { objects[5]->handle(); } |
Sissors | 0:d726461bd0af | 108 | static void handler6(void) { objects[6]->handle(); } |
Sissors | 0:d726461bd0af | 109 | static void handler7(void) { objects[7]->handle(); } |
Sissors | 0:d726461bd0af | 110 | static void handler8(void) { objects[8]->handle(); } |
Sissors | 0:d726461bd0af | 111 | static void handler9(void) { objects[9]->handle(); } |
Sissors | 0:d726461bd0af | 112 | static void handler10(void) { objects[10]->handle(); } |
Sissors | 0:d726461bd0af | 113 | static void handler11(void) { objects[11]->handle(); } |
Sissors | 0:d726461bd0af | 114 | static void handler12(void) { objects[12]->handle(); } |
Sissors | 0:d726461bd0af | 115 | |
Sissors | 0:d726461bd0af | 116 | }; |