uc-sdk
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
lpc17xx_rtc.h
Go to the documentation of this file.
1 /***********************************************************************/
21 /* Peripheral group ----------------------------------------------------------- */
27 #ifndef LPC17XX_RTC_H_
28 #define LPC17XX_RTC_H_
29 
30 /* Includes ------------------------------------------------------------------- */
31 #include "LPC17xx.h"
32 #include "lpc_types.h"
33 
34 
35 #ifdef __cplusplus
36 extern "C"
37 {
38 #endif
39 
40 
41 /* Private Macros ------------------------------------------------------------- */
46 /* ----------------------- BIT DEFINITIONS ----------------------------------- */
47 /* Miscellaneous register group --------------------------------------------- */
48 /**********************************************************************
49 * ILR register definitions
50 **********************************************************************/
52 #define RTC_ILR_BITMASK ((0x00000003))
53 
54 #define RTC_IRL_RTCCIF ((1<<0))
55 
56 #define RTC_IRL_RTCALF ((1<<1))
57 
58 /**********************************************************************
59 * CCR register definitions
60 **********************************************************************/
62 #define RTC_CCR_BITMASK ((0x00000013))
63 
64 #define RTC_CCR_CLKEN ((1<<0))
65 
66 #define RTC_CCR_CTCRST ((1<<1))
67 
68 #define RTC_CCR_CCALEN ((1<<4))
69 
70 /**********************************************************************
71 * CIIR register definitions
72 **********************************************************************/
74 #define RTC_CIIR_IMSEC ((1<<0))
75 
76 #define RTC_CIIR_IMMIN ((1<<1))
77 
78 #define RTC_CIIR_IMHOUR ((1<<2))
79 
80 #define RTC_CIIR_IMDOM ((1<<3))
81 
82 #define RTC_CIIR_IMDOW ((1<<4))
83 
84 #define RTC_CIIR_IMDOY ((1<<5))
85 
86 #define RTC_CIIR_IMMON ((1<<6))
87 
88 #define RTC_CIIR_IMYEAR ((1<<7))
89 
90 #define RTC_CIIR_BITMASK ((0xFF))
91 
92 /**********************************************************************
93 * AMR register definitions
94 **********************************************************************/
96 #define RTC_AMR_AMRSEC ((1<<0))
97 
98 #define RTC_AMR_AMRMIN ((1<<1))
99 
100 #define RTC_AMR_AMRHOUR ((1<<2))
101 
102 #define RTC_AMR_AMRDOM ((1<<3))
103 
104 #define RTC_AMR_AMRDOW ((1<<4))
105 
106 #define RTC_AMR_AMRDOY ((1<<5))
107 
108 #define RTC_AMR_AMRMON ((1<<6))
109 
110 #define RTC_AMR_AMRYEAR ((1<<7))
111 
112 #define RTC_AMR_BITMASK ((0xFF))
113 
114 /**********************************************************************
115 * RTC_AUX register definitions
116 **********************************************************************/
118 #define RTC_AUX_RTC_OSCF ((1<<4))
119 
120 /**********************************************************************
121 * RTC_AUXEN register definitions
122 **********************************************************************/
124 #define RTC_AUXEN_RTC_OSCFEN ((1<<4))
125 
126 /* Consolidated time register group ----------------------------------- */
127 /**********************************************************************
128 * Consolidated Time Register 0 definitions
129 **********************************************************************/
130 #define RTC_CTIME0_SECONDS_MASK ((0x3F))
131 #define RTC_CTIME0_MINUTES_MASK ((0x3F00))
132 #define RTC_CTIME0_HOURS_MASK ((0x1F0000))
133 #define RTC_CTIME0_DOW_MASK ((0x7000000))
134 
135 /**********************************************************************
136 * Consolidated Time Register 1 definitions
137 **********************************************************************/
138 #define RTC_CTIME1_DOM_MASK ((0x1F))
139 #define RTC_CTIME1_MONTH_MASK ((0xF00))
140 #define RTC_CTIME1_YEAR_MASK ((0xFFF0000))
141 
142 /**********************************************************************
143 * Consolidated Time Register 2 definitions
144 **********************************************************************/
145 #define RTC_CTIME2_DOY_MASK ((0xFFF))
146 
147 /**********************************************************************
148 * Time Counter Group and Alarm register group
149 **********************************************************************/
151 #define RTC_SEC_MASK (0x0000003F)
152 
153 #define RTC_MIN_MASK (0x0000003F)
154 
155 #define RTC_HOUR_MASK (0x0000001F)
156 
157 #define RTC_DOM_MASK (0x0000001F)
158 
159 #define RTC_DOW_MASK (0x00000007)
160 
161 #define RTC_DOY_MASK (0x000001FF)
162 
163 #define RTC_MONTH_MASK (0x0000000F)
164 
165 #define RTC_YEAR_MASK (0x00000FFF)
166 
167 #define RTC_SECOND_MAX 59
168 #define RTC_MINUTE_MAX 59
169 #define RTC_HOUR_MAX 23
170 #define RTC_MONTH_MIN 1
171 #define RTC_MONTH_MAX 12
172 #define RTC_DAYOFMONTH_MIN 1
173 #define RTC_DAYOFMONTH_MAX 31
174 #define RTC_DAYOFWEEK_MAX 6
175 #define RTC_DAYOFYEAR_MIN 1
176 #define RTC_DAYOFYEAR_MAX 366
177 #define RTC_YEAR_MAX 4095
179 /**********************************************************************
180 * Calibration register
181 **********************************************************************/
182 /* Calibration register */
184 #define RTC_CALIBRATION_CALVAL_MASK ((0x1FFFF))
185 
186 #define RTC_CALIBRATION_LIBDIR ((1<<17))
187 
188 #define RTC_CALIBRATION_MAX ((0x20000))
189 
190 #define RTC_CALIB_DIR_FORWARD ((uint8_t)(0))
191 #define RTC_CALIB_DIR_BACKWARD ((uint8_t)(1))
192 
193 
194 /* ---------------- CHECK PARAMETER DEFINITIONS ---------------------------- */
196 #define PARAM_RTCx(x) (((uint32_t *)x)==((uint32_t *)LPC_RTC))
197 
198 /* Macro check RTC interrupt type */
199 #define PARAM_RTC_INT(n) ((n==RTC_INT_COUNTER_INCREASE) || (n==RTC_INT_ALARM))
200 
201 /* Macro check RTC time type */
202 #define PARAM_RTC_TIMETYPE(n) ((n==RTC_TIMETYPE_SECOND) || (n==RTC_TIMETYPE_MINUTE) \
203 || (n==RTC_TIMETYPE_HOUR) || (n==RTC_TIMETYPE_DAYOFWEEK) \
204 || (n==RTC_TIMETYPE_DAYOFMONTH) || (n==RTC_TIMETYPE_DAYOFYEAR) \
205 || (n==RTC_TIMETYPE_MONTH) || (n==RTC_TIMETYPE_YEAR))
206 
207 /* Macro check RTC calibration type */
208 #define PARAM_RTC_CALIB_DIR(n) ((n==RTC_CALIB_DIR_FORWARD) || (n==RTC_CALIB_DIR_BACKWARD))
209 
210 /* Macro check RTC GPREG type */
211 #define PARAM_RTC_GPREG_CH(n) ((n>=0) && (n<=4))
212 
218 /* Public Types --------------------------------------------------------------- */
224 typedef struct {
225  uint32_t SEC;
226  uint32_t MIN;
227  uint32_t HOUR;
228  uint32_t DOM;
229  uint32_t DOW;
230  uint32_t DOY;
231  uint32_t MONTH;
232  uint32_t YEAR;
233 } RTC_TIME_Type;
234 
236 typedef enum {
239 } RTC_INT_OPT;
240 
241 
243 typedef enum {
253 
260 /* Public Functions ----------------------------------------------------------- */
265 void RTC_Init (LPC_RTC_TypeDef *RTCx);
266 void RTC_DeInit(LPC_RTC_TypeDef *RTCx);
268 void RTC_Cmd (LPC_RTC_TypeDef *RTCx, FunctionalState NewState);
269 void RTC_CntIncrIntConfig (LPC_RTC_TypeDef *RTCx, uint32_t CntIncrIntType, \
270  FunctionalState NewState);
271 void RTC_AlarmIntConfig (LPC_RTC_TypeDef *RTCx, uint32_t AlarmTimeType, \
272  FunctionalState NewState);
273 void RTC_SetTime (LPC_RTC_TypeDef *RTCx, uint32_t Timetype, uint32_t TimeValue);
274 uint32_t RTC_GetTime(LPC_RTC_TypeDef *RTCx, uint32_t Timetype);
275 void RTC_SetFullTime (LPC_RTC_TypeDef *RTCx, RTC_TIME_Type *pFullTime);
276 void RTC_GetFullTime (LPC_RTC_TypeDef *RTCx, RTC_TIME_Type *pFullTime);
277 void RTC_SetAlarmTime (LPC_RTC_TypeDef *RTCx, uint32_t Timetype, uint32_t ALValue);
278 uint32_t RTC_GetAlarmTime (LPC_RTC_TypeDef *RTCx, uint32_t Timetype);
279 void RTC_SetFullAlarmTime (LPC_RTC_TypeDef *RTCx, RTC_TIME_Type *pFullTime);
280 void RTC_GetFullAlarmTime (LPC_RTC_TypeDef *RTCx, RTC_TIME_Type *pFullTime);
281 IntStatus RTC_GetIntPending (LPC_RTC_TypeDef *RTCx, uint32_t IntType);
282 void RTC_ClearIntPending (LPC_RTC_TypeDef *RTCx, uint32_t IntType);
284 void RTC_CalibConfig(LPC_RTC_TypeDef *RTCx, uint32_t CalibValue, uint8_t CalibDir);
285 void RTC_WriteGPREG (LPC_RTC_TypeDef *RTCx, uint8_t Channel, uint32_t Value);
286 uint32_t RTC_ReadGPREG (LPC_RTC_TypeDef *RTCx, uint8_t Channel);
287 
292 #ifdef __cplusplus
293 }
294 #endif
295 
296 #endif /* LPC17XX_RTC_H_ */
297 
302 /* --------------------------------- End Of File ------------------------------ */