Skip to content

Commit 2d53612

Browse files
committed
finish moving edpt stream to tusb.c
1 parent e3c9d94 commit 2d53612

File tree

2 files changed

+43
-30
lines changed

2 files changed

+43
-30
lines changed

src/class/cdc/cdc_host.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,8 @@ bool cdch_xfer_cb(uint8_t daddr, uint8_t ep_addr, xfer_result_t event, uint32_t
340340

341341
if ( 0 == tu_edpt_stream_write_xfer(&p_cdc->stream.tx) )
342342
{
343-
// If there is no data left, a ZLP should be sent if needed
344-
// xferred_bytes is multiple of EP Packet size and not zero
343+
// If there is no data left, a ZLP should be sent if:
344+
// - xferred_bytes is multiple of EP Packet size and not zero
345345
tu_edpt_stream_write_zlp_if_needed(&p_cdc->stream.tx, xferred_bytes);
346346
}
347347
}

src/tusb.c

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,41 @@ bool stream_claim(tu_edpt_stream_t* s)
242242
return false;
243243
}
244244

245+
TU_ATTR_ALWAYS_INLINE static inline
246+
bool stream_xfer(tu_edpt_stream_t* s, uint16_t count)
247+
{
248+
if (s->is_host)
249+
{
250+
#if CFG_TUH_ENABLED
251+
return usbh_edpt_xfer(s->daddr, s->ep_addr, count ? s->ep_buf : NULL, count);
252+
#endif
253+
}else
254+
{
255+
#if CFG_TUD_ENABLED
256+
return usbd_edpt_xfer(s->rhport, s->ep_addr, cont ? s->ep_buf : NULL, count);
257+
#endif
258+
}
259+
260+
return false;
261+
}
262+
263+
TU_ATTR_ALWAYS_INLINE static inline
264+
bool stream_release(tu_edpt_stream_t* s)
265+
{
266+
if (s->is_host)
267+
{
268+
#if CFG_TUH_ENABLED
269+
return usbh_edpt_release(s->daddr, s->ep_addr);
270+
#endif
271+
}else
272+
{
273+
#if CFG_TUD_ENABLED
274+
return usbd_edpt_release(s->rhport, s->ep_addr);
275+
#endif
276+
}
277+
278+
return false;
279+
}
245280

246281
//--------------------------------------------------------------------+
247282
// Stream Write
@@ -253,7 +288,7 @@ bool tu_edpt_stream_write_zlp_if_needed(tu_edpt_stream_t* s, uint32_t last_xferr
253288
TU_VERIFY( !tu_fifo_count(&s->ff) && last_xferred_bytes && (0 == (last_xferred_bytes & (s->ep_packetsize-1))) );
254289

255290
TU_VERIFY( stream_claim(s) );
256-
TU_ASSERT( usbh_edpt_xfer(s->daddr, s->ep_addr, NULL, 0) );
291+
TU_ASSERT( stream_xfer(s, 0) );
257292

258293
return true;
259294
}
@@ -271,16 +306,13 @@ uint32_t tu_edpt_stream_write_xfer(tu_edpt_stream_t* s)
271306

272307
if ( count )
273308
{
274-
//TU_ASSERT( usbd_edpt_xfer(rhport, p_cdc->ep_in, p_cdc->epin_buf, count), 0 );
275-
TU_ASSERT( usbh_edpt_xfer(s->daddr, s->ep_addr, s->ep_buf, count), 0 );
309+
TU_ASSERT( stream_xfer(s, count), 0 );
276310
return count;
277311
}else
278312
{
279313
// Release endpoint since we don't make any transfer
280314
// Note: data is dropped if terminal is not connected
281-
//usbd_edpt_release(rhport, p_cdc->ep_in);
282-
283-
usbh_edpt_release(s->daddr, s->ep_addr);
315+
stream_release(s);
284316
return 0;
285317
}
286318
}
@@ -327,32 +359,13 @@ uint32_t tu_edpt_stream_read_xfer(tu_edpt_stream_t* s)
327359
uint16_t count = (uint16_t) (available & ~(s->ep_packetsize -1));
328360
count = tu_min16(count, s->ep_bufsize);
329361

330-
if (s->is_host)
331-
{
332-
#if CFG_TUH_ENABLED
333-
TU_ASSERT( usbh_edpt_xfer(s->daddr, s->ep_addr, s->ep_buf, count), 0 );
334-
#endif
335-
}else
336-
{
337-
#if CFG_TUD_ENABLED
338-
TU_ASSERT( usbd_edpt_xfer(s->rhport, s->ep_addr, s->ep_buf, count), 0 );
339-
#endif
340-
}
362+
TU_ASSERT( stream_xfer(s, count), 0 );
363+
341364
return count;
342365
}else
343366
{
344367
// Release endpoint since we don't make any transfer
345-
if (s->is_host)
346-
{
347-
#if CFG_TUH_ENABLED
348-
usbh_edpt_release(s->daddr, s->ep_addr);
349-
#endif
350-
}else
351-
{
352-
#if CFG_TUD_ENABLED
353-
usbd_edpt_release(s->rhport, s->ep_addr);
354-
#endif
355-
}
368+
stream_release(s);
356369

357370
return 0;
358371
}

0 commit comments

Comments
 (0)