]> cloudbase.mooo.com Git - z180-stamp.git/blobdiff - avr/cmd_date.c
rewrite of cmd_cpu/do_cpu_freq
[z180-stamp.git] / avr / cmd_date.c
index efba8584f9790e21160284b5323b3e961b096072..0bd3ebb517cc1fe3ba375df6335efe23e73c3ac5 100644 (file)
@@ -4,17 +4,15 @@
  * (C) Copyright 2001
  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  *
  * (C) Copyright 2001
  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  *
- * SPDX-License-Identifier:    GPL-2.0+
+ * SPDX-License-Identifier:    GPL-2.0
  */
 
 /*
  * RTC, Date & Time support: get and set date & time
  */
  */
 
 /*
  * RTC, Date & Time support: get and set date & time
  */
-#include "common.h"
-#include <string.h>
+#include "cmd_date.h"
 #include "time.h"
 #include "rtc.h"
 #include "time.h"
 #include "rtc.h"
-#include "command.h"
 
 
 /*
 
 
 /*
@@ -125,20 +123,20 @@ int mk_date (const char *datestr, struct tm *tmp)
        return (-1);
 }
 
        return (-1);
 }
 
-command_ret_t do_date(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+command_ret_t do_date(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc, char * const argv[])
 {
        struct tm t;
        char buf[30];
 {
        struct tm t;
        char buf[30];
-       int rcode = CMD_RET_SUCCESS;
-
-       (void) cmdtp; (void) flag;
+       int rc;
+       command_ret_t rcode = CMD_RET_FAILURE;
 
        switch (argc) {
        case 2:                 /* set date & time */
                /* initialize t with current time */
 
        switch (argc) {
        case 2:                 /* set date & time */
                /* initialize t with current time */
-               rcode = rtc_get (&t);
-
-               if(!rcode) {
+               if(rtc_get(&t) < 0) {
+                       my_puts_P(PSTR("## Get date failed\n"));
+                       break;
+               } else {
                        /* insert new date & time */
                        if (mk_date (argv[1], &t) != 0) {
                                my_puts_P(PSTR("## Bad date format\n"));
                        /* insert new date & time */
                        if (mk_date (argv[1], &t) != 0) {
                                my_puts_P(PSTR("## Bad date format\n"));
@@ -150,22 +148,24 @@ command_ret_t do_date(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
                        gmtime_r(&time, &t);
 
                        /* and write to RTC */
                        gmtime_r(&time, &t);
 
                        /* and write to RTC */
-                       rcode = rtc_set (&t);
-                       if(rcode)
+                       if(rtc_set(&t) < 0) {
                                my_puts_P(PSTR("## Set date failed\n"));
                                my_puts_P(PSTR("## Set date failed\n"));
-               } else {
-                       my_puts_P(PSTR("## Get date failed\n"));
+                               break;
+                       }
                }
                /* FALL TROUGH */
        case 1:                 /* get date & time */
                }
                /* FALL TROUGH */
        case 1:                 /* get date & time */
-               rcode = rtc_get (&t);
-
-               if (rcode) {
+               rc = rtc_get(&t);
+               if (rc >= 0) {
+                       asctime_r(&t, buf);
+                       printf_P(PSTR("%s"), buf);
+                       if (rc == 1)
+                               printf_P(PSTR("  (Invalid)"));
+                       putchar('\n');
+                       rcode = CMD_RET_SUCCESS;
+               } else {
                        my_puts_P(PSTR("## Get date failed\n"));
                        my_puts_P(PSTR("## Get date failed\n"));
-                       break;
                }
                }
-               asctime_r(&t, buf);
-               printf_P(PSTR("%s\n"), buf);
                break;
 
        default:
                break;
 
        default: