Implement dcd_edpt_ISO_xfer() and adapt transmission scheme
This commit is contained in:
@@ -670,8 +670,13 @@ bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dcd_edpt_ISO_xfer (uint8_t rhport, uint8_t ep_addr, tu_fifo_t * ff, uint16_t total_bytes)
|
bool dcd_edpt_ISO_xfer (uint8_t rhport, uint8_t ep_addr, tu_fifo_t * ff)
|
||||||
{
|
{
|
||||||
|
// USB buffers always work in bytes so to avoid unnecessary divisions we demand item_size = 1
|
||||||
|
TU_ASSERT(ff->item_size == 1);
|
||||||
|
|
||||||
|
uint16_t total_bytes = tu_fifo_count(ff);
|
||||||
|
|
||||||
uint8_t const epnum = tu_edpt_number(ep_addr);
|
uint8_t const epnum = tu_edpt_number(ep_addr);
|
||||||
uint8_t const dir = tu_edpt_dir(ep_addr);
|
uint8_t const dir = tu_edpt_dir(ep_addr);
|
||||||
|
|
||||||
@@ -680,6 +685,16 @@ bool dcd_edpt_ISO_xfer (uint8_t rhport, uint8_t ep_addr, tu_fifo_t * ff, uint16_
|
|||||||
xfer->ff = ff;
|
xfer->ff = ff;
|
||||||
xfer->total_len = total_bytes;
|
xfer->total_len = total_bytes;
|
||||||
|
|
||||||
|
// Set copy mode to constant address - required since data copied to or from the hardware USB FIFO needs to be written at a constant address
|
||||||
|
if (dir == TUSB_DIR_IN)
|
||||||
|
{
|
||||||
|
tu_fifo_set_copy_mode_write(ff, TU_FIFO_COPY_CST);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tu_fifo_set_copy_mode_read(ff, TU_FIFO_COPY_CST);
|
||||||
|
}
|
||||||
|
|
||||||
// EP0 can only handle one packet
|
// EP0 can only handle one packet
|
||||||
if(epnum == 0) {
|
if(epnum == 0) {
|
||||||
ep0_pending[dir] = total_bytes;
|
ep0_pending[dir] = total_bytes;
|
||||||
@@ -692,9 +707,7 @@ bool dcd_edpt_ISO_xfer (uint8_t rhport, uint8_t ep_addr, tu_fifo_t * ff, uint16_
|
|||||||
uint8_t const short_packet_size = total_bytes % xfer->max_size;
|
uint8_t const short_packet_size = total_bytes % xfer->max_size;
|
||||||
|
|
||||||
// Zero-size packet is special case.
|
// Zero-size packet is special case.
|
||||||
if(short_packet_size > 0 || (total_bytes == 0)) {
|
if(short_packet_size > 0 || (total_bytes == 0)) num_packets++;
|
||||||
num_packets++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Schedule packets to be sent within interrupt
|
// Schedule packets to be sent within interrupt
|
||||||
edpt_schedule_packets(rhport, epnum, dir, num_packets, total_bytes);
|
edpt_schedule_packets(rhport, epnum, dir, num_packets, total_bytes);
|
||||||
@@ -900,14 +913,20 @@ static void handle_rxflvl_ints(uint8_t rhport, USB_OTG_OUTEndpointTypeDef * out_
|
|||||||
{
|
{
|
||||||
xfer_ctl_t * xfer = XFER_CTL_BASE(epnum, TUSB_DIR_OUT);
|
xfer_ctl_t * xfer = XFER_CTL_BASE(epnum, TUSB_DIR_OUT);
|
||||||
|
|
||||||
|
|
||||||
// TODO: TAKE CARE OF ISO FIFO!
|
|
||||||
|
|
||||||
// Read packet off RxFIFO
|
// Read packet off RxFIFO
|
||||||
|
if (xfer->buffer)
|
||||||
|
{
|
||||||
|
// Linear buffer
|
||||||
read_fifo_packet(rhport, xfer->buffer, bcnt);
|
read_fifo_packet(rhport, xfer->buffer, bcnt);
|
||||||
|
|
||||||
// Increment pointer to xfer data
|
// Increment pointer to xfer data
|
||||||
xfer->buffer += bcnt;
|
xfer->buffer += bcnt;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Ring buffer
|
||||||
|
tu_fifo_write_n(xfer->ff, (const void *) rx_fifo, bcnt);
|
||||||
|
}
|
||||||
|
|
||||||
// Truncate transfer length in case of short packet
|
// Truncate transfer length in case of short packet
|
||||||
if(bcnt < xfer->max_size) {
|
if(bcnt < xfer->max_size) {
|
||||||
@@ -1014,14 +1033,20 @@ static void handle_epin_ints(uint8_t rhport, USB_OTG_DeviceTypeDef * dev, USB_OT
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: TAKE CARE OF ISO FIFO!
|
|
||||||
|
|
||||||
// Push packet to Tx-FIFO
|
// Push packet to Tx-FIFO
|
||||||
|
if (xfer->buffer)
|
||||||
|
{
|
||||||
write_fifo_packet(rhport, n, xfer->buffer, packet_size);
|
write_fifo_packet(rhport, n, xfer->buffer, packet_size);
|
||||||
|
|
||||||
// Increment pointer to xfer data
|
// Increment pointer to xfer data
|
||||||
xfer->buffer += packet_size;
|
xfer->buffer += packet_size;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
usb_fifo_t tx_fifo = FIFO_BASE(rhport, n);
|
||||||
|
tu_fifo_read_n(xfer->ff, (void *) tx_fifo, packet_size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Turn off TXFE if all bytes are written.
|
// Turn off TXFE if all bytes are written.
|
||||||
if (((in_ep[n].DIEPTSIZ & USB_OTG_DIEPTSIZ_XFRSIZ_Msk) >> USB_OTG_DIEPTSIZ_XFRSIZ_Pos) == 0)
|
if (((in_ep[n].DIEPTSIZ & USB_OTG_DIEPTSIZ_XFRSIZ_Msk) >> USB_OTG_DIEPTSIZ_XFRSIZ_Pos) == 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user