diff options
Diffstat (limited to 'firmware/drivers/rtc/rtc_s35390a.c')
-rw-r--r-- | firmware/drivers/rtc/rtc_s35390a.c | 48 |
1 files changed, 31 insertions, 17 deletions
diff --git a/firmware/drivers/rtc/rtc_s35390a.c b/firmware/drivers/rtc/rtc_s35390a.c index 6bcf5c939b..0b95431330 100644 --- a/firmware/drivers/rtc/rtc_s35390a.c +++ b/firmware/drivers/rtc/rtc_s35390a.c | |||
@@ -58,35 +58,49 @@ void rtc_init(void) | |||
58 | { | 58 | { |
59 | } | 59 | } |
60 | 60 | ||
61 | int rtc_read_datetime(unsigned char* buf) | 61 | int rtc_read_datetime(struct tm *tm) |
62 | { | 62 | { |
63 | unsigned char data[7]; | 63 | unsigned char buf[7]; |
64 | int i, ret; | 64 | int i, ret; |
65 | 65 | ||
66 | ret = i2c_read(RTC_ADDR | (REALTIME_DATA1 << 1), -1, sizeof(data), data); | 66 | ret = i2c_read(RTC_ADDR | (REALTIME_DATA1 << 1), -1, sizeof(buf), buf); |
67 | reverse_bits(data, sizeof(data)); | 67 | reverse_bits(buf, sizeof(buf)); |
68 | 68 | ||
69 | buf[4] &= 0x3f; /* mask out p.m. flag */ | 69 | buf[4] &= 0x3f; /* mask out p.m. flag */ |
70 | 70 | ||
71 | for (i = 0; i < 7; i++) { | 71 | for (i = 0; i < sizeof(buf); i++) |
72 | buf[i] = data[6 - i]; | 72 | BCD2DEC(buf[i]); |
73 | } | 73 | |
74 | tm->tm_sec = buf[6]; | ||
75 | tm->tm_min = buf[5]; | ||
76 | tm->tm_hour = buf[4]; | ||
77 | tm->tm_wday = buf[3]; | ||
78 | tm->tm_mday = buf[2]; | ||
79 | tm->tm_mon = buf[1] - 1; | ||
80 | tm->tm_year = buf[0] + 100; | ||
74 | 81 | ||
75 | return ret; | 82 | return ret; |
76 | } | 83 | } |
77 | 84 | ||
78 | int rtc_write_datetime(unsigned char* buf) | 85 | int rtc_write_datetime(const struct tm *tm) |
79 | { | 86 | { |
80 | unsigned char data[7]; | 87 | unsigned char buf[7]; |
81 | int i, ret; | 88 | int i, ret; |
82 | 89 | ||
83 | for (i = 0; i < 7; i++) { | 90 | buf[6] = tm->tm_sec; |
84 | data[i] = buf[6 - i]; | 91 | buf[5] = tm->tm_min; |
85 | } | 92 | buf[4] = tm->tm_hour; |
86 | 93 | buf[3] = tm->tm_wday; | |
87 | reverse_bits(data, sizeof(data)); | 94 | buf[2] = tm->tm_mday; |
88 | ret = i2c_write(RTC_ADDR | (REALTIME_DATA1 << 1), -1, sizeof(data), data); | 95 | buf[1] = tm->tm_mon + 1; |
89 | 96 | buf[0] = tm->tm_year - 100; | |
97 | |||
98 | for (i = 0; i < sizeof(buf); i++) | ||
99 | DEC2BCD(buf[i]); | ||
100 | |||
101 | reverse_bits(buf, sizeof(buf)); | ||
102 | ret = i2c_write(RTC_ADDR | (REALTIME_DATA1 << 1), -1, sizeof(buf), buf); | ||
103 | |||
90 | return ret; | 104 | return ret; |
91 | } | 105 | } |
92 | 106 | ||