1 /******************** (C) COPYRIGHT 2006 STMicroelectronics ********************
2 * File Name : 75x_rtc.c
3 * Author : MCD Application Team
4 * Date First Issued : 03/10/2006
5 * Description : This file provides all the RTC software functions.
6 ********************************************************************************
10 ********************************************************************************
11 * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
13 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
14 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
15 * CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
16 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
17 *******************************************************************************/
19 /* Includes ------------------------------------------------------------------*/
23 /* Private typedef -----------------------------------------------------------*/
24 /* Private define ------------------------------------------------------------*/
25 #define RTC_CNF_Enable_Mask 0x0010 /* Configuration Flag Enable Mask */
26 #define RTC_CNF_Disable_Mask 0xFFEF /* Configuration Flag Disable Mask */
27 #define RTC_LSB_Mask 0x0000FFFF /* RTC LSB Mask */
28 #define RTC_MSB_Mask 0xFFFF0000 /* RTC MSB Mask */
29 #define RTC_Prescaler_MSB_Mask 0x000F0000 /* RTC Prescaler MSB Mask */
31 /* Private macro -------------------------------------------------------------*/
32 /* Private variables ---------------------------------------------------------*/
33 /* Private function prototypes -----------------------------------------------*/
34 /* Private functions ---------------------------------------------------------*/
35 /*******************************************************************************
36 * Function Name : RTC_DeInit
37 * Description : Deinitializes the RTC peripheral registers to their
38 * default reset values.
42 *******************************************************************************/
45 MRCC_PeripheralSWResetConfig(MRCC_Peripheral_RTC,ENABLE);
46 MRCC_PeripheralSWResetConfig(MRCC_Peripheral_RTC,DISABLE);
49 /*******************************************************************************
50 * Function Name : RTC_ITConfig
51 * Description : Enables or disables the specified RTC interrupts.
52 * Input : - RTC_IT: specifies the RTC interrupts sources to be enabled
54 * This parameter can be a combination of one or more of the
56 * - RTC_IT_Overflow: Overflow interrupt
57 * - RTC_IT_Alarm: Alarm interrupt
58 * - RTC_IT_Second: Second interrupt
59 * - NewState: new state of the specified RTC interrupts.
60 * This parameter can be: ENABLE or DISABLE.
63 *******************************************************************************/
64 void RTC_ITConfig(u16 RTC_IT, FunctionalState NewState)
66 if(NewState == ENABLE)
76 /*******************************************************************************
77 * Function Name : RTC_EnterConfigMode
78 * Description : Enters the RTC configuration mode.
82 *******************************************************************************/
83 void RTC_EnterConfigMode(void)
85 /* Set the CNF flag to enter in the Configuration Mode */
86 RTC->CRL |= RTC_CNF_Enable_Mask;
89 /*******************************************************************************
90 * Function Name : RTC_ExitConfigMode
91 * Description : Exits from the RTC configuration mode.
95 *******************************************************************************/
96 void RTC_ExitConfigMode(void)
98 /* Reset the CNF flag to exit from the Configuration Mode */
99 RTC->CRL &= RTC_CNF_Disable_Mask;
102 /*******************************************************************************
103 * Function Name : RTC_GetCounter
104 * Description : Gets the RTC counter value.
107 * Return : RTC counter value.
108 *******************************************************************************/
109 u32 RTC_GetCounter(void)
114 return (((u32)RTC->CNTH << 16 ) |Tmp) ;
117 /*******************************************************************************
118 * Function Name : RTC_SetCounter
119 * Description : Sets the RTC counter value.
120 * Input : RTC counter new value.
123 *******************************************************************************/
124 void RTC_SetCounter(u32 CounterValue)
126 RTC_EnterConfigMode();
128 /* COUNTER Config ------------------------------------------------------------*/
129 /* Set RTC COUNTER MSB word */
130 RTC->CNTH =(CounterValue & RTC_MSB_Mask) >> 16;
131 /* Set RTC COUNTER LSB word */
132 RTC->CNTL =(CounterValue & RTC_LSB_Mask);
134 RTC_ExitConfigMode();
137 /*******************************************************************************
138 * Function Name : RTC_SetPrescaler
139 * Description : Sets the RTC prescaler value.
140 * Input : RTC prescaler new value.
143 *******************************************************************************/
144 void RTC_SetPrescaler(u32 PrescalerValue)
146 RTC_EnterConfigMode();
148 /* PRESCALER Config ----------------------------------------------------------*/
149 /* Set RTC PRESCALER MSB word */
150 RTC->PRLH = (PrescalerValue & RTC_Prescaler_MSB_Mask) >> 16;
151 /* Set RTC PRESCALER LSB word */
152 RTC->PRLL = (PrescalerValue & RTC_LSB_Mask);
154 RTC_ExitConfigMode();
157 /*******************************************************************************
158 * Function Name : RTC_GetPrescaler
159 * Description : Gets the RTC prescaler value.
162 * Return : RTC prescaler value.
163 *******************************************************************************/
164 u32 RTC_GetPrescaler(void)
169 return (((u32)(RTC->PRLH & 0x000F) << 16 ) | Tmp);
172 /*******************************************************************************
173 * Function Name : RTC_SetAlarm
174 * Description : Sets the RTC alarm value.
175 * Input : RTC alarm new value.
178 *******************************************************************************/
179 void RTC_SetAlarm(u32 AlarmValue)
181 RTC_EnterConfigMode();
183 /* ALARM Config --------------------------------------------------------------*/
184 /* Set the ALARM MSB word */
185 RTC->ALRH = (AlarmValue & RTC_MSB_Mask) >> 16;
186 /* Set the ALARM LSB word */
187 RTC->ALRL = (AlarmValue & RTC_LSB_Mask);
189 RTC_ExitConfigMode();
192 /*******************************************************************************
193 * Function Name : RTC_GetDivider
194 * Description : Gets the RTC divider value.
197 * Return : RTC Divider value.
198 *******************************************************************************/
199 u32 RTC_GetDivider(void)
203 return (((u32)(RTC->DIVH & 0x000F) << 16 ) | Tmp);
206 /*******************************************************************************
207 * Function Name : RTC_WaitForLastTask
208 * Description : Waits until last write operation on RTC registers has finished.
209 * This function must be called before any write to RTC registers.
213 *******************************************************************************/
214 void RTC_WaitForLastTask(void)
216 /* Loop until RTOFF flag is set */
217 while ((RTC->CRL & RTC_FLAG_RTOFF) == RESET);
220 /*******************************************************************************
221 * Function Name : RTC_WaitForSynchro
222 * Description : Waits until the RTC registers (RTC_CNT, RTC_ALR and RTC_PRL)
223 * are synchronized with RTC APB clock.
224 * This function must be called before any read operation after
225 * an APB reset or an APB clock stop.
229 *******************************************************************************/
230 void RTC_WaitForSynchro(void)
233 RTC->CRL &= ~RTC_FLAG_RSF;
235 /* Loop until RSF flag is set */
236 while((RTC->CRL & RTC_FLAG_RSF)== RESET);
239 /*******************************************************************************
240 * Function Name : RTC_GetFlagStatus
241 * Description : Checks whether the specified RTC flag is set or not.
242 * Input : RTC_FLAG: specifies the flag to check.
243 * This parameter can be one the following values:
244 * - RTC_FLAG_RTOFF: RTC Operation OFF flag
245 * - RTC_FLAG_RSF: Registers Synchronized flag
246 * - RTC_FLAG_Overflow: Overflow interrupt flag
247 * - RTC_FLAG_Alarm: Alarm interrupt flag
248 * - RTC_FLAG_Second: Second interrupt flag
250 * Return : The new state of RTC_FLAG (SET or RESET).
251 *******************************************************************************/
252 FlagStatus RTC_GetFlagStatus(u16 RTC_FLAG)
254 if((RTC->CRL & RTC_FLAG) != RESET)
264 /*******************************************************************************
265 * Function Name : RTC_ClearFlag
266 * Description : Clears the RTC
\92s pending flags.
267 * Input : RTC_FLAG: specifies the flag to clear.
268 * This parameter can be a combination of one or more of
269 * the following values:
270 * - RTC_FLAG_RSF: Registers Synchronized flag. This flag
271 * is cleared only after an APB reset or an APB Clock stop.
272 * - RTC_FLAG_Overflow: Overflow interrupt flag
273 * - RTC_FLAG_Alarm: Alarm interrupt flag
274 * - RTC_FLAG_Second: Second interrupt flag
277 *******************************************************************************/
278 void RTC_ClearFlag(u16 RTC_FLAG)
280 /* Clear the coressponding RTC flag */
281 RTC->CRL &= ~RTC_FLAG;
284 /*******************************************************************************
285 * Function Name : RTC_GetITStatus
286 * Description : Checks whether the specified RTC interrupt has occured or not.
287 * Input : RTC_IT: specifies the RTC interrupts sources to check.
288 * This parameter can be a combination of one or more of
289 * the following values:
290 * - RTC_IT_Overflow: Overflow interrupt
291 * - RTC_IT_Alarm: Alarm interrupt
292 * - RTC_IT_Second: Second interrupt
294 * Return : The new state of the RTC_IT (SET or RESET).
295 *******************************************************************************/
296 ITStatus RTC_GetITStatus(u16 RTC_IT)
298 if(((RTC->CRH & RTC_IT) != RESET)&& ((RTC->CRL & RTC_IT) != RESET))
308 /*******************************************************************************
309 * Function Name : RTC_ClearITPendingBit
310 * Description : Clears the RTC
\92s interrupt pending bits.
311 * Input : RTC_IT: specifies the interrupt pending bit to clear.
312 * This parameter can be any combination of one or more of
313 * the following values:
314 * - RTC_IT_Overflow: Overflow interrupt
315 * - RTC_IT_Alarm: Alarm interrupt
316 * - RTC_IT_Second: Second interrupt
319 *******************************************************************************/
320 void RTC_ClearITPendingBit(u16 RTC_IT)
322 /* Clear the coressponding RTC pending bit */
326 /******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/