From c2cecc74b0acb11254392b6622655a4758f35903 Mon Sep 17 00:00:00 2001
From: zwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Date: Mon, 29 Jun 2009 00:00:50 +0000
Subject: [PATCH] Move JTAG interface list to new files. - Adds new source
 files to encapsulate static/dynamic module handling. - Further work should
 implement the jtag_interface_modules_load routine,   to populate the
 jtag_interfaces list from shared libraries in a path.

git-svn-id: svn://svn.berlios.de/openocd/trunk@2413 b42882b7-edfa-0310-969c-e2dbd0fdcd60
---
 src/jtag/Makefile.am  |   4 +-
 src/jtag/interfaces.c | 155 ++++++++++++++++++++++++++++++++++++++++++
 src/jtag/interfaces.h |  45 ++++++++++++
 src/jtag/tcl.c        | 125 +---------------------------------
 4 files changed, 204 insertions(+), 125 deletions(-)
 create mode 100644 src/jtag/interfaces.c
 create mode 100644 src/jtag/interfaces.h

diff --git a/src/jtag/Makefile.am b/src/jtag/Makefile.am
index 5af6c74fa..ba722c6dc 100644
--- a/src/jtag/Makefile.am
+++ b/src/jtag/Makefile.am
@@ -75,12 +75,14 @@ endif
 
 libjtag_la_SOURCES = \
 	core.c \
-	tcl.c \
 	interface.c \
+	interfaces.c \
+	tcl.c \
 	$(DRIVERFILES)
 
 noinst_HEADERS = \
 	interface.h \
+	interfaces.h \
 	commands.h \
 	minidriver.h \
 	bitbang.h \
diff --git a/src/jtag/interfaces.c b/src/jtag/interfaces.c
new file mode 100644
index 000000000..1d8cb7566
--- /dev/null
+++ b/src/jtag/interfaces.c
@@ -0,0 +1,155 @@
+/***************************************************************************
+ *   Copyright (C) 2005 by Dominic Rath                                    *
+ *   Dominic.Rath@gmx.de                                                   *
+ *                                                                         *
+ *   Copyright (C) 2007,2008 Øyvind Harboe                                 *
+ *   oyvind.harboe@zylin.com                                               *
+ *                                                                         *
+ *   Copyright (C) 2009 SoftPLC Corporation                                *
+ *       http://softplc.com                                                *
+ *   dick@softplc.com                                                      *
+ *                                                                         *
+ *   Copyright (C) 2009 Zachary T Welch                                    *
+ *   zw@superlucidity.net                                                  *
+ *                                                                         *
+ *   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.             *
+ ***************************************************************************/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "interfaces.h"
+
+/**
+ * @file This file includes declarations for all built-in jtag interfaces,
+ *  which are then listed in the jtag_interfaces array.
+ *
+ *  Dynamic loading can be implemented be searching for shared libraries
+ *  that contain a jtag_interface structure that can added to this list.
+ */
+
+#if BUILD_ZY1000 == 1
+extern jtag_interface_t zy1000_interface;
+#elif defined(BUILD_MINIDRIVER_DUMMY)
+extern jtag_interface_t minidummy_interface;
+#else // standard drivers
+#if BUILD_PARPORT == 1
+extern jtag_interface_t parport_interface;
+#endif
+#if BUILD_DUMMY == 1
+extern jtag_interface_t dummy_interface;
+#endif
+#if BUILD_FT2232_FTD2XX == 1
+extern jtag_interface_t ft2232_interface;
+#endif
+#if BUILD_FT2232_LIBFTDI == 1
+extern jtag_interface_t ft2232_interface;
+#endif
+#if BUILD_AMTJTAGACCEL == 1
+extern jtag_interface_t amt_jtagaccel_interface;
+#endif
+#if BUILD_EP93XX == 1
+extern jtag_interface_t ep93xx_interface;
+#endif
+#if BUILD_AT91RM9200 == 1
+extern jtag_interface_t at91rm9200_interface;
+#endif
+#if BUILD_GW16012 == 1
+extern jtag_interface_t gw16012_interface;
+#endif
+#if BUILD_PRESTO_LIBFTDI == 1 || BUILD_PRESTO_FTD2XX == 1
+extern jtag_interface_t presto_interface;
+#endif
+#if BUILD_USBPROG == 1
+extern jtag_interface_t usbprog_interface;
+#endif
+#if BUILD_JLINK == 1
+extern jtag_interface_t jlink_interface;
+#endif
+#if BUILD_VSLLINK == 1
+extern jtag_interface_t vsllink_interface;
+#endif
+#if BUILD_RLINK == 1
+extern jtag_interface_t rlink_interface;
+#endif
+#if BUILD_ARMJTAGEW == 1
+extern jtag_interface_t armjtagew_interface;
+#endif
+#endif // standard drivers
+
+/**
+ * The list of built-in JTAG interfaces, containing entries for those
+ * drivers that were enabled by the @c configure script.
+ *
+ * The list should be defined to contain either one minidriver interface
+ * or some number of standard driver interfaces, never both.
+ */
+jtag_interface_t *jtag_interfaces[] = {
+#if BUILD_ZY1000 == 1
+		&zy1000_interface,
+#elif defined(BUILD_MINIDRIVER_DUMMY)
+		&minidummy_interface,
+#else // standard drivers
+#if BUILD_PARPORT == 1
+		&parport_interface,
+#endif
+#if BUILD_DUMMY == 1
+		&dummy_interface,
+#endif
+#if BUILD_FT2232_FTD2XX == 1
+		&ft2232_interface,
+#endif
+#if BUILD_FT2232_LIBFTDI == 1
+		&ft2232_interface,
+#endif
+#if BUILD_AMTJTAGACCEL == 1
+		&amt_jtagaccel_interface,
+#endif
+#if BUILD_EP93XX == 1
+		&ep93xx_interface,
+#endif
+#if BUILD_AT91RM9200 == 1
+		&at91rm9200_interface,
+#endif
+#if BUILD_GW16012 == 1
+		&gw16012_interface,
+#endif
+#if BUILD_PRESTO_LIBFTDI == 1 || BUILD_PRESTO_FTD2XX == 1
+		&presto_interface,
+#endif
+#if BUILD_USBPROG == 1
+		&usbprog_interface,
+#endif
+#if BUILD_JLINK == 1
+		&jlink_interface,
+#endif
+#if BUILD_VSLLINK == 1
+		&vsllink_interface,
+#endif
+#if BUILD_RLINK == 1
+		&rlink_interface,
+#endif
+#if BUILD_ARMJTAGEW == 1
+		&armjtagew_interface,
+#endif
+#endif // standard drivers
+		NULL,
+	};
+
+void jtag_interface_modules_load(const char *path)
+{
+	// @todo: implement dynamic module loading for JTAG interface drivers
+}
diff --git a/src/jtag/interfaces.h b/src/jtag/interfaces.h
new file mode 100644
index 000000000..a6d944059
--- /dev/null
+++ b/src/jtag/interfaces.h
@@ -0,0 +1,45 @@
+/***************************************************************************
+ *   Copyright (C) 2005 by Dominic Rath                                    *
+ *   Dominic.Rath@gmx.de                                                   *
+ *                                                                         *
+ *   Copyright (C) 2007,2008 Øyvind Harboe                                 *
+ *   oyvind.harboe@zylin.com                                               *
+ *                                                                         *
+ *   Copyright (C) 2009 SoftPLC Corporation                                *
+ *       http://softplc.com                                                *
+ *   dick@softplc.com                                                      *
+ *                                                                         *
+ *   Copyright (C) 2009 Zachary T Welch                                    *
+ *   zw@superlucidity.net                                                  *
+ *                                                                         *
+ *   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.             *
+ ***************************************************************************/
+#ifndef OPENOCD_JTAG_INTERFACES_H
+#define OPENOCD_JTAG_INTERFACES_H
+
+/**
+ * @file Exports the list of JTAG interface drivers, along with routines
+ * for loading and unloading them dynamically from shared libraries.
+ */
+
+#include "interface.h"
+
+/// Dynamically load all JTAG interface modules from specified directory.
+void jtag_interface_modules_load(const char *path);
+
+extern jtag_interface_t *jtag_interfaces[];
+
+#endif // OPENOCD_JTAG_INTERFACES_H
diff --git a/src/jtag/tcl.c b/src/jtag/tcl.c
index 2ea3868dc..759f8f7c4 100644
--- a/src/jtag/tcl.c
+++ b/src/jtag/tcl.c
@@ -34,6 +34,7 @@
 #include "jtag.h"
 #include "minidriver.h"
 #include "interface.h"
+#include "interfaces.h"
 
 #ifdef HAVE_STRINGS_H
 #include <strings.h>
@@ -46,130 +47,6 @@ static const Jim_Nvp nvp_jtag_tap_event[] = {
 	{ .name = NULL, .value = -1 }
 };
 
-/* jtag interfaces (parport, FTDI-USB, TI-USB, ...)
- */
-
-#if BUILD_ZY1000 == 1
-	extern jtag_interface_t zy1000_interface;
-#elif defined(BUILD_MINIDRIVER_DUMMY)
-	extern jtag_interface_t minidummy_interface;
-#else // standard drivers
-#if BUILD_PARPORT == 1
-	extern jtag_interface_t parport_interface;
-#endif
-
-#if BUILD_DUMMY == 1
-	extern jtag_interface_t dummy_interface;
-#endif
-
-#if BUILD_FT2232_FTD2XX == 1
-	extern jtag_interface_t ft2232_interface;
-#endif
-
-#if BUILD_FT2232_LIBFTDI == 1
-	extern jtag_interface_t ft2232_interface;
-#endif
-
-#if BUILD_AMTJTAGACCEL == 1
-	extern jtag_interface_t amt_jtagaccel_interface;
-#endif
-
-#if BUILD_EP93XX == 1
-	extern jtag_interface_t ep93xx_interface;
-#endif
-
-#if BUILD_AT91RM9200 == 1
-	extern jtag_interface_t at91rm9200_interface;
-#endif
-
-#if BUILD_GW16012 == 1
-	extern jtag_interface_t gw16012_interface;
-#endif
-
-#if BUILD_PRESTO_LIBFTDI == 1 || BUILD_PRESTO_FTD2XX == 1
-	extern jtag_interface_t presto_interface;
-#endif
-
-#if BUILD_USBPROG == 1
-	extern jtag_interface_t usbprog_interface;
-#endif
-
-#if BUILD_JLINK == 1
-	extern jtag_interface_t jlink_interface;
-#endif
-
-#if BUILD_VSLLINK == 1
-	extern jtag_interface_t vsllink_interface;
-#endif
-
-#if BUILD_RLINK == 1
-	extern jtag_interface_t rlink_interface;
-#endif
-
-#if BUILD_ARMJTAGEW == 1
-	extern jtag_interface_t armjtagew_interface;
-#endif
-#endif // standard drivers
-
-/**
- * The list of built-in JTAG interfaces, containing entries for those
- * drivers that were enabled by the @c configure script.
- *
- * The list should be defined to contain either one minidriver interface
- * or some number of standard driver interfaces, never both.
- */
-jtag_interface_t *jtag_interfaces[] = {
-#if BUILD_ZY1000 == 1
-	&zy1000_interface,
-#elif defined(BUILD_MINIDRIVER_DUMMY)
-	&minidummy_interface,
-#else // standard drivers
-#if BUILD_PARPORT == 1
-	&parport_interface,
-#endif
-#if BUILD_DUMMY == 1
-	&dummy_interface,
-#endif
-#if BUILD_FT2232_FTD2XX == 1
-	&ft2232_interface,
-#endif
-#if BUILD_FT2232_LIBFTDI == 1
-	&ft2232_interface,
-#endif
-#if BUILD_AMTJTAGACCEL == 1
-	&amt_jtagaccel_interface,
-#endif
-#if BUILD_EP93XX == 1
-	&ep93xx_interface,
-#endif
-#if BUILD_AT91RM9200 == 1
-	&at91rm9200_interface,
-#endif
-#if BUILD_GW16012 == 1
-	&gw16012_interface,
-#endif
-#if BUILD_PRESTO_LIBFTDI == 1 || BUILD_PRESTO_FTD2XX == 1
-	&presto_interface,
-#endif
-#if BUILD_USBPROG == 1
-	&usbprog_interface,
-#endif
-#if BUILD_JLINK == 1
-	&jlink_interface,
-#endif
-#if BUILD_VSLLINK == 1
-	&vsllink_interface,
-#endif
-#if BUILD_RLINK == 1
-	&rlink_interface,
-#endif
-#if BUILD_ARMJTAGEW == 1
-	&armjtagew_interface,
-#endif
-#endif // standard drivers
-	NULL,
-};
-
 extern jtag_interface_t *jtag_interface;
 
 /* jtag commands */
-- 
GitLab