@@ -102,24 +102,22 @@ static void update_read_buffer(uint8_t *buf)
102
102
*/
103
103
static void k64f_tx_reclaim (struct k64f_enetdata * k64f_enet )
104
104
{
105
- uint8_t i = 0 ;
106
-
107
105
/* Get exclusive access */
108
106
sys_mutex_lock (& k64f_enet -> TXLockMutex );
109
107
110
- i = k64f_enet -> tx_consume_index ;
111
108
// Traverse all descriptors, looking for the ones modified by the uDMA
112
- while ((i != k64f_enet -> tx_produce_index ) && (!(g_handle .txBdDirty -> control & ENET_BUFFDESCRIPTOR_TX_READY_MASK ))) {
113
- pbuf_free (tx_buff [i ]);
109
+ while ((k64f_enet -> tx_consume_index != k64f_enet -> tx_produce_index ) &&
110
+ (!(g_handle .txBdDirty -> control & ENET_BUFFDESCRIPTOR_TX_READY_MASK ))) {
111
+ pbuf_free (tx_buff [k64f_enet -> tx_consume_index % ENET_TX_RING_LEN ]);
114
112
if (g_handle .txBdDirty -> control & ENET_BUFFDESCRIPTOR_TX_WRAP_MASK )
115
113
g_handle .txBdDirty = g_handle .txBdBase ;
116
114
else
117
115
g_handle .txBdDirty ++ ;
118
116
119
- i = (i + 1 ) % ENET_TX_RING_LEN ;
117
+ k64f_enet -> tx_consume_index += 1 ;
118
+ osSemaphoreRelease (k64f_enet -> xTXDCountSem .id );
120
119
}
121
120
122
- k64f_enet -> tx_consume_index = i ;
123
121
/* Restore access */
124
122
sys_mutex_unlock (& k64f_enet -> TXLockMutex );
125
123
}
@@ -524,17 +522,17 @@ static err_t k64f_low_level_output(struct netif *netif, struct pbuf *p)
524
522
dst += q -> len ;
525
523
}
526
524
527
- /* Wait until a descriptor is available for the transfer. */
528
- /* THIS WILL BLOCK UNTIL THERE ARE A DESCRIPTOR AVAILABLE */
529
- while ( g_handle . txBdCurrent -> control & ENET_BUFFDESCRIPTOR_TX_READY_MASK )
530
- osSemaphoreWait ( k64f_enet -> xTXDCountSem . id , osWaitForever ) ;
525
+ /* Check if a descriptor is available for the transfer. */
526
+ int32_t count = osSemaphoreWait ( k64f_enet -> xTXDCountSem . id , 0 );
527
+ if ( count < 1 )
528
+ return ERR_BUF ;
531
529
532
530
/* Get exclusive access */
533
531
sys_mutex_lock (& k64f_enet -> TXLockMutex );
534
532
535
533
/* Save the buffer so that it can be freed when transmit is done */
536
- tx_buff [k64f_enet -> tx_produce_index ] = temp_pbuf ;
537
- k64f_enet -> tx_produce_index = ( k64f_enet -> tx_produce_index + 1 ) % ENET_TX_RING_LEN ;
534
+ tx_buff [k64f_enet -> tx_produce_index % ENET_TX_RING_LEN ] = temp_pbuf ;
535
+ k64f_enet -> tx_produce_index += 1 ;
538
536
539
537
/* Setup transfers */
540
538
g_handle .txBdCurrent -> buffer = psend ;
0 commit comments