Subversion Repositories pentevo

Rev

Rev 656 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed | ?url?

  1. #ifndef __RTC_H__
  2. #define __RTC_H__
  3. /**
  4.  * @file
  5.  * @brief RTC support.
  6.  * @author http://www.nedopc.com
  7.  *
  8.  * RTC PCF8583 support for ZX Evolution.
  9.  *
  10.  * ZX Evolution emulate Gluk clock standard:
  11.  * - full read/write time emulate;
  12.  * - full read/write nvram emulate;
  13.  * - registers A,B,C,D read only;
  14.  * - alarm functions not emulated.
  15.  *
  16.  * Save modes of ZX Evolution to RTC NVRAM.
  17.  */
  18.  
  19. /** Address of PCF8583 RTC chip.*/
  20. #define RTC_ADDRESS  0xA0
  21.  
  22. /** Register for year additional data. */
  23. #define RTC_YEAR_ADD_REG     0xFF
  24. /** Register for common modes. */
  25. #define RTC_COMMON_MODE_REG  0xFE
  26. /** Register for ps2mouse resolution. */
  27. #define RTC_PS2MOUSE_RES_REG 0xFD
  28.  
  29. /** Init RTC.*/
  30. void rtc_init(void);
  31.  
  32. /**
  33.  * Write byte to RTC.
  34.  * @param addr [in] - address of internal register on RTC
  35.  * @param data [in] - data to write
  36.  */
  37. void rtc_write(UBYTE addr, UBYTE data);
  38.  
  39. /**
  40.  * Read byte from RTC.
  41.  * @return data
  42.  * @param addr [in] - address of internal register on RTC
  43.  */
  44. UBYTE rtc_read(UBYTE addr);
  45.  
  46.  
  47. /** Seconds register index. */
  48. #define GLUK_REG_SEC        0x00
  49. /** Seconds alarm register index. */
  50. #define GLUK_REG_SEC_ALARM  0x01
  51. /** Minutes register index. */
  52. #define GLUK_REG_MIN        0x02
  53. /** Minutes alarm register index. */
  54. #define GLUK_REG_MIN_ALARM  0x03
  55. /** Hours register index. */
  56. #define GLUK_REG_HOUR       0x04
  57. /** Hours alarm register index. */
  58. #define GLUK_REG_HOUR_ALARM 0x05
  59. /** Day of week register index. */
  60. #define GLUK_REG_DAY_WEEK   0x06
  61. /** Day of month register index. */
  62. #define GLUK_REG_DAY_MONTH  0x07
  63. /** Month register index. */
  64. #define GLUK_REG_MONTH      0x08
  65. /** Year register index. */
  66. #define GLUK_REG_YEAR       0x09
  67. /** A register index. */
  68. #define GLUK_REG_A          0x0A
  69. /** B register index. */
  70. #define GLUK_REG_B          0x0B
  71. /** C register index. */
  72. #define GLUK_REG_C          0x0C
  73. /** D register index. */
  74. #define GLUK_REG_D          0x0D
  75.  
  76. /** B register 2 bit - data mode (A 1 in DM signifies binary data while a 0 in DM specifies BCD data). */
  77. #define GLUK_B_DATA_MODE      0x04
  78. /** B register 1 bit - 24/12 mode (A 1 indicates the 24-hour mode and a 0 indicates the 12-hour mode). */
  79. #define GLUK_B_24_12_MODE     0x02
  80. /** C register 4 bit - Update-ended interrupt flag [UF] (Bit is set after each update cycle, UF is cleared by reading Register C or a RESET). */
  81. #define GLUK_C_UPDATE_FLAG    0x10
  82. /** C register 0 bit - unused in original, but in ZXEVO clear PS2 keyboard log on write. */
  83. /** C register 0 bit - unused in original, but in ZXEVO NUM LED status of PS2 keyboard on read. */
  84. #define GLUK_C_CLEAR_LOG_FLAG 0x01
  85. #define GLUK_C_NUM_LED_FLAG   0x01
  86. /** C register 1 bit - unused in original, but in ZXEVO switch CAPS LED mode on PS2 keyboard. */
  87. #define GLUK_C_CAPS_LED_FLAG  0x02
  88. /** C register 2 bit - unused in original, but in ZXEVO switch EEPROM mode on extra bytes (>0xF0). */
  89. #define GLUK_C_EEPROM_FLAG    0x80
  90.  
  91. /** Initial value for Gluk A register. */
  92. #define GLUK_A_INIT_VALUE   0x00
  93. /** Initial value for Gluk B register. */
  94. #define GLUK_B_INIT_VALUE   0x02
  95. /** Initial value for Gluk C register. */
  96. #define GLUK_C_INIT_VALUE   0x00
  97. /** Initial value for Gluk D register. */
  98. #define GLUK_D_INIT_VALUE   0x80
  99.  
  100. /** Read values from RTC and setup Gluk clock registers. */
  101. void gluk_init(void);
  102.  
  103. /** Increment Gluk clock registers on one second. */
  104. void gluk_inc(void);
  105.  
  106. /**
  107.  * Get Gluk clock registers data.
  108.  * @return registers data
  109.  * @param index [in] - index of Gluck clock register
  110.  */
  111. UBYTE gluk_get_reg(UBYTE index);
  112.  
  113. /**
  114.  * Set Gluk clock registers data.
  115.  * @param index [in] - index of Gluck clock register
  116.  * @param data [in] - data
  117.  */
  118. void gluk_set_reg(UBYTE index, UBYTE data);
  119.  
  120.  
  121. #endif //__RTC_H__
  122.