create urj_tap_chain_connect() and urj_bus_init() by factoring cmd_cable() and cmd_initbus() respectively.

New routines present a more convenient API for use by C and language bindings.

Patch by Steve Tell.


git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@1919 b68d4a1b-bc3d-0410-92ed-d4ac073336b7
master
Mike Frysinger 14 years ago
parent 0604c8bd7d
commit c3d25af7a9

@ -4,6 +4,13 @@
for some useful command related functions to the public cmd.h header.
In the process, constify the array passed into urj_cmd_params.
* include/urjtag/bus.h, src/bus/buses.c, src/cmd/cmd_initbus.c: Pull the
guts of cmd_initbus_run() out into a new helper func named
urj_bus_init(). Patch by Steve Tell.
* include/urjtag/chain.h, src/cmd/cmd_cable.c, src/tap/chain.c: Pull the
guts of cmd_cable_run() out into a new helper func named
urj_tap_chain_connect(). Patch by Steve Tell.
2011-06-25 Mike Frysinger <vapier@gentoo.org>
* src/cmd/cmd_initbus.c: Drop useless double const keywords.

@ -52,10 +52,24 @@ void urj_bus_buses_free (void);
int urj_bus_buses_add (urj_bus_t *abus);
int urj_bus_buses_delete (urj_bus_t *abus);
/** set active bus
/**
* set active bus
*
* @param n choose n'th bus in #urj_buses as the active bus
*
* @return URJ_STATUS_OK on success; URJ_STATUS_FAIL on error
*/
int urj_bus_buses_set (int n);
/**
* Initialize the specified bus.
*
* @param chain jtag chain object
* @param drivername name of bus driver
* @param params additional driver-specific parameters
*
* @return URJ_STATUS_OK on success; URJ_STATUS_FAIL on error
*/
int urj_bus_init (urj_chain_t *chain, const char *drivername, char *params[]);
#endif /* URJ_BUS_H */

@ -49,6 +49,16 @@ struct URJ_CHAIN
urj_chain_t *urj_tap_chain_alloc (void);
void urj_tap_chain_free (urj_chain_t *chain);
/**
* Connect the chain to the specified cable.
*
* @param chain chain object to connect
* @param drivername name of cable driver
* @param params additional driver-specific parameters
*
* @return URJ_STATUS_OK on success; URJ_STATUS_FAIL on error
*/
int urj_tap_chain_connect (urj_chain_t *chain, const char *drivername, char *params[]);
void urj_tap_chain_disconnect (urj_chain_t *chain);
/** @return URJ_STATUS_OK on success; URJ_STATUS_FAIL on error */
int urj_tap_chain_clock (urj_chain_t *chain, int tms, int tdi, int n);

@ -32,6 +32,7 @@
#include <urjtag/bus.h>
#include <urjtag/chain.h>
#include <urjtag/part.h>
#include <urjtag/cmd.h>
#include "buses.h"
@ -141,6 +142,47 @@ urj_bus_buses_set (int n)
return URJ_STATUS_OK;
}
int
urj_bus_init (urj_chain_t *chain, const char *drivername, char *params[])
{
int drv, i;
const urj_param_t **bus_params;
if (urj_cmd_test_cable (chain) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
if (urj_tap_chain_active_part (chain) == NULL)
return URJ_STATUS_FAIL;
for (drv = 0; urj_bus_drivers[drv] != NULL; drv++)
if (strcasecmp (urj_bus_drivers[drv]->name, drivername) == 0)
break;
if (urj_bus_drivers[drv] == NULL)
{
urj_error_set (URJ_ERROR_NOTFOUND, "Unknown bus: %s", drivername);
return URJ_STATUS_FAIL;
}
urj_param_init (&bus_params);
for (i = 0; params[i] != NULL; i++)
if (urj_param_push (&urj_bus_param_list, &bus_params,
params[i]) != URJ_STATUS_OK)
{
urj_param_clear (&bus_params);
return URJ_STATUS_FAIL;
}
if (urj_bus_init_bus (chain, urj_bus_drivers[drv], bus_params) == NULL)
{
urj_param_clear (&bus_params);
return URJ_STATUS_FAIL;
}
urj_param_clear (&bus_params);
return URJ_STATUS_OK;
}
urj_bus_t *
urj_bus_init_bus (urj_chain_t *chain, const urj_bus_driver_t *bus_driver,
const urj_param_t *param[])

@ -48,15 +48,8 @@ cable_probe (char *params[])
static int
cmd_cable_run (urj_chain_t *chain, char *params[])
{
urj_cable_t *cable = NULL;
int i;
int j;
int paramc = urj_cmd_params (params);
const urj_param_t **cable_params;
urj_cable_parport_devtype_t devtype = -1;
const char *devname = NULL;
int param_start = 2;
const urj_cable_driver_t *driver;
/* we need at least one parameter for 'cable' command */
if (paramc < 2)
@ -102,78 +95,7 @@ cmd_cable_run (urj_chain_t *chain, char *params[])
}
}
/* search cable driver list */
for (i = 0; urj_tap_cable_drivers[i]; i++)
if (strcasecmp (params[1], urj_tap_cable_drivers[i]->name) == 0)
break;
driver = urj_tap_cable_drivers[i];
if (!driver)
{
urj_error_set (URJ_ERROR_NOTFOUND, _("Unknown cable type: '%s'"),
params[1]);
return URJ_STATUS_FAIL;
}
if (paramc >= 3 && strcasecmp (params[2], "help") == 0)
{
driver->help (URJ_LOG_LEVEL_NORMAL, driver->name);
return URJ_STATUS_OK;
}
if (driver->device_type == URJ_CABLE_DEVICE_PARPORT)
{
if (paramc < 4)
{
urj_error_set (URJ_ERROR_SYNTAX,
"parallel cable requires >= 4 parameters");
return URJ_STATUS_FAIL;
}
for (j = 0; j < URJ_CABLE_PARPORT_N_DEVS; j++)
if (strcasecmp (params[2],
urj_cable_parport_devtype_string(j)) == 0)
break;
if (j == URJ_CABLE_PARPORT_N_DEVS)
{
urj_error_set (URJ_ERROR_INVALID,
"unknown parallel port device type '%s'", params[2]);
return URJ_STATUS_FAIL;
}
devtype = j;
devname = params[3];
param_start = 4;
}
urj_param_init (&cable_params);
for (j = param_start; params[j] != NULL; j++)
if (urj_param_push (&urj_cable_param_list, &cable_params,
params[j]) != URJ_STATUS_OK)
{
urj_param_clear (&cable_params);
return URJ_STATUS_FAIL;
}
switch (driver->device_type)
{
case URJ_CABLE_DEVICE_PARPORT:
cable = urj_tap_cable_parport_connect (chain, driver, devtype, devname,
cable_params);
break;
case URJ_CABLE_DEVICE_USB:
cable = urj_tap_cable_usb_connect (chain, driver, cable_params);
break;
case URJ_CABLE_DEVICE_OTHER:
cable = urj_tap_cable_other_connect (chain, driver, cable_params);
break;
}
urj_param_clear (&cable_params);
if (cable == NULL)
return URJ_STATUS_FAIL;
chain->cable->chain = chain;
return URJ_STATUS_OK;
return urj_tap_chain_connect (chain, params[1], &params[2]);
}
static void

@ -40,9 +40,6 @@
static int
cmd_initbus_run (urj_chain_t *chain, char *params[])
{
int drv, i;
const urj_param_t **bus_params;
if (urj_cmd_params (params) < 2)
{
urj_error_set (URJ_ERROR_SYNTAX,
@ -51,40 +48,7 @@ cmd_initbus_run (urj_chain_t *chain, char *params[])
return URJ_STATUS_FAIL;
}
if (urj_cmd_test_cable (chain) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
if (urj_tap_chain_active_part (chain) == NULL)
return URJ_STATUS_FAIL;
for (drv = 0; urj_bus_drivers[drv] != NULL; drv++)
if (strcasecmp (urj_bus_drivers[drv]->name, params[1]) == 0)
break;
if (urj_bus_drivers[drv] == NULL)
{
urj_error_set (URJ_ERROR_NOTFOUND, _("Unknown bus: %s"), params[1]);
return URJ_STATUS_FAIL;
}
urj_param_init (&bus_params);
for (i = 2; params[i] != NULL; i++)
if (urj_param_push (&urj_bus_param_list, &bus_params,
params[i]) != URJ_STATUS_OK)
{
urj_param_clear (&bus_params);
return URJ_STATUS_FAIL;
}
if (urj_bus_init_bus(chain, urj_bus_drivers[drv], bus_params) == NULL)
{
urj_param_clear (&bus_params);
return URJ_STATUS_FAIL;
}
urj_param_clear (&bus_params);
return URJ_STATUS_OK;
return urj_bus_init (chain, params[1], &params[2]);
}
static void

@ -33,7 +33,7 @@
#include <urjtag/tap_state.h>
#include <urjtag/tap.h>
#include <urjtag/data_register.h>
#include <urjtag/cmd.h>
#include <urjtag/bsdl.h>
#include <urjtag/chain.h>
@ -71,6 +71,100 @@ urj_tap_chain_free (urj_chain_t *chain)
free (chain);
}
int
urj_tap_chain_connect (urj_chain_t *chain, const char *drivername, char *params[])
{
urj_cable_t *cable;
int i, j, paramc;
const urj_param_t **cable_params;
const urj_cable_driver_t *driver;
urj_cable_parport_devtype_t devtype;
const char *devname;
int param_start;
param_start = 0;
paramc = urj_cmd_params (params);
/* search cable driver list */
for (i = 0; urj_tap_cable_drivers[i]; i++)
if (strcasecmp (drivername, urj_tap_cable_drivers[i]->name) == 0)
break;
driver = urj_tap_cable_drivers[i];
if (!driver)
{
urj_error_set (URJ_ERROR_INVALID,
"unknown cable driver '%s'", drivername);
return URJ_STATUS_FAIL;
}
if (driver->device_type == URJ_CABLE_DEVICE_PARPORT)
{
if (paramc < 3)
{
urj_error_set (URJ_ERROR_SYNTAX,
"parallel cable requires >= 3 parameters");
return URJ_STATUS_FAIL;
}
for (j = 0; j < URJ_CABLE_PARPORT_N_DEVS; j++)
if (strcasecmp (params[0],
urj_cable_parport_devtype_string (j)) == 0)
break;
if (j == URJ_CABLE_PARPORT_N_DEVS)
{
urj_error_set (URJ_ERROR_INVALID,
"unknown parallel port device type '%s'",
params[0]);
return URJ_STATUS_FAIL;
}
devtype = j;
devname = params[1];
param_start = 2;
}
else
{
/* Silence gcc uninitialized warnings */
devtype = -1;
devname = NULL;
}
urj_param_init (&cable_params);
for (j = param_start; params[j] != NULL; j++)
if (urj_param_push (&urj_cable_param_list, &cable_params,
params[j]) != URJ_STATUS_OK)
{
urj_param_clear (&cable_params);
return URJ_STATUS_FAIL;
}
switch (driver->device_type)
{
case URJ_CABLE_DEVICE_PARPORT:
cable = urj_tap_cable_parport_connect (chain, driver, devtype, devname,
cable_params);
break;
case URJ_CABLE_DEVICE_USB:
cable = urj_tap_cable_usb_connect (chain, driver, cable_params);
break;
case URJ_CABLE_DEVICE_OTHER:
cable = urj_tap_cable_other_connect (chain, driver, cable_params);
break;
default:
cable = NULL;
break;
}
urj_param_clear (&cable_params);
if (cable == NULL)
return URJ_STATUS_FAIL;
chain->cable->chain = chain;
return URJ_STATUS_OK;
}
void
urj_tap_chain_disconnect (urj_chain_t *chain)
{

Loading…
Cancel
Save