Example #1
0
/**
  * @brief  Configures the RTC Alarm.
  * @param  None
  * @retval None
  */
void RTC_AlarmConfig(void)
{
  EXTI_InitTypeDef EXTI_InitStructure;
  RTC_AlarmTypeDef RTC_AlarmStructure;
  NVIC_InitTypeDef NVIC_InitStructure;
  
  /* EXTI configuration */
  EXTI_ClearITPendingBit(EXTI_Line17);
  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);
  
  /* Enable the RTC Alarm Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = RTC_Alarm_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
 
  /* Set the alarmA Masks */
  RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_All;
  RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_A, &RTC_AlarmStructure);
  
  /* Set AlarmA subseconds and enable SubSec Alarm : generate 8 interripts per Second */
  RTC_AlarmSubSecondConfig(RTC_Alarm_A, 0xFF, RTC_AlarmSubSecondMask_SS14_5);

  /* Enable AlarmA interrupt */
  RTC_ITConfig(RTC_IT_ALRA, ENABLE);
  
  /* Enable the alarmA */
  RTC_AlarmCmd(RTC_Alarm_A, DISABLE);
  
}
Example #2
0
//初始化闹钟		  
//以1970年1月1日为基准
//1970~2099年为合法年份
//syear,smon,sday,hour,min,sec:闹钟的年月日时分秒   
//返回值:0,成功;其他:错误代码.
u8 RTC_Alarm_Set(u16 syear,u8 smon,u8 sday,u8 hour,u8 min,u8 sec)
{
	u16 t;
	u32 seccount=0;
	if(syear<1970||syear>2099)return 1;	   
	for(t=1970;t<syear;t++)	//把所有年份的秒钟相加
	{
		if(Is_Leap_Year(t))seccount+=31622400;//闰年的秒钟数
		else seccount+=31536000;			  //平年的秒钟数
	}
	smon-=1;
	for(t=0;t<smon;t++)	   //把前面月份的秒钟数相加
	{
		seccount+=(u32)mon_table[t]*86400;//月份秒钟数相加
		if(Is_Leap_Year(syear)&&t==1)seccount+=86400;//闰年2月份增加一天的秒钟数	   
	}
	seccount+=(u32)(sday-1)*86400;//把前面日期的秒钟数相加 
	seccount+=(u32)hour*3600;//小时秒钟数
    seccount+=(u32)min*60;	 //分钟秒钟数
	seccount+=sec;//最后的秒钟加上去 			    
	//设置时钟
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);	//使能PWR和BKP外设时钟   
	PWR_BackupAccessCmd(ENABLE);	//使能后备寄存器访问  
	//上面三步是必须的!
	
	RTC_SetAlarm(seccount);
 
	RTC_WaitForLastTask();	//等待最近一次对RTC寄存器的写操作完成  	
	
	return 0;	    
}
Example #3
0
/**
  * @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();
}
Example #4
0
/***************************************************************************
Declaration : void sleep(char wdt_prescaler)

Description : Sleep until WDT interrupt controlled by wdt_prescaler
***************************************************************************/
void sleep(int data_ms, char mode)
{
   /* Enable the RTC Alarm interrupt */
    RTC_ITConfig(RTC_IT_ALR, ENABLE);
    /* Wait until last write operation on RTC registers has finished */
    RTC_WaitForLastTask();

    /* Alarm in data_ms */
 //   RTC_SetAlarm(RTC_GetCounter()+ data_ms<<5);

    RTC_SetAlarm(RTC_GetCounter()+ data_ms);
    /* Wait until last write operation on RTC registers has finished */
    RTC_WaitForLastTask();

    /* Request to enter STOP mode with regulator ON */
    PWR_EnterSTOPMode(PWR_Regulator_ON, PWR_STOPEntry_WFI);
    
    /* At this stage the system has resumed from STOP mode -------------------*/

    /* 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) */
    /* Enable the RTC Alarm interrupt */
    SYSCLKConfig_STOP();
    RTC_ITConfig(RTC_IT_ALR, DISABLE);
   /* Wait until last write operation on RTC registers has finished */
    RTC_WaitForLastTask();
	

	

}
Example #5
0
static void RtcSetAlarmConfig( void )
{
    EXTI_InitTypeDef EXTI_InitStructure;
    RTC_AlarmTypeDef RTC_AlarmStructure;
    NVIC_InitTypeDef NVIC_InitStructure;

    /* EXTI configuration */
    EXTI_ClearITPendingBit( EXTI_Line17 );
    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 );

    /* Enable the RTC Alarm Interrupt */
    NVIC_InitStructure.NVIC_IRQChannel = RTC_Alarm_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
    //NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init( &NVIC_InitStructure );

    /* Set the alarmA Masks */
    RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_DateWeekDay;
    RTC_SetAlarm( RTC_Format_BIN, RTC_Alarm_A, &RTC_AlarmStructure );

    /* Enable AlarmA interrupt */
    RTC_ITConfig( RTC_IT_ALRA, DISABLE );

    /* Enable the alarmA */
    RTC_AlarmCmd( RTC_Alarm_A, DISABLE );
}
Example #6
0
void RTCAlarm_IRQHandler(void)
{	
	uint32_t RTC_counter;
	RTC->CRL &= (uint16_t)RTC_FLAG_ALR;
	EXTI->PR = EXTI_Line17;
	RTC_counter = RTC_GetCounter();
	if(RTC_counter >= (sysCfg.sleepTime + sleepTimeOld))
	{
		sleepTimeOld = RTC_counter;
		sysEventFlag |=  MCU_WAKEUP_FLAG;	
		InitTimeout(&MCU_WakeupTimeout,TIME_SEC(60));
	}
	
	
	if(GET_ACC_PIN == ACC_ON)
	{
			POWER_EN_SET_OUTPUT;
			POWER_EN_PIN_SET;
			timepowerOffDelay = RTC_counter;
	}
	else if(RTC_counter >= (sysCfg.powerOffDelayTime + timepowerOffDelay))
	{
			POWER_EN_SET_INPUT;
			timepowerOffDelay = RTC_counter;
	}
	RTC_SetAlarm((RTC_counter + ALARM_TIME));
	sysEventFlag |=  RTC_ALARM_FLAG;	
}
Example #7
0
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);
}
Example #8
0
/**
  * @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();
  }
}
Example #9
0
/*******************************************************************************
* 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();
  }
}
Example #10
0
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);
}
Example #11
0
File: rtc.c Project: yzfcer/wind-os
/*
************************************************************
*	函数名称:	RTC_AlarmSet
*
*	函数功能:	RTC闹钟初始化
*
*	入口参数:	sec:秒值
*
*	返回参数:	无
*
*	说明:		写入一个32bit的秒数,来代表时间。当与RTC_CNT相等时产生闹钟中断
************************************************************
*/
void RTC_AlarmSet(unsigned int sec)
{

	RTC_WaitForLastTask();
	RTC_SetAlarm(sec);
	RTC_WaitForLastTask();
	RTC_WaitForSynchro();			//等待RTC寄存器同步

}
/*******************************************************************************
 * @brief   main routine
 ******************************************************************************/
int main (void)
{  
  SIM_Init (SIM_MODULE_FRDM_RTC_WATCH_CONFIG);
  MCG_LITE_Init (MCG_LITE_HIRC_48MHZ);
  
  // OSC module initialization
  OSC_Init(OSC_MODULE_OSCERCLK_ON_STOPMODE_ON_CONFIG(OSC_SC16P));
  MCG_ExtClkType(OSC_REQST);
  MCG_CrystalMode(LOW_POWER_OSC);
  MCG_CrystalFreqRangeSel(LOW_FREQ_RANGE);
  MCG_WaitOscInit();
  
  // LEDs initialization
  PORT_Init (PORTD, PORT_MODULE_ALT1_MODE, PIN_5, 0, NULL);
  GPIO_Init (GPIOD, GPIO_PIN_OUTPUT, PIN_5);
  GPIO_Set (GPIOD, PIN_5);
  PORT_Init (PORTE, PORT_MODULE_ALT1_MODE, PIN_31, 0, NULL);
  GPIO_Init (GPIOE, GPIO_PIN_OUTPUT, PIN_31);
  GPIO_Set (GPIOE, PIN_31);
  
  // VLLx, VCAPx pins disable
  PORT_Init(PORTC, PORT_MODULE_DISABLED_MODE, PIN_20|PIN_21|PIN_22|PIN_23, 0, NULL);
  // SLCD pin configuration
  PORT_Init(PORTE, PORT_MODULE_ALT0_MODE, PIN_20|PIN_21, 0, NULL);
  PORT_Init(PORTB, PORT_MODULE_ALT0_MODE, PIN_18|PIN_19, 0, NULL);
  PORT_Init(PORTC, PORT_MODULE_ALT0_MODE, PIN_0|PIN_4|PIN_6|PIN_7, 0, NULL);
  PORT_Init(PORTD, PORT_MODULE_ALT0_MODE, PIN_0|PIN_2|PIN_3|PIN_4, 0, NULL);
  // SLCD initialization
  LCD_Init (LCD_FRDM_CONFIG,                                                    \
            LCD_FRONT_PLANE_PINS_FRDM_KL43,                                     \
            LCD_BACK_PLANE_PINS_FRDM_KL43,                                      \
            LCD_ASSIGN_BACK_PLANES_FRDM_KL43);
  LCD_Delete_Char(0);
  LCD_Delete_Char(1);
  LCD_Delete_Char(2);
  LCD_Delete_Char(3);
  
  // Set the time according to system clock
  BUILD_DATE_TIME(time);
  // RTC initialization
  RTC_Init (RTC_MODULE_FRDM_RTC_WATCH_CONFIG, RTC_MkTime (&time), 3, rtc_callback);
  RTC_SetAlarm (RTC_GetTime ()+alarm_interval);
  // Write time to the LCD
  lcd_settime(&time);
  
  __enable_irq();
  
  while (1)
  {
    
  }
}
Example #13
0
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);
}
Example #14
0
void DecrementAlarmMinutes()
{
    int currentAlarmHour = AlarmAStruct.RTC_AlarmTime.RTC_Hours;
    int currentAlarmMinute = AlarmAStruct.RTC_AlarmTime.RTC_Minutes;
    currentAlarmHour--;
    if(currentAlarmHour <= -1) {
        currentAlarmHour = 23;
    }
    AlarmAStruct.RTC_AlarmTime.RTC_Hours = currentAlarmHour;
    AlarmAStruct.RTC_AlarmTime.RTC_Minutes = currentAlarmMinute;
    AlarmAStruct.RTC_AlarmTime.RTC_Seconds = 0x00;
    AlarmAStruct.RTC_AlarmMask = RTC_AlarmMask_DateWeekDay;
    RTC_SetAlarm(RTC_Format_BIN,RTC_Alarm_A,&AlarmAStruct);
}
/***************************************************************************//*!
 * @brief   RTC Callback function (second interrupt, alarm interrupt).
 ******************************************************************************/
void rtc_callback (RTC_CALLBACK_TYPE type)
{ 
  if (type == TAF_CALLBACK) 
  { 
    RTC_SetAlarm (RTC_GetTime()+alarm_interval);
    GPIO_Tgl (GPIOE, PIN_31);
  }
  if (type == TSF_CALLBACK) 
  { 
    RTC_GmTime (RTC_GetTime(),&time);
    lcd_settime(&time);
    GPIO_Tgl (GPIOD, PIN_5);
  }
}
Example #16
0
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);
}
Example #17
0
void TIM2_IRQHandler(void)
{
	if ( TIM_GetITStatus(TIM2 , TIM_IT_Update) != RESET ) 
	{	
		TIM_ClearITPendingBit(TIM2 , TIM_FLAG_Update);

		/////////////////////////////////////////////////////////////////
		// Power OFF GPS and GSM before go into standby mode
		/////////////////////////////////////////////////////////////////
		GSM_TurnOnOff_delay();
#ifdef USE_STM32_GPS_BOARD_VB
		GPSPowerOff();
		GSM_PowerOff();
#endif
		/* Wait till RTC Second event occurs */
		RTC_ClearFlag(RTC_FLAG_SEC);
		while(RTC_GetFlagStatus(RTC_FLAG_SEC) == RESET);

		// normal working state
		if(BKP_TRUE == BKP_ReadBackupRegister(BKP_DR1))
		{
			/* Set the RTC Alarm after xx s */
			DEBUG("in timer2 bkptrue %d\n", (BKP_ReadBackupRegister(BKP_DR4) + BKP_ReadBackupRegister(BKP_DR4) <<16));
			RTC_SetAlarm(RTC_GetCounter()+ ((BKP_ReadBackupRegister(BKP_DR4) + BKP_ReadBackupRegister(BKP_DR4) <<16)/SLEEP_TIM2_RATIO));
		}
		else
		{
			DEBUG("in timer2 bkpfalse\n");
			RTC_SetAlarm(RTC_GetCounter()+ (SLEEP_NORMAL_SEC/SLEEP_TIM2_RATIO));
		}
	
		/* Wait until last write operation on RTC registers has finished */
		RTC_WaitForLastTask();		
		/* Request to enter STANDBY mode (Wake Up flag is cleared in PWR_EnterSTANDBYMode function) */
		PWR_EnterSTANDBYMode();
	}		 	
}
/**
  * @brief  Sets the RTC Alarm Register Value
  * @param Hours, Minutes and Seconds data
  * @retval : None
  */
void SetAlarm(uint8_t Hour,uint8_t Minute, uint8_t Seconds)
{
  uint32_t CounterValue;
  
  CounterValue=((Hour * 3600)+ (Minute * 60)+Seconds);
  
  if(CounterValue == 0)
  {
    CounterValue = SECONDS_IN_DAY;
  }

  RTC_WaitForLastTask();
  RTC_SetAlarm(CounterValue);
  RTC_WaitForLastTask();
}
Example #19
0
/*******************************************************************************
* Function Name  : SetAlarm
* Description    : Sets the RTC Alarm Register Value
* Input          : Hours, Minutes and Seconds data
* Output         : None
* Return         : None
*******************************************************************************/
void SetAlarm(u8 u8_Hour,u8 u8_Minute, u8 u8_Seconds)
{
  u32 u32_CounterValue;
  
  u32_CounterValue=((u8_Hour * 3600)+ (u8_Minute * 60)+u8_Seconds);
  
  if(u32_CounterValue == 0)
  {
    u32_CounterValue = SECONDS_IN_DAY;
  }

  RTC_WaitForLastTask();
  RTC_SetAlarm(u32_CounterValue);
  RTC_WaitForLastTask();
}
Example #20
0
void cancelAlarm(void)
{    
#ifndef PRECISION_IN_MS
    RTC_WaitForLastTask();
    RTC_SetAlarm(0);
    RTC_WaitForLastTask();
    RTC_ITConfig(RTC_IT_ALR, DISABLE);
    RTC_WaitForLastTask();
    RTC_ClearITPendingBit(RTC_IT_ALR);
    RTC_WaitForLastTask();
#else
    alarm = 0;    
#endif
    alarmProc = NULL;
}
Example #21
0
/**
 * @brief	Set the time of valve open
 */
void WATER_SetWaterTime(RTC_TimeTypeDef *RTC_TimeStruct)
{
	vTaskSuspendAll();
	RTC_AlarmCmd(RTC_Alarm_A, DISABLE);

	m_waterTime.RTC_AlarmTime.RTC_H12 = RTC_TimeStruct->RTC_H12;
	m_waterTime.RTC_AlarmTime.RTC_Hours = RTC_TimeStruct->RTC_Hours;
	m_waterTime.RTC_AlarmTime.RTC_Minutes = RTC_TimeStruct->RTC_Minutes;
	m_waterTime.RTC_AlarmTime.RTC_Seconds = RTC_TimeStruct->RTC_Seconds;
	m_waterTime.RTC_AlarmMask = RTC_AlarmMask_DateWeekDay;
	RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_A, &m_waterTime);

	RTC_AlarmCmd(RTC_Alarm_A, ENABLE);
	xTaskResumeAll();
}
Example #22
0
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();
}
Example #23
0
/*******************************************************************************
* 函 数 名:	
* 功    能:	
* 参    数:
* 返    回:	
*******************************************************************************/
uint8_t RTC_Init(uint32_t pre_value, uint32_t alarm_value, uint32_t count_value)
{	
	uint8_t count;
    NVIC_InitTypeDef NVIC_InitStructure;
	//RTC全局中断
	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);		

	RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR , ENABLE);	
	PWR_BackupAccessCmd(ENABLE);
	//设置外部低速晶振(LSE),使用外设低速晶振
	RCC_LSEConfig(RCC_LSE_ON);	
	//检查指定的RCC标志位设置与否,等待低速晶振就绪
	while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)	
	{
		count++;
		Delayms(10);
	}
	if(count>=250)
		return 1;
	//设置RTC时钟(RTCCLK),选择LSE作为RTC时钟   
	RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);		 
	RCC_RTCCLKCmd(ENABLE);	
	//等待最近一次对RTC寄存器的读操作完成
	RTC_WaitForSynchro();
	//等待最近一次对RTC寄存器的写操作完成
	RTC_WaitForLastTask();	
	//设置报警时间
	RTC_SetAlarm(alarm_value);
	RTC_WaitForLastTask();	
	//配置中断
	RTC_ITConfig( RTC_IT_SEC|RTC_IT_ALR|RTC_IT_OW, ENABLE);	
	RTC_WaitForLastTask();	
	//设置RTC预分频的值
	RTC_SetPrescaler(pre_value); 
	RTC_WaitForLastTask();	
	//清除RCC的复位标志位
	RCC_ClearFlag();
	
 	RTC_WaitForLastTask();	
	RTC_SetCounter(count_value);	
	RTC_WaitForLastTask();	
	return 0;
}
Example #24
0
/*******************************************************************************
* Function Name  : Alarm_PreAdjust
* Description    : Configures an alarm event to occurs within the current day.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void Alarm_PreAdjust(void)
{
  uint32_t tmp = 0;

  /* Set the LCD Back Color */
  LCD_SetBackColor(Blue);

  /* Set the LCD Text Color */
  LCD_SetTextColor(White);

  if(BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5)
  {
    LCD_DisplayStringLine(Line8, "Time not configured ");
    LCD_DisplayStringLine(Line9, "     Press SEL      ");
    while(ReadKey() == NOKEY)
    {
    }
    return;
  }
  /* Read the alarm value stored in the Backup register */
  tmp = BKP_ReadBackupRegister(BKP_DR6);
  tmp |= BKP_ReadBackupRegister(BKP_DR7) << 16;
  
  /* Clear Line8 */
  LCD_ClearLine(Line8);
    
  /* Display time separators ":" on Line4 */
  LCD_DisplayChar(Line8, 212, ':');
  LCD_DisplayChar(Line8, 166, ':');

  /* Display the alarm value */
  Alarm_Display(tmp);
  /* Store new alarm value */
  tmp = Alarm_Regulate();

  /* Wait until last write operation on RTC registers has finished */
  RTC_WaitForLastTask();
  /* Set RTC Alarm register with the new value */
  RTC_SetAlarm(tmp);
  /* Wait until last write operation on RTC registers has finished */
  RTC_WaitForLastTask();  

  /* Save the Alarm value in the Backup register */
  BKP_WriteBackupRegister(BKP_DR6, (tmp & 0x0000FFFF));
  BKP_WriteBackupRegister(BKP_DR7, (tmp >> 16));
}
Example #25
0
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);
}
Example #27
0
void IncrementAlarmMinutes()
{
    int currentAlarmHour = AlarmAStruct.RTC_AlarmTime.RTC_Hours;
    int currentAlarmMinute = AlarmAStruct.RTC_AlarmTime.RTC_Minutes;
    currentAlarmMinute++;
    if(currentAlarmMinute >= 60) {
        currentAlarmMinute = 0;
        currentAlarmHour++;
        if(currentAlarmHour >= 24)
            currentAlarmHour = 0;
    }
    AlarmAStruct.RTC_AlarmTime.RTC_Hours = currentAlarmHour;
    AlarmAStruct.RTC_AlarmTime.RTC_Minutes = currentAlarmMinute;
    AlarmAStruct.RTC_AlarmTime.RTC_Seconds = 0x00;
    AlarmAStruct.RTC_AlarmMask = RTC_AlarmMask_DateWeekDay;
    RTC_SetAlarm(RTC_Format_BIN,RTC_Alarm_A,&AlarmAStruct);
}
Example #28
0
/**
 * @brief  Configures the RTC Alarm.
 * @param  None
 * @retval None
 */
static void RTC_AlarmConfig(void) {
	EXTI_InitTypeDef EXTI_InitStructure;
	RTC_AlarmTypeDef RTC_AlarmStructure;
	NVIC_InitTypeDef NVIC_InitStructure;

	RTC_AlarmCmd(RTC_Alarm_A, DISABLE);
	//RTC_AlarmStructure.RTC_AlarmTime.RTC_H12 ;

	/* EXTI configuration */
	EXTI_ClearITPendingBit(EXTI_Line17);
	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);

	/* Enable the RTC Alarm Interrupt */
	NVIC_InitStructure.NVIC_IRQChannel = RTC_Alarm_IRQn;
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 7;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&NVIC_InitStructure);

	/* Set the alarm A Masks */
	RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_None;
	RTC_AlarmStructure.RTC_AlarmDateWeekDaySel = RTC_AlarmDateWeekDaySel_WeekDay;
	//RTC_AlarmStructure.RTC_AlarmDateWeekDay = RTC_Weekday_Monday | RTC_Weekday_Tuesday | RTC_Weekday_Wednesday | RTC_Weekday_Thursday | RTC_Weekday_Friday;
	RTC_AlarmStructure.RTC_AlarmDateWeekDay =  (RTC_Weekday_Tuesday | RTC_Weekday_Sunday);

	//RTC_AlarmStructure.RTC_AlarmDateWeekDay = RTC_Weekday_Wednesday;
	RTC_AlarmStructure.RTC_AlarmTime.RTC_Hours = 0x00;
	RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes = 0x01;
	RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds = 0x00;
	RTC_SetAlarm(RTC_Format_BCD, RTC_Alarm_A, &RTC_AlarmStructure);

	/* Set alarm A sub seconds and enable SubSec Alarm : generate 8 interrupts per Second */
	//RTC_AlarmSubSecondConfig(RTC_Alarm_A, 0xFF, RTC_AlarmSubSecondMask_SS14_5);

	/* Enable the RTC Alarm A Interrupt */
	  RTC_ITConfig(RTC_IT_ALRA, ENABLE);

	  /* Enable the alarm  A */
	  RTC_AlarmCmd(RTC_Alarm_A, ENABLE);
}
Example #29
0
/**
 * @brief Configure gpio
 */
void WATER_Init(void)
{
	// Enable GPIO clock
	RCC_AHB1PeriphClockCmd(WATER_GPIO_CLOCK_PORT, ENABLE);

	// Configure key pin to analog input
	GPIO_InitTypeDef GPIO_InitStructure;
	GPIO_StructInit(&GPIO_InitStructure);

	GPIO_InitStructure.GPIO_Pin = WATER_PIN_NUM;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
	GPIO_Init(WATER_PIN_PORT, &GPIO_InitStructure);

	GPIO_SetBits(WATER_PIN_PORT, WATER_PIN_NUM);

	// set default water time
	m_waterTime.RTC_AlarmTime.RTC_H12 = RTC_H12_AM;
	m_waterTime.RTC_AlarmTime.RTC_Hours = WATER_DEFAULT_HOUR;
	m_waterTime.RTC_AlarmTime.RTC_Minutes = WATER_DEFAULT_MINUTE;
	m_waterTime.RTC_AlarmTime.RTC_Seconds = WATER_DEFAULT_SECOND;
	m_waterTime.RTC_AlarmMask = RTC_AlarmMask_DateWeekDay;
	RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_A, &m_waterTime);
	RTC_AlarmCmd(RTC_Alarm_A, ENABLE);

	m_period = WATER_DEFAULT_PERIOD;
	m_moistureThreshold = WATER_DEFAULT_MOISTURE_THRESHOLD;
	m_waterLock = xSemaphoreCreateMutex();

	// Create that task that handles the console itself.
	xTaskCreate( 	WATER_Task,					/* The task that implements the command console. */
					"WATER",					/* Text name assigned to the task.  This is just to assist debugging.  The kernel does not use this name itself. */
					WATER_TASK_STACK,			/* The size of the stack allocated to the task. */
					NULL,						/* The parameter is not used, so NULL is passed. */
					WATER_TASK_PRIORITY,		/* The priority allocated to the task. */
					&m_waterTask );				/* A handle is not required, so just pass NULL. */


#if SUPPORT_WATER_TEST_COMMAND
	FreeRTOS_CLIRegisterCommand(&xWaterOpen);
#endif
}
Example #30
0
/**
  * @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();
  }
}