diff options
Diffstat (limited to 'firmware/drivers/rtc')
-rw-r--r-- | firmware/drivers/rtc/rtc_jz4740.c | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/firmware/drivers/rtc/rtc_jz4740.c b/firmware/drivers/rtc/rtc_jz4740.c index 77e0860cd2..da39b3faf7 100644 --- a/firmware/drivers/rtc/rtc_jz4740.c +++ b/firmware/drivers/rtc/rtc_jz4740.c | |||
@@ -28,11 +28,7 @@ | |||
28 | #include "jz4740.h" | 28 | #include "jz4740.h" |
29 | #include "rtc.h" | 29 | #include "rtc.h" |
30 | #include "timefuncs.h" | 30 | #include "timefuncs.h" |
31 | 31 | #include "logf.h" | |
32 | static unsigned int epoch = 1900; | ||
33 | static const unsigned char days_in_mo[] = { | ||
34 | 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 | ||
35 | }; | ||
36 | 32 | ||
37 | static const unsigned int yearday[5] = {0, 366, 366+365, 366+365*2, 366+365*3}; | 33 | static const unsigned int yearday[5] = {0, 366, 366+365, 366+365*2, 366+365*3}; |
38 | static const unsigned int sweekday = 6; | 34 | static const unsigned int sweekday = 6; |
@@ -52,8 +48,8 @@ static const unsigned int sum_monthday[13] = { | |||
52 | 365 | 48 | 365 |
53 | }; | 49 | }; |
54 | 50 | ||
55 | #if 0 | 51 | static unsigned int jz_mktime(int year, int mon, int day, int hour, int min, |
56 | static unsigned int jz_mktime(int year, int mon, int day, int hour, int min, int sec) | 52 | int sec) |
57 | { | 53 | { |
58 | unsigned int seccounter; | 54 | unsigned int seccounter; |
59 | 55 | ||
@@ -79,10 +75,9 @@ static unsigned int jz_mktime(int year, int mon, int day, int hour, int min, int | |||
79 | 75 | ||
80 | return seccounter; | 76 | return seccounter; |
81 | } | 77 | } |
82 | #endif | ||
83 | 78 | ||
84 | static void jz_gettime(unsigned int rtc, int *year, int *mon, int *day, int *hour, | 79 | static void jz_gettime(unsigned int rtc, int *year, int *mon, int *day, |
85 | int *min, int *sec, int *weekday) | 80 | int *hour, int *min, int *sec, int *weekday) |
86 | { | 81 | { |
87 | unsigned int tday, tsec, i, tmp; | 82 | unsigned int tday, tsec, i, tmp; |
88 | 83 | ||
@@ -143,9 +138,9 @@ int rtc_read_datetime(unsigned char* buf) | |||
143 | rtc_tm.tm_wday = wday; | 138 | rtc_tm.tm_wday = wday; |
144 | /* Don't use centry, but start from year 1970 */ | 139 | /* Don't use centry, but start from year 1970 */ |
145 | rtc_tm.tm_mon = mon; | 140 | rtc_tm.tm_mon = mon; |
146 | if ((year += (epoch - 1900)) <= 69) | 141 | if (year <= 69) |
147 | year += 100; | 142 | year += 100; |
148 | rtc_tm.tm_year = year + 1900; | 143 | rtc_tm.tm_year = year; |
149 | 144 | ||
150 | rtc_tm.tm_yday = 0; /* Not implemented for now */ | 145 | rtc_tm.tm_yday = 0; /* Not implemented for now */ |
151 | rtc_tm.tm_isdst = -1; /* Not implemented for now */ | 146 | rtc_tm.tm_isdst = -1; /* Not implemented for now */ |
@@ -156,7 +151,20 @@ int rtc_read_datetime(unsigned char* buf) | |||
156 | 151 | ||
157 | int rtc_write_datetime(unsigned char* buf) | 152 | int rtc_write_datetime(unsigned char* buf) |
158 | { | 153 | { |
159 | (void)buf; | 154 | struct tm *rtc_tm = (struct tm*)buf; |
155 | unsigned int year, lval; | ||
156 | |||
157 | year = rtc_tm->tm_year; | ||
158 | /* Don't use centry, but start from year 1970 */ | ||
159 | if (year > 69) | ||
160 | year -= 100; | ||
161 | year += 2000; | ||
162 | |||
163 | lval = jz_mktime(year, rtc_tm->tm_mon, rtc_tm->tm_mday, rtc_tm->tm_hour, | ||
164 | rtc_tm->tm_min, rtc_tm->tm_sec); | ||
165 | REG_RTC_RSR = lval; | ||
166 | |||
167 | return 0; | ||
160 | } | 168 | } |
161 | 169 | ||
162 | #if 0 | 170 | #if 0 |