aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2011-10-09 18:37:31 +0200
committerHolger Hans Peter Freyther <zecke@selfish.org>2011-10-09 18:38:32 +0200
commit74ae64b3551b8061380b8f4f120096a57dea8c7e (patch)
tree0c453d22f129f99f0f16502aeaf03203d6885e5a
parent587730174f15220538ca3a1db1ccc601d079632c (diff)
sam: Select the IO Backend at runtime when a device name is specified
The configure part is more messy than I had hoped for. One can not just specify @VARIABLE_THAT_HAS_SOURCES@, I need to go through the every backend and add the sourcecode.
-rw-r--r--Makefile.am16
-rw-r--r--configure.in14
-rw-r--r--io.c30
-rw-r--r--io.h3
-rw-r--r--main.c4
5 files changed, 48 insertions, 19 deletions
diff --git a/Makefile.am b/Makefile.am
index a1f695f..ae59bd6 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -4,7 +4,21 @@ AUTOMAKE_OPTIONS = gnu
bin_PROGRAMS = sam7
-sam7_SOURCES = main.c io.c io_@IOTYPE@.c samba.c cmd.c
+sam7_SOURCES = main.c io.c samba.c cmd.c
+
+if HAVE_IOKIT
+sam7_SOURCES += io_iokit.c
+endif
+if HAVE_WIN32
+sam7_SOURCES += io_win32.c
+endif
+if HAVE_POSIX
+sam7_SOURCES += io_posix.c
+endif
+if HAVE_LIBUSB
+sam7_SOURCES += io_libusb.c
+endif
+
noinst_HEADERS = io.h samba.h cmd.h loader128_data.h loader256_data.h
EXTRA_DIST = driver/Makefile driver/at91.c \
diff --git a/configure.in b/configure.in
index 66e6206..4a5a8b3 100644
--- a/configure.in
+++ b/configure.in
@@ -15,14 +15,15 @@ AC_PROG_MAKE_SET
case "${host}" in
*-*-darwin* )
LIBS="$LIBS -framework IOKIT -framework CoreFoundation"
- IOTYPE="iokit"
+ have_iokit="true"
;;
*-*-cygwin* )
LIBS="$LIBS -lsetupapi"
- IOTYPE="win32"
+ have_win32="true"
;;
* )
- AC_CHECK_LIB(usb,usb_init,IOTYPE="libusb";LIBS="$LIBS -lusb",IOTYPE="posix")
+ have_posix="true"
+ AC_CHECK_LIB(usb,usb_init,have_libusb="true";LIBS="$LIBS -lusb")
;;
esac
@@ -37,8 +38,9 @@ AC_CHECK_HEADERS(ctype.h,,)
AC_CHECK_HEADERS(endian.h,,)
-
-
-AC_SUBST(IOTYPE)
+AM_CONDITIONAL([HAVE_IOKIT], [test x$have_iokit = xtrue])
+AM_CONDITIONAL([HAVE_WIN32], [test x$have_win32 = xtrue])
+AM_CONDITIONAL([HAVE_POSIX], [test x$have_posix = xtrue])
+AM_CONDITIONAL([HAVE_LIBUSB],[test x$have_libusb = xtrue])
AC_OUTPUT(Makefile)
diff --git a/io.c b/io.c
index 304e4ed..165962b 100644
--- a/io.c
+++ b/io.c
@@ -31,14 +31,7 @@ int io_driver_register(struct io_driver *driver)
return 0;
}
-struct io_driver *io_driver_at(int i)
-{
- if (i >= last_driver)
- return NULL;
- return drivers[i];
-}
-
-void io_driver_activate(struct io_driver *driver)
+static void io_driver_activate(struct io_driver *driver)
{
printf("Activating driver: %s\n", driver->name);
g_driver = driver;
@@ -63,3 +56,24 @@ int io_read(void *buff, int len)
{
return g_driver->io_read(buff, len);
}
+
+void io_driver_select_backend(const char *name)
+{
+ int i;
+ struct io_driver *driver = drivers[0];
+
+ for ( i = 0; ;++i) {
+ if (!drivers[i])
+ break;
+
+ if (name && strcmp("posix", drivers[i]->name) == 0) {
+ driver = drivers[i];
+ break;
+ } else if (!name && strcmp("libusb", drivers[i]->name) == 0) {
+ driver = drivers[i];
+ break;
+ }
+ }
+
+ io_driver_activate(driver);
+}
diff --git a/io.h b/io.h
index a8a916f..2e6f001 100644
--- a/io.h
+++ b/io.h
@@ -28,8 +28,7 @@ struct io_driver {
};
int io_driver_register(struct io_driver *driver);
-struct io_driver *io_driver_at(int);
-void io_driver_activate(struct io_driver *driver);
+void io_driver_select_backend(const char *line);
int io_init( char *dev );
int io_cleanup( void );
diff --git a/main.c b/main.c
index 8afd894..1a79554 100644
--- a/main.c
+++ b/main.c
@@ -88,8 +88,8 @@ int main( int argc, char *argv[] )
}
}
- /* Activate a default driver */
- io_driver_activate(io_driver_at(0));
+ /* If we have a path, attempt to use the posix backend */
+ io_driver_select_backend(line);
if( io_init( line ) < 0 ) {
fprintf(stderr, "Failed to initialize the SAM7 device.\n");