diff --git a/jtag/ChangeLog b/jtag/ChangeLog index f50543f4..25e66b4e 100644 --- a/jtag/ChangeLog +++ b/jtag/ChangeLog @@ -1,3 +1,15 @@ +2003-01-08 Marcel Telka + + * include/cable.h: Unified and simplified cable driver handling, added driver name + and driver description into driver interface structure. + * src/help.c (help): Ditto. + * src/jtag.c (main): Ditto. + * src/tap/Makefile.am: Ditto. + * src/tap/cable.c: Ditto. + * src/tap/cable/dlc5.c: Ditto. + * src/tap/cable/ea253.c: Ditto. + * src/tap/cable/ei012.c: Ditto. + 2003-01-08 Marcel Telka * include/cable.h: Added cable driver for ETC EI012 JTAG Cable. diff --git a/jtag/include/cable.h b/jtag/include/cable.h index 129f67be..805f9485 100644 --- a/jtag/include/cable.h +++ b/jtag/include/cable.h @@ -29,6 +29,8 @@ #include typedef struct { + const char *name; + const char *description; int (*init)( unsigned int ); void (*done)( void ); void (*clock)( int, int ); @@ -41,8 +43,6 @@ extern cable_driver_t *cable; #define tap_get_tdo cable->get_tdo #define tap_set_trst cable->set_trst -extern cable_driver_t ea253_cable_driver; -extern cable_driver_t dlc5_cable_driver; -extern cable_driver_t ei012_cable_driver; +extern cable_driver_t *cable_drivers[]; #endif /* CABLE_H */ diff --git a/jtag/src/help.c b/jtag/src/help.c index 0e713e10..551f4112 100644 --- a/jtag/src/help.c +++ b/jtag/src/help.c @@ -29,6 +29,8 @@ #include #include +#include "cable.h" + void help( const char *cmd ) { @@ -62,7 +64,9 @@ help( const char *cmd ) "Usage: help [COMMAND]\n" "Print short help for COMMAND, or list of available commands.\n" ); - else if (strcmp( cmd, "cable" ) == 0) + else if (strcmp( cmd, "cable" ) == 0) { + int i; + printf( "Usage: cable parallel PORTADDR CABLE\n" "Select JTAG cable connected to parallel port.\n" @@ -72,11 +76,11 @@ help( const char *cmd ) "\n" "List of supported cables:\n" "none No cable connected\n" - "DLC5 Xilinx DLC5 JTAG Parallel Cable III\n" - "EA253 ETC EA253 JTAG Cable\n" - "EI012 ETC EI012 JTAG Cable\n" ); - else if (strcmp( cmd, "detect" ) == 0) + + for (i = 0; cable_drivers[i]; i++) + printf( "%-11s%s\n", cable_drivers[i]->name, cable_drivers[i]->description ); + } else if (strcmp( cmd, "detect" ) == 0) printf( "Usage: detect\n" "Detect parts on the JTAG chain.\n" diff --git a/jtag/src/jtag.c b/jtag/src/jtag.c index f14a4066..346c008b 100644 --- a/jtag/src/jtag.c +++ b/jtag/src/jtag.c @@ -101,6 +101,7 @@ main( void ) } if (strcmp( t, "cable" ) == 0) { + int i; unsigned int port; t = get_token( NULL ); @@ -137,33 +138,30 @@ main( void ) if (strcmp( t, "none" ) == 0) { printf( "Changed cable to 'none'\n" ); cable = NULL; - } else if (strcmp( t, "DLC5" ) == 0) { - cable = &dlc5_cable_driver; - - if (!cable->init( port )) - cable = NULL; - } else if (strcmp( t, "EA253" ) == 0) { - cable = &ea253_cable_driver; - - if (!cable->init( port )) - cable = NULL; - } else if (strcmp( t, "EI012" ) == 0) { - cable = &ei012_cable_driver; - - if (!cable->init( port )) - cable = NULL; - } else { - printf( "Unknown cable: %s\n", t ); continue; } + + for (i = 0; cable_drivers[i]; i++) + if (strcmp( t, cable_drivers[i]->name ) == 0) + break; - if (cable) { - cable->set_trst( 0 ); - cable->set_trst( 1 ); + if (!cable_drivers[i]) { + printf( "Unknown cable: %s\n", t ); + continue; + } - tap_reset(); + cable = cable_drivers[i]; + printf( "Initilizing %s on parallel port at 0x%x\n", cable->description, port ); + if (!cable->init( port )) { + printf( "Error: Cable driver initialization failed!\n" ); + cable = NULL; + continue; } + cable->set_trst( 0 ); + cable->set_trst( 1 ); + tap_reset(); + continue; } diff --git a/jtag/src/tap/Makefile.am b/jtag/src/tap/Makefile.am index 7a2bc289..1b5ef1b2 100644 --- a/jtag/src/tap/Makefile.am +++ b/jtag/src/tap/Makefile.am @@ -27,6 +27,7 @@ libtap_a_SOURCES = \ tap.c \ register.c \ state.c \ + cable.c \ cable/dlc5.c \ cable/ea253.c \ cable/ei012.c diff --git a/jtag/src/tap/cable.c b/jtag/src/tap/cable.c new file mode 100644 index 00000000..f0b43f6c --- /dev/null +++ b/jtag/src/tap/cable.c @@ -0,0 +1,36 @@ +/* + * $Id$ + * + * Copyright (C) 2003 ETC s.r.o. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * Written by Marcel Telka , 2003. + * + */ + +#include "cable.h" + +extern cable_driver_t dlc5_cable_driver; +extern cable_driver_t ea253_cable_driver; +extern cable_driver_t ei012_cable_driver; + +cable_driver_t *cable_drivers[] = { + &dlc5_cable_driver, + &ea253_cable_driver, + &ei012_cable_driver, + NULL /* last must be NULL */ +}; diff --git a/jtag/src/tap/cable/dlc5.c b/jtag/src/tap/cable/dlc5.c index 4b27b25f..4e4c9249 100644 --- a/jtag/src/tap/cable/dlc5.c +++ b/jtag/src/tap/cable/dlc5.c @@ -27,7 +27,6 @@ * */ -#include #include #include "cable.h" @@ -60,13 +59,7 @@ dlc5_init( unsigned int aport ) { tap_state_init(); port = aport; - printf( "Initilizing Xilinx DLC5 JTAG Parallel Cable III on parallel port at 0x%x\n", port ); - if (ioperm( port, 2, 1 )) { - printf( "Error: Initialization failed!\n" ); - return 0; - } - - return 1; + return !ioperm( port, 2, 1 ); } static void @@ -102,6 +95,8 @@ dlc5_set_trst( int new_trst ) } cable_driver_t dlc5_cable_driver = { + "DLC5", + "Xilinx DLC5 JTAG Parallel Cable III", dlc5_init, dlc5_done, dlc5_clock, diff --git a/jtag/src/tap/cable/ea253.c b/jtag/src/tap/cable/ea253.c index 2266021d..e20a20f1 100644 --- a/jtag/src/tap/cable/ea253.c +++ b/jtag/src/tap/cable/ea253.c @@ -23,7 +23,6 @@ * */ -#include #include #include "cable.h" @@ -53,11 +52,8 @@ ea253_init( unsigned int aport ) { tap_state_init(); port = aport; - printf( "Initilizing cable EA253 on parallel port at 0x%x\n", port ); - if (ioperm( port, 2, 1 )) { - printf( "Error: Initialization failed!\n" ); + if (ioperm( port, 2, 1 )) return 0; - } tap_state_set_trst( (inb( port ) >> TRST) & 1 ); return 1; @@ -100,6 +96,8 @@ ea253_set_trst( int new_trst ) } cable_driver_t ea253_cable_driver = { + "EA253", + "ETC EA253 JTAG Cable", ea253_init, ea253_done, ea253_clock, diff --git a/jtag/src/tap/cable/ei012.c b/jtag/src/tap/cable/ei012.c index 63e1eeda..92728216 100644 --- a/jtag/src/tap/cable/ei012.c +++ b/jtag/src/tap/cable/ei012.c @@ -53,11 +53,8 @@ ei012_init( unsigned int aport ) { tap_state_init(); port = aport; - printf( "Initilizing ETC EI012 JTAG Cable on parallel port at 0x%x\n", port ); - if (ioperm( port, 2, 1 )) { - printf( "Error: Initialization failed!\n" ); + if (ioperm( port, 2, 1 )) return 0; - } tap_state_set_trst( (inb( port ) >> TRST) & 1 ); return 1; @@ -100,6 +97,8 @@ ei012_set_trst( int new_trst ) } cable_driver_t ei012_cable_driver = { + "EI012", + "ETC EI012 JTAG Cable", ei012_init, ei012_done, ei012_clock,