Example #1
0
void updateTime()
{
	uint32_t TimeVar =  RTC_GetCounter();

	/* Reset RTC Counter when Time is 23:59:59 */
	if (RTC_GetCounter() >= 0x0001517F)
	{
		RTC_SetCounter(0x0);
		/* Wait until last write operation on RTC registers has finished */
		RTC_WaitForLastTask();

		DateUpdate();

	}

	/* Compute  hours */
	mHour = TimeVar / 3600;
	/* Compute minutes */
	mMinute = (TimeVar % 3600) / 60;
	/* Compute seconds */
	mSecond = (TimeVar % 3600) % 60;



}
Example #2
0
/**
 * @brief Chaeks is counter value is more than 86399 and the number of
 *   elapsed and updates date that many times
 * @param None
 * @retval :None
 */
void CheckForDaysElapsed(void)
{
	uint8_t DaysElapsed;

	if((get_sec_counter() / SECONDS_IN_DAY) != 0)
	{
		for(DaysElapsed = 0; DaysElapsed < (get_sec_counter() / SECONDS_IN_DAY)
				;DaysElapsed++)
		{
			DateUpdate();
		}
		set_sec_counter(get_sec_counter() % SECONDS_IN_DAY);
	}
}
Example #3
0
void CheckForDaysElapsed(void)
{
  uint8_t DaysElapsed;

  if((RTC_GetCounter() / SECONDS_IN_DAY) != 0)
  {
    for(DaysElapsed = 0; DaysElapsed < (RTC_GetCounter() / SECONDS_IN_DAY)\
         ;DaysElapsed++)
    {
      DateUpdate();
    }

    RTC_SetCounter(RTC_GetCounter() % SECONDS_IN_DAY);
  }
}
/**
  * @brief  This function handles RTC_IRQHandler .
  * @param  None
  * @retval : None
  */
void RTC_IRQHandler(void)
{
    NVIC_ClearPendingIRQ(RTC_IRQn);
    RTC_ClearITPendingBit(RTC_IT_SEC);

    CalculateTime();
    alarm_check(alarm_buffer_ptr);

    /* If counter is equal to 86399: one day was elapsed */
    /* This takes care of date change and resetting of counter in case of
    power on - Run mode/ Main supply switched on condition*/
    if(RTC_GetCounter() == 86399)
    {
        /* Wait until last write operation on RTC registers has finished */
        RTC_WaitForLastTask();
        /* Reset counter value */
        RTC_SetCounter(0x0);
        /* Wait until last write operation on RTC registers has finished */
        RTC_WaitForLastTask();

        /* Increment the date */
        DateUpdate();
    }
}
Example #5
0
/*******************************************************************************
* Function Name  : RTC_IRQHandler
* Description    : This function handles RTC global interrupt request.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void RTC_IRQHandler(void)
{
  u8 u8_Month,u8_Day;
  u16 u16_Year;

  atcIncrementCounter();
  GprsIdleIncMSec();

  u8_Month = BKP_ReadBackupRegister(BKP_DR2);
  u8_Day = BKP_ReadBackupRegister(BKP_DR3);
  u16_Year = BKP_ReadBackupRegister(BKP_DR4);



  //NVIC_ClearIRQChannelPendingBit(RTC_IRQn);
  RTC_ClearITPendingBit(RTC_IT_SEC);

  /* If counter is equal to 86399: one day was elapsed */
  /* This takes care of date change and resetting of counter in case of
  power on - Run mode/ Main supply switched on condition*/
  if(RTC_GetCounter() == 86399)
  {
    /* Wait until last write operation on RTC registers has finished */
    RTC_WaitForLastTask();
    /* Reset counter value */
    RTC_SetCounter(0x0);
    /* Wait until last write operation on RTC registers has finished */
    RTC_WaitForLastTask();

    /* Increment the date */
    DateUpdate();
  }

  if((RTC_GetCounter()/3600 == 1)&&(((RTC_GetCounter()%3600)/60) == 59)&&
     (((RTC_GetCounter()%3600)%60) == 59))
  {
    /* March Correction */
    if((u8_Month == 3) && (u8_Day >24))
    {
      if(WeekDay(u16_Year,u8_Month,u8_Day)==0)
      {
        if((u16_SummerTimeCorrect & 0x8000) == 0x8000)
        {
          RTC_SetCounter(RTC_GetCounter() + 3601);

          /* Reset March correction flag */
          u16_SummerTimeCorrect &= 0x7FFF;

          /* Set October correction flag  */
          u16_SummerTimeCorrect |= 0x4000;
          u16_SummerTimeCorrect |= u16_Year;
          BKP_WriteBackupRegister(BKP_DR7,u16_SummerTimeCorrect);
        }
      }
    }
      /* October Correction */
    if((u8_Month == 10) && (u8_Day >24))
    {
      if(WeekDay(u16_Year,u8_Month,u8_Day)==0)
      {
        if((u16_SummerTimeCorrect & 0x4000) == 0x4000)
        {
          RTC_SetCounter(RTC_GetCounter() - 3599);

          /* Reset October correction flag */
          u16_SummerTimeCorrect &= 0xBFFF;

          /* Set March correction flag  */
          u16_SummerTimeCorrect |= 0x8000;
          u16_SummerTimeCorrect |= u16_Year;
          BKP_WriteBackupRegister(BKP_DR7,u16_SummerTimeCorrect);
        }
      }
    }
  }
}
Example #6
0
/**
  * @brief  This function handles RTC_IRQHandler .
  * @param  None
  * @retval : None
  */
void RTC_IRQHandler(void)
{
//   uint8_t Month,Day;
//   uint16_t Year;
//
//   Month = BKP_ReadBackupRegister(BKP_DR2);
//   Day = BKP_ReadBackupRegister(BKP_DR3);
//   Year = BKP_ReadBackupRegister(BKP_DR4);
    NVIC_ClearPendingIRQ(RTC_IRQn);
    RTC_ClearITPendingBit(RTC_IT_SEC);

    TimeSecTick = 1;

    /* If counter is equal to 86399: one day was elapsed */
    /* This takes care of date change and resetting of counter in case of
    power on - Run mode/ Main supply switched on condition*/
    if(RTC_GetCounter() == 86399)
    {
        /* Wait until last write operation on RTC registers has finished */
        RTC_WaitForLastTask();
        /* Reset counter value */
        RTC_SetCounter(0x0);
        /* Wait until last write operation on RTC registers has finished */
        RTC_WaitForLastTask();

        /* Increment the date */
        DateUpdate();
    }

// 	__NOP();

//   if((RTC_GetCounter()/3600 == 1)&&(((RTC_GetCounter()%3600)/60) == 59)&&
//      (((RTC_GetCounter()%3600)%60) == 59))
//   {
//     /* March Correction */
//     if((Month == 3) && (Day >24))
//     {
//       if(WeekDay(Year,Month,Day)==0)
//       {
//         if((SummerTimeCorrect & 0x8000) == 0x8000)
//         {
//           RTC_SetCounter(RTC_GetCounter() + 3601);
//
//           /* Reset March correction flag */
//           SummerTimeCorrect &= 0x7FFF;
//
//           /* Set October correction flag  */
//           SummerTimeCorrect |= 0x4000;
//           SummerTimeCorrect |= Year;
//           BKP_WriteBackupRegister(BKP_DR7,SummerTimeCorrect);
//         }
//       }
//     }
//       /* October Correction */
//     if((Month == 10) && (Day >24))
//     {
//       if(WeekDay(Year,Month,Day)==0)
//       {
//         if((SummerTimeCorrect & 0x4000) == 0x4000)
//         {
//           RTC_SetCounter(RTC_GetCounter() - 3599);
//
//           /* Reset October correction flag */
//           SummerTimeCorrect &= 0xBFFF;
//
//           /* Set March correction flag  */
//           SummerTimeCorrect |= 0x8000;
//           SummerTimeCorrect |= Year;
//           BKP_WriteBackupRegister(BKP_DR7,SummerTimeCorrect);
//         }
//       }
//     }
//   }
}