Skip to content

Instantly share code, notes, and snippets.

@akimasa
Created December 31, 2015 14:34
Show Gist options
  • Save akimasa/9313fdb926cde27bbabf to your computer and use it in GitHub Desktop.
Save akimasa/9313fdb926cde27bbabf to your computer and use it in GitHub Desktop.
/*
===============================================================================
Name : TestSleep.c
Author : $(author)
Version :
Copyright : $(copyright)
Description : main definition
===============================================================================
*/
#ifdef __USE_CMSIS
#include "LPC8xx.h"
#endif
#include <cr_section_macros.h>
// TODO: insert other include files here
#include "lpc8xx_gpio.h"
#include "lpc8xx_mrt.h"
#include "lpc8xx_pmu.h"
#include "lpc8xx_nmi.h"
#include "lpc8xx_wkt.h"
// TODO: insert other definitions and declarations here
void SwitchMatrix_Init()
{
/* Enable SWM clock */
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<7);
/* Pin Assign 8 bit Configuration */
/* none */
/* Pin Assign 1 bit Configuration */
LPC_SWM->PINENABLE0 = 0xffffffffUL;
//PIO0_0 -> PIO0_5
}
void deepsleep(uint32_t count){
/* alarm/wake timer as wakeup source */
LPC_SYSCON->STARTERP1 = 0x1<<15;
/* DISABLE gpio as wakeup source (PINT7)*/
LPC_SYSCON->STARTERP0 = 0x0;
LPC_PMU->PCON = 0x1;
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 = count;
NVIC_EnableIRQ(WKT_IRQn);
// Use the ARM WFI instruction.
__WFI();
}
/******************************************************************************
** Function name: WKT_IRQHandler
**
** Descriptions: alarm/wake timer interrupt handler
**
** parameters: None
** Returned value: None
**
******************************************************************************/
void WKT_IRQHandler(void)
{
if ( LPC_WKT->CTRL & WKT_FLAG )
{
LPC_WKT->CTRL |= WKT_FLAG; /* clear interrupt flag */
}
return;
}
/******************************************************************************
** Function name: halt_wkt
**
** Descriptions: Halt timer
**
** parameters: None
** Returned value: None
**
******************************************************************************/
void halt_wkt(void)
{
LPC_WKT->CTRL |= WKT_CLR;
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment