summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/common/timefuncs.c48
1 files changed, 30 insertions, 18 deletions
diff --git a/firmware/common/timefuncs.c b/firmware/common/timefuncs.c
index 53ca5f3c16..cc54840376 100644
--- a/firmware/common/timefuncs.c
+++ b/firmware/common/timefuncs.c
@@ -27,9 +27,23 @@
27#include "timefuncs.h" 27#include "timefuncs.h"
28#include "debug.h" 28#include "debug.h"
29 29
30#ifndef SIMULATOR 30#if !(defined SIMULATOR && CONFIG_RTC)
31
31static struct tm tm; 32static struct tm tm;
32#endif 33
34static void fill_default_tm(struct tm *tm)
35{
36 tm->tm_sec = 0;
37 tm->tm_min = 0;
38 tm->tm_hour = 0;
39 tm->tm_mday = 1;
40 tm->tm_mon = 0;
41 tm->tm_year = 70;
42 tm->tm_wday = 1;
43 tm->tm_yday = 0; /* Not implemented for now */
44 tm->tm_isdst = -1; /* Not implemented for now */
45}
46#endif /* !(defined SIMULATOR && CONFIG_RTC)*/
33 47
34bool valid_time(const struct tm *tm) 48bool valid_time(const struct tm *tm)
35{ 49{
@@ -72,32 +86,30 @@ struct tm *get_time(void)
72 1964+nn here to make leap years work correctly, so the date will be one 86 1964+nn here to make leap years work correctly, so the date will be one
73 year off in the iriver firmware but at least won't be reset anymore. */ 87 year off in the iriver firmware but at least won't be reset anymore. */
74 tm.tm_year = ((rtcbuf[6] & 0xf0) >> 4) * 10 + (rtcbuf[6] & 0x0f) + 64; 88 tm.tm_year = ((rtcbuf[6] & 0xf0) >> 4) * 10 + (rtcbuf[6] & 0x0f) + 64;
75#else 89#else /* Not IRIVER_H300_SERIES */
76 tm.tm_year = ((rtcbuf[6] & 0xf0) >> 4) * 10 + (rtcbuf[6] & 0x0f) + 100; 90 tm.tm_year = ((rtcbuf[6] & 0xf0) >> 4) * 10 + (rtcbuf[6] & 0x0f) + 100;
77#endif 91#endif /* IRIVER_H300_SERIES */
78 92
79 tm.tm_yday = 0; /* Not implemented for now */ 93 tm.tm_yday = 0; /* Not implemented for now */
80 tm.tm_isdst = -1; /* Not implemented for now */ 94 tm.tm_isdst = -1; /* Not implemented for now */
81#else 95#else /* CONFIG_RTC == RTC_JZ47XX */
82 rtc_read_datetime((unsigned char*)&tm); 96 rtc_read_datetime((unsigned char*)&tm);
83#endif 97#endif /* CONFIG_RTC */
84 } 98 }
85#else 99#else /* No RTC */
86 tm.tm_sec = 0; 100 fill_default_tm(&tm);
87 tm.tm_min = 0; 101#endif /* RTC */
88 tm.tm_hour = 0;
89 tm.tm_mday = 1;
90 tm.tm_mon = 0;
91 tm.tm_year = 70;
92 tm.tm_wday = 1;
93 tm.tm_yday = 0; /* Not implemented for now */
94 tm.tm_isdst = -1; /* Not implemented for now */
95#endif
96 return &tm; 102 return &tm;
97#else 103
104#else /* SIMULATOR */
105#if CONFIG_RTC
98 time_t now = time(NULL); 106 time_t now = time(NULL);
99 return localtime(&now); 107 return localtime(&now);
108#else /* Simulator, no RTC */
109 fill_default_tm(&tm);
110 return &tm;
100#endif 111#endif
112#endif /* SIMULATOR */
101} 113}
102 114
103int set_time(const struct tm *tm) 115int set_time(const struct tm *tm)