--- /dev/null
+/**\r
+ ******************************************************************************\r
+ * @file stm32f10x_rtc.c\r
+ * @author MCD Application Team\r
+ * @version V3.3.0\r
+ * @date 04/16/2010\r
+ * @brief This file provides all the RTC firmware functions.\r
+ ******************************************************************************\r
+ * @copy\r
+ *\r
+ * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS\r
+ * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE\r
+ * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY\r
+ * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING\r
+ * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE\r
+ * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.\r
+ *\r
+ * <h2><center>© COPYRIGHT 2010 STMicroelectronics</center></h2>\r
+ */ \r
+\r
+/* Includes ------------------------------------------------------------------*/\r
+#include "stm32f10x_rtc.h"\r
+\r
+/** @addtogroup STM32F10x_StdPeriph_Driver\r
+ * @{\r
+ */\r
+\r
+/** @defgroup RTC \r
+ * @brief RTC driver modules\r
+ * @{\r
+ */\r
+\r
+/** @defgroup RTC_Private_TypesDefinitions\r
+ * @{\r
+ */ \r
+/**\r
+ * @}\r
+ */\r
+\r
+/** @defgroup RTC_Private_Defines\r
+ * @{\r
+ */\r
+\r
+#define CRL_CNF_Set ((uint16_t)0x0010) /*!< Configuration Flag Enable Mask */\r
+#define CRL_CNF_Reset ((uint16_t)0xFFEF) /*!< Configuration Flag Disable Mask */\r
+#define RTC_LSB_Mask ((uint32_t)0x0000FFFF) /*!< RTC LSB Mask */\r
+#define PRLH_MSB_Mask ((uint32_t)0x000F0000) /*!< RTC Prescaler MSB Mask */\r
+\r
+/**\r
+ * @}\r
+ */\r
+\r
+/** @defgroup RTC_Private_Macros\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * @}\r
+ */\r
+\r
+/** @defgroup RTC_Private_Variables\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * @}\r
+ */\r
+\r
+/** @defgroup RTC_Private_FunctionPrototypes\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * @}\r
+ */\r
+\r
+/** @defgroup RTC_Private_Functions\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * @brief Enables or disables the specified RTC interrupts.\r
+ * @param RTC_IT: specifies the RTC interrupts sources to be enabled or disabled.\r
+ * This parameter can be any combination of the following values:\r
+ * @arg RTC_IT_OW: Overflow interrupt\r
+ * @arg RTC_IT_ALR: Alarm interrupt\r
+ * @arg RTC_IT_SEC: Second interrupt\r
+ * @param NewState: new state of the specified RTC interrupts.\r
+ * This parameter can be: ENABLE or DISABLE.\r
+ * @retval None\r
+ */\r
+void RTC_ITConfig(uint16_t RTC_IT, FunctionalState NewState)\r
+{\r
+ /* Check the parameters */\r
+ assert_param(IS_RTC_IT(RTC_IT)); \r
+ assert_param(IS_FUNCTIONAL_STATE(NewState));\r
+ \r
+ if (NewState != DISABLE)\r
+ {\r
+ RTC->CRH |= RTC_IT;\r
+ }\r
+ else\r
+ {\r
+ RTC->CRH &= (uint16_t)~RTC_IT;\r
+ }\r
+}\r
+\r
+/**\r
+ * @brief Enters the RTC configuration mode.\r
+ * @param None\r
+ * @retval None\r
+ */\r
+void RTC_EnterConfigMode(void)\r
+{\r
+ /* Set the CNF flag to enter in the Configuration Mode */\r
+ RTC->CRL |= CRL_CNF_Set;\r
+}\r
+\r
+/**\r
+ * @brief Exits from the RTC configuration mode.\r
+ * @param None\r
+ * @retval None\r
+ */\r
+void RTC_ExitConfigMode(void)\r
+{\r
+ /* Reset the CNF flag to exit from the Configuration Mode */\r
+ RTC->CRL &= CRL_CNF_Reset;\r
+}\r
+\r
+/**\r
+ * @brief Gets the RTC counter value.\r
+ * @param None\r
+ * @retval RTC counter value.\r
+ */\r
+uint32_t RTC_GetCounter(void)\r
+{\r
+ uint16_t tmp = 0;\r
+ tmp = RTC->CNTL;\r
+ return (((uint32_t)RTC->CNTH << 16 ) | tmp) ;\r
+}\r
+\r
+/**\r
+ * @brief Sets the RTC counter value.\r
+ * @param CounterValue: RTC counter new value.\r
+ * @retval None\r
+ */\r
+void RTC_SetCounter(uint32_t CounterValue)\r
+{ \r
+ RTC_EnterConfigMode();\r
+ /* Set RTC COUNTER MSB word */\r
+ RTC->CNTH = CounterValue >> 16;\r
+ /* Set RTC COUNTER LSB word */\r
+ RTC->CNTL = (CounterValue & RTC_LSB_Mask);\r
+ RTC_ExitConfigMode();\r
+}\r
+\r
+/**\r
+ * @brief Sets the RTC prescaler value.\r
+ * @param PrescalerValue: RTC prescaler new value.\r
+ * @retval None\r
+ */\r
+void RTC_SetPrescaler(uint32_t PrescalerValue)\r
+{\r
+ /* Check the parameters */\r
+ assert_param(IS_RTC_PRESCALER(PrescalerValue));\r
+ \r
+ RTC_EnterConfigMode();\r
+ /* Set RTC PRESCALER MSB word */\r
+ RTC->PRLH = (PrescalerValue & PRLH_MSB_Mask) >> 16;\r
+ /* Set RTC PRESCALER LSB word */\r
+ RTC->PRLL = (PrescalerValue & RTC_LSB_Mask);\r
+ RTC_ExitConfigMode();\r
+}\r
+\r
+/**\r
+ * @brief Sets the RTC alarm value.\r
+ * @param AlarmValue: RTC alarm new value.\r
+ * @retval None\r
+ */\r
+void RTC_SetAlarm(uint32_t AlarmValue)\r
+{ \r
+ RTC_EnterConfigMode();\r
+ /* Set the ALARM MSB word */\r
+ RTC->ALRH = AlarmValue >> 16;\r
+ /* Set the ALARM LSB word */\r
+ RTC->ALRL = (AlarmValue & RTC_LSB_Mask);\r
+ RTC_ExitConfigMode();\r
+}\r
+\r
+/**\r
+ * @brief Gets the RTC divider value.\r
+ * @param None\r
+ * @retval RTC Divider value.\r
+ */\r
+uint32_t RTC_GetDivider(void)\r
+{\r
+ uint32_t tmp = 0x00;\r
+ tmp = ((uint32_t)RTC->DIVH & (uint32_t)0x000F) << 16;\r
+ tmp |= RTC->DIVL;\r
+ return tmp;\r
+}\r
+\r
+/**\r
+ * @brief Waits until last write operation on RTC registers has finished.\r
+ * @note This function must be called before any write to RTC registers.\r
+ * @param None\r
+ * @retval None\r
+ */\r
+void RTC_WaitForLastTask(void)\r
+{\r
+ /* Loop until RTOFF flag is set */\r
+ while ((RTC->CRL & RTC_FLAG_RTOFF) == (uint16_t)RESET)\r
+ {\r
+ }\r
+}\r
+\r
+/**\r
+ * @brief Waits until the RTC registers (RTC_CNT, RTC_ALR and RTC_PRL)\r
+ * are synchronized with RTC APB clock.\r
+ * @note This function must be called before any read operation after an APB reset\r
+ * or an APB clock stop.\r
+ * @param None\r
+ * @retval None\r
+ */\r
+void RTC_WaitForSynchro(void)\r
+{\r
+ /* Clear RSF flag */\r
+ RTC->CRL &= (uint16_t)~RTC_FLAG_RSF;\r
+ /* Loop until RSF flag is set */\r
+ while ((RTC->CRL & RTC_FLAG_RSF) == (uint16_t)RESET)\r
+ {\r
+ }\r
+}\r
+\r
+/**\r
+ * @brief Checks whether the specified RTC flag is set or not.\r
+ * @param RTC_FLAG: specifies the flag to check.\r
+ * This parameter can be one the following values:\r
+ * @arg RTC_FLAG_RTOFF: RTC Operation OFF flag\r
+ * @arg RTC_FLAG_RSF: Registers Synchronized flag\r
+ * @arg RTC_FLAG_OW: Overflow flag\r
+ * @arg RTC_FLAG_ALR: Alarm flag\r
+ * @arg RTC_FLAG_SEC: Second flag\r
+ * @retval The new state of RTC_FLAG (SET or RESET).\r
+ */\r
+FlagStatus RTC_GetFlagStatus(uint16_t RTC_FLAG)\r
+{\r
+ FlagStatus bitstatus = RESET;\r
+ \r
+ /* Check the parameters */\r
+ assert_param(IS_RTC_GET_FLAG(RTC_FLAG)); \r
+ \r
+ if ((RTC->CRL & RTC_FLAG) != (uint16_t)RESET)\r
+ {\r
+ bitstatus = SET;\r
+ }\r
+ else\r
+ {\r
+ bitstatus = RESET;\r
+ }\r
+ return bitstatus;\r
+}\r
+\r
+/**\r
+ * @brief Clears the RTC\92s pending flags.\r
+ * @param RTC_FLAG: specifies the flag to clear.\r
+ * This parameter can be any combination of the following values:\r
+ * @arg RTC_FLAG_RSF: Registers Synchronized flag. This flag is cleared only after\r
+ * an APB reset or an APB Clock stop.\r
+ * @arg RTC_FLAG_OW: Overflow flag\r
+ * @arg RTC_FLAG_ALR: Alarm flag\r
+ * @arg RTC_FLAG_SEC: Second flag\r
+ * @retval None\r
+ */\r
+void RTC_ClearFlag(uint16_t RTC_FLAG)\r
+{\r
+ /* Check the parameters */\r
+ assert_param(IS_RTC_CLEAR_FLAG(RTC_FLAG)); \r
+ \r
+ /* Clear the coressponding RTC flag */\r
+ RTC->CRL &= (uint16_t)~RTC_FLAG;\r
+}\r
+\r
+/**\r
+ * @brief Checks whether the specified RTC interrupt has occured or not.\r
+ * @param RTC_IT: specifies the RTC interrupts sources to check.\r
+ * This parameter can be one of the following values:\r
+ * @arg RTC_IT_OW: Overflow interrupt\r
+ * @arg RTC_IT_ALR: Alarm interrupt\r
+ * @arg RTC_IT_SEC: Second interrupt\r
+ * @retval The new state of the RTC_IT (SET or RESET).\r
+ */\r
+ITStatus RTC_GetITStatus(uint16_t RTC_IT)\r
+{\r
+ ITStatus bitstatus = RESET;\r
+ /* Check the parameters */\r
+ assert_param(IS_RTC_GET_IT(RTC_IT)); \r
+ \r
+ bitstatus = (ITStatus)(RTC->CRL & RTC_IT);\r
+ if (((RTC->CRH & RTC_IT) != (uint16_t)RESET) && (bitstatus != (uint16_t)RESET))\r
+ {\r
+ bitstatus = SET;\r
+ }\r
+ else\r
+ {\r
+ bitstatus = RESET;\r
+ }\r
+ return bitstatus;\r
+}\r
+\r
+/**\r
+ * @brief Clears the RTC\92s interrupt pending bits.\r
+ * @param RTC_IT: specifies the interrupt pending bit to clear.\r
+ * This parameter can be any combination of the following values:\r
+ * @arg RTC_IT_OW: Overflow interrupt\r
+ * @arg RTC_IT_ALR: Alarm interrupt\r
+ * @arg RTC_IT_SEC: Second interrupt\r
+ * @retval None\r
+ */\r
+void RTC_ClearITPendingBit(uint16_t RTC_IT)\r
+{\r
+ /* Check the parameters */\r
+ assert_param(IS_RTC_IT(RTC_IT)); \r
+ \r
+ /* Clear the coressponding RTC pending bit */\r
+ RTC->CRL &= (uint16_t)~RTC_IT;\r
+}\r
+\r
+/**\r
+ * @}\r
+ */\r
+\r
+/**\r
+ * @}\r
+ */\r
+\r
+/**\r
+ * @}\r
+ */\r
+\r
+/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/\r