From 5add664874f4855491e28c3a869105eb25c5f4d7 Mon Sep 17 00:00:00 2001 From: Reinhard Panhuber Date: Fri, 30 Apr 2021 17:37:14 +0200 Subject: Remove n from tu_fifo_get_write_info() and fix bug in vendor class --- src/common/tusb_fifo.c | 33 ++++++++------------------------- src/common/tusb_fifo.h | 2 +- 2 files changed, 9 insertions(+), 26 deletions(-) (limited to 'src/common') 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. lenwr_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) { -- cgit v1.3.1