diff --git a/inc/usb.h b/inc/usb.h index 1145b00..24e1731 100644 --- a/inc/usb.h +++ b/inc/usb.h @@ -44,6 +44,9 @@ bool_t ep_tx_ready(uint8_t ep); * REQUIRES: ep_tx_ready(@ep) == TRUE */ void usb_write(uint8_t ep, const void *buf, uint32_t len); +/* Is the USB enumerated at High Speed? */ +bool_t usb_is_highspeed(void); + /* * Local variables: * mode: C diff --git a/src/floppy.c b/src/floppy.c index 2e96d59..1fe8a5a 100644 --- a/src/floppy.c +++ b/src/floppy.c @@ -615,10 +615,15 @@ static uint8_t floppy_write_prep(const struct gw_write_flux *wf) static void floppy_write_wait_data(void) { bool_t write_finished; + unsigned int u_buf_threshold; floppy_process_write_packet(); wdata_decode_flux(); + /* We don't wait for the massive F7 u_buf[] to fill at Full Speed. */ + u_buf_threshold = ((U_BUF_SZ > 16384) && !usb_is_highspeed()) + ? 16384 - 512 : U_BUF_SZ - 512; + /* Wait for DMA and input buffers to fill, or write stream to end. We must * take care because, since we are not yet draining the DMA buffer, the * write stream may end without us noticing and setting rw.write_finished. @@ -627,7 +632,7 @@ static void floppy_write_wait_data(void) ? rw.write_finished : (u_buf[U_MASK(u_prod-1)] == 0)); if (((dma.prod != (ARRAY_SIZE(dma.buf)-1)) - || ((uint32_t)(u_prod - u_cons) < (U_BUF_SZ - 512))) + || ((uint32_t)(u_prod - u_cons) < u_buf_threshold)) && !write_finished) return; diff --git a/src/usb/core.c b/src/usb/core.c index 4615b1d..e1f3fad 100644 --- a/src/usb/core.c +++ b/src/usb/core.c @@ -49,7 +49,7 @@ static bool_t handle_control_request(void) memcpy(ep0.data, device_qualifier, ep0.data_len); } } else if ((type == DESC_CONFIGURATION) && (idx == 0)) { - if (hw_is_highspeed()) { + if (usb_is_highspeed()) { ep0.data_len = config_hs_descriptor[2]; /* wTotalLength */ memcpy(ep0.data, config_hs_descriptor, ep0.data_len); } else { diff --git a/src/usb/defs.h b/src/usb/defs.h index 0fb6d63..497f06c 100644 --- a/src/usb/defs.h +++ b/src/usb/defs.h @@ -83,7 +83,6 @@ void usb_setaddr(uint8_t addr); void hw_usb_init(void); void hw_usb_deinit(void); bool_t hw_has_highspeed(void); -bool_t hw_is_highspeed(void); #define WARN printk diff --git a/src/usb/hw_dwc_otg.c b/src/usb/hw_dwc_otg.c index ffe871f..a9b8847 100644 --- a/src/usb/hw_dwc_otg.c +++ b/src/usb/hw_dwc_otg.c @@ -31,7 +31,7 @@ bool_t hw_has_highspeed(void) return conf_iface == IFACE_HS_EMBEDDED; } -bool_t hw_is_highspeed(void) +bool_t usb_is_highspeed(void) { return is_hs; } diff --git a/src/usb/hw_f1.c b/src/usb/hw_f1.c index 7b4e455..0619d18 100644 --- a/src/usb/hw_f1.c +++ b/src/usb/hw_f1.c @@ -27,7 +27,7 @@ bool_t hw_has_highspeed(void) return FALSE; } -bool_t hw_is_highspeed(void) +bool_t usb_is_highspeed(void) { return FALSE; }