]> git.zerfleddert.de Git - usb-driver/commitdiff
move XPCU transfer function
authorMichael Gernoth <michael@gernoth.net>
Fri, 11 Apr 2008 13:16:28 +0000 (15:16 +0200)
committerMichael Gernoth <michael@gernoth.net>
Fri, 11 Apr 2008 13:16:28 +0000 (15:16 +0200)
usb-driver.c
xpcu.c
xpcu.h

index 647a5bcf2ba7be8a6a13a0172e6c7476b4713398..53a0309f6b93cc555770288519c74fd7e93dd2c1 100644 (file)
@@ -160,32 +160,7 @@ static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
 #ifndef NO_WINDRVR
                                ret = (*ioctl_func) (fd, request, wdioctl);
 #else
-                               xpcu_claim(xpcu, XPCU_CLAIM);
-                               /* http://www.jungo.com/support/documentation/windriver/802/wdusb_man_mhtml/node55.html#SECTION001213000000000000000 */
-                               if (ut->dwPipeNum == 0) { /* control pipe */
-                                       int requesttype, request, value, index, size;
-                                       requesttype = ut->SetupPacket[0];
-                                       request = ut->SetupPacket[1];
-                                       value = ut->SetupPacket[2] | (ut->SetupPacket[3] << 8);
-                                       index = ut->SetupPacket[4] | (ut->SetupPacket[5] << 8);
-                                       size = ut->SetupPacket[6] | (ut->SetupPacket[7] << 8);
-                                       DPRINTF("requesttype: %x, request: %x, value: %u, index: %u, size: %u\n", requesttype, request, value, index, size);
-                                       ret = usb_control_msg(xpcu->handle, requesttype, request, value, index, ut->pBuffer, size, ut->dwTimeout);
-                               } else {
-                                       if (ut->fRead) {
-                                               ret = usb_bulk_read(xpcu->handle, ut->dwPipeNum, ut->pBuffer, ut->dwBufferSize, ut->dwTimeout);
-                                       } else {
-                                               ret = usb_bulk_write(xpcu->handle, ut->dwPipeNum, ut->pBuffer, ut->dwBufferSize, ut->dwTimeout);
-                                       }
-                                       xpcu_claim(xpcu, XPCU_RELEASE);
-                               }
-
-                               if (ret < 0) {
-                                       fprintf(stderr, "usb_transfer: %d (%s)\n", ret, usb_strerror());
-                               } else {
-                                       ut->dwBytesTransferred = ret;
-                                       ret = 0;
-                               }
+                               xpcu_transfer(xpcu, ut);
 #endif
 
 #ifdef DEBUG
diff --git a/xpcu.c b/xpcu.c
index a37826b46b63dd06bce0143b80832f0f6c05f86f..28770fe6eba169a0690d52952443a593d29c7b54 100644 (file)
--- a/xpcu.c
+++ b/xpcu.c
@@ -3,8 +3,8 @@
 #include <unistd.h>
 #include <strings.h>
 #include <usb.h>
-#include "xpcu.h"
 #include "usb-driver.h"
+#include "xpcu.h"
 
 int xpcu_deviceinfo(struct xpcu_s *xpcu, unsigned char *buf) {
        int i,j,k,l;
@@ -199,6 +199,39 @@ int xpcu_claim(struct xpcu_s *xpcu, int claim) {
        return ret;
 }
 
+int xpcu_transfer(struct xpcu_s *xpcu, struct usb_transfer *ut) {
+       int ret = 0;
+
+       xpcu_claim(xpcu, XPCU_CLAIM);
+       /* http://www.jungo.com/support/documentation/windriver/802/wdusb_man_mhtml/node55.html#SECTION001213000000000000000 */
+       if (ut->dwPipeNum == 0) { /* control pipe */
+               int requesttype, request, value, index, size;
+               requesttype = ut->SetupPacket[0];
+               request = ut->SetupPacket[1];
+               value = ut->SetupPacket[2] | (ut->SetupPacket[3] << 8);
+               index = ut->SetupPacket[4] | (ut->SetupPacket[5] << 8);
+               size = ut->SetupPacket[6] | (ut->SetupPacket[7] << 8);
+               DPRINTF("requesttype: %x, request: %x, value: %u, index: %u, size: %u\n", requesttype, request, value, index, size);
+               ret = usb_control_msg(xpcu->handle, requesttype, request, value, index, ut->pBuffer, size, ut->dwTimeout);
+       } else {
+               if (ut->fRead) {
+                       ret = usb_bulk_read(xpcu->handle, ut->dwPipeNum, ut->pBuffer, ut->dwBufferSize, ut->dwTimeout);
+               } else {
+                       ret = usb_bulk_write(xpcu->handle, ut->dwPipeNum, ut->pBuffer, ut->dwBufferSize, ut->dwTimeout);
+               }
+               xpcu_claim(xpcu, XPCU_RELEASE);
+       }
+
+       if (ret < 0) {
+               fprintf(stderr, "usb_transfer: %d (%s)\n", ret, usb_strerror());
+       } else {
+               ut->dwBytesTransferred = ret;
+               ret = 0;
+       }
+
+       return ret;
+}
+
 struct xpcu_s *xpcu_open(void) {
        static struct xpcu_s xpcu;
 
diff --git a/xpcu.h b/xpcu.h
index 611496c78f8ce978c442e2c693bc6d97277c0e4f..9583ed2cb4ce05601abc1d684fdc2fc866867f29 100644 (file)
--- a/xpcu.h
+++ b/xpcu.h
@@ -11,4 +11,5 @@ struct xpcu_s {
 
 int __attribute__ ((visibility ("hidden"))) xpcu_deviceinfo(struct xpcu_s *xpcu, unsigned char *buf);
 int __attribute__ ((visibility ("hidden"))) xpcu_claim(struct xpcu_s *xpcu, int claim);
+int __attribute__ ((visibility ("hidden"))) xpcu_transfer(struct xpcu_s *xpcu, struct usb_transfer *ut);
 struct xpcu_s __attribute__ ((visibility ("hidden"))) *xpcu_open(void);
Impressum, Datenschutz