1 /**********************************************************************
\r
2 * $Id$ lpc18xx_rtc.h 2011-06-02
\r
4 * @file lpc18xx_rtc.h
\r
5 * @brief Contains all macro definitions and function prototypes
\r
6 * support for RTC firmware library on LPC18xx
\r
8 * @date 02. June. 2011
\r
9 * @author NXP MCU SW Application Team
\r
11 * Copyright(C) 2011, NXP Semiconductor
\r
12 * All rights reserved.
\r
14 ***********************************************************************
\r
15 * Software that is described herein is for illustrative purposes only
\r
16 * which provides customers with programming information regarding the
\r
17 * products. This software is supplied "AS IS" without any warranties.
\r
18 * NXP Semiconductors assumes no responsibility or liability for the
\r
19 * use of the software, conveys no license or title under any patent,
\r
20 * copyright, or mask work right to the product. NXP Semiconductors
\r
21 * reserves the right to make changes in the software without
\r
22 * notification. NXP Semiconductors also make no representation or
\r
23 * warranty that such application will be suitable for the specified
\r
24 * use without further testing or modification.
\r
25 **********************************************************************/
\r
27 /* Peripheral group ----------------------------------------------------------- */
\r
28 /** @defgroup RTC RTC (Real-Time Clock)
\r
29 * @ingroup LPC1800CMSIS_FwLib_Drivers
\r
33 #ifndef LPC18XX_RTC_H_
\r
34 #define LPC18XX_RTC_H_
\r
36 /* Includes ------------------------------------------------------------------- */
\r
37 #include "LPC18xx.h"
\r
38 #include "lpc_types.h"
\r
47 /* Private Macros ------------------------------------------------------------- */
\r
48 /** @defgroup RTC_Private_Macros RTC Private Macros
\r
52 /* ----------------------- BIT DEFINITIONS ----------------------------------- */
\r
53 /* Miscellaneous register group --------------------------------------------- */
\r
54 /**********************************************************************
\r
55 * ILR register definitions
\r
56 **********************************************************************/
\r
57 /** ILR register mask */
\r
58 #define RTC_ILR_BITMASK ((0x00000003))
\r
59 /** Bit inform the source interrupt is counter increment*/
\r
60 #define RTC_IRL_RTCCIF ((1<<0))
\r
61 /** Bit inform the source interrupt is alarm match*/
\r
62 #define RTC_IRL_RTCALF ((1<<1))
\r
64 /**********************************************************************
\r
65 * CCR register definitions
\r
66 **********************************************************************/
\r
67 /** CCR register mask */
\r
68 #define RTC_CCR_BITMASK ((0x00000013))
\r
70 #define RTC_CCR_CLKEN ((1<<0))
\r
72 #define RTC_CCR_CTCRST ((1<<1))
\r
73 /** Calibration counter enable */
\r
74 #define RTC_CCR_CCALEN ((1<<4))
\r
76 /**********************************************************************
\r
77 * CIIR register definitions
\r
78 **********************************************************************/
\r
79 /** Counter Increment Interrupt bit for second */
\r
80 #define RTC_CIIR_IMSEC ((1<<0))
\r
81 /** Counter Increment Interrupt bit for minute */
\r
82 #define RTC_CIIR_IMMIN ((1<<1))
\r
83 /** Counter Increment Interrupt bit for hour */
\r
84 #define RTC_CIIR_IMHOUR ((1<<2))
\r
85 /** Counter Increment Interrupt bit for day of month */
\r
86 #define RTC_CIIR_IMDOM ((1<<3))
\r
87 /** Counter Increment Interrupt bit for day of week */
\r
88 #define RTC_CIIR_IMDOW ((1<<4))
\r
89 /** Counter Increment Interrupt bit for day of year */
\r
90 #define RTC_CIIR_IMDOY ((1<<5))
\r
91 /** Counter Increment Interrupt bit for month */
\r
92 #define RTC_CIIR_IMMON ((1<<6))
\r
93 /** Counter Increment Interrupt bit for year */
\r
94 #define RTC_CIIR_IMYEAR ((1<<7))
\r
95 /** CIIR bit mask */
\r
96 #define RTC_CIIR_BITMASK ((0xFF))
\r
98 /**********************************************************************
\r
99 * AMR register definitions
\r
100 **********************************************************************/
\r
101 /** Counter Increment Select Mask bit for second */
\r
102 #define RTC_AMR_AMRSEC ((1<<0))
\r
103 /** Counter Increment Select Mask bit for minute */
\r
104 #define RTC_AMR_AMRMIN ((1<<1))
\r
105 /** Counter Increment Select Mask bit for hour */
\r
106 #define RTC_AMR_AMRHOUR ((1<<2))
\r
107 /** Counter Increment Select Mask bit for day of month */
\r
108 #define RTC_AMR_AMRDOM ((1<<3))
\r
109 /** Counter Increment Select Mask bit for day of week */
\r
110 #define RTC_AMR_AMRDOW ((1<<4))
\r
111 /** Counter Increment Select Mask bit for day of year */
\r
112 #define RTC_AMR_AMRDOY ((1<<5))
\r
113 /** Counter Increment Select Mask bit for month */
\r
114 #define RTC_AMR_AMRMON ((1<<6))
\r
115 /** Counter Increment Select Mask bit for year */
\r
116 #define RTC_AMR_AMRYEAR ((1<<7))
\r
117 /** AMR bit mask */
\r
118 #define RTC_AMR_BITMASK ((0xFF))
\r
120 /**********************************************************************
\r
121 * RTC_AUX register definitions
\r
122 **********************************************************************/
\r
123 /** RTC Oscillator Fail detect flag */
\r
124 #define RTC_AUX_RTC_OSCF ((1<<4))
\r
126 /**********************************************************************
\r
127 * RTC_AUXEN register definitions
\r
128 **********************************************************************/
\r
129 /** Oscillator Fail Detect interrupt enable*/
\r
130 #define RTC_AUXEN_RTC_OSCFEN ((1<<4))
\r
132 /* Consolidated time register group ----------------------------------- */
\r
133 /**********************************************************************
\r
134 * Consolidated Time Register 0 definitions
\r
135 **********************************************************************/
\r
136 #define RTC_CTIME0_SECONDS_MASK ((0x3F))
\r
137 #define RTC_CTIME0_MINUTES_MASK ((0x3F00))
\r
138 #define RTC_CTIME0_HOURS_MASK ((0x1F0000))
\r
139 #define RTC_CTIME0_DOW_MASK ((0x7000000))
\r
141 /**********************************************************************
\r
142 * Consolidated Time Register 1 definitions
\r
143 **********************************************************************/
\r
144 #define RTC_CTIME1_DOM_MASK ((0x1F))
\r
145 #define RTC_CTIME1_MONTH_MASK ((0xF00))
\r
146 #define RTC_CTIME1_YEAR_MASK ((0xFFF0000))
\r
148 /**********************************************************************
\r
149 * Consolidated Time Register 2 definitions
\r
150 **********************************************************************/
\r
151 #define RTC_CTIME2_DOY_MASK ((0xFFF))
\r
153 /**********************************************************************
\r
154 * Time Counter Group and Alarm register group
\r
155 **********************************************************************/
\r
156 /** SEC register mask */
\r
157 #define RTC_SEC_MASK (0x0000003F)
\r
158 /** MIN register mask */
\r
159 #define RTC_MIN_MASK (0x0000003F)
\r
160 /** HOUR register mask */
\r
161 #define RTC_HOUR_MASK (0x0000001F)
\r
162 /** DOM register mask */
\r
163 #define RTC_DOM_MASK (0x0000001F)
\r
164 /** DOW register mask */
\r
165 #define RTC_DOW_MASK (0x00000007)
\r
166 /** DOY register mask */
\r
167 #define RTC_DOY_MASK (0x000001FF)
\r
168 /** MONTH register mask */
\r
169 #define RTC_MONTH_MASK (0x0000000F)
\r
170 /** YEAR register mask */
\r
171 #define RTC_YEAR_MASK (0x00000FFF)
\r
173 #define RTC_SECOND_MAX 59 /*!< Maximum value of second */
\r
174 #define RTC_MINUTE_MAX 59 /*!< Maximum value of minute*/
\r
175 #define RTC_HOUR_MAX 23 /*!< Maximum value of hour*/
\r
176 #define RTC_MONTH_MIN 1 /*!< Minimum value of month*/
\r
177 #define RTC_MONTH_MAX 12 /*!< Maximum value of month*/
\r
178 #define RTC_DAYOFMONTH_MIN 1 /*!< Minimum value of day of month*/
\r
179 #define RTC_DAYOFMONTH_MAX 31 /*!< Maximum value of day of month*/
\r
180 #define RTC_DAYOFWEEK_MAX 6 /*!< Maximum value of day of week*/
\r
181 #define RTC_DAYOFYEAR_MIN 1 /*!< Minimum value of day of year*/
\r
182 #define RTC_DAYOFYEAR_MAX 366 /*!< Maximum value of day of year*/
\r
183 #define RTC_YEAR_MAX 4095 /*!< Maximum value of year*/
\r
185 /**********************************************************************
\r
186 * Calibration register
\r
187 **********************************************************************/
\r
188 /* Calibration register */
\r
189 /** Calibration value */
\r
190 #define RTC_CALIBRATION_CALVAL_MASK ((0x1FFFF))
\r
191 /** Calibration direction */
\r
192 #define RTC_CALIBRATION_LIBDIR ((1<<17))
\r
193 /** Calibration max value */
\r
194 #define RTC_CALIBRATION_MAX ((0x20000))
\r
195 /** Calibration definitions */
\r
196 #define RTC_CALIB_DIR_FORWARD ((uint8_t)(0))
\r
197 #define RTC_CALIB_DIR_BACKWARD ((uint8_t)(1))
\r
200 /* ---------------- CHECK PARAMETER DEFINITIONS ---------------------------- */
\r
201 /** Macro to determine if it is valid RTC peripheral */
\r
202 #define PARAM_RTCx(x) (((uint32_t *)x)==((uint32_t *)LPC_RTC))
\r
204 /* Macro check RTC interrupt type */
\r
205 #define PARAM_RTC_INT(n) ((n==RTC_INT_COUNTER_INCREASE) || (n==RTC_INT_ALARM))
\r
207 /* Macro check RTC time type */
\r
208 #define PARAM_RTC_TIMETYPE(n) ((n==RTC_TIMETYPE_SECOND) || (n==RTC_TIMETYPE_MINUTE) \
\r
209 || (n==RTC_TIMETYPE_HOUR) || (n==RTC_TIMETYPE_DAYOFWEEK) \
\r
210 || (n==RTC_TIMETYPE_DAYOFMONTH) || (n==RTC_TIMETYPE_DAYOFYEAR) \
\r
211 || (n==RTC_TIMETYPE_MONTH) || (n==RTC_TIMETYPE_YEAR))
\r
213 /* Macro check RTC calibration type */
\r
214 #define PARAM_RTC_CALIB_DIR(n) ((n==RTC_CALIB_DIR_FORWARD) || (n==RTC_CALIB_DIR_BACKWARD))
\r
216 /* Macro check RTC GPREG type */
\r
217 #define PARAM_RTC_GPREG_CH(n) ((n<=63))
\r
219 /* RTC GPREG base address*/
\r
220 #define RTC_GPREG_BASE 0x40041000
\r
226 /* Public Types --------------------------------------------------------------- */
\r
227 /** @defgroup RTC_Public_Types RTC Public Types
\r
231 /*********************************************************************//**
\r
232 * @brief RTC enumeration
\r
233 **********************************************************************/
\r
234 /** @brief RTC interrupt source */
\r
236 RTC_INT_COUNTER_INCREASE = RTC_IRL_RTCCIF, /*!< Counter Increment Interrupt */
\r
237 RTC_INT_ALARM = RTC_IRL_RTCALF /*!< The alarm interrupt */
\r
241 /** @brief RTC time type option */
\r
243 RTC_TIMETYPE_SECOND = 0, /*!< Second */
\r
244 RTC_TIMETYPE_MINUTE = 1, /*!< Month */
\r
245 RTC_TIMETYPE_HOUR = 2, /*!< Hour */
\r
246 RTC_TIMETYPE_DAYOFWEEK = 3, /*!< Day of week */
\r
247 RTC_TIMETYPE_DAYOFMONTH = 4, /*!< Day of month */
\r
248 RTC_TIMETYPE_DAYOFYEAR = 5, /*!< Day of year */
\r
249 RTC_TIMETYPE_MONTH = 6, /*!< Month */
\r
250 RTC_TIMETYPE_YEAR = 7 /*!< Year */
\r
251 } RTC_TIMETYPE_Num;
\r
254 /*********************************************************************//**
\r
255 * @brief RTC structure definitions
\r
256 **********************************************************************/
\r
257 /** @brief Time structure definitions for easy manipulate the data */
\r
259 uint32_t SEC; /*!< Seconds Register */
\r
260 uint32_t MIN; /*!< Minutes Register */
\r
261 uint32_t HOUR; /*!< Hours Register */
\r
262 uint32_t DOM; /*!< Day of Month Register */
\r
263 uint32_t DOW; /*!< Day of Week Register */
\r
264 uint32_t DOY; /*!< Day of Year Register */
\r
265 uint32_t MONTH; /*!< Months Register */
\r
266 uint32_t YEAR; /*!< Years Register */
\r
275 /* Public Functions ----------------------------------------------------------- */
\r
276 /** @defgroup RTC_Public_Functions RTC Public Functions
\r
280 void RTC_Init (LPC_RTC_Type *RTCx);
\r
281 void RTC_DeInit(LPC_RTC_Type *RTCx);
\r
283 void RTC_ResetClockTickCounter(LPC_RTC_Type *RTCx);
\r
284 void RTC_Cmd (LPC_RTC_Type *RTCx, FunctionalState NewState);
\r
286 void RTC_SetTime (LPC_RTC_Type *RTCx, uint32_t Timetype, uint32_t TimeValue);
\r
287 uint32_t RTC_GetTime(LPC_RTC_Type *RTCx, uint32_t Timetype);
\r
289 void RTC_SetFullTime (LPC_RTC_Type *RTCx, RTC_TIME_Type *pFullTime);
\r
290 void RTC_GetFullTime (LPC_RTC_Type *RTCx, RTC_TIME_Type *pFullTime);
\r
292 void RTC_AlarmIntConfig (LPC_RTC_Type *RTCx, uint32_t AlarmTimeType, FunctionalState NewState);
\r
293 void RTC_SetAlarmTime (LPC_RTC_Type *RTCx, uint32_t Timetype, uint32_t ALValue);
\r
294 uint32_t RTC_GetAlarmTime (LPC_RTC_Type *RTCx, uint32_t Timetype);
\r
295 void RTC_SetFullAlarmTime (LPC_RTC_Type *RTCx, RTC_TIME_Type *pFullTime);
\r
296 void RTC_GetFullAlarmTime (LPC_RTC_Type *RTCx, RTC_TIME_Type *pFullTime);
\r
298 void RTC_CntIncrIntConfig (LPC_RTC_Type *RTCx, uint32_t CntIncrIntType, FunctionalState NewState);
\r
299 IntStatus RTC_GetIntPending (LPC_RTC_Type *RTCx, uint32_t IntType);
\r
300 void RTC_ClearIntPending (LPC_RTC_Type *RTCx, uint32_t IntType);
\r
302 void RTC_CalibCounterCmd(LPC_RTC_Type *RTCx, FunctionalState NewState);
\r
303 void RTC_CalibConfig(LPC_RTC_Type *RTCx, uint32_t CalibValue, uint8_t CalibDir);
\r
305 void RTC_WriteGPREG (LPC_RTC_Type *RTCx, uint8_t Channel, uint32_t Value);
\r
306 uint32_t RTC_ReadGPREG (LPC_RTC_Type *RTCx, uint8_t Channel);
\r
316 #endif /* LPC18XX_RTC_H_ */
\r
322 /* --------------------------------- End Of File ------------------------------ */
\r