在线时间13 小时
UID3228950
注册时间2021-4-13
NXP金币0
该用户从未签到
注册会员
- 积分
- 119
- 最后登录
- 2022-1-26
|
volatile bool busyWait;
#define EXAMPLE_SNVS_IRQHandler SNVS_HP_WRAPPER_IRQHandler
void EXAMPLE_SNVS_IRQHandler(void)
{
// if (SNVS_HP_RTC_GetStatusFlags(SNVS) & kSNVS_RTC_AlarmInterruptFlag)
// {
busyWait = false;
SNVS_HP_RTC_DisableInterrupts(SNVS, kSNVS_RTC_AlarmInterrupt);
SNVS_HP_RTC_StopTimer(SNVS);
SNVS_HP_RTC_ClearStatusFlags(SNVS, kSNVS_RTC_AlarmInterruptFlag); //Clear alarm flag
SNVS_HP_RTC_ClearStatusFlags(SNVS, kSNVS_RTC_PeriodicInterrupt); //Clear alarm flag
LPM_DisableWakeupSource(SNVS_HP_WRAPPER_IRQn);
// }
}
#define kCLOCK_SnvsHp0 kCLOCK_SnvsHp
#define EXAMPLE_SNVS_IRQn SNVS_HP_WRAPPER_IRQn
#define EXAMPLE_SNVS_IRQHandler SNVS_HP_WRAPPER_IRQHandler
void rtc(void)
{
uint32_t sec;
uint8_t index;
snvs_hp_rtc_datetime_t rtcDate;
snvs_hp_rtc_config_t snvsRtcConfig;
SNVS_HP_RTC_GetDefaultConfig(&snvsRtcConfig);
SNVS_HP_RTC_Init(SNVS, &snvsRtcConfig);
PRINTF("SNVS HP example:\r\n");
/* Set a start date time and start RT */
rtcDate.year = 2014U;
rtcDate.month = 12U;
rtcDate.day = 25U;
rtcDate.hour = 19U;
rtcDate.minute = 0;
rtcDate.second = 0;
/* Set RTC time to default time and date and start the RTC */
SNVS_HP_RTC_SetDatetime(SNVS, &rtcDate);
SNVS_HP_RTC_StartTimer(SNVS);
PRINTF("Set up time to wake up an alarm.\r\n");
/* This loop will set the SNVS alarm */
busyWait = true;
index = 0;
sec = 0;
/* Get date time */
SNVS_HP_RTC_GetDatetime(SNVS, &rtcDate);
/* print default time */
PRINTF("Current datetime: %04d-%02d-%02d %02d:%02d:%02d\r\n", rtcDate.year, rtcDate.month, rtcDate.day,
rtcDate.hour, rtcDate.minute, rtcDate.second);
/* Get alarm time from user */
PRINTF("Please input the number of second to wait for alarm and press enter \r\n");
PRINTF("The second must be positive value\r\n");
sec = 10;
SNVS_HP_RTC_GetDatetime(SNVS, &rtcDate);
if ((rtcDate.second + sec) < 60)
{
rtcDate.second += sec;
}
else
{
rtcDate.minute += (rtcDate.second + sec) / 60U;
rtcDate.second = (rtcDate.second + sec) % 60U;
}
SNVS_HP_RTC_SetAlarm(SNVS, &rtcDate);
// SNVS_HP_RTC_ClearStatusFlags(SNVS, kSNVS_RTC_AlarmInterruptFlag);
/* Enable SNVS alarm interrupt */
SNVS_HP_RTC_EnableInterrupts(SNVS, kSNVS_RTC_PeriodicInterrupt);
/* Enable at the NVIC */
NVIC_ClearPendingIRQ(EXAMPLE_SNVS_IRQn);
NVIC_EnableIRQ(EXAMPLE_SNVS_IRQn);
EnableIRQ(EXAMPLE_SNVS_IRQn);
LPM_EnableWakeupSource(EXAMPLE_SNVS_IRQn);
/* Get alarm time */
SNVS_HP_RTC_GetAlarm(SNVS, &rtcDate);
/* Print alarm time */
PRINTF("Alarm will occur at: %04d-%02d-%02d %02d:%02d:%02d\r\n", rtcDate.year, rtcDate.month, rtcDate.day,
rtcDate.hour, rtcDate.minute, rtcDate.second);
/* Wait until alarm occurs */
// while (busyWait)
// {
// }
// PRINTF("\r\n Alarm occurs !!!! ");
}
/*!
* @brief main demo function.
*/
int main(void)
{
uint8_t ch;
uint32_t freq;
bool needSetWakeup = 1; /* Need to set wakeup. */
/* Init board hardware. */
BOARD_ConfigMPU();
BOARD_InitPins();
BOARD_InitBootClocks();
/* When wakeup from suspend, peripheral's doze & stop requests won't be cleared, need to clear them manually */
IOMUXC_GPR->GPR4 = 0x00000000;
IOMUXC_GPR->GPR7 = 0x00000000;
IOMUXC_GPR->GPR8 = 0x00000000;
IOMUXC_GPR->GPR12 = 0x00000000;
/* Configure UART divider to default */
CLOCK_SetMux(kCLOCK_UartMux, 1); /* Set UART source to OSC 24M */
CLOCK_SetDiv(kCLOCK_UartDiv, 0); /* Set UART divider to 1 */
BOARD_InitDebugConsole();
/* Since SNVS_PMIC_STBY_REQ_GPIO5_IO02 will output a high-level signal under Stop Mode(Suspend Mode) and this pin is
* connected to LCD power switch circuit. So it needs to be configured as a low-level output GPIO to reduce the
* current. */
BOARD_Init_PMIC_STBY_REQ();
BOARD_InitBootPeripherals();
PRINTF("\r\nCPU wakeup source 0x%x...\r\n", SRC->SRSR);
PRINTF("\r\n***********************************************************\r\n");
PRINTF("\tPower Mode Switch Demo for %s\r\n", CPU_NAME);
PRINTF("***********************************************************\r\n");
APP_PrintRunFrequency(0);
LPM_Init();
/* Set power mode to over run after power on */
APP_SetRunMode(LPM_PowerModeOverRun);
LPM_OverDriveRun();
while (1)
{
freq = CLOCK_GetFreq(kCLOCK_CpuClk);
PRINTF("\r\n########## Power Mode Switch Demo (build %s) ###########\n\r\n", __DATE__);
PRINTF(" Core Clock = %dHz \r\n", freq);
APP_ShowPowerMode(s_curRunMode);
PRINTF("\r\nSelect the desired operation \n\r\n");
PRINTF("Press %c for enter: Over RUN - System Over Run mode\r\n",
(uint8_t)'A' + (uint8_t)LPM_PowerModeOverRun);
PRINTF("Press %c for enter: Full RUN - System Full Run mode\r\n",
(uint8_t)'A' + (uint8_t)LPM_PowerModeFullRun);
PRINTF("Press %c for enter: Low Speed RUN - System Low Speed Run mode\r\n",
(uint8_t)'A' + (uint8_t)LPM_PowerModeLowSpeedRun);
PRINTF("Press %c for enter: Low Power RUN - System Low Power Run mode\r\n",
(uint8_t)'A' + (uint8_t)LPM_PowerModeLowPowerRun);
PRINTF("Press %c for enter: System Idle - System Wait mode\r\n",
(uint8_t)'A' + (uint8_t)LPM_PowerModeSysIdle);
PRINTF("Press %c for enter: Low Power Idle - Low Power Idle mode\r\n",
(uint8_t)'A' + (uint8_t)LPM_PowerModeLPIdle);
PRINTF("Press %c for enter: Suspend - Suspend mode\r\n", (uint8_t)'A' + (uint8_t)LPM_PowerModeSuspend);
#if (HAS_WAKEUP_PIN)
PRINTF("Press %c for enter: SNVS - Shutdown the system\r\n",
(uint8_t)'A' + (uint8_t)LPM_PowerModeSNVS);
#endif
PRINTF("\r\nWaiting for power mode select...\r\n\r\n");
/* Wait for user response */
ch = GETCHAR();
if ((ch >= 'a') && (ch <= 'z'))
{
ch -= 'a' - 'A';
}
s_targetPowerMode = (lpm_power_mode_t)(ch - 'A');
if (s_targetPowerMode <= LPM_PowerModeEnd)
{
/* If could not set the target power mode, loop continue. */
if (!APP_CheckPowerMode(s_curRunMode, s_targetPowerMode))
{
continue;
}
/* If target mode is run mode, don't need to set wakeup source. */
if (s_targetPowerMode <= LPM_PowerModeLowPowerRun)
{
needSetWakeup = false;
}
else
{
needSetWakeup = true;
}
if (needSetWakeup)
{
// APP_GetWakeupConfig(s_targetPowerMode);
// APP_SetWakeupConfig(s_targetPowerMode);
}
rtc();
SDK_DelayAtLeastUs(100, SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY);
APP_PowerPreSwitchHook(s_targetPowerMode);
APP_PowerModeSwitch(s_targetPowerMode);
APP_PowerPostSwitchHook(s_targetPowerMode);
// while (busyWait)
// {
//
// }
PRINTF("\r\n Alarm occurs !!!! ");
}
PRINTF("\r\nNext loop\r\n");
}
}
|
|