void RTC_Alarm_IRQHandler() { if(RTC_GetITStatus(RTC_IT_ALRA) != RESET) { //RTC_AlarmCmd(RTC_Alarm_A, ENABLE); PWR_RTCAccessCmd(ENABLE); // Доступ в RTC RTC_ClearITPendingBit(RTC_IT_ALRA); RTC_ClearFlag(RTC_FLAG_ALRAF); PWR_RTCAccessCmd(DISABLE); EXTI_ClearITPendingBit(EXTI_Line17); //OLED_DrawString_fast(0,0,"alarm",10); } /////////////////////////????????????????????????????????????????????????????????????????????????????????????? if(RTC_GetFlagStatus(RTC_FLAG_ALRAF) != RESET) { PWR_RTCAccessCmd(ENABLE); RTC_ClearFlag(RTC_FLAG_ALRAF); PWR_RTCAccessCmd(DISABLE); //f_WakeupToAlarm=1; curent_cmd = 5; } ///////////////////////// }
/** * @brief Enters STANDBY mode, RTC Alarm within 3 second or an external RESET * will wake-up the system from STANDBY * @param None * @retval None */ static void EnterSTANDBYMode(void) { RTC_AlarmTypeDef RTC_AlarmStructure; RTC_TimeTypeDef RTC_TimeStructure; /* Disable the Alarm A */ RTC_AlarmCmd(RTC_Alarm_A, DISABLE); /* Get the current time */ RTC_GetTime(RTC_Format_BIN, &RTC_TimeStructure); /* Set the alarm to current time + 3s */ RTC_AlarmStructure.RTC_AlarmTime.RTC_H12 = RTC_TimeStructure.RTC_H12; RTC_AlarmStructure.RTC_AlarmTime.RTC_Hours = RTC_TimeStructure.RTC_Hours; RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes = RTC_TimeStructure.RTC_Minutes; RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds = (RTC_TimeStructure.RTC_Seconds + 0x3) % 60; RTC_AlarmStructure.RTC_AlarmDateWeekDay = 31; RTC_AlarmStructure.RTC_AlarmDateWeekDaySel = RTC_AlarmDateWeekDaySel_Date; RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_DateWeekDay | RTC_AlarmMask_Hours | RTC_AlarmMask_Minutes; RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_A, &RTC_AlarmStructure); /* Enable RTC Alarm A Interrupt: this Interrupt will wake-up the system from STANDBY mode (RTC Alarm IT not enabled in NVIC) */ RTC_ITConfig(RTC_IT_ALRA, ENABLE); /* Enable the Alarm A */ RTC_AlarmCmd(RTC_Alarm_A, ENABLE); /* Clear RTC Alarm Flag */ RTC_ClearFlag(RTC_FLAG_ALRAF); /* Request to enter STANDBY mode (Wake Up flag is cleared in PWR_EnterSTANDBYMode function) */ PWR_EnterSTANDBYMode(); }
/** * @brief This function handles RTC Tamper and Time Stamp interrupts requests. * @param None * @retval None */ void TAMP_STAMP_IRQHandler(void) { if(RTC_GetFlagStatus(RTC_FLAG_TAMP1F) != RESET) { /* Tamper 1 detection event occurred */ /* Check if RTC Backup Data registers are cleared */ if(IsBackupRegReset() == 0) { /* OK, RTC Backup Data registers are reset as expected */ /* Toggle LED2 */ STM_EVAL_LEDToggle(LED2); } else { /* RTC Backup Data registers are not reset */ /* Toggle LED4 */ STM_EVAL_LEDToggle(LED4); } /* Clear Tamper 1 pin Event pending flag */ RTC_ClearFlag(RTC_FLAG_TAMP1F); /* Disable Tamper pin 1 */ RTC_TamperCmd(RTC_Tamper_1, DISABLE); /* Enable Tamper pin */ RTC_TamperCmd(RTC_Tamper_1, ENABLE); } }
void test(void) { //Reads data from the specified RTC Backup data Register. //入侵检测 if (RTC_ReadBackupRegister(RTC_BKP_DR0) != 0x32F2) { /* RTC configuration */ RTC_Config(); /* Configure the time&date register */ RTC_TimeRegulate(); } else { /* Enable the PWR clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Allow access to RTC */ PWR_BackupAccessCmd(ENABLE); /* Wait for RTC APB registers synchronisation */ RTC_WaitForSynchro(); /* Clear the RTC Alarm Flag */ RTC_ClearFlag(RTC_FLAG_ALRAF); /* Clear the EXTI Line 17 Pending bit (Connected internally to RTC Alarm) */ EXTI_ClearITPendingBit(EXTI_Line17); } while (1); }
void HAL_RTC_Set_UnixAlarm(time_t value) { RTC_AlarmTypeDef RTC_AlarmStructure; time_t alarm_time = HAL_RTC_Get_UnixTime() + value; struct tm *alarm_time_tm; alarm_time_tm = localtime(&alarm_time); /* Disable the Alarm A */ RTC_AlarmCmd(RTC_Alarm_A, DISABLE); RTC_AlarmStructure.RTC_AlarmTime.RTC_Hours = alarm_time_tm->tm_hour; RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes = alarm_time_tm->tm_min; RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds = alarm_time_tm->tm_sec; RTC_AlarmStructure.RTC_AlarmDateWeekDay = alarm_time_tm->tm_mday; RTC_AlarmStructure.RTC_AlarmDateWeekDaySel = RTC_AlarmDateWeekDaySel_Date; RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_None; /* Configure the RTC Alarm A register */ RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_A, &RTC_AlarmStructure); /* Enable the RTC Alarm A Interrupt */ RTC_ITConfig(RTC_IT_ALRA, ENABLE); /* Enable the Alarm A */ RTC_AlarmCmd(RTC_Alarm_A, ENABLE); /* Clear RTC Alarm Flag */ RTC_ClearFlag(RTC_FLAG_ALRAF); }
/** * @brief RTC Tamper Configuration.. * @param None * @retval None */ static void RTC_TamperConfig(void) { EXTI_InitTypeDef EXTI_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; /* EXTI configuration *********************************************************/ EXTI_ClearITPendingBit(EXTI_Line19); EXTI_InitStructure.EXTI_Line = EXTI_Line19; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); /* Enable RTC_IRQn */ NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQn; NVIC_InitStructure.NVIC_IRQChannelPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* determines the number of active pulse for the specific level */ RTC_TamperFilterConfig(RTC_TamperFilter_2Sample); /* Determines the frequency at which each of the tamper inputs are sampled */ RTC_TamperSamplingFreqConfig(RTC_TamperSamplingFreq_RTCCLK_Div32768); RTC_TamperPullUpCmd(DISABLE); /* Select the tamper 1 with High level */ RTC_TamperTriggerConfig(RTC_Tamper_1, RTC_TamperTrigger_LowLevel ); /* Clear tamper 1 falg */ RTC_ClearFlag(RTC_FLAG_TAMP1F); }
void TM_RTC_DisableAlarm(TM_RTC_Alarm_t Alarm) { switch (Alarm) { case TM_RTC_Alarm_A: /* Disable Alarm A */ RTC_AlarmCmd(RTC_Alarm_A, DISABLE); /* Disable Alarm A interrupt */ RTC_ITConfig(RTC_IT_ALRA, DISABLE); /* Clear Alarm A pending bit */ RTC_ClearFlag(RTC_IT_ALRA); break; case TM_RTC_Alarm_B: /* Disable Alarm B */ RTC_AlarmCmd(RTC_Alarm_B, DISABLE); /* Disable Alarm B interrupt */ RTC_ITConfig(RTC_IT_ALRB, DISABLE); /* Clear Alarm B pending bit */ RTC_ClearFlag(RTC_IT_ALRB); break; default: break; } /* Clear RTC Alarm pending bit */ EXTI_ClearITPendingBit(EXTI_Line17); /* Configure EXTI 17 as interrupt */ EXTI_InitStruct.EXTI_Line = EXTI_Line17; EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising; EXTI_InitStruct.EXTI_LineCmd = ENABLE; /* Initialite Alarm EXTI interrupt */ EXTI_Init(&EXTI_InitStruct); /* Configure the RTC Alarm Interrupt */ NVIC_InitStruct.NVIC_IRQChannel = RTC_Alarm_IRQn; NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = RTC_PRIORITY; NVIC_InitStruct.NVIC_IRQChannelSubPriority = RTC_ALARM_SUBPRIORITY; NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE; /* Initialize RTC Alarm Interrupt */ NVIC_Init(&NVIC_InitStruct); }
/******************************************************************************* * Function Name : main * Description : Main program. * Input : None * Output : None * Return : None *******************************************************************************/ int main(void) { #ifdef DEBUG debug(); #endif /* Clock configuration */ RCC_Configuration(); /* Enable PWR and BKP clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); /* GPIO configuration */ GPIO_Configuration(); /* Configure EXTI Line to generate an interrupt on falling edge */ EXTI_Configuration(); /* Configure RTC clock source and prescaler */ RTC_Configuration(); /* NVIC configuration */ NVIC_Configuration(); /* Configure the SysTick to generate an interrupt each 1 millisecond */ SysTick_Configuration(); /* Turn on led connected to GPIO_LED Pin6 */ GPIO_SetBits(GPIO_LED, GPIO_Pin_6); while (1) { /* Insert 1.5 second delay */ Delay(1500); /* Wait till RTC Second event occurs */ RTC_ClearFlag(RTC_FLAG_SEC); while(RTC_GetFlagStatus(RTC_FLAG_SEC) == RESET); /* Alarm in 3 second */ RTC_SetAlarm(RTC_GetCounter()+ 3); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); /* Turn off led connected to GPIO_LED Pin6 */ GPIO_ResetBits(GPIO_LED, GPIO_Pin_6); /* Request to enter STOP mode with regulator in low power mode*/ PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); /* At this stage the system has resumed from STOP mode -------------------*/ /* Turn on led connected to GPIO_LED Pin6 */ GPIO_SetBits(GPIO_LED, GPIO_Pin_6); /* Configures system clock after wake-up from STOP: enable HSE, PLL and select PLL as system clock source (HSE and PLL are disabled in STOP mode) */ SYSCLKConfig_STOP(); } }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /* Setup the microcontroller system. Initialize the Embedded Flash Interface, initialize the PLL and update the SystemFrequency variable. */ SystemInit(); /* Initialize LEDs and Key Button mounted on STM3210X-EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_PBInit(Button_KEY, Mode_EXTI); /* Enable PWR and BKP clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); /* Configure EXTI Line to generate an interrupt on falling edge */ EXTI_Configuration(); /* Configure RTC clock source and prescaler */ RTC_Configuration(); /* NVIC configuration */ NVIC_Configuration(); /* Configure the SysTick to generate an interrupt each 1 millisecond */ SysTick_Configuration(); /* Turn on LED1 */ STM_EVAL_LEDOn(LED1); while (1) { /* Insert 1.5 second delay */ Delay(1500); /* Wait till RTC Second event occurs */ RTC_ClearFlag(RTC_FLAG_SEC); while(RTC_GetFlagStatus(RTC_FLAG_SEC) == RESET); /* Alarm in 3 second */ RTC_SetAlarm(RTC_GetCounter()+ 3); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); /* Turn off LED1 */ STM_EVAL_LEDOff(LED1); /* Request to enter STOP mode with regulator in low power mode*/ PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); /* At this stage the system has resumed from STOP mode -------------------*/ /* Turn on LED1 */ STM_EVAL_LEDOn(LED1); /* Configures system clock after wake-up from STOP: enable HSE, PLL and select PLL as system clock source (HSE and PLL are disabled in STOP mode) */ SYSCLKConfig_STOP(); } }
/******************************************************************************* * Function Name : RTC_IRQHandler * Description : This function handles RTC global interrupt request. * Input : None * Output : None * Return : None *******************************************************************************/ void RTC_IRQHandler(void) { if((GPIOC->IDR)&(0x00001000)) { GPIOC->BRR |= 0x00001000; } else { GPIOC->BSRR |= 0x00001000; } RTC_ClearFlag(RTC_IT_SEC); }
void RTC_WKUP_IRQHandler(void) { if (RTC_GetITStatus(RTC_IT_WUT) != RESET) { EXTI_ClearITPendingBit(EXTI_Line22); RTC_ClearITPendingBit(RTC_IT_WUT); RTC_ClearFlag(RTC_FLAG_WUTF); } }
void rtc_timer_start(u32 alarmValue) { //enable BKP and PWR, Clock RCC_APB1PeriphClockCmd(RCC_APB1Periph_BKP|RCC_APB1Periph_PWR , ENABLE); // RTC clock source configuration PWR_BackupAccessCmd(ENABLE); //Allow access to BKP Domain RCC_LSEConfig(RCC_LSE_ON); //Enable LSE OSC while(RCC_GetFlagStatus(RCC_FLAG_LSERDY)==RESET); //Wait till LSE is ready RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); //Select the RTC Clock Source RCC_RTCCLKCmd(ENABLE); //enable RTC // RTC configuration // Wait for RTC APB registers synchronisation RTC_WaitForSynchro(); RTC_SetPrescaler(0); //Set the RTC time base to 30.5us RTC_WaitForLastTask(); //Wait until last write operation on RTC registers has finished //Set the RTC time counter to 0 RTC_SetCounter(0); RTC_WaitForLastTask(); // Set the RTC time alarm(the length of slot) RTC_SetAlarm(alarmValue); RTC_WaitForLastTask(); //interrupt when reach alarm value RTC_ClearFlag(RTC_IT_ALR); RTC_ITConfig(RTC_IT_ALR, ENABLE); //Configures EXTI line 17 to generate an interrupt on rising edge(alarm interrupt to wakeup board) EXTI_ClearITPendingBit(EXTI_Line17); EXTI_InitTypeDef EXTI_InitStructure; EXTI_InitStructure.EXTI_Line = EXTI_Line17; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); //Configure RTC global interrupt: //Configure NVIC: Preemption Priority = 1 and Sub Priority = 1 NVIC_InitTypeDef NVIC_InitStructure; NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); //Configure RTC Alarm interrupt: //Configure NVIC: Preemption Priority = 0 and Sub Priority = 1 NVIC_InitStructure.NVIC_IRQChannel = RTCAlarm_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); }
/**************************************************************************** * 名 称:void clock_ini(void) * 功 能:时钟初始化函数 * 入口参数:无 * 出口参数:无 * 说 明: * 调用方法: ****************************************************************************/ void clock_ini(void) { #if defined (STOP_Mode) if(BKP_CheckLOCK_RTC() != BKP_RTC_Flag){ RTC_Configuration(); RTC_InitStructure.RTC_AsynchPrediv = AsynchPrediv; RTC_InitStructure.RTC_SynchPrediv = SynchPrediv; RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24; while(RTC_Init(&RTC_InitStructure) == ERROR) {} Set_Time(time); BKP_LOCK_RTC(); }else{ while(RCC_GetFlagStatus(RCC_FLAG_PORRST) == RESET) {} while(RCC_GetFlagStatus(RCC_FLAG_PINRST) == RESET) {} RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); PWR_RTCAccessCmd(ENABLE); RTC_WaitForSynchro(); } RTC_Alarm_Exit(); RTC_NVIC_Configuration(); RTC_ClearFlag(RTC_FLAG_ALRAF); PWR_ClearFlag(PWR_FLAG_WU); #elif defined (TANDBY_Mode) RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); PWR_RTCAccessCmd(ENABLE); PWR_ClearFlag(PWR_FLAG_WU); if(PWR_GetFlagStatus(PWR_FLAG_SB) != RESET) { PWR_ClearFlag(PWR_FLAG_SB); RTC_WaitForSynchro(); }else { RTC_Configuration(); RTC_InitStructure.RTC_AsynchPrediv = AsynchPrediv; RTC_InitStructure.RTC_SynchPrediv = SynchPrediv; RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24; while(RTC_Init(&RTC_InitStructure) == ERROR) {} Set_Time(time); RTC_ClearFlag(RTC_FLAG_ALRAF); } #endif }
static void RtcClearStatus( void ) { /* Clear RTC Alarm Flag */ RTC_ClearFlag(RTC_FLAG_ALRAF); /* Enable RTC Alarm A Interrupt */ RTC_ITConfig( RTC_IT_ALRA, DISABLE ); /* Enable the Alarm A */ RTC_AlarmCmd( RTC_Alarm_A, DISABLE ); }
void RTC_WKUP_IRQHandler(void) { if(RTC_GetITStatus(RTC_IT_WUT) != RESET) { EXTI_ClearITPendingBit(EXTI_Line20); //OK PWR_RTCAccessCmd(ENABLE); RTC_ClearITPendingBit(RTC_IT_WUT); RTC_ClearFlag(RTC_FLAG_WUTF); PWR_RTCAccessCmd(DISABLE); l++; printf("RTC Interrupt executed: %d \n\r", l); } }
void radiotimer_schedule(uint16_t offset) { RTC_ITConfig(RTC_IT_ALR, DISABLE); //need to disable radio also in case that a radio interrupt is happening // Set the RTC alarm(RTC timer will alarm at next state of slot) RTC_SetAlarm(offset); RTC_WaitForLastTask(); //set radiotimer irpstatus radiotimer_vars.overflowORcompare = RADIOTIMER_COMPARE; RTC_ClearFlag(RTC_IT_ALR); RTC_ITConfig(RTC_IT_ALR, ENABLE); }
INTFUNC void RTC_IRQHandler(void) { // Blinking if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_15) == Bit_RESET) { GPIO_WriteBit(GPIOA, GPIO_Pin_15, Bit_SET); GPIO_WriteBit(GPIOA, GPIO_Pin_13, Bit_RESET); } else { GPIO_WriteBit(GPIOA, GPIO_Pin_15, Bit_RESET); GPIO_WriteBit(GPIOA, GPIO_Pin_13, Bit_SET); } RTC_ClearFlag(RTC_IT_SEC); }
INTFUNC void RTC_IRQHandler(void) { // Blinking if((GPIOC->IDR)&(0x00001000)) { // clear GPIOC->BRR |= 0x00001000; } else { // set GPIOC->BSRR |= 0x00001000; } RTC_ClearFlag(RTC_IT_SEC); }
/*! * \brief PIOS_IAP_Init - performs required initializations for iap module. * \param none. * \return none. * \retval none. * * Created: Sep 8, 2010 10:10:48 PM by joe */ void PIOS_IAP_Init( void ) { /* Enable CRC clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC, ENABLE); /* Enable PWR and BKP clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Enable write access to Backup domain */ PWR_BackupAccessCmd(ENABLE); /* Clear Tamper pin Event(TE) pending flag */ RTC_ClearFlag(RTC_FLAG_TAMP1F); }
void radiotimer_cancel() { RTC_ITConfig(RTC_IT_ALR, DISABLE); //need to disable radio also in case that a radio interrupt is happening // set RTC alarm (slotlength) RTC_SetAlarm(radiotimer_vars.currentSlotPeriod); RTC_WaitForLastTask(); //set radiotimer irpstatus radiotimer_vars.overflowORcompare = RADIOTIMER_OVERFLOW; RTC_ClearFlag(RTC_IT_ALR); RTC_ITConfig(RTC_IT_ALR, ENABLE); }
void RTC_STOP_WakeUp(void) { /* Enable PWR and BKP clocks */ /* PWR时钟(电源控制)与BKP时钟(RTC后备寄存器)使能 */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); /* Allow access to BKP Domain */ PWR_BackupAccessCmd(ENABLE); /* RTC clock source configuration ----------------------------------------*/ /* Reset Backup Domain */ BKP_DeInit(); /* Enable LSE OSC */ RCC_LSEConfig(RCC_LSE_ON); /* Wait till LSE is ready */ while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) { } /* Select the RTC Clock Source */ RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); /* Enable the RTC Clock */ RCC_RTCCLKCmd(ENABLE); /* RTC configuration -----------------------------------------------------*/ /* Wait for RTC APB registers synchronisation */ RTC_WaitForSynchro(); /* Set the RTC time base to 1s */ RTC_SetPrescaler(32767); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); /* Enable the RTC Alarm interrupt */ RTC_ITConfig(RTC_IT_ALR, ENABLE); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); RTC_ClearFlag(RTC_FLAG_SEC); while(RTC_GetFlagStatus(RTC_FLAG_SEC) == RESET); /* Alarm in 5 second */ RTC_SetAlarm(RTC_GetCounter()+ 5); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); }
/** * @brief This function handles External line 0 interrupt request. * @param None * @retval None */ void EXTI0_IRQHandler(void) { /* Clear the TimeStamp registers */ if(EXTI_GetITStatus(WAKEUP_BUTTON_EXTI_LINE) != RESET) { /* Turn LED1 ON and LED2 OFF */ STM_EVAL_LEDOn(LED1); STM_EVAL_LEDOff(LED2); /* Clear The TSF Flag (Clear TimeStamp Registers) */ RTC_ClearFlag(RTC_FLAG_TSF); printf("\r\n******************** TimeStamp Event Cleared ********************"); /* Clear the Wakeup Button EXTI line pending bit */ EXTI_ClearITPendingBit(WAKEUP_BUTTON_EXTI_LINE); } }
void radiotimer_setPeriod(uint16_t period) { RTC_ITConfig(RTC_IT_ALR, DISABLE); //need to disable radio also in case that a radio interrupt is happening when set Alarm value //Reset RTC Counter to begin a new slot RTC_SetAlarm(period); RTC_WaitForLastTask(); radiotimer_vars.currentSlotPeriod = period; //set radiotimer irpstatus radiotimer_vars.overflowORcompare = RADIOTIMER_OVERFLOW; RTC_ClearFlag(RTC_IT_ALR); RTC_ITConfig(RTC_IT_ALR, ENABLE); }
void Set_Alarm_Time(uint8_t Sec) { uint32_t sec_time; RTC_AlarmCmd(RTC_Alarm_A, DISABLE); sec_time = Get_Time().Hour*3600 + Get_Time().Min*60 + Get_Time().Sec + Sec; RTC_AlarmStructure.RTC_AlarmTime.RTC_Hours = (sec_time / 3600) % 24; RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes = (sec_time % 3600) / 60; RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds = sec_time % 60; RTC_AlarmStructure.RTC_AlarmDateWeekDay = Get_Time().Day + (sec_time > 86400 ? 1 : 0); RTC_AlarmStructure.RTC_AlarmDateWeekDaySel = RTC_AlarmDateWeekDaySel_Date; RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_None; RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_A, &RTC_AlarmStructure); RTC_ITConfig(RTC_IT_ALRA, ENABLE); RTC_AlarmCmd(RTC_Alarm_A, ENABLE); RTC_ClearFlag(RTC_FLAG_ALRAF); PWR_ClearFlag(PWR_FLAG_WU); }
//alarm A interrupt handler //when alarm occurs, clear all the interrupt bits and flags //then set the flag to play mp3 void RTC_Alarm_IRQHandler(void) { //resets alarm flags and sets flag to play mp3 if(RTC_GetITStatus(RTC_IT_ALRA) != RESET) { RTC_ClearFlag(RTC_FLAG_ALRAF); RTC_ClearITPendingBit(RTC_IT_ALRA); EXTI_ClearITPendingBit(EXTI_Line17); interruptOccurred = 1; mp3PlayingFlag = 0; GPIO_WriteBit(GPIOE, GPIO_Pin_6, Bit_RESET); } }
void RTC_Time_Init(void) { if (RTC_ReadBackupRegister(RTC_BKP_DR0) != 0x32F2) { /* RTC configuration */ RTC_Config(); /* Configure the RTC data register and RTC prescaler */ RTC_InitStructure.RTC_AsynchPrediv = AsynchPrediv; RTC_InitStructure.RTC_SynchPrediv = SynchPrediv; RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24; /* Check on RTC init */ if (RTC_Init(&RTC_InitStructure) == ERROR) { MessageBox_Show("Prescaler Config failed", "RTC Error", true, false); } /* Configure the time register */ RTC_TimeRegulate(0,0,0); } else { /* Check if the Power On Reset flag is set */ if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET) { } /* Check if the Pin Reset flag is set */ else if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET) { } /* Enable the PWR clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Allow access to RTC */ PWR_BackupAccessCmd(ENABLE); /* Wait for RTC APB registers synchronisation */ RTC_WaitForSynchro(); /* Clear the RTC Alarm Flag */ RTC_ClearFlag(RTC_FLAG_ALRAF); } }
/** * @brief This function handles External lines 9 to 5 interrupt request. * @param None * @retval None */ void EXTI15_10_IRQHandler(void) { if(EXTI_GetITStatus(KEY_BUTTON_EXTI_LINE) != RESET) { /* Clear the SEL Button EXTI line pending bit */ EXTI_ClearITPendingBit(KEY_BUTTON_EXTI_LINE); /* Disable the Alarm A */ RTC_AlarmCmd(RTC_Alarm_A, DISABLE); /* Disable RTC Alarm A Interrupt */ RTC_ITConfig(RTC_IT_ALRA, DISABLE); /* Clear Power WakeUp (CWUF) pending flag */ PWR_ClearFlag(PWR_FLAG_WU); RTC_GetTime(RTC_Format_BIN, &RTC_TimeStructure); /* Set the alarm to current time + 5s */ RTC_AlarmStructure.RTC_AlarmTime.RTC_H12 = RTC_TimeStructure.RTC_H12; RTC_AlarmStructure.RTC_AlarmTime.RTC_Hours = RTC_TimeStructure.RTC_Hours; RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes = RTC_TimeStructure.RTC_Minutes; RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds = (RTC_TimeStructure.RTC_Seconds + 0x5) % 60; RTC_AlarmStructure.RTC_AlarmDateWeekDay = 0x31; RTC_AlarmStructure.RTC_AlarmDateWeekDaySel = RTC_AlarmDateWeekDaySel_Date; RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_DateWeekDay | RTC_AlarmMask_Hours | RTC_AlarmMask_Minutes; RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_A, &RTC_AlarmStructure); /* Enable RTC Alarm A Interrupt: this Interrupt will wake-up the system from STANDBY mode (RTC Alarm IT not enabled in NVIC) */ RTC_ITConfig(RTC_IT_ALRA, ENABLE); /* Enable the Alarm A */ RTC_AlarmCmd(RTC_Alarm_A, ENABLE); /* Clear RTC Alarm Flag */ RTC_ClearFlag(RTC_FLAG_ALRAF); /* Request to enter STANDBY mode (Wake Up flag is cleared in PWR_EnterSTANDBYMode function) */ PWR_EnterSTANDBYMode(); } }
void platform_mcu_enter_standby(uint32_t secondsToWakeup) { platform_rtc_time_t time; uint32_t currentSecond; RTC_AlarmTypeDef RTC_AlarmStructure; PWR_WakeUpPinCmd(ENABLE); if(secondsToWakeup == MICO_WAIT_FOREVER) PWR_EnterSTANDBYMode(); platform_log("Wake up in %d seconds", secondsToWakeup); platform_rtc_get_time(&time); currentSecond = time.hr*3600 + time.min*60 + time.sec; currentSecond += secondsToWakeup; RTC_AlarmStructure.RTC_AlarmTime.RTC_H12 = RTC_HourFormat_24; RTC_AlarmStructure.RTC_AlarmTime.RTC_Hours = currentSecond/3600%24; RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes = currentSecond/60%60; RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds = currentSecond%60; RTC_AlarmStructure.RTC_AlarmDateWeekDay = 0x31; RTC_AlarmStructure.RTC_AlarmDateWeekDaySel = RTC_AlarmDateWeekDaySel_Date; RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_DateWeekDay ; RTC_AlarmCmd(RTC_Alarm_A, DISABLE); /* Disable the Alarm A */ RTC_ITConfig(RTC_IT_ALRA, DISABLE); /* Clear RTC Alarm Flag */ RTC_ClearFlag(RTC_FLAG_ALRAF); RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_A, &RTC_AlarmStructure); /* Enable RTC Alarm A Interrupt: this Interrupt will wake-up the system from STANDBY mode (RTC Alarm IT not enabled in NVIC) */ RTC_ITConfig(RTC_IT_ALRA, ENABLE); /* Enable the Alarm A */ RTC_AlarmCmd(RTC_Alarm_A, ENABLE); PWR_EnterSTANDBYMode(); }
void EXTI9_5_IRQHandler(void) #endif { if(EXTI_GetITStatus(SEL_BUTTON_EXTI_LINE) != RESET) { /* Clear the SEL Button EXTI line pending bit */ EXTI_ClearITPendingBit(SEL_BUTTON_EXTI_LINE); /* Turn on LED1 */ STM_EVAL_LEDOn(LED1); /* Disable the Alarm A */ RTC_AlarmCmd(RTC_Alarm_A, DISABLE); RTC_GetTime(RTC_Format_BCD, &RTC_TimeStructure); /* Set the alarm X+5s */ RTC_AlarmStructure.RTC_AlarmTime.RTC_H12 = RTC_TimeStructure.RTC_H12; RTC_AlarmStructure.RTC_AlarmTime.RTC_Hours = RTC_TimeStructure.RTC_Hours; RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes = RTC_TimeStructure.RTC_Minutes; RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds = (RTC_TimeStructure.RTC_Seconds + 0x5) % 60; RTC_AlarmStructure.RTC_AlarmDateWeekDay = 0x31; RTC_AlarmStructure.RTC_AlarmDateWeekDaySel = RTC_AlarmDateWeekDaySel_Date; RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_DateWeekDay; RTC_SetAlarm(RTC_Format_BCD, RTC_Alarm_A, &RTC_AlarmStructure); /* Enable RTC Alarm A Interrupt */ RTC_ITConfig(RTC_IT_ALRA, ENABLE); /* Enable the Alarm A */ RTC_AlarmCmd(RTC_Alarm_A, ENABLE); /* Clear RTC Alarm A flag */ RTC_ClearFlag(RTC_FLAG_ALRAF); /* Clear WakeUp flag */ PWR_ClearFlag(PWR_FLAG_WU); /* Request to enter STANDBY mode (Wake Up flag is cleared in PWR_EnterSTANDBYMode function) */ PWR_EnterSTANDBYMode(); } }
/* * Turn of timer tick and schedule wakeup * after given ticks. */ void p_pos_powerTickSuspend(UVAR_t ticks) { /* * First, systick off. */ SysTick->CTRL &= ~(SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk); /* * Then, schedule RTC wakeup after ticks have passed. */ if (ticks == INFINITE) return; if (ticks / HZ > 65536) // max 18 hours ticks = 65536 * HZ; ticks -= PORTCFG_POWER_TICKLESS_SAFETY_MARGIN; // oscillator starts up 2 ms RTC_WakeUpCmd(DISABLE); if (ticks <= MS(10000)) { // Wakeup timer ticks at 32768 / 8 = 4096 Hz RTC_WakeUpClockConfig(RTC_WakeUpClock_RTCCLK_Div8); RTC_SetWakeUpCounter(4096 * ticks / HZ); } else { // Wakeup timer ticks at 1 Hz RTC_WakeUpClockConfig(RTC_WakeUpClock_CK_SPRE_16bits); RTC_SetWakeUpCounter(ticks / HZ); } EXTI_ClearITPendingBit(EXTI_Line22); RTC_ITConfig(RTC_IT_WUT, ENABLE); RTC_ClearITPendingBit(RTC_IT_WUT); RTC_ClearFlag(RTC_FLAG_WUTF); NVIC_EnableIRQ(RTC_WKUP_IRQn); startTime = rtcTimeNow(); RTC_WakeUpCmd(ENABLE); }