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.
This commit is contained in:
parent
587730174f
commit
74ae64b355
16
Makefile.am
16
Makefile.am
|
@ -4,7 +4,21 @@ AUTOMAKE_OPTIONS = gnu
|
||||||
|
|
||||||
bin_PROGRAMS = sam7
|
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
|
noinst_HEADERS = io.h samba.h cmd.h loader128_data.h loader256_data.h
|
||||||
|
|
||||||
EXTRA_DIST = driver/Makefile driver/at91.c \
|
EXTRA_DIST = driver/Makefile driver/at91.c \
|
||||||
|
|
14
configure.in
14
configure.in
|
@ -15,14 +15,15 @@ AC_PROG_MAKE_SET
|
||||||
case "${host}" in
|
case "${host}" in
|
||||||
*-*-darwin* )
|
*-*-darwin* )
|
||||||
LIBS="$LIBS -framework IOKIT -framework CoreFoundation"
|
LIBS="$LIBS -framework IOKIT -framework CoreFoundation"
|
||||||
IOTYPE="iokit"
|
have_iokit="true"
|
||||||
;;
|
;;
|
||||||
*-*-cygwin* )
|
*-*-cygwin* )
|
||||||
LIBS="$LIBS -lsetupapi"
|
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
|
esac
|
||||||
|
@ -37,8 +38,9 @@ AC_CHECK_HEADERS(ctype.h,,)
|
||||||
AC_CHECK_HEADERS(endian.h,,)
|
AC_CHECK_HEADERS(endian.h,,)
|
||||||
|
|
||||||
|
|
||||||
|
AM_CONDITIONAL([HAVE_IOKIT], [test x$have_iokit = xtrue])
|
||||||
|
AM_CONDITIONAL([HAVE_WIN32], [test x$have_win32 = xtrue])
|
||||||
AC_SUBST(IOTYPE)
|
AM_CONDITIONAL([HAVE_POSIX], [test x$have_posix = xtrue])
|
||||||
|
AM_CONDITIONAL([HAVE_LIBUSB],[test x$have_libusb = xtrue])
|
||||||
|
|
||||||
AC_OUTPUT(Makefile)
|
AC_OUTPUT(Makefile)
|
||||||
|
|
30
io.c
30
io.c
|
@ -31,14 +31,7 @@ int io_driver_register(struct io_driver *driver)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct io_driver *io_driver_at(int i)
|
static void io_driver_activate(struct io_driver *driver)
|
||||||
{
|
|
||||||
if (i >= last_driver)
|
|
||||||
return NULL;
|
|
||||||
return drivers[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
void io_driver_activate(struct io_driver *driver)
|
|
||||||
{
|
{
|
||||||
printf("Activating driver: %s\n", driver->name);
|
printf("Activating driver: %s\n", driver->name);
|
||||||
g_driver = driver;
|
g_driver = driver;
|
||||||
|
@ -63,3 +56,24 @@ int io_read(void *buff, int len)
|
||||||
{
|
{
|
||||||
return g_driver->io_read(buff, 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);
|
||||||
|
}
|
||||||
|
|
3
io.h
3
io.h
|
@ -28,8 +28,7 @@ struct io_driver {
|
||||||
};
|
};
|
||||||
|
|
||||||
int io_driver_register(struct io_driver *driver);
|
int io_driver_register(struct io_driver *driver);
|
||||||
struct io_driver *io_driver_at(int);
|
void io_driver_select_backend(const char *line);
|
||||||
void io_driver_activate(struct io_driver *driver);
|
|
||||||
|
|
||||||
int io_init( char *dev );
|
int io_init( char *dev );
|
||||||
int io_cleanup( void );
|
int io_cleanup( void );
|
||||||
|
|
4
main.c
4
main.c
|
@ -88,8 +88,8 @@ int main( int argc, char *argv[] )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Activate a default driver */
|
/* If we have a path, attempt to use the posix backend */
|
||||||
io_driver_activate(io_driver_at(0));
|
io_driver_select_backend(line);
|
||||||
|
|
||||||
if( io_init( line ) < 0 ) {
|
if( io_init( line ) < 0 ) {
|
||||||
fprintf(stderr, "Failed to initialize the SAM7 device.\n");
|
fprintf(stderr, "Failed to initialize the SAM7 device.\n");
|
||||||
|
|
Reference in New Issue