Skip to content

Commit 104a5da

Browse files
authored
Merge pull request #2618 from HiFiPhile/fifo_const_split
tusb_fifo: skip constant address functions if not used
2 parents 4101369 + c303b5d commit 104a5da

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

src/common/tusb_fifo.c

+29-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ TU_ATTR_ALWAYS_INLINE static inline void _ff_unlock(osal_mutex_t mutex)
6262
typedef enum
6363
{
6464
TU_FIFO_COPY_INC, ///< Copy from/to an increasing source/destination address - default mode
65+
#ifdef TUP_MEM_CONST_ADDR
6566
TU_FIFO_COPY_CST_FULL_WORDS, ///< Copy from/to a constant source/destination address - required for e.g. STM32 to write into USB hardware FIFO
67+
#endif
6668
} tu_fifo_copy_mode_t;
6769

6870
bool tu_fifo_config(tu_fifo_t *f, void* buffer, uint16_t depth, uint16_t item_size, bool overwritable)
@@ -92,6 +94,7 @@ bool tu_fifo_config(tu_fifo_t *f, void* buffer, uint16_t depth, uint16_t item_si
9294
// Pull & Push
9395
//--------------------------------------------------------------------+
9496

97+
#ifdef TUP_MEM_CONST_ADDR
9598
// Intended to be used to read from hardware USB FIFO in e.g. STM32 where all data is read from a constant address
9699
// Code adapted from dcd_synopsys.c
97100
// TODO generalize with configurable 1 byte or 4 byte each read
@@ -140,6 +143,7 @@ static void _ff_pull_const_addr(void * app_buf, const uint8_t * ff_buf, uint16_t
140143
*reg_tx = tmp32;
141144
}
142145
}
146+
#endif
143147

144148
// send one item to fifo WITHOUT updating write pointer
145149
static inline void _ff_push(tu_fifo_t* f, void const * app_buf, uint16_t rel)
@@ -179,7 +183,7 @@ static void _ff_push_n(tu_fifo_t* f, void const * app_buf, uint16_t n, uint16_t
179183
memcpy(f->buffer, ((uint8_t const*) app_buf) + lin_bytes, wrap_bytes);
180184
}
181185
break;
182-
186+
#ifdef TUP_MEM_CONST_ADDR
183187
case TU_FIFO_COPY_CST_FULL_WORDS:
184188
// Intended for hardware buffers from which it can be read word by word only
185189
if(n <= lin_count)
@@ -224,6 +228,7 @@ static void _ff_push_n(tu_fifo_t* f, void const * app_buf, uint16_t n, uint16_t
224228
if (wrap_bytes > 0) _ff_push_const_addr(ff_buf, app_buf, wrap_bytes);
225229
}
226230
break;
231+
#endif
227232
default: break;
228233
}
229234
}
@@ -265,7 +270,7 @@ static void _ff_pull_n(tu_fifo_t* f, void* app_buf, uint16_t n, uint16_t rd_ptr,
265270
memcpy((uint8_t*) app_buf + lin_bytes, f->buffer, wrap_bytes);
266271
}
267272
break;
268-
273+
#ifdef TUP_MEM_CONST_ADDR
269274
case TU_FIFO_COPY_CST_FULL_WORDS:
270275
if ( n <= lin_count )
271276
{
@@ -310,6 +315,7 @@ static void _ff_pull_n(tu_fifo_t* f, void* app_buf, uint16_t n, uint16_t rd_ptr,
310315
// Read data wrapped part
311316
if (wrap_bytes > 0) _ff_pull_const_addr(app_buf, ff_buf, wrap_bytes);
312317
}
318+
#endif
313319
break;
314320

315321
default: break;
@@ -727,10 +733,29 @@ uint16_t tu_fifo_read_n(tu_fifo_t* f, void * buffer, uint16_t n)
727733
return _tu_fifo_read_n(f, buffer, n, TU_FIFO_COPY_INC);
728734
}
729735

736+
#ifdef TUP_MEM_CONST_ADDR
737+
/******************************************************************************/
738+
/*!
739+
@brief This function will read n elements from the array index specified by
740+
the read pointer and increment the read index.
741+
This function checks for an overflow and corrects read pointer if required.
742+
The dest address will not be incremented which is useful for writing to registers.
743+
744+
@param[in] f
745+
Pointer to the FIFO buffer to manipulate
746+
@param[in] buffer
747+
The pointer to data location
748+
@param[in] n
749+
Number of element that buffer can afford
750+
751+
@returns number of items read from the FIFO
752+
*/
753+
/******************************************************************************/
730754
uint16_t tu_fifo_read_n_const_addr_full_words(tu_fifo_t* f, void * buffer, uint16_t n)
731755
{
732756
return _tu_fifo_read_n(f, buffer, n, TU_FIFO_COPY_CST_FULL_WORDS);
733757
}
758+
#endif
734759

735760
/******************************************************************************/
736761
/*!
@@ -839,6 +864,7 @@ uint16_t tu_fifo_write_n(tu_fifo_t* f, const void * data, uint16_t n)
839864
return _tu_fifo_write_n(f, data, n, TU_FIFO_COPY_INC);
840865
}
841866

867+
#ifdef TUP_MEM_CONST_ADDR
842868
/******************************************************************************/
843869
/*!
844870
@brief This function will write n elements into the array index specified by
@@ -858,6 +884,7 @@ uint16_t tu_fifo_write_n_const_addr_full_words(tu_fifo_t* f, const void * data,
858884
{
859885
return _tu_fifo_write_n(f, data, n, TU_FIFO_COPY_CST_FULL_WORDS);
860886
}
887+
#endif
861888

862889
/******************************************************************************/
863890
/*!

src/common/tusb_fifo.h

+4
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,15 @@ void tu_fifo_config_mutex(tu_fifo_t *f, osal_mutex_t wr_mutex, osal_mutex_t rd_m
156156

157157
bool tu_fifo_write (tu_fifo_t* f, void const * p_data);
158158
uint16_t tu_fifo_write_n (tu_fifo_t* f, void const * p_data, uint16_t n);
159+
#ifdef TUP_MEM_CONST_ADDR
159160
uint16_t tu_fifo_write_n_const_addr_full_words (tu_fifo_t* f, const void * data, uint16_t n);
161+
#endif
160162

161163
bool tu_fifo_read (tu_fifo_t* f, void * p_buffer);
162164
uint16_t tu_fifo_read_n (tu_fifo_t* f, void * p_buffer, uint16_t n);
165+
#ifdef TUP_MEM_CONST_ADDR
163166
uint16_t tu_fifo_read_n_const_addr_full_words (tu_fifo_t* f, void * buffer, uint16_t n);
167+
#endif
164168

165169
bool tu_fifo_peek (tu_fifo_t* f, void * p_buffer);
166170
uint16_t tu_fifo_peek_n (tu_fifo_t* f, void * p_buffer, uint16_t n);

src/common/tusb_mcu.h

+4
Original file line numberDiff line numberDiff line change
@@ -448,4 +448,8 @@
448448
#define TUP_DCD_EDPT_ISO_ALLOC
449449
#endif
450450

451+
#if defined(TUP_USBIP_DWC2)
452+
#define TUP_MEM_CONST_ADDR
453+
#endif
454+
451455
#endif

0 commit comments

Comments
 (0)