From 1f7d4a6aac0bfe45ac140545655f7e3b989d5062 Mon Sep 17 00:00:00 2001
From: NIIBE Yutaka <gniibe@fsij.org>
Date: Mon, 26 Jun 2017 19:50:55 +0900
Subject: Fix usb drivers.

---
 mcu/usb-mkl27z.c    | 38 +-------------------------------------
 mcu/usb-stm32f103.c | 39 +--------------------------------------
 mcu/usb-usbip.c     |  5 +----
 usb_lld.h           |  9 ++++++++-
 usb_lld_driver.h    | 37 +++++++++++++++++++++++++++++++++++++
 5 files changed, 48 insertions(+), 80 deletions(-)
 create mode 100644 usb_lld_driver.h

diff --git a/mcu/usb-mkl27z.c b/mcu/usb-mkl27z.c
index f5e5b2b..1492959 100644
--- a/mcu/usb-mkl27z.c
+++ b/mcu/usb-mkl27z.c
@@ -272,43 +272,7 @@ kl27z_ep_clear_dtog (int rx, uint8_t n)
   kl27z_ep_clear_stall (n);
 }
 
-#define USB_MAX_PACKET_SIZE 64	/* For FS device */
-
-enum STANDARD_REQUESTS {
-  GET_STATUS = 0,
-  CLEAR_FEATURE,
-  RESERVED1,
-  SET_FEATURE,
-  RESERVED2,
-  SET_ADDRESS,
-  GET_DESCRIPTOR,
-  SET_DESCRIPTOR,
-  GET_CONFIGURATION,
-  SET_CONFIGURATION,
-  GET_INTERFACE,
-  SET_INTERFACE,
-  SYNCH_FRAME,
-  TOTAL_REQUEST  /* Total number of Standard request */
-};
-
-
-enum FEATURE_SELECTOR {
-  FEATURE_ENDPOINT_HALT=0,
-  FEATURE_DEVICE_REMOTE_WAKEUP=1
-};
-
-
-/* The state machine states of a control pipe */
-enum {
-  WAIT_SETUP,
-  IN_DATA,
-  OUT_DATA,
-  LAST_IN_DATA,
-  WAIT_STATUS_IN,
-  WAIT_STATUS_OUT,
-  STALLED,
-  PAUSE
-};
+#include "usb_lld_driver.h"
 
 static int handle_transaction (struct usb_dev *dev, uint8_t stat);
 
diff --git a/mcu/usb-stm32f103.c b/mcu/usb-stm32f103.c
index a6e6850..3eed8cc 100644
--- a/mcu/usb-stm32f103.c
+++ b/mcu/usb-stm32f103.c
@@ -31,44 +31,7 @@
 
 #include "sys-stm32f103.h"
 #include "usb_lld.h"
-
-#define USB_MAX_PACKET_SIZE 64	/* For FS device */
-
-enum STANDARD_REQUESTS
-{
-  GET_STATUS = 0,
-  CLEAR_FEATURE,
-  RESERVED1,
-  SET_FEATURE,
-  RESERVED2,
-  SET_ADDRESS,
-  GET_DESCRIPTOR,
-  SET_DESCRIPTOR,
-  GET_CONFIGURATION,
-  SET_CONFIGURATION,
-  GET_INTERFACE,
-  SET_INTERFACE,
-  SYNCH_FRAME,
-  TOTAL_REQUEST  /* Total number of Standard request */
-};
-
-/* The state machine states of a control pipe */
-enum CONTROL_STATE
-{
-  WAIT_SETUP,
-  IN_DATA,
-  OUT_DATA,
-  LAST_IN_DATA,
-  WAIT_STATUS_IN,
-  WAIT_STATUS_OUT,
-  STALLED,
-};
-
-enum FEATURE_SELECTOR
-{
-  FEATURE_ENDPOINT_HALT=0,
-  FEATURE_DEVICE_REMOTE_WAKEUP=1
-};
+#include "usb_lld_driver.h"
 
 #define REG_BASE  (0x40005C00UL) /* USB_IP Peripheral Registers base address */
 #define PMA_ADDR  (0x40006000UL) /* USB_IP Packet Memory Area base address   */
diff --git a/mcu/usb-usbip.c b/mcu/usb-usbip.c
index ad19d43..9e585c8 100644
--- a/mcu/usb-usbip.c
+++ b/mcu/usb-usbip.c
@@ -47,7 +47,7 @@
 #include <poll.h>
 
 #include <usb_lld.h>
-#include <usb_lld_common.h>
+#include <usb_lld_driver.h>
 
 #include <alloca.h>
 
@@ -200,15 +200,12 @@ static struct usb_controller usbc;
 static void
 notify_device (uint8_t intr, uint8_t ep_num, uint8_t dir)
 {
-  extern sigset_t ss_cur;
-
   pthread_mutex_lock (&usbc.mutex);
   if (usbc.intr)
     pthread_cond_wait (&usbc.cond, &usbc.mutex);
   usbc.intr = intr;
   usbc.dir = (dir == USBIP_DIR_IN);
   usbc.ep_num = ep_num;
-  fprintf (stderr, "sigmask: %08llx\n", *(long long *)&ss_cur);
   pthread_kill (tid_main, SIGUSR1);
   pthread_mutex_unlock (&usbc.mutex);
 }
diff --git a/usb_lld.h b/usb_lld.h
index 2451ce4..c41a431 100644
--- a/usb_lld.h
+++ b/usb_lld.h
@@ -134,12 +134,19 @@ uint8_t usb_lld_current_configuration (struct usb_dev *dev);
 void usb_lld_prepare_shutdown (void);
 void usb_lld_shutdown (void);
 
-#ifdef MCU_KINETIS_L
+#if defined(MCU_KINETIS_L)
 void usb_lld_tx_enable_buf (int ep_num, const void *buf, size_t len);
 void usb_lld_rx_enable_buf (int ep_num, void *buf, size_t len);
 
 void usb_lld_setup_endp (struct usb_dev *dev, int ep_num, int rx_en, int tx_en);
 void usb_lld_stall (int ep_num);
+#elif defined(GNU_LINUX_EMULATION)
+void usb_lld_tx_enable_buf (int ep_num, const void *buf, size_t len);
+void usb_lld_rx_enable_buf (int ep_num, void *buf, size_t len);
+
+void usb_lld_setup_endp (struct usb_dev *dev, int ep_num, int rx_en, int tx_en);
+void usb_lld_stall_tx (int ep_num);
+void usb_lld_stall_rx (int ep_num);
 #else
 /* EP_TYPE[1:0] EndPoint TYPE */
 #define EP_BULK        (0x0000) /* EndPoint BULK        */
diff --git a/usb_lld_driver.h b/usb_lld_driver.h
new file mode 100644
index 0000000..6a4c95f
--- /dev/null
+++ b/usb_lld_driver.h
@@ -0,0 +1,37 @@
+#define USB_MAX_PACKET_SIZE 64	/* For FS device */
+
+enum STANDARD_REQUESTS
+{
+  GET_STATUS = 0,
+  CLEAR_FEATURE,
+  RESERVED1,
+  SET_FEATURE,
+  RESERVED2,
+  SET_ADDRESS,
+  GET_DESCRIPTOR,
+  SET_DESCRIPTOR,
+  GET_CONFIGURATION,
+  SET_CONFIGURATION,
+  GET_INTERFACE,
+  SET_INTERFACE,
+  SYNCH_FRAME,
+  TOTAL_REQUEST  /* Total number of Standard request */
+};
+
+/* The state machine states of a control pipe */
+enum CONTROL_STATE
+{
+  WAIT_SETUP,
+  IN_DATA,
+  OUT_DATA,
+  LAST_IN_DATA,
+  WAIT_STATUS_IN,
+  WAIT_STATUS_OUT,
+  STALLED,
+};
+
+enum FEATURE_SELECTOR
+{
+  FEATURE_ENDPOINT_HALT=0,
+  FEATURE_DEVICE_REMOTE_WAKEUP=1
+};
-- 
cgit v1.2.3