@@ -237,26 +237,27 @@ bool STM32_EMAC::link_out(emac_mem_buf_t *buf)
237
237
}
238
238
239
239
/* *
240
- * Should allocate a a contiguous memory buffer and transfer the bytes of the incoming
240
+ * Should allocate a contiguous memory buffer and transfer the bytes of the incoming
241
241
* packet to the buffer.
242
242
*
243
- * @return a memory buffer filled with the received packet (including MAC header)
244
- * NULL on memory error
243
+ * @param buf If a frame was received and the memory buffer allocation was successful, a memory
244
+ * buffer filled with the received packet (including MAC header)
245
+ * @return negative value when no more frames,
246
+ * zero when frame is received
245
247
*/
246
- emac_mem_buf_t * STM32_EMAC::low_level_input ()
248
+ int STM32_EMAC::low_level_input (emac_mem_buf_t **buf )
247
249
{
248
250
uint16_t len = 0 ;
249
251
uint8_t *buffer;
250
252
__IO ETH_DMADescTypeDef *dmarxdesc;
251
253
uint32_t bufferoffset = 0 ;
252
254
uint32_t byteslefttocopy = 0 ;
253
- emac_mem_buf_t *buf = 0 ;
254
255
emac_mem_buf_t *q;
255
256
uint32_t payloadoffset = 0 ;
256
257
257
258
/* get received frame */
258
- if (HAL_ETH_GetReceivedFrame (&EthHandle) != HAL_OK) {
259
- return NULL ;
259
+ if (HAL_ETH_GetReceivedFrame_IT (&EthHandle) != HAL_OK) {
260
+ return - 1 ;
260
261
}
261
262
262
263
/* Obtain the size of the packet and put it into the "len" variable. */
@@ -268,13 +269,13 @@ emac_mem_buf_t *STM32_EMAC::low_level_input()
268
269
269
270
if (len > 0 ) {
270
271
/* Allocate a memory buffer chain from buffer pool */
271
- buf = memory_manager->alloc_pool (len, 0 );
272
+ * buf = memory_manager->alloc_pool (len, 0 );
272
273
}
273
274
274
- if (buf != NULL ) {
275
+ if (* buf != NULL ) {
275
276
dmarxdesc = EthHandle.RxFrameInfos .FSRxDesc ;
276
277
bufferoffset = 0 ;
277
- for (q = buf; q != NULL ; q = memory_manager->get_next (q)) {
278
+ for (q = * buf; q != NULL ; q = memory_manager->get_next (q)) {
278
279
byteslefttocopy = memory_manager->get_len (q);
279
280
payloadoffset = 0 ;
280
281
@@ -316,7 +317,7 @@ emac_mem_buf_t *STM32_EMAC::low_level_input()
316
317
/* Resume DMA reception */
317
318
EthHandle.Instance ->DMARPDR = 0 ;
318
319
}
319
- return buf ;
320
+ return 0 ;
320
321
}
321
322
322
323
@@ -325,15 +326,16 @@ emac_mem_buf_t *STM32_EMAC::low_level_input()
325
326
*/
326
327
void STM32_EMAC::packet_rx ()
327
328
{
328
- emac_mem_buf_t *p;
329
-
330
329
/* move received packet into a new buf */
331
- p = low_level_input ();
332
- if (p == NULL ) {
333
- return ;
330
+ while (1 ) {
331
+ emac_mem_buf_t *p = NULL ;
332
+ if (low_level_input (&p) < 0 ) {
333
+ break ;
334
+ }
335
+ if (p) {
336
+ emac_link_input_cb (p);
337
+ }
334
338
}
335
-
336
- emac_link_input_cb (p);
337
339
}
338
340
339
341
/* * \brief Worker thread.
0 commit comments