adapter/jlink: Use COMMAND_PARSE_* instead of sscanf()
While at it, apply some coding style fixes. Change-Id: I77a6917a045af733ebe9211ca338952dbd49c89b Signed-off-by: Marc Schink <dev@zapb.de> Reviewed-on: https://review.openocd.org/c/openocd/+/8416 Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com> Tested-by: jenkins
This commit is contained in:
parent
2b6d63a44d
commit
fc0ec6cf0b
|
@ -961,23 +961,18 @@ static int jlink_reset_safe(int trst, int srst)
|
||||||
|
|
||||||
COMMAND_HANDLER(jlink_usb_command)
|
COMMAND_HANDLER(jlink_usb_command)
|
||||||
{
|
{
|
||||||
int tmp;
|
|
||||||
|
|
||||||
if (CMD_ARGC != 1)
|
if (CMD_ARGC != 1)
|
||||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||||
|
|
||||||
if (sscanf(CMD_ARGV[0], "%i", &tmp) != 1) {
|
unsigned int tmp;
|
||||||
command_print(CMD, "Invalid USB address: %s", CMD_ARGV[0]);
|
COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], tmp);
|
||||||
return ERROR_COMMAND_ARGUMENT_INVALID;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tmp < JAYLINK_USB_ADDRESS_0 || tmp > JAYLINK_USB_ADDRESS_3) {
|
if (tmp > JAYLINK_USB_ADDRESS_3) {
|
||||||
command_print(CMD, "Invalid USB address: %s", CMD_ARGV[0]);
|
command_print(CMD, "Invalid USB address: %s", CMD_ARGV[0]);
|
||||||
return ERROR_COMMAND_ARGUMENT_INVALID;
|
return ERROR_COMMAND_ARGUMENT_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
usb_address = tmp;
|
usb_address = tmp;
|
||||||
|
|
||||||
use_usb_address = true;
|
use_usb_address = true;
|
||||||
|
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
|
@ -1035,38 +1030,35 @@ COMMAND_HANDLER(jlink_handle_free_memory_command)
|
||||||
|
|
||||||
COMMAND_HANDLER(jlink_handle_jlink_jtag_command)
|
COMMAND_HANDLER(jlink_handle_jlink_jtag_command)
|
||||||
{
|
{
|
||||||
int tmp;
|
|
||||||
int version;
|
|
||||||
|
|
||||||
if (!CMD_ARGC) {
|
if (!CMD_ARGC) {
|
||||||
|
unsigned int version;
|
||||||
|
|
||||||
switch (jtag_command_version) {
|
switch (jtag_command_version) {
|
||||||
case JAYLINK_JTAG_VERSION_2:
|
case JAYLINK_JTAG_VERSION_2:
|
||||||
version = 2;
|
version = 2;
|
||||||
break;
|
break;
|
||||||
case JAYLINK_JTAG_VERSION_3:
|
case JAYLINK_JTAG_VERSION_3:
|
||||||
version = 3;
|
version = 3;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return ERROR_FAIL;
|
return ERROR_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
command_print(CMD, "JTAG command version: %i", version);
|
command_print(CMD, "JTAG command version: %u", version);
|
||||||
} else if (CMD_ARGC == 1) {
|
} else if (CMD_ARGC == 1) {
|
||||||
if (sscanf(CMD_ARGV[0], "%i", &tmp) != 1) {
|
uint8_t tmp;
|
||||||
command_print(CMD, "Invalid argument: %s", CMD_ARGV[0]);
|
COMMAND_PARSE_NUMBER(u8, CMD_ARGV[0], tmp);
|
||||||
return ERROR_COMMAND_ARGUMENT_INVALID;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (tmp) {
|
switch (tmp) {
|
||||||
case 2:
|
case 2:
|
||||||
jtag_command_version = JAYLINK_JTAG_VERSION_2;
|
jtag_command_version = JAYLINK_JTAG_VERSION_2;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
jtag_command_version = JAYLINK_JTAG_VERSION_3;
|
jtag_command_version = JAYLINK_JTAG_VERSION_3;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
command_print(CMD, "Invalid argument: %s", CMD_ARGV[0]);
|
command_print(CMD, "Invalid argument: %s", CMD_ARGV[0]);
|
||||||
return ERROR_COMMAND_ARGUMENT_INVALID;
|
return ERROR_COMMAND_ARGUMENT_INVALID;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||||
|
@ -1077,9 +1069,6 @@ COMMAND_HANDLER(jlink_handle_jlink_jtag_command)
|
||||||
|
|
||||||
COMMAND_HANDLER(jlink_handle_target_power_command)
|
COMMAND_HANDLER(jlink_handle_target_power_command)
|
||||||
{
|
{
|
||||||
int ret;
|
|
||||||
int enable;
|
|
||||||
|
|
||||||
if (CMD_ARGC != 1)
|
if (CMD_ARGC != 1)
|
||||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||||
|
|
||||||
|
@ -1089,16 +1078,10 @@ COMMAND_HANDLER(jlink_handle_target_power_command)
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp(CMD_ARGV[0], "on")) {
|
bool enable;
|
||||||
enable = true;
|
COMMAND_PARSE_ON_OFF(CMD_ARGV[0], enable);
|
||||||
} else if (!strcmp(CMD_ARGV[0], "off")) {
|
|
||||||
enable = false;
|
|
||||||
} else {
|
|
||||||
command_print(CMD, "Invalid argument: %s", CMD_ARGV[0]);
|
|
||||||
return ERROR_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = jaylink_set_target_power(devh, enable);
|
int ret = jaylink_set_target_power(devh, enable);
|
||||||
|
|
||||||
if (ret != JAYLINK_OK) {
|
if (ret != JAYLINK_OK) {
|
||||||
command_print(CMD, "jaylink_set_target_power() failed: %s",
|
command_print(CMD, "jaylink_set_target_power() failed: %s",
|
||||||
|
@ -1407,8 +1390,6 @@ static int config_trace(bool enabled, enum tpiu_pin_protocol pin_protocol,
|
||||||
|
|
||||||
COMMAND_HANDLER(jlink_handle_config_usb_address_command)
|
COMMAND_HANDLER(jlink_handle_config_usb_address_command)
|
||||||
{
|
{
|
||||||
uint8_t tmp;
|
|
||||||
|
|
||||||
if (!jaylink_has_cap(caps, JAYLINK_DEV_CAP_READ_CONFIG)) {
|
if (!jaylink_has_cap(caps, JAYLINK_DEV_CAP_READ_CONFIG)) {
|
||||||
command_print(CMD, "Reading configuration is not supported by the "
|
command_print(CMD, "Reading configuration is not supported by the "
|
||||||
"device");
|
"device");
|
||||||
|
@ -1418,10 +1399,8 @@ COMMAND_HANDLER(jlink_handle_config_usb_address_command)
|
||||||
if (!CMD_ARGC) {
|
if (!CMD_ARGC) {
|
||||||
show_config_usb_address(CMD);
|
show_config_usb_address(CMD);
|
||||||
} else if (CMD_ARGC == 1) {
|
} else if (CMD_ARGC == 1) {
|
||||||
if (sscanf(CMD_ARGV[0], "%" SCNd8, &tmp) != 1) {
|
uint8_t tmp;
|
||||||
command_print(CMD, "Invalid USB address: %s", CMD_ARGV[0]);
|
COMMAND_PARSE_NUMBER(u8, CMD_ARGV[0], tmp);
|
||||||
return ERROR_COMMAND_ARGUMENT_INVALID;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tmp > JAYLINK_USB_ADDRESS_3) {
|
if (tmp > JAYLINK_USB_ADDRESS_3) {
|
||||||
command_print(CMD, "Invalid USB address: %u", tmp);
|
command_print(CMD, "Invalid USB address: %u", tmp);
|
||||||
|
@ -1880,7 +1859,7 @@ static const struct command_registration jlink_subcommand_handlers[] = {
|
||||||
.handler = &jlink_handle_target_power_command,
|
.handler = &jlink_handle_target_power_command,
|
||||||
.mode = COMMAND_EXEC,
|
.mode = COMMAND_EXEC,
|
||||||
.help = "set the target power supply",
|
.help = "set the target power supply",
|
||||||
.usage = "<on|off>"
|
.usage = "<0|1|on|off>"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
.name = "freemem",
|
.name = "freemem",
|
||||||
|
|
Loading…
Reference in New Issue