Created
December 31, 2015 15:05
-
-
Save akimasa/655b6fa8a0e43c04caee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main(void) { | |
SwitchMatrix_Init(); | |
GPIOInit(); | |
GPIOSetDir( 0, 0, 1 ); | |
GPIOSetDir( 0, 2, 1 ); | |
if(LPC_PMU->PCON & (1 << 11)) { | |
LPC_PMU->PCON |= (0x1<<11); | |
LPC_WKT->CTRL |= WKT_CLR; | |
NVIC_ClearPendingIRQ(WKT_IRQn); | |
NVIC_DisableIRQ(WKT_IRQn); | |
} | |
while(1){ | |
GPIOSetBitValue(0, 0, 0); | |
GPIOSetBitValue(0, 2, 1); | |
/* alarm/wake timer as wakeup source */ | |
LPC_SYSCON->STARTERP1 = 0x1<<15; | |
/* gpio as wakeup source (PINT7)*/ | |
LPC_SYSCON->STARTERP0 = 0x1<<7; | |
GPIOSetPinInterrupt( CHANNEL7, PORT0, 4, 1, 0 ); | |
LPC_PMU->PCON = 0x1;//deepsleep 0x1 powerdown 0x2 | |
LPC_SYSCON->PDSLEEPCFG &= ~(WDT_OSC_PD | BOD_PD); | |
LPC_SYSCON->PDAWAKECFG = LPC_SYSCON->PDRUNCFG; | |
SCB->SCR |= NVIC_LP_SLEEPDEEP; | |
LPC_PMU->DPDCTRL |= (0x1 << 2); | |
// Self wake-up timer (WKT)の有効化 | |
// UM10601 13.3 Basic configuration | |
LPC_SYSCON->SYSAHBCLKCTRL |= (0x1 << 9); | |
LPC_SYSCON->PRESETCTRL &= ~(0x1 << 9); | |
LPC_SYSCON->PRESETCTRL |= (0x1 << 9); | |
//Use 10khz low power clock | |
LPC_WKT->CTRL |= WKT_CLKSEL; | |
LPC_WKT->COUNT = 10*1500; | |
NVIC_EnableIRQ(WKT_IRQn); | |
// Use the ARM WFI instruction. | |
__WFI(); | |
GPIOSetBitValue(0, 0, 1); | |
GPIOSetBitValue(0, 2, 1); | |
deepsleep(500*10); | |
GPIOSetBitValue( 0, 0, 1 ); | |
GPIOSetBitValue( 0, 2, 0 ); | |
deepsleep(100*10); | |
GPIOSetBitValue(0, 0, 1); | |
GPIOSetBitValue(0, 2, 1); | |
// Deep power-downの処理 | |
// UM10601 5.6.3 Deep power-down control register | |
LPC_PMU->DPDCTRL |= (1 << 0) | (1 << 2) | (1 << 3); // Hysteresis for WAKEUP pin enabled | |
// UM10601 5.6.1 Power control register | |
LPC_PMU->PCON &= ~(1 << 3); // NODPD = 0 | |
LPC_PMU->PCON |= 0x3; // PM = 0x3 | |
// UM10601 5.3.1.1 System control register | |
SCB->SCR |= (1 << 2); // SLEEPDEEP = 1 | |
/// Self wake-up timer (WKT)設定 | |
// 13.6.1 Control register | |
LPC_WKT->CTRL |= (1 << 0); // CLKSEL = 1 10KHzのlow power clockを利用 | |
LPC_WKT->COUNT = 30000; // 10KHzなので、3秒に設定 | |
// Use the ARM WFI instruction. | |
__WFI(); | |
} | |
return 0 ; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment