diff options
author | Zachary T Welch <zw@superlucidity.net> | 2009-10-22 21:05:50 -0700 |
---|---|---|
committer | Zachary T Welch <zw@superlucidity.net> | 2009-11-05 18:03:18 -0800 |
commit | b7b561aae809ab9022b9f213dc5a12b6d58ce2ee (patch) | |
tree | 7385f125924a53e90e7ef5e636c7f74e83958fb8 /src | |
parent | f6f1dbfafdfac93d8f9a9540c71f011fac7611e0 (diff) | |
download | openocd_libswd-b7b561aae809ab9022b9f213dc5a12b6d58ce2ee.tar.gz openocd_libswd-b7b561aae809ab9022b9f213dc5a12b6d58ce2ee.tar.bz2 openocd_libswd-b7b561aae809ab9022b9f213dc5a12b6d58ce2ee.tar.xz openocd_libswd-b7b561aae809ab9022b9f213dc5a12b6d58ce2ee.zip |
Improve jtag command argument parsing.
Diffstat (limited to 'src')
-rw-r--r-- | src/jtag/amt_jtagaccel.c | 6 | ||||
-rw-r--r-- | src/jtag/ft2232.c | 8 | ||||
-rw-r--r-- | src/jtag/gw16012.c | 4 | ||||
-rw-r--r-- | src/jtag/parport.c | 4 | ||||
-rw-r--r-- | src/jtag/tcl.c | 40 | ||||
-rw-r--r-- | src/jtag/vsllink.c | 25 |
6 files changed, 36 insertions, 51 deletions
diff --git a/src/jtag/amt_jtagaccel.c b/src/jtag/amt_jtagaccel.c index b12aa763..e3f440cc 100644 --- a/src/jtag/amt_jtagaccel.c +++ b/src/jtag/amt_jtagaccel.c @@ -534,9 +534,9 @@ static int amt_jtagaccel_handle_parport_port_command( /* only if the port wasn't overwritten by cmdline */ if (amt_jtagaccel_port == 0) { - int retval = parse_u16(args[0], &amt_jtagaccel_port); - if (ERROR_OK != retval) - return retval; + uint16_t port; + COMMAND_PARSE_NUMBER(u16, args[0], port); + amt_jtagaccel_port = port; } else { diff --git a/src/jtag/ft2232.c b/src/jtag/ft2232.c index bd910b35..b3389cc8 100644 --- a/src/jtag/ft2232.c +++ b/src/jtag/ft2232.c @@ -2919,12 +2919,8 @@ static int ft2232_handle_vid_pid_command(struct command_context_s* cmd_ctx, char int retval = ERROR_OK; for (i = 0; i < argc; i += 2) { - retval = parse_u16(args[i], &ft2232_vid[i >> 1]); - if (ERROR_OK != retval) - break; - retval = parse_u16(args[i + 1], &ft2232_pid[i >> 1]); - if (ERROR_OK != retval) - break; + COMMAND_PARSE_NUMBER(u16, args[i], ft2232_vid[i >> 1]); + COMMAND_PARSE_NUMBER(u16, args[i + 1], ft2232_pid[i >> 1]); } /* diff --git a/src/jtag/gw16012.c b/src/jtag/gw16012.c index 46635d07..4b0ffd73 100644 --- a/src/jtag/gw16012.c +++ b/src/jtag/gw16012.c @@ -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 */ if (gw16012_port == 0) { - int retval = parse_u16(args[0], &gw16012_port); - if (ERROR_OK != retval) - return retval; + COMMAND_PARSE_NUMBER(u16, args[0], gw16012_port); } else { diff --git a/src/jtag/parport.c b/src/jtag/parport.c index 41e02475..12a5eea5 100644 --- a/src/jtag/parport.c +++ b/src/jtag/parport.c @@ -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 */ if (parport_port == 0) { - int retval = parse_u16(args[0], &parport_port); - if (ERROR_OK != retval) - return retval; + COMMAND_PARSE_NUMBER(u16, args[0], parport_port); } else { diff --git a/src/jtag/tcl.c b/src/jtag/tcl.c index 5056a5c5..c064a825 100644 --- a/src/jtag/tcl.c +++ b/src/jtag/tcl.c @@ -1050,9 +1050,8 @@ static int handle_jtag_nsrst_delay_command(struct command_context_s *cmd_ctx, if (argc == 1) { unsigned delay; - int retval = parse_uint(args[0], &delay); - if (ERROR_OK != retval) - return retval; + COMMAND_PARSE_NUMBER(uint, args[0], delay); + jtag_set_nsrst_delay(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) { unsigned delay; - int retval = parse_uint(args[0], &delay); - if (ERROR_OK != retval) - return retval; + COMMAND_PARSE_NUMBER(uint, args[0], delay); + jtag_set_ntrst_delay(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) { unsigned delay; - int retval = parse_uint(args[0], &delay); - if (ERROR_OK != retval) - return retval; + COMMAND_PARSE_NUMBER(uint, args[0], delay); + jtag_set_nsrst_assert_width(delay); } 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) { unsigned delay; - int retval = parse_uint(args[0], &delay); - if (ERROR_OK != retval) - return retval; + COMMAND_PARSE_NUMBER(uint, args[0], delay); + jtag_set_ntrst_assert_width(delay); } 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"); unsigned cur_speed = 0; - int retval = parse_uint(args[0], &cur_speed); - if (ERROR_OK != retval) - return retval; - retval = jtag_config_speed(cur_speed); + COMMAND_PARSE_NUMBER(uint, args[0], cur_speed); + retval = jtag_config_speed(cur_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) { unsigned khz = 0; - int retval = parse_uint(args[0], &khz); - if (ERROR_OK != retval) - return retval; + COMMAND_PARSE_NUMBER(uint, args[0], khz); + retval = jtag_config_khz(khz); if (ERROR_OK != retval) return retval; @@ -1174,9 +1167,8 @@ static int handle_jtag_rclk_command(struct command_context_s *cmd_ctx, char *cmd if (argc == 1) { unsigned khz = 0; - int retval = parse_uint(args[0], &khz); - if (ERROR_OK != retval) - return retval; + COMMAND_PARSE_NUMBER(uint, args[0], khz); + retval = jtag_config_rclk(khz); if (ERROR_OK != retval) return retval; @@ -1231,9 +1223,7 @@ static int handle_runtest_command(struct command_context_s *cmd_ctx, return ERROR_COMMAND_SYNTAX_ERROR; unsigned num_clocks; - int retval = parse_uint(args[0], &num_clocks); - if (ERROR_OK != retval) - return retval; + COMMAND_PARSE_NUMBER(uint, args[0], num_clocks); jtag_add_runtest(num_clocks, TAP_IDLE); return jtag_execute_queue(); diff --git a/src/jtag/vsllink.c b/src/jtag/vsllink.c index ab55a190..1f1b8670 100644 --- a/src/jtag/vsllink.c +++ b/src/jtag/vsllink.c @@ -1407,7 +1407,8 @@ static int vsllink_handle_usb_vid_command(struct command_context_s *cmd_ctx, cha 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) @@ -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"); 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) @@ -1428,11 +1430,11 @@ static int vsllink_handle_usb_bulkin_command(struct command_context_s *cmd_ctx, return ERROR_OK; } - int retval = parse_u8(args[0], &vsllink_usb_bulkin); - if (ERROR_OK == retval) - vsllink_usb_bulkin |= 0x80; + COMMAND_PARSE_NUMBER(u8, args[0], vsllink_usb_bulkin); - 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) @@ -1443,11 +1445,11 @@ static int vsllink_handle_usb_bulkout_command(struct command_context_s *cmd_ctx, return ERROR_OK; } - int retval = parse_u8(args[0], &vsllink_usb_bulkout); - if (ERROR_OK == retval) - vsllink_usb_bulkout &= ~0x80; + COMMAND_PARSE_NUMBER(u8, args[0], vsllink_usb_bulkin); - 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) @@ -1458,7 +1460,8 @@ static int vsllink_handle_usb_interface_command(struct command_context_s *cmd_ct return ERROR_OK; } - return parse_u8(args[0], &vsllink_usb_interface); + COMMAND_PARSE_NUMBER(u8, args[0], vsllink_usb_interface); + return ERROR_OK; } /***************************************************************************/ |