[1839040] Make "cable" command less parport-centric. Changes "cable" command syntax!

git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@809 b68d4a1b-bc3d-0410-92ed-d4ac073336b7
master
Kolja Waschk 17 years ago
parent 4bedeb6c74
commit 4b93f558b6

@ -38,7 +38,7 @@ typedef struct cable_driver_t cable_driver_t;
struct cable_driver_t {
const char *name;
const char *description;
cable_t *(*connect)( cable_driver_t *, parport_t * );
int (*connect)( char *params[], cable_t *cable );
void (*disconnect)( cable_t *cable );
void (*cable_free)( cable_t *cable );
int (*init)( cable_t * );

@ -34,7 +34,7 @@ typedef struct parport_t parport_t;
typedef struct {
const char *type;
cable_t *(*connect)( const char **, int );
parport_t *(*connect)( const char **, int );
void (*parport_free)( parport_t * );
int (*open)( parport_t * );
int (*close)( parport_t * );

@ -39,18 +39,19 @@
static int
cmd_cable_run( char *params[] )
{
cable_t *cable = malloc( sizeof *cable );
int i;
/* we need at least one parameter for 'cable' command */
if (cmd_params( params ) < 2)
return -1;
/* search connection type driver */
for (i = 0; parport_drivers[i]; i++)
if (strcasecmp( params[1], parport_drivers[i]->type ) == 0)
/* search cable driver list */
for (i = 0; cable_drivers[i]; i++)
if (strcasecmp( params[1], cable_drivers[i]->name ) == 0)
break;
if (!parport_drivers[i]) {
printf( _("Unknown connection type: %s\n"), params[1] );
if (!cable_drivers[i]) {
printf( _("Unknown cable type: %s\n"), params[1] );
return 1;
}
@ -58,13 +59,23 @@ cmd_cable_run( char *params[] )
bus_free( bus );
bus = NULL;
}
chain_disconnect( chain );
chain->cable = parport_drivers[i]->connect( (const char **) &params[2], cmd_params( params ) - 2 );
if (!chain->cable) {
if (!cable) {
printf( _("%s(%d) malloc failed!\n"), __FILE__, __LINE__);
return 1;
}
cable->driver = cable_drivers[i];
if ( cable->driver->connect( ++params, cable ) ) {
printf( _("Error: Cable connection failed!\n") );
return 1;
}
chain->cable = cable;
if (cable_init( chain->cable )) {
printf( _("Error: Cable initialization failed!\n") );
chain_disconnect( chain );
@ -83,43 +94,14 @@ cmd_cable_help( void )
int i;
printf( _(
"Usage: %s PORTADDR CABLE\n"
"Usage: %s DEV CABLE\n"
#ifdef HAVE_LIBFTDI
"Usage: %s VID:PID:S/N CABLE\n"
"Usage: %s VID:PID:S/N CABLE\n"
#endif
#ifdef HAVE_LIBFTD2XX
"Usage: %s VID:PID:S/N CABLE\n"
"Usage: %s VID:PID:S/N CABLE\n"
#endif
#ifdef HAVE_LIBUSB
"Usage: %s VID:PID:S/N CABLE\n"
#endif
"Select JTAG cable connected to parallel port.\n"
"Usage: %s DRIVER [DRIVER_OPTS]\n"
"Select JTAG cable type.\n"
"\n"
"PORTADDR parallel port address (e.g. 0x378)\n"
"CABLE cable type\n"
#if defined HAVE_LIBUSB || defined HAVE_LIBFTDI || defined HAVE_LIBFTD2XX
"DEV ppdev device (e.g. /dev/parport0)\n"
"VID empty or USB vendor ID, hex (e.g. 09FB)\n"
"PID empty or USB product ID, hex (e.g. 6001)\n"
"S/N empty or USB product serial number, ASCII\n"
#endif
"DRIVER name of cable\n"
"DRIVER_OPTS options for the selected cable\n"
"\n"
"List of supported cables:\n"
"%-13s No cable connected\n"
), "cable parallel", "cable ppdev",
#ifdef HAVE_LIBFTDI
"cable ftdi", "cable ftdi-mpsse",
#endif
#ifdef HAVE_LIBFTD2XX
"cable ftd2xx", "cable ftd2xx-mpsse",
#endif
#ifdef HAVE_LIBUSB
"cable xpcu",
#endif
"none" );
), "cable" );
for (i = 0; cable_drivers[i]; i++)
printf( _("%-13s %s\n"), cable_drivers[i]->name, _(cable_drivers[i]->description) );

@ -22,7 +22,11 @@
*
*/
#include "sysdep.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cable.h"
#include "parport.h"
@ -30,23 +34,49 @@
#include "generic.h"
cable_t *
generic_connect( cable_driver_t *cable_driver, parport_t *port )
#include <brux/cmd.h>
int
generic_connect( char *params[], cable_t *cable )
{
generic_params_t *params = malloc( sizeof *params );
cable_t *cable = malloc( sizeof *cable );
if (!params || !cable) {
free( params );
generic_params_t *cable_params = malloc( sizeof *cable_params );
parport_t *port;
int i;
if ( cmd_params( params ) < 3 ) {
printf( _("not enough arguments!\n") );
return 1;
}
/* search parport driver list */
for (i = 0; parport_drivers[i]; i++)
if (strcasecmp( params[1], parport_drivers[i]->type ) == 0)
break;
if (!parport_drivers[i]) {
printf( _("Unknown port driver: %s\n"), params[1] );
return 2;
}
/* set up parport driver */
port = parport_drivers[i]->connect( (const char **) &params[2],
cmd_params( params ) - 2 );
if (port == NULL) {
printf( _("Error: Cable connection failed!\n") );
return 3;
}
if (!cable_params) {
free( cable_params );
free( cable );
return NULL;
return 4;
}
cable->driver = cable_driver;
cable->port = port;
cable->params = params;
cable->params = cable_params;
cable->chain = NULL;
return cable;
return 0;
}
void

@ -36,7 +36,7 @@ typedef struct {
#define PARAM_TRST(cable) ((generic_params_t *) cable->params)->trst
#define PARAM_SRESET(cable) ((generic_params_t *) cable->params)->sreset
cable_t *generic_connect( cable_driver_t *cable_driver, parport_t *port );
int generic_connect( char *params[], cable_t *cable );
void generic_disconnect( cable_t *cable );
void generic_cable_free( cable_t *cable );
void generic_done( cable_t *cable );

@ -148,24 +148,21 @@ direct_parport_free( parport_t *port )
free( port );
}
static cable_t *
parport_t *
direct_connect( const char **par, int parnum )
{
int i;
long int port_scan_val;
unsigned int port;
port_node_t *pn = ports;
parport_t *parport;
cable_t *cable;
if (parnum != 2) {
if (parnum != 1) {
printf( _("Syntax error!\n") );
return NULL;
}
port_scan_val = strtol(par[0], NULL, 0);
// if ((sscanf( par[0], "0x%x", &port ) != 1) && (sscanf( par[0], "%d", &port ) != 1)) {
if (port_scan_val < 0 || (port_scan_val + 3) > 0xffff) {
printf( _("Invalid port address!\n") );
return NULL;
@ -185,21 +182,7 @@ direct_connect( const char **par, int parnum )
}
}
if (strcasecmp( par[1], "none" ) == 0) {
printf( _("Changed cable to 'none'\n") );
return NULL;
}
for (i = 0; cable_drivers[i]; i++)
if (strcasecmp( par[1], cable_drivers[i]->name ) == 0)
break;
if (!cable_drivers[i]) {
printf( _("Unknown cable: %s\n"), par[1] );
return NULL;
}
printf( _("Initializing %s on parallel port at 0x%x\n"), _(cable_drivers[i]->description), port );
printf( _("Initializing parallel port at 0x%x\n"), port );
parport = direct_parport_alloc( port );
if (!parport) {
@ -207,11 +190,7 @@ direct_connect( const char **par, int parnum )
return NULL;
}
cable = cable_drivers[i]->connect( cable_drivers[i], parport );
if (!cable)
direct_parport_free( parport );
return cable;
return parport;
}
static int

@ -138,13 +138,12 @@ ftd2xx_parport_free( parport_t *port )
}
static cable_driver_t *
int
ftd2xx_pre_connect( const char **par, int parnum )
{
int i;
port_node_t *pn;
if (parnum != 2) {
if (parnum != 1) {
printf( _("Syntax error!\n") );
return NULL;
}
@ -156,35 +155,22 @@ ftd2xx_pre_connect( const char **par, int parnum )
break;
}
if (strcmp( par[1], "none" ) == 0) {
printf( _("Changed cable to 'none'\n") );
return NULL;
}
for (i = 0; cable_drivers[i]; i++)
if (strcmp( par[1], cable_drivers[i]->name ) == 0)
break;
if (!cable_drivers[i]) {
printf( _("Unknown cable: %s\n"), par[1] );
return NULL;
}
#if TODO
printf( _("Initializing %s on FTDI device %s\n"), _(cable_drivers[i]->description), par[0] );
#else
printf( _("Initializing on FTDI device %s\n"), par[0] );
#endif
return cable_drivers[i];
return 1;
}
static cable_t *
parport_t *
ftd2xx_std_connect( const char **par, int parnum )
{
parport_t *parport;
cable_driver_t *cable_driver;
cable_t *cable;
cable_driver = ftd2xx_pre_connect(par, parnum);
if (!cable_driver)
if (!ftd2xx_pre_connect(par, parnum))
return NULL;
parport = ftd2xx_parport_alloc( par[0], &ftd2xx_parport_driver, OUTBUF_LEN_STD );
@ -193,23 +179,16 @@ ftd2xx_std_connect( const char **par, int parnum )
return NULL;
}
cable = cable_driver->connect( cable_driver, parport );
if (!cable)
ftd2xx_parport_free( parport );
return cable;
return parport;
}
static cable_t *
parport_t *
ftd2xx_mpsse_connect( const char **par, int parnum )
{
parport_t *parport;
cable_driver_t *cable_driver;
cable_t *cable;
cable_driver = ftd2xx_pre_connect(par, parnum);
if (!cable_driver)
if (!ftd2xx_pre_connect(par, parnum))
return NULL;
parport = ftd2xx_parport_alloc( par[0], &ftd2xx_mpsse_parport_driver, OUTBUF_LEN_MPSSE );
@ -218,11 +197,7 @@ ftd2xx_mpsse_connect( const char **par, int parnum )
return NULL;
}
cable = cable_driver->connect( cable_driver, parport );
if (!cable)
ftd2xx_parport_free( parport );
return cable;
return parport;
}

@ -142,15 +142,14 @@ ftdi_parport_free( parport_t *port )
}
static cable_driver_t *
int
ftdi_pre_connect( const char **par, int parnum )
{
int i;
port_node_t *pn;
if (parnum != 2) {
if (parnum != 1) {
printf( _("Syntax error!\n") );
return NULL;
return 0;
}
for (pn = ports; pn; pn = pn->next)
@ -160,35 +159,22 @@ ftdi_pre_connect( const char **par, int parnum )
break;
}
if (strcmp( par[1], "none" ) == 0) {
printf( _("Changed cable to 'none'\n") );
return NULL;
}
for (i = 0; cable_drivers[i]; i++)
if (strcmp( par[1], cable_drivers[i]->name ) == 0)
break;
if (!cable_drivers[i]) {
printf( _("Unknown cable: %s\n"), par[1] );
return NULL;
}
#if TODO
printf( _("Initializing %s on FTDI device %s\n"), _(cable_drivers[i]->description), par[0] );
#else
printf( _("Initializing on FTDI device %s\n"), par[0] );
#endif
return cable_drivers[i];
return 1;
}
static cable_t *
parport_t *
ftdi_std_connect( const char **par, int parnum )
{
parport_t *parport;
cable_driver_t *cable_driver;
cable_t *cable;
cable_driver = ftdi_pre_connect(par, parnum);
if (!cable_driver)
if(!ftdi_pre_connect(par, parnum))
return NULL;
parport = ftdi_parport_alloc( par[0], &ftdi_parport_driver, OUTBUF_LEN_STD );
@ -197,23 +183,16 @@ ftdi_std_connect( const char **par, int parnum )
return NULL;
}
cable = cable_driver->connect( cable_driver, parport );
if (!cable)
ftdi_parport_free( parport );
return cable;
return parport;
}
static cable_t *
parport_t *
ftdi_mpsse_connect( const char **par, int parnum )
{
parport_t *parport;
cable_driver_t *cable_driver;
cable_t *cable;
cable_driver = ftdi_pre_connect(par, parnum);
if (!cable_driver)
if(!ftdi_pre_connect(par, parnum))
return NULL;
parport = ftdi_parport_alloc( par[0], &ftdi_mpsse_parport_driver, OUTBUF_LEN_MPSSE );
@ -222,11 +201,7 @@ ftdi_mpsse_connect( const char **par, int parnum )
return NULL;
}
cable = cable_driver->connect( cable_driver, parport );
if (!cable)
ftdi_parport_free( parport );
return cable;
return parport;
}

@ -107,15 +107,13 @@ ppdev_parport_free( parport_t *port )
free( port );
}
static cable_t *
parport_t *
ppdev_connect( const char **par, int parnum )
{
int i;
port_node_t *pn;
parport_t *parport;
cable_t *cable;
if (parnum != 2) {
if (parnum != 1) {
printf( _("Syntax error!\n") );
return NULL;
}
@ -127,21 +125,7 @@ ppdev_connect( const char **par, int parnum )
break;
}
if (strcasecmp( par[1], "none" ) == 0) {
printf( _("Changed cable to 'none'\n") );
return NULL;
}
for (i = 0; cable_drivers[i]; i++)
if (strcmp( par[1], cable_drivers[i]->name ) == 0)
break;
if (!cable_drivers[i]) {
printf( _("Unknown cable: %s\n"), par[1] );
return NULL;
}
printf( _("Initializing %s on ppdev port %s\n"), _(cable_drivers[i]->description), par[0] );
printf( _("Initializing ppdev port %s\n"), par[0] );
parport = ppdev_parport_alloc( par[0] );
if (!parport) {
@ -149,11 +133,7 @@ ppdev_connect( const char **par, int parnum )
return NULL;
}
cable = cable_drivers[i]->connect( cable_drivers[i], parport );
if (!cable)
ppdev_parport_free( parport );
return cable;
return parport;
}
static int

@ -129,15 +129,14 @@ xpcu_pp_free( parport_t *port )
/* ---------------------------------------------------------------------- */
static cable_t *
parport_t *
xpcu_pp_connect( const char **par, int parnum )
{
int i;
port_node_t *pn;
parport_t *parport;
cable_t *cable;
if (parnum != 2) {
if (parnum != 1) {
printf( _("Syntax error!\n") );
return NULL;
}
@ -149,21 +148,11 @@ xpcu_pp_connect( const char **par, int parnum )
break;
}
if (strcmp( par[1], "none" ) == 0) {
printf( _("Changed cable to 'none'\n") );
return NULL;
}
for (i = 0; cable_drivers[i]; i++)
if (strcmp( par[1], cable_drivers[i]->name ) == 0)
break;
if (!cable_drivers[i]) {
printf( _("Unknown cable: %s\n"), par[1] );
return NULL;
}
#ifdef TODO
printf( _("Initializing %s, device %s\n"), _(cable_drivers[i]->description), par[0] );
#else
printf( _("Initializing device %s\n"), par[0] );
#endif
parport = xpcu_pp_alloc( par[0] );
if (!parport) {
@ -171,11 +160,7 @@ xpcu_pp_connect( const char **par, int parnum )
return NULL;
}
cable = cable_drivers[i]->connect( cable_drivers[i], parport );
if (!cable)
xpcu_pp_free( parport );
return cable;
return parport;
}
/* ---------------------------------------------------------------------- */

Loading…
Cancel
Save