stm32f10x_rtc.c
Go to the documentation of this file.
1 
22 /* Includes ------------------------------------------------------------------*/
23 #include "stm32f10x_rtc.h"
24 
44 #define RTC_LSB_MASK ((uint32_t)0x0000FFFF)
45 #define PRLH_MSB_MASK ((uint32_t)0x000F0000)
90 void RTC_ITConfig(uint16_t RTC_IT, FunctionalState NewState)
91 {
92  /* Check the parameters */
93  assert_param(IS_RTC_IT(RTC_IT));
95 
96  if (NewState != DISABLE)
97  {
98  RTC->CRH |= RTC_IT;
99  }
100  else
101  {
102  RTC->CRH &= (uint16_t)~RTC_IT;
103  }
104 }
105 
112 {
113  /* Set the CNF flag to enter in the Configuration Mode */
114  RTC->CRL |= RTC_CRL_CNF;
115 }
116 
123 {
124  /* Reset the CNF flag to exit from the Configuration Mode */
125  RTC->CRL &= (uint16_t)~((uint16_t)RTC_CRL_CNF);
126 }
127 
133 uint32_t RTC_GetCounter(void)
134 {
135  uint16_t tmp = 0;
136  tmp = RTC->CNTL;
137  return (((uint32_t)RTC->CNTH << 16 ) | tmp) ;
138 }
139 
145 void RTC_SetCounter(uint32_t CounterValue)
146 {
148  /* Set RTC COUNTER MSB word */
149  RTC->CNTH = CounterValue >> 16;
150  /* Set RTC COUNTER LSB word */
151  RTC->CNTL = (CounterValue & RTC_LSB_MASK);
153 }
154 
160 void RTC_SetPrescaler(uint32_t PrescalerValue)
161 {
162  /* Check the parameters */
163  assert_param(IS_RTC_PRESCALER(PrescalerValue));
164 
166  /* Set RTC PRESCALER MSB word */
167  RTC->PRLH = (PrescalerValue & PRLH_MSB_MASK) >> 16;
168  /* Set RTC PRESCALER LSB word */
169  RTC->PRLL = (PrescalerValue & RTC_LSB_MASK);
171 }
172 
178 void RTC_SetAlarm(uint32_t AlarmValue)
179 {
181  /* Set the ALARM MSB word */
182  RTC->ALRH = AlarmValue >> 16;
183  /* Set the ALARM LSB word */
184  RTC->ALRL = (AlarmValue & RTC_LSB_MASK);
186 }
187 
193 uint32_t RTC_GetDivider(void)
194 {
195  uint32_t tmp = 0x00;
196  tmp = ((uint32_t)RTC->DIVH & (uint32_t)0x000F) << 16;
197  tmp |= RTC->DIVL;
198  return tmp;
199 }
200 
208 {
209  /* Loop until RTOFF flag is set */
210  while ((RTC->CRL & RTC_FLAG_RTOFF) == (uint16_t)RESET)
211  {
212  }
213 }
214 
224 {
225  /* Clear RSF flag */
226  RTC->CRL &= (uint16_t)~RTC_FLAG_RSF;
227  /* Loop until RSF flag is set */
228  while ((RTC->CRL & RTC_FLAG_RSF) == (uint16_t)RESET)
229  {
230  }
231 }
232 
244 FlagStatus RTC_GetFlagStatus(uint16_t RTC_FLAG)
245 {
246  FlagStatus bitstatus = RESET;
247 
248  /* Check the parameters */
249  assert_param(IS_RTC_GET_FLAG(RTC_FLAG));
250 
251  if ((RTC->CRL & RTC_FLAG) != (uint16_t)RESET)
252  {
253  bitstatus = SET;
254  }
255  else
256  {
257  bitstatus = RESET;
258  }
259  return bitstatus;
260 }
261 
273 void RTC_ClearFlag(uint16_t RTC_FLAG)
274 {
275  /* Check the parameters */
276  assert_param(IS_RTC_CLEAR_FLAG(RTC_FLAG));
277 
278  /* Clear the corresponding RTC flag */
279  RTC->CRL &= (uint16_t)~RTC_FLAG;
280 }
281 
291 ITStatus RTC_GetITStatus(uint16_t RTC_IT)
292 {
293  ITStatus bitstatus = RESET;
294  /* Check the parameters */
295  assert_param(IS_RTC_GET_IT(RTC_IT));
296 
297  bitstatus = (ITStatus)(RTC->CRL & RTC_IT);
298  if (((RTC->CRH & RTC_IT) != (uint16_t)RESET) && (bitstatus != (uint16_t)RESET))
299  {
300  bitstatus = SET;
301  }
302  else
303  {
304  bitstatus = RESET;
305  }
306  return bitstatus;
307 }
308 
318 void RTC_ClearITPendingBit(uint16_t RTC_IT)
319 {
320  /* Check the parameters */
321  assert_param(IS_RTC_IT(RTC_IT));
322 
323  /* Clear the corresponding RTC pending bit */
324  RTC->CRL &= (uint16_t)~RTC_IT;
325 }
326 
339 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
FlagStatus
Definition: stm32f4xx.h:706
void RTC_SetCounter(uint32_t CounterValue)
Sets the RTC counter value.
uint32_t RTC_GetDivider(void)
Gets the RTC divider value.
#define IS_RTC_GET_FLAG(FLAG)
#define RTC_FLAG_RSF
void RTC_ClearFlag(uint16_t RTC_FLAG)
Clears the RTC&#39;s pending flags.
#define RTC_CRL_CNF
Definition: stm32f10x.h:4492
#define IS_RTC_GET_IT(IT)
void assert_param(int val)
This file contains all the functions prototypes for the RTC firmware library.
#define IS_FUNCTIONAL_STATE(STATE)
Definition: stm32f4xx.h:709
#define IS_RTC_CLEAR_FLAG(FLAG)
void RTC_WaitForLastTask(void)
Waits until last write operation on RTC registers has finished.
FlagStatus RTC_GetFlagStatus(uint16_t RTC_FLAG)
Checks whether the specified RTC flag is set or not.
Definition: stm32f4xx.h:706
enum FlagStatus ITStatus
ITStatus RTC_GetITStatus(uint16_t RTC_IT)
Checks whether the specified RTC interrupt has occurred or not.
void RTC_SetAlarm(uint32_t AlarmValue)
Sets the RTC alarm value.
#define PRLH_MSB_MASK
Definition: stm32f10x_rtc.c:45
void RTC_EnterConfigMode(void)
Enters the RTC configuration mode.
void RTC_ClearITPendingBit(uint16_t RTC_IT)
Clears the RTC&#39;s interrupt pending bits.
#define RTC_FLAG_RTOFF
Definition: stm32f10x_rtc.h:72
#define RTC_LSB_MASK
Definition: stm32f10x_rtc.c:44
void RTC_WaitForSynchro(void)
Waits until the RTC registers (RTC_CNT, RTC_ALR and RTC_PRL) are synchronized with RTC APB clock...
void RTC_ExitConfigMode(void)
Exits from the RTC configuration mode.
#define IS_RTC_IT(IT)
Definition: stm32f10x_rtc.h:61
#define IS_RTC_PRESCALER(PRESCALER)
Definition: stm32f10x_rtc.h:81
uint32_t RTC_GetCounter(void)
Gets the RTC counter value.
void RTC_SetPrescaler(uint32_t PrescalerValue)
Sets the RTC prescaler value.
#define RTC
Definition: stm32f4xx.h:2046


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Thu Apr 15 2021 05:07:48