Rev 656 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 72 | chrv | 1 | #ifndef __RTC_H__ |
| 2 | #define __RTC_H__ |
||
| 104 | chrv | 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. |
||
| 126 | chrv | 15 | * |
| 16 | * Save modes of ZX Evolution to RTC NVRAM. |
||
| 104 | chrv | 17 | */ |
| 72 | chrv | 18 | |
| 75 | chrv | 19 | /** Address of PCF8583 RTC chip.*/ |
| 72 | chrv | 20 | #define RTC_ADDRESS 0xA0 |
| 21 | |||
| 104 | chrv | 22 | /** Register for year additional data. */ |
| 126 | chrv | 23 | #define RTC_YEAR_ADD_REG 0xFF |
| 24 | /** Register for common modes. */ |
||
| 25 | #define RTC_COMMON_MODE_REG 0xFE |
||
| 299 | chrv | 26 | /** Register for ps2mouse resolution. */ |
| 27 | #define RTC_PS2MOUSE_RES_REG 0xFD |
||
| 104 | chrv | 28 | |
| 75 | chrv | 29 | /** Init RTC.*/ |
| 72 | chrv | 30 | void rtc_init(void); |
| 75 | chrv | 31 | |
| 32 | /** |
||
| 33 | * Write byte to RTC. |
||
| 104 | chrv | 34 | * @param addr [in] - address of internal register on RTC |
| 35 | * @param data [in] - data to write |
||
| 75 | chrv | 36 | */ |
| 72 | chrv | 37 | void rtc_write(UBYTE addr, UBYTE data); |
| 75 | chrv | 38 | |
| 39 | /** |
||
| 40 | * Read byte from RTC. |
||
| 41 | * @return data |
||
| 104 | chrv | 42 | * @param addr [in] - address of internal register on RTC |
| 75 | chrv | 43 | */ |
| 72 | chrv | 44 | UBYTE rtc_read(UBYTE addr); |
| 45 | |||
| 94 | chrv | 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 | |||
| 104 | chrv | 76 | /** B register 2 bit - data mode (A 1 in DM signifies binary data while a 0 in DM specifies BCD data). */ |
| 505 | chrv | 77 | #define GLUK_B_DATA_MODE 0x04 |
| 129 | chrv | 78 | /** B register 1 bit - 24/12 mode (A 1 indicates the 24-hour mode and a 0 indicates the 12-hour mode). */ |
| 505 | chrv | 79 | #define GLUK_B_24_12_MODE 0x02 |
| 129 | chrv | 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). */ |
| 505 | chrv | 81 | #define GLUK_C_UPDATE_FLAG 0x10 |
| 672 | chrv | 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. */ |
||
| 505 | chrv | 84 | #define GLUK_C_CLEAR_LOG_FLAG 0x01 |
| 672 | chrv | 85 | #define GLUK_C_NUM_LED_FLAG 0x01 |
| 656 | chrv | 86 | /** C register 1 bit - unused in original, but in ZXEVO switch CAPS LED mode on PS2 keyboard. */ |
| 505 | chrv | 87 | #define GLUK_C_CAPS_LED_FLAG 0x02 |
| 656 | chrv | 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 |
||
| 104 | chrv | 90 | |
| 486 | chrv | 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 | |||
| 104 | chrv | 100 | /** Read values from RTC and setup Gluk clock registers. */ |
| 101 | void gluk_init(void); |
||
| 102 | |||
| 103 | /** Increment Gluk clock registers on one second. */ |
||
| 94 | chrv | 104 | void gluk_inc(void); |
| 105 | |||
| 106 | /** |
||
| 107 | * Get Gluk clock registers data. |
||
| 108 | * @return registers data |
||
| 104 | chrv | 109 | * @param index [in] - index of Gluck clock register |
| 94 | chrv | 110 | */ |
| 104 | chrv | 111 | UBYTE gluk_get_reg(UBYTE index); |
| 94 | chrv | 112 | |
| 104 | chrv | 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); |
||
| 94 | chrv | 119 | |
| 100 | chrv | 120 | |
| 72 | chrv | 121 | #endif //__RTC_H__ |