summaryrefslogtreecommitdiff
path: root/avr
diff options
context:
space:
mode:
authorLeo C2014-08-31 22:37:26 +0200
committerLeo C2014-08-31 22:37:26 +0200
commitf76ca346168afe6cf68127934765a61bd477380e (patch)
tree8c0904fc0ed9dd59be329afc497956fe38e0cbd5 /avr
parent55027f3b53e5250768632efdd470c9e938e883e7 (diff)
downloadz180-stamp-f76ca346168afe6cf68127934765a61bd477380e.zip
$() expansion deleted (only ${}). setenv_ulong(), setenv_hex()
Diffstat (limited to 'avr')
-rw-r--r--avr/cli.c22
-rw-r--r--avr/env.c103
-rw-r--r--avr/main.c15
3 files changed, 79 insertions, 61 deletions
diff --git a/avr/cli.c b/avr/cli.c
index be5df40..08e7038 100644
--- a/avr/cli.c
+++ b/avr/cli.c
@@ -56,8 +56,8 @@ static void process_macros(const char *input, char *output)
#endif
uint_fast8_t state = 0; /* 0 = waiting for '$' */
- /* 1 = waiting for '(' or '{' */
- /* 2 = waiting for ')' or '}' */
+ /* 1 = waiting for '{' */
+ /* 2 = waiting for '}' */
/* 3 = waiting for ''' */
char *output_start = output;
@@ -94,7 +94,7 @@ static void process_macros(const char *input, char *output)
}
break;
case 1: /* Waiting for ( */
- if (c == '(' || c == '{') {
+ if (c == '{') {
state++;
varname_start = input;
} else {
@@ -109,7 +109,7 @@ static void process_macros(const char *input, char *output)
}
break;
case 2: /* Waiting for ) */
- if (c == ')' || c == '}') {
+ if (c == '}') {
char envname[CONFIG_SYS_ENV_NAMELEN+1], *envval;
/* Varname # of chars */
uint_fast8_t envcnt = input - varname_start - 1;
@@ -153,13 +153,21 @@ static void process_macros(const char *input, char *output)
strlen(output_start), output_start);
}
- /*
+/**
+ *
+ *
* WARNING:
*
* We must create a temporary copy of the command since the command we get
* may be the result from getenv(), which returns a pointer directly to
* the environment data, which may change magicly when the command we run
* creates or modifies environment variables (like "bootp" does).
+ *
+ *
+ * @param cmd
+ * @param flag
+ * @returns
+ *
*/
static int cli_run_command(const char *cmd, int flag)
{
@@ -173,7 +181,7 @@ static int cli_run_command(const char *cmd, int flag)
uint_fast8_t inquotes, repeatable = 1;
int rc = 0;
- debug_parser("[RUN_COMMAND] cmd[%p]=\"%s\"\n",
+ debug_parser("[RUN_COMMAND] cmd[%p]=\"%s\"\n",
cmd, cmd ? cmd : "NULL");
clear_ctrlc(); /* forget any previous Control C */
@@ -290,7 +298,7 @@ static int run_command_repeatable(const char *cmd, int flag)
int run_command_list(const char *cmd, int len)
{
(void) len;
-
+
return cli_run_command_list(cmd);
}
diff --git a/avr/env.c b/avr/env.c
index 602d845..5d1c5c0 100644
--- a/avr/env.c
+++ b/avr/env.c
@@ -1,7 +1,6 @@
#include "common.h"
#include <string.h>
#include <stdlib.h>
-
#include <avr/eeprom.h>
#include "config.h"
@@ -28,7 +27,7 @@
const FLASH char default_env[] = {
"bootdelay=" "3" DELIM
- "bootcmd=" "reset; loadf; go $(startaddr)" DELIM
+ "bootcmd=" "reset; loadf; go ${startaddr}" DELIM
"baudrate=" "115200" DELIM
"startaddr=" "0" DELIM
DELIM
@@ -423,35 +422,6 @@ int env_print(const MEMX char *name)
}
-command_ret_t do_env_print(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
- command_ret_t rc = CMD_RET_SUCCESS;
-
- (void) cmdtp; (void) flag;
-
- if (argc == 1) {
- /* print all env vars */
- int size = env_print(NULL);
- if (size < 0)
- return CMD_RET_FAILURE;
- printf_P(PSTR("\nEnvironment size: %d/%d bytes\n"),
- size, ENV_SIZE);
- return CMD_RET_SUCCESS;
- }
-
- /* print selected env vars */
- for (int i = 1; i < argc; ++i) {
- int rc = env_print(argv[i]);
- if (rc < 0) {
- printf_P(PSTR("## Error: \"%s\" not defined\n"), argv[i]);
- rc = CMD_RET_FAILURE;
- }
- }
-
- return rc;
-}
-
-
/**
* Set or delete environment variable
*
@@ -552,37 +522,47 @@ int setenv(const char *varname, const char *varvalue)
return (int) _do_env_set(0, argc, (char * const *)argv);
}
-#if 0
/**
* Set an environment variable to an integer value
*
- * @param varname Environment variable to set
- * @param value Value to set it to
+ * @param name Environment variable to set
+ * @param value Value to set it to
+ * @param radix Base
* @return 0 if ok, 1 on error
*/
-int setenv_ulong(const char *varname, unsigned long value)
+static
+int setenv_intval(const MEMX char *name, unsigned long value, int radix)
{
- /* TODO: this should be unsigned */
- char *str = simple_itoa(value);
+ char buf[11];
- return setenv(varname, str);
-}
-#endif
+ ultoa(value, buf, radix);
+ return setenv(name, buf);
+}
/**
- * Set an environment variable to an value in hex
+ * Set an environment variable to a decimal integer value
*
- * @param varname Environment variable to set
- * @param value Value to set it to
+ * @param name Environment variable to set
+ * @param value Value to set it to
* @return 0 if ok, 1 on error
*/
-int setenv_hex(const MEMX char *varname, unsigned long value)
+int setenv_ulong(const MEMX char *name, unsigned long value)
{
- char str[sizeof(unsigned long) *2 + 1];
+ return setenv_intval(name, value, 10);
+}
+
- sprintf_P(str, PSTR("%lx"), value);
- return setenv(varname, str);
+/**
+ * Set an environment variable to a value in hex
+ *
+ * @param name Environment variable to set
+ * @param value Value to set it to
+ * @return 0 if ok, 1 on error
+ */
+int setenv_hex(const MEMX char *name, unsigned long value)
+{
+ return setenv_intval(name, value, 16);
}
@@ -613,6 +593,35 @@ unsigned long getenv_ulong(const MEMX char *name, int base, unsigned long defaul
}
+command_ret_t do_env_print(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+ command_ret_t rc = CMD_RET_SUCCESS;
+
+ (void) cmdtp; (void) flag;
+
+ if (argc == 1) {
+ /* print all env vars */
+ int size = env_print(NULL);
+ if (size < 0)
+ return CMD_RET_FAILURE;
+ printf_P(PSTR("\nEnvironment size: %d/%d bytes\n"),
+ size, ENV_SIZE);
+ return CMD_RET_SUCCESS;
+ }
+
+ /* print selected env vars */
+ for (int i = 1; i < argc; ++i) {
+ int rc = env_print(argv[i]);
+ if (rc < 0) {
+ printf_P(PSTR("## Error: \"%s\" not defined\n"), argv[i]);
+ rc = CMD_RET_FAILURE;
+ }
+ }
+
+ return rc;
+}
+
+
command_ret_t do_env_set(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
(void) cmdtp;
diff --git a/avr/main.c b/avr/main.c
index a09f05c..e4c98b8 100644
--- a/avr/main.c
+++ b/avr/main.c
@@ -26,7 +26,7 @@ static uint8_t mcusr;
/*--------------------------------------------------------------------------*/
#if DEBUG
-__attribute__ ((naked)) __attribute__ ((section (".init3")))
+__attribute__ ((naked)) __attribute__ ((section (".init3")))
void preset_ram (void)
{
for (uint8_t *p = RAMSTART; p <= (uint8_t *) RAMEND; p++)
@@ -68,7 +68,7 @@ void setup_avr(void)
/* TODO: move to init section? */
mcusr = MCUSR;
MCUSR = 0;
-
+
/* WD */
/* CPU */
@@ -79,7 +79,7 @@ void setup_avr(void)
/* disable unused periphels */
PRR0 = _BV(PRTIM2) | _BV(PRTIM0) | _BV(PRADC);
- PRR1 = _BV(PRTIM5) | _BV(PRTIM4) | _BV(PRTIM3) |
+ PRR1 = _BV(PRTIM5) | _BV(PRTIM4) | _BV(PRTIM3) |
_BV(PRUSART3) | _BV(PRUSART2) | _BV(PRUSART1);
/* disable analog comparator */
@@ -111,7 +111,7 @@ static int stored_bootdelay;
/***************************************************************************
* Watch for 'delay' seconds for autoboot stop.
- * returns: 0 - no key, allow autoboot
+ * returns: 0 - no key, allow autoboot
* 1 - got key, abort
*/
@@ -207,7 +207,7 @@ int main(void)
if (reset_reason_is_power_on())
_delay_ms(CONFIG_PWRON_DELAY);
-
+
serial_setup(getenv_ulong(PSTR("baudrate"), 10, CONFIG_BAUDRATE));
sei();
@@ -215,7 +215,7 @@ int main(void)
debug("\n=========================< (RE)START DEBUG >=========================\n");
print_reset_reason();
#endif
-
+
#if DEBUG
unsigned long i_speed = getenv_ulong(PSTR("i2c_clock"), 10, CONFIG_SYS_I2C_CLOCK);
debug("### Setting I2C clock Frequency to %lu Hz.\n", i_speed);
@@ -225,6 +225,7 @@ int main(void)
#endif
printf_P(PSTR("\n(ATMEGA1281+HD64180)_stamp Tester\n"));
-
+
+
main_loop();
}