My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lpc17xx_rtc.h 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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. /* Peripheral group ----------------------------------------------------------- */
  33. /** @defgroup RTC RTC (Real Time Clock)
  34. * @ingroup LPC1700CMSIS_FwLib_Drivers
  35. * @{
  36. */
  37. #ifndef LPC17XX_RTC_H_
  38. #define LPC17XX_RTC_H_
  39. /* Includes ------------------------------------------------------------------- */
  40. #include "LPC17xx.h"
  41. #include "lpc_types.h"
  42. #ifdef __cplusplus
  43. extern "C"
  44. {
  45. #endif
  46. /* Private Macros ------------------------------------------------------------- */
  47. /** @defgroup RTC_Private_Macros RTC Private Macros
  48. * @{
  49. */
  50. /* ----------------------- BIT DEFINITIONS ----------------------------------- */
  51. /* Miscellaneous register group --------------------------------------------- */
  52. /**********************************************************************
  53. * ILR register definitions
  54. **********************************************************************/
  55. /** ILR register mask */
  56. #define RTC_ILR_BITMASK ((0x00000003))
  57. /** Bit inform the source interrupt is counter increment*/
  58. #define RTC_IRL_RTCCIF ((1<<0))
  59. /** Bit inform the source interrupt is alarm match*/
  60. #define RTC_IRL_RTCALF ((1<<1))
  61. /**********************************************************************
  62. * CCR register definitions
  63. **********************************************************************/
  64. /** CCR register mask */
  65. #define RTC_CCR_BITMASK ((0x00000013))
  66. /** Clock enable */
  67. #define RTC_CCR_CLKEN ((1<<0))
  68. /** Clock reset */
  69. #define RTC_CCR_CTCRST ((1<<1))
  70. /** Calibration counter enable */
  71. #define RTC_CCR_CCALEN ((1<<4))
  72. /**********************************************************************
  73. * CIIR register definitions
  74. **********************************************************************/
  75. /** Counter Increment Interrupt bit for second */
  76. #define RTC_CIIR_IMSEC ((1<<0))
  77. /** Counter Increment Interrupt bit for minute */
  78. #define RTC_CIIR_IMMIN ((1<<1))
  79. /** Counter Increment Interrupt bit for hour */
  80. #define RTC_CIIR_IMHOUR ((1<<2))
  81. /** Counter Increment Interrupt bit for day of month */
  82. #define RTC_CIIR_IMDOM ((1<<3))
  83. /** Counter Increment Interrupt bit for day of week */
  84. #define RTC_CIIR_IMDOW ((1<<4))
  85. /** Counter Increment Interrupt bit for day of year */
  86. #define RTC_CIIR_IMDOY ((1<<5))
  87. /** Counter Increment Interrupt bit for month */
  88. #define RTC_CIIR_IMMON ((1<<6))
  89. /** Counter Increment Interrupt bit for year */
  90. #define RTC_CIIR_IMYEAR ((1<<7))
  91. /** CIIR bit mask */
  92. #define RTC_CIIR_BITMASK ((0xFF))
  93. /**********************************************************************
  94. * AMR register definitions
  95. **********************************************************************/
  96. /** Counter Increment Select Mask bit for second */
  97. #define RTC_AMR_AMRSEC ((1<<0))
  98. /** Counter Increment Select Mask bit for minute */
  99. #define RTC_AMR_AMRMIN ((1<<1))
  100. /** Counter Increment Select Mask bit for hour */
  101. #define RTC_AMR_AMRHOUR ((1<<2))
  102. /** Counter Increment Select Mask bit for day of month */
  103. #define RTC_AMR_AMRDOM ((1<<3))
  104. /** Counter Increment Select Mask bit for day of week */
  105. #define RTC_AMR_AMRDOW ((1<<4))
  106. /** Counter Increment Select Mask bit for day of year */
  107. #define RTC_AMR_AMRDOY ((1<<5))
  108. /** Counter Increment Select Mask bit for month */
  109. #define RTC_AMR_AMRMON ((1<<6))
  110. /** Counter Increment Select Mask bit for year */
  111. #define RTC_AMR_AMRYEAR ((1<<7))
  112. /** AMR bit mask */
  113. #define RTC_AMR_BITMASK ((0xFF))
  114. /**********************************************************************
  115. * RTC_AUX register definitions
  116. **********************************************************************/
  117. /** RTC Oscillator Fail detect flag */
  118. #define RTC_AUX_RTC_OSCF ((1<<4))
  119. /**********************************************************************
  120. * RTC_AUXEN register definitions
  121. **********************************************************************/
  122. /** Oscillator Fail Detect interrupt enable*/
  123. #define RTC_AUXEN_RTC_OSCFEN ((1<<4))
  124. /* Consolidated time register group ----------------------------------- */
  125. /**********************************************************************
  126. * Consolidated Time Register 0 definitions
  127. **********************************************************************/
  128. #define RTC_CTIME0_SECONDS_MASK ((0x3F))
  129. #define RTC_CTIME0_MINUTES_MASK ((0x3F00))
  130. #define RTC_CTIME0_HOURS_MASK ((0x1F0000))
  131. #define RTC_CTIME0_DOW_MASK ((0x7000000))
  132. /**********************************************************************
  133. * Consolidated Time Register 1 definitions
  134. **********************************************************************/
  135. #define RTC_CTIME1_DOM_MASK ((0x1F))
  136. #define RTC_CTIME1_MONTH_MASK ((0xF00))
  137. #define RTC_CTIME1_YEAR_MASK ((0xFFF0000))
  138. /**********************************************************************
  139. * Consolidated Time Register 2 definitions
  140. **********************************************************************/
  141. #define RTC_CTIME2_DOY_MASK ((0xFFF))
  142. /**********************************************************************
  143. * Time Counter Group and Alarm register group
  144. **********************************************************************/
  145. /** SEC register mask */
  146. #define RTC_SEC_MASK (0x0000003F)
  147. /** MIN register mask */
  148. #define RTC_MIN_MASK (0x0000003F)
  149. /** HOUR register mask */
  150. #define RTC_HOUR_MASK (0x0000001F)
  151. /** DOM register mask */
  152. #define RTC_DOM_MASK (0x0000001F)
  153. /** DOW register mask */
  154. #define RTC_DOW_MASK (0x00000007)
  155. /** DOY register mask */
  156. #define RTC_DOY_MASK (0x000001FF)
  157. /** MONTH register mask */
  158. #define RTC_MONTH_MASK (0x0000000F)
  159. /** YEAR register mask */
  160. #define RTC_YEAR_MASK (0x00000FFF)
  161. #define RTC_SECOND_MAX 59 /*!< Maximum value of second */
  162. #define RTC_MINUTE_MAX 59 /*!< Maximum value of minute*/
  163. #define RTC_HOUR_MAX 23 /*!< Maximum value of hour*/
  164. #define RTC_MONTH_MIN 1 /*!< Minimum value of month*/
  165. #define RTC_MONTH_MAX 12 /*!< Maximum value of month*/
  166. #define RTC_DAYOFMONTH_MIN 1 /*!< Minimum value of day of month*/
  167. #define RTC_DAYOFMONTH_MAX 31 /*!< Maximum value of day of month*/
  168. #define RTC_DAYOFWEEK_MAX 6 /*!< Maximum value of day of week*/
  169. #define RTC_DAYOFYEAR_MIN 1 /*!< Minimum value of day of year*/
  170. #define RTC_DAYOFYEAR_MAX 366 /*!< Maximum value of day of year*/
  171. #define RTC_YEAR_MAX 4095 /*!< Maximum value of year*/
  172. /**********************************************************************
  173. * Calibration register
  174. **********************************************************************/
  175. /* Calibration register */
  176. /** Calibration value */
  177. #define RTC_CALIBRATION_CALVAL_MASK ((0x1FFFF))
  178. /** Calibration direction */
  179. #define RTC_CALIBRATION_LIBDIR ((1<<17))
  180. /** Calibration max value */
  181. #define RTC_CALIBRATION_MAX ((0x20000))
  182. /** Calibration definitions */
  183. #define RTC_CALIB_DIR_FORWARD ((uint8_t)(0))
  184. #define RTC_CALIB_DIR_BACKWARD ((uint8_t)(1))
  185. /* ---------------- CHECK PARAMETER DEFINITIONS ---------------------------- */
  186. /** Macro to determine if it is valid RTC peripheral */
  187. #define PARAM_RTCx(x) (((uint32_t *)x)==((uint32_t *)LPC_RTC))
  188. /* Macro check RTC interrupt type */
  189. #define PARAM_RTC_INT(n) ((n==RTC_INT_COUNTER_INCREASE) || (n==RTC_INT_ALARM))
  190. /* Macro check RTC time type */
  191. #define PARAM_RTC_TIMETYPE(n) ((n==RTC_TIMETYPE_SECOND) || (n==RTC_TIMETYPE_MINUTE) \
  192. || (n==RTC_TIMETYPE_HOUR) || (n==RTC_TIMETYPE_DAYOFWEEK) \
  193. || (n==RTC_TIMETYPE_DAYOFMONTH) || (n==RTC_TIMETYPE_DAYOFYEAR) \
  194. || (n==RTC_TIMETYPE_MONTH) || (n==RTC_TIMETYPE_YEAR))
  195. /* Macro check RTC calibration type */
  196. #define PARAM_RTC_CALIB_DIR(n) ((n==RTC_CALIB_DIR_FORWARD) || (n==RTC_CALIB_DIR_BACKWARD))
  197. /* Macro check RTC GPREG type */
  198. #define PARAM_RTC_GPREG_CH(n) (n<=4)
  199. /**
  200. * @}
  201. */
  202. /* Public Types --------------------------------------------------------------- */
  203. /** @defgroup RTC_Public_Types RTC Public Types
  204. * @{
  205. */
  206. /** @brief Time structure definitions for easy manipulate the data */
  207. typedef struct {
  208. uint32_t SEC; /*!< Seconds Register */
  209. uint32_t MIN; /*!< Minutes Register */
  210. uint32_t HOUR; /*!< Hours Register */
  211. uint32_t DOM; /*!< Day of Month Register */
  212. uint32_t DOW; /*!< Day of Week Register */
  213. uint32_t DOY; /*!< Day of Year Register */
  214. uint32_t MONTH; /*!< Months Register */
  215. uint32_t YEAR; /*!< Years Register */
  216. } RTC_TIME_Type;
  217. /** @brief RTC interrupt source */
  218. typedef enum {
  219. RTC_INT_COUNTER_INCREASE = RTC_IRL_RTCCIF, /*!< Counter Increment Interrupt */
  220. RTC_INT_ALARM = RTC_IRL_RTCALF /*!< The alarm interrupt */
  221. } RTC_INT_OPT;
  222. /** @brief RTC time type option */
  223. typedef enum {
  224. RTC_TIMETYPE_SECOND = 0, /*!< Second */
  225. RTC_TIMETYPE_MINUTE = 1, /*!< Month */
  226. RTC_TIMETYPE_HOUR = 2, /*!< Hour */
  227. RTC_TIMETYPE_DAYOFWEEK = 3, /*!< Day of week */
  228. RTC_TIMETYPE_DAYOFMONTH = 4, /*!< Day of month */
  229. RTC_TIMETYPE_DAYOFYEAR = 5, /*!< Day of year */
  230. RTC_TIMETYPE_MONTH = 6, /*!< Month */
  231. RTC_TIMETYPE_YEAR = 7 /*!< Year */
  232. } RTC_TIMETYPE_Num;
  233. /**
  234. * @}
  235. */
  236. /* Public Functions ----------------------------------------------------------- */
  237. /** @defgroup RTC_Public_Functions RTC Public Functions
  238. * @{
  239. */
  240. void RTC_Init (LPC_RTC_TypeDef *RTCx);
  241. void RTC_DeInit(LPC_RTC_TypeDef *RTCx);
  242. void RTC_ResetClockTickCounter(LPC_RTC_TypeDef *RTCx);
  243. void RTC_Cmd (LPC_RTC_TypeDef *RTCx, FunctionalState NewState);
  244. void RTC_CntIncrIntConfig (LPC_RTC_TypeDef *RTCx, uint32_t CntIncrIntType, \
  245. FunctionalState NewState);
  246. void RTC_AlarmIntConfig (LPC_RTC_TypeDef *RTCx, uint32_t AlarmTimeType, \
  247. FunctionalState NewState);
  248. void RTC_SetTime (LPC_RTC_TypeDef *RTCx, uint32_t Timetype, uint32_t TimeValue);
  249. uint32_t RTC_GetTime(LPC_RTC_TypeDef *RTCx, uint32_t Timetype);
  250. void RTC_SetFullTime (LPC_RTC_TypeDef *RTCx, RTC_TIME_Type *pFullTime);
  251. void RTC_GetFullTime (LPC_RTC_TypeDef *RTCx, RTC_TIME_Type *pFullTime);
  252. void RTC_SetAlarmTime (LPC_RTC_TypeDef *RTCx, uint32_t Timetype, uint32_t ALValue);
  253. uint32_t RTC_GetAlarmTime (LPC_RTC_TypeDef *RTCx, uint32_t Timetype);
  254. void RTC_SetFullAlarmTime (LPC_RTC_TypeDef *RTCx, RTC_TIME_Type *pFullTime);
  255. void RTC_GetFullAlarmTime (LPC_RTC_TypeDef *RTCx, RTC_TIME_Type *pFullTime);
  256. IntStatus RTC_GetIntPending (LPC_RTC_TypeDef *RTCx, uint32_t IntType);
  257. void RTC_ClearIntPending (LPC_RTC_TypeDef *RTCx, uint32_t IntType);
  258. void RTC_CalibCounterCmd(LPC_RTC_TypeDef *RTCx, FunctionalState NewState);
  259. void RTC_CalibConfig(LPC_RTC_TypeDef *RTCx, uint32_t CalibValue, uint8_t CalibDir);
  260. void RTC_WriteGPREG (LPC_RTC_TypeDef *RTCx, uint8_t Channel, uint32_t Value);
  261. uint32_t RTC_ReadGPREG (LPC_RTC_TypeDef *RTCx, uint8_t Channel);
  262. /**
  263. * @}
  264. */
  265. #ifdef __cplusplus
  266. }
  267. #endif
  268. #endif /* LPC17XX_RTC_H_ */
  269. /**
  270. * @}
  271. */
  272. /* --------------------------------- End Of File ------------------------------ */