lpc17xx_rtc.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. #ifndef _LPC17XX_RTC_H_
  2. #define _LPC17XX_RTC_H_
  3. /*
  4. * Copyright (C) 2012 by Ole Reinhardt (ole.reinhardt@embedded-it.de)
  5. *
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. * 3. Neither the name of the copyright holders nor the names of
  18. * contributors may be used to endorse or promote products derived
  19. * from this software without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  31. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32. * SUCH DAMAGE.
  33. *
  34. * For additional information see http://www.ethernut.de/
  35. *
  36. * Parts taken from lpc177x_8x_rtc.h 2011-06-02
  37. * file lpc177x_8x_rtc.h
  38. * brief Contains all macro definitions and function prototypes
  39. * support for Ethernet MAC firmware library on LPC177x_8x
  40. * version 1.0
  41. * date 02. June. 2011
  42. * author NXP MCU SW Application Team
  43. *
  44. * Copyright(C) 2011, NXP Semiconductor
  45. * All rights reserved.
  46. *
  47. ***********************************************************************
  48. * Software that is described herein is for illustrative purposes only
  49. * which provides customers with programming information regarding the
  50. * products. This software is supplied "AS IS" without any warranties.
  51. * NXP Semiconductors assumes no responsibility or liability for the
  52. * use of the software, conveys no license or title under any patent,
  53. * copyright, or mask work right to the product. NXP Semiconductors
  54. * reserves the right to make changes in the software without
  55. * notification. NXP Semiconductors also make no representation or
  56. * warranty that such application will be suitable for the specified
  57. * use without further testing or modification.
  58. **********************************************************************/
  59. /*!
  60. * \verbatim
  61. * $Id: $
  62. * \endverbatim
  63. */
  64. /*============================================================================*
  65. LPC17xx RTC misc register defines
  66. *============================================================================*/
  67. /*----------------------------------------------------------------------------*
  68. ILR register definitions
  69. *----------------------------------------------------------------------------*/
  70. /* ILR register mask */
  71. #define RTC_ILR_BITMASK 0x00000003
  72. /* Bit inform the source interrupt is counter increment*/
  73. #define RTC_IRL_RTCCIF _BV(0)
  74. /* Bit inform the source interrupt is alarm match*/
  75. #define RTC_IRL_RTCALF _BV(1)
  76. /*----------------------------------------------------------------------------*
  77. CCR register definitions
  78. *----------------------------------------------------------------------------*/
  79. /* CCR register mask */
  80. #define RTC_CCR_BITMASK 0x00000013
  81. /* Clock enable */
  82. #define RTC_CCR_CLKEN _BV(0)
  83. /* Clock reset */
  84. #define RTC_CCR_CTCRST _BV(1)
  85. /* Calibration counter enable */
  86. #define RTC_CCR_CCALEN _BV(4)
  87. /*----------------------------------------------------------------------------*
  88. CIIR register definitions
  89. *----------------------------------------------------------------------------*/
  90. /* Counter Increment Interrupt bit for second */
  91. #define RTC_CIIR_IMSEC _BV(0)
  92. /* Counter Increment Interrupt bit for minute */
  93. #define RTC_CIIR_IMMIN _BV(1)
  94. /* Counter Increment Interrupt bit for hour */
  95. #define RTC_CIIR_IMHOUR _BV(2)
  96. /* Counter Increment Interrupt bit for day of month */
  97. #define RTC_CIIR_IMDOM _BV(3)
  98. /* Counter Increment Interrupt bit for day of week */
  99. #define RTC_CIIR_IMDOW _BV(4)
  100. /* Counter Increment Interrupt bit for day of year */
  101. #define RTC_CIIR_IMDOY _BV(5)
  102. /* Counter Increment Interrupt bit for month */
  103. #define RTC_CIIR_IMMON _BV(6)
  104. /* Counter Increment Interrupt bit for year */
  105. #define RTC_CIIR_IMYEAR _BV(7)
  106. /* CIIR bit mask */
  107. #define RTC_CIIR_BITMASK 0xFF
  108. /*----------------------------------------------------------------------------*
  109. AMR register definitions
  110. *----------------------------------------------------------------------------*/
  111. /* Counter Increment Select Mask bit for second */
  112. #define RTC_AMR_AMRSEC _BV(0)
  113. /* Counter Increment Select Mask bit for minute */
  114. #define RTC_AMR_AMRMIN _BV(1)
  115. /* Counter Increment Select Mask bit for hour */
  116. #define RTC_AMR_AMRHOUR _BV(2)
  117. /* Counter Increment Select Mask bit for day of month */
  118. #define RTC_AMR_AMRDOM _BV(3)
  119. /* Counter Increment Select Mask bit for day of week */
  120. #define RTC_AMR_AMRDOW _BV(4)
  121. /* Counter Increment Select Mask bit for day of year */
  122. #define RTC_AMR_AMRDOY _BV(5)
  123. /* Counter Increment Select Mask bit for month */
  124. #define RTC_AMR_AMRMON _BV(6)
  125. /* Counter Increment Select Mask bit for year */
  126. #define RTC_AMR_AMRYEAR _BV(7)
  127. /* AMR bit mask */
  128. #define RTC_AMR_BITMASK 0xFF
  129. /*----------------------------------------------------------------------------*
  130. RTC_AUX register definitions
  131. *----------------------------------------------------------------------------*/
  132. /* RTC Oscillator Fail detect flag */
  133. #define RTC_AUX_RTC_OSCF _BV(4)
  134. /*----------------------------------------------------------------------------*
  135. RTC_AUXEN register definitions
  136. *----------------------------------------------------------------------------*/
  137. /* Oscillator Fail Detect interrupt enable*/
  138. #define RTC_AUXEN_RTC_OSCFEN _BV(4)
  139. /*============================================================================*
  140. Consolidated time registers
  141. *============================================================================*/
  142. /*----------------------------------------------------------------------------*
  143. Consolidated Time Register 0 definitions
  144. *----------------------------------------------------------------------------*/
  145. #define RTC_CTIME0_SECONDS_MASK 0x3F
  146. #define RTC_CTIME0_MINUTES_MASK 0x3F00
  147. #define RTC_CTIME0_HOURS_MASK 0x1F0000
  148. #define RTC_CTIME0_DOW_MASK 0x7000000
  149. /*----------------------------------------------------------------------------*
  150. Consolidated Time Register 1 definitions
  151. *----------------------------------------------------------------------------*/
  152. #define RTC_CTIME1_DOM_MASK 0x1F
  153. #define RTC_CTIME1_MONTH_MASK 0xF00
  154. #define RTC_CTIME1_YEAR_MASK 0xFFF0000
  155. /*----------------------------------------------------------------------------*
  156. Consolidated Time Register 2 definitions
  157. *----------------------------------------------------------------------------*/
  158. #define RTC_CTIME2_DOY_MASK 0x0FFF
  159. /*----------------------------------------------------------------------------*
  160. Time Counter Group and Alarm register
  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. /* Maximum value of second */
  179. #define RTC_SECOND_MAX 59
  180. /* Maximum value of minute*/
  181. #define RTC_MINUTE_MAX 59
  182. /* Maximum value of hour*/
  183. #define RTC_HOUR_MAX 23
  184. /* Minimum value of month*/
  185. #define RTC_MONTH_MIN 1
  186. /* Maximum value of month*/
  187. #define RTC_MONTH_MAX 12
  188. /* Minimum value of day of month*/
  189. #define RTC_DAYOFMONTH_MIN 1
  190. /* Maximum value of day of month*/
  191. #define RTC_DAYOFMONTH_MAX 31
  192. /* Maximum value of day of week*/
  193. #define RTC_DAYOFWEEK_MAX 6
  194. /* Minimum value of day of year*/
  195. #define RTC_DAYOFYEAR_MIN 1
  196. /* Maximum value of day of year*/
  197. #define RTC_DAYOFYEAR_MAX 366
  198. /* Maximum value of year*/
  199. #define RTC_YEAR_MAX 4095
  200. /*----------------------------------------------------------------------------*
  201. Calibration register
  202. *----------------------------------------------------------------------------*/
  203. /* Calibration value */
  204. #define RTC_CALIBRATION_CALVAL_MASK 0x1FFFF
  205. /* Calibration direction */
  206. #define RTC_CALIBRATION_LIBDIR _BV(17)
  207. /* Calibration max value */
  208. #define RTC_CALIBRATION_MAX 0x20000
  209. /* Calibration definitions */
  210. #define RTC_CALIB_DIR_FORWARD 0
  211. #define RTC_CALIB_DIR_BACKWARD 1
  212. #endif /* __LPC17XX_RTC_H_ */