Encapsulate the core jtag interface pointer:
- Add new jtag_config_khz to increase encapsulation of jtag->khz call. - Add new jtag_get_speed_readable to encapsulate of jtag->speed_div call. - Make definition of jtag static in core.c, remove extern from tcl.c. git-svn-id: svn://svn.berlios.de/openocd/trunk@2171 b42882b7-edfa-0310-969c-e2dbd0fdcd60
This commit is contained in:
parent
5f4ecc60a9
commit
e8febc2255
|
@ -103,7 +103,7 @@ static int speed_khz = 0;
|
||||||
static bool hasKHz = false;
|
static bool hasKHz = false;
|
||||||
static int jtag_speed = 0;
|
static int jtag_speed = 0;
|
||||||
|
|
||||||
struct jtag_interface_s *jtag = NULL;
|
static struct jtag_interface_s *jtag = NULL;
|
||||||
|
|
||||||
/* configuration */
|
/* configuration */
|
||||||
jtag_interface_t *jtag_interface = NULL;
|
jtag_interface_t *jtag_interface = NULL;
|
||||||
|
@ -1178,6 +1178,27 @@ unsigned jtag_get_speed_khz(void)
|
||||||
{
|
{
|
||||||
return speed_khz;
|
return speed_khz;
|
||||||
}
|
}
|
||||||
|
int jtag_config_khz(unsigned khz)
|
||||||
|
{
|
||||||
|
LOG_DEBUG("handle jtag khz");
|
||||||
|
jtag_set_speed_khz(khz);
|
||||||
|
|
||||||
|
int cur_speed = 0;
|
||||||
|
if (jtag != NULL)
|
||||||
|
{
|
||||||
|
LOG_DEBUG("have interface set up");
|
||||||
|
int speed_div1;
|
||||||
|
int retval = jtag->khz(jtag_get_speed_khz(), &speed_div1);
|
||||||
|
if (ERROR_OK != retval)
|
||||||
|
{
|
||||||
|
jtag_set_speed_khz(0);
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
cur_speed = speed_div1;
|
||||||
|
}
|
||||||
|
return jtag_set_speed(cur_speed);
|
||||||
|
}
|
||||||
|
|
||||||
int jtag_get_speed(void)
|
int jtag_get_speed(void)
|
||||||
{
|
{
|
||||||
return jtag_speed;
|
return jtag_speed;
|
||||||
|
@ -1192,6 +1213,12 @@ int jtag_set_speed(int speed)
|
||||||
return jtag ? jtag->speed(speed) : ERROR_OK;
|
return jtag ? jtag->speed(speed) : ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int jtag_get_speed_readable(int *speed)
|
||||||
|
{
|
||||||
|
return jtag ? jtag->speed_div(jtag_get_speed(), speed) : ERROR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void jtag_set_verify(bool enable)
|
void jtag_set_verify(bool enable)
|
||||||
{
|
{
|
||||||
jtag_verify = enable;
|
jtag_verify = enable;
|
||||||
|
|
|
@ -269,6 +269,14 @@ extern int jtag_call_event_callbacks(enum jtag_event event);
|
||||||
|
|
||||||
/// @returns The current JTAG speed setting.
|
/// @returns The current JTAG speed setting.
|
||||||
int jtag_get_speed(void);
|
int jtag_get_speed(void);
|
||||||
|
/**
|
||||||
|
* Given a @a speed setting, use the interface @c speed_div callback to
|
||||||
|
* adjust the setting.
|
||||||
|
* @param speed The speed setting to convert back to readable KHz.
|
||||||
|
* @returns ERROR_OK if the interface has not been initialized or on success;
|
||||||
|
* otherwise, the error code produced by the @c speed_div callback.
|
||||||
|
*/
|
||||||
|
int jtag_get_speed_readable(int *speed);
|
||||||
/**
|
/**
|
||||||
* Set the JTAG speed. This routine will call the underlying
|
* Set the JTAG speed. This routine will call the underlying
|
||||||
* interface @c speed callback, if the interface has been initialized.
|
* interface @c speed callback, if the interface has been initialized.
|
||||||
|
@ -708,6 +716,7 @@ unsigned jtag_get_nsrst_delay(void);
|
||||||
void jtag_set_ntrst_delay(unsigned delay);
|
void jtag_set_ntrst_delay(unsigned delay);
|
||||||
unsigned jtag_get_ntrst_delay(void);
|
unsigned jtag_get_ntrst_delay(void);
|
||||||
|
|
||||||
|
int jtag_config_khz(unsigned khz);
|
||||||
void jtag_set_speed_khz(unsigned speed);
|
void jtag_set_speed_khz(unsigned speed);
|
||||||
unsigned jtag_get_speed_khz(void);
|
unsigned jtag_get_speed_khz(void);
|
||||||
|
|
||||||
|
|
|
@ -170,7 +170,6 @@ jtag_interface_t *jtag_interfaces[] = {
|
||||||
NULL,
|
NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct jtag_interface_s *jtag;
|
|
||||||
extern jtag_interface_t *jtag_interface;
|
extern jtag_interface_t *jtag_interface;
|
||||||
|
|
||||||
/* jtag commands */
|
/* jtag commands */
|
||||||
|
@ -1012,41 +1011,24 @@ static int handle_jtag_khz_command(struct command_context_s *cmd_ctx, char *cmd,
|
||||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||||
|
|
||||||
int retval = ERROR_OK;
|
int retval = ERROR_OK;
|
||||||
int cur_speed = 0;
|
|
||||||
if (argc == 1)
|
if (argc == 1)
|
||||||
{
|
{
|
||||||
LOG_DEBUG("handle jtag khz");
|
retval = jtag_config_khz(strtoul(args[0], NULL, 0));
|
||||||
|
|
||||||
jtag_set_speed_khz(strtoul(args[0], NULL, 0));
|
|
||||||
if (jtag != NULL)
|
|
||||||
{
|
|
||||||
LOG_DEBUG("have interface set up");
|
|
||||||
int speed_div1;
|
|
||||||
retval = jtag->khz(jtag_get_speed_khz(), &speed_div1);
|
|
||||||
if (ERROR_OK != retval)
|
|
||||||
{
|
|
||||||
jtag_set_speed_khz(0);
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
cur_speed = speed_div1;
|
|
||||||
}
|
|
||||||
retval = jtag_set_speed(cur_speed);
|
|
||||||
}
|
|
||||||
|
|
||||||
cur_speed = jtag_get_speed_khz();
|
|
||||||
if (jtag != NULL)
|
|
||||||
{
|
|
||||||
retval = jtag->speed_div(jtag_get_speed(), &cur_speed);
|
|
||||||
if (ERROR_OK != retval)
|
if (ERROR_OK != retval)
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int cur_speed;
|
||||||
|
retval = jtag_get_speed_readable(&cur_speed);
|
||||||
|
if (ERROR_OK != retval)
|
||||||
|
return retval;
|
||||||
|
|
||||||
if (cur_speed)
|
if (cur_speed)
|
||||||
command_print(cmd_ctx, "%d kHz", cur_speed);
|
command_print(cmd_ctx, "%d kHz", cur_speed);
|
||||||
else
|
else
|
||||||
command_print(cmd_ctx, "RCLK - adaptive");
|
command_print(cmd_ctx, "RCLK - adaptive");
|
||||||
return retval;
|
|
||||||
|
|
||||||
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int handle_jtag_reset_command(struct command_context_s *cmd_ctx,
|
static int handle_jtag_reset_command(struct command_context_s *cmd_ctx,
|
||||||
|
|
Loading…
Reference in New Issue