| LPCOpen Platform v1.03 LPCOpen Platform for NXP LPC Microcontrollers

- Main Page
- Modules
- Data Structures
- Files
- Related Pages

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
rtc_001.h
Go to the documentation of this file.
1 /*
2 * @brief Real Time Clock registers and control functions
3 *
4 * @note
5 * Copyright(C) NXP Semiconductors, 2012
6 * All rights reserved.
7 *
8 * @par
9 * Software that is described herein is for illustrative purposes only
10 * which provides customers with programming information regarding the
11 * LPC products. This software is supplied "AS IS" without any warranties of
12 * any kind, and NXP Semiconductors and its licensor disclaim any and
13 * all warranties, express or implied, including all implied warranties of
14 * merchantability, fitness for a particular purpose and non-infringement of
15 * intellectual property rights. NXP Semiconductors assumes no responsibility
16 * or liability for the use of the software, conveys no license or rights under any
17 * patent, copyright, mask work right, or any other intellectual property rights in
18 * or to any products. NXP Semiconductors reserves the right to make changes
19 * in the software without notification. NXP Semiconductors also makes no
20 * representation or warranty that such application will be suitable for the
21 * specified use without further testing or modification.
22 *
23 * @par
24 * Permission to use, copy, modify, and distribute this software and its
25 * documentation is hereby granted, under NXP Semiconductors' and its
26 * licensor's relevant copyrights 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 #ifndef __RTC_001_H_
33 #define __RTC_001_H_
34
35 #include "sys_config.h"
36 #include "cmsis.h"
37
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41
48 #if defined(CHIP_LPC177X_8X) || defined(CHIP_LPC407X_8X) || defined(CHIP_LPC18XX) || defined(CHIP_LPC43XX)
49 #define RTC_EV_SUPPORT 1 /* Event Monitor/Recorder support */
50 #endif
51
54 typedef enum IP_RTC_TIMEINDEX {
55 RTC_TIMETYPE_SECOND,
56 RTC_TIMETYPE_MINUTE,
57 RTC_TIMETYPE_HOUR,
58 RTC_TIMETYPE_DAYOFMONTH,
59 RTC_TIMETYPE_DAYOFWEEK,
60 RTC_TIMETYPE_DAYOFYEAR,
61 RTC_TIMETYPE_MONTH,
62 RTC_TIMETYPE_YEAR,
63 RTC_TIMETYPE_LAST
64 } IP_RTC_TIMEINDEX_T;
65
66 #if RTC_EV_SUPPORT
67
70 typedef enum IP_RTC_EV_CHANNEL {
71 RTC_EV_CHANNEL_1 = 0,
72 RTC_EV_CHANNEL_2,
73 RTC_EV_CHANNEL_3,
74 RTC_EV_CHANNEL_NUM,
75 } IP_RTC_EV_CHANNEL_T;
76 #endif /*RTC_EV_SUPPORT*/
77
81 typedef struct {
82 __IO uint32_t ILR;
83 __I uint32_t RESERVED0;
84 __IO uint32_t CCR;
85 __IO uint32_t CIIR;
86 __IO uint32_t AMR;
87 __I uint32_t CTIME[3];
88 __IO uint32_t TIME[RTC_TIMETYPE_LAST];
89 __IO uint32_t CALIBRATION;
90 #if defined(CHIP_LPC177X_8X) || defined(CHIP_LPC407X_8X) || defined(CHIP_LPC175X_6X)
91 __IO uint32_t GPREG[5];
92 __IO uint32_t RTC_AUXEN;
93 __IO uint32_t RTC_AUX;
94 #else
95 __I uint32_t RESERVED1[7];
96 #endif
97 __IO uint32_t ALRM[RTC_TIMETYPE_LAST];
98 #if RTC_EV_SUPPORT
99 __IO uint32_t ERSTATUS;
100 __IO uint32_t ERCONTROL;
101 __I uint32_t ERCOUNTERS;
102 __I uint32_t RESERVED2;
103 __I uint32_t ERFIRSTSTAMP[RTC_EV_CHANNEL_NUM];
104 __I uint32_t RESERVED3;
105 __I uint32_t ERLASTSTAMP[RTC_EV_CHANNEL_NUM];
106 #endif /*RTC_EV_SUPPORT*/
107 } IP_RTC_001_T;
108
113 #define RTC_ILR_BITMASK ((0x00000003))
114
115 #define RTC_IRL_RTCCIF ((1 << 0))
116
117 #define RTC_IRL_RTCALF ((1 << 1))
118
123 #define RTC_CCR_BITMASK ((0x00000013))
124
125 #define RTC_CCR_CLKEN ((1 << 0))
126
127 #define RTC_CCR_CTCRST ((1 << 1))
128
129 #define RTC_CCR_CCALEN ((1 << 4))
130
135 #define RTC_AMR_CIIR_IMSEC ((1 << 0))
136
137 #define RTC_AMR_CIIR_IMMIN ((1 << 1))
138
139 #define RTC_AMR_CIIR_IMHOUR ((1 << 2))
140
141 #define RTC_AMR_CIIR_IMDOM ((1 << 3))
142
143 #define RTC_AMR_CIIR_IMDOW ((1 << 4))
144
145 #define RTC_AMR_CIIR_IMDOY ((1 << 5))
146
147 #define RTC_AMR_CIIR_IMMON ((1 << 6))
148
149 #define RTC_AMR_CIIR_IMYEAR ((1 << 7))
150
151 #define RTC_AMR_CIIR_BITMASK ((0xFF))
152
157 #define RTC_AUX_RTC_OSCF ((1 << 4))
158 #if defined(CHIP_LPC177X_8X) || defined(CHIP_LPC407X_8X)
159
160 #define RTC_AUX_RTC_PDOUT ((1 << 6))
161 #endif
162
167 #define RTC_AUXEN_RTC_OSCFEN ((1 << 4))
168
172 #define RTC_CTIME0_SECONDS_MASK ((0x3F))
173 #define RTC_CTIME0_MINUTES_MASK ((0x3F00))
174 #define RTC_CTIME0_HOURS_MASK ((0x1F0000))
175 #define RTC_CTIME0_DOW_MASK ((0x7000000))
176
180 #define RTC_CTIME1_DOM_MASK ((0x1F))
181 #define RTC_CTIME1_MONTH_MASK ((0xF00))
182 #define RTC_CTIME1_YEAR_MASK ((0xFFF0000))
183
187 #define RTC_CTIME2_DOY_MASK ((0xFFF))
188
193 #define RTC_SEC_MASK (0x0000003F)
194
195 #define RTC_MIN_MASK (0x0000003F)
196
197 #define RTC_HOUR_MASK (0x0000001F)
198
199 #define RTC_DOM_MASK (0x0000001F)
200
201 #define RTC_DOW_MASK (0x00000007)
202
203 #define RTC_DOY_MASK (0x000001FF)
204
205 #define RTC_MONTH_MASK (0x0000000F)
206
207 #define RTC_YEAR_MASK (0x00000FFF)
208
209 #define RTC_SECOND_MAX 59
210 #define RTC_MINUTE_MAX 59
211 #define RTC_HOUR_MAX 23
212 #define RTC_MONTH_MIN 1
213 #define RTC_MONTH_MAX 12
214 #define RTC_DAYOFMONTH_MIN 1
215 #define RTC_DAYOFMONTH_MAX 31
216 #define RTC_DAYOFWEEK_MAX 6
217 #define RTC_DAYOFYEAR_MIN 1
218 #define RTC_DAYOFYEAR_MAX 366
219 #define RTC_YEAR_MAX 4095
225 #define RTC_CALIBRATION_CALVAL_MASK ((0x1FFFF))
226
227 #define RTC_CALIBRATION_LIBDIR ((1 << 17))
228
229 #define RTC_CALIBRATION_MAX ((0x20000))
230
231 #define RTC_CALIB_DIR_FORWARD ((uint8_t) (0))
232 #define RTC_CALIB_DIR_BACKWARD ((uint8_t) (1))
233
234 #if RTC_EV_SUPPORT
235
239 #define RTC_ERCTRL_BITMASK ((uint32_t) 0xC0F03C0F)
240
241 #define RTC_ERCTRL_INTWAKE_EN ((uint32_t) (1 << 0))
242
243 #define RTC_ERCTRL_GPCLEAR_EN ((uint32_t) (1 << 1))
244
245 #define RTC_ERCTRL_POL_NEGATIVE (0) /* Event as positive edge */
246 #define RTC_ERCTRL_POL_POSITIVE ((uint32_t) (1 << 2)) /* Event as negative edge */
247
248 #define RTC_ERCTRL_INPUT_EN ((uint32_t) (1 << 3))
249
250 #define RTC_ERCTRL_CHANNEL_CONFIG_BITMASK(ch) ((uint32_t) (0x0F << (10 * ch)))
251 #define RTC_ERCTRL_CHANNEL_CONFIG(ch, flag) ((uint32_t) (flag << (10 * ch)))
252
254 #define RTC_ERCTRL_MODE_MASK (((uint32_t) 3) << 30)
255 #define RTC_ERCTRL_MODE_CLK_DISABLE (((uint32_t) 0) << 30)
256 #define RTC_ERCTRL_MODE_16HZ (((uint32_t) 1) << 30)
257 #define RTC_ERCTRL_MODE_64HZ (((uint32_t) 2) << 30)
258 #define RTC_ERCTRL_MODE_1KHZ (((uint32_t) 3) << 30)
259 #define RTC_ERCTRL_MODE(n) (((uint32_t) n) << 30)
260
265 #define RTC_ERSTATUS_CHANNEL_EV(ch) ((uint32_t) (1 << ch)) /* At least 1 event has occurred on a specific channel */
266
267 #define RTC_ERSTATUS_GPCLEARED ((uint32_t) (1 << 3))
268
269 #define RTC_ERSTATUS_WAKEUP ((uint32_t) (((uint32_t) 1) << 31))
270
275 #define RTC_ER_COUNTER(ch, n) ((uint32_t) ((n >> (8 * ch)) & 0x07))
276
280 #define RTC_ER_TIMESTAMP_SEC(n) ((uint32_t) (n & 0x3F))
281 #define RTC_ER_TIMESTAMP_MIN(n) ((uint32_t) ((n >> 6) & 0x3F))
282 #define RTC_ER_TIMESTAMP_HOUR(n) ((uint32_t) ((n >> 12) & 0x1F))
283 #define RTC_ER_TIMESTAMP_DOY(n) ((uint32_t) ((n >> 17) & 0x1FF))
284
288 typedef enum IP_RTC_EV_MODE {
289 RTC_EV_MODE_DISABLE = 0,
290 RTC_EV_MODE_ENABLE_16HZ = 1,
291 RTC_EV_MODE_ENABLE_64HZ = 2,
292 RTC_EV_MODE_ENABLE_1KHZ = 3,
293 RTC_EV_MODE_LAST,
294 } IP_RTC_EV_MODE_T;
295
299 typedef struct {
300 uint8_t sec;
301 uint8_t min;
302 uint8_t hour;
303 uint16_t dayofyear;
304 } IP_RTC_EV_TIMESTAMP_T;
305
306 #endif /*RTC_EV_SUPPORT*/
307
313 typedef enum IP_RTC_INT_OPT {
314 RTC_INT_COUNTER_INCREASE = RTC_IRL_RTCCIF,
315 RTC_INT_ALARM = RTC_IRL_RTCALF
316 } IP_RTC_INT_OPT_T;
317
318 typedef struct {
319 uint32_t time[RTC_TIMETYPE_LAST];
320 } IP_RTC_TIME_T;
321
327 void IP_RTC_Init(IP_RTC_001_T *pRTC);
328
334 STATIC INLINE void IP_RTC_DeInit(IP_RTC_001_T *pRTC)
335 {
336 pRTC->CCR = 0x00;
337 }
338
344 void IP_RTC_ResetClockTickCounter(IP_RTC_001_T *pRTC);
345
352 void IP_RTC_Enable(IP_RTC_001_T *pRTC, FunctionalState NewState);
353
361 void IP_RTC_CntIncrIntConfig(IP_RTC_001_T *pRTC, uint32_t cntrMask, FunctionalState NewState);
362
370 void IP_RTC_AlarmIntConfig(IP_RTC_001_T *pRTC, uint32_t alarmMask, FunctionalState NewState);
371
379 void IP_RTC_SetTime(IP_RTC_001_T *pRTC, IP_RTC_TIMEINDEX_T Timetype, uint32_t TimeValue);
380
387 uint32_t IP_RTC_GetTime(IP_RTC_001_T *pRTC, IP_RTC_TIMEINDEX_T Timetype);
388
395 void IP_RTC_SetFullTime(IP_RTC_001_T *pRTC, IP_RTC_TIME_T *pFullTime);
396
403 void IP_RTC_GetFullTime(IP_RTC_001_T *pRTC, IP_RTC_TIME_T *pFullTime);
404
412 void IP_RTC_SetAlarmTime(IP_RTC_001_T *pRTC, IP_RTC_TIMEINDEX_T Timetype, uint32_t ALValue);
413
420 uint32_t IP_RTC_GetAlarmTime(IP_RTC_001_T *pRTC, IP_RTC_TIMEINDEX_T Timetype);
421
428 void IP_RTC_SetFullAlarmTime(IP_RTC_001_T *pRTC, IP_RTC_TIME_T *pFullTime);
429
436 void IP_RTC_GetFullAlarmTime(IP_RTC_001_T *pRTC, IP_RTC_TIME_T *pFullTime);
437
446 void IP_RTC_CalibCounterCmd(IP_RTC_001_T *pRTC, FunctionalState NewState);
447
457 void IP_RTC_CalibConfig(IP_RTC_001_T *pRTC, uint32_t CalibValue, uint8_t CalibDir);
458
467 STATIC INLINE void IP_RTC_ClearIntPending(IP_RTC_001_T *pRTC, uint32_t IntType)
468 {
469 pRTC->ILR = IntType;
470 }
471
481 STATIC INLINE IntStatus IP_RTC_GetIntPending(IP_RTC_001_T *pRTC, uint32_t IntType)
482 {
483 return (pRTC->ILR & IntType) ? SET : RESET;
484 }
485
486 #if RTC_EV_SUPPORT
487
497 STATIC INLINE void IP_RTC_EV_Config(IP_RTC_001_T *pRTC, IP_RTC_EV_CHANNEL_T ch, uint32_t flag)
498 {
499 uint32_t temp;
500
501 temp = pRTC->ERCONTROL & (~(RTC_ERCTRL_CHANNEL_CONFIG_BITMASK(ch))) & RTC_ERCTRL_BITMASK;
502 pRTC->ERCONTROL = temp | (RTC_ERCTRL_CHANNEL_CONFIG(ch, flag) & RTC_ERCTRL_BITMASK);
503 }
504
511 STATIC INLINE void IP_RTC_EV_SetMode(IP_RTC_001_T *pRTC, IP_RTC_EV_MODE_T mode)
512 {
513 uint32_t temp;
514
515 temp = pRTC->ERCONTROL & (~RTC_ERCTRL_MODE_MASK) & RTC_ERCTRL_BITMASK;
516 pRTC->ERCONTROL = temp | RTC_ERCTRL_MODE(mode);
517 }
518
524 STATIC INLINE uint32_t IP_RTC_EV_GetStatus(IP_RTC_001_T *pRTC)
525 {
526 return pRTC->ERSTATUS & (RTC_ERSTATUS_GPCLEARED | RTC_ERSTATUS_WAKEUP);
527 }
528
535 STATIC INLINE void IP_RTC_EV_ClearStatus(IP_RTC_001_T *pRTC, uint32_t flag)
536 {
537 pRTC->ERSTATUS = flag & (RTC_ERSTATUS_GPCLEARED | RTC_ERSTATUS_WAKEUP);
538 }
539
546 STATIC INLINE FlagStatus IP_RTC_EV_GetChannelStatus(IP_RTC_001_T *pRTC, IP_RTC_EV_CHANNEL_T ch)
547 {
548 return (pRTC->ERSTATUS & RTC_ERSTATUS_CHANNEL_EV(ch)) ? SET : RESET;
549 }
550
557 STATIC INLINE void IP_RTC_EV_ClearChannelStatus(IP_RTC_001_T *pRTC, IP_RTC_EV_CHANNEL_T ch)
558 {
559 pRTC->ERSTATUS = RTC_ERSTATUS_CHANNEL_EV(ch);
560 }
561
568 STATIC INLINE uint8_t IP_RTC_EV_GetCounter(IP_RTC_001_T *pRTC, IP_RTC_EV_CHANNEL_T ch)
569 {
570 return RTC_ER_COUNTER(ch, pRTC->ERCOUNTERS);
571 }
572
580 void IP_RTC_EV_GetFirstTimeStamp(IP_RTC_001_T *pRTC, IP_RTC_EV_CHANNEL_T ch, IP_RTC_EV_TIMESTAMP_T *pTimeStamp);
581
589 void IP_RTC_EV_GetLastTimeStamp(IP_RTC_001_T *pRTC, IP_RTC_EV_CHANNEL_T ch, IP_RTC_EV_TIMESTAMP_T *pTimeStamp);
590
591 #endif /*RTC_EV_SUPPORT*/
592
596 #ifdef __cplusplus
597 }
598 #endif
599
600 #endif /* __RTC_001_H_ */