1 /**********************************************************************
\r
2 * $Id$ lpc18xx_rtc.c 2011-06-02
\r
4 * @file lpc18xx_rtc.c
\r
5 * @brief Contains all functions support for RTC firmware library on LPC18xx
\r
7 * @date 02. June. 2011
\r
8 * @author NXP MCU SW Application Team
\r
10 * Copyright(C) 2011, NXP Semiconductor
\r
11 * All rights reserved.
\r
13 ***********************************************************************
\r
14 * Software that is described herein is for illustrative purposes only
\r
15 * which provides customers with programming information regarding the
\r
16 * products. This software is supplied "AS IS" without any warranties.
\r
17 * NXP Semiconductors assumes no responsibility or liability for the
\r
18 * use of the software, conveys no license or title under any patent,
\r
19 * copyright, or mask work right to the product. NXP Semiconductors
\r
20 * reserves the right to make changes in the software without
\r
21 * notification. NXP Semiconductors also make no representation or
\r
22 * warranty that such application will be suitable for the specified
\r
23 * use without further testing or modification.
\r
24 **********************************************************************/
\r
27 /* Peripheral group ----------------------------------------------------------- */
\r
32 /* Includes ------------------------------------------------------------------- */
\r
33 #include "lpc18xx_rtc.h"
\r
34 #include "lpc18xx_cgu.h"
\r
36 /* If this source file built with example, the LPC18xx FW library configuration
\r
37 * file in each example directory ("lpc18xx_libcfg.h") must be included,
\r
38 * otherwise the default FW library configuration file must be included instead
\r
40 #ifdef __BUILD_WITH_EXAMPLE__
\r
41 #include "lpc18xx_libcfg.h"
\r
43 #include "lpc18xx_libcfg_default.h"
\r
44 #endif /* __BUILD_WITH_EXAMPLE__ */
\r
49 /* Public Functions ----------------------------------------------------------- */
\r
50 /** @addtogroup RTC_Public_Functions
\r
54 /********************************************************************//**
\r
55 * @brief Initializes the RTC peripheral.
\r
56 * @param[in] RTCx RTC peripheral selected, should be LPC_RTC
\r
58 *********************************************************************/
\r
59 void RTC_Init (LPC_RTC_Type *RTCx)
\r
61 CHECK_PARAM(PARAM_RTCx(RTCx));
\r
63 // Configure clock to RTC
\r
64 LPC_CREG->CREG0 &= ~((1<<3)|(1<<2)); // Reset 32Khz oscillator
\r
65 LPC_CREG->CREG0 |= (1<<1)|(1<<0); // Enable 32 kHz & 1 kHz on osc32k and release reset
\r
66 LPC_SCU->SFSCLK_0 = 1 | (0x3<<2); // function 1; CGU clk out, pull down
\r
67 LPC_CGU->BASE_OUT_CLK = (CGU_CLKSRC_32KHZ_OSC<<24) |(1<<11); // base clock out use 32KHz crystal and auto block
\r
70 /* Reset RTC clock*/
\r
71 RTCx->CCR = RTC_CCR_CTCRST | RTC_CCR_CCALEN;
\r
73 while(RTCx->CCR!=(RTC_CCR_CTCRST | RTC_CCR_CCALEN));
\r
76 /* Finish resetting RTC clock*/
\r
77 RTCx->CCR = RTC_CCR_CCALEN;
\r
79 while(RTCx->CCR != RTC_CCR_CCALEN);
\r
80 /* Clear counter increment and alarm interrupt */
\r
81 RTCx->ILR = RTC_IRL_RTCCIF | RTC_IRL_RTCALF;
\r
82 while(RTCx->ILR!=0);
\r
83 // Clear all register to be default
\r
86 RTCx->CALIBRATION = 0x00;
\r
90 /*********************************************************************//**
\r
91 * @brief De-initializes the RTC peripheral registers to their
\r
92 * default reset values.
\r
93 * @param[in] RTCx RTC peripheral selected, should be LPC_RTC
\r
95 **********************************************************************/
\r
96 void RTC_DeInit(LPC_RTC_Type *RTCx)
\r
98 CHECK_PARAM(PARAM_RTCx(RTCx));
\r
103 /*********************************************************************//**
\r
104 * @brief Reset clock tick counter in RTC peripheral
\r
105 * @param[in] RTCx RTC peripheral selected, should be LPC_RTC
\r
107 **********************************************************************/
\r
108 void RTC_ResetClockTickCounter(LPC_RTC_Type *RTCx)
\r
110 CHECK_PARAM(PARAM_RTCx(RTCx));
\r
112 RTCx->CCR |= RTC_CCR_CTCRST;
\r
113 RTCx->CCR &= (~RTC_CCR_CTCRST) & RTC_CCR_BITMASK;
\r
116 /*********************************************************************//**
\r
117 * @brief Start/Stop RTC peripheral
\r
118 * @param[in] RTCx RTC peripheral selected, should be LPC_RTC
\r
119 * @param[in] NewState New State of this function, should be:
\r
120 * - ENABLE :The time counters are enabled
\r
121 * - DISABLE :The time counters are disabled
\r
123 **********************************************************************/
\r
124 void RTC_Cmd (LPC_RTC_Type *RTCx, FunctionalState NewState)
\r
126 CHECK_PARAM(PARAM_RTCx(RTCx));
\r
127 CHECK_PARAM(PARAM_FUNCTIONALSTATE(NewState));
\r
129 if (NewState == ENABLE)
\r
133 RTCx->CCR |= RTC_CCR_CLKEN;
\r
135 while((RTCx->CCR&RTC_CCR_CLKEN)==0);
\r
139 RTCx->CCR &= (~RTC_CCR_CLKEN) & RTC_CCR_BITMASK;
\r
144 /*********************************************************************//**
\r
145 * @brief Enable/Disable Counter increment interrupt for each time type
\r
146 * in RTC peripheral
\r
147 * @param[in] RTCx RTC peripheral selected, should be LPC_RTC
\r
148 * @param[in] CntIncrIntType: Counter Increment Interrupt type,
\r
149 * an increment of this type value below will generates
\r
150 * an interrupt, should be:
\r
151 * - RTC_TIMETYPE_SECOND
\r
152 * - RTC_TIMETYPE_MINUTE
\r
153 * - RTC_TIMETYPE_HOUR
\r
154 * - RTC_TIMETYPE_DAYOFWEEK
\r
155 * - RTC_TIMETYPE_DAYOFMONTH
\r
156 * - RTC_TIMETYPE_DAYOFYEAR
\r
157 * - RTC_TIMETYPE_MONTH
\r
158 * - RTC_TIMETYPE_YEAR
\r
159 * @param[in] NewState New State of this function, should be:
\r
160 * - ENABLE: Counter Increment interrupt for this time type are enabled
\r
161 * - DISABLE: Counter Increment interrupt for this time type are disabled
\r
163 **********************************************************************/
\r
164 void RTC_CntIncrIntConfig (LPC_RTC_Type *RTCx, uint32_t CntIncrIntType, \
\r
165 FunctionalState NewState)
\r
169 CHECK_PARAM(PARAM_RTCx(RTCx));
\r
170 CHECK_PARAM(PARAM_FUNCTIONALSTATE(NewState));
\r
171 CHECK_PARAM(PARAM_RTC_TIMETYPE(CntIncrIntType));
\r
173 switch (CntIncrIntType)
\r
175 case RTC_TIMETYPE_SECOND:
\r
176 tem = RTC_CIIR_IMSEC;
\r
178 case RTC_TIMETYPE_MINUTE:
\r
179 tem = RTC_CIIR_IMMIN;
\r
181 case RTC_TIMETYPE_HOUR:
\r
182 tem = RTC_CIIR_IMHOUR;
\r
184 case RTC_TIMETYPE_DAYOFWEEK:
\r
185 tem = RTC_CIIR_IMDOW;
\r
187 case RTC_TIMETYPE_DAYOFMONTH:
\r
188 tem = RTC_CIIR_IMDOM;
\r
190 case RTC_TIMETYPE_DAYOFYEAR:
\r
191 tem = RTC_CIIR_IMDOY;
\r
193 case RTC_TIMETYPE_MONTH:
\r
194 tem = RTC_CIIR_IMMON;
\r
196 case RTC_TIMETYPE_YEAR:
\r
197 tem = RTC_CIIR_IMYEAR;
\r
200 if (NewState == ENABLE)
\r
206 //while((RTCx->CIIR & tem)== 0);
\r
212 RTCx->CIIR &= (~tem) & RTC_CIIR_BITMASK;
\r
214 //while(RTCx->CIIR & tem);
\r
219 /*********************************************************************//**
\r
220 * @brief Enable/Disable Alarm interrupt for each time type
\r
221 * in RTC peripheral
\r
222 * @param[in] RTCx RTC peripheral selected, should be LPC_RTC
\r
223 * @param[in] AlarmTimeType: Alarm Time Interrupt type,
\r
224 * an matching of this type value below with current time
\r
225 * in RTC will generates an interrupt, should be:
\r
226 * - RTC_TIMETYPE_SECOND
\r
227 * - RTC_TIMETYPE_MINUTE
\r
228 * - RTC_TIMETYPE_HOUR
\r
229 * - RTC_TIMETYPE_DAYOFWEEK
\r
230 * - RTC_TIMETYPE_DAYOFMONTH
\r
231 * - RTC_TIMETYPE_DAYOFYEAR
\r
232 * - RTC_TIMETYPE_MONTH
\r
233 * - RTC_TIMETYPE_YEAR
\r
234 * @param[in] NewState New State of this function, should be:
\r
235 * - ENABLE: Alarm interrupt for this time type are enabled
\r
236 * - DISABLE: Alarm interrupt for this time type are disabled
\r
238 **********************************************************************/
\r
239 void RTC_AlarmIntConfig (LPC_RTC_Type *RTCx, uint32_t AlarmTimeType, \
\r
240 FunctionalState NewState)
\r
244 CHECK_PARAM(PARAM_RTCx(RTCx));
\r
245 CHECK_PARAM(PARAM_FUNCTIONALSTATE(NewState));
\r
246 CHECK_PARAM(PARAM_RTC_TIMETYPE(AlarmTimeType));
\r
248 switch (AlarmTimeType)
\r
250 case RTC_TIMETYPE_SECOND:
\r
251 tem = (RTC_AMR_AMRSEC);
\r
253 case RTC_TIMETYPE_MINUTE:
\r
254 tem = (RTC_AMR_AMRMIN);
\r
256 case RTC_TIMETYPE_HOUR:
\r
257 tem = (RTC_AMR_AMRHOUR);
\r
259 case RTC_TIMETYPE_DAYOFWEEK:
\r
260 tem = (RTC_AMR_AMRDOW);
\r
262 case RTC_TIMETYPE_DAYOFMONTH:
\r
263 tem = (RTC_AMR_AMRDOM);
\r
265 case RTC_TIMETYPE_DAYOFYEAR:
\r
266 tem = (RTC_AMR_AMRDOY);
\r
268 case RTC_TIMETYPE_MONTH:
\r
269 tem = (RTC_AMR_AMRMON);
\r
271 case RTC_TIMETYPE_YEAR:
\r
272 tem = (RTC_AMR_AMRYEAR);
\r
275 if (NewState == ENABLE)
\r
279 RTCx->AMR &= (~tem) & RTC_AMR_BITMASK;
\r
281 //while(RTCx->AMR & tem);
\r
287 RTCx->AMR |= (tem);
\r
289 //while((RTCx->AMR & tem)== 0);
\r
294 /*********************************************************************//**
\r
295 * @brief Set current time value for each time type in RTC peripheral
\r
296 * @param[in] RTCx RTC peripheral selected, should be LPC_RTC
\r
297 * @param[in] Timetype Time Type, should be:
\r
298 * - RTC_TIMETYPE_SECOND
\r
299 * - RTC_TIMETYPE_MINUTE
\r
300 * - RTC_TIMETYPE_HOUR
\r
301 * - RTC_TIMETYPE_DAYOFWEEK
\r
302 * - RTC_TIMETYPE_DAYOFMONTH
\r
303 * - RTC_TIMETYPE_DAYOFYEAR
\r
304 * - RTC_TIMETYPE_MONTH
\r
305 * - RTC_TIMETYPE_YEAR
\r
306 * @param[in] TimeValue Time value to set
\r
308 **********************************************************************/
\r
309 void RTC_SetTime (LPC_RTC_Type *RTCx, uint32_t Timetype, uint32_t TimeValue)
\r
311 CHECK_PARAM(PARAM_RTCx(RTCx));
\r
312 CHECK_PARAM(PARAM_RTC_TIMETYPE(Timetype));
\r
316 case RTC_TIMETYPE_SECOND:
\r
317 CHECK_PARAM(TimeValue <= RTC_SECOND_MAX);
\r
319 RTCx->SEC = TimeValue & RTC_SEC_MASK;
\r
322 case RTC_TIMETYPE_MINUTE:
\r
323 CHECK_PARAM(TimeValue <= RTC_MINUTE_MAX);
\r
325 RTCx->MIN = TimeValue & RTC_MIN_MASK;
\r
328 case RTC_TIMETYPE_HOUR:
\r
329 CHECK_PARAM(TimeValue <= RTC_HOUR_MAX);
\r
331 RTCx->HRS = TimeValue & RTC_HOUR_MASK;
\r
334 case RTC_TIMETYPE_DAYOFWEEK:
\r
335 CHECK_PARAM(TimeValue <= RTC_DAYOFWEEK_MAX);
\r
337 RTCx->DOW = TimeValue & RTC_DOW_MASK;
\r
340 case RTC_TIMETYPE_DAYOFMONTH:
\r
341 CHECK_PARAM((TimeValue <= RTC_DAYOFMONTH_MAX) \
\r
342 && (TimeValue >= RTC_DAYOFMONTH_MIN));
\r
344 RTCx->DOM = TimeValue & RTC_DOM_MASK;
\r
347 case RTC_TIMETYPE_DAYOFYEAR:
\r
348 CHECK_PARAM((TimeValue >= RTC_DAYOFYEAR_MIN) \
\r
349 && (TimeValue <= RTC_DAYOFYEAR_MAX));
\r
351 RTCx->DOY = TimeValue & RTC_DOY_MASK;
\r
354 case RTC_TIMETYPE_MONTH:
\r
355 CHECK_PARAM((TimeValue >= RTC_MONTH_MIN) \
\r
356 && (TimeValue <= RTC_MONTH_MAX));
\r
358 RTCx->MONTH = TimeValue & RTC_MONTH_MASK;
\r
361 case RTC_TIMETYPE_YEAR:
\r
362 CHECK_PARAM(TimeValue <= RTC_YEAR_MAX);
\r
364 RTCx->YEAR = TimeValue & RTC_YEAR_MASK;
\r
369 /*********************************************************************//**
\r
370 * @brief Get current time value for each type time type
\r
371 * @param[in] RTCx RTC peripheral selected, should be LPC_RTC
\r
372 * @param[in] Timetype Time Type, should be:
\r
373 * - RTC_TIMETYPE_SECOND
\r
374 * - RTC_TIMETYPE_MINUTE
\r
375 * - RTC_TIMETYPE_HOUR
\r
376 * - RTC_TIMETYPE_DAYOFWEEK
\r
377 * - RTC_TIMETYPE_DAYOFMONTH
\r
378 * - RTC_TIMETYPE_DAYOFYEAR
\r
379 * - RTC_TIMETYPE_MONTH
\r
380 * - RTC_TIMETYPE_YEAR
\r
381 * @return Value of time according to specified time type
\r
382 **********************************************************************/
\r
383 uint32_t RTC_GetTime(LPC_RTC_Type *RTCx, uint32_t Timetype)
\r
385 CHECK_PARAM(PARAM_RTCx(RTCx));
\r
386 CHECK_PARAM(PARAM_RTC_TIMETYPE(Timetype));
\r
390 case RTC_TIMETYPE_SECOND:
\r
391 return (RTCx->SEC & RTC_SEC_MASK);
\r
392 case RTC_TIMETYPE_MINUTE:
\r
393 return (RTCx->MIN & RTC_MIN_MASK);
\r
394 case RTC_TIMETYPE_HOUR:
\r
395 return (RTCx->HRS & RTC_HOUR_MASK);
\r
396 case RTC_TIMETYPE_DAYOFWEEK:
\r
397 return (RTCx->DOW & RTC_DOW_MASK);
\r
398 case RTC_TIMETYPE_DAYOFMONTH:
\r
399 return (RTCx->DOM & RTC_DOM_MASK);
\r
400 case RTC_TIMETYPE_DAYOFYEAR:
\r
401 return (RTCx->DOY & RTC_DOY_MASK);
\r
402 case RTC_TIMETYPE_MONTH:
\r
403 return (RTCx->MONTH & RTC_MONTH_MASK);
\r
404 case RTC_TIMETYPE_YEAR:
\r
405 return (RTCx->YEAR & RTC_YEAR_MASK);
\r
412 /*********************************************************************//**
\r
413 * @brief Set full of time in RTC peripheral
\r
414 * @param[in] RTCx RTC peripheral selected, should be LPC_RTC
\r
415 * @param[in] pFullTime Pointer to a RTC_TIME_Type structure that
\r
416 * contains time value in full.
\r
418 **********************************************************************/
\r
419 void RTC_SetFullTime (LPC_RTC_Type *RTCx, RTC_TIME_Type *pFullTime)
\r
421 CHECK_PARAM(PARAM_RTCx(RTCx));
\r
423 RTCx->DOM = pFullTime->DOM & RTC_DOM_MASK;
\r
424 RTCx->DOW = pFullTime->DOW & RTC_DOW_MASK;
\r
425 RTCx->DOY = pFullTime->DOY & RTC_DOY_MASK;
\r
426 RTCx->HRS = pFullTime->HOUR & RTC_HOUR_MASK;
\r
427 RTCx->MIN = pFullTime->MIN & RTC_MIN_MASK;
\r
428 RTCx->SEC = pFullTime->SEC & RTC_SEC_MASK;
\r
429 RTCx->MONTH = pFullTime->MONTH & RTC_MONTH_MASK;
\r
430 RTCx->YEAR = pFullTime->YEAR & RTC_YEAR_MASK;
\r
434 /*********************************************************************//**
\r
435 * @brief Get full of time in RTC peripheral
\r
436 * @param[in] RTCx RTC peripheral selected, should be LPC_RTC
\r
437 * @param[in] pFullTime Pointer to a RTC_TIME_Type structure that
\r
438 * will be stored time in full.
\r
440 **********************************************************************/
\r
441 void RTC_GetFullTime (LPC_RTC_Type *RTCx, RTC_TIME_Type *pFullTime)
\r
443 CHECK_PARAM(PARAM_RTCx(RTCx));
\r
445 pFullTime->DOM = RTCx->DOM & RTC_DOM_MASK;
\r
446 pFullTime->DOW = RTCx->DOW & RTC_DOW_MASK;
\r
447 pFullTime->DOY = RTCx->DOY & RTC_DOY_MASK;
\r
448 pFullTime->HOUR = RTCx->HRS & RTC_HOUR_MASK;
\r
449 pFullTime->MIN = RTCx->MIN & RTC_MIN_MASK;
\r
450 pFullTime->SEC = RTCx->SEC & RTC_SEC_MASK;
\r
451 pFullTime->MONTH = RTCx->MONTH & RTC_MONTH_MASK;
\r
452 pFullTime->YEAR = RTCx->YEAR & RTC_YEAR_MASK;
\r
456 /*********************************************************************//**
\r
457 * @brief Set alarm time value for each time type
\r
458 * @param[in] RTCx RTC peripheral selected, should be LPC_RTC
\r
459 * @param[in] Timetype Time Type, should be:
\r
460 * - RTC_TIMETYPE_SECOND
\r
461 * - RTC_TIMETYPE_MINUTE
\r
462 * - RTC_TIMETYPE_HOUR
\r
463 * - RTC_TIMETYPE_DAYOFWEEK
\r
464 * - RTC_TIMETYPE_DAYOFMONTH
\r
465 * - RTC_TIMETYPE_DAYOFYEAR
\r
466 * - RTC_TIMETYPE_MONTH
\r
467 * - RTC_TIMETYPE_YEAR
\r
468 * @param[in] ALValue Alarm time value to set
\r
470 **********************************************************************/
\r
471 void RTC_SetAlarmTime (LPC_RTC_Type *RTCx, uint32_t Timetype, uint32_t ALValue)
\r
473 CHECK_PARAM(PARAM_RTCx(RTCx));
\r
477 case RTC_TIMETYPE_SECOND:
\r
478 CHECK_PARAM(ALValue <= RTC_SECOND_MAX);
\r
480 RTCx->ASEC = ALValue & RTC_SEC_MASK;
\r
483 case RTC_TIMETYPE_MINUTE:
\r
484 CHECK_PARAM(ALValue <= RTC_MINUTE_MAX);
\r
486 RTCx->AMIN = ALValue & RTC_MIN_MASK;
\r
489 case RTC_TIMETYPE_HOUR:
\r
490 CHECK_PARAM(ALValue <= RTC_HOUR_MAX);
\r
492 RTCx->AHRS = ALValue & RTC_HOUR_MASK;
\r
495 case RTC_TIMETYPE_DAYOFWEEK:
\r
496 CHECK_PARAM(ALValue <= RTC_DAYOFWEEK_MAX);
\r
498 RTCx->ADOW = ALValue & RTC_DOW_MASK;
\r
501 case RTC_TIMETYPE_DAYOFMONTH:
\r
502 CHECK_PARAM((ALValue <= RTC_DAYOFMONTH_MAX) \
\r
503 && (ALValue >= RTC_DAYOFMONTH_MIN));
\r
505 RTCx->ADOM = ALValue & RTC_DOM_MASK;
\r
508 case RTC_TIMETYPE_DAYOFYEAR:
\r
509 CHECK_PARAM((ALValue >= RTC_DAYOFYEAR_MIN) \
\r
510 && (ALValue <= RTC_DAYOFYEAR_MAX));
\r
512 RTCx->ADOY = ALValue & RTC_DOY_MASK;
\r
515 case RTC_TIMETYPE_MONTH:
\r
516 CHECK_PARAM((ALValue >= RTC_MONTH_MIN) \
\r
517 && (ALValue <= RTC_MONTH_MAX));
\r
519 RTCx->AMON = ALValue & RTC_MONTH_MASK;
\r
522 case RTC_TIMETYPE_YEAR:
\r
523 CHECK_PARAM(ALValue <= RTC_YEAR_MAX);
\r
525 RTCx->AYRS = ALValue & RTC_YEAR_MASK;
\r
532 /*********************************************************************//**
\r
533 * @brief Get alarm time value for each time type
\r
534 * @param[in] RTCx RTC peripheral selected, should be LPC_RTC
\r
535 * @param[in] Timetype Time Type, should be:
\r
536 * - RTC_TIMETYPE_SECOND
\r
537 * - RTC_TIMETYPE_MINUTE
\r
538 * - RTC_TIMETYPE_HOUR
\r
539 * - RTC_TIMETYPE_DAYOFWEEK
\r
540 * - RTC_TIMETYPE_DAYOFMONTH
\r
541 * - RTC_TIMETYPE_DAYOFYEAR
\r
542 * - RTC_TIMETYPE_MONTH
\r
543 * - RTC_TIMETYPE_YEAR
\r
544 * @return Value of Alarm time according to specified time type
\r
545 **********************************************************************/
\r
546 uint32_t RTC_GetAlarmTime (LPC_RTC_Type *RTCx, uint32_t Timetype)
\r
550 case RTC_TIMETYPE_SECOND:
\r
551 return (RTCx->ASEC & RTC_SEC_MASK);
\r
552 case RTC_TIMETYPE_MINUTE:
\r
553 return (RTCx->AMIN & RTC_MIN_MASK);
\r
554 case RTC_TIMETYPE_HOUR:
\r
555 return (RTCx->AHRS & RTC_HOUR_MASK);
\r
556 case RTC_TIMETYPE_DAYOFWEEK:
\r
557 return (RTCx->ADOW & RTC_DOW_MASK);
\r
558 case RTC_TIMETYPE_DAYOFMONTH:
\r
559 return (RTCx->ADOM & RTC_DOM_MASK);
\r
560 case RTC_TIMETYPE_DAYOFYEAR:
\r
561 return (RTCx->ADOY & RTC_DOY_MASK);
\r
562 case RTC_TIMETYPE_MONTH:
\r
563 return (RTCx->AMON & RTC_MONTH_MASK);
\r
564 case RTC_TIMETYPE_YEAR:
\r
565 return (RTCx->AYRS & RTC_YEAR_MASK);
\r
572 /*********************************************************************//**
\r
573 * @brief Set full of alarm time in RTC peripheral
\r
574 * @param[in] RTCx RTC peripheral selected, should be LPC_RTC
\r
575 * @param[in] pFullTime Pointer to a RTC_TIME_Type structure that
\r
576 * contains alarm time value in full.
\r
578 **********************************************************************/
\r
579 void RTC_SetFullAlarmTime (LPC_RTC_Type *RTCx, RTC_TIME_Type *pFullTime)
\r
581 CHECK_PARAM(PARAM_RTCx(RTCx));
\r
583 RTCx->ADOM = pFullTime->DOM & RTC_DOM_MASK;
\r
584 RTCx->ADOW = pFullTime->DOW & RTC_DOW_MASK;
\r
585 RTCx->ADOY = pFullTime->DOY & RTC_DOY_MASK;
\r
586 RTCx->AHRS = pFullTime->HOUR & RTC_HOUR_MASK;
\r
587 RTCx->AMIN = pFullTime->MIN & RTC_MIN_MASK;
\r
588 RTCx->ASEC = pFullTime->SEC & RTC_SEC_MASK;
\r
589 RTCx->AMON = pFullTime->MONTH & RTC_MONTH_MASK;
\r
590 RTCx->AYRS = pFullTime->YEAR & RTC_YEAR_MASK;
\r
594 /*********************************************************************//**
\r
595 * @brief Get full of alarm time in RTC peripheral
\r
596 * @param[in] RTCx RTC peripheral selected, should be LPC_RTC
\r
597 * @param[in] pFullTime Pointer to a RTC_TIME_Type structure that
\r
598 * will be stored alarm time in full.
\r
600 **********************************************************************/
\r
601 void RTC_GetFullAlarmTime (LPC_RTC_Type *RTCx, RTC_TIME_Type *pFullTime)
\r
603 CHECK_PARAM(PARAM_RTCx(RTCx));
\r
605 pFullTime->DOM = RTCx->ADOM & RTC_DOM_MASK;
\r
606 pFullTime->DOW = RTCx->ADOW & RTC_DOW_MASK;
\r
607 pFullTime->DOY = RTCx->ADOY & RTC_DOY_MASK;
\r
608 pFullTime->HOUR = RTCx->AHRS & RTC_HOUR_MASK;
\r
609 pFullTime->MIN = RTCx->AMIN & RTC_MIN_MASK;
\r
610 pFullTime->SEC = RTCx->ASEC & RTC_SEC_MASK;
\r
611 pFullTime->MONTH = RTCx->AMON & RTC_MONTH_MASK;
\r
612 pFullTime->YEAR = RTCx->AYRS & RTC_YEAR_MASK;
\r
616 /*********************************************************************//**
\r
617 * @brief Check whether if specified Location interrupt in
\r
618 * RTC peripheral is set or not
\r
619 * @param[in] RTCx RTC peripheral selected, should be LPC_RTC
\r
620 * @param[in] IntType Interrupt location type, should be:
\r
621 * - RTC_INT_COUNTER_INCREASE: Counter Increment Interrupt block generated an interrupt.
\r
622 * - RTC_INT_ALARM: Alarm generated an interrupt.
\r
623 * @return New state of specified Location interrupt in RTC peripheral
\r
626 **********************************************************************/
\r
627 IntStatus RTC_GetIntPending (LPC_RTC_Type *RTCx, uint32_t IntType)
\r
629 CHECK_PARAM(PARAM_RTCx(RTCx));
\r
630 CHECK_PARAM(PARAM_RTC_INT(IntType));
\r
632 return ((RTCx->ILR & IntType) ? SET : RESET);
\r
636 /*********************************************************************//**
\r
637 * @brief Clear specified Location interrupt pending in
\r
639 * @param[in] RTCx RTC peripheral selected, should be LPC_RTC
\r
640 * @param[in] IntType Interrupt location type, should be:
\r
641 * - RTC_INT_COUNTER_INCREASE :Clear Counter Increment Interrupt pending.
\r
642 * - RTC_INT_ALARM :Clear alarm interrupt pending
\r
644 **********************************************************************/
\r
645 void RTC_ClearIntPending (LPC_RTC_Type *RTCx, uint32_t IntType)
\r
647 CHECK_PARAM(PARAM_RTCx(RTCx));
\r
648 CHECK_PARAM(PARAM_RTC_INT(IntType));
\r
650 RTCx->ILR = IntType;
\r
653 /*********************************************************************//**
\r
654 * @brief Enable/Disable calibration counter in RTC peripheral
\r
655 * @param[in] RTCx RTC peripheral selected, should be LPC_RTC
\r
656 * @param[in] NewState New State of this function, should be:
\r
657 * - ENABLE :The calibration counter is enabled and counting
\r
658 * - DISABLE :The calibration counter is disabled and reset to zero
\r
660 **********************************************************************/
\r
661 void RTC_CalibCounterCmd(LPC_RTC_Type *RTCx, FunctionalState NewState)
\r
663 CHECK_PARAM(PARAM_RTCx(RTCx));
\r
664 CHECK_PARAM(PARAM_FUNCTIONALSTATE(NewState));
\r
666 if (NewState == ENABLE)
\r
670 RTCx->CCR &= (~RTC_CCR_CCALEN) & RTC_CCR_BITMASK;
\r
671 }while(RTCx->CCR&RTC_CCR_CCALEN);
\r
675 RTCx->CCR |= RTC_CCR_CCALEN;
\r
680 /*********************************************************************//**
\r
681 * @brief Configures Calibration in RTC peripheral
\r
682 * @param[in] RTCx RTC peripheral selected, should be LPC_RTC
\r
683 * @param[in] CalibValue Calibration value, should be in range from
\r
685 * @param[in] CalibDir Calibration Direction, should be:
\r
686 * - RTC_CALIB_DIR_FORWARD :Forward calibration
\r
687 * - RTC_CALIB_DIR_BACKWARD :Backward calibration
\r
689 **********************************************************************/
\r
690 void RTC_CalibConfig(LPC_RTC_Type *RTCx, uint32_t CalibValue, uint8_t CalibDir)
\r
692 CHECK_PARAM(PARAM_RTCx(RTCx));
\r
693 CHECK_PARAM(PARAM_RTC_CALIB_DIR(CalibDir));
\r
694 CHECK_PARAM(CalibValue < RTC_CALIBRATION_MAX);
\r
696 RTCx->CALIBRATION = ((CalibValue - 1) & RTC_CALIBRATION_CALVAL_MASK) \
\r
697 | ((CalibDir == RTC_CALIB_DIR_BACKWARD) ? RTC_CALIBRATION_LIBDIR : 0);
\r
701 /*********************************************************************//**
\r
702 * @brief Write value to General purpose registers
\r
703 * @param[in] RTCx RTC peripheral selected, should be LPC_RTC
\r
704 * @param[in] Channel General purpose registers Channel number,
\r
705 * should be in range from 0 to 63.
\r
706 * @param[in] Value Value to write
\r
708 * Note: These General purpose registers can be used to store important
\r
709 * information when the main power supply is off. The value in these
\r
710 * registers is not affected by chip reset.
\r
711 **********************************************************************/
\r
712 void RTC_WriteGPREG (LPC_RTC_Type *RTCx, uint8_t Channel, uint32_t Value)
\r
716 CHECK_PARAM(PARAM_RTCx(RTCx));
\r
717 CHECK_PARAM(PARAM_RTC_GPREG_CH(Channel));
\r
719 preg = (uint32_t *)RTC_GPREG_BASE;
\r
725 /*********************************************************************//**
\r
726 * @brief Read value from General purpose registers
\r
727 * @param[in] RTCx RTC peripheral selected, should be LPC_RTC
\r
728 * @param[in] Channel General purpose registers Channel number,
\r
729 * should be in range from 0 to 4.
\r
730 * @return Read Value
\r
731 * Note: These General purpose registers can be used to store important
\r
732 * information when the main power supply is off. The value in these
\r
733 * registers is not affected by chip reset.
\r
734 **********************************************************************/
\r
735 uint32_t RTC_ReadGPREG (LPC_RTC_Type *RTCx, uint8_t Channel)
\r
740 CHECK_PARAM(PARAM_RTCx(RTCx));
\r
741 CHECK_PARAM(PARAM_RTC_GPREG_CH(Channel));
\r
743 preg = (uint32_t *)RTC_GPREG_BASE;
\r
759 /* --------------------------------- End Of File ------------------------------ */
\r