x12rtc.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. #ifndef _DEV_X12RTC_H_
  2. #define _DEV_X12RTC_H_
  3. /*
  4. * Copyright (C) 2005-2006 by egnite Software GmbH. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the copyright holders nor the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
  23. * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * For additional information see http://www.ethernut.de/
  33. */
  34. /*
  35. * $Log: x12rtc.h,v $
  36. * Revision 1.3 2006/10/05 17:18:49 haraldkipp
  37. * Hardware independant RTC layer added.
  38. *
  39. * Revision 1.2 2006/01/19 18:42:21 haraldkipp
  40. * Make it compile even if the calling module doesn't include time.h.
  41. *
  42. * Revision 1.1 2005/10/24 11:41:39 haraldkipp
  43. * Initial check-in.
  44. *
  45. */
  46. #include <dev/rtc.h>
  47. /*! \name Non-Volatile Alarm Registers */
  48. /*@{*/
  49. #define X12RTC_SCA0 0x00 /*!< \brief Alarm 0 second. */
  50. #define X12RTC_SCA1 0x08 /*!< \brief Alarm 1 second. */
  51. #define X12RTC_SCA_ESC 0x80 /*!< \brief Second alarm enabled. */
  52. #define X12RTC_MNA0 0x01 /*!< \brief Alarm 0 minute. */
  53. #define X12RTC_MNA1 0x09 /*!< \brief Alarm 1 minute. */
  54. #define X12RTC_MNA_EMN 0x80 /*!< \brief Minute alarm enabled. */
  55. #define X12RTC_HRA0 0x02 /*!< \brief Alarm 0 hour. */
  56. #define X12RTC_HRA1 0x0A /*!< \brief Alarm 1 hour. */
  57. #define X12RTC_HRA_EHR 0x80 /*!< \brief Hour alarm enabled. */
  58. #define X12RTC_DTA0 0x03 /*!< \brief Alarm 0 day of month. */
  59. #define X12RTC_DTA1 0x0B /*!< \brief Alarm 1 day of month. */
  60. #define X12RTC_DTA_EDT 0x80 /*!< \brief Day of month alarm enabled. */
  61. #define X12RTC_MOA0 0x04 /*!< \brief Alarm 0 month. */
  62. #define X12RTC_MOA1 0x0C /*!< \brief Alarm 1 month. */
  63. #define X12RTC_MOA_EMO 0x80 /*!< \brief Month alarm enabled. */
  64. #define X12RTC_YRA0 0x05 /*!< \brief Currently unused alarm 0 register. */
  65. #define X12RTC_YRA1 0x0D /*!< \brief Currently unused alarm 1 register. */
  66. #define X12RTC_DWA0 0x06 /*!< \brief Alarm 0 weekday. */
  67. #define X12RTC_DWA1 0x0E /*!< \brief Alarm 1 weekday. */
  68. #define X12RTC_DWA_EDW 0x80 /*!< \brief Weekday alarm enabled. */
  69. #define X12RTC_Y2K0 0x07 /*!< \brief Alarm 0 . */
  70. #define X12RTC_Y2K1 0x0F /*!< \brief Alarm 1 . */
  71. /*@}*/
  72. /*! \name Non-Volatile Control Registers */
  73. /*@{*/
  74. #define X12RTC_BL 0x10 /*!< \brief Block protection and watchdog register. */
  75. #define X12RTC_BL_WD 0x14 /*!< \brief Watchdog configuration. */
  76. #define X12RTC_BL_WD_1750 0x00 /*!< \brief Timeout after 1.75 seconds. */
  77. #define X12RTC_BL_WD_750 0x04 /*!< \brief Timeout after 750 milliseconds. */
  78. #define X12RTC_BL_WD_250 0x10 /*!< \brief Timeout after 250 milliseconds. */
  79. #define X12RTC_BL_WD_OFF 0x14 /*!< \brief Disabled. */
  80. #define X12RTC_BL_BP 0xE0 /*!< \brief Block protection. */
  81. #define X12RTC_BL_BP_NONE 0x00 /*!< \brief No protection. */
  82. #define X12RTC_BL_BP_UQUAD 0x20 /*!< \brief Upper quarter protected. */
  83. #define X12RTC_BL_BP_UHALF 0x40 /*!< \brief Upper half protected. */
  84. #define X12RTC_BL_BP_FULL 0x60 /*!< \brief Full array protected. */
  85. #define X12RTC_BL_BP_FIRST1 0x80 /*!< \brief First page protected. */
  86. #define X12RTC_BL_BP_FIRST2 0xA0 /*!< \brief First 2 pages protected. */
  87. #define X12RTC_BL_BP_FIRST3 0xC0 /*!< \brief First 4 pages protected. */
  88. #define X12RTC_BL_BP_FIRST8 0xE0 /*!< \brief First 8 pages protected. */
  89. #define X12RTC_INT 0x11 /*!< \brief Interrupt control and freq. output register. */
  90. #define X12RTC_INT_FO 0x14 /*!< \brief Programmable frequency output bits. */
  91. #define X12RTC_INT_FO_IRQ 0x00 /*!< \brief Alarm interrupt. */
  92. #define X12RTC_INT_FO_32KHZ 0x04 /*!< \brief 32.768kHz. */
  93. #define X12RTC_INT_FO_100HZ 0x10 /*!< \brief 100Hz. */
  94. #define X12RTC_INT_FO_1HZ 0x14 /*!< \brief 1Hz. */
  95. #define X12RTC_INT_AL0E 0x20 /*!< \brief Alarm 0 interrupt enable. */
  96. #define X12RTC_INT_AL1E 0x40 /*!< \brief Alarm 1 interrupt enable. */
  97. #define X12RTC_INT_IM 0x80 /*!< \brief Repetitive alarm. */
  98. #define X12RTC_ATR 0x12 /*!< \brief Analog trimming register. */
  99. #define X12RTC_DTR 0x13 /*!< \brief Digital trimming register. */
  100. #define X12RTC_DTR_NONE 0x00 /*!< \brief 0 PPM. */
  101. #define X12RTC_DTR_PLUS10 0x02 /*!< \brief +10 PPM. */
  102. #define X12RTC_DTR_PLUS20 0x01 /*!< \brief +20 PPM. */
  103. #define X12RTC_DTR_PLUS30 0x03 /*!< \brief +30 PPM. */
  104. #define X12RTC_DTR_MINUS10 0x06 /*!< \brief -10 PPM. */
  105. #define X12RTC_DTR_MINUS20 0x05 /*!< \brief -20 PPM. */
  106. #define X12RTC_DTR_MINUS30 0x07 /*!< \brief -30 PPM. */
  107. /*@}*/
  108. /*! \name Volatile Date and Time Registers */
  109. /*@{*/
  110. #define X12RTC_SC 0x30 /*!< Seconds register, 0 - 59. */
  111. #define X12RTC_MN 0x31 /*!< Minutes register, 0 - 59. */
  112. #define X12RTC_HR 0x32 /*!< Hours register, 0 - 23. */
  113. #define X12RTC_HR_MIL 0x80 /*!< Use 24h format. */
  114. #define X12RTC_DT 0x33 /*!< Day register, 1 - 31. */
  115. #define X12RTC_MO 0x34 /*!< Month register, 1 - 12. */
  116. #define X12RTC_YR 0x35 /*!< Year register, 0 - 99. */
  117. #define X12RTC_DW 0x36 /*!< Day of the weeks register, 0 - 6. */
  118. #define X128xRTC_SSEC 0x37 /*!< X1286 1/100 second register, 0 - 99 (read only). */
  119. #define X122xRTC_Y2K 0x37 /*!< X1226 epoch register, 19 or 20. */
  120. /*@}*/
  121. /*! \name Volatile Status Register */
  122. /*@{*/
  123. #define X12RTC_SR 0x3F /*!< Status register. */
  124. #define X12RTC_SR_RTCF 0x01 /*!< Power failure. */
  125. #define X12RTC_SR_WEL 0x02 /*!< Memory write enable. */
  126. #define X12RTC_SR_RWEL 0x04 /*!< Register write enable. */
  127. #define X12RTC_SR_AL0 0x20 /*!< Alarm 0 indicator. */
  128. #define X12RTC_SR_AL1 0x40 /*!< Alarm 1 indicator. */
  129. #define X12RTC_SR_BAT 0x80 /*!< Operating from battery. */
  130. /*@}*/
  131. extern NUTRTC rtcX12x6;
  132. __BEGIN_DECLS
  133. /* Prototypes */
  134. extern int X12Init(void);
  135. extern int X12RtcGetClock(struct _tm *tm);
  136. extern int X12RtcSetClock(CONST struct _tm *tm);
  137. extern int X12RtcGetAlarm(int idx, struct _tm *tm, int *aflgs);
  138. extern int X12RtcSetAlarm(int idx, CONST struct _tm *tm, int aflgs);
  139. extern int X12RtcGetStatus(u_long *sflgs);
  140. extern int X12RtcClearStatus(u_long sflgs);
  141. extern int X12RtcReadRegs(u_char addr, u_char *buff, size_t len);
  142. extern int X12RtcWrite(int nv, CONST u_char *buff, size_t len);
  143. extern int X12EepromRead(u_int addr, void *buff, size_t len);
  144. extern int X12EepromWrite(u_int addr, CONST void *buff, size_t len);
  145. __END_DECLS
  146. /* End of prototypes */
  147. #endif