From: Antoine Mathys <barsamin@gmail.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>, paul@codesourcery.com
Subject: [Qemu-devel] [PATCH v2 3/6] hw/ds1338.c: Fix handling of HOURS register.
Date: Tue, 11 Dec 2012 23:57:10 +0100 [thread overview]
Message-ID: <50C7BA46.6000009@gmail.com> (raw)
In-Reply-To: <50C7B767.8020406@gmail.com>
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>
---
hw/ds1338.c | 29 ++++++++++++++++++-----------
1 file changed, 18 insertions(+), 11 deletions(-)
diff --git a/hw/ds1338.c b/hw/ds1338.c
index 69018bc..0f88720 100644
--- a/hw/ds1338.c
+++ b/hw/ds1338.c
@@ -55,10 +55,15 @@ static void capture_current_time(DS1338State *s)
qemu_get_timedate(&now, s->offset);
s->nvram[0] = to_bcd(now.tm_sec);
s->nvram[1] = to_bcd(now.tm_min);
- if (s->nvram[2] & 0x40) {
- s->nvram[2] = (to_bcd((now.tm_hour % 12)) + 1) | 0x40;
- if (now.tm_hour >= 12) {
- s->nvram[2] |= 0x20;
+ if (s->nvram[2] & HOURS_12) {
+ int tmp = now.tm_hour;
+ if (tmp == 0) {
+ 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 {
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);
break;
case 2:
- if (data & 0x40) {
- if (data & 0x20) {
- data = from_bcd(data & 0x4f) + 11;
- } else {
- data = from_bcd(data & 0x1f) - 1;
+ if (data & HOURS_12) {
+ int tmp = from_bcd(data & (HOURS_PM - 1));
+ if (data & HOURS_PM) {
+ tmp += 12;
+ }
+ if (tmp == 24) {
+ tmp = 0;
}
+ now.tm_hour = tmp;
} else {
- data = from_bcd(data);
+ now.tm_hour = from_bcd(data & (HOURS_12 - 1));
}
- now.tm_hour = data;
break;
case 3:
now.tm_wday = from_bcd(data & 7) - 1;
--
1.7.10.4
next prev parent reply other threads:[~2012-12-11 22:57 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-11 22:44 [Qemu-devel] [PATCH v2 0/6] hw/ds1338.c Antoine Mathys
2012-12-11 22:49 ` [Qemu-devel] [PATCH v2 1/6] hw/ds1338.c: Correct bug in conversion to BCD Antoine Mathys
2012-12-12 12:08 ` Peter Maydell
2012-12-11 22:52 ` [Qemu-devel] [PATCH v2 2/6] hw/ds1338.c: Add definitions for various flags in the RTC registers Antoine Mathys
2012-12-12 12:09 ` Peter Maydell
2012-12-11 22:57 ` Antoine Mathys [this message]
2012-12-12 12:10 ` [Qemu-devel] [PATCH v2 3/6] hw/ds1338.c: Fix handling of HOURS register Peter Maydell
2012-12-11 22:58 ` [Qemu-devel] [PATCH v2 4/6] hw/ds1338.c: Ensure state is properly initialized Antoine Mathys
2012-12-12 12:05 ` Peter Maydell
2012-12-12 12:46 ` Antoine Mathys
2012-12-12 13:02 ` Peter Maydell
2012-12-12 13:11 ` Antoine Mathys
2012-12-12 13:31 ` Peter Maydell
2012-12-11 22:58 ` [Qemu-devel] [PATCH v2 5/6] hw/ds1338.c: Implement support for the control register Antoine Mathys
2012-12-12 12:18 ` Peter Maydell
2012-12-11 22:59 ` [Qemu-devel] [PATCH v2 6/6] hw/ds1338.c: Fix handling of DAY (wday) register Antoine Mathys
2012-12-12 12:23 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=50C7BA46.6000009@gmail.com \
--to=barsamin@gmail.com \
--cc=paul@codesourcery.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).