Skip to content

Commit a840225

Browse files
author
Mika Leppänen
committed
Corrected TX buffer reclaim error
When all TX descriptors were reserved in a row so that TX buffer reclaim interrupt did not happen during reservation sequence, after the interrupt occurred, TX buffer reclaim did no longer free buffers. This happened because when all descriptors were in use, last free index pointed to consumed index.
1 parent a5a8b35 commit a840225

File tree

1 file changed

+6
-1
lines changed
  • features/netsocket/emac-drivers/TARGET_NXP_EMAC/TARGET_LPCTarget

1 file changed

+6
-1
lines changed

features/netsocket/emac-drivers/TARGET_NXP_EMAC/TARGET_LPCTarget/lpc17_emac.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ struct lpc_enetdata {
116116
volatile uint32_t rx_free_descs; /**< Count of free RX descriptors */
117117
emac_mem_buf_t *txb[LPC_NUM_BUFF_TXDESCS]; /**< TX pbuf pointer list, zero-copy mode */
118118
uint32_t lpc_last_tx_idx; /**< TX last descriptor index, zero-copy mode */
119+
uint32_t lpc_reserved_tx_num; /**< Number of reserved TX descriptors, zero-copy mode */
119120
};
120121

121122
#if defined(TARGET_LPC1768) || defined(TARGET_LPC1769)
@@ -419,6 +420,7 @@ bool LPC17_EMAC::lpc_tx_setup()
419420
LPC_EMAC->TxDescriptorNumber = LPC_NUM_BUFF_TXDESCS - 1;
420421

421422
lpc_enetdata.lpc_last_tx_idx = 0;
423+
lpc_enetdata.lpc_reserved_tx_num = 0;
422424

423425
return true;
424426
}
@@ -431,7 +433,8 @@ void LPC17_EMAC::lpc_tx_reclaim_st(uint32_t cidx)
431433
{
432434
TXLockMutex.lock();
433435

434-
while (cidx != lpc_enetdata.lpc_last_tx_idx) {
436+
// If consume index not last freed index or all descriptors in use
437+
while (cidx != lpc_enetdata.lpc_last_tx_idx || lpc_enetdata.lpc_reserved_tx_num == LPC_NUM_BUFF_TXDESCS) {
435438
if (lpc_enetdata.txb[lpc_enetdata.lpc_last_tx_idx] != NULL) {
436439
memory_manager->free(lpc_enetdata.txb[lpc_enetdata.lpc_last_tx_idx]);
437440
lpc_enetdata.txb[lpc_enetdata.lpc_last_tx_idx] = NULL;
@@ -443,6 +446,7 @@ void LPC17_EMAC::lpc_tx_reclaim_st(uint32_t cidx)
443446
if (lpc_enetdata.lpc_last_tx_idx >= LPC_NUM_BUFF_TXDESCS) {
444447
lpc_enetdata.lpc_last_tx_idx = 0;
445448
}
449+
lpc_enetdata.lpc_reserved_tx_num--;
446450
}
447451

448452
TXLockMutex.unlock();
@@ -573,6 +577,7 @@ bool LPC17_EMAC::link_out(emac_mem_buf_t *p)
573577
if (idx >= LPC_NUM_BUFF_TXDESCS) {
574578
idx = 0;
575579
}
580+
lpc_enetdata.lpc_reserved_tx_num++;
576581
}
577582

578583
LPC_EMAC->TxProduceIndex = idx;

0 commit comments

Comments
 (0)