r3100 - in trunk/src/host: . usbreset

werner at sita.openmoko.org werner at sita.openmoko.org
Sun Oct 7 11:45:01 CEST 2007


Author: werner
Date: 2007-10-07 11:44:53 +0200 (Sun, 07 Oct 2007)
New Revision: 3100

Added:
   trunk/src/host/usbreset/
   trunk/src/host/usbreset/Makefile.am
   trunk/src/host/usbreset/README
   trunk/src/host/usbreset/autogen.sh
   trunk/src/host/usbreset/configure.ac
   trunk/src/host/usbreset/usbreset.c
Log:
- usbreset/: moved from developers/werner to trunk/src/host
- usbreset.c: added copyright header
- Makefile: removed, using autotools instead
- usbreset.c (main): added support for selecting a specific device
- README: usage and build instructions



Added: trunk/src/host/usbreset/Makefile.am
===================================================================
--- trunk/src/host/usbreset/Makefile.am	2007-10-07 09:42:55 UTC (rev 3099)
+++ trunk/src/host/usbreset/Makefile.am	2007-10-07 09:44:53 UTC (rev 3100)
@@ -0,0 +1,5 @@
+AM_CFLAGS = -Wall
+
+bin_PROGRAMS = usbreset
+
+usbreset_SOURCES = usbreset.c

Added: trunk/src/host/usbreset/README
===================================================================
--- trunk/src/host/usbreset/README	2007-10-07 09:42:55 UTC (rev 3099)
+++ trunk/src/host/usbreset/README	2007-10-07 09:44:53 UTC (rev 3100)
@@ -0,0 +1,24 @@
+usbreset - Reset one or all USB devices
+=======================================
+
+"usbreset" performs a USB bus reset for one or all devices.
+
+If invoked without arguments, all devices on all USB busses are reset.
+
+If a bus/devnum pair is specified, only that device is reset. The bus
+and device number can be obtained with lsusb. E.g.,
+
+# lsusb
+Bus 001 Device 005: ID 047d:101f Kensington PocketMouse Pro
+# usbreset 1/5
+
+would reset the mouse in this example.
+
+
+Compilation and installation
+----------------------------
+
+./autogen.sh
+./confgure
+make
+make install

Added: trunk/src/host/usbreset/autogen.sh
===================================================================
--- trunk/src/host/usbreset/autogen.sh	2007-10-07 09:42:55 UTC (rev 3099)
+++ trunk/src/host/usbreset/autogen.sh	2007-10-07 09:44:53 UTC (rev 3100)
@@ -0,0 +1,2 @@
+#! /bin/sh
+AUTOMAKE="automake --foreign --add-missing --copy" autoreconf


Property changes on: trunk/src/host/usbreset/autogen.sh
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/src/host/usbreset/configure.ac
===================================================================
--- trunk/src/host/usbreset/configure.ac	2007-10-07 09:42:55 UTC (rev 3099)
+++ trunk/src/host/usbreset/configure.ac	2007-10-07 09:44:53 UTC (rev 3100)
@@ -0,0 +1,12 @@
+AC_INIT([usbreset],[0.1])
+AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)
+
+AC_PROG_CC
+
+PKG_CHECK_MODULES(USB, libusb,,
+  AC_MSG_ERROR([*** Required libusb not installed ***]))
+
+LIBS="$LIBS $USB_LIBS"
+
+AC_CONFIG_FILES(Makefile)
+AC_OUTPUT

Added: trunk/src/host/usbreset/usbreset.c
===================================================================
--- trunk/src/host/usbreset/usbreset.c	2007-10-07 09:42:55 UTC (rev 3099)
+++ trunk/src/host/usbreset/usbreset.c	2007-10-07 09:44:53 UTC (rev 3100)
@@ -0,0 +1,93 @@
+/*
+ * usbreset.c - Reset one or all USB devices
+ *
+ * (C) 2007 by OpenMoko, Inc.
+ * Written by Werner Almesberger <werner at openmoko.org>
+ *
+ * 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
+ */
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <usb.h>
+
+
+static void usage(const char *name)
+{
+	fprintf(stderr, "usage: %s [bus/device]\n", name);
+	exit(1);
+}
+
+
+int main(int argc, const char **argv)
+{
+	struct usb_bus *usb_bus;
+	struct usb_device *dev;
+	int all = 0;
+	int bus_num, dev_num;
+
+	switch (argc) {
+		case 1:
+			all = 1;
+			break;
+		case 2:
+			if (sscanf(argv[1], "%d/%d", &bus_num, &dev_num) != 2)
+				usage(*argv);
+			break;
+		case 3:
+			usage(*argv);
+	}
+
+	usb_init();
+	usb_find_busses();
+	usb_find_devices();
+        for (usb_bus = usb_get_busses(); usb_bus; usb_bus = usb_bus->next)
+		for (dev = usb_bus->devices; dev; dev = dev->next) {
+			struct usb_dev_handle *handle;
+
+			if (dev->descriptor.bDeviceClass == USB_CLASS_HUB)
+				continue;
+			if (!all &&
+			    (atoi(usb_bus->dirname) != bus_num ||
+			    dev->devnum != dev_num))
+				continue;
+
+			handle = usb_open(dev);
+			if (!handle) {
+				fprintf(stderr, "usb_open: %s\n",
+				    usb_strerror());
+				continue;
+			}
+			if (usb_reset(handle) < 0) {
+				fprintf(stderr, "usb_reset: %s\n",
+				    usb_strerror());
+				continue;
+			}
+
+			if (!all)
+				return 0;
+
+			fprintf(stderr,"reset %s/%s\n",
+			    usb_bus->dirname, dev->filename);
+		}
+
+	if (!all) {
+		fprintf(stderr, "no device %d/%d found\n", bus_num, dev_num);
+		return 1;
+	}
+
+	return 0;
+}





More information about the commitlog mailing list