summaryrefslogtreecommitdiff
path: root/firmware/common
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/common')
-rw-r--r--firmware/common/timefuncs.c53
-rw-r--r--firmware/common/timefuncs.h44
2 files changed, 97 insertions, 0 deletions
diff --git a/firmware/common/timefuncs.c b/firmware/common/timefuncs.c
new file mode 100644
index 0000000000..0371762465
--- /dev/null
+++ b/firmware/common/timefuncs.c
@@ -0,0 +1,53 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#include "config.h"
21
22#include "rtc.h"
23#include "time.h"
24#include "debug.h"
25
26static struct tm tm;
27
28struct tm *get_time(void)
29{
30 char rtcbuf[8];
31 int i;
32
33 /* We don't need the first byte, but we want the indexes in the
34 buffer to match the data sheet */
35 rtc_read_multiple(1, &rtcbuf[1], 7);
36
37 for(i = 0;i < 7;i++)
38 {
39 DEBUGF("%02x ", rtcbuf[i]);
40 }
41 DEBUGF("\n");
42
43 tm.tm_sec = ((rtcbuf[1] & 0x70) >> 4) * 10 + (rtcbuf[1] & 0x0f);
44 tm.tm_min = ((rtcbuf[2] & 0x70) >> 4) * 10 + (rtcbuf[2] & 0x0f);
45 tm.tm_hour = ((rtcbuf[3] & 0x30) >> 4) * 10 + (rtcbuf[3] & 0x0f);
46 tm.tm_mday = ((rtcbuf[5] & 0x30) >> 4) * 10 + (rtcbuf[5] & 0x0f);
47 tm.tm_mon = ((rtcbuf[6] & 0x10) >> 4) * 10 + (rtcbuf[6] & 0x0f);
48 tm.tm_year = ((rtcbuf[7] & 0xf0) >> 4) * 10 + (rtcbuf[7] & 0x0f) + 2000;
49 tm.tm_wday = rtcbuf[4] & 0x07;
50 tm.tm_yday = 0; /* Not implemented for now */
51 tm.tm_isdst = -1; /* Not implemented for now */
52 return &tm;
53}
diff --git a/firmware/common/timefuncs.h b/firmware/common/timefuncs.h
new file mode 100644
index 0000000000..1110ad9a44
--- /dev/null
+++ b/firmware/common/timefuncs.h
@@ -0,0 +1,44 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#ifndef _TIMEFUNCS_H_
21#define _TIMEFUNCS_H_
22
23#include "config.h"
24
25#ifndef SIMULATOR
26
27struct tm
28{
29 int tm_sec; /* seconds */
30 int tm_min; /* minutes */
31 int tm_hour; /* hours */
32 int tm_mday; /* day of the month */
33 int tm_mon; /* month */
34 int tm_year; /* year */
35 int tm_wday; /* day of the week */
36 int tm_yday; /* day in the year */
37 int tm_isdst; /* daylight saving time */
38};
39
40#endif
41
42struct tm *get_time(void);
43
44#endif /* _TIMEFUNCS_H_ */