/*---------------------------------------------------------------------------------------------------------*/
/* Function for System Entry to Power Down Mode */
/*---------------------------------------------------------------------------------------------------------*/
void PowerDownFunction(void)
{
/* Check if all the debug messages are finished */
UART_WAIT_TX_EMPTY(UART0);
/* Enter to Power-down mode */
CLK_PowerDown();
__ISB();
}
/* Update System Core Clock */
/* User can use SystemCoreClockUpdate() to calculate PllClock, SystemCoreClock and CycylesPerUs automatically. */
SystemCoreClockUpdate();
/*----------------------------------------------------------------------*/
/* Init I/O Multi-function */
/*----------------------------------------------------------------------*/
/* Set GPB multi-function pins for UART0 RXD and TXD */
SYS->GPB_MFPH = (SYS->GPB_MFPH & ~(SYS_GPB_MFPH_PB12MFP_Msk | SYS_GPB_MFPH_PB13MFP_Msk)) |
(SYS_GPB_MFPH_PB12MFP_UART0_RXD | SYS_GPB_MFPH_PB13MFP_UART0_TXD);
/* Configure UART0 and set UART0 baud rate */
UART_Open(UART0, 115200);
}
int main(void)
{
/* Init System, IP clock and multi-function I/O. */
SYS_Init();
/* Init UART0 for printf */
UART0_Init();
printf("\n\nCPU @ %d Hz\n", SystemCoreClock);
printf("+-------------------------------------------------------+\n");
printf("| GPIO Power-Down and Wake-up by PB.3 Sample Code |\n");
printf("+-------------------------------------------------------+\n\n");
/* Configure PB.3 as Input mode and enable interrupt by rising edge trigger */
GPIO_SetMode(PB, BIT3, GPIO_MODE_QUASI);
GPIO_EnableInt(PB, 3, GPIO_INT_FALLING);
NVIC_EnableIRQ(GPIO_PAPBPGPH_IRQn);
/* Enable interrupt de-bounce function and select de-bounce sampling cycle time is 1024 clocks of LIRC clock */
GPIO_SET_DEBOUNCE_TIME(GPIO_DBCTL_DBCLKSRC_LIRC, GPIO_DBCTL_DBCLKSEL_1024);
GPIO_ENABLE_DEBOUNCE(PB, BIT3);
/* Unlock protected registers before entering Power-down mode */
SYS_UnlockReg();
/* Waiting for PB.3 rising-edge interrupt event */
while(1)
{
printf("Enter to Power-Down. Wait PB.3 rising edge interrupt to wake up ...\n");
__disable_irq();
/* Enter to Power-down mode */
PowerDownFunction();
printf("MAIN PB.3 INT occurred.\n");
GPIO_CLR_INT_FLAG(PB, BIT3);
NVIC_ClearPendingIRQ(GPIO_PAPBPGPH_IRQn);
printf("System waken-up done.\n\n");
}
}