summaryrefslogtreecommitdiff
path: root/src
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
parent6acfa14fec1805b6f875f4bdbe00360065e72731 (diff)
Remove n from tu_fifo_get_write_info() and fix bug in vendor class
Diffstat (limited to 'src')
-rw-r--r--src/class/audio/audio_device.c8
-rw-r--r--src/class/vendor/vendor_device.h6
-rw-r--r--src/common/tusb_fifo.c33
-rw-r--r--src/common/tusb_fifo.h2
4 files changed, 16 insertions, 33 deletions
diff --git a/src/class/audio/audio_device.c b/src/class/audio/audio_device.c
index fc5402834..76ebc8aba 100644
--- a/src/class/audio/audio_device.c
+++ b/src/class/audio/audio_device.c
@@ -654,15 +654,17 @@ static bool audiod_decode_type_I_pcm(uint8_t rhport, audiod_function_t* audio, u
for (cnt_ff = 0; cnt_ff < n_ff_used; cnt_ff++)
{
- tu_fifo_get_write_info(&audio->rx_supp_ff[cnt_ff], &info, nBytesPerFFToRead);
+ tu_fifo_get_write_info(&audio->rx_supp_ff[cnt_ff], &info);
if (info.len_lin != 0)
{
+ info.len_lin = tu_min16(nBytesPerFFToRead, info.len_lin);
src = &audio->lin_buf_out[cnt_ff*audio->n_channels_per_ff_rx * audio->n_bytes_per_sampe_rx];
dst_end = info.ptr_lin + info.len_lin;
src = audiod_interleaved_copy_bytes_fast_decode(nBytesToCopy, info.ptr_lin, dst_end, src, n_ff_used);
// Handle wrapped part of FIFO
+ info.len_wrap = tu_min16(nBytesPerFFToRead - info.len_lin, info.len_wrap);
if (info.len_wrap != 0)
{
dst_end = info.ptr_wrap + info.len_wrap;
@@ -987,11 +989,9 @@ static uint16_t audiod_encode_type_I_pcm(uint8_t rhport, audiod_function_t* audi
tu_fifo_get_read_info(&audio->tx_supp_ff[cnt_ff], &info);
- // Limit up to desired length
- info.len_lin = tu_min16(nBytesPerFFToSend, info.len_lin);
-
if (info.len_lin != 0)
{
+ info.len_lin = tu_min16(nBytesPerFFToSend, info.len_lin); // Limit up to desired length
src_end = info.ptr_lin + info.len_lin;
dst = audiod_interleaved_copy_bytes_fast_encode(nBytesToCopy, info.ptr_lin, src_end, dst, n_ff_used);
diff --git a/src/class/vendor/vendor_device.h b/src/class/vendor/vendor_device.h
index ffa2e3b70..2c3d79a3d 100644
--- a/src/class/vendor/vendor_device.h
+++ b/src/class/vendor/vendor_device.h
@@ -59,7 +59,7 @@ uint32_t tud_vendor_n_write_str (uint8_t itf, char const* str);
static inline bool tud_vendor_mounted (void);
static inline uint32_t tud_vendor_available (void);
static inline uint32_t tud_vendor_read (void* buffer, uint32_t bufsize);
-static inline bool tud_vendor_peek (int pos, uint8_t* u8);
+static inline bool tud_vendor_peek (uint8_t* u8);
static inline uint32_t tud_vendor_write (void const* buffer, uint32_t bufsize);
static inline uint32_t tud_vendor_write_str (char const* str);
static inline uint32_t tud_vendor_write_available (void);
@@ -95,9 +95,9 @@ static inline uint32_t tud_vendor_read (void* buffer, uint32_t bufsize)
return tud_vendor_n_read(0, buffer, bufsize);
}
-static inline bool tud_vendor_peek (int pos, uint8_t* u8)
+static inline bool tud_vendor_peek (uint8_t* u8)
{
- return tud_vendor_n_peek(0, pos, u8);
+ return tud_vendor_n_peek(0, u8);
}
static inline uint32_t tud_vendor_write (void const* buffer, uint32_t bufsize)
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)
{