<p>laforge has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/simtrace2/+/16611">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">host_communication: Send zero-length-packet on wMaxPacketSize<br><br>We need to send zero-length packets on bulk endpoints whenever the<br>transfer size is exactly a multiple of the wMaxPacketSize.<br><br>See USB 2.0 Specification Section 5.8.3 titled "Bulk Transfer Packet<br>Size constraints."<br><br>Change-Id: Ice3842399d5a5c4a18383860f81074497c6e7c9b<br>Closes: OS#4331<br>---<br>M firmware/atmel_softpack_libraries/libchip_sam3s/source/USBD_HAL.c<br>M firmware/atmel_softpack_libraries/usb/include/USBD.h<br>M firmware/libcommon/source/host_communication.c<br>3 files changed, 18 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/simtrace2 refs/changes/11/16611/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/firmware/atmel_softpack_libraries/libchip_sam3s/source/USBD_HAL.c b/firmware/atmel_softpack_libraries/libchip_sam3s/source/USBD_HAL.c</span><br><span>index 0eccc65..ac2595c 100644</span><br><span>--- a/firmware/atmel_softpack_libraries/libchip_sam3s/source/USBD_HAL.c</span><br><span>+++ b/firmware/atmel_softpack_libraries/libchip_sam3s/source/USBD_HAL.c</span><br><span>@@ -1077,6 +1077,14 @@</span><br><span>  *      Exported functions</span><br><span>  *---------------------------------------------------------------------------*/</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+uint16_t USBD_GetEndpointSize(uint8_t bEndpoint)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+    Endpoint *pEndpoint = &(endpoints[bEndpoint]);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    return pEndpoint->size;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /**</span><br><span>  * USBD (UDP) interrupt handler</span><br><span>  * Manages device resume, suspend, end of bus reset.</span><br><span>diff --git a/firmware/atmel_softpack_libraries/usb/include/USBD.h b/firmware/atmel_softpack_libraries/usb/include/USBD.h</span><br><span>index 15a6859..6fc931f 100644</span><br><span>--- a/firmware/atmel_softpack_libraries/usb/include/USBD.h</span><br><span>+++ b/firmware/atmel_softpack_libraries/usb/include/USBD.h</span><br><span>@@ -214,6 +214,8 @@</span><br><span>  *         Exported functions</span><br><span>  *------------------------------------------------------------------------------*/</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+extern uint16_t USBD_GetEndpointSize(uint8_t bEndpoint);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> //extern void USBD_IrqHandler(void);</span><br><span> </span><br><span> extern void USBD_Init(void);</span><br><span>diff --git a/firmware/libcommon/source/host_communication.c b/firmware/libcommon/source/host_communication.c</span><br><span>index 0e496c5..9a6e5b3 100644</span><br><span>--- a/firmware/libcommon/source/host_communication.c</span><br><span>+++ b/firmware/libcommon/source/host_communication.c</span><br><span>@@ -33,10 +33,18 @@</span><br><span> {</span><br><span>      struct msgb *msg = (struct msgb *) arg;</span><br><span>      struct usb_buffered_ep *bep = msg->dst;</span><br><span style="color: hsl(120, 100%, 40%);">+    uint16_t ep_size = USBD_GetEndpointSize(bep->ep);</span><br><span>         unsigned long x;</span><br><span> </span><br><span>         TRACE_DEBUG("%s (EP=0x%02x)\r\n", __func__, bep->ep);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+        if (((msgb_length(msg) % ep_size) == 0) && (transferred == ep_size)) {</span><br><span style="color: hsl(120, 100%, 40%);">+                /* terminate with ZLP; pass in 'msg' again as 'arg' so we get</span><br><span style="color: hsl(120, 100%, 40%);">+          * called the second time and proceed with usb_buf_free below */</span><br><span style="color: hsl(120, 100%, 40%);">+              USBD_Write(bep->ep, 0, 0, (TransferCallback) &usb_write_cb, msg);</span><br><span style="color: hsl(120, 100%, 40%);">+              return;</span><br><span style="color: hsl(120, 100%, 40%);">+       }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>  local_irq_save(x);</span><br><span>   bep->in_progress--;</span><br><span>       local_irq_restore(x);</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/simtrace2/+/16611">change 16611</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/simtrace2/+/16611"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: simtrace2 </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: Ice3842399d5a5c4a18383860f81074497c6e7c9b </div>
<div style="display:none"> Gerrit-Change-Number: 16611 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: laforge <laforge@osmocom.org> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>