Fri, 18 Apr 2014 01:34:20 -0600
added RTC emulation (attempts to set the date are ignored, and the year is currently hardcoded to 1987 because UNIX PC SysV has a few Y2K bugs)
andrew@151 | 1 | #ifndef _TC8250_H |
andrew@151 | 2 | #define _TC8250_H |
andrew@151 | 3 | |
andrew@151 | 4 | #include <stdbool.h> |
andrew@151 | 5 | #include <stddef.h> |
andrew@151 | 6 | #include <stdint.h> |
andrew@151 | 7 | #include <stdio.h> |
andrew@151 | 8 | |
andrew@151 | 9 | typedef struct { |
andrew@151 | 10 | bool chip_enable; |
andrew@151 | 11 | bool address_latch_enable; |
andrew@151 | 12 | bool write_enable; |
andrew@151 | 13 | uint8_t address; |
andrew@151 | 14 | uint8_t seconds_offset; |
andrew@151 | 15 | uint8_t minutes_offset; |
andrew@151 | 16 | uint8_t hours_offset; |
andrew@151 | 17 | uint8_t days_offset; |
andrew@151 | 18 | uint8_t months_offset; |
andrew@151 | 19 | uint8_t years_offset; |
andrew@151 | 20 | uint8_t weekday_offset; |
andrew@151 | 21 | } TC8250_CTX; |
andrew@151 | 22 | |
andrew@151 | 23 | void tc8250_init(TC8250_CTX *ctx); |
andrew@151 | 24 | void tc8250_set_chip_enable(TC8250_CTX *ctx, bool enabled); |
andrew@151 | 25 | void tc8250_set_address_latch_enable(TC8250_CTX *ctx, bool enabled); |
andrew@151 | 26 | void tc8250_set_write_enable(TC8250_CTX *ctx, bool enabled); |
andrew@151 | 27 | uint8_t tc8250_read_reg(TC8250_CTX *ctx); |
andrew@151 | 28 | void tc8250_write_reg(TC8250_CTX *ctx, uint8_t val); |
andrew@151 | 29 | |
andrew@151 | 30 | enum { |
andrew@151 | 31 | ONE_SEC_DIGT = 0x0, /* 1 sec digit */ |
andrew@151 | 32 | TEN_SEC_DIGT = 0x1, /* 10 sec digit */ |
andrew@151 | 33 | ONE_MIN_DIGT = 0x2, /* 1 minute digit */ |
andrew@151 | 34 | TEN_MIN_DIGT = 0x3, /* 10 minutes digit */ |
andrew@151 | 35 | ONE_HR_DIGT = 0x4, /* 1 hour digit */ |
andrew@151 | 36 | TEN_HR_DIGT = 0x5, /* 10 hours digit */ |
andrew@151 | 37 | ONE_DAY_DIGT = 0x6, /* 1 day digit */ |
andrew@151 | 38 | TEN_DAY_DIGT = 0x7, /* 10 days digit */ |
andrew@151 | 39 | ONE_MNTH_DIGT = 0x8, /* 1 month digit */ |
andrew@151 | 40 | TEN_MNTH_DIGT = 0x9, /* 10 month digit */ |
andrew@151 | 41 | ONE_YR_DIGT = 0xa, /* 1 year digit */ |
andrew@151 | 42 | TEN_YR_DIGT = 0xb, /* 10 year digit */ |
andrew@151 | 43 | WEEK_DAY = 0xc, /* day of the week */ |
andrew@151 | 44 | TOUT_CONTROL = 0xd, /* Tout control */ |
andrew@151 | 45 | PROTECT_KEY = 0xe, /* protection key */ |
andrew@151 | 46 | RTC_STATUS = 0xf /* real time clock status */ |
andrew@151 | 47 | }; |
andrew@151 | 48 | #endif |