]> cloudbase.mooo.com Git - z180-stamp.git/blobdiff - avr/env.c
env var fmon (F_CPU)
[z180-stamp.git] / avr / env.c
index 6bbd99c4f91fb1725004111a8f2cb6f0f468e3a7..8896004c8effb9729732fe451c01fa842caaab39 100644 (file)
--- a/avr/env.c
+++ b/avr/env.c
 
 #define DEBUG_ENV      0       /* set to 1 to debug */
 
-#define debug_env(fmt, args...)                                                              \
+#define debug_env(fmt, args...)                                                \
        debug_cond(DEBUG_ENV, fmt, ##args)
 
 
-#define ENV_SIZE       (CONFIG_ENV_SIZE - sizeof(uint16_t) -1)
-#define ACTIVE_FLAG    1
-#define OBSOLETE_FLAG  0
-
-#define ENVLIST_DELETE (1<<0)
-
-
 /*
  * Default Environment
  */
 #define DELIM          "\0"
 
 const FLASH char default_env[] = {
-       ENV_BAUDRATE      "=" "115200" DELIM
-       ENV_BOOTDELAY     "=" "3" DELIM
+       ENV_BAUDRATE      "=" stringify(CONFIG_BAUDRATE) DELIM
+       ENV_BOOTDELAY     "=" stringify(CONFIG_BOOTDELAY) DELIM
        ENV_BOOTCMD               "=" "pin ${pins};loadcpm3;go ${startaddress}" DELIM
        ENV_CPM3_SYSFILE  "=" CONFIG_CPM3_SYSFILE DELIM
        ENV_PINALIAS      "=" "0:PG5,1:PG4,2:PB4,3:PB5,4:PB6,5:PB7,"
                                                  "6:PG3,7:PG2,8:PG1,9:PG0,10:PE7" DELIM
-       //ENV_STARTADDRESS  "=" "0" DELIM
        "pins"                    "=" "2,8 low 9 high 3 2" DELIM
        DELIM
 };
 
 
+#define ENV_SIZE       (CONFIG_ENV_SIZE - sizeof(uint16_t) - sizeof(uint8_t))
+
+#define ENVLIST_DELETE (1<<0)
+
+
 /* EEPROM storage */
 typedef struct environment_s {
        uint16_t        crc;            /* CRC16 over data bytes        */
        uint8_t         flags;          /* active/obsolete flags        */
+#define ACTIVE_FLAG            1
+#define OBSOLETE_FLAG  0
        char            data[ENV_SIZE]; /* Environment data             */
 } env_t;
 
@@ -139,7 +138,7 @@ static char *env_item_insert_name(char *pos, const char *name, int len)
        while (*end++ != 0)
                while (*end++ != 0);
 
-       if (end > env_list + ENV_SIZE)
+       if (end + len >= env_list + ENV_SIZE)
                return NULL;
 
        memmove(dstp, pos, end - pos);
@@ -693,9 +692,6 @@ command_ret_t do_env_print(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED,
        bool mode = 0;
        command_ret_t rc = CMD_RET_SUCCESS;
 
-       /* reset getopt() */
-       optind = 0;
-
        int opt;
        while ((opt = getopt(argc, argv, PSTR("s"))) != -1) {
                switch (opt) {
@@ -714,7 +710,7 @@ command_ret_t do_env_print(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED,
                        return CMD_RET_FAILURE;
                if (mode == 0)
                        printf_P(PSTR("\nEnvironment size: %d/%d bytes\n"),
-                               size, ENV_SIZE);
+                               size, ENV_SIZE - 1);
                return CMD_RET_SUCCESS;
        }
 
@@ -795,3 +791,91 @@ int env_complete(char *var, int maxv, char *cmdv[], int bufsz, char *buf)
        return found;
 }
 #endif
+
+cmd_tbl_t cmd_tbl_env[] = {
+CMD_TBL_ITEM_COMPLETE(
+       printenv, CONFIG_SYS_MAXARGS,   1|CTBL_SUBCMDAUTO,      do_env_print,
+       "print environment variables",
+       "[-s] [name ...]\n"
+       "    Print value of environment variable(s) 'name'\n"
+       "    If no names are given, print values of all environment variables\n"
+       "    -s Print in setenv form",
+       var_complete
+),
+CMD_TBL_ITEM_COMPLETE(
+       setenv, CONFIG_SYS_MAXARGS,     CTBL_SUBCMDAUTO,        do_env_set,
+       "set environment variables",
+       "name value ...\n"
+       "    - set environment variable 'name' to 'value ...'\n"
+       "setenv name\n"
+       "    - delete environment variable 'name'",
+       var_complete
+),
+CMD_TBL_ITEM(
+       saveenv,        1,      CTBL_SUBCMDAUTO,        do_env_save,
+       "save environment variables to persistent storage",
+       ""
+),
+CMD_TBL_ITEM(
+       defaultenv,     1,      CTBL_SUBCMDAUTO,        do_env_default,
+       "set all environment variables to their default values",
+       ""
+),
+
+CMD_TBL_ITEM_COMPLETE(
+       print, CONFIG_SYS_MAXARGS,      1,      do_env_print,
+       "print environment variables",
+       "[-s] [name ...]\n"
+       "    Print value of environment variable(s) 'name'\n"
+       "    If no names are given, print values of all environment variables\n"
+       "    -s Print in setenv form",
+       var_complete
+),
+CMD_TBL_ITEM_COMPLETE(
+       set, CONFIG_SYS_MAXARGS,        0,      do_env_set,
+       "set environment variables",
+       "name value ...\n"
+       "    - set environment variable 'name' to 'value ...'\n"
+       "setenv name\n"
+       "    - delete environment variable 'name'",
+       var_complete
+),
+CMD_TBL_ITEM(
+       save,   1,      0,      do_env_save,
+       "save environment variables to persistent storage",
+       ""
+),
+CMD_TBL_ITEM(
+       default,        1,      0,      do_env_default,
+       "set all environment variables to their default values",
+       ""
+),
+
+CMD_TBL_ITEM(
+       help,   CONFIG_SYS_MAXARGS,     CTBL_RPT,       do_help,
+       "Print sub command description/usage",
+       "\n"
+       "       - print brief description of all sub commands\n"
+       "env help command ...\n"
+       "       - print detailed usage of sub cmd 'command'"
+),
+
+/* This does not use the CMD_TBL_ITEM macro as ? can't be used in symbol names */
+       {FSTR("?"),   CONFIG_SYS_MAXARGS, 1, do_help,
+        NULL,
+#ifdef  CONFIG_SYS_LONGHELP
+       FSTR(""),
+#endif /* CONFIG_SYS_LONGHELP */
+       NULL,
+#ifdef CONFIG_AUTO_COMPLETE
+       NULL,
+#endif
+},
+/* Mark end of table */
+CMD_TBL_END(cmd_tbl_env)
+};
+
+command_ret_t do_env(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc UNUSED, char * const argv[] UNUSED)
+{
+       return CMD_RET_USAGE;
+}