lpc17xx_rtc.c (24646B)
1 /********************************************************************** 2 * $Id$ lpc17xx_rtc.c 2011-06-06 3 *//** 4 * @file lpc17xx_rtc.c 5 * @brief Contains all functions support for RTC firmware library on LPC17xx 6 * @version 3.1 7 * @date 6. June. 2011 8 * @author NXP MCU SW Application Team 9 * 10 * Copyright(C) 2011, NXP Semiconductor 11 * All rights reserved. 12 * 13 *********************************************************************** 14 * Software that is described herein is for illustrative purposes only 15 * which provides customers with programming information regarding the 16 * products. This software is supplied "AS IS" without any warranties. 17 * NXP Semiconductors assumes no responsibility or liability for the 18 * use of the software, conveys no license or title under any patent, 19 * copyright, or mask work right to the product. NXP Semiconductors 20 * reserves the right to make changes in the software without 21 * notification. NXP Semiconductors also make no representation or 22 * warranty that such application will be suitable for the specified 23 * use without further testing or modification. 24 * Permission to use, copy, modify, and distribute this software and its 25 * documentation is hereby granted, under NXP Semiconductors' 26 * relevant copyright in the software, without fee, provided that it 27 * is used in conjunction with NXP Semiconductors microcontrollers. This 28 * copyright, permission, and disclaimer notice must appear in all copies of 29 * this code. 30 **********************************************************************/ 31 32 33 /* Peripheral group ----------------------------------------------------------- */ 34 /** @addtogroup RTC 35 * @{ 36 */ 37 38 /* Includes ------------------------------------------------------------------- */ 39 #include "lpc17xx_rtc.h" 40 #include "lpc17xx_clkpwr.h" 41 42 43 /* If this source file built with example, the LPC17xx FW library configuration 44 * file in each example directory ("lpc17xx_libcfg.h") must be included, 45 * otherwise the default FW library configuration file must be included instead 46 */ 47 #ifdef __BUILD_WITH_EXAMPLE__ 48 #include "lpc17xx_libcfg.h" 49 #else 50 #include "lpc17xx_libcfg_default.h" 51 #endif /* __BUILD_WITH_EXAMPLE__ */ 52 53 54 #ifdef _RTC 55 56 /* Public Functions ----------------------------------------------------------- */ 57 /** @addtogroup RTC_Public_Functions 58 * @{ 59 */ 60 61 /********************************************************************//** 62 * @brief Initializes the RTC peripheral. 63 * @param[in] RTCx RTC peripheral selected, should be LPC_RTC 64 * @return None 65 *********************************************************************/ 66 void RTC_Init (LPC_RTC_TypeDef *RTCx) 67 { 68 CHECK_PARAM(PARAM_RTCx(RTCx)); 69 70 /* Set up clock and power for RTC module */ 71 CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCRTC, ENABLE); 72 73 // Clear all register to be default 74 RTCx->ILR = 0x00; 75 RTCx->CCR = 0x00; 76 RTCx->CIIR = 0x00; 77 RTCx->AMR = 0xFF; 78 RTCx->CALIBRATION = 0x00; 79 } 80 81 82 /*********************************************************************//** 83 * @brief De-initializes the RTC peripheral registers to their 84 * default reset values. 85 * @param[in] RTCx RTC peripheral selected, should be LPC_RTC 86 * @return None 87 **********************************************************************/ 88 void RTC_DeInit(LPC_RTC_TypeDef *RTCx) 89 { 90 CHECK_PARAM(PARAM_RTCx(RTCx)); 91 92 RTCx->CCR = 0x00; 93 // Disable power and clock for RTC module 94 CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCRTC, DISABLE); 95 } 96 97 /*********************************************************************//** 98 * @brief Reset clock tick counter in RTC peripheral 99 * @param[in] RTCx RTC peripheral selected, should be LPC_RTC 100 * @return None 101 **********************************************************************/ 102 void RTC_ResetClockTickCounter(LPC_RTC_TypeDef *RTCx) 103 { 104 CHECK_PARAM(PARAM_RTCx(RTCx)); 105 106 RTCx->CCR |= RTC_CCR_CTCRST; 107 RTCx->CCR &= (~RTC_CCR_CTCRST) & RTC_CCR_BITMASK; 108 } 109 110 /*********************************************************************//** 111 * @brief Start/Stop RTC peripheral 112 * @param[in] RTCx RTC peripheral selected, should be LPC_RTC 113 * @param[in] NewState New State of this function, should be: 114 * - ENABLE: The time counters are enabled 115 * - DISABLE: The time counters are disabled 116 * @return None 117 **********************************************************************/ 118 void RTC_Cmd (LPC_RTC_TypeDef *RTCx, FunctionalState NewState) 119 { 120 CHECK_PARAM(PARAM_RTCx(RTCx)); 121 CHECK_PARAM(PARAM_FUNCTIONALSTATE(NewState)); 122 123 if (NewState == ENABLE) 124 { 125 RTCx->CCR |= RTC_CCR_CLKEN; 126 } 127 else 128 { 129 RTCx->CCR &= (~RTC_CCR_CLKEN) & RTC_CCR_BITMASK; 130 } 131 } 132 133 134 /*********************************************************************//** 135 * @brief Enable/Disable Counter increment interrupt for each time type 136 * in RTC peripheral 137 * @param[in] RTCx RTC peripheral selected, should be LPC_RTC 138 * @param[in] CntIncrIntType: Counter Increment Interrupt type, 139 * an increment of this type value below will generates 140 * an interrupt, should be: 141 * - RTC_TIMETYPE_SECOND 142 * - RTC_TIMETYPE_MINUTE 143 * - RTC_TIMETYPE_HOUR 144 * - RTC_TIMETYPE_DAYOFWEEK 145 * - RTC_TIMETYPE_DAYOFMONTH 146 * - RTC_TIMETYPE_DAYOFYEAR 147 * - RTC_TIMETYPE_MONTH 148 * - RTC_TIMETYPE_YEAR 149 * @param[in] NewState New State of this function, should be: 150 * - ENABLE: Counter Increment interrupt for this 151 * time type are enabled 152 * - DISABLE: Counter Increment interrupt for this 153 * time type are disabled 154 * @return None 155 **********************************************************************/ 156 void RTC_CntIncrIntConfig (LPC_RTC_TypeDef *RTCx, uint32_t CntIncrIntType, \ 157 FunctionalState NewState) 158 { 159 CHECK_PARAM(PARAM_RTCx(RTCx)); 160 CHECK_PARAM(PARAM_FUNCTIONALSTATE(NewState)); 161 CHECK_PARAM(PARAM_RTC_TIMETYPE(CntIncrIntType)); 162 163 if (NewState == ENABLE) 164 { 165 switch (CntIncrIntType) 166 { 167 case RTC_TIMETYPE_SECOND: 168 RTCx->CIIR |= RTC_CIIR_IMSEC; 169 break; 170 case RTC_TIMETYPE_MINUTE: 171 RTCx->CIIR |= RTC_CIIR_IMMIN; 172 break; 173 case RTC_TIMETYPE_HOUR: 174 RTCx->CIIR |= RTC_CIIR_IMHOUR; 175 break; 176 case RTC_TIMETYPE_DAYOFWEEK: 177 RTCx->CIIR |= RTC_CIIR_IMDOW; 178 break; 179 case RTC_TIMETYPE_DAYOFMONTH: 180 RTCx->CIIR |= RTC_CIIR_IMDOM; 181 break; 182 case RTC_TIMETYPE_DAYOFYEAR: 183 RTCx->CIIR |= RTC_CIIR_IMDOY; 184 break; 185 case RTC_TIMETYPE_MONTH: 186 RTCx->CIIR |= RTC_CIIR_IMMON; 187 break; 188 case RTC_TIMETYPE_YEAR: 189 RTCx->CIIR |= RTC_CIIR_IMYEAR; 190 break; 191 } 192 } 193 else 194 { 195 switch (CntIncrIntType) 196 { 197 case RTC_TIMETYPE_SECOND: 198 RTCx->CIIR &= (~RTC_CIIR_IMSEC) & RTC_CIIR_BITMASK; 199 break; 200 case RTC_TIMETYPE_MINUTE: 201 RTCx->CIIR &= (~RTC_CIIR_IMMIN) & RTC_CIIR_BITMASK; 202 break; 203 case RTC_TIMETYPE_HOUR: 204 RTCx->CIIR &= (~RTC_CIIR_IMHOUR) & RTC_CIIR_BITMASK; 205 break; 206 case RTC_TIMETYPE_DAYOFWEEK: 207 RTCx->CIIR &= (~RTC_CIIR_IMDOW) & RTC_CIIR_BITMASK; 208 break; 209 case RTC_TIMETYPE_DAYOFMONTH: 210 RTCx->CIIR &= (~RTC_CIIR_IMDOM) & RTC_CIIR_BITMASK; 211 break; 212 case RTC_TIMETYPE_DAYOFYEAR: 213 RTCx->CIIR &= (~RTC_CIIR_IMDOY) & RTC_CIIR_BITMASK; 214 break; 215 case RTC_TIMETYPE_MONTH: 216 RTCx->CIIR &= (~RTC_CIIR_IMMON) & RTC_CIIR_BITMASK; 217 break; 218 case RTC_TIMETYPE_YEAR: 219 RTCx->CIIR &= (~RTC_CIIR_IMYEAR) & RTC_CIIR_BITMASK; 220 break; 221 } 222 } 223 } 224 225 226 /*********************************************************************//** 227 * @brief Enable/Disable Alarm interrupt for each time type 228 * in RTC peripheral 229 * @param[in] RTCx RTC peripheral selected, should be LPC_RTC 230 * @param[in] AlarmTimeType: Alarm Time Interrupt type, 231 * an matching of this type value below with current time 232 * in RTC will generates an interrupt, should be: 233 * - RTC_TIMETYPE_SECOND 234 * - RTC_TIMETYPE_MINUTE 235 * - RTC_TIMETYPE_HOUR 236 * - RTC_TIMETYPE_DAYOFWEEK 237 * - RTC_TIMETYPE_DAYOFMONTH 238 * - RTC_TIMETYPE_DAYOFYEAR 239 * - RTC_TIMETYPE_MONTH 240 * - RTC_TIMETYPE_YEAR 241 * @param[in] NewState New State of this function, should be: 242 * - ENABLE: Alarm interrupt for this 243 * time type are enabled 244 * - DISABLE: Alarm interrupt for this 245 * time type are disabled 246 * @return None 247 **********************************************************************/ 248 void RTC_AlarmIntConfig (LPC_RTC_TypeDef *RTCx, uint32_t AlarmTimeType, \ 249 FunctionalState NewState) 250 { 251 CHECK_PARAM(PARAM_RTCx(RTCx)); 252 CHECK_PARAM(PARAM_FUNCTIONALSTATE(NewState)); 253 CHECK_PARAM(PARAM_RTC_TIMETYPE(AlarmTimeType)); 254 255 if (NewState == ENABLE) 256 { 257 switch (AlarmTimeType) 258 { 259 case RTC_TIMETYPE_SECOND: 260 RTCx->AMR &= (~RTC_AMR_AMRSEC) & RTC_AMR_BITMASK; 261 break; 262 case RTC_TIMETYPE_MINUTE: 263 RTCx->AMR &= (~RTC_AMR_AMRMIN) & RTC_AMR_BITMASK; 264 break; 265 case RTC_TIMETYPE_HOUR: 266 RTCx->AMR &= (~RTC_AMR_AMRHOUR) & RTC_AMR_BITMASK; 267 break; 268 case RTC_TIMETYPE_DAYOFWEEK: 269 RTCx->AMR &= (~RTC_AMR_AMRDOW) & RTC_AMR_BITMASK; 270 break; 271 case RTC_TIMETYPE_DAYOFMONTH: 272 RTCx->AMR &= (~RTC_AMR_AMRDOM) & RTC_AMR_BITMASK; 273 break; 274 case RTC_TIMETYPE_DAYOFYEAR: 275 RTCx->AMR &= (~RTC_AMR_AMRDOY) & RTC_AMR_BITMASK; 276 break; 277 case RTC_TIMETYPE_MONTH: 278 RTCx->AMR &= (~RTC_AMR_AMRMON) & RTC_AMR_BITMASK; 279 break; 280 case RTC_TIMETYPE_YEAR: 281 RTCx->AMR &= (~RTC_AMR_AMRYEAR) & RTC_AMR_BITMASK; 282 break; 283 } 284 } 285 else 286 { 287 switch (AlarmTimeType) 288 { 289 case RTC_TIMETYPE_SECOND: 290 RTCx->AMR |= (RTC_AMR_AMRSEC); 291 break; 292 case RTC_TIMETYPE_MINUTE: 293 RTCx->AMR |= (RTC_AMR_AMRMIN); 294 break; 295 case RTC_TIMETYPE_HOUR: 296 RTCx->AMR |= (RTC_AMR_AMRHOUR); 297 break; 298 case RTC_TIMETYPE_DAYOFWEEK: 299 RTCx->AMR |= (RTC_AMR_AMRDOW); 300 break; 301 case RTC_TIMETYPE_DAYOFMONTH: 302 RTCx->AMR |= (RTC_AMR_AMRDOM); 303 break; 304 case RTC_TIMETYPE_DAYOFYEAR: 305 RTCx->AMR |= (RTC_AMR_AMRDOY); 306 break; 307 case RTC_TIMETYPE_MONTH: 308 RTCx->AMR |= (RTC_AMR_AMRMON); 309 break; 310 case RTC_TIMETYPE_YEAR: 311 RTCx->AMR |= (RTC_AMR_AMRYEAR); 312 break; 313 } 314 } 315 } 316 317 318 /*********************************************************************//** 319 * @brief Set current time value for each time type in RTC peripheral 320 * @param[in] RTCx RTC peripheral selected, should be LPC_RTC 321 * @param[in] Timetype: Time Type, should be: 322 * - RTC_TIMETYPE_SECOND 323 * - RTC_TIMETYPE_MINUTE 324 * - RTC_TIMETYPE_HOUR 325 * - RTC_TIMETYPE_DAYOFWEEK 326 * - RTC_TIMETYPE_DAYOFMONTH 327 * - RTC_TIMETYPE_DAYOFYEAR 328 * - RTC_TIMETYPE_MONTH 329 * - RTC_TIMETYPE_YEAR 330 * @param[in] TimeValue Time value to set 331 * @return None 332 **********************************************************************/ 333 void RTC_SetTime (LPC_RTC_TypeDef *RTCx, uint32_t Timetype, uint32_t TimeValue) 334 { 335 CHECK_PARAM(PARAM_RTCx(RTCx)); 336 CHECK_PARAM(PARAM_RTC_TIMETYPE(Timetype)); 337 338 switch ( Timetype) 339 { 340 case RTC_TIMETYPE_SECOND: 341 CHECK_PARAM(TimeValue <= RTC_SECOND_MAX); 342 343 RTCx->SEC = TimeValue & RTC_SEC_MASK; 344 break; 345 346 case RTC_TIMETYPE_MINUTE: 347 CHECK_PARAM(TimeValue <= RTC_MINUTE_MAX); 348 349 RTCx->MIN = TimeValue & RTC_MIN_MASK; 350 break; 351 352 case RTC_TIMETYPE_HOUR: 353 CHECK_PARAM(TimeValue <= RTC_HOUR_MAX); 354 355 RTCx->HOUR = TimeValue & RTC_HOUR_MASK; 356 break; 357 358 case RTC_TIMETYPE_DAYOFWEEK: 359 CHECK_PARAM(TimeValue <= RTC_DAYOFWEEK_MAX); 360 361 RTCx->DOW = TimeValue & RTC_DOW_MASK; 362 break; 363 364 case RTC_TIMETYPE_DAYOFMONTH: 365 CHECK_PARAM((TimeValue <= RTC_DAYOFMONTH_MAX) \ 366 && (TimeValue >= RTC_DAYOFMONTH_MIN)); 367 368 RTCx->DOM = TimeValue & RTC_DOM_MASK; 369 break; 370 371 case RTC_TIMETYPE_DAYOFYEAR: 372 CHECK_PARAM((TimeValue >= RTC_DAYOFYEAR_MIN) \ 373 && (TimeValue <= RTC_DAYOFYEAR_MAX)); 374 375 RTCx->DOY = TimeValue & RTC_DOY_MASK; 376 break; 377 378 case RTC_TIMETYPE_MONTH: 379 CHECK_PARAM((TimeValue >= RTC_MONTH_MIN) \ 380 && (TimeValue <= RTC_MONTH_MAX)); 381 382 RTCx->MONTH = TimeValue & RTC_MONTH_MASK; 383 break; 384 385 case RTC_TIMETYPE_YEAR: 386 CHECK_PARAM(TimeValue <= RTC_YEAR_MAX); 387 388 RTCx->YEAR = TimeValue & RTC_YEAR_MASK; 389 break; 390 } 391 } 392 393 /*********************************************************************//** 394 * @brief Get current time value for each type time type 395 * @param[in] RTCx RTC peripheral selected, should be LPC_RTC 396 * @param[in] Timetype: Time Type, should be: 397 * - RTC_TIMETYPE_SECOND 398 * - RTC_TIMETYPE_MINUTE 399 * - RTC_TIMETYPE_HOUR 400 * - RTC_TIMETYPE_DAYOFWEEK 401 * - RTC_TIMETYPE_DAYOFMONTH 402 * - RTC_TIMETYPE_DAYOFYEAR 403 * - RTC_TIMETYPE_MONTH 404 * - RTC_TIMETYPE_YEAR 405 * @return Value of time according to specified time type 406 **********************************************************************/ 407 uint32_t RTC_GetTime(LPC_RTC_TypeDef *RTCx, uint32_t Timetype) 408 { 409 CHECK_PARAM(PARAM_RTCx(RTCx)); 410 CHECK_PARAM(PARAM_RTC_TIMETYPE(Timetype)); 411 412 switch (Timetype) 413 { 414 case RTC_TIMETYPE_SECOND: 415 return (RTCx->SEC & RTC_SEC_MASK); 416 case RTC_TIMETYPE_MINUTE: 417 return (RTCx->MIN & RTC_MIN_MASK); 418 case RTC_TIMETYPE_HOUR: 419 return (RTCx->HOUR & RTC_HOUR_MASK); 420 case RTC_TIMETYPE_DAYOFWEEK: 421 return (RTCx->DOW & RTC_DOW_MASK); 422 case RTC_TIMETYPE_DAYOFMONTH: 423 return (RTCx->DOM & RTC_DOM_MASK); 424 case RTC_TIMETYPE_DAYOFYEAR: 425 return (RTCx->DOY & RTC_DOY_MASK); 426 case RTC_TIMETYPE_MONTH: 427 return (RTCx->MONTH & RTC_MONTH_MASK); 428 case RTC_TIMETYPE_YEAR: 429 return (RTCx->YEAR & RTC_YEAR_MASK); 430 default: 431 return (0); 432 } 433 } 434 435 436 /*********************************************************************//** 437 * @brief Set full of time in RTC peripheral 438 * @param[in] RTCx RTC peripheral selected, should be LPC_RTC 439 * @param[in] pFullTime Pointer to a RTC_TIME_Type structure that 440 * contains time value in full. 441 * @return None 442 **********************************************************************/ 443 void RTC_SetFullTime (LPC_RTC_TypeDef *RTCx, RTC_TIME_Type *pFullTime) 444 { 445 CHECK_PARAM(PARAM_RTCx(RTCx)); 446 447 RTCx->DOM = pFullTime->DOM & RTC_DOM_MASK; 448 RTCx->DOW = pFullTime->DOW & RTC_DOW_MASK; 449 RTCx->DOY = pFullTime->DOY & RTC_DOY_MASK; 450 RTCx->HOUR = pFullTime->HOUR & RTC_HOUR_MASK; 451 RTCx->MIN = pFullTime->MIN & RTC_MIN_MASK; 452 RTCx->SEC = pFullTime->SEC & RTC_SEC_MASK; 453 RTCx->MONTH = pFullTime->MONTH & RTC_MONTH_MASK; 454 RTCx->YEAR = pFullTime->YEAR & RTC_YEAR_MASK; 455 } 456 457 458 /*********************************************************************//** 459 * @brief Get full of time in RTC peripheral 460 * @param[in] RTCx RTC peripheral selected, should be LPC_RTC 461 * @param[in] pFullTime Pointer to a RTC_TIME_Type structure that 462 * will be stored time in full. 463 * @return None 464 **********************************************************************/ 465 void RTC_GetFullTime (LPC_RTC_TypeDef *RTCx, RTC_TIME_Type *pFullTime) 466 { 467 CHECK_PARAM(PARAM_RTCx(RTCx)); 468 469 pFullTime->DOM = RTCx->DOM & RTC_DOM_MASK; 470 pFullTime->DOW = RTCx->DOW & RTC_DOW_MASK; 471 pFullTime->DOY = RTCx->DOY & RTC_DOY_MASK; 472 pFullTime->HOUR = RTCx->HOUR & RTC_HOUR_MASK; 473 pFullTime->MIN = RTCx->MIN & RTC_MIN_MASK; 474 pFullTime->SEC = RTCx->SEC & RTC_SEC_MASK; 475 pFullTime->MONTH = RTCx->MONTH & RTC_MONTH_MASK; 476 pFullTime->YEAR = RTCx->YEAR & RTC_YEAR_MASK; 477 } 478 479 480 /*********************************************************************//** 481 * @brief Set alarm time value for each time type 482 * @param[in] RTCx RTC peripheral selected, should be LPC_RTC 483 * @param[in] Timetype: Time Type, should be: 484 * - RTC_TIMETYPE_SECOND 485 * - RTC_TIMETYPE_MINUTE 486 * - RTC_TIMETYPE_HOUR 487 * - RTC_TIMETYPE_DAYOFWEEK 488 * - RTC_TIMETYPE_DAYOFMONTH 489 * - RTC_TIMETYPE_DAYOFYEAR 490 * - RTC_TIMETYPE_MONTH 491 * - RTC_TIMETYPE_YEAR 492 * @param[in] ALValue Alarm time value to set 493 * @return None 494 **********************************************************************/ 495 void RTC_SetAlarmTime (LPC_RTC_TypeDef *RTCx, uint32_t Timetype, uint32_t ALValue) 496 { 497 CHECK_PARAM(PARAM_RTCx(RTCx)); 498 499 switch (Timetype) 500 { 501 case RTC_TIMETYPE_SECOND: 502 CHECK_PARAM(ALValue <= RTC_SECOND_MAX); 503 504 RTCx->ALSEC = ALValue & RTC_SEC_MASK; 505 break; 506 507 case RTC_TIMETYPE_MINUTE: 508 CHECK_PARAM(ALValue <= RTC_MINUTE_MAX); 509 510 RTCx->ALMIN = ALValue & RTC_MIN_MASK; 511 break; 512 513 case RTC_TIMETYPE_HOUR: 514 CHECK_PARAM(ALValue <= RTC_HOUR_MAX); 515 516 RTCx->ALHOUR = ALValue & RTC_HOUR_MASK; 517 break; 518 519 case RTC_TIMETYPE_DAYOFWEEK: 520 CHECK_PARAM(ALValue <= RTC_DAYOFWEEK_MAX); 521 522 RTCx->ALDOW = ALValue & RTC_DOW_MASK; 523 break; 524 525 case RTC_TIMETYPE_DAYOFMONTH: 526 CHECK_PARAM((ALValue <= RTC_DAYOFMONTH_MAX) \ 527 && (ALValue >= RTC_DAYOFMONTH_MIN)); 528 529 RTCx->ALDOM = ALValue & RTC_DOM_MASK; 530 break; 531 532 case RTC_TIMETYPE_DAYOFYEAR: 533 CHECK_PARAM((ALValue >= RTC_DAYOFYEAR_MIN) \ 534 && (ALValue <= RTC_DAYOFYEAR_MAX)); 535 536 RTCx->ALDOY = ALValue & RTC_DOY_MASK; 537 break; 538 539 case RTC_TIMETYPE_MONTH: 540 CHECK_PARAM((ALValue >= RTC_MONTH_MIN) \ 541 && (ALValue <= RTC_MONTH_MAX)); 542 543 RTCx->ALMON = ALValue & RTC_MONTH_MASK; 544 break; 545 546 case RTC_TIMETYPE_YEAR: 547 CHECK_PARAM(ALValue <= RTC_YEAR_MAX); 548 549 RTCx->ALYEAR = ALValue & RTC_YEAR_MASK; 550 break; 551 } 552 } 553 554 555 556 /*********************************************************************//** 557 * @brief Get alarm time value for each time type 558 * @param[in] RTCx RTC peripheral selected, should be LPC_RTC 559 * @param[in] Timetype: Time Type, should be: 560 * - RTC_TIMETYPE_SECOND 561 * - RTC_TIMETYPE_MINUTE 562 * - RTC_TIMETYPE_HOUR 563 * - RTC_TIMETYPE_DAYOFWEEK 564 * - RTC_TIMETYPE_DAYOFMONTH 565 * - RTC_TIMETYPE_DAYOFYEAR 566 * - RTC_TIMETYPE_MONTH 567 * - RTC_TIMETYPE_YEAR 568 * @return Value of Alarm time according to specified time type 569 **********************************************************************/ 570 uint32_t RTC_GetAlarmTime (LPC_RTC_TypeDef *RTCx, uint32_t Timetype) 571 { 572 switch (Timetype) 573 { 574 case RTC_TIMETYPE_SECOND: 575 return (RTCx->ALSEC & RTC_SEC_MASK); 576 case RTC_TIMETYPE_MINUTE: 577 return (RTCx->ALMIN & RTC_MIN_MASK); 578 case RTC_TIMETYPE_HOUR: 579 return (RTCx->ALHOUR & RTC_HOUR_MASK); 580 case RTC_TIMETYPE_DAYOFWEEK: 581 return (RTCx->ALDOW & RTC_DOW_MASK); 582 case RTC_TIMETYPE_DAYOFMONTH: 583 return (RTCx->ALDOM & RTC_DOM_MASK); 584 case RTC_TIMETYPE_DAYOFYEAR: 585 return (RTCx->ALDOY & RTC_DOY_MASK); 586 case RTC_TIMETYPE_MONTH: 587 return (RTCx->ALMON & RTC_MONTH_MASK); 588 case RTC_TIMETYPE_YEAR: 589 return (RTCx->ALYEAR & RTC_YEAR_MASK); 590 default: 591 return (0); 592 } 593 } 594 595 596 /*********************************************************************//** 597 * @brief Set full of alarm time in RTC peripheral 598 * @param[in] RTCx RTC peripheral selected, should be LPC_RTC 599 * @param[in] pFullTime Pointer to a RTC_TIME_Type structure that 600 * contains alarm time value in full. 601 * @return None 602 **********************************************************************/ 603 void RTC_SetFullAlarmTime (LPC_RTC_TypeDef *RTCx, RTC_TIME_Type *pFullTime) 604 { 605 CHECK_PARAM(PARAM_RTCx(RTCx)); 606 607 RTCx->ALDOM = pFullTime->DOM & RTC_DOM_MASK; 608 RTCx->ALDOW = pFullTime->DOW & RTC_DOW_MASK; 609 RTCx->ALDOY = pFullTime->DOY & RTC_DOY_MASK; 610 RTCx->ALHOUR = pFullTime->HOUR & RTC_HOUR_MASK; 611 RTCx->ALMIN = pFullTime->MIN & RTC_MIN_MASK; 612 RTCx->ALSEC = pFullTime->SEC & RTC_SEC_MASK; 613 RTCx->ALMON = pFullTime->MONTH & RTC_MONTH_MASK; 614 RTCx->ALYEAR = pFullTime->YEAR & RTC_YEAR_MASK; 615 } 616 617 618 /*********************************************************************//** 619 * @brief Get full of alarm time in RTC peripheral 620 * @param[in] RTCx RTC peripheral selected, should be LPC_RTC 621 * @param[in] pFullTime Pointer to a RTC_TIME_Type structure that 622 * will be stored alarm time in full. 623 * @return None 624 **********************************************************************/ 625 void RTC_GetFullAlarmTime (LPC_RTC_TypeDef *RTCx, RTC_TIME_Type *pFullTime) 626 { 627 CHECK_PARAM(PARAM_RTCx(RTCx)); 628 629 pFullTime->DOM = RTCx->ALDOM & RTC_DOM_MASK; 630 pFullTime->DOW = RTCx->ALDOW & RTC_DOW_MASK; 631 pFullTime->DOY = RTCx->ALDOY & RTC_DOY_MASK; 632 pFullTime->HOUR = RTCx->ALHOUR & RTC_HOUR_MASK; 633 pFullTime->MIN = RTCx->ALMIN & RTC_MIN_MASK; 634 pFullTime->SEC = RTCx->ALSEC & RTC_SEC_MASK; 635 pFullTime->MONTH = RTCx->ALMON & RTC_MONTH_MASK; 636 pFullTime->YEAR = RTCx->ALYEAR & RTC_YEAR_MASK; 637 } 638 639 640 /*********************************************************************//** 641 * @brief Check whether if specified Location interrupt in 642 * RTC peripheral is set or not 643 * @param[in] RTCx RTC peripheral selected, should be LPC_RTC 644 * @param[in] IntType Interrupt location type, should be: 645 * - RTC_INT_COUNTER_INCREASE: Counter Increment Interrupt 646 * block generated an interrupt. 647 * - RTC_INT_ALARM: Alarm generated an 648 * interrupt. 649 * @return New state of specified Location interrupt in RTC peripheral 650 * (SET or RESET) 651 **********************************************************************/ 652 IntStatus RTC_GetIntPending (LPC_RTC_TypeDef *RTCx, uint32_t IntType) 653 { 654 CHECK_PARAM(PARAM_RTCx(RTCx)); 655 CHECK_PARAM(PARAM_RTC_INT(IntType)); 656 657 return ((RTCx->ILR & IntType) ? SET : RESET); 658 } 659 660 661 /*********************************************************************//** 662 * @brief Clear specified Location interrupt pending in 663 * RTC peripheral 664 * @param[in] RTCx RTC peripheral selected, should be LPC_RTC 665 * @param[in] IntType Interrupt location type, should be: 666 * - RTC_INT_COUNTER_INCREASE: Clear Counter Increment 667 * Interrupt pending. 668 * - RTC_INT_ALARM: Clear alarm interrupt pending 669 * @return None 670 **********************************************************************/ 671 void RTC_ClearIntPending (LPC_RTC_TypeDef *RTCx, uint32_t IntType) 672 { 673 CHECK_PARAM(PARAM_RTCx(RTCx)); 674 CHECK_PARAM(PARAM_RTC_INT(IntType)); 675 676 RTCx->ILR |= IntType; 677 } 678 679 /*********************************************************************//** 680 * @brief Enable/Disable calibration counter in RTC peripheral 681 * @param[in] RTCx RTC peripheral selected, should be LPC_RTC 682 * @param[in] NewState New State of this function, should be: 683 * - ENABLE: The calibration counter is enabled and counting 684 * - DISABLE: The calibration counter is disabled and reset to zero 685 * @return None 686 **********************************************************************/ 687 void RTC_CalibCounterCmd(LPC_RTC_TypeDef *RTCx, FunctionalState NewState) 688 { 689 CHECK_PARAM(PARAM_RTCx(RTCx)); 690 CHECK_PARAM(PARAM_FUNCTIONALSTATE(NewState)); 691 692 if (NewState == ENABLE) 693 { 694 RTCx->CCR &= (~RTC_CCR_CCALEN) & RTC_CCR_BITMASK; 695 } 696 else 697 { 698 RTCx->CCR |= RTC_CCR_CCALEN; 699 } 700 } 701 702 703 /*********************************************************************//** 704 * @brief Configures Calibration in RTC peripheral 705 * @param[in] RTCx RTC peripheral selected, should be LPC_RTC 706 * @param[in] CalibValue Calibration value, should be in range from 707 * 0 to 131,072 708 * @param[in] CalibDir Calibration Direction, should be: 709 * - RTC_CALIB_DIR_FORWARD: Forward calibration 710 * - RTC_CALIB_DIR_BACKWARD: Backward calibration 711 * @return None 712 **********************************************************************/ 713 void RTC_CalibConfig(LPC_RTC_TypeDef *RTCx, uint32_t CalibValue, uint8_t CalibDir) 714 { 715 CHECK_PARAM(PARAM_RTCx(RTCx)); 716 CHECK_PARAM(PARAM_RTC_CALIB_DIR(CalibDir)); 717 CHECK_PARAM(CalibValue < RTC_CALIBRATION_MAX); 718 719 RTCx->CALIBRATION = ((CalibValue) & RTC_CALIBRATION_CALVAL_MASK) \ 720 | ((CalibDir == RTC_CALIB_DIR_BACKWARD) ? RTC_CALIBRATION_LIBDIR : 0); 721 } 722 723 724 /*********************************************************************//** 725 * @brief Write value to General purpose registers 726 * @param[in] RTCx RTC peripheral selected, should be LPC_RTC 727 * @param[in] Channel General purpose registers Channel number, 728 * should be in range from 0 to 4. 729 * @param[in] Value Value to write 730 * @return None 731 * Note: These General purpose registers can be used to store important 732 * information when the main power supply is off. The value in these 733 * registers is not affected by chip reset. 734 **********************************************************************/ 735 void RTC_WriteGPREG (LPC_RTC_TypeDef *RTCx, uint8_t Channel, uint32_t Value) 736 { 737 uint32_t *preg; 738 739 CHECK_PARAM(PARAM_RTCx(RTCx)); 740 CHECK_PARAM(PARAM_RTC_GPREG_CH(Channel)); 741 742 preg = (uint32_t *)&RTCx->GPREG0; 743 preg += Channel; 744 *preg = Value; 745 } 746 747 748 /*********************************************************************//** 749 * @brief Read value from General purpose registers 750 * @param[in] RTCx RTC peripheral selected, should be LPC_RTC 751 * @param[in] Channel General purpose registers Channel number, 752 * should be in range from 0 to 4. 753 * @return Read Value 754 * Note: These General purpose registers can be used to store important 755 * information when the main power supply is off. The value in these 756 * registers is not affected by chip reset. 757 **********************************************************************/ 758 uint32_t RTC_ReadGPREG (LPC_RTC_TypeDef *RTCx, uint8_t Channel) 759 { 760 uint32_t *preg; 761 uint32_t value; 762 763 CHECK_PARAM(PARAM_RTCx(RTCx)); 764 CHECK_PARAM(PARAM_RTC_GPREG_CH(Channel)); 765 766 preg = (uint32_t *)&RTCx->GPREG0; 767 preg += Channel; 768 value = *preg; 769 return (value); 770 } 771 772 /** 773 * @} 774 */ 775 776 #endif /* _RTC */ 777 778 /** 779 * @} 780 */ 781 782 /* --------------------------------- End Of File ------------------------------ */ 783