Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / mvmeppc / stand / libsa / clock.c
blobfc1cf0532a6ed4812bcf54cc060e4388d3ba66a7
1 /* $NetBSD: clock.c,v 1.2 2009/01/12 11:32:44 tsutsui Exp $ */
3 /*
4 * This is a slightly modified version of mvme68k's standalone clock.c.
5 * As there was no attribution/copyright header on that file, there's
6 * not going to be one for this file.
7 */
9 #include <sys/types.h>
11 #include "stand.h"
12 #include "net.h"
13 #include "libsa.h"
14 #include "bugsyscalls.h"
16 #define FROMBCD(x) (int)((((unsigned int)(x)) >> 4) * 10 +\
17 (((unsigned int)(x)) & 0xf))
19 #define SECDAY (24 * 60 * 60)
20 #define SECYR (SECDAY * 365)
21 #define LEAPYEAR(y) (((y) & 3) == 0)
22 #define YEAR0 68
25 * This code is defunct after 2068.
26 * Will Unix still be here then??
28 const short dayyr[12] =
29 {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
31 static u_long
32 chiptotime(int sec, int min, int hour, int day, int mon, int year)
34 int days, yr;
36 sec = FROMBCD(sec);
37 min = FROMBCD(min);
38 hour = FROMBCD(hour);
39 day = FROMBCD(day);
40 mon = FROMBCD(mon);
41 year = FROMBCD(year) + YEAR0;
42 if (year < 70)
43 year = 70;
45 /* simple sanity checks */
46 if (year < 70 || mon < 1 || mon > 12 || day < 1 || day > 31)
47 return (0);
48 days = 0;
49 for (yr = 70; yr < year; yr++)
50 days += LEAPYEAR(yr) ? 366 : 365;
51 days += dayyr[mon - 1] + day - 1;
52 if (LEAPYEAR(yr) && mon > 2)
53 days++;
54 /* now have days since Jan 1, 1970; the rest is easy... */
55 return (days * SECDAY + hour * 3600 + min * 60 + sec);
58 satime_t
59 getsecs(void)
61 struct bug_rtc_rd rr;
63 bugsys_rtc_rd(&rr);
65 return (chiptotime(rr.rr_second, rr.rr_minute, rr.rr_hour,
66 rr.rr_dayofmonth, rr.rr_month, rr.rr_year));