@@ -62,7 +62,9 @@ TU_ATTR_ALWAYS_INLINE static inline void _ff_unlock(osal_mutex_t mutex)
62
62
typedef enum
63
63
{
64
64
TU_FIFO_COPY_INC , ///< Copy from/to an increasing source/destination address - default mode
65
+ #ifdef TUP_MEM_CONST_ADDR
65
66
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
66
68
} tu_fifo_copy_mode_t ;
67
69
68
70
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
92
94
// Pull & Push
93
95
//--------------------------------------------------------------------+
94
96
97
+ #ifdef TUP_MEM_CONST_ADDR
95
98
// Intended to be used to read from hardware USB FIFO in e.g. STM32 where all data is read from a constant address
96
99
// Code adapted from dcd_synopsys.c
97
100
// 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
140
143
* reg_tx = tmp32 ;
141
144
}
142
145
}
146
+ #endif
143
147
144
148
// send one item to fifo WITHOUT updating write pointer
145
149
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
179
183
memcpy (f -> buffer , ((uint8_t const * ) app_buf ) + lin_bytes , wrap_bytes );
180
184
}
181
185
break ;
182
-
186
+ #ifdef TUP_MEM_CONST_ADDR
183
187
case TU_FIFO_COPY_CST_FULL_WORDS :
184
188
// Intended for hardware buffers from which it can be read word by word only
185
189
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
224
228
if (wrap_bytes > 0 ) _ff_push_const_addr (ff_buf , app_buf , wrap_bytes );
225
229
}
226
230
break ;
231
+ #endif
227
232
default : break ;
228
233
}
229
234
}
@@ -265,7 +270,7 @@ static void _ff_pull_n(tu_fifo_t* f, void* app_buf, uint16_t n, uint16_t rd_ptr,
265
270
memcpy ((uint8_t * ) app_buf + lin_bytes , f -> buffer , wrap_bytes );
266
271
}
267
272
break ;
268
-
273
+ #ifdef TUP_MEM_CONST_ADDR
269
274
case TU_FIFO_COPY_CST_FULL_WORDS :
270
275
if ( n <= lin_count )
271
276
{
@@ -310,6 +315,7 @@ static void _ff_pull_n(tu_fifo_t* f, void* app_buf, uint16_t n, uint16_t rd_ptr,
310
315
// Read data wrapped part
311
316
if (wrap_bytes > 0 ) _ff_pull_const_addr (app_buf , ff_buf , wrap_bytes );
312
317
}
318
+ #endif
313
319
break ;
314
320
315
321
default : break ;
@@ -727,10 +733,29 @@ uint16_t tu_fifo_read_n(tu_fifo_t* f, void * buffer, uint16_t n)
727
733
return _tu_fifo_read_n (f , buffer , n , TU_FIFO_COPY_INC );
728
734
}
729
735
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
+ /******************************************************************************/
730
754
uint16_t tu_fifo_read_n_const_addr_full_words (tu_fifo_t * f , void * buffer , uint16_t n )
731
755
{
732
756
return _tu_fifo_read_n (f , buffer , n , TU_FIFO_COPY_CST_FULL_WORDS );
733
757
}
758
+ #endif
734
759
735
760
/******************************************************************************/
736
761
/*!
@@ -839,6 +864,7 @@ uint16_t tu_fifo_write_n(tu_fifo_t* f, const void * data, uint16_t n)
839
864
return _tu_fifo_write_n (f , data , n , TU_FIFO_COPY_INC );
840
865
}
841
866
867
+ #ifdef TUP_MEM_CONST_ADDR
842
868
/******************************************************************************/
843
869
/*!
844
870
@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,
858
884
{
859
885
return _tu_fifo_write_n (f , data , n , TU_FIFO_COPY_CST_FULL_WORDS );
860
886
}
887
+ #endif
861
888
862
889
/******************************************************************************/
863
890
/*!
0 commit comments