summaryrefslogtreecommitdiff
path: root/avr/pcf8583.c
diff options
context:
space:
mode:
Diffstat (limited to 'avr/pcf8583.c')
-rw-r--r--avr/pcf8583.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/avr/pcf8583.c b/avr/pcf8583.c
index af1331d..7e9d749 100644
--- a/avr/pcf8583.c
+++ b/avr/pcf8583.c
@@ -4,10 +4,11 @@
#include "common.h"
#include <stdlib.h>
-#include "debug.h"
-#include "command.h"
+#include "time.h"
#include "rtc.h"
#include "i2c.h"
+#include "command.h"
+#include "debug.h"
#define DEBUG_RTC 0
@@ -34,17 +35,17 @@ static uint_fast8_t bcd2bin(uint8_t val)
static uint8_t bin2bcd (uint_fast8_t val)
{
div_t d = div(val, 10);
-
+
return (d.quot << 4) | d.rem;
}
-int rtc_get (struct rtc_time *tmp)
+int rtc_get (struct tm *tmp)
{
int rel = 0;
uint8_t rtcbuf[NR_OF_REGS];
- uint16_t year;
-
+ int16_t year;
+
i2c_read(CONFIG_SYS_I2C_RTC_ADDR, 0, 1, rtcbuf, NR_OF_REGS);
i2c_read(CONFIG_SYS_I2C_RTC_ADDR, 0x10, 1, (uint8_t *) &year, 2);
@@ -56,12 +57,12 @@ int rtc_get (struct rtc_time *tmp)
tmp->tm_min = bcd2bin (rtcbuf[REG_MIN] & 0x7F);
tmp->tm_hour = bcd2bin (rtcbuf[REG_HOUR] & 0x3F);
tmp->tm_mday = bcd2bin (rtcbuf[REG_YRDATE] & 0x3F);
- tmp->tm_mon = bcd2bin (rtcbuf[REG_WDMON] & 0x1F);
+ tmp->tm_mon = bcd2bin (rtcbuf[REG_WDMON] & 0x1F) - 1;
while (year%4 < (rtcbuf[REG_YRDATE]>>6)) {
year++;
/* TODO: update RTC ram */
}
- tmp->tm_year = year;
+ tmp->tm_year = year;
tmp->tm_wday = rtcbuf[REG_WDMON] >> 5;
tmp->tm_yday = 0;
tmp->tm_isdst= 0;
@@ -74,7 +75,7 @@ int rtc_get (struct rtc_time *tmp)
return rel;
}
-int rtc_set (struct rtc_time *tmp)
+int rtc_set (struct tm *tmp)
{
uint8_t rtcbuf[NR_OF_REGS];
@@ -84,7 +85,7 @@ int rtc_set (struct rtc_time *tmp)
rtcbuf[REG_CS] = 0x84;
rtcbuf[REG_CSEC] = 0x00;
- rtcbuf[REG_WDMON ] = bin2bcd(tmp->tm_mon) | ((tmp->tm_wday) << 5);
+ rtcbuf[REG_WDMON ] = (bin2bcd(tmp->tm_mon) + 1) | ((tmp->tm_wday) << 5);
rtcbuf[REG_YRDATE] = ((tmp->tm_year % 4) << 6) | bin2bcd(tmp->tm_mday);
rtcbuf[REG_HOUR ] = bin2bcd(tmp->tm_hour);
rtcbuf[REG_MIN ] = bin2bcd(tmp->tm_min);