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__archive__
parent
5f4ecc60a9
commit
e8febc2255
|
@ -103,7 +103,7 @@ static int speed_khz = 0;
|
|||
static bool hasKHz = false;
|
||||
static int jtag_speed = 0;
|
||||
|
||||
struct jtag_interface_s *jtag = NULL;
|
||||
static struct jtag_interface_s *jtag = NULL;
|
||||
|
||||
/* configuration */
|
||||
jtag_interface_t *jtag_interface = NULL;
|
||||
|
@ -1178,6 +1178,27 @@ unsigned jtag_get_speed_khz(void)
|
|||
{
|
||||
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)
|
||||
{
|
||||
return jtag_speed;
|
||||
|
@ -1192,6 +1213,12 @@ int jtag_set_speed(int speed)
|
|||
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)
|
||||
{
|
||||
jtag_verify = enable;
|
||||
|
|
|
@ -269,6 +269,14 @@ extern int jtag_call_event_callbacks(enum jtag_event event);
|
|||
|
||||
/// @returns The current JTAG speed setting.
|
||||
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
|
||||
* 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);
|
||||
unsigned jtag_get_ntrst_delay(void);
|
||||
|
||||
int jtag_config_khz(unsigned khz);
|
||||
void jtag_set_speed_khz(unsigned speed);
|
||||
unsigned jtag_get_speed_khz(void);
|
||||
|
||||
|
|
|
@ -170,7 +170,6 @@ jtag_interface_t *jtag_interfaces[] = {
|
|||
NULL,
|
||||
};
|
||||
|
||||
extern struct jtag_interface_s *jtag;
|
||||
extern jtag_interface_t *jtag_interface;
|
||||
|
||||
/* 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;
|
||||
|
||||
int retval = ERROR_OK;
|
||||
int cur_speed = 0;
|
||||
if (argc == 1)
|
||||
{
|
||||
LOG_DEBUG("handle jtag khz");
|
||||
|
||||
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);
|
||||
retval = jtag_config_khz(strtoul(args[0], NULL, 0));
|
||||
if (ERROR_OK != retval)
|
||||
return retval;
|
||||
}
|
||||
|
||||
int cur_speed;
|
||||
retval = jtag_get_speed_readable(&cur_speed);
|
||||
if (ERROR_OK != retval)
|
||||
return retval;
|
||||
|
||||
if (cur_speed)
|
||||
command_print(cmd_ctx, "%d kHz", cur_speed);
|
||||
else
|
||||
command_print(cmd_ctx, "RCLK - adaptive");
|
||||
return retval;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
static int handle_jtag_reset_command(struct command_context_s *cmd_ctx,
|
||||
|
|
Loading…
Reference in New Issue