diff options
Diffstat (limited to 'firmware/drivers/rtc/rtc_mr100.c')
-rw-r--r-- | firmware/drivers/rtc/rtc_mr100.c | 54 |
1 files changed, 36 insertions, 18 deletions
diff --git a/firmware/drivers/rtc/rtc_mr100.c b/firmware/drivers/rtc/rtc_mr100.c index 7ec3996a87..209845cea8 100644 --- a/firmware/drivers/rtc/rtc_mr100.c +++ b/firmware/drivers/rtc/rtc_mr100.c | |||
@@ -124,31 +124,49 @@ void rtc_init(void) | |||
124 | 124 | ||
125 | } | 125 | } |
126 | 126 | ||
127 | int rtc_read_datetime(unsigned char* buf) | 127 | int rtc_read_datetime(struct tm *tm) |
128 | { | 128 | { |
129 | int i; | 129 | unsigned int i; |
130 | unsigned char v[7]; | 130 | int rc; |
131 | unsigned char buf[7]; | ||
131 | 132 | ||
132 | i = sw_i2c(SW_I2C_READ, RTC_CMD_DATA, v, 7); | 133 | rc = sw_i2c(SW_I2C_READ, RTC_CMD_DATA, buf, sizeof(buf)); |
133 | 134 | ||
134 | v[4] &= 0x3f; /* mask out p.m. flag */ | 135 | buf[4] &= 0x3f; /* mask out p.m. flag */ |
135 | 136 | ||
136 | for(i=0; i<7; i++) | 137 | for (i = 0; i < sizeof(buf); i++) |
137 | buf[i] = v[6-i]; | 138 | buf[i] = BCD2DEC(buf[i]); |
138 | 139 | ||
139 | return i; | 140 | tm->tm_sec = buf[6]; |
141 | tm->tm_min = buf[5]; | ||
142 | tm->tm_hour = buf[4]; | ||
143 | tm->tm_wday = buf[3]; | ||
144 | tm->tm_mday = buf[2]; | ||
145 | tm->tm_mon = buf[1] - 1; | ||
146 | tm->tm_year = buf[0] + 100; | ||
147 | |||
148 | return rc; | ||
140 | } | 149 | } |
141 | 150 | ||
142 | int rtc_write_datetime(unsigned char* buf) | 151 | int rtc_write_datetime(const struct tm *tm) |
143 | { | 152 | { |
144 | int i; | 153 | unsigned int i; |
145 | unsigned char v[7]; | 154 | int rc; |
155 | unsigned char buf[7]; | ||
146 | 156 | ||
147 | for(i=0; i<7; i++) | 157 | buf[6] = tm->tm_sec; |
148 | v[i]=buf[6-i]; | 158 | buf[5] = tm->tm_min; |
149 | 159 | buf[4] = tm->tm_hour; | |
150 | i = sw_i2c(SW_I2C_WRITE, RTC_CMD_DATA, v, 7); | 160 | buf[3] = tm->tm_wday; |
151 | 161 | buf[2] = tm->tm_mday; | |
152 | return i; | 162 | buf[1] = tm->tm_mon + 1; |
163 | buf[0] = tm->tm_year - 100; | ||
164 | |||
165 | for (i = 0; i < sizeof(buf); i++) | ||
166 | buf[i] = DEC2BCD(buf[i]); | ||
167 | |||
168 | rc = sw_i2c(SW_I2C_WRITE, RTC_CMD_DATA, buf, sizeof(buf)); | ||
169 | |||
170 | return rc; | ||
153 | } | 171 | } |
154 | 172 | ||