STM32F10x Standard Peripherals Library  3.5.0
/opt/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_rtc.c
Go to the documentation of this file.
00001 
00022 /* Includes ------------------------------------------------------------------*/
00023 #include "stm32f10x_rtc.h"
00024 
00044 #define RTC_LSB_MASK     ((uint32_t)0x0000FFFF)  
00045 #define PRLH_MSB_MASK    ((uint32_t)0x000F0000)  
00090 void RTC_ITConfig(uint16_t RTC_IT, FunctionalState NewState)
00091 {
00092   /* Check the parameters */
00093   assert_param(IS_RTC_IT(RTC_IT));  
00094   assert_param(IS_FUNCTIONAL_STATE(NewState));
00095   
00096   if (NewState != DISABLE)
00097   {
00098     RTC->CRH |= RTC_IT;
00099   }
00100   else
00101   {
00102     RTC->CRH &= (uint16_t)~RTC_IT;
00103   }
00104 }
00105 
00111 void RTC_EnterConfigMode(void)
00112 {
00113   /* Set the CNF flag to enter in the Configuration Mode */
00114   RTC->CRL |= RTC_CRL_CNF;
00115 }
00116 
00122 void RTC_ExitConfigMode(void)
00123 {
00124   /* Reset the CNF flag to exit from the Configuration Mode */
00125   RTC->CRL &= (uint16_t)~((uint16_t)RTC_CRL_CNF); 
00126 }
00127 
00133 uint32_t RTC_GetCounter(void)
00134 {
00135   uint16_t tmp = 0;
00136   tmp = RTC->CNTL;
00137   return (((uint32_t)RTC->CNTH << 16 ) | tmp) ;
00138 }
00139 
00145 void RTC_SetCounter(uint32_t CounterValue)
00146 { 
00147   RTC_EnterConfigMode();
00148   /* Set RTC COUNTER MSB word */
00149   RTC->CNTH = CounterValue >> 16;
00150   /* Set RTC COUNTER LSB word */
00151   RTC->CNTL = (CounterValue & RTC_LSB_MASK);
00152   RTC_ExitConfigMode();
00153 }
00154 
00160 void RTC_SetPrescaler(uint32_t PrescalerValue)
00161 {
00162   /* Check the parameters */
00163   assert_param(IS_RTC_PRESCALER(PrescalerValue));
00164   
00165   RTC_EnterConfigMode();
00166   /* Set RTC PRESCALER MSB word */
00167   RTC->PRLH = (PrescalerValue & PRLH_MSB_MASK) >> 16;
00168   /* Set RTC PRESCALER LSB word */
00169   RTC->PRLL = (PrescalerValue & RTC_LSB_MASK);
00170   RTC_ExitConfigMode();
00171 }
00172 
00178 void RTC_SetAlarm(uint32_t AlarmValue)
00179 {  
00180   RTC_EnterConfigMode();
00181   /* Set the ALARM MSB word */
00182   RTC->ALRH = AlarmValue >> 16;
00183   /* Set the ALARM LSB word */
00184   RTC->ALRL = (AlarmValue & RTC_LSB_MASK);
00185   RTC_ExitConfigMode();
00186 }
00187 
00193 uint32_t RTC_GetDivider(void)
00194 {
00195   uint32_t tmp = 0x00;
00196   tmp = ((uint32_t)RTC->DIVH & (uint32_t)0x000F) << 16;
00197   tmp |= RTC->DIVL;
00198   return tmp;
00199 }
00200 
00207 void RTC_WaitForLastTask(void)
00208 {
00209   /* Loop until RTOFF flag is set */
00210   while ((RTC->CRL & RTC_FLAG_RTOFF) == (uint16_t)RESET)
00211   {
00212   }
00213 }
00214 
00223 void RTC_WaitForSynchro(void)
00224 {
00225   /* Clear RSF flag */
00226   RTC->CRL &= (uint16_t)~RTC_FLAG_RSF;
00227   /* Loop until RSF flag is set */
00228   while ((RTC->CRL & RTC_FLAG_RSF) == (uint16_t)RESET)
00229   {
00230   }
00231 }
00232 
00244 FlagStatus RTC_GetFlagStatus(uint16_t RTC_FLAG)
00245 {
00246   FlagStatus bitstatus = RESET;
00247   
00248   /* Check the parameters */
00249   assert_param(IS_RTC_GET_FLAG(RTC_FLAG)); 
00250   
00251   if ((RTC->CRL & RTC_FLAG) != (uint16_t)RESET)
00252   {
00253     bitstatus = SET;
00254   }
00255   else
00256   {
00257     bitstatus = RESET;
00258   }
00259   return bitstatus;
00260 }
00261 
00273 void RTC_ClearFlag(uint16_t RTC_FLAG)
00274 {
00275   /* Check the parameters */
00276   assert_param(IS_RTC_CLEAR_FLAG(RTC_FLAG)); 
00277     
00278   /* Clear the corresponding RTC flag */
00279   RTC->CRL &= (uint16_t)~RTC_FLAG;
00280 }
00281 
00291 ITStatus RTC_GetITStatus(uint16_t RTC_IT)
00292 {
00293   ITStatus bitstatus = RESET;
00294   /* Check the parameters */
00295   assert_param(IS_RTC_GET_IT(RTC_IT)); 
00296   
00297   bitstatus = (ITStatus)(RTC->CRL & RTC_IT);
00298   if (((RTC->CRH & RTC_IT) != (uint16_t)RESET) && (bitstatus != (uint16_t)RESET))
00299   {
00300     bitstatus = SET;
00301   }
00302   else
00303   {
00304     bitstatus = RESET;
00305   }
00306   return bitstatus;
00307 }
00308 
00318 void RTC_ClearITPendingBit(uint16_t RTC_IT)
00319 {
00320   /* Check the parameters */
00321   assert_param(IS_RTC_IT(RTC_IT));  
00322   
00323   /* Clear the corresponding RTC pending bit */
00324   RTC->CRL &= (uint16_t)~RTC_IT;
00325 }
00326 
00339 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/