2 ******************************************************************************
\r
3 * @file stm32f10x_rtc.c
\r
4 * @author MCD Application Team
\r
7 * @brief This file provides all the RTC firmware functions.
\r
8 ******************************************************************************
\r
11 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
\r
12 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
\r
13 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
\r
14 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
\r
15 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
\r
16 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
\r
18 * <h2><center>© COPYRIGHT 2010 STMicroelectronics</center></h2>
\r
21 /* Includes ------------------------------------------------------------------*/
\r
22 #include "stm32f10x_rtc.h"
\r
24 /** @addtogroup STM32F10x_StdPeriph_Driver
\r
29 * @brief RTC driver modules
\r
33 /** @defgroup RTC_Private_TypesDefinitions
\r
40 /** @defgroup RTC_Private_Defines
\r
43 #define RTC_LSB_MASK ((uint32_t)0x0000FFFF) /*!< RTC LSB Mask */
\r
44 #define PRLH_MSB_MASK ((uint32_t)0x000F0000) /*!< RTC Prescaler MSB Mask */
\r
50 /** @defgroup RTC_Private_Macros
\r
58 /** @defgroup RTC_Private_Variables
\r
66 /** @defgroup RTC_Private_FunctionPrototypes
\r
74 /** @defgroup RTC_Private_Functions
\r
79 * @brief Enables or disables the specified RTC interrupts.
\r
80 * @param RTC_IT: specifies the RTC interrupts sources to be enabled or disabled.
\r
81 * This parameter can be any combination of the following values:
\r
82 * @arg RTC_IT_OW: Overflow interrupt
\r
83 * @arg RTC_IT_ALR: Alarm interrupt
\r
84 * @arg RTC_IT_SEC: Second interrupt
\r
85 * @param NewState: new state of the specified RTC interrupts.
\r
86 * This parameter can be: ENABLE or DISABLE.
\r
89 void RTC_ITConfig(uint16_t RTC_IT, FunctionalState NewState)
\r
91 /* Check the parameters */
\r
92 assert_param(IS_RTC_IT(RTC_IT));
\r
93 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
95 if (NewState != DISABLE)
\r
101 RTC->CRH &= (uint16_t)~RTC_IT;
\r
106 * @brief Enters the RTC configuration mode.
\r
110 void RTC_EnterConfigMode(void)
\r
112 /* Set the CNF flag to enter in the Configuration Mode */
\r
113 RTC->CRL |= RTC_CRL_CNF;
\r
117 * @brief Exits from the RTC configuration mode.
\r
121 void RTC_ExitConfigMode(void)
\r
123 /* Reset the CNF flag to exit from the Configuration Mode */
\r
124 RTC->CRL &= (uint16_t)~((uint16_t)RTC_CRL_CNF);
\r
128 * @brief Gets the RTC counter value.
\r
130 * @retval RTC counter value.
\r
132 uint32_t RTC_GetCounter(void)
\r
136 return (((uint32_t)RTC->CNTH << 16 ) | tmp) ;
\r
140 * @brief Sets the RTC counter value.
\r
141 * @param CounterValue: RTC counter new value.
\r
144 void RTC_SetCounter(uint32_t CounterValue)
\r
146 RTC_EnterConfigMode();
\r
147 /* Set RTC COUNTER MSB word */
\r
148 RTC->CNTH = CounterValue >> 16;
\r
149 /* Set RTC COUNTER LSB word */
\r
150 RTC->CNTL = (CounterValue & RTC_LSB_MASK);
\r
151 RTC_ExitConfigMode();
\r
155 * @brief Sets the RTC prescaler value.
\r
156 * @param PrescalerValue: RTC prescaler new value.
\r
159 void RTC_SetPrescaler(uint32_t PrescalerValue)
\r
161 /* Check the parameters */
\r
162 assert_param(IS_RTC_PRESCALER(PrescalerValue));
\r
164 RTC_EnterConfigMode();
\r
165 /* Set RTC PRESCALER MSB word */
\r
166 RTC->PRLH = (PrescalerValue & PRLH_MSB_MASK) >> 16;
\r
167 /* Set RTC PRESCALER LSB word */
\r
168 RTC->PRLL = (PrescalerValue & RTC_LSB_MASK);
\r
169 RTC_ExitConfigMode();
\r
173 * @brief Sets the RTC alarm value.
\r
174 * @param AlarmValue: RTC alarm new value.
\r
177 void RTC_SetAlarm(uint32_t AlarmValue)
\r
179 RTC_EnterConfigMode();
\r
180 /* Set the ALARM MSB word */
\r
181 RTC->ALRH = AlarmValue >> 16;
\r
182 /* Set the ALARM LSB word */
\r
183 RTC->ALRL = (AlarmValue & RTC_LSB_MASK);
\r
184 RTC_ExitConfigMode();
\r
188 * @brief Gets the RTC divider value.
\r
190 * @retval RTC Divider value.
\r
192 uint32_t RTC_GetDivider(void)
\r
194 uint32_t tmp = 0x00;
\r
195 tmp = ((uint32_t)RTC->DIVH & (uint32_t)0x000F) << 16;
\r
201 * @brief Waits until last write operation on RTC registers has finished.
\r
202 * @note This function must be called before any write to RTC registers.
\r
206 void RTC_WaitForLastTask(void)
\r
208 /* Loop until RTOFF flag is set */
\r
209 while ((RTC->CRL & RTC_FLAG_RTOFF) == (uint16_t)RESET)
\r
215 * @brief Waits until the RTC registers (RTC_CNT, RTC_ALR and RTC_PRL)
\r
216 * are synchronized with RTC APB clock.
\r
217 * @note This function must be called before any read operation after an APB reset
\r
218 * or an APB clock stop.
\r
222 void RTC_WaitForSynchro(void)
\r
224 /* Clear RSF flag */
\r
225 RTC->CRL &= (uint16_t)~RTC_FLAG_RSF;
\r
226 /* Loop until RSF flag is set */
\r
227 while ((RTC->CRL & RTC_FLAG_RSF) == (uint16_t)RESET)
\r
233 * @brief Checks whether the specified RTC flag is set or not.
\r
234 * @param RTC_FLAG: specifies the flag to check.
\r
235 * This parameter can be one the following values:
\r
236 * @arg RTC_FLAG_RTOFF: RTC Operation OFF flag
\r
237 * @arg RTC_FLAG_RSF: Registers Synchronized flag
\r
238 * @arg RTC_FLAG_OW: Overflow flag
\r
239 * @arg RTC_FLAG_ALR: Alarm flag
\r
240 * @arg RTC_FLAG_SEC: Second flag
\r
241 * @retval The new state of RTC_FLAG (SET or RESET).
\r
243 FlagStatus RTC_GetFlagStatus(uint16_t RTC_FLAG)
\r
245 FlagStatus bitstatus = RESET;
\r
247 /* Check the parameters */
\r
248 assert_param(IS_RTC_GET_FLAG(RTC_FLAG));
\r
250 if ((RTC->CRL & RTC_FLAG) != (uint16_t)RESET)
\r
262 * @brief Clears the RTC
\92s pending flags.
\r
263 * @param RTC_FLAG: specifies the flag to clear.
\r
264 * This parameter can be any combination of the following values:
\r
265 * @arg RTC_FLAG_RSF: Registers Synchronized flag. This flag is cleared only after
\r
266 * an APB reset or an APB Clock stop.
\r
267 * @arg RTC_FLAG_OW: Overflow flag
\r
268 * @arg RTC_FLAG_ALR: Alarm flag
\r
269 * @arg RTC_FLAG_SEC: Second flag
\r
272 void RTC_ClearFlag(uint16_t RTC_FLAG)
\r
274 /* Check the parameters */
\r
275 assert_param(IS_RTC_CLEAR_FLAG(RTC_FLAG));
\r
277 /* Clear the coressponding RTC flag */
\r
278 RTC->CRL &= (uint16_t)~RTC_FLAG;
\r
282 * @brief Checks whether the specified RTC interrupt has occured or not.
\r
283 * @param RTC_IT: specifies the RTC interrupts sources to check.
\r
284 * This parameter can be one of the following values:
\r
285 * @arg RTC_IT_OW: Overflow interrupt
\r
286 * @arg RTC_IT_ALR: Alarm interrupt
\r
287 * @arg RTC_IT_SEC: Second interrupt
\r
288 * @retval The new state of the RTC_IT (SET or RESET).
\r
290 ITStatus RTC_GetITStatus(uint16_t RTC_IT)
\r
292 ITStatus bitstatus = RESET;
\r
293 /* Check the parameters */
\r
294 assert_param(IS_RTC_GET_IT(RTC_IT));
\r
296 bitstatus = (ITStatus)(RTC->CRL & RTC_IT);
\r
297 if (((RTC->CRH & RTC_IT) != (uint16_t)RESET) && (bitstatus != (uint16_t)RESET))
\r
309 * @brief Clears the RTC
\92s interrupt pending bits.
\r
310 * @param RTC_IT: specifies the interrupt pending bit to clear.
\r
311 * This parameter can be any combination of the following values:
\r
312 * @arg RTC_IT_OW: Overflow interrupt
\r
313 * @arg RTC_IT_ALR: Alarm interrupt
\r
314 * @arg RTC_IT_SEC: Second interrupt
\r
317 void RTC_ClearITPendingBit(uint16_t RTC_IT)
\r
319 /* Check the parameters */
\r
320 assert_param(IS_RTC_IT(RTC_IT));
\r
322 /* Clear the coressponding RTC pending bit */
\r
323 RTC->CRL &= (uint16_t)~RTC_IT;
\r
338 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
\r