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