hw/ds1338.c: Fix handling of HOURS register.

Per the datasheet, the mapping between 12 and 24 hours modes is:
      0      <->  12   PM
      1-12   <->  1-12 AM
      13-23  <->  1-11 PM

Signed-off-by: Antoine Mathys <barsamin@gmail.com>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Antoine Mathys 2012-12-13 14:05:27 +00:00 committed by Peter Maydell
parent 95c9361598
commit 59dda8e05b

View File

@ -55,10 +55,15 @@ static void capture_current_time(DS1338State *s)
qemu_get_timedate(&now, s->offset); qemu_get_timedate(&now, s->offset);
s->nvram[0] = to_bcd(now.tm_sec); s->nvram[0] = to_bcd(now.tm_sec);
s->nvram[1] = to_bcd(now.tm_min); s->nvram[1] = to_bcd(now.tm_min);
if (s->nvram[2] & 0x40) { if (s->nvram[2] & HOURS_12) {
s->nvram[2] = (to_bcd((now.tm_hour % 12)) + 1) | 0x40; int tmp = now.tm_hour;
if (now.tm_hour >= 12) { if (tmp == 0) {
s->nvram[2] |= 0x20; tmp = 24;
}
if (tmp <= 12) {
s->nvram[2] = HOURS_12 | to_bcd(tmp);
} else {
s->nvram[2] = HOURS_12 | HOURS_PM | to_bcd(tmp - 12);
} }
} else { } else {
s->nvram[2] = to_bcd(now.tm_hour); s->nvram[2] = to_bcd(now.tm_hour);
@ -132,16 +137,18 @@ static int ds1338_send(I2CSlave *i2c, uint8_t data)
now.tm_min = from_bcd(data & 0x7f); now.tm_min = from_bcd(data & 0x7f);
break; break;
case 2: case 2:
if (data & 0x40) { if (data & HOURS_12) {
if (data & 0x20) { int tmp = from_bcd(data & (HOURS_PM - 1));
data = from_bcd(data & 0x4f) + 11; if (data & HOURS_PM) {
} else { tmp += 12;
data = from_bcd(data & 0x1f) - 1;
} }
} else { if (tmp == 24) {
data = from_bcd(data); tmp = 0;
}
now.tm_hour = tmp;
} else {
now.tm_hour = from_bcd(data & (HOURS_12 - 1));
} }
now.tm_hour = data;
break; break;
case 3: case 3:
now.tm_wday = from_bcd(data & 7) - 1; now.tm_wday = from_bcd(data & 7) - 1;