jtag: simplify management of non-implemented handlers

There is just a single entry point for the jtag API .khz(),
.speed_div(), .power_dropout(), .srst_asserted().

Simplify the code by in-lining the default handler.
The overall code behaviour is not changed.
This change prevents modifying at run-time the content of
struct jtag_interface.

Inspired from change http://openocd.zylin.com/943
by Evan Hunter <ehunter@broadcom.com>

Change-Id: I09aeb76d614db57b1884ac7ee9f00c152cd77849
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4892
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
This commit is contained in:
Antonio Borneo
2018-07-11 10:21:04 +02:00
committed by Tomas Vanek
parent 7cddeb0af2
commit e26910fdad
2 changed files with 29 additions and 48 deletions

View File

@@ -66,30 +66,6 @@ static int jim_adapter_name(Jim_Interp *interp, int argc, Jim_Obj * const *argv)
return JIM_OK;
}
static int default_khz(int khz, int *jtag_speed)
{
LOG_ERROR("Translation from khz to jtag_speed not implemented");
return ERROR_FAIL;
}
static int default_speed_div(int speed, int *khz)
{
LOG_ERROR("Translation from jtag_speed to khz not implemented");
return ERROR_FAIL;
}
static int default_power_dropout(int *dropout)
{
*dropout = 0; /* by default we can't detect power dropout */
return ERROR_OK;
}
static int default_srst_asserted(int *srst_asserted)
{
*srst_asserted = 0; /* by default we can't detect srst asserted */
return ERROR_OK;
}
COMMAND_HANDLER(interface_transport_command)
{
char **transports;
@@ -158,21 +134,8 @@ COMMAND_HANDLER(handle_interface_command)
LOG_WARNING("Adapter driver '%s' did not declare "
"which transports it allows; assuming "
"legacy JTAG-only", jtag_interface->name);
retval = allow_transports(CMD_CTX, jtag_interface->transports
return allow_transports(CMD_CTX, jtag_interface->transports
? jtag_interface->transports : jtag_only);
if (ERROR_OK != retval)
return retval;
if (jtag_interface->khz == NULL)
jtag_interface->khz = default_khz;
if (jtag_interface->speed_div == NULL)
jtag_interface->speed_div = default_speed_div;
if (jtag_interface->power_dropout == NULL)
jtag_interface->power_dropout = default_power_dropout;
if (jtag_interface->srst_asserted == NULL)
jtag_interface->srst_asserted = default_srst_asserted;
return ERROR_OK;
}
/* no valid interface was found (i.e. the configuration option,