Improve jtag command argument parsing.

This commit is contained in:
Zachary T Welch 2009-10-22 21:05:50 -07:00
parent f6f1dbfafd
commit b7b561aae8
6 changed files with 36 additions and 51 deletions

View File

@ -534,9 +534,9 @@ static int amt_jtagaccel_handle_parport_port_command(
/* only if the port wasn't overwritten by cmdline */ /* only if the port wasn't overwritten by cmdline */
if (amt_jtagaccel_port == 0) if (amt_jtagaccel_port == 0)
{ {
int retval = parse_u16(args[0], &amt_jtagaccel_port); uint16_t port;
if (ERROR_OK != retval) COMMAND_PARSE_NUMBER(u16, args[0], port);
return retval; amt_jtagaccel_port = port;
} }
else else
{ {

View File

@ -2919,12 +2919,8 @@ static int ft2232_handle_vid_pid_command(struct command_context_s* cmd_ctx, char
int retval = ERROR_OK; int retval = ERROR_OK;
for (i = 0; i < argc; i += 2) for (i = 0; i < argc; i += 2)
{ {
retval = parse_u16(args[i], &ft2232_vid[i >> 1]); COMMAND_PARSE_NUMBER(u16, args[i], ft2232_vid[i >> 1]);
if (ERROR_OK != retval) COMMAND_PARSE_NUMBER(u16, args[i + 1], ft2232_pid[i >> 1]);
break;
retval = parse_u16(args[i + 1], &ft2232_pid[i >> 1]);
if (ERROR_OK != retval)
break;
} }
/* /*

View File

@ -576,9 +576,7 @@ static int gw16012_handle_parport_port_command(struct command_context_s *cmd_ctx
/* only if the port wasn't overwritten by cmdline */ /* only if the port wasn't overwritten by cmdline */
if (gw16012_port == 0) if (gw16012_port == 0)
{ {
int retval = parse_u16(args[0], &gw16012_port); COMMAND_PARSE_NUMBER(u16, args[0], gw16012_port);
if (ERROR_OK != retval)
return retval;
} }
else else
{ {

View File

@ -435,9 +435,7 @@ static int parport_handle_parport_port_command(struct command_context_s *cmd_ctx
/* only if the port wasn't overwritten by cmdline */ /* only if the port wasn't overwritten by cmdline */
if (parport_port == 0) if (parport_port == 0)
{ {
int retval = parse_u16(args[0], &parport_port); COMMAND_PARSE_NUMBER(u16, args[0], parport_port);
if (ERROR_OK != retval)
return retval;
} }
else else
{ {

View File

@ -1050,9 +1050,8 @@ static int handle_jtag_nsrst_delay_command(struct command_context_s *cmd_ctx,
if (argc == 1) if (argc == 1)
{ {
unsigned delay; unsigned delay;
int retval = parse_uint(args[0], &delay); COMMAND_PARSE_NUMBER(uint, args[0], delay);
if (ERROR_OK != retval)
return retval;
jtag_set_nsrst_delay(delay); jtag_set_nsrst_delay(delay);
} }
command_print(cmd_ctx, "jtag_nsrst_delay: %u", jtag_get_nsrst_delay()); command_print(cmd_ctx, "jtag_nsrst_delay: %u", jtag_get_nsrst_delay());
@ -1067,9 +1066,8 @@ static int handle_jtag_ntrst_delay_command(struct command_context_s *cmd_ctx,
if (argc == 1) if (argc == 1)
{ {
unsigned delay; unsigned delay;
int retval = parse_uint(args[0], &delay); COMMAND_PARSE_NUMBER(uint, args[0], delay);
if (ERROR_OK != retval)
return retval;
jtag_set_ntrst_delay(delay); jtag_set_ntrst_delay(delay);
} }
command_print(cmd_ctx, "jtag_ntrst_delay: %u", jtag_get_ntrst_delay()); command_print(cmd_ctx, "jtag_ntrst_delay: %u", jtag_get_ntrst_delay());
@ -1084,9 +1082,8 @@ static int handle_jtag_nsrst_assert_width_command(struct command_context_s *cmd_
if (argc == 1) if (argc == 1)
{ {
unsigned delay; unsigned delay;
int retval = parse_uint(args[0], &delay); COMMAND_PARSE_NUMBER(uint, args[0], delay);
if (ERROR_OK != retval)
return retval;
jtag_set_nsrst_assert_width(delay); jtag_set_nsrst_assert_width(delay);
} }
command_print(cmd_ctx, "jtag_nsrst_assert_width: %u", jtag_get_nsrst_assert_width()); command_print(cmd_ctx, "jtag_nsrst_assert_width: %u", jtag_get_nsrst_assert_width());
@ -1101,9 +1098,8 @@ static int handle_jtag_ntrst_assert_width_command(struct command_context_s *cmd_
if (argc == 1) if (argc == 1)
{ {
unsigned delay; unsigned delay;
int retval = parse_uint(args[0], &delay); COMMAND_PARSE_NUMBER(uint, args[0], delay);
if (ERROR_OK != retval)
return retval;
jtag_set_ntrst_assert_width(delay); jtag_set_ntrst_assert_width(delay);
} }
command_print(cmd_ctx, "jtag_ntrst_assert_width: %u", jtag_get_ntrst_assert_width()); command_print(cmd_ctx, "jtag_ntrst_assert_width: %u", jtag_get_ntrst_assert_width());
@ -1124,11 +1120,9 @@ static int handle_jtag_speed_command(struct command_context_s *cmd_ctx, char *cm
LOG_DEBUG("handle jtag speed"); LOG_DEBUG("handle jtag speed");
unsigned cur_speed = 0; unsigned cur_speed = 0;
int retval = parse_uint(args[0], &cur_speed); COMMAND_PARSE_NUMBER(uint, args[0], cur_speed);
if (ERROR_OK != retval)
return retval;
retval = jtag_config_speed(cur_speed);
retval = jtag_config_speed(cur_speed);
} }
command_print(cmd_ctx, "jtag_speed: %d", jtag_get_speed()); command_print(cmd_ctx, "jtag_speed: %d", jtag_get_speed());
@ -1144,9 +1138,8 @@ static int handle_jtag_khz_command(struct command_context_s *cmd_ctx, char *cmd,
if (argc == 1) if (argc == 1)
{ {
unsigned khz = 0; unsigned khz = 0;
int retval = parse_uint(args[0], &khz); COMMAND_PARSE_NUMBER(uint, args[0], khz);
if (ERROR_OK != retval)
return retval;
retval = jtag_config_khz(khz); retval = jtag_config_khz(khz);
if (ERROR_OK != retval) if (ERROR_OK != retval)
return retval; return retval;
@ -1174,9 +1167,8 @@ static int handle_jtag_rclk_command(struct command_context_s *cmd_ctx, char *cmd
if (argc == 1) if (argc == 1)
{ {
unsigned khz = 0; unsigned khz = 0;
int retval = parse_uint(args[0], &khz); COMMAND_PARSE_NUMBER(uint, args[0], khz);
if (ERROR_OK != retval)
return retval;
retval = jtag_config_rclk(khz); retval = jtag_config_rclk(khz);
if (ERROR_OK != retval) if (ERROR_OK != retval)
return retval; return retval;
@ -1231,9 +1223,7 @@ static int handle_runtest_command(struct command_context_s *cmd_ctx,
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
unsigned num_clocks; unsigned num_clocks;
int retval = parse_uint(args[0], &num_clocks); COMMAND_PARSE_NUMBER(uint, args[0], num_clocks);
if (ERROR_OK != retval)
return retval;
jtag_add_runtest(num_clocks, TAP_IDLE); jtag_add_runtest(num_clocks, TAP_IDLE);
return jtag_execute_queue(); return jtag_execute_queue();

View File

@ -1407,7 +1407,8 @@ static int vsllink_handle_usb_vid_command(struct command_context_s *cmd_ctx, cha
return ERROR_OK; return ERROR_OK;
} }
return parse_u16(args[0], &vsllink_usb_vid); COMMAND_PARSE_NUMBER(u16, args[0], vsllink_usb_vid);
return ERROR_OK;
} }
static int vsllink_handle_usb_pid_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) static int vsllink_handle_usb_pid_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
@ -1417,7 +1418,8 @@ static int vsllink_handle_usb_pid_command(struct command_context_s *cmd_ctx, cha
LOG_ERROR("parameter error, should be one parameter for PID"); LOG_ERROR("parameter error, should be one parameter for PID");
return ERROR_OK; return ERROR_OK;
} }
return parse_u16(args[0], &vsllink_usb_pid); COMMAND_PARSE_NUMBER(u16, args[0], vsllink_usb_pid);
return ERROR_OK;
} }
static int vsllink_handle_usb_bulkin_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) static int vsllink_handle_usb_bulkin_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
@ -1428,11 +1430,11 @@ static int vsllink_handle_usb_bulkin_command(struct command_context_s *cmd_ctx,
return ERROR_OK; return ERROR_OK;
} }
int retval = parse_u8(args[0], &vsllink_usb_bulkin); COMMAND_PARSE_NUMBER(u8, args[0], vsllink_usb_bulkin);
if (ERROR_OK == retval)
vsllink_usb_bulkin |= 0x80;
return retval; vsllink_usb_bulkin |= 0x80;
return ERROR_OK;
} }
static int vsllink_handle_usb_bulkout_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) static int vsllink_handle_usb_bulkout_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
@ -1443,11 +1445,11 @@ static int vsllink_handle_usb_bulkout_command(struct command_context_s *cmd_ctx,
return ERROR_OK; return ERROR_OK;
} }
int retval = parse_u8(args[0], &vsllink_usb_bulkout); COMMAND_PARSE_NUMBER(u8, args[0], vsllink_usb_bulkin);
if (ERROR_OK == retval)
vsllink_usb_bulkout &= ~0x80;
return retval; vsllink_usb_bulkout &= ~0x80;
return ERROR_OK;
} }
static int vsllink_handle_usb_interface_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) static int vsllink_handle_usb_interface_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
@ -1458,7 +1460,8 @@ static int vsllink_handle_usb_interface_command(struct command_context_s *cmd_ct
return ERROR_OK; return ERROR_OK;
} }
return parse_u8(args[0], &vsllink_usb_interface); COMMAND_PARSE_NUMBER(u8, args[0], vsllink_usb_interface);
return ERROR_OK;
} }
/***************************************************************************/ /***************************************************************************/