From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:48287) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TfcLV-0008Ms-Iu for qemu-devel@nongnu.org; Mon, 03 Dec 2012 15:10:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TfcLU-0005LU-Jq for qemu-devel@nongnu.org; Mon, 03 Dec 2012 15:10:29 -0500 Received: from mail-bk0-f45.google.com ([209.85.214.45]:33038) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TfcLU-0005L3-Ak for qemu-devel@nongnu.org; Mon, 03 Dec 2012 15:10:28 -0500 Received: by mail-bk0-f45.google.com with SMTP id jk13so1191601bkc.4 for ; Mon, 03 Dec 2012 12:10:26 -0800 (PST) Message-ID: <50BD0725.3010905@gmail.com> Date: Mon, 03 Dec 2012 21:10:13 +0100 From: Antoine Mathys MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH 5/?] hw/ds1338.c: Fix handling of DATE (wday) register List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, paul@codesourcery.com Per the datasheet, the DATE (wday) register is user defined. Implement this. Signed-off-by: Antoine Mathys --- hw/ds1338.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/hw/ds1338.c b/hw/ds1338.c index 8f85635..c502934 100644 --- a/hw/ds1338.c +++ b/hw/ds1338.c @@ -20,6 +20,7 @@ typedef struct { I2CSlave i2c; int64_t offset; + uint8_t wday_offset; uint8_t nvram[NVRAM_SIZE]; int32_t ptr; bool addr_byte; @@ -33,6 +34,7 @@ static const VMStateDescription vmstate_ds1338 = { .fields = (VMStateField[]) { VMSTATE_I2C_SLAVE(i2c, DS1338State), VMSTATE_INT64(offset, DS1338State), + VMSTATE_UINT8(wday_offset, DS1338State), VMSTATE_UINT8_ARRAY(nvram, DS1338State, NVRAM_SIZE), VMSTATE_INT32(ptr, DS1338State), VMSTATE_BOOL(addr_byte, DS1338State), @@ -62,7 +64,7 @@ static void write_time(DS1338State *s, const struct tm *tm) } else { s->nvram[2] = to_bcd(tm->tm_hour); } - s->nvram[3] = to_bcd(tm->tm_wday + 1); + s->nvram[3] = to_bcd((tm->tm_wday + s->wday_offset) % 7 + 1); s->nvram[4] = to_bcd(tm->tm_mday); s->nvram[5] = to_bcd(tm->tm_mon + 1); s->nvram[6] = to_bcd(tm->tm_year - 100); @@ -164,7 +166,12 @@ static int ds1338_send(I2CSlave *i2c, uint8_t data) } break; case 3: - now.tm_wday = from_bcd(data & 0x07) - 1; + { + int user_wday = from_bcd(data & 0x07) - 1; + if ((user_wday >= 0) && (user_wday <= 6)) { + s->wday_offset = (user_wday - now.tm_wday + 7) % 7; + } + } break; case 4: now.tm_mday = from_bcd(data & 0x3f); @@ -194,6 +201,9 @@ static int ds1338_send(I2CSlave *i2c, uint8_t data) static int ds1338_init(I2CSlave *i2c) { + DS1338State *s = FROM_I2C_SLAVE(DS1338State, i2c); + s->wday_offset = 0; + return 0; } -- 1.7.10.4