NXP's driver library for LPC17xx, ported to mbed's online compiler. Not tested! I had to fix a lot of warings and found a couple of pretty obvious bugs, so the chances are there are more. Original: http://ics.nxp.com/support/documents/microcontrollers/zip/lpc17xx.cmsis.driver.library.zip
lpc17xx_rtc.c
00001 /** 00002 * @file : lpc17xx_rtc.c 00003 * @brief : Contains all functions support for RTC firmware library on LPC17xx 00004 * @version : 1.0 00005 * @date : 23. Apr. 2009 00006 * @author : HieuNguyen 00007 ************************************************************************** 00008 * Software that is described herein is for illustrative purposes only 00009 * which provides customers with programming information regarding the 00010 * products. This software is supplied "AS IS" without any warranties. 00011 * NXP Semiconductors assumes no responsibility or liability for the 00012 * use of the software, conveys no license or title under any patent, 00013 * copyright, or mask work right to the product. NXP Semiconductors 00014 * reserves the right to make changes in the software without 00015 * notification. NXP Semiconductors also make no representation or 00016 * warranty that such application will be suitable for the specified 00017 * use without further testing or modification. 00018 **********************************************************************/ 00019 00020 00021 /* Peripheral group ----------------------------------------------------------- */ 00022 /** @addtogroup RTC 00023 * @{ 00024 */ 00025 00026 /* Includes ------------------------------------------------------------------- */ 00027 #include "lpc17xx_rtc.h" 00028 #include "lpc17xx_clkpwr.h" 00029 00030 00031 /* If this source file built with example, the LPC17xx FW library configuration 00032 * file in each example directory ("lpc17xx_libcfg.h") must be included, 00033 * otherwise the default FW library configuration file must be included instead 00034 */ 00035 #ifdef __BUILD_WITH_EXAMPLE__ 00036 #include "lpc17xx_libcfg.h" 00037 #else 00038 #include "lpc17xx_libcfg_default.h" 00039 #endif /* __BUILD_WITH_EXAMPLE__ */ 00040 00041 00042 #ifdef _RTC 00043 00044 /* Public Functions ----------------------------------------------------------- */ 00045 /** @addtogroup RTC_Public_Functions 00046 * @{ 00047 */ 00048 00049 /********************************************************************//** 00050 * @brief Initializes the RTC peripheral. 00051 * @param[in] RTCx RTC peripheral selected, should be RTC 00052 * @return None 00053 *********************************************************************/ 00054 void RTC_Init (LPC_RTC_TypeDef *RTCx) 00055 { 00056 CHECK_PARAM(PARAM_RTCx(RTCx)); 00057 00058 /* Set up clock and power for RTC module */ 00059 CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCRTC, ENABLE); 00060 00061 // Clear all register to be default 00062 RTCx->ILR = 0x00; 00063 RTCx->CCR = 0x00; 00064 RTCx->CIIR = 0x00; 00065 RTCx->AMR = 0xFF; 00066 RTCx->CALIBRATION = 0x00; 00067 } 00068 00069 00070 /*********************************************************************//** 00071 * @brief De-initializes the RTC peripheral registers to their 00072 * default reset values. 00073 * @param[in] RTCx RTC peripheral selected, should be RTC 00074 * @return None 00075 **********************************************************************/ 00076 void RTC_DeInit(LPC_RTC_TypeDef *RTCx) 00077 { 00078 CHECK_PARAM(PARAM_RTCx(RTCx)); 00079 00080 RTCx->CCR = 0x00; 00081 // Disable power and clock for RTC module 00082 CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCRTC, DISABLE); 00083 } 00084 00085 /*********************************************************************//** 00086 * @brief Reset clock tick counter in RTC peripheral 00087 * @param[in] RTCx RTC peripheral selected, should be RTC 00088 * @return None 00089 **********************************************************************/ 00090 void RTC_ResetClockTickCounter(LPC_RTC_TypeDef *RTCx) 00091 { 00092 CHECK_PARAM(PARAM_RTCx(RTCx)); 00093 00094 RTCx->CCR |= RTC_CCR_CTCRST; 00095 RTCx->CCR &= (~RTC_CCR_CTCRST) & RTC_CCR_BITMASK; 00096 } 00097 00098 /*********************************************************************//** 00099 * @brief Start/Stop RTC peripheral 00100 * @param[in] RTCx RTC peripheral selected, should be RTC 00101 * @param[in] NewState New State of this function, should be: 00102 * - ENABLE: The time counters are enabled 00103 * - DISABLE: The time counters are disabled 00104 * @return None 00105 **********************************************************************/ 00106 void RTC_Cmd (LPC_RTC_TypeDef *RTCx, FunctionalState NewState) 00107 { 00108 CHECK_PARAM(PARAM_RTCx(RTCx)); 00109 CHECK_PARAM(PARAM_FUNCTIONALSTATE(NewState)); 00110 00111 if (NewState == ENABLE) 00112 { 00113 RTCx->CCR |= RTC_CCR_CLKEN; 00114 } 00115 else 00116 { 00117 RTCx->CCR &= (~RTC_CCR_CLKEN) & RTC_CCR_BITMASK; 00118 } 00119 } 00120 00121 00122 /*********************************************************************//** 00123 * @brief Enable/Disable Counter increment interrupt for each time type 00124 * in RTC peripheral 00125 * @param[in] RTCx RTC peripheral selected, should be RTC 00126 * @param[in] CntIncrIntType: Counter Increment Interrupt type, 00127 * an increment of this type value below will generates 00128 * an interrupt, should be: 00129 * - RTC_TIMETYPE_SECOND 00130 * - RTC_TIMETYPE_MINUTE 00131 * - RTC_TIMETYPE_HOUR 00132 * - RTC_TIMETYPE_DAYOFWEEK 00133 * - RTC_TIMETYPE_DAYOFMONTH 00134 * - RTC_TIMETYPE_DAYOFYEAR 00135 * - RTC_TIMETYPE_MONTH 00136 * - RTC_TIMETYPE_YEAR 00137 * @param[in] NewState New State of this function, should be: 00138 * - ENABLE: Counter Increment interrupt for this 00139 * time type are enabled 00140 * - DISABLE: Counter Increment interrupt for this 00141 * time type are disabled 00142 * @return None 00143 **********************************************************************/ 00144 void RTC_CntIncrIntConfig (LPC_RTC_TypeDef *RTCx, uint32_t CntIncrIntType, \ 00145 FunctionalState NewState) 00146 { 00147 CHECK_PARAM(PARAM_RTCx(RTCx)); 00148 CHECK_PARAM(PARAM_FUNCTIONALSTATE(NewState)); 00149 CHECK_PARAM(PARAM_RTC_TIMETYPE(CntIncrIntType)); 00150 00151 if (NewState == ENABLE) 00152 { 00153 switch (CntIncrIntType) 00154 { 00155 case RTC_TIMETYPE_SECOND : 00156 RTCx->CIIR |= RTC_CIIR_IMSEC; 00157 break; 00158 case RTC_TIMETYPE_MINUTE : 00159 RTCx->CIIR |= RTC_CIIR_IMMIN; 00160 break; 00161 case RTC_TIMETYPE_HOUR : 00162 RTCx->CIIR |= RTC_CIIR_IMHOUR; 00163 break; 00164 case RTC_TIMETYPE_DAYOFWEEK : 00165 RTCx->CIIR |= RTC_CIIR_IMDOW; 00166 break; 00167 case RTC_TIMETYPE_DAYOFMONTH : 00168 RTCx->CIIR |= RTC_CIIR_IMDOM; 00169 break; 00170 case RTC_TIMETYPE_DAYOFYEAR : 00171 RTCx->CIIR |= RTC_CIIR_IMDOY; 00172 break; 00173 case RTC_TIMETYPE_MONTH : 00174 RTCx->CIIR |= RTC_CIIR_IMMON; 00175 break; 00176 case RTC_TIMETYPE_YEAR : 00177 RTCx->CIIR |= RTC_CIIR_IMYEAR; 00178 break; 00179 } 00180 } 00181 else 00182 { 00183 switch (CntIncrIntType) 00184 { 00185 case RTC_TIMETYPE_SECOND : 00186 RTCx->CIIR &= (~RTC_CIIR_IMSEC) & RTC_CIIR_BITMASK; 00187 break; 00188 case RTC_TIMETYPE_MINUTE : 00189 RTCx->CIIR &= (~RTC_CIIR_IMMIN) & RTC_CIIR_BITMASK; 00190 break; 00191 case RTC_TIMETYPE_HOUR : 00192 RTCx->CIIR &= (~RTC_CIIR_IMHOUR) & RTC_CIIR_BITMASK; 00193 break; 00194 case RTC_TIMETYPE_DAYOFWEEK : 00195 RTCx->CIIR &= (~RTC_CIIR_IMDOW) & RTC_CIIR_BITMASK; 00196 break; 00197 case RTC_TIMETYPE_DAYOFMONTH : 00198 RTCx->CIIR &= (~RTC_CIIR_IMDOM) & RTC_CIIR_BITMASK; 00199 break; 00200 case RTC_TIMETYPE_DAYOFYEAR : 00201 RTCx->CIIR &= (~RTC_CIIR_IMDOY) & RTC_CIIR_BITMASK; 00202 break; 00203 case RTC_TIMETYPE_MONTH : 00204 RTCx->CIIR &= (~RTC_CIIR_IMMON) & RTC_CIIR_BITMASK; 00205 break; 00206 case RTC_TIMETYPE_YEAR : 00207 RTCx->CIIR &= (~RTC_CIIR_IMYEAR) & RTC_CIIR_BITMASK; 00208 break; 00209 } 00210 } 00211 } 00212 00213 00214 /*********************************************************************//** 00215 * @brief Enable/Disable Alarm interrupt for each time type 00216 * in RTC peripheral 00217 * @param[in] RTCx RTC peripheral selected, should be RTC 00218 * @param[in] AlarmTimeType: Alarm Time Interrupt type, 00219 * an matching of this type value below with current time 00220 * in RTC will generates an interrupt, should be: 00221 * - RTC_TIMETYPE_SECOND 00222 * - RTC_TIMETYPE_MINUTE 00223 * - RTC_TIMETYPE_HOUR 00224 * - RTC_TIMETYPE_DAYOFWEEK 00225 * - RTC_TIMETYPE_DAYOFMONTH 00226 * - RTC_TIMETYPE_DAYOFYEAR 00227 * - RTC_TIMETYPE_MONTH 00228 * - RTC_TIMETYPE_YEAR 00229 * @param[in] NewState New State of this function, should be: 00230 * - ENABLE: Alarm interrupt for this 00231 * time type are enabled 00232 * - DISABLE: Alarm interrupt for this 00233 * time type are disabled 00234 * @return None 00235 **********************************************************************/ 00236 void RTC_AlarmIntConfig (LPC_RTC_TypeDef *RTCx, uint32_t AlarmTimeType, \ 00237 FunctionalState NewState) 00238 { 00239 CHECK_PARAM(PARAM_RTCx(RTCx)); 00240 CHECK_PARAM(PARAM_FUNCTIONALSTATE(NewState)); 00241 CHECK_PARAM(PARAM_RTC_TIMETYPE(AlarmTimeType)); 00242 00243 if (NewState == ENABLE) 00244 { 00245 switch (AlarmTimeType) 00246 { 00247 case RTC_TIMETYPE_SECOND : 00248 RTCx->AMR &= (~RTC_AMR_AMRSEC) & RTC_AMR_BITMASK; 00249 break; 00250 case RTC_TIMETYPE_MINUTE : 00251 RTCx->AMR &= (~RTC_AMR_AMRMIN) & RTC_AMR_BITMASK; 00252 break; 00253 case RTC_TIMETYPE_HOUR : 00254 RTCx->AMR &= (~RTC_AMR_AMRHOUR) & RTC_AMR_BITMASK; 00255 break; 00256 case RTC_TIMETYPE_DAYOFWEEK : 00257 RTCx->AMR &= (~RTC_AMR_AMRDOW) & RTC_AMR_BITMASK; 00258 break; 00259 case RTC_TIMETYPE_DAYOFMONTH : 00260 RTCx->AMR &= (~RTC_AMR_AMRDOM) & RTC_AMR_BITMASK; 00261 break; 00262 case RTC_TIMETYPE_DAYOFYEAR : 00263 RTCx->AMR &= (~RTC_AMR_AMRDOY) & RTC_AMR_BITMASK; 00264 break; 00265 case RTC_TIMETYPE_MONTH : 00266 RTCx->AMR &= (~RTC_AMR_AMRMON) & RTC_AMR_BITMASK; 00267 break; 00268 case RTC_TIMETYPE_YEAR : 00269 RTCx->AMR &= (~RTC_AMR_AMRYEAR) & RTC_AMR_BITMASK; 00270 break; 00271 } 00272 } 00273 else 00274 { 00275 switch (AlarmTimeType) 00276 { 00277 case RTC_TIMETYPE_SECOND : 00278 RTCx->AMR |= (RTC_AMR_AMRSEC); 00279 break; 00280 case RTC_TIMETYPE_MINUTE : 00281 RTCx->AMR |= (RTC_AMR_AMRMIN); 00282 break; 00283 case RTC_TIMETYPE_HOUR : 00284 RTCx->AMR |= (RTC_AMR_AMRHOUR); 00285 break; 00286 case RTC_TIMETYPE_DAYOFWEEK : 00287 RTCx->AMR |= (RTC_AMR_AMRDOW); 00288 break; 00289 case RTC_TIMETYPE_DAYOFMONTH : 00290 RTCx->AMR |= (RTC_AMR_AMRDOM); 00291 break; 00292 case RTC_TIMETYPE_DAYOFYEAR : 00293 RTCx->AMR |= (RTC_AMR_AMRDOY); 00294 break; 00295 case RTC_TIMETYPE_MONTH : 00296 RTCx->AMR |= (RTC_AMR_AMRMON); 00297 break; 00298 case RTC_TIMETYPE_YEAR : 00299 RTCx->AMR |= (RTC_AMR_AMRYEAR); 00300 break; 00301 } 00302 } 00303 } 00304 00305 00306 /*********************************************************************//** 00307 * @brief Set current time value for each time type in RTC peripheral 00308 * @param[in] RTCx RTC peripheral selected, should be RTC 00309 * @param[in] Timetype: Time Type, should be: 00310 * - RTC_TIMETYPE_SECOND 00311 * - RTC_TIMETYPE_MINUTE 00312 * - RTC_TIMETYPE_HOUR 00313 * - RTC_TIMETYPE_DAYOFWEEK 00314 * - RTC_TIMETYPE_DAYOFMONTH 00315 * - RTC_TIMETYPE_DAYOFYEAR 00316 * - RTC_TIMETYPE_MONTH 00317 * - RTC_TIMETYPE_YEAR 00318 * @param[in] TimeValue Time value to set 00319 * @return None 00320 **********************************************************************/ 00321 void RTC_SetTime (LPC_RTC_TypeDef *RTCx, uint32_t Timetype, uint32_t TimeValue) 00322 { 00323 CHECK_PARAM(PARAM_RTCx(RTCx)); 00324 CHECK_PARAM(PARAM_RTC_TIMETYPE(Timetype)); 00325 00326 switch ( Timetype) 00327 { 00328 case RTC_TIMETYPE_SECOND : 00329 CHECK_PARAM(TimeValue < RTC_SECOND_MAX); 00330 00331 RTCx->SEC = TimeValue & RTC_SEC_MASK; 00332 break; 00333 00334 case RTC_TIMETYPE_MINUTE : 00335 CHECK_PARAM(TimeValue < RTC_MINUTE_MAX); 00336 00337 RTCx->MIN = TimeValue & RTC_MIN_MASK; 00338 break; 00339 00340 case RTC_TIMETYPE_HOUR : 00341 CHECK_PARAM(TimeValue < RTC_HOUR_MAX); 00342 00343 RTCx->HOUR = TimeValue & RTC_HOUR_MASK; 00344 break; 00345 00346 case RTC_TIMETYPE_DAYOFWEEK : 00347 CHECK_PARAM(TimeValue < RTC_DAYOFWEEK_MAX); 00348 00349 RTCx->DOW = TimeValue & RTC_DOW_MASK; 00350 break; 00351 00352 case RTC_TIMETYPE_DAYOFMONTH : 00353 CHECK_PARAM((TimeValue < RTC_DAYOFMONTH_MAX) \ 00354 && (TimeValue > RTC_DAYOFMONTH_MIN)); 00355 00356 RTCx->DOM = TimeValue & RTC_DOM_MASK; 00357 break; 00358 00359 case RTC_TIMETYPE_DAYOFYEAR : 00360 CHECK_PARAM((TimeValue > RTC_DAYOFYEAR_MIN) \ 00361 && (TimeValue < RTC_DAYOFYEAR_MAX)); 00362 00363 RTCx->DOY = TimeValue & RTC_DOY_MASK; 00364 break; 00365 00366 case RTC_TIMETYPE_MONTH : 00367 CHECK_PARAM((TimeValue > RTC_MONTH_MIN) \ 00368 && (TimeValue < RTC_MONTH_MAX)); 00369 00370 RTCx->MONTH = TimeValue & RTC_MONTH_MASK; 00371 break; 00372 00373 case RTC_TIMETYPE_YEAR : 00374 CHECK_PARAM(TimeValue < RTC_YEAR_MAX); 00375 00376 RTCx->YEAR = TimeValue & RTC_YEAR_MASK; 00377 break; 00378 } 00379 } 00380 00381 /*********************************************************************//** 00382 * @brief Get current time value for each type time type 00383 * @param[in] RTCx RTC peripheral selected, should be RTC 00384 * @param[in] Timetype: Time Type, should be: 00385 * - RTC_TIMETYPE_SECOND 00386 * - RTC_TIMETYPE_MINUTE 00387 * - RTC_TIMETYPE_HOUR 00388 * - RTC_TIMETYPE_DAYOFWEEK 00389 * - RTC_TIMETYPE_DAYOFMONTH 00390 * - RTC_TIMETYPE_DAYOFYEAR 00391 * - RTC_TIMETYPE_MONTH 00392 * - RTC_TIMETYPE_YEAR 00393 * @return Value of time according to specified time type 00394 **********************************************************************/ 00395 uint32_t RTC_GetTime(LPC_RTC_TypeDef *RTCx, uint32_t Timetype) 00396 { 00397 CHECK_PARAM(PARAM_RTCx(RTCx)); 00398 CHECK_PARAM(PARAM_RTC_TIMETYPE(Timetype)); 00399 00400 switch (Timetype) 00401 { 00402 case RTC_TIMETYPE_SECOND : 00403 return (RTCx->SEC & RTC_SEC_MASK); 00404 case RTC_TIMETYPE_MINUTE : 00405 return (RTCx->MIN & RTC_MIN_MASK); 00406 case RTC_TIMETYPE_HOUR : 00407 return (RTCx->HOUR & RTC_HOUR_MASK); 00408 case RTC_TIMETYPE_DAYOFWEEK : 00409 return (RTCx->DOW & RTC_DOW_MASK); 00410 case RTC_TIMETYPE_DAYOFMONTH : 00411 return (RTCx->DOM & RTC_DOM_MASK); 00412 case RTC_TIMETYPE_DAYOFYEAR : 00413 return (RTCx->DOY & RTC_DOY_MASK); 00414 case RTC_TIMETYPE_MONTH : 00415 return (RTCx->MONTH & RTC_MONTH_MASK); 00416 case RTC_TIMETYPE_YEAR : 00417 return (RTCx->YEAR & RTC_YEAR_MASK); 00418 default: 00419 return (0); 00420 } 00421 } 00422 00423 00424 /*********************************************************************//** 00425 * @brief Set full of time in RTC peripheral 00426 * @param[in] RTCx RTC peripheral selected, should be RTC 00427 * @param[in] pFullTime Pointer to a RTC_TIME_Type structure that 00428 * contains time value in full. 00429 * @return None 00430 **********************************************************************/ 00431 void RTC_SetFullTime (LPC_RTC_TypeDef *RTCx, RTC_TIME_Type *pFullTime) 00432 { 00433 CHECK_PARAM(PARAM_RTCx(RTCx)); 00434 00435 RTCx->DOM = pFullTime->DOM & RTC_DOM_MASK; 00436 RTCx->DOW = pFullTime->DOW & RTC_DOW_MASK; 00437 RTCx->DOY = pFullTime->DOY & RTC_DOY_MASK; 00438 RTCx->HOUR = pFullTime->HOUR & RTC_HOUR_MASK; 00439 RTCx->MIN = pFullTime->MIN & RTC_MIN_MASK; 00440 RTCx->SEC = pFullTime->SEC & RTC_SEC_MASK; 00441 RTCx->MONTH = pFullTime->MONTH & RTC_MONTH_MASK; 00442 RTCx->YEAR = pFullTime->YEAR & RTC_YEAR_MASK; 00443 } 00444 00445 00446 /*********************************************************************//** 00447 * @brief Get full of time in RTC peripheral 00448 * @param[in] RTCx RTC peripheral selected, should be RTC 00449 * @param[in] pFullTime Pointer to a RTC_TIME_Type structure that 00450 * will be stored time in full. 00451 * @return None 00452 **********************************************************************/ 00453 void RTC_GetFullTime (LPC_RTC_TypeDef *RTCx, RTC_TIME_Type *pFullTime) 00454 { 00455 CHECK_PARAM(PARAM_RTCx(RTCx)); 00456 00457 pFullTime->DOM = RTCx->DOM & RTC_DOM_MASK; 00458 pFullTime->DOW = RTCx->DOW & RTC_DOW_MASK; 00459 pFullTime->DOY = RTCx->DOY & RTC_DOY_MASK; 00460 pFullTime->HOUR = RTCx->HOUR & RTC_HOUR_MASK; 00461 pFullTime->MIN = RTCx->MIN & RTC_MIN_MASK; 00462 pFullTime->SEC = RTCx->SEC & RTC_SEC_MASK; 00463 pFullTime->MONTH = RTCx->MONTH & RTC_MONTH_MASK; 00464 pFullTime->YEAR = RTCx->YEAR & RTC_YEAR_MASK; 00465 } 00466 00467 00468 /*********************************************************************//** 00469 * @brief Set alarm time value for each time type 00470 * @param[in] RTCx RTC peripheral selected, should be RTC 00471 * @param[in] Timetype: Time Type, should be: 00472 * - RTC_TIMETYPE_SECOND 00473 * - RTC_TIMETYPE_MINUTE 00474 * - RTC_TIMETYPE_HOUR 00475 * - RTC_TIMETYPE_DAYOFWEEK 00476 * - RTC_TIMETYPE_DAYOFMONTH 00477 * - RTC_TIMETYPE_DAYOFYEAR 00478 * - RTC_TIMETYPE_MONTH 00479 * - RTC_TIMETYPE_YEAR 00480 * @param[in] ALValue Alarm time value to set 00481 * @return None 00482 **********************************************************************/ 00483 void RTC_SetAlarmTime (LPC_RTC_TypeDef *RTCx, uint32_t Timetype, uint32_t ALValue) 00484 { 00485 CHECK_PARAM(PARAM_RTCx(RTCx)); 00486 00487 switch (Timetype) 00488 { 00489 case RTC_TIMETYPE_SECOND : 00490 CHECK_PARAM(ALValue < RTC_SECOND_MAX); 00491 00492 RTCx->ALSEC = ALValue & RTC_SEC_MASK; 00493 break; 00494 00495 case RTC_TIMETYPE_MINUTE : 00496 CHECK_PARAM(ALValue < RTC_MINUTE_MAX); 00497 00498 RTCx->ALMIN = ALValue & RTC_MIN_MASK; 00499 break; 00500 00501 case RTC_TIMETYPE_HOUR : 00502 CHECK_PARAM(ALValue < RTC_HOUR_MAX); 00503 00504 RTCx->ALHOUR = ALValue & RTC_HOUR_MASK; 00505 break; 00506 00507 case RTC_TIMETYPE_DAYOFWEEK : 00508 CHECK_PARAM(ALValue < RTC_DAYOFWEEK_MAX); 00509 00510 RTCx->ALDOW = ALValue & RTC_DOW_MASK; 00511 break; 00512 00513 case RTC_TIMETYPE_DAYOFMONTH : 00514 CHECK_PARAM((ALValue < RTC_DAYOFMONTH_MAX) \ 00515 && (ALValue > RTC_DAYOFMONTH_MIN)); 00516 00517 RTCx->ALDOM = ALValue & RTC_DOM_MASK; 00518 break; 00519 00520 case RTC_TIMETYPE_DAYOFYEAR : 00521 CHECK_PARAM((ALValue > RTC_DAYOFYEAR_MIN) \ 00522 && (ALValue < RTC_DAYOFYEAR_MAX)); 00523 00524 RTCx->ALDOY = ALValue & RTC_DOY_MASK; 00525 break; 00526 00527 case RTC_TIMETYPE_MONTH : 00528 CHECK_PARAM((ALValue > RTC_MONTH_MIN) \ 00529 && (ALValue < RTC_MONTH_MAX)); 00530 00531 RTCx->ALMON = ALValue & RTC_MONTH_MASK; 00532 break; 00533 00534 case RTC_TIMETYPE_YEAR : 00535 CHECK_PARAM(ALValue < RTC_YEAR_MAX); 00536 00537 RTCx->ALYEAR = ALValue & RTC_YEAR_MASK; 00538 break; 00539 } 00540 } 00541 00542 00543 00544 /*********************************************************************//** 00545 * @brief Get alarm time value for each time type 00546 * @param[in] RTCx RTC peripheral selected, should be RTC 00547 * @param[in] Timetype: Time Type, should be: 00548 * - RTC_TIMETYPE_SECOND 00549 * - RTC_TIMETYPE_MINUTE 00550 * - RTC_TIMETYPE_HOUR 00551 * - RTC_TIMETYPE_DAYOFWEEK 00552 * - RTC_TIMETYPE_DAYOFMONTH 00553 * - RTC_TIMETYPE_DAYOFYEAR 00554 * - RTC_TIMETYPE_MONTH 00555 * - RTC_TIMETYPE_YEAR 00556 * @return Value of Alarm time according to specified time type 00557 **********************************************************************/ 00558 uint32_t RTC_GetAlarmTime (LPC_RTC_TypeDef *RTCx, uint32_t Timetype) 00559 { 00560 switch (Timetype) 00561 { 00562 case RTC_TIMETYPE_SECOND : 00563 return (RTCx->ALSEC & RTC_SEC_MASK); 00564 case RTC_TIMETYPE_MINUTE : 00565 return (RTCx->ALMIN & RTC_MIN_MASK); 00566 case RTC_TIMETYPE_HOUR : 00567 return (RTCx->ALHOUR & RTC_HOUR_MASK); 00568 case RTC_TIMETYPE_DAYOFWEEK : 00569 return (RTCx->ALDOW & RTC_DOW_MASK); 00570 case RTC_TIMETYPE_DAYOFMONTH : 00571 return (RTCx->ALDOM & RTC_DOM_MASK); 00572 case RTC_TIMETYPE_DAYOFYEAR : 00573 return (RTCx->ALDOY & RTC_DOY_MASK); 00574 case RTC_TIMETYPE_MONTH : 00575 return (RTCx->ALMON & RTC_MONTH_MASK); 00576 case RTC_TIMETYPE_YEAR : 00577 return (RTCx->ALYEAR & RTC_YEAR_MASK); 00578 default: 00579 return (0); 00580 } 00581 } 00582 00583 00584 /*********************************************************************//** 00585 * @brief Set full of alarm time in RTC peripheral 00586 * @param[in] RTCx RTC peripheral selected, should be RTC 00587 * @param[in] pFullTime Pointer to a RTC_TIME_Type structure that 00588 * contains alarm time value in full. 00589 * @return None 00590 **********************************************************************/ 00591 void RTC_SetFullAlarmTime (LPC_RTC_TypeDef *RTCx, RTC_TIME_Type *pFullTime) 00592 { 00593 CHECK_PARAM(PARAM_RTCx(RTCx)); 00594 00595 RTCx->ALDOM = pFullTime->DOM & RTC_DOM_MASK; 00596 RTCx->ALDOW = pFullTime->DOW & RTC_DOW_MASK; 00597 RTCx->ALDOY = pFullTime->DOY & RTC_DOY_MASK; 00598 RTCx->ALHOUR = pFullTime->HOUR & RTC_HOUR_MASK; 00599 RTCx->ALMIN = pFullTime->MIN & RTC_MIN_MASK; 00600 RTCx->ALSEC = pFullTime->SEC & RTC_SEC_MASK; 00601 RTCx->ALMON = pFullTime->MONTH & RTC_MONTH_MASK; 00602 RTCx->ALYEAR = pFullTime->YEAR & RTC_YEAR_MASK; 00603 } 00604 00605 00606 /*********************************************************************//** 00607 * @brief Get full of alarm time in RTC peripheral 00608 * @param[in] RTCx RTC peripheral selected, should be RTC 00609 * @param[in] pFullTime Pointer to a RTC_TIME_Type structure that 00610 * will be stored alarm time in full. 00611 * @return None 00612 **********************************************************************/ 00613 void RTC_GetFullAlarmTime (LPC_RTC_TypeDef *RTCx, RTC_TIME_Type *pFullTime) 00614 { 00615 CHECK_PARAM(PARAM_RTCx(RTCx)); 00616 00617 pFullTime->DOM = RTCx->ALDOM & RTC_DOM_MASK; 00618 pFullTime->DOW = RTCx->ALDOW & RTC_DOW_MASK; 00619 pFullTime->DOY = RTCx->ALDOY & RTC_DOY_MASK; 00620 pFullTime->HOUR = RTCx->ALHOUR & RTC_HOUR_MASK; 00621 pFullTime->MIN = RTCx->ALMIN & RTC_MIN_MASK; 00622 pFullTime->SEC = RTCx->ALSEC & RTC_SEC_MASK; 00623 pFullTime->MONTH = RTCx->ALMON & RTC_MONTH_MASK; 00624 pFullTime->YEAR = RTCx->ALYEAR & RTC_YEAR_MASK; 00625 } 00626 00627 00628 /*********************************************************************//** 00629 * @brief Check whether if specified Location interrupt in 00630 * RTC peripheral is set or not 00631 * @param[in] RTCx RTC peripheral selected, should be RTC 00632 * @param[in] IntType Interrupt location type, should be: 00633 * - RTC_INT_COUNTER_INCREASE: Counter Increment Interrupt 00634 * block generated an interrupt. 00635 * - RTC_INT_ALARM: Alarm generated an 00636 * interrupt. 00637 * @return New state of specified Location interrupt in RTC peripheral 00638 * (SET or RESET) 00639 **********************************************************************/ 00640 IntStatus RTC_GetIntPending (LPC_RTC_TypeDef *RTCx, uint32_t IntType) 00641 { 00642 CHECK_PARAM(PARAM_RTCx(RTCx)); 00643 CHECK_PARAM(PARAM_RTC_INT(IntType)); 00644 00645 return ((RTCx->ILR & IntType) ? SET : RESET); 00646 } 00647 00648 00649 /*********************************************************************//** 00650 * @brief Clear specified Location interrupt pending in 00651 * RTC peripheral 00652 * @param[in] RTCx RTC peripheral selected, should be RTC 00653 * @param[in] IntType Interrupt location type, should be: 00654 * - RTC_INT_COUNTER_INCREASE: Clear Counter Increment 00655 * Interrupt pending. 00656 * - RTC_INT_ALARM: Clear alarm interrupt pending 00657 * @return None 00658 **********************************************************************/ 00659 void RTC_ClearIntPending (LPC_RTC_TypeDef *RTCx, uint32_t IntType) 00660 { 00661 CHECK_PARAM(PARAM_RTCx(RTCx)); 00662 CHECK_PARAM(PARAM_RTC_INT(IntType)); 00663 00664 RTCx->ILR = IntType; 00665 } 00666 00667 /*********************************************************************//** 00668 * @brief Enable/Disable calibration counter in RTC peripheral 00669 * @param[in] RTCx RTC peripheral selected, should be RTC 00670 * @param[in] NewState New State of this function, should be: 00671 * - ENABLE: The calibration counter is enabled and counting 00672 * - DISABLE: The calibration counter is disabled and reset to zero 00673 * @return None 00674 **********************************************************************/ 00675 void RTC_CalibCounterCmd(LPC_RTC_TypeDef *RTCx, FunctionalState NewState) 00676 { 00677 CHECK_PARAM(PARAM_RTCx(RTCx)); 00678 CHECK_PARAM(PARAM_FUNCTIONALSTATE(NewState)); 00679 00680 if (NewState == ENABLE) 00681 { 00682 RTCx->CCR &= (~RTC_CCR_CCALEN) & RTC_CCR_BITMASK; 00683 } 00684 else 00685 { 00686 RTCx->CCR |= RTC_CCR_CCALEN; 00687 } 00688 } 00689 00690 00691 /*********************************************************************//** 00692 * @brief Configures Calibration in RTC peripheral 00693 * @param[in] RTCx RTC peripheral selected, should be RTC 00694 * @param[in] CalibValue Calibration value, should be in range from 00695 * 0 to 131,072 00696 * @param[in] CalibDir Calibration Direction, should be: 00697 * - RTC_CALIB_DIR_FORWARD: Forward calibration 00698 * - RTC_CALIB_DIR_BACKWARD: Backward calibration 00699 * @return None 00700 **********************************************************************/ 00701 void RTC_CalibConfig(LPC_RTC_TypeDef *RTCx, uint32_t CalibValue, uint8_t CalibDir) 00702 { 00703 CHECK_PARAM(PARAM_RTCx(RTCx)); 00704 CHECK_PARAM(PARAM_RTC_CALIB_DIR(CalibDir)); 00705 CHECK_PARAM(CalibValue > RTC_CALIBRATION_MAX); 00706 00707 RTCx->CALIBRATION = ((CalibValue - 1) & RTC_CALIBRATION_CALVAL_MASK) \ 00708 | ((CalibDir == RTC_CALIB_DIR_BACKWARD) ? RTC_CALIBRATION_LIBDIR : 0); 00709 } 00710 00711 00712 /*********************************************************************//** 00713 * @brief Write value to General purpose registers 00714 * @param[in] RTCx RTC peripheral selected, should be RTC 00715 * @param[in] Channel General purpose registers Channel number, 00716 * should be in range from 0 to 4. 00717 * @param[in] Value Value to write 00718 * @return None 00719 * Note: These General purpose registers can be used to store important 00720 * information when the main power supply is off. The value in these 00721 * registers is not affected by chip reset. 00722 **********************************************************************/ 00723 void RTC_WriteGPREG (LPC_RTC_TypeDef *RTCx, uint8_t Channel, uint32_t Value) 00724 { 00725 uint32_t *preg; 00726 00727 CHECK_PARAM(PARAM_RTCx(RTCx)); 00728 CHECK_PARAM(PARAM_RTC_GPREG_CH(Channel)); 00729 00730 preg = (uint32_t *)&RTCx->GPREG0; 00731 preg += Channel; 00732 *preg = Value; 00733 } 00734 00735 00736 /*********************************************************************//** 00737 * @brief Read value from General purpose registers 00738 * @param[in] RTCx RTC peripheral selected, should be RTC 00739 * @param[in] Channel General purpose registers Channel number, 00740 * should be in range from 0 to 4. 00741 * @return Read Value 00742 * Note: These General purpose registers can be used to store important 00743 * information when the main power supply is off. The value in these 00744 * registers is not affected by chip reset. 00745 **********************************************************************/ 00746 uint32_t RTC_ReadGPREG (LPC_RTC_TypeDef *RTCx, uint8_t Channel) 00747 { 00748 uint32_t *preg; 00749 uint32_t value; 00750 00751 CHECK_PARAM(PARAM_RTCx(RTCx)); 00752 CHECK_PARAM(PARAM_RTC_GPREG_CH(Channel)); 00753 00754 preg = (uint32_t *)&RTCx->GPREG0; 00755 preg += Channel; 00756 value = *preg; 00757 return (value); 00758 } 00759 00760 /** 00761 * @} 00762 */ 00763 00764 #endif /* _RTC */ 00765 00766 /** 00767 * @} 00768 */ 00769 00770 /* --------------------------------- End Of File ------------------------------ */ 00771
Generated on Tue Jul 12 2022 17:06:02 by 1.7.2