Skip to content

Instantly share code, notes, and snippets.

@akimasa
Last active December 31, 2015 14:39
Show Gist options
  • Save akimasa/847ebca4250dd67d6c6a to your computer and use it in GitHub Desktop.
Save akimasa/847ebca4250dd67d6c6a to your computer and use it in GitHub Desktop.
int main(void) {
SwitchMatrix_Init();
GPIOInit();
GPIOSetDir( 0, 0, 1 );
GPIOSetDir( 0, 2, 1 );
if(LPC_PMU->PCON & (1 << 11)) {
// DPDFLAG(11)が立ってるので、deep power-downからの復帰である。
// 同フラグをクリア
LPC_PMU->PCON &= ~(1 << 11);
// Needed?
NVIC_ClearPendingIRQ(WKT_IRQn);
NVIC_DisableIRQ(WKT_IRQn);
LPC_PMU->DPDCTRL = 0;
SCB->SCR = 0;
LPC_WKT->CTRL |= (1 << 1) | (1 << 2);
}
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);
// 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