diff options
Diffstat (limited to 'avr/env.c')
-rw-r--r-- | avr/env.c | 77 |
1 files changed, 45 insertions, 32 deletions
@@ -114,9 +114,9 @@ typedef struct environment_s { typedef struct env_item_s { -#define EF_N_EEP (1<<7) -#define EF_V_EEP (1<<6) -#define EF_DIRTY (1<<0) +#define EF_N_EEP (1<<7) /* Variable name is in EEPROM */ +#define EF_V_EEP (1<<6) /* Variable value is in EEPROM */ +#define EF_DIRTY (1<<0) /* Variable is new or value changed */ uint8_t flags; union { uint16_t eep; @@ -307,7 +307,7 @@ static env_item_t *envlist_search(const char *name) sizeof(env_item_t), comp_env_key_item); } - +#if 0 env_item_t *envlist_insert(const char *key, env_item_t *e) { const size_t size = sizeof(env_item_t); @@ -322,7 +322,7 @@ env_item_t *envlist_insert(const char *key, env_item_t *e) } else return NULL; } - +#endif env_item_t *envlist_enter(env_item_t *e) { @@ -406,14 +406,11 @@ static int envlist_delete(const char *name) free(ep->name.ram); entrycount--; -printf_P(PSTR("*** envlist_delete memmove: 0x%.4x, 0x%.4x, %d\n"), - (unsigned) ep, (unsigned) ep + size, - (env_list - ep)*size + entrycount*size); memmove(ep, ep + 1, (env_list - ep)*size + entrycount*size); rc = 1; } -#if 1 +#if 0 dump_ram((uint8_t *) &env_list[0], entrycount * sizeof(env_item_t), "=== env_list:"); dump_heap(); @@ -427,7 +424,6 @@ printf_P(PSTR("*** envlist_delete memmove: 0x%.4x, 0x%.4x, %d\n"), return rc; } - char *getenv(const char *name) { env_item_t *ep; @@ -438,8 +434,7 @@ char *getenv(const char *name) ep = envlist_get(name, ENV_GET_VAL); if (ep != NULL) ret = ep->val.ram; - -#if 1 +#if 0 dump_ram((uint8_t *) &env_list[0], entrycount * sizeof(env_item_t), "=== env_list:"); dump_heap(); @@ -449,23 +444,20 @@ char *getenv(const char *name) env_item_print(&env_list[i]); } #endif - return ret; } +/* TODO: implement saveenv() */ int saveenv(void) { int rc = 0; - // rc = env_export(&env_new); if (rc) return rc; - // rc = eeprom_bus_write(CONFIG_SYS_DEF_EEPROM_ADDR, // off, (uchar *)&env_new, CONFIG_ENV_SIZE); - return rc; } @@ -481,9 +473,9 @@ int set_default_env(void) unsigned int len = CONFIG_ENV_SIZE - offsetof(env_t, data); unsigned int i, src = 0; char c = 0xff, c0 = c; - +#if 0 printf_P(PSTR("\n\n** set_default_env()\n")); - +#endif while (len) { memcpy_P(buf, default_env+src, sizeof(buf)); @@ -497,11 +489,12 @@ printf_P(PSTR("\n\n** set_default_env()\n")); } eeprom_update_block(buf, (char *) eep, i); -/**/ printf_P(PSTR("eeprom_update_block: eep: 0x%.4x, i:%d\n"), +#if 0 + printf_P(PSTR("eeprom_update_block: eep: 0x%.4x, i:%d\n"), (unsigned int) eep, i); -/**/ dump_ram((uint8_t *) buf, i, "=== buf:"); -/**/ dump_eep((const uint8_t *) eep, i); - + dump_ram((uint8_t *) buf, i, "=== buf:"); + dump_eep((const uint8_t *) eep, i); +#endif if (c == 0 && c0 == 0) len = 0; if (len > sizeof(buf)) @@ -509,13 +502,9 @@ printf_P(PSTR("\n\n** set_default_env()\n")); src += sizeof(buf); eep += sizeof(buf); } - -printf_P(PSTR("** crc adr: 0x%.4x, crc: 0x%.4x\n"), - (unsigned int) (uint16_t *) CONFIG_ENV_OFFSET + offsetof(env_t,crc), crc); - - eeprom_update_word((uint16_t *) CONFIG_ENV_OFFSET + offsetof(env_t,crc), crc); - -/**/ dump_eep(0, 128); +#if 0 + dump_eep(0, 128); +#endif return 0; } @@ -635,14 +624,24 @@ int do_env_print(cmd_tbl_t *cmdtp, int flag, int argc, } -/* +/** + * Set or delete environment variable + * * Set a new environment variable, * or replace or delete an existing one. + * + * @param flag (not used) + * @param argc + * @param argv[1] Environment variable to set or delete + * if no more args + * @param argv[2] ... Value to set it to + * + * @return 0 if ok, 1 on error */ static int _do_env_set(int flag, int argc, char * const argv[]) { - int i, len; - char *name, *value, *s; + int i, len; + char *name, *value, *s; env_item_t e, *ep; (void) flag; @@ -704,6 +703,13 @@ static int _do_env_set(int flag, int argc, char * const argv[]) return 0; } +/** + * Set an environment variable + * + * @param varname Environment variable to set + * @param varvalue Value to set it to + * @return 0 if ok, 1 on error + */ int setenv(const char *varname, const char *varvalue) { const char * const argv[3] = { NULL, varname, varvalue }; @@ -748,6 +754,13 @@ int setenv_hex(const char *varname, unsigned long value) return setenv(varname, str); } +/** + * Get an environment variable as a hex value + * + * @param varname Environment variable to get + * @param default_val Return this, if variable does not exist + * @return hex value of variable or default_val + */ unsigned long getenv_hex(const char *varname, unsigned long default_val) { const char *s; |