@@ -102,24 +102,22 @@ static void update_read_buffer(uint8_t *buf)
102102 */
103103static void k64f_tx_reclaim (struct k64f_enetdata * k64f_enet )
104104{
105- uint8_t i = 0 ;
106-
107105 /* Get exclusive access */
108106 sys_mutex_lock (& k64f_enet -> TXLockMutex );
109107
110- i = k64f_enet -> tx_consume_index ;
111108 // 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 ]);
114112 if (g_handle .txBdDirty -> control & ENET_BUFFDESCRIPTOR_TX_WRAP_MASK )
115113 g_handle .txBdDirty = g_handle .txBdBase ;
116114 else
117115 g_handle .txBdDirty ++ ;
118116
119- i = (i + 1 ) % ENET_TX_RING_LEN ;
117+ k64f_enet -> tx_consume_index += 1 ;
118+ osSemaphoreRelease (k64f_enet -> xTXDCountSem .id );
120119 }
121120
122- k64f_enet -> tx_consume_index = i ;
123121 /* Restore access */
124122 sys_mutex_unlock (& k64f_enet -> TXLockMutex );
125123}
@@ -524,17 +522,17 @@ static err_t k64f_low_level_output(struct netif *netif, struct pbuf *p)
524522 dst += q -> len ;
525523 }
526524
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 ;
531529
532530 /* Get exclusive access */
533531 sys_mutex_lock (& k64f_enet -> TXLockMutex );
534532
535533 /* 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 ;
538536
539537 /* Setup transfers */
540538 g_handle .txBdCurrent -> buffer = psend ;
0 commit comments