summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorReinhard Panhuber <[email protected]>2021-04-30 17:37:14 +0200
committerReinhard Panhuber <[email protected]>2021-04-30 17:37:14 +0200
commit5add664874f4855491e28c3a869105eb25c5f4d7 (patch)
treeff387df13468a07782a8bf84d76033ecbf91a693 /src/common
parent6acfa14fec1805b6f875f4bdbe00360065e72731 (diff)
Remove n from tu_fifo_get_write_info() and fix bug in vendor class
Diffstat (limited to 'src/common')
-rw-r--r--src/common/tusb_fifo.c33
-rw-r--r--src/common/tusb_fifo.h2
2 files changed, 9 insertions, 26 deletions
diff --git a/src/common/tusb_fifo.c b/src/common/tusb_fifo.c
index c80bb1497..a386273f0 100644
--- a/src/common/tusb_fifo.c
+++ b/src/common/tusb_fifo.c
@@ -950,11 +950,9 @@ void tu_fifo_get_read_info(tu_fifo_t *f, tu_fifo_buffer_info_t *info)
Returns the length and pointer to which bytes can be written into FIFO in a linear manner.
This is of major interest for DMA transmissions not using circular mode. If a returned length is zero the
- corresponding pointer is invalid. The returned length is limited to the number of BYTES n which the user
- wants to write into the buffer.
- The write pointer does NOT get advanced, use tu_fifo_advance_write_pointer() to do so! If the length
- returned is less than n i.e. len<n, then a wrap occurs and you need to execute this function a second
- time to get a pointer to the wrapped part!
+ corresponding pointer is invalid. The returned lengths summed up are the currently free space in the FIFO.
+ The write pointer does NOT get advanced, use tu_fifo_advance_write_pointer() to do so!
+ TAKE CARE TO NOT OVERFLOW THE BUFFER MORE THAN TWO TIMES THE FIFO DEPTH - IT CAN NOT RECOVERE OTHERWISE!
@param[in] f
Pointer to FIFO
@param[out] *info
@@ -963,12 +961,12 @@ void tu_fifo_get_read_info(tu_fifo_t *f, tu_fifo_buffer_info_t *info)
Number of ITEMS to write into buffer
*/
/******************************************************************************/
-void tu_fifo_get_write_info(tu_fifo_t *f, tu_fifo_buffer_info_t *info, uint16_t n)
+void tu_fifo_get_write_info(tu_fifo_t *f, tu_fifo_buffer_info_t *info)
{
uint16_t w = f->wr_idx, r = f->rd_idx;
uint16_t free = _tu_fifo_remaining(f, w, r);
- if (free == 0 || n > 2*f->depth) // If overwrite is allowed it must be less than or equal to 2 x buffer length, otherwise the overflow can not be resolved by the read functions
+ if (free == 0)
{
info->len_lin = 0;
info->len_wrap = 0;
@@ -977,21 +975,6 @@ void tu_fifo_get_write_info(tu_fifo_t *f, tu_fifo_buffer_info_t *info, uint16_t
return;
}
- // We need n here because we must enforce the read and write pointers to be not more separated than 2*depth!
- if (!f->overwritable)
- {
- // Not overwritable limit up to full
- n = tu_min16(n, free);
- }
- else if (n >= f->depth)
- {
- n = f->depth;
- // We start writing at the read pointer's position since we fill the complete
- // buffer and we do not want to modify the read pointer within a write function!
- // This would end up in a race condition with read functions!
- w = r;
- }
-
// Get relative pointers
w = get_relative_pointer(f, w);
r = get_relative_pointer(f, r);
@@ -1002,14 +985,14 @@ void tu_fifo_get_write_info(tu_fifo_t *f, tu_fifo_buffer_info_t *info, uint16_t
if (w < r)
{
// Non wrapping case
- info->len_lin = tu_min16(n, r-w); // Limit to required length
+ info->len_lin = r-w; // Limit to required length
info->len_wrap = 0;
info->ptr_wrap = NULL;
}
else
{
- info->len_lin = tu_min16(n, f->depth - w); // Limit to required length
- info->len_wrap = n-info->len_lin; // Remaining length - n already was limited to free or FIFO depth
+ info->len_lin = f->depth - w;
+ info->len_wrap = free - info->len_lin; // Remaining length - n already was limited to free or FIFO depth
info->ptr_wrap = f->buffer; // Always start of buffer
}
diff --git a/src/common/tusb_fifo.h b/src/common/tusb_fifo.h
index 7bc6b60b9..f8cc282d3 100644
--- a/src/common/tusb_fifo.h
+++ b/src/common/tusb_fifo.h
@@ -142,7 +142,7 @@ void tu_fifo_advance_read_pointer (tu_fifo_t *f, uint16_t n);
// This functions deliver a pointer to start reading/writing from/to and a valid linear length along which no wrap occurs.
void tu_fifo_get_read_info(tu_fifo_t *f, tu_fifo_buffer_info_t *info);
-void tu_fifo_get_write_info(tu_fifo_t *f, tu_fifo_buffer_info_t *info, uint16_t n);
+void tu_fifo_get_write_info(tu_fifo_t *f, tu_fifo_buffer_info_t *info);
static inline uint16_t tu_fifo_depth(tu_fifo_t* f)
{