svf: factorize big switch case

Factorize function svf_run_command() by moving out of the 'case'
the common code related to the label 'xxr_common'.

The target is to drop later on the ugly label 'xxr_common' inside
the switch.

Apart for:
- the function and local variables declaration,
- the added function call in place of original code,
- the reduced indentation in the new function,
this change is a dummy copy/paste with no code modification.

Change-Id: I8149cf25f460326ba6666a9287c5c309e5d99488
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/9040
Tested-by: jenkins
This commit is contained in:
Antonio Borneo
2025-06-29 23:43:11 +02:00
parent ad8d96230d
commit 1c668a0a6b

View File

@@ -979,121 +979,12 @@ static int svf_execute_tap(void)
return ERROR_OK; return ERROR_OK;
} }
static int svf_run_command(struct command_context *cmd_ctx, char *cmd_str) static int svf_xxr_common(char **argus, int num_of_argu, char command, struct svf_xxr_para *xxr_para_tmp)
{ {
char *argus[256], command; int i, i_tmp;
int num_of_argu = 0, i;
/* tmp variable */
int i_tmp;
/* for RUNTEST */
int run_count;
float min_time;
/* for XXR */
struct svf_xxr_para *xxr_para_tmp;
uint8_t **pbuffer_tmp; uint8_t **pbuffer_tmp;
struct scan_field field; struct scan_field field;
/* for STATE */
enum tap_state *path = NULL, state;
/* flag padding commands skipped due to -tap command */
int padding_command_skipped = 0;
if (svf_parse_cmd_string(cmd_str, strlen(cmd_str), argus, &num_of_argu) != ERROR_OK)
return ERROR_FAIL;
/* NOTE: we're a bit loose here, because we ignore case in
* TAP state names (instead of insisting on uppercase).
*/
command = svf_find_string_in_array(argus[0],
(char **)svf_command_name, ARRAY_SIZE(svf_command_name));
switch (command) {
case ENDDR:
case ENDIR:
if (num_of_argu != 2) {
LOG_ERROR("invalid parameter of %s", argus[0]);
return ERROR_FAIL;
}
i_tmp = tap_state_by_name(argus[1]);
if (svf_tap_state_is_stable(i_tmp)) {
if (command == ENDIR) {
svf_para.ir_end_state = i_tmp;
LOG_DEBUG("\tIR end_state = %s",
tap_state_name(i_tmp));
} else {
svf_para.dr_end_state = i_tmp;
LOG_DEBUG("\tDR end_state = %s",
tap_state_name(i_tmp));
}
} else {
LOG_ERROR("%s: %s is not a stable state",
argus[0], argus[1]);
return ERROR_FAIL;
}
break;
case FREQUENCY:
if (num_of_argu != 1 && num_of_argu != 3) {
LOG_ERROR("invalid parameter of %s", argus[0]);
return ERROR_FAIL;
}
if (num_of_argu == 1) {
/* TODO: set jtag speed to full speed */
svf_para.frequency = 0;
} else {
if (strcmp(argus[2], "HZ")) {
LOG_ERROR("HZ not found in FREQUENCY command");
return ERROR_FAIL;
}
if (svf_execute_tap() != ERROR_OK)
return ERROR_FAIL;
svf_para.frequency = atof(argus[1]);
/* TODO: set jtag speed to */
if (svf_para.frequency > 0) {
command_run_linef(cmd_ctx,
"adapter speed %d",
(int)svf_para.frequency / 1000);
LOG_DEBUG("\tfrequency = %f", svf_para.frequency);
}
}
break;
case HDR:
if (svf_tap_is_specified) {
padding_command_skipped = 1;
break;
}
xxr_para_tmp = &svf_para.hdr_para;
goto xxr_common;
case HIR:
if (svf_tap_is_specified) {
padding_command_skipped = 1;
break;
}
xxr_para_tmp = &svf_para.hir_para;
goto xxr_common;
case TDR:
if (svf_tap_is_specified) {
padding_command_skipped = 1;
break;
}
xxr_para_tmp = &svf_para.tdr_para;
goto xxr_common;
case TIR:
if (svf_tap_is_specified) {
padding_command_skipped = 1;
break;
}
xxr_para_tmp = &svf_para.tir_para;
goto xxr_common;
case SDR:
xxr_para_tmp = &svf_para.sdr_para;
goto xxr_common;
case SIR:
xxr_para_tmp = &svf_para.sir_para;
goto xxr_common;
xxr_common:
/* XXR length [TDI (tdi)] [TDO (tdo)][MASK (mask)] [SMASK (smask)] */ /* XXR length [TDI (tdi)] [TDO (tdo)][MASK (mask)] [SMASK (smask)] */
if (num_of_argu > 10 || (num_of_argu % 2)) { if (num_of_argu > 10 || (num_of_argu % 2)) {
LOG_ERROR("invalid parameter of %s", argus[0]); LOG_ERROR("invalid parameter of %s", argus[0]);
@@ -1373,6 +1264,126 @@ xxr_common:
svf_buffer_index += (i + 7) >> 3; svf_buffer_index += (i + 7) >> 3;
} }
return ERROR_OK;
}
static int svf_run_command(struct command_context *cmd_ctx, char *cmd_str)
{
char *argus[256], command;
int num_of_argu = 0, i, retval;
/* tmp variable */
int i_tmp;
/* for RUNTEST */
int run_count;
float min_time;
/* for XXR */
struct svf_xxr_para *xxr_para_tmp;
/* for STATE */
enum tap_state *path = NULL, state;
/* flag padding commands skipped due to -tap command */
int padding_command_skipped = 0;
if (svf_parse_cmd_string(cmd_str, strlen(cmd_str), argus, &num_of_argu) != ERROR_OK)
return ERROR_FAIL;
/* NOTE: we're a bit loose here, because we ignore case in
* TAP state names (instead of insisting on uppercase).
*/
command = svf_find_string_in_array(argus[0],
(char **)svf_command_name, ARRAY_SIZE(svf_command_name));
switch (command) {
case ENDDR:
case ENDIR:
if (num_of_argu != 2) {
LOG_ERROR("invalid parameter of %s", argus[0]);
return ERROR_FAIL;
}
i_tmp = tap_state_by_name(argus[1]);
if (svf_tap_state_is_stable(i_tmp)) {
if (command == ENDIR) {
svf_para.ir_end_state = i_tmp;
LOG_DEBUG("\tIR end_state = %s",
tap_state_name(i_tmp));
} else {
svf_para.dr_end_state = i_tmp;
LOG_DEBUG("\tDR end_state = %s",
tap_state_name(i_tmp));
}
} else {
LOG_ERROR("%s: %s is not a stable state",
argus[0], argus[1]);
return ERROR_FAIL;
}
break;
case FREQUENCY:
if (num_of_argu != 1 && num_of_argu != 3) {
LOG_ERROR("invalid parameter of %s", argus[0]);
return ERROR_FAIL;
}
if (num_of_argu == 1) {
/* TODO: set jtag speed to full speed */
svf_para.frequency = 0;
} else {
if (strcmp(argus[2], "HZ")) {
LOG_ERROR("HZ not found in FREQUENCY command");
return ERROR_FAIL;
}
if (svf_execute_tap() != ERROR_OK)
return ERROR_FAIL;
svf_para.frequency = atof(argus[1]);
/* TODO: set jtag speed to */
if (svf_para.frequency > 0) {
command_run_linef(cmd_ctx,
"adapter speed %d",
(int)svf_para.frequency / 1000);
LOG_DEBUG("\tfrequency = %f", svf_para.frequency);
}
}
break;
case HDR:
if (svf_tap_is_specified) {
padding_command_skipped = 1;
break;
}
xxr_para_tmp = &svf_para.hdr_para;
goto xxr_common;
case HIR:
if (svf_tap_is_specified) {
padding_command_skipped = 1;
break;
}
xxr_para_tmp = &svf_para.hir_para;
goto xxr_common;
case TDR:
if (svf_tap_is_specified) {
padding_command_skipped = 1;
break;
}
xxr_para_tmp = &svf_para.tdr_para;
goto xxr_common;
case TIR:
if (svf_tap_is_specified) {
padding_command_skipped = 1;
break;
}
xxr_para_tmp = &svf_para.tir_para;
goto xxr_common;
case SDR:
xxr_para_tmp = &svf_para.sdr_para;
goto xxr_common;
case SIR:
xxr_para_tmp = &svf_para.sir_para;
goto xxr_common;
xxr_common:
retval = svf_xxr_common(argus, num_of_argu, command, xxr_para_tmp);
if (retval != ERROR_OK)
return retval;
break; break;
case PIO: case PIO:
case PIOMAP: case PIOMAP: