mbed library sources modified for open wear

Dependents:   openwear-lifelogger-example

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Mon Dec 02 11:30:05 2013 +0000
Revision:
52:a51c77007319
Child:
70:c1fbde68b492
Synchronized with git revision 49df530ae72ce97ccc773d1f2c13b38e868e6abd

Full URL: https://github.com/mbedmicro/mbed/commit/49df530ae72ce97ccc773d1f2c13b38e868e6abd/

Add STMicroelectronics NUCLEO_F103RB target

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 52:a51c77007319 1 /**
mbed_official 52:a51c77007319 2 ******************************************************************************
mbed_official 52:a51c77007319 3 * @file stm32f10x_rtc.c
mbed_official 52:a51c77007319 4 * @author MCD Application Team
mbed_official 52:a51c77007319 5 * @version V3.5.0
mbed_official 52:a51c77007319 6 * @date 11-March-2011
mbed_official 52:a51c77007319 7 * @brief This file provides all the RTC firmware functions.
mbed_official 52:a51c77007319 8 ******************************************************************************
mbed_official 52:a51c77007319 9 * @attention
mbed_official 52:a51c77007319 10 *
mbed_official 52:a51c77007319 11 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
mbed_official 52:a51c77007319 12 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
mbed_official 52:a51c77007319 13 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
mbed_official 52:a51c77007319 14 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
mbed_official 52:a51c77007319 15 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
mbed_official 52:a51c77007319 16 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
mbed_official 52:a51c77007319 17 *
mbed_official 52:a51c77007319 18 * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
mbed_official 52:a51c77007319 19 ******************************************************************************
mbed_official 52:a51c77007319 20 */
mbed_official 52:a51c77007319 21
mbed_official 52:a51c77007319 22 /* Includes ------------------------------------------------------------------*/
mbed_official 52:a51c77007319 23 #include "stm32f10x_rtc.h"
mbed_official 52:a51c77007319 24
mbed_official 52:a51c77007319 25 /** @addtogroup STM32F10x_StdPeriph_Driver
mbed_official 52:a51c77007319 26 * @{
mbed_official 52:a51c77007319 27 */
mbed_official 52:a51c77007319 28
mbed_official 52:a51c77007319 29 /** @defgroup RTC
mbed_official 52:a51c77007319 30 * @brief RTC driver modules
mbed_official 52:a51c77007319 31 * @{
mbed_official 52:a51c77007319 32 */
mbed_official 52:a51c77007319 33
mbed_official 52:a51c77007319 34 /** @defgroup RTC_Private_TypesDefinitions
mbed_official 52:a51c77007319 35 * @{
mbed_official 52:a51c77007319 36 */
mbed_official 52:a51c77007319 37 /**
mbed_official 52:a51c77007319 38 * @}
mbed_official 52:a51c77007319 39 */
mbed_official 52:a51c77007319 40
mbed_official 52:a51c77007319 41 /** @defgroup RTC_Private_Defines
mbed_official 52:a51c77007319 42 * @{
mbed_official 52:a51c77007319 43 */
mbed_official 52:a51c77007319 44 #define RTC_LSB_MASK ((uint32_t)0x0000FFFF) /*!< RTC LSB Mask */
mbed_official 52:a51c77007319 45 #define PRLH_MSB_MASK ((uint32_t)0x000F0000) /*!< RTC Prescaler MSB Mask */
mbed_official 52:a51c77007319 46
mbed_official 52:a51c77007319 47 /**
mbed_official 52:a51c77007319 48 * @}
mbed_official 52:a51c77007319 49 */
mbed_official 52:a51c77007319 50
mbed_official 52:a51c77007319 51 /** @defgroup RTC_Private_Macros
mbed_official 52:a51c77007319 52 * @{
mbed_official 52:a51c77007319 53 */
mbed_official 52:a51c77007319 54
mbed_official 52:a51c77007319 55 /**
mbed_official 52:a51c77007319 56 * @}
mbed_official 52:a51c77007319 57 */
mbed_official 52:a51c77007319 58
mbed_official 52:a51c77007319 59 /** @defgroup RTC_Private_Variables
mbed_official 52:a51c77007319 60 * @{
mbed_official 52:a51c77007319 61 */
mbed_official 52:a51c77007319 62
mbed_official 52:a51c77007319 63 /**
mbed_official 52:a51c77007319 64 * @}
mbed_official 52:a51c77007319 65 */
mbed_official 52:a51c77007319 66
mbed_official 52:a51c77007319 67 /** @defgroup RTC_Private_FunctionPrototypes
mbed_official 52:a51c77007319 68 * @{
mbed_official 52:a51c77007319 69 */
mbed_official 52:a51c77007319 70
mbed_official 52:a51c77007319 71 /**
mbed_official 52:a51c77007319 72 * @}
mbed_official 52:a51c77007319 73 */
mbed_official 52:a51c77007319 74
mbed_official 52:a51c77007319 75 /** @defgroup RTC_Private_Functions
mbed_official 52:a51c77007319 76 * @{
mbed_official 52:a51c77007319 77 */
mbed_official 52:a51c77007319 78
mbed_official 52:a51c77007319 79 /**
mbed_official 52:a51c77007319 80 * @brief Enables or disables the specified RTC interrupts.
mbed_official 52:a51c77007319 81 * @param RTC_IT: specifies the RTC interrupts sources to be enabled or disabled.
mbed_official 52:a51c77007319 82 * This parameter can be any combination of the following values:
mbed_official 52:a51c77007319 83 * @arg RTC_IT_OW: Overflow interrupt
mbed_official 52:a51c77007319 84 * @arg RTC_IT_ALR: Alarm interrupt
mbed_official 52:a51c77007319 85 * @arg RTC_IT_SEC: Second interrupt
mbed_official 52:a51c77007319 86 * @param NewState: new state of the specified RTC interrupts.
mbed_official 52:a51c77007319 87 * This parameter can be: ENABLE or DISABLE.
mbed_official 52:a51c77007319 88 * @retval None
mbed_official 52:a51c77007319 89 */
mbed_official 52:a51c77007319 90 void RTC_ITConfig(uint16_t RTC_IT, FunctionalState NewState)
mbed_official 52:a51c77007319 91 {
mbed_official 52:a51c77007319 92 /* Check the parameters */
mbed_official 52:a51c77007319 93 assert_param(IS_RTC_IT(RTC_IT));
mbed_official 52:a51c77007319 94 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 52:a51c77007319 95
mbed_official 52:a51c77007319 96 if (NewState != DISABLE)
mbed_official 52:a51c77007319 97 {
mbed_official 52:a51c77007319 98 RTC->CRH |= RTC_IT;
mbed_official 52:a51c77007319 99 }
mbed_official 52:a51c77007319 100 else
mbed_official 52:a51c77007319 101 {
mbed_official 52:a51c77007319 102 RTC->CRH &= (uint16_t)~RTC_IT;
mbed_official 52:a51c77007319 103 }
mbed_official 52:a51c77007319 104 }
mbed_official 52:a51c77007319 105
mbed_official 52:a51c77007319 106 /**
mbed_official 52:a51c77007319 107 * @brief Enters the RTC configuration mode.
mbed_official 52:a51c77007319 108 * @param None
mbed_official 52:a51c77007319 109 * @retval None
mbed_official 52:a51c77007319 110 */
mbed_official 52:a51c77007319 111 void RTC_EnterConfigMode(void)
mbed_official 52:a51c77007319 112 {
mbed_official 52:a51c77007319 113 /* Set the CNF flag to enter in the Configuration Mode */
mbed_official 52:a51c77007319 114 RTC->CRL |= RTC_CRL_CNF;
mbed_official 52:a51c77007319 115 }
mbed_official 52:a51c77007319 116
mbed_official 52:a51c77007319 117 /**
mbed_official 52:a51c77007319 118 * @brief Exits from the RTC configuration mode.
mbed_official 52:a51c77007319 119 * @param None
mbed_official 52:a51c77007319 120 * @retval None
mbed_official 52:a51c77007319 121 */
mbed_official 52:a51c77007319 122 void RTC_ExitConfigMode(void)
mbed_official 52:a51c77007319 123 {
mbed_official 52:a51c77007319 124 /* Reset the CNF flag to exit from the Configuration Mode */
mbed_official 52:a51c77007319 125 RTC->CRL &= (uint16_t)~((uint16_t)RTC_CRL_CNF);
mbed_official 52:a51c77007319 126 }
mbed_official 52:a51c77007319 127
mbed_official 52:a51c77007319 128 /**
mbed_official 52:a51c77007319 129 * @brief Gets the RTC counter value.
mbed_official 52:a51c77007319 130 * @param None
mbed_official 52:a51c77007319 131 * @retval RTC counter value.
mbed_official 52:a51c77007319 132 */
mbed_official 52:a51c77007319 133 uint32_t RTC_GetCounter(void)
mbed_official 52:a51c77007319 134 {
mbed_official 52:a51c77007319 135 uint16_t tmp = 0;
mbed_official 52:a51c77007319 136 tmp = RTC->CNTL;
mbed_official 52:a51c77007319 137 return (((uint32_t)RTC->CNTH << 16 ) | tmp) ;
mbed_official 52:a51c77007319 138 }
mbed_official 52:a51c77007319 139
mbed_official 52:a51c77007319 140 /**
mbed_official 52:a51c77007319 141 * @brief Sets the RTC counter value.
mbed_official 52:a51c77007319 142 * @param CounterValue: RTC counter new value.
mbed_official 52:a51c77007319 143 * @retval None
mbed_official 52:a51c77007319 144 */
mbed_official 52:a51c77007319 145 void RTC_SetCounter(uint32_t CounterValue)
mbed_official 52:a51c77007319 146 {
mbed_official 52:a51c77007319 147 RTC_EnterConfigMode();
mbed_official 52:a51c77007319 148 /* Set RTC COUNTER MSB word */
mbed_official 52:a51c77007319 149 RTC->CNTH = CounterValue >> 16;
mbed_official 52:a51c77007319 150 /* Set RTC COUNTER LSB word */
mbed_official 52:a51c77007319 151 RTC->CNTL = (CounterValue & RTC_LSB_MASK);
mbed_official 52:a51c77007319 152 RTC_ExitConfigMode();
mbed_official 52:a51c77007319 153 }
mbed_official 52:a51c77007319 154
mbed_official 52:a51c77007319 155 /**
mbed_official 52:a51c77007319 156 * @brief Sets the RTC prescaler value.
mbed_official 52:a51c77007319 157 * @param PrescalerValue: RTC prescaler new value.
mbed_official 52:a51c77007319 158 * @retval None
mbed_official 52:a51c77007319 159 */
mbed_official 52:a51c77007319 160 void RTC_SetPrescaler(uint32_t PrescalerValue)
mbed_official 52:a51c77007319 161 {
mbed_official 52:a51c77007319 162 /* Check the parameters */
mbed_official 52:a51c77007319 163 assert_param(IS_RTC_PRESCALER(PrescalerValue));
mbed_official 52:a51c77007319 164
mbed_official 52:a51c77007319 165 RTC_EnterConfigMode();
mbed_official 52:a51c77007319 166 /* Set RTC PRESCALER MSB word */
mbed_official 52:a51c77007319 167 RTC->PRLH = (PrescalerValue & PRLH_MSB_MASK) >> 16;
mbed_official 52:a51c77007319 168 /* Set RTC PRESCALER LSB word */
mbed_official 52:a51c77007319 169 RTC->PRLL = (PrescalerValue & RTC_LSB_MASK);
mbed_official 52:a51c77007319 170 RTC_ExitConfigMode();
mbed_official 52:a51c77007319 171 }
mbed_official 52:a51c77007319 172
mbed_official 52:a51c77007319 173 /**
mbed_official 52:a51c77007319 174 * @brief Sets the RTC alarm value.
mbed_official 52:a51c77007319 175 * @param AlarmValue: RTC alarm new value.
mbed_official 52:a51c77007319 176 * @retval None
mbed_official 52:a51c77007319 177 */
mbed_official 52:a51c77007319 178 void RTC_SetAlarm(uint32_t AlarmValue)
mbed_official 52:a51c77007319 179 {
mbed_official 52:a51c77007319 180 RTC_EnterConfigMode();
mbed_official 52:a51c77007319 181 /* Set the ALARM MSB word */
mbed_official 52:a51c77007319 182 RTC->ALRH = AlarmValue >> 16;
mbed_official 52:a51c77007319 183 /* Set the ALARM LSB word */
mbed_official 52:a51c77007319 184 RTC->ALRL = (AlarmValue & RTC_LSB_MASK);
mbed_official 52:a51c77007319 185 RTC_ExitConfigMode();
mbed_official 52:a51c77007319 186 }
mbed_official 52:a51c77007319 187
mbed_official 52:a51c77007319 188 /**
mbed_official 52:a51c77007319 189 * @brief Gets the RTC divider value.
mbed_official 52:a51c77007319 190 * @param None
mbed_official 52:a51c77007319 191 * @retval RTC Divider value.
mbed_official 52:a51c77007319 192 */
mbed_official 52:a51c77007319 193 uint32_t RTC_GetDivider(void)
mbed_official 52:a51c77007319 194 {
mbed_official 52:a51c77007319 195 uint32_t tmp = 0x00;
mbed_official 52:a51c77007319 196 tmp = ((uint32_t)RTC->DIVH & (uint32_t)0x000F) << 16;
mbed_official 52:a51c77007319 197 tmp |= RTC->DIVL;
mbed_official 52:a51c77007319 198 return tmp;
mbed_official 52:a51c77007319 199 }
mbed_official 52:a51c77007319 200
mbed_official 52:a51c77007319 201 /**
mbed_official 52:a51c77007319 202 * @brief Waits until last write operation on RTC registers has finished.
mbed_official 52:a51c77007319 203 * @note This function must be called before any write to RTC registers.
mbed_official 52:a51c77007319 204 * @param None
mbed_official 52:a51c77007319 205 * @retval None
mbed_official 52:a51c77007319 206 */
mbed_official 52:a51c77007319 207 void RTC_WaitForLastTask(void)
mbed_official 52:a51c77007319 208 {
mbed_official 52:a51c77007319 209 /* Loop until RTOFF flag is set */
mbed_official 52:a51c77007319 210 while ((RTC->CRL & RTC_FLAG_RTOFF) == (uint16_t)RESET)
mbed_official 52:a51c77007319 211 {
mbed_official 52:a51c77007319 212 }
mbed_official 52:a51c77007319 213 }
mbed_official 52:a51c77007319 214
mbed_official 52:a51c77007319 215 /**
mbed_official 52:a51c77007319 216 * @brief Waits until the RTC registers (RTC_CNT, RTC_ALR and RTC_PRL)
mbed_official 52:a51c77007319 217 * are synchronized with RTC APB clock.
mbed_official 52:a51c77007319 218 * @note This function must be called before any read operation after an APB reset
mbed_official 52:a51c77007319 219 * or an APB clock stop.
mbed_official 52:a51c77007319 220 * @param None
mbed_official 52:a51c77007319 221 * @retval None
mbed_official 52:a51c77007319 222 */
mbed_official 52:a51c77007319 223 void RTC_WaitForSynchro(void)
mbed_official 52:a51c77007319 224 {
mbed_official 52:a51c77007319 225 /* Clear RSF flag */
mbed_official 52:a51c77007319 226 RTC->CRL &= (uint16_t)~RTC_FLAG_RSF;
mbed_official 52:a51c77007319 227 /* Loop until RSF flag is set */
mbed_official 52:a51c77007319 228 while ((RTC->CRL & RTC_FLAG_RSF) == (uint16_t)RESET)
mbed_official 52:a51c77007319 229 {
mbed_official 52:a51c77007319 230 }
mbed_official 52:a51c77007319 231 }
mbed_official 52:a51c77007319 232
mbed_official 52:a51c77007319 233 /**
mbed_official 52:a51c77007319 234 * @brief Checks whether the specified RTC flag is set or not.
mbed_official 52:a51c77007319 235 * @param RTC_FLAG: specifies the flag to check.
mbed_official 52:a51c77007319 236 * This parameter can be one the following values:
mbed_official 52:a51c77007319 237 * @arg RTC_FLAG_RTOFF: RTC Operation OFF flag
mbed_official 52:a51c77007319 238 * @arg RTC_FLAG_RSF: Registers Synchronized flag
mbed_official 52:a51c77007319 239 * @arg RTC_FLAG_OW: Overflow flag
mbed_official 52:a51c77007319 240 * @arg RTC_FLAG_ALR: Alarm flag
mbed_official 52:a51c77007319 241 * @arg RTC_FLAG_SEC: Second flag
mbed_official 52:a51c77007319 242 * @retval The new state of RTC_FLAG (SET or RESET).
mbed_official 52:a51c77007319 243 */
mbed_official 52:a51c77007319 244 FlagStatus RTC_GetFlagStatus(uint16_t RTC_FLAG)
mbed_official 52:a51c77007319 245 {
mbed_official 52:a51c77007319 246 FlagStatus bitstatus = RESET;
mbed_official 52:a51c77007319 247
mbed_official 52:a51c77007319 248 /* Check the parameters */
mbed_official 52:a51c77007319 249 assert_param(IS_RTC_GET_FLAG(RTC_FLAG));
mbed_official 52:a51c77007319 250
mbed_official 52:a51c77007319 251 if ((RTC->CRL & RTC_FLAG) != (uint16_t)RESET)
mbed_official 52:a51c77007319 252 {
mbed_official 52:a51c77007319 253 bitstatus = SET;
mbed_official 52:a51c77007319 254 }
mbed_official 52:a51c77007319 255 else
mbed_official 52:a51c77007319 256 {
mbed_official 52:a51c77007319 257 bitstatus = RESET;
mbed_official 52:a51c77007319 258 }
mbed_official 52:a51c77007319 259 return bitstatus;
mbed_official 52:a51c77007319 260 }
mbed_official 52:a51c77007319 261
mbed_official 52:a51c77007319 262 /**
mbed_official 52:a51c77007319 263 * @brief Clears the RTC's pending flags.
mbed_official 52:a51c77007319 264 * @param RTC_FLAG: specifies the flag to clear.
mbed_official 52:a51c77007319 265 * This parameter can be any combination of the following values:
mbed_official 52:a51c77007319 266 * @arg RTC_FLAG_RSF: Registers Synchronized flag. This flag is cleared only after
mbed_official 52:a51c77007319 267 * an APB reset or an APB Clock stop.
mbed_official 52:a51c77007319 268 * @arg RTC_FLAG_OW: Overflow flag
mbed_official 52:a51c77007319 269 * @arg RTC_FLAG_ALR: Alarm flag
mbed_official 52:a51c77007319 270 * @arg RTC_FLAG_SEC: Second flag
mbed_official 52:a51c77007319 271 * @retval None
mbed_official 52:a51c77007319 272 */
mbed_official 52:a51c77007319 273 void RTC_ClearFlag(uint16_t RTC_FLAG)
mbed_official 52:a51c77007319 274 {
mbed_official 52:a51c77007319 275 /* Check the parameters */
mbed_official 52:a51c77007319 276 assert_param(IS_RTC_CLEAR_FLAG(RTC_FLAG));
mbed_official 52:a51c77007319 277
mbed_official 52:a51c77007319 278 /* Clear the corresponding RTC flag */
mbed_official 52:a51c77007319 279 RTC->CRL &= (uint16_t)~RTC_FLAG;
mbed_official 52:a51c77007319 280 }
mbed_official 52:a51c77007319 281
mbed_official 52:a51c77007319 282 /**
mbed_official 52:a51c77007319 283 * @brief Checks whether the specified RTC interrupt has occurred or not.
mbed_official 52:a51c77007319 284 * @param RTC_IT: specifies the RTC interrupts sources to check.
mbed_official 52:a51c77007319 285 * This parameter can be one of the following values:
mbed_official 52:a51c77007319 286 * @arg RTC_IT_OW: Overflow interrupt
mbed_official 52:a51c77007319 287 * @arg RTC_IT_ALR: Alarm interrupt
mbed_official 52:a51c77007319 288 * @arg RTC_IT_SEC: Second interrupt
mbed_official 52:a51c77007319 289 * @retval The new state of the RTC_IT (SET or RESET).
mbed_official 52:a51c77007319 290 */
mbed_official 52:a51c77007319 291 ITStatus RTC_GetITStatus(uint16_t RTC_IT)
mbed_official 52:a51c77007319 292 {
mbed_official 52:a51c77007319 293 ITStatus bitstatus = RESET;
mbed_official 52:a51c77007319 294 /* Check the parameters */
mbed_official 52:a51c77007319 295 assert_param(IS_RTC_GET_IT(RTC_IT));
mbed_official 52:a51c77007319 296
mbed_official 52:a51c77007319 297 bitstatus = (ITStatus)(RTC->CRL & RTC_IT);
mbed_official 52:a51c77007319 298 if (((RTC->CRH & RTC_IT) != (uint16_t)RESET) && (bitstatus != (uint16_t)RESET))
mbed_official 52:a51c77007319 299 {
mbed_official 52:a51c77007319 300 bitstatus = SET;
mbed_official 52:a51c77007319 301 }
mbed_official 52:a51c77007319 302 else
mbed_official 52:a51c77007319 303 {
mbed_official 52:a51c77007319 304 bitstatus = RESET;
mbed_official 52:a51c77007319 305 }
mbed_official 52:a51c77007319 306 return bitstatus;
mbed_official 52:a51c77007319 307 }
mbed_official 52:a51c77007319 308
mbed_official 52:a51c77007319 309 /**
mbed_official 52:a51c77007319 310 * @brief Clears the RTC's interrupt pending bits.
mbed_official 52:a51c77007319 311 * @param RTC_IT: specifies the interrupt pending bit to clear.
mbed_official 52:a51c77007319 312 * This parameter can be any combination of the following values:
mbed_official 52:a51c77007319 313 * @arg RTC_IT_OW: Overflow interrupt
mbed_official 52:a51c77007319 314 * @arg RTC_IT_ALR: Alarm interrupt
mbed_official 52:a51c77007319 315 * @arg RTC_IT_SEC: Second interrupt
mbed_official 52:a51c77007319 316 * @retval None
mbed_official 52:a51c77007319 317 */
mbed_official 52:a51c77007319 318 void RTC_ClearITPendingBit(uint16_t RTC_IT)
mbed_official 52:a51c77007319 319 {
mbed_official 52:a51c77007319 320 /* Check the parameters */
mbed_official 52:a51c77007319 321 assert_param(IS_RTC_IT(RTC_IT));
mbed_official 52:a51c77007319 322
mbed_official 52:a51c77007319 323 /* Clear the corresponding RTC pending bit */
mbed_official 52:a51c77007319 324 RTC->CRL &= (uint16_t)~RTC_IT;
mbed_official 52:a51c77007319 325 }
mbed_official 52:a51c77007319 326
mbed_official 52:a51c77007319 327 /**
mbed_official 52:a51c77007319 328 * @}
mbed_official 52:a51c77007319 329 */
mbed_official 52:a51c77007319 330
mbed_official 52:a51c77007319 331 /**
mbed_official 52:a51c77007319 332 * @}
mbed_official 52:a51c77007319 333 */
mbed_official 52:a51c77007319 334
mbed_official 52:a51c77007319 335 /**
mbed_official 52:a51c77007319 336 * @}
mbed_official 52:a51c77007319 337 */
mbed_official 52:a51c77007319 338
mbed_official 52:a51c77007319 339 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/