summaryrefslogtreecommitdiff
path: root/firmware/drivers/rtc/rtc_s3c2440.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers/rtc/rtc_s3c2440.c')
-rw-r--r--firmware/drivers/rtc/rtc_s3c2440.c40
1 files changed, 20 insertions, 20 deletions
diff --git a/firmware/drivers/rtc/rtc_s3c2440.c b/firmware/drivers/rtc/rtc_s3c2440.c
index d39b50a2ca..9b449052a9 100644
--- a/firmware/drivers/rtc/rtc_s3c2440.c
+++ b/firmware/drivers/rtc/rtc_s3c2440.c
@@ -30,28 +30,28 @@ void rtc_init(void)
30 RTCCON |= 1; 30 RTCCON |= 1;
31} 31}
32 32
33int rtc_read_datetime(unsigned char* buf) 33int rtc_read_datetime(struct tm *tm)
34{ 34{
35 buf[0] = BCDSEC; 35 tm->tm_sec = BCD2DEC(BCDSEC);
36 buf[1] = BCDMIN; 36 tm->tm_min = BCD2DEC(BCDMIN);
37 buf[2] = BCDHOUR; 37 tm->tm_hour = BCD2DEC(BCDHOUR);
38 buf[3] = BCDDAY-1; /* timefuncs wants 0..6 for wday */ 38 tm->tm_wday = BCD2DEC(BCDDAY) - 1; /* timefuncs wants 0..6 for wday */
39 buf[4] = BCDDATE; 39 tm->tm_mday = BCD2DEC(BCDDATE);
40 buf[5] = BCDMON; 40 tm->tm_mon = BCD2DEC(BCDMON) - 1;
41 buf[6] = BCDYEAR; 41 tm->tm_year = BCD2DEC(BCDYEAR) + 100;
42 42
43 return 1; 43 return 1;
44} 44}
45 45
46int rtc_write_datetime(unsigned char* buf) 46int rtc_write_datetime(const struct tm *tm)
47{ 47{
48 BCDSEC = buf[0]; 48 BCDSEC = DEC2BCD(tm->tm_sec);
49 BCDMIN = buf[1]; 49 BCDMIN = DEC2BCD(tm->tm_min);
50 BCDHOUR = buf[2]; 50 BCDHOUR = DEC2BCD(tm->tm_hour);
51 BCDDAY = buf[3]+1; /* chip wants 1..7 for wday */ 51 BCDDAY = DEC2BCD(tm->tm_wday) + 1; /* chip wants 1..7 for wday */
52 BCDDATE = buf[4]; 52 BCDDATE = DEC2BCD(tm->tm_mday);
53 BCDMON = buf[5]; 53 BCDMON = DEC2BCD(tm->tm_mon + 1);
54 BCDYEAR = buf[6]; 54 BCDYEAR = DEC2BCD(tm->tm_year - 100);
55 55
56 return 1; 56 return 1;
57} 57}
@@ -88,15 +88,15 @@ bool rtc_check_alarm_flag(void)
88/* set alarm time registers to the given time (repeat once per day) */ 88/* set alarm time registers to the given time (repeat once per day) */
89void rtc_set_alarm(int h, int m) 89void rtc_set_alarm(int h, int m)
90{ 90{
91 ALMMIN=(((m / 10) << 4) | (m % 10)) & 0x7f; /* minutes */ 91 ALMMIN = DEC2BCD(m); /* minutes */
92 ALMHOUR=(((h / 10) << 4) | (h % 10)) & 0x3f; /* hour */ 92 ALMHOUR = DEC2BCD(h); /* hour */
93} 93}
94 94
95/* read out the current alarm time */ 95/* read out the current alarm time */
96void rtc_get_alarm(int *h, int *m) 96void rtc_get_alarm(int *h, int *m)
97{ 97{
98 *m=((ALMMIN & 0x70) >> 4) * 10 + (ALMMIN & 0x0f); 98 *m = BCD2DEC(ALMMIN);
99 *h=((ALMHOUR & 0x30) >> 4) * 10 + (ALMHOUR & 0x0f); 99 *h = BCD2DEC(ALMHOUR);
100} 100}
101 101
102/* turn alarm on or off by setting the alarm flag enable 102/* turn alarm on or off by setting the alarm flag enable