NXP's driver library for LPC17xx, ported to mbed's online compiler. Not tested! I had to fix a lot of warings and found a couple of pretty obvious bugs, so the chances are there are more. Original: http://ics.nxp.com/support/documents/microcontrollers/zip/lpc17xx.cmsis.driver.library.zip

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers lpc17xx_rtc.h Source File

lpc17xx_rtc.h

Go to the documentation of this file.
00001 /***********************************************************************//**
00002  * @file    : lpc17xx_rtc.h
00003  * @brief    : Contains all macro definitions and function prototypes
00004  *                 support for RTC firmware library on LPC17xx
00005  * @version    : 1.0
00006  * @date    : 23. Apr. 2009
00007  * @author    : HieuNguyen
00008  **************************************************************************
00009  * Software that is described herein is for illustrative purposes only
00010  * which provides customers with programming information regarding the
00011  * products. This software is supplied "AS IS" without any warranties.
00012  * NXP Semiconductors assumes no responsibility or liability for the
00013  * use of the software, conveys no license or title under any patent,
00014  * copyright, or mask work right to the product. NXP Semiconductors
00015  * reserves the right to make changes in the software without
00016  * notification. NXP Semiconductors also make no representation or
00017  * warranty that such application will be suitable for the specified
00018  * use without further testing or modification.
00019  **************************************************************************/
00020 
00021 /* Peripheral group ----------------------------------------------------------- */
00022 /** @defgroup RTC
00023  * @ingroup LPC1700CMSIS_FwLib_Drivers
00024  * @{
00025  */
00026 
00027 #ifndef LPC17XX_RTC_H_
00028 #define LPC17XX_RTC_H_
00029 
00030 /* Includes ------------------------------------------------------------------- */
00031 #include "cmsis.h"
00032 #include "lpc_types.h"
00033 
00034 
00035 #ifdef __cplusplus
00036 extern "C"
00037 {
00038 #endif
00039 
00040 
00041 /* Private Macros ------------------------------------------------------------- */
00042 /** @defgroup RTC_Private_Macros
00043  * @{
00044  */
00045 
00046 /** @defgroup RTC_REGISTER_BIT_DEFINITIONS
00047  * @{
00048  */
00049 
00050 /* Miscellaneous register group --------------------------------------------- */
00051 
00052 /**********************************************************************
00053 * ILR register definitions
00054 **********************************************************************/
00055 /** ILR register mask */
00056 #define RTC_ILR_BITMASK            ((0x00000003))
00057 /** Bit inform the source interrupt is counter increment*/
00058 #define RTC_IRL_RTCCIF            ((1<<0))
00059 /** Bit inform the source interrupt is alarm match*/
00060 #define RTC_IRL_RTCALF            ((1<<1))
00061 
00062 
00063 /**********************************************************************
00064 * CCR register definitions
00065 **********************************************************************/
00066 /** CCR register mask */
00067 #define RTC_CCR_BITMASK            ((0x00000013))
00068 /** Clock enable */
00069 #define RTC_CCR_CLKEN            ((1<<0))
00070 /** Clock reset */
00071 #define RTC_CCR_CTCRST            ((1<<1))
00072 /** Calibration counter enable */
00073 #define RTC_CCR_CCALEN            ((1<<4))
00074 
00075 
00076 /**********************************************************************
00077 * CIIR register definitions
00078 **********************************************************************/
00079 /** Counter Increment Interrupt bit for second */
00080 #define RTC_CIIR_IMSEC            ((1<<0))
00081 /** Counter Increment Interrupt bit for minute */
00082 #define RTC_CIIR_IMMIN            ((1<<1))
00083 /** Counter Increment Interrupt bit for hour */
00084 #define RTC_CIIR_IMHOUR            ((1<<2))
00085 /** Counter Increment Interrupt bit for day of month */
00086 #define RTC_CIIR_IMDOM            ((1<<3))
00087 /** Counter Increment Interrupt bit for day of week */
00088 #define RTC_CIIR_IMDOW            ((1<<4))
00089 /** Counter Increment Interrupt bit for day of year */
00090 #define RTC_CIIR_IMDOY            ((1<<5))
00091 /** Counter Increment Interrupt bit for month */
00092 #define RTC_CIIR_IMMON            ((1<<6))
00093 /** Counter Increment Interrupt bit for year */
00094 #define RTC_CIIR_IMYEAR            ((1<<7))
00095 /** CIIR bit mask */
00096 #define RTC_CIIR_BITMASK        ((0xFF))
00097 
00098 /**********************************************************************
00099 * AMR register definitions
00100 **********************************************************************/
00101 /** Counter Increment Select Mask bit for second */
00102 #define RTC_AMR_AMRSEC            ((1<<0))
00103 /** Counter Increment Select Mask bit for minute */
00104 #define RTC_AMR_AMRMIN            ((1<<1))
00105 /** Counter Increment Select Mask bit for hour */
00106 #define RTC_AMR_AMRHOUR            ((1<<2))
00107 /** Counter Increment Select Mask bit for day of month */
00108 #define RTC_AMR_AMRDOM            ((1<<3))
00109 /** Counter Increment Select Mask bit for day of week */
00110 #define RTC_AMR_AMRDOW            ((1<<4))
00111 /** Counter Increment Select Mask bit for day of year */
00112 #define RTC_AMR_AMRDOY            ((1<<5))
00113 /** Counter Increment Select Mask bit for month */
00114 #define RTC_AMR_AMRMON            ((1<<6))
00115 /** Counter Increment Select Mask bit for year */
00116 #define RTC_AMR_AMRYEAR            ((1<<7))
00117 /** AMR bit mask */
00118 #define RTC_AMR_BITMASK            ((0xFF))
00119 
00120 /**********************************************************************
00121 * RTC_AUX register definitions
00122 **********************************************************************/
00123 /** RTC Oscillator Fail detect flag */
00124 #define RTC_AUX_RTC_OSCF        ((1<<4))
00125 
00126 /**********************************************************************
00127 * RTC_AUXEN register definitions
00128 **********************************************************************/
00129 /** Oscillator Fail Detect interrupt enable*/
00130 #define RTC_AUXEN_RTC_OSCFEN    ((1<<4))
00131 
00132 
00133 /* Consolidated time register group ----------------------------------- */
00134 /** Consolidated Time Register 0 */
00135 #define RTC_CTIME0_SECONDS_MASK        ((0x3F))
00136 #define RTC_CTIME0_MINUTES_MASK        ((0x3F00))
00137 #define RTC_CTIME0_HOURS_MASK        ((0x1F0000))
00138 #define RTC_CTIME0_DOW_MASK            ((0x7000000))
00139 /** Consolidated Time Register 1 */
00140 #define RTC_CTIME1_DOM_MASK            ((0x1F))
00141 #define RTC_CTIME1_MONTH_MASK        ((0xF00))
00142 #define RTC_CTIME1_YEAR_MASK        ((0xFFF0000))
00143 /** Consolidated Time Register 2 */
00144 #define RTC_CTIME2_DOY_MASK            ((0xFFF))
00145 
00146 
00147 /* Time Counter Group and Alarm register group ----------------------------- */
00148 /** SEC register mask */
00149 #define RTC_SEC_MASK            (0x0000003F)
00150 /** MIN register mask */
00151 #define RTC_MIN_MASK            (0x0000003F)
00152 /** HOUR register mask */
00153 #define RTC_HOUR_MASK            (0x0000001F)
00154 /** DOM register mask */
00155 #define RTC_DOM_MASK            (0x0000001F)
00156 /** DOW register mask */
00157 #define RTC_DOW_MASK            (0x00000007)
00158 /** DOY register mask */
00159 #define RTC_DOY_MASK            (0x000001FF)
00160 /** MONTH register mask */
00161 #define RTC_MONTH_MASK            (0x0000000F)
00162 /** YEAR register mask */
00163 #define RTC_YEAR_MASK            (0x00000FFF)
00164 
00165 #define RTC_SECOND_MAX        59 /*!< Maximum value of second */
00166 #define RTC_MINUTE_MAX        59 /*!< Maximum value of minute*/
00167 #define RTC_HOUR_MAX        23 /*!< Maximum value of hour*/
00168 #define RTC_MONTH_MIN        1 /*!< Minimum value of month*/
00169 #define RTC_MONTH_MAX        12 /*!< Maximum value of month*/
00170 #define RTC_DAYOFMONTH_MIN     1 /*!< Minimum value of day of month*/
00171 #define RTC_DAYOFMONTH_MAX     31 /*!< Maximum value of day of month*/
00172 #define RTC_DAYOFWEEK_MAX    6 /*!< Maximum value of day of week*/
00173 #define RTC_DAYOFYEAR_MIN    1 /*!< Minimum value of day of year*/
00174 #define RTC_DAYOFYEAR_MAX    366 /*!< Maximum value of day of year*/
00175 #define RTC_YEAR_MAX        4095 /*!< Maximum value of year*/
00176 
00177 /* Calibration register */
00178 /** Calibration value */
00179 #define RTC_CALIBRATION_CALVAL_MASK        ((0x1FFFF))
00180 /** Calibration direction */
00181 #define RTC_CALIBRATION_LIBDIR            ((1<<17))
00182 /** Calibration max value */
00183 #define RTC_CALIBRATION_MAX                ((0x20000))
00184 
00185 /**
00186  * @}
00187  */
00188 
00189 /**
00190  * @}
00191  */
00192 
00193 
00194 /* Public Types --------------------------------------------------------------- */
00195 /** @defgroup RTC_Public_Types
00196  * @{
00197  */
00198 
00199 /** @brief Time structure definitions for easy manipulate the data */
00200 typedef struct {
00201     uint32_t SEC ;         /*!< Seconds Register */
00202     uint32_t MIN ;         /*!< Minutes Register */
00203     uint32_t HOUR ;         /*!< Hours Register */
00204     uint32_t DOM ;        /*!< Day of Month Register */
00205     uint32_t DOW ;         /*!< Day of Week Register */
00206     uint32_t DOY ;         /*!< Day of Year Register */
00207     uint32_t MONTH ;     /*!< Months Register */
00208     uint32_t YEAR ;         /*!< Years Register */
00209 } RTC_TIME_Type;
00210 
00211 /** @brief RTC interrupt source */
00212 typedef enum {
00213     RTC_INT_COUNTER_INCREASE  = RTC_IRL_RTCCIF,     /*!<  Counter Increment Interrupt */
00214     RTC_INT_ALARM  = RTC_IRL_RTCALF,                 /*!< The alarm interrupt */
00215 } RTC_INT_OPT;
00216 
00217 #define PARAM_RTC_INT(n)    ((n==RTC_INT_COUNTER_INCREASE) || (n==RTC_INT_ALARM))
00218 
00219 
00220 /** @brief RTC time type option */
00221 typedef enum {
00222     RTC_TIMETYPE_SECOND  = 0,         /*!< Second */
00223     RTC_TIMETYPE_MINUTE  = 1,         /*!< Month */
00224     RTC_TIMETYPE_HOUR  = 2,             /*!< Hour */
00225     RTC_TIMETYPE_DAYOFWEEK  = 3,     /*!< Day of week */
00226     RTC_TIMETYPE_DAYOFMONTH  = 4,     /*!< Day of month */
00227     RTC_TIMETYPE_DAYOFYEAR  = 5,     /*!< Day of year */
00228     RTC_TIMETYPE_MONTH  = 6,         /*!< Month */
00229     RTC_TIMETYPE_YEAR  = 7,             /*!< Year */
00230 } RTC_TIMETYPE_Num;
00231 
00232 #define PARAM_RTC_TIMETYPE(n)    ((n==RTC_TIMETYPE_SECOND) || (n==RTC_TIMETYPE_MINUTE) \
00233 || (n==RTC_TIMETYPE_HOUR) || (n==RTC_TIMETYPE_DAYOFWEEK) \
00234 || (n==RTC_TIMETYPE_DAYOFMONTH) || (n==RTC_TIMETYPE_DAYOFYEAR) \
00235 || (n==RTC_TIMETYPE_MONTH) || (n==RTC_TIMETYPE_YEAR))
00236 
00237 
00238 /**
00239  * @}
00240  */
00241 
00242 
00243 /* Public Macros -------------------------------------------------------------- */
00244 /** @defgroup RTC_Public_Macros
00245  * @{
00246  */
00247 
00248 /** Macro to determine if it is valid RTC peripheral */
00249 #define PARAM_RTCx(x)    (((uint32_t *)x)==((uint32_t *)LPC_RTC))
00250 
00251 /** Calibration definitions */
00252 #define RTC_CALIB_DIR_FORWARD    ((uint8_t)(0))
00253 #define RTC_CALIB_DIR_BACKWARD    ((uint8_t)(1))
00254 
00255 #define PARAM_RTC_CALIB_DIR(n)    ((n==RTC_CALIB_DIR_FORWARD) || (n==RTC_CALIB_DIR_BACKWARD))
00256 #define PARAM_RTC_GPREG_CH(n)    (n<=4)
00257 
00258 #define PARAM_RTC_CALIBRATION_DIR(n)
00259 
00260 /**
00261  * @}
00262  */
00263 
00264 
00265 /* Public Functions ----------------------------------------------------------- */
00266 /** @defgroup RTC_Public_Functions
00267  * @{
00268  */
00269 
00270 void RTC_Init (LPC_RTC_TypeDef *RTCx);
00271 void RTC_DeInit(LPC_RTC_TypeDef *RTCx);
00272 void RTC_ResetClockTickCounter(LPC_RTC_TypeDef *RTCx);
00273 void RTC_Cmd (LPC_RTC_TypeDef *RTCx, FunctionalState NewState);
00274 void RTC_CntIncrIntConfig (LPC_RTC_TypeDef *RTCx, uint32_t CntIncrIntType, \
00275                                 FunctionalState NewState);
00276 void RTC_AlarmIntConfig (LPC_RTC_TypeDef *RTCx, uint32_t AlarmTimeType, \
00277                                 FunctionalState NewState);
00278 void RTC_SetTime (LPC_RTC_TypeDef *RTCx, uint32_t Timetype, uint32_t TimeValue);
00279 uint32_t RTC_GetTime(LPC_RTC_TypeDef *RTCx, uint32_t Timetype);
00280 void RTC_SetFullTime (LPC_RTC_TypeDef *RTCx, RTC_TIME_Type *pFullTime);
00281 void RTC_GetFullTime (LPC_RTC_TypeDef *RTCx, RTC_TIME_Type *pFullTime);
00282 void RTC_SetAlarmTime (LPC_RTC_TypeDef *RTCx, uint32_t Timetype, uint32_t ALValue);
00283 uint32_t RTC_GetAlarmTime (LPC_RTC_TypeDef *RTCx, uint32_t Timetype);
00284 void RTC_SetFullAlarmTime (LPC_RTC_TypeDef *RTCx, RTC_TIME_Type *pFullTime);
00285 void RTC_GetFullAlarmTime (LPC_RTC_TypeDef *RTCx, RTC_TIME_Type *pFullTime);
00286 IntStatus RTC_GetIntPending (LPC_RTC_TypeDef *RTCx, uint32_t IntType);
00287 void RTC_ClearIntPending (LPC_RTC_TypeDef *RTCx, uint32_t IntType);
00288 void RTC_CalibCounterCmd(LPC_RTC_TypeDef *RTCx, FunctionalState NewState);
00289 void RTC_CalibConfig(LPC_RTC_TypeDef *RTCx, uint32_t CalibValue, uint8_t CalibDir);
00290 void RTC_WriteGPREG (LPC_RTC_TypeDef *RTCx, uint8_t Channel, uint32_t Value);
00291 uint32_t RTC_ReadGPREG (LPC_RTC_TypeDef *RTCx, uint8_t Channel);
00292 
00293 /**
00294  * @}
00295  */
00296 
00297 #ifdef __cplusplus
00298 }
00299 #endif
00300 
00301 #endif /* LPC17XX_RTC_H_ */
00302 
00303 /**
00304  * @}
00305  */
00306 
00307 /* --------------------------------- End Of File ------------------------------ */