Change FIFO use indication to ff == NULL to avoid future errors.

This way people don't need to pay attention for the buffer pointer
This commit is contained in:
Reinhard Panhuber
2021-02-14 09:25:34 +01:00
parent b634b5958b
commit 893f997dcb
6 changed files with 63 additions and 57 deletions

View File

@@ -144,13 +144,13 @@ static void dcd_in_xfer(struct xfer_ctl_t *xfer, USBD_EP_T *ep)
{
uint16_t bytes_now = tu_min16(xfer->in_remaining_bytes, xfer->max_packet_size);
if (xfer->data_ptr)
if (xfer->ff)
{
memcpy((uint8_t *)(USBD_BUF_BASE + ep->BUFSEG), xfer->data_ptr, bytes_now);
tu_fifo_read_n(xfer->ff, (void *) (USBD_BUF_BASE + ep->BUFSEG), bytes_now);
}
else
{
tu_fifo_read_n(xfer->ff, (void *) (USBD_BUF_BASE + ep->BUFSEG), bytes_now);
memcpy((uint8_t *)(USBD_BUF_BASE + ep->BUFSEG), xfer->data_ptr, bytes_now);
}
ep->MXPLD = bytes_now;
@@ -277,6 +277,7 @@ bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t *buffer, uint16_t to
/* store away the information we'll needing now and later */
xfer->data_ptr = buffer;
xfer->ff = NULL;
xfer->in_remaining_bytes = total_bytes;
xfer->total_bytes = total_bytes;
@@ -429,14 +430,14 @@ void dcd_int_handler(uint8_t rhport)
if (out_ep)
{
/* copy the data from the PC to the previously provided buffer */
if (xfer->data_ptr)
if (xfer->ff)
{
memcpy(xfer->data_ptr, (uint8_t *)(USBD_BUF_BASE + ep->BUFSEG), available_bytes);
xfer->data_ptr += available_bytes;
tu_fifo_write_n(xfer->ff, (const void *) (USBD_BUF_BASE + ep->BUFSEG), available_bytes);
}
else
{
tu_fifo_write_n(xfer->ff, (const void *) (USBD_BUF_BASE + ep->BUFSEG), available_bytes);
memcpy(xfer->data_ptr, (uint8_t *)(USBD_BUF_BASE + ep->BUFSEG), available_bytes);
xfer->data_ptr += available_bytes;
}
xfer->out_bytes_so_far += available_bytes;
@@ -452,8 +453,7 @@ void dcd_int_handler(uint8_t rhport)
/* update the bookkeeping to reflect the data that has now been sent to the PC */
xfer->in_remaining_bytes -= available_bytes;
/* increment only if xfer->data_ptr != NULL - if xfer->data_ptr == NULL then a FIFO is used for which xfer->data_ptr MUST STAY ZERO! */
if (xfer->data_ptr) xfer->data_ptr += available_bytes;
xfer->data_ptr += available_bytes;
/* if more data to send, send it; otherwise, alert TinyUSB that we've finished */
if (xfer->in_remaining_bytes)

View File

@@ -144,13 +144,13 @@ static void dcd_in_xfer(struct xfer_ctl_t *xfer, USBD_EP_T *ep)
{
uint16_t bytes_now = tu_min16(xfer->in_remaining_bytes, xfer->max_packet_size);
if (xfer->data_ptr)
if (xfer->ff)
{
memcpy((uint8_t *)(USBD_BUF_BASE + ep->BUFSEG), xfer->data_ptr, bytes_now);
tu_fifo_read_n(xfer->ff, (void *) (USBD_BUF_BASE + ep->BUFSEG), bytes_now);
}
else
{
tu_fifo_read_n(xfer->ff, (void *) (USBD_BUF_BASE + ep->BUFSEG), bytes_now);
memcpy((uint8_t *)(USBD_BUF_BASE + ep->BUFSEG), xfer->data_ptr, bytes_now);
}
ep->MXPLD = bytes_now;
@@ -281,6 +281,7 @@ bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t *buffer, uint16_t to
/* store away the information we'll needing now and later */
xfer->data_ptr = buffer;
xfer->ff = NULL;
xfer->in_remaining_bytes = total_bytes;
xfer->total_bytes = total_bytes;
@@ -438,14 +439,14 @@ void dcd_int_handler(uint8_t rhport)
if (out_ep)
{
/* copy the data from the PC to the previously provided buffer */
if (xfer->data_ptr)
if (xfer->ff)
{
memcpy(xfer->data_ptr, (uint8_t *)(USBD_BUF_BASE + ep->BUFSEG), available_bytes);
xfer->data_ptr += available_bytes;
tu_fifo_write_n(xfer->ff, (const void *) (USBD_BUF_BASE + ep->BUFSEG), available_bytes);
}
else
{
tu_fifo_write_n(xfer->ff, (const void *) (USBD_BUF_BASE + ep->BUFSEG), available_bytes);
memcpy(xfer->data_ptr, (uint8_t *)(USBD_BUF_BASE + ep->BUFSEG), available_bytes);
xfer->data_ptr += available_bytes;
}
xfer->out_bytes_so_far += available_bytes;
@@ -460,7 +461,7 @@ void dcd_int_handler(uint8_t rhport)
{
/* update the bookkeeping to reflect the data that has now been sent to the PC */
xfer->in_remaining_bytes -= available_bytes;
if (xfer->data_ptr) xfer->data_ptr += available_bytes;
xfer->data_ptr += available_bytes;
/* if more data to send, send it; otherwise, alert TinyUSB that we've finished */
if (xfer->in_remaining_bytes)

View File

@@ -181,7 +181,11 @@ static void dcd_userEP_in_xfer(struct xfer_ctl_t *xfer, USBD_EP_T *ep)
}
/* provided buffers are thankfully 32-bit aligned, allowing most data to be transfered as 32-bit */
if (xfer->data_ptr)
if (xfer->ff)
{
tu_fifo_read_n(xfer->ff, (void *) (ep->EPDAT_BYTE), bytes_now);
}
else
{
uint16_t countdown = bytes_now;
while (countdown > 3)
@@ -195,10 +199,6 @@ static void dcd_userEP_in_xfer(struct xfer_ctl_t *xfer, USBD_EP_T *ep)
while (countdown--)
ep->EPDAT_BYTE = *xfer->data_ptr++;
}
else
{
tu_fifo_read_n(xfer->ff, (void *) (ep->EPDAT_BYTE), bytes_now);
}
/* for short packets, we must nudge the peripheral to say 'that's all folks' */
if (bytes_now != xfer->max_packet_size)
@@ -394,6 +394,7 @@ bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t *buffer, uint16_t to
/* store away the information we'll needing now and later */
xfer->data_ptr = buffer;
xfer->ff = NULL;
xfer->in_remaining_bytes = total_bytes;
xfer->total_bytes = total_bytes;
@@ -656,14 +657,15 @@ void dcd_int_handler(uint8_t rhport)
#else
uint16_t const available_bytes = ep->EPDATCNT & USBD_EPDATCNT_DATCNT_Msk;
/* copy the data from the PC to the previously provided buffer */
if (xfer->data_ptr)
if (xfer->ff)
{
for (int count = 0; (count < available_bytes) && (xfer->out_bytes_so_far < xfer->total_bytes); count++, xfer->out_bytes_so_far++)
*xfer->data_ptr++ = ep->EPDAT_BYTE;
tu_fifo_write_n(xfer->ff, (const void *) &ep->EPDAT_BYTE, tu_min16(available_bytes, xfer->total_bytes - xfer->out_bytes_so_far));
}
else
{
tu_fifo_write_n(xfer->ff, (const void *) &ep->EPDAT_BYTE, tu_min16(available_bytes, xfer->total_bytes - xfer->out_bytes_so_far));
for (int count = 0; (count < available_bytes) && (xfer->out_bytes_so_far < xfer->total_bytes); count++, xfer->out_bytes_so_far++)
*xfer->data_ptr++ = ep->EPDAT_BYTE;
}
/* when the transfer is finished, alert TinyUSB; otherwise, continue accepting more data */