Fork of original library to fix mbed 5 deprecation warnings
Dependencies: LPC1114_WakeInterruptIn
Fork of WakeUp by
WakeUp_LPC812.cpp
00001 #ifdef TARGET_LPC812 00002 00003 #include "WakeUp.h" 00004 00005 Callback<void()> WakeUp::cbk; 00006 float WakeUp::cycles_per_ms = 10.0; 00007 00008 void WakeUp::set_ms(uint32_t ms) 00009 { 00010 //Enable clock to register interface: 00011 LPC_SYSCON->SYSAHBCLKCTRL |= 1<<9; 00012 00013 //Clear the counter: 00014 LPC_WKT->CTRL |= 1<<2; 00015 if (ms != 0) { 00016 //Enable clock to register interface: 00017 LPC_SYSCON->SYSAHBCLKCTRL |= 1<<9; 00018 00019 //Set 10kHz timer as source, and just to be sure clear status bit 00020 LPC_WKT->CTRL = 3; 00021 00022 //Enable the 10kHz timer 00023 LPC_PMU->DPDCTRL |= (1<<2) | (1<<3); 00024 00025 //Set interrupts 00026 NVIC_SetVector(WKT_IRQn, (uint32_t)WakeUp::irq_handler); 00027 NVIC_EnableIRQ(WKT_IRQn); 00028 00029 //Load the timer 00030 LPC_WKT->COUNT = (uint32_t)((float)ms * cycles_per_ms); 00031 00032 } else { 00033 //Disable clock to register interface: 00034 LPC_SYSCON->SYSAHBCLKCTRL &= ~(1<<9); 00035 00036 //Disable the 10kHz timer 00037 LPC_PMU->DPDCTRL &= ~((1<<2) | (1<<3)); 00038 } 00039 } 00040 00041 void WakeUp::irq_handler(void) 00042 { 00043 //Clear status 00044 LPC_WKT->CTRL |= 2; 00045 00046 //Disable clock to register interface: 00047 LPC_SYSCON->SYSAHBCLKCTRL &= ~(1<<9); 00048 00049 //Disable the 10kHz timer 00050 LPC_PMU->DPDCTRL &= ~((1<<2) | (1<<3)); 00051 00052 if (cbk) { 00053 cbk.call(); 00054 } 00055 } 00056 00057 void WakeUp::calibrate(void) 00058 { 00059 cycles_per_ms = 10.0; 00060 set_ms(1100); 00061 wait_ms(100); 00062 00063 uint32_t prevread = LPC_WKT->COUNT; 00064 uint32_t read = LPC_WKT->COUNT; 00065 while( read != prevread) { 00066 prevread = read; 00067 read = LPC_WKT->COUNT; 00068 } 00069 00070 uint32_t ticks = 11000 - read; 00071 00072 cycles_per_ms = ticks / 100.0; 00073 set_ms(0); 00074 } 00075 00076 #endif
Generated on Tue Jul 12 2022 18:10:46 by 1.7.2