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