Kaynağa Gözat

usb: Cleaner interface for configuring a double-buffered pipe

Keir Fraser 5 yıl önce
ebeveyn
işleme
b941c8a9bf
3 değiştirilmiş dosya ile 14 ekleme ve 11 silme
  1. 4 2
      src/usb/cdc_acm.c
  2. 1 0
      src/usb/defs.h
  3. 9 9
      src/usb/hw_f1.c

+ 4 - 2
src/usb/cdc_acm.c

@@ -92,12 +92,14 @@ bool_t cdc_acm_handle_class_request(void)
 
 bool_t cdc_acm_set_configuration(void)
 {
+    uint8_t bulk_type = USB_EP_TYPE_BULK_DBLBUF;
+
     /* Notification Element (D->H) */
     usb_configure_ep(0x81, USB_EP_TYPE_INTERRUPT, 0);
     /* Bulk Pipe (H->D) */
-    usb_configure_ep(0x02, USB_EP_TYPE_BULK, 2*USB_FS_MPS);
+    usb_configure_ep(0x02, bulk_type, USB_FS_MPS);
     /* Bulk Pipe (D->H) */
-    usb_configure_ep(0x83, USB_EP_TYPE_BULK, 2*USB_FS_MPS);
+    usb_configure_ep(0x83, bulk_type, USB_FS_MPS);
 
     floppy_configured();
 

+ 1 - 0
src/usb/defs.h

@@ -71,6 +71,7 @@ extern uint8_t pending_addr;
 bool_t handle_control_request(void);
 
 /* USB Hardware */
+#define USB_EP_TYPE_BULK_DBLBUF 4u /* Create a double-buffered Endpoint */
 void usb_configure_ep(uint8_t ep, uint8_t type, uint32_t size);
 
 #define WARN printk

+ 9 - 9
src/usb/hw_f1.c

@@ -204,22 +204,22 @@ void usb_configure_ep(uint8_t ep, uint8_t type, uint32_t size)
     bd = &usb_bufd[ep];
 
     old_epr = usb->epr[ep];
+    new_epr = 0;
 
-    /* Sets: Type and Endpoint Address.
-     * Clears: CTR_RX and CTR_TX. */
-    new_epr = USB_EPR_EP_TYPE(type) | USB_EPR_EA(ep);
-
-    dbl_buf = (size > USB_FS_MPS);
+    dbl_buf = (type == USB_EP_TYPE_BULK_DBLBUF);
     if (dbl_buf) {
         ASSERT(ep != 0);
-        ASSERT(type == USB_EP_TYPE_BULK);
-        ASSERT(size == 2*USB_FS_MPS);
+        type = USB_EP_TYPE_BULK;
         new_epr |= USB_EPR_EP_KIND_DBL_BUF;
         bd->addr_0 = buf_end;
-        bd->addr_1 = buf_end + size/2;
-        buf_end += size;
+        bd->addr_1 = buf_end + size;
+        buf_end += 2*size;
     }
 
+    /* Sets: Type and Endpoint Address.
+     * Clears: CTR_RX and CTR_TX. */
+    new_epr |= USB_EPR_EP_TYPE(type) | USB_EPR_EA(ep);
+
     if (in || (ep == 0)) {
         if (dbl_buf) {
             bd->count_0 = bd->count_1 = 0;