@@ -97,21 +97,21 @@ bool tu_fifo_config(tu_fifo_t *f, void* buffer, uint16_t depth, uint16_t item_si
97
97
// TODO generalize with configurable 1 byte or 4 byte each read
98
98
static void _ff_push_const_addr (uint8_t * ff_buf , const void * app_buf , uint16_t len )
99
99
{
100
- volatile const uint32_t * rx_fifo = (volatile const uint32_t * ) app_buf ;
100
+ volatile const uint32_t * reg_rx = (volatile const uint32_t * ) app_buf ;
101
101
102
102
// Reading full available 32 bit words from const app address
103
103
uint16_t full_words = len >> 2 ;
104
104
while (full_words -- )
105
105
{
106
- tu_unaligned_write32 (ff_buf , * rx_fifo );
106
+ tu_unaligned_write32 (ff_buf , * reg_rx );
107
107
ff_buf += 4 ;
108
108
}
109
109
110
110
// Read the remaining 1-3 bytes from const app address
111
111
uint8_t const bytes_rem = len & 0x03 ;
112
112
if ( bytes_rem )
113
113
{
114
- uint32_t tmp32 = * rx_fifo ;
114
+ uint32_t tmp32 = * reg_rx ;
115
115
memcpy (ff_buf , & tmp32 , bytes_rem );
116
116
}
117
117
}
@@ -120,24 +120,24 @@ static void _ff_push_const_addr(uint8_t * ff_buf, const void * app_buf, uint16_t
120
120
// where all data is written to a constant address in full word copies
121
121
static void _ff_pull_const_addr (void * app_buf , const uint8_t * ff_buf , uint16_t len )
122
122
{
123
- volatile uint32_t * tx_fifo = (volatile uint32_t * ) app_buf ;
123
+ volatile uint32_t * reg_tx = (volatile uint32_t * ) app_buf ;
124
124
125
- // Pushing full available 32 bit words to const app address
125
+ // Write full available 32 bit words to const address
126
126
uint16_t full_words = len >> 2 ;
127
127
while (full_words -- )
128
128
{
129
- * tx_fifo = tu_unaligned_read32 (ff_buf );
129
+ * reg_tx = tu_unaligned_read32 (ff_buf );
130
130
ff_buf += 4 ;
131
131
}
132
132
133
- // Write the remaining 1-3 bytes into const app address
133
+ // Write the remaining 1-3 bytes into const address
134
134
uint8_t const bytes_rem = len & 0x03 ;
135
135
if ( bytes_rem )
136
136
{
137
137
uint32_t tmp32 = 0 ;
138
138
memcpy (& tmp32 , ff_buf , bytes_rem );
139
139
140
- * tx_fifo = tmp32 ;
140
+ * reg_tx = tmp32 ;
141
141
}
142
142
}
143
143
@@ -148,21 +148,21 @@ static inline void _ff_push(tu_fifo_t* f, void const * app_buf, uint16_t rel)
148
148
}
149
149
150
150
// send n items to fifo WITHOUT updating write pointer
151
- static void _ff_push_n (tu_fifo_t * f , void const * app_buf , uint16_t n , uint16_t rel , tu_fifo_copy_mode_t copy_mode )
151
+ static void _ff_push_n (tu_fifo_t * f , void const * app_buf , uint16_t n , uint16_t wr_ptr , tu_fifo_copy_mode_t copy_mode )
152
152
{
153
- uint16_t const nLin = f -> depth - rel ;
154
- uint16_t const nWrap = n - nLin ;
153
+ uint16_t const lin_count = f -> depth - wr_ptr ;
154
+ uint16_t const wrap_count = n - lin_count ;
155
155
156
- uint16_t nLin_bytes = nLin * f -> item_size ;
157
- uint16_t nWrap_bytes = nWrap * f -> item_size ;
156
+ uint16_t lin_bytes = lin_count * f -> item_size ;
157
+ uint16_t wrap_bytes = wrap_count * f -> item_size ;
158
158
159
159
// current buffer of fifo
160
- uint8_t * ff_buf = f -> buffer + (rel * f -> item_size );
160
+ uint8_t * ff_buf = f -> buffer + (wr_ptr * f -> item_size );
161
161
162
162
switch (copy_mode )
163
163
{
164
164
case TU_FIFO_COPY_INC :
165
- if (n <= nLin )
165
+ if (n <= lin_count )
166
166
{
167
167
// Linear only
168
168
memcpy (ff_buf , app_buf , n * f -> item_size );
@@ -172,17 +172,17 @@ static void _ff_push_n(tu_fifo_t* f, void const * app_buf, uint16_t n, uint16_t
172
172
// Wrap around
173
173
174
174
// Write data to linear part of buffer
175
- memcpy (ff_buf , app_buf , nLin_bytes );
175
+ memcpy (ff_buf , app_buf , lin_bytes );
176
176
177
177
// Write data wrapped around
178
178
// TU_ASSERT(nWrap_bytes <= f->depth, );
179
- memcpy (f -> buffer , ((uint8_t const * ) app_buf ) + nLin_bytes , nWrap_bytes );
179
+ memcpy (f -> buffer , ((uint8_t const * ) app_buf ) + lin_bytes , wrap_bytes );
180
180
}
181
181
break ;
182
182
183
183
case TU_FIFO_COPY_CST_FULL_WORDS :
184
184
// Intended for hardware buffers from which it can be read word by word only
185
- if (n <= nLin )
185
+ if (n <= lin_count )
186
186
{
187
187
// Linear only
188
188
_ff_push_const_addr (ff_buf , app_buf , n * f -> item_size );
@@ -192,17 +192,18 @@ static void _ff_push_n(tu_fifo_t* f, void const * app_buf, uint16_t n, uint16_t
192
192
// Wrap around case
193
193
194
194
// Write full words to linear part of buffer
195
- uint16_t nLin_4n_bytes = nLin_bytes & 0xFFFC ;
195
+ uint16_t nLin_4n_bytes = lin_bytes & 0xFFFC ;
196
196
_ff_push_const_addr (ff_buf , app_buf , nLin_4n_bytes );
197
197
ff_buf += nLin_4n_bytes ;
198
198
199
199
// There could be odd 1-3 bytes before the wrap-around boundary
200
- volatile const uint32_t * rx_fifo = (volatile const uint32_t * ) app_buf ;
201
- uint8_t rem = nLin_bytes & 0x03 ;
200
+ uint8_t rem = lin_bytes & 0x03 ;
202
201
if (rem > 0 )
203
202
{
204
- uint8_t remrem = (uint8_t ) tu_min16 (nWrap_bytes , 4 - rem );
205
- nWrap_bytes -= remrem ;
203
+ volatile const uint32_t * rx_fifo = (volatile const uint32_t * ) app_buf ;
204
+
205
+ uint8_t remrem = (uint8_t ) tu_min16 (wrap_bytes , 4 - rem );
206
+ wrap_bytes -= remrem ;
206
207
207
208
uint32_t tmp32 = * rx_fifo ;
208
209
uint8_t * src_u8 = ((uint8_t * ) & tmp32 );
@@ -220,7 +221,7 @@ static void _ff_push_n(tu_fifo_t* f, void const * app_buf, uint16_t n, uint16_t
220
221
}
221
222
222
223
// Write data wrapped part
223
- if (nWrap_bytes > 0 ) _ff_push_const_addr (ff_buf , app_buf , nWrap_bytes );
224
+ if (wrap_bytes > 0 ) _ff_push_const_addr (ff_buf , app_buf , wrap_bytes );
224
225
}
225
226
break ;
226
227
}
@@ -233,21 +234,21 @@ static inline void _ff_pull(tu_fifo_t* f, void * app_buf, uint16_t rel)
233
234
}
234
235
235
236
// get n items from fifo WITHOUT updating read pointer
236
- static void _ff_pull_n (tu_fifo_t * f , void * app_buf , uint16_t n , uint16_t rel , tu_fifo_copy_mode_t copy_mode )
237
+ static void _ff_pull_n (tu_fifo_t * f , void * app_buf , uint16_t n , uint16_t rd_ptr , tu_fifo_copy_mode_t copy_mode )
237
238
{
238
- uint16_t const nLin = f -> depth - rel ;
239
- uint16_t const nWrap = n - nLin ; // only used if wrapped
239
+ uint16_t const lin_count = f -> depth - rd_ptr ;
240
+ uint16_t const wrap_count = n - lin_count ; // only used if wrapped
240
241
241
- uint16_t nLin_bytes = nLin * f -> item_size ;
242
- uint16_t nWrap_bytes = nWrap * f -> item_size ;
242
+ uint16_t lin_bytes = lin_count * f -> item_size ;
243
+ uint16_t wrap_bytes = wrap_count * f -> item_size ;
243
244
244
245
// current buffer of fifo
245
- uint8_t * ff_buf = f -> buffer + (rel * f -> item_size );
246
+ uint8_t * ff_buf = f -> buffer + (rd_ptr * f -> item_size );
246
247
247
248
switch (copy_mode )
248
249
{
249
250
case TU_FIFO_COPY_INC :
250
- if ( n <= nLin )
251
+ if ( n <= lin_count )
251
252
{
252
253
// Linear only
253
254
memcpy (app_buf , ff_buf , n * f -> item_size );
@@ -257,15 +258,15 @@ static void _ff_pull_n(tu_fifo_t* f, void* app_buf, uint16_t n, uint16_t rel, tu
257
258
// Wrap around
258
259
259
260
// Read data from linear part of buffer
260
- memcpy (app_buf , ff_buf , nLin_bytes );
261
+ memcpy (app_buf , ff_buf , lin_bytes );
261
262
262
263
// Read data wrapped part
263
- memcpy ((uint8_t * ) app_buf + nLin_bytes , f -> buffer , nWrap_bytes );
264
+ memcpy ((uint8_t * ) app_buf + lin_bytes , f -> buffer , wrap_bytes );
264
265
}
265
266
break ;
266
267
267
268
case TU_FIFO_COPY_CST_FULL_WORDS :
268
- if ( n <= nLin )
269
+ if ( n <= lin_count )
269
270
{
270
271
// Linear only
271
272
_ff_pull_const_addr (app_buf , ff_buf , n * f -> item_size );
@@ -275,17 +276,18 @@ static void _ff_pull_n(tu_fifo_t* f, void* app_buf, uint16_t n, uint16_t rel, tu
275
276
// Wrap around case
276
277
277
278
// Read full words from linear part of buffer
278
- uint16_t nLin_4n_bytes = nLin_bytes & 0xFFFC ;
279
- _ff_pull_const_addr (app_buf , ff_buf , nLin_4n_bytes );
280
- ff_buf += nLin_4n_bytes ;
279
+ uint16_t lin_4n_bytes = lin_bytes & 0xFFFC ;
280
+ _ff_pull_const_addr (app_buf , ff_buf , lin_4n_bytes );
281
+ ff_buf += lin_4n_bytes ;
281
282
282
283
// There could be odd 1-3 bytes before the wrap-around boundary
283
- volatile uint32_t * tx_fifo = (volatile uint32_t * ) app_buf ;
284
- uint8_t rem = nLin_bytes & 0x03 ;
284
+ uint8_t rem = lin_bytes & 0x03 ;
285
285
if (rem > 0 )
286
286
{
287
- uint8_t remrem = (uint8_t ) tu_min16 (nWrap_bytes , 4 - rem );
288
- nWrap_bytes -= remrem ;
287
+ volatile uint32_t * reg_tx = (volatile uint32_t * ) app_buf ;
288
+
289
+ uint8_t remrem = (uint8_t ) tu_min16 (wrap_bytes , 4 - rem );
290
+ wrap_bytes -= remrem ;
289
291
290
292
uint32_t tmp32 = 0 ;
291
293
uint8_t * dst_u8 = (uint8_t * )& tmp32 ;
@@ -297,15 +299,15 @@ static void _ff_pull_n(tu_fifo_t* f, void* app_buf, uint16_t n, uint16_t rel, tu
297
299
ff_buf = f -> buffer ;
298
300
while (remrem -- ) * dst_u8 ++ = * ff_buf ++ ;
299
301
300
- * tx_fifo = tmp32 ;
302
+ * reg_tx = tmp32 ;
301
303
}
302
304
else
303
305
{
304
306
ff_buf = f -> buffer ; // wrap around to beginning
305
307
}
306
308
307
309
// Read data wrapped part
308
- if (nWrap_bytes > 0 ) _ff_pull_const_addr (app_buf , ff_buf , nWrap_bytes );
310
+ if (wrap_bytes > 0 ) _ff_pull_const_addr (app_buf , ff_buf , wrap_bytes );
309
311
}
310
312
break ;
311
313
@@ -413,16 +415,16 @@ static bool _tu_fifo_peek(tu_fifo_t* f, void * p_buffer, uint16_t wr_idx, uint16
413
415
{
414
416
uint16_t cnt = _ff_count (f -> depth , wr_idx , rd_idx );
415
417
418
+ // nothing to peek
419
+ if ( cnt == 0 ) return false;
420
+
416
421
// Check overflow and correct if required
417
422
if ( cnt > f -> depth )
418
423
{
419
424
rd_idx = _ff_correct_read_index (f , wr_idx );
420
425
cnt = f -> depth ;
421
426
}
422
427
423
- // Skip beginning of buffer
424
- if ( cnt == 0 ) return false;
425
-
426
428
uint16_t rd_ptr = idx2ptr (f -> depth , rd_idx );
427
429
428
430
// Peek data
@@ -437,16 +439,16 @@ static uint16_t _tu_fifo_peek_n(tu_fifo_t* f, void * p_buffer, uint16_t n, uint1
437
439
{
438
440
uint16_t cnt = _ff_count (f -> depth , wr_idx , rd_idx );
439
441
442
+ // nothing to peek
443
+ if ( cnt == 0 ) return 0 ;
444
+
440
445
// Check overflow and correct if required
441
446
if ( cnt > f -> depth )
442
447
{
443
448
rd_idx = _ff_correct_read_index (f , wr_idx );
444
449
cnt = f -> depth ;
445
450
}
446
451
447
- // Skip beginning of buffer
448
- if ( cnt == 0 ) return 0 ;
449
-
450
452
// Check if we can read something at and after offset - if too less is available we read what remains
451
453
if ( cnt < n ) n = cnt ;
452
454
0 commit comments