1 //==========================================================================
5 // RedBoot time/date commands
7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 2003 Gary Thomas
13 // eCos is free software; you can redistribute it and/or modify it under
14 // the terms of the GNU General Public License as published by the Free
15 // Software Foundation; either version 2 or (at your option) any later version.
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 // You should have received a copy of the GNU General Public License along
23 // with eCos; if not, write to the Free Software Foundation, Inc.,
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26 // As a special exception, if other files instantiate templates or use macros
27 // or inline functions from this file, or you compile this file and link it
28 // with other works to produce a work based on this file, this file does not
29 // by itself cause the resulting work to be covered by the GNU General Public
30 // License. However the source code for this file must still be made available
31 // in accordance with section (3) of the GNU General Public License.
33 // This exception does not invalidate any other reasons why a work based on
34 // this file might be covered by the GNU General Public License.
36 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37 // at http://sources.redhat.com/ecos/ecos-license/
38 // -------------------------------------------
39 //####ECOSGPLCOPYRIGHTEND####
40 //==========================================================================
41 //#####DESCRIPTIONBEGIN####
47 //####DESCRIPTIONEND####
48 // -------------------------------------------------------------------------
51 #include <pkgconf/hal.h>
52 #include <pkgconf/wallclock.h>
54 #include <cyg/infra/diag.h>
55 #include <cyg/io/wallclock.hxx> // The WallClock API
56 #include <cyg/io/wallclock/wallclock.inl> // Helper functions (avoids LIBC)
59 "Show/Set the time of day",
60 "[YYYY/MM/DD HH:MM:SS]",
65 verify(cyg_uint32 val, int min, int max, char *id)
67 if (((int)val < min) || ((int)val > max)) {
68 diag_printf("%s is out of range - must be [%d..%d]\n", id, min, max);
75 do_time_date(int argc, char *argv[])
77 cyg_uint32 now = Cyg_WallClock::wallclock->get_current_time();
78 cyg_uint32 year, month, mday, hour, minute, second;
83 // Just show the current time/date
84 _simple_mkdate(now, &year, &month, &mday, &hour, &minute, &second);
85 diag_printf("%04d/%02d/%02d %02d:%02d:%02d\n",
86 year, month, mday, hour, minute, second);
87 } else if (argc == 3) {
89 if (!parse_num(sp, (unsigned long *)&year, &sp, "/") ||
90 !parse_num(sp, (unsigned long *)&month, &sp, "/") ||
91 !parse_num(sp, (unsigned long *)&mday, &sp, "/")) {
95 if (!parse_num(sp, (unsigned long *)&hour, &sp, ":") ||
96 !parse_num(sp, (unsigned long *)&minute, &sp, ":") ||
97 !parse_num(sp, (unsigned long *)&second, &sp, ":")) {
101 // Verify values make some sense, then set the hardware
102 if (year < 100) year += 2000;
103 ok = ok && verify(year, 1970, 2034, "year");
104 ok = ok && verify(month, 1, 12, "month");
105 ok = ok && verify(mday, 1, 31, "day");
106 ok = ok && verify(hour, 0, 23, "hour");
107 ok = ok && verify(minute, 0, 59, "minute");
108 ok = ok && verify(second, 0, 59, "second");
110 now = _simple_mktime(year, month, mday, hour, minute, second);
111 Cyg_WallClock::wallclock->set_current_time(now);
118 diag_printf("usage: date [YYYY/MM/DD HH:MM:SS]\n");
123 // -------------------------------------------------------------------------