1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include <stdio.h> /* get NULL */
27 #include "timefuncs.h"
33 static void fill_default_tm(struct tm
*tm
)
42 tm
->tm_yday
= 0; /* Not implemented for now */
43 tm
->tm_isdst
= -1; /* Not implemented for now */
45 #endif /* !CONFIG_RTC */
47 bool valid_time(const struct tm
*tm
)
49 if (tm
->tm_hour
< 0 || tm
->tm_hour
> 23 ||
50 tm
->tm_sec
< 0 || tm
->tm_sec
> 59 ||
51 tm
->tm_min
< 0 || tm
->tm_min
> 59 ||
52 tm
->tm_year
< 100 || tm
->tm_year
> 199 ||
53 tm
->tm_mon
< 0 || tm
->tm_mon
> 11 ||
54 tm
->tm_wday
< 0 || tm
->tm_wday
> 6 ||
55 tm
->tm_mday
< 1 || tm
->tm_mday
> 31)
61 struct tm
*get_time(void)
64 static long timeout
= 0;
66 /* Don't read the RTC more than once per second */
67 if (TIME_AFTER(current_tick
, timeout
))
69 /* Once per second, 1/10th of a second off */
70 timeout
= HZ
* (current_tick
/ HZ
+ 1) + HZ
/ 5;
71 rtc_read_datetime(&tm
);
73 tm
.tm_yday
= 0; /* Not implemented for now */
74 tm
.tm_isdst
= -1; /* Not implemented for now */
82 int set_time(const struct tm
*tm
)
89 rc
= rtc_write_datetime(tm
);
106 void set_day_of_week(struct tm
*tm
)
108 int y
=tm
->tm_year
+1900;
111 static const char mo
[] = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 };
113 if(m
== 0 || m
== 1) y
--;
114 tm
->tm_wday
= (d
+ mo
[m
] + y
+ y
/4 - y
/100 + y
/400) % 7;