Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions source/portable/NetworkInterface/Zynq/x_emacpsif.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

extern XEmacPs_Config mac_configs[ XPAR_XEMACPS_NUM_INSTANCES ];


*
void xemacpsif_setmac( uint32_t index,
uint8_t * addr );
uint8_t * xemacpsif_getmac( uint32_t index );
Expand Down Expand Up @@ -115,7 +115,8 @@
volatile int rxHead, rxTail;
volatile int txHead, txTail;

volatile int txBusy;
/* txMutex is replacing the earlier int variable 'txBusy'. */
SemaphoreHandle_t txMutex; /* Replacing the earlier variable 'volatile int txBusy'. */

volatile uint32_t isr_events;

Expand Down Expand Up @@ -170,7 +171,7 @@
void vInitialiseOnIndex( BaseType_t xIndex );

#ifdef __cplusplus
} /* extern "C" */
} /* extern "C" */
#endif

#endif /* __NETIF_XAXIEMACIF_H__ */
30 changes: 22 additions & 8 deletions source/portable/NetworkInterface/Zynq/x_emacpsif_dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ void emacps_send_handler( void * arg )
* "isr_events". The task in NetworkInterface will wake-up and do the necessary work.
*/
xemacpsif->isr_events |= EMAC_IF_TX_EVENT;
xemacpsif->txBusy = pdFALSE;

/* Take the mutex without blocking. */
xSemaphoreGiveFromISR( xemacpsif->txMutex, &xHigherPriorityTaskWoken );

if( xEMACTaskHandles[ xEMACIndex ] != NULL )
{
Expand Down Expand Up @@ -252,7 +254,6 @@ XStatus emacps_send_message( xemacpsif_s * xemacpsif,
int iReleaseAfterSend )
{
int txHead = xemacpsif->txHead;
int iHasSent = 0;
uint32_t ulBaseAddress = xemacpsif->emacps.Config.BaseAddress;
BaseType_t xEMACIndex = get_xEMACIndex( &xemacpsif->emacps );
TickType_t xBlockTimeTicks = pdMS_TO_TICKS( 5000U );
Expand Down Expand Up @@ -315,8 +316,6 @@ XStatus emacps_send_message( xemacpsif_s * xemacpsif,
{
}

iHasSent = pdTRUE;

txHead++;

if( txHead == ipconfigNIC_N_TX_DESC )
Expand All @@ -328,18 +327,24 @@ XStatus emacps_send_message( xemacpsif_s * xemacpsif,
* accessed as little as possible. */
xemacpsif->txHead = txHead;

if( xSemaphoreTake( xemacpsif->txMutex, 200U ) == pdFALSE )
{
FreeRTOS_printf( ( "emacps_send_message: mutex can not be taken, something is really wrong.\n" ) );
/* There is no risk in continuing here. */
}

/* Data Synchronization Barrier */
dsb();

if( iHasSent == pdTRUE )
{
/* Make STARTTX high */
uint32_t ulValue = XEmacPs_ReadReg( ulBaseAddress, XEMACPS_NWCTRL_OFFSET );
/* Start transmit */
xemacpsif->txBusy = pdTRUE;
XEmacPs_WriteReg( ulBaseAddress, XEMACPS_NWCTRL_OFFSET, ( ulValue | XEMACPS_NWCTRL_STARTTX_MASK ) );
/* Set the Start transmit bit. */
ulValue |= XEMACPS_NWCTRL_STARTTX_MASK;
XEmacPs_WriteReg( ulBaseAddress, XEMACPS_NWCTRL_OFFSET, ulValue );
/* Read back the register to make sure the data is flushed. */
( void ) XEmacPs_ReadReg( ulBaseAddress, XEMACPS_NWCTRL_OFFSET );
/* The mutex will be given later on in emacps_send_handler(). */
}

dsb();
Expand Down Expand Up @@ -685,6 +690,15 @@ XStatus init_dma( xemacpsif_s * xemacpsif )
configASSERT( xTXDescriptorSemaphores[ xEMACIndex ] );
}

if( xemacpsif->txMutex == NULL )
{
/* txMutex can always be taken, except between sending a packet
* and receiving the TX RX interrupt. */
xemacpsif->txMutex = xSemaphoreCreateBinary();
configASSERT( xemacpsif->txMutex != NULL );
xSemaphoreGive( xemacpsif->txMutex );
}

/*
* Allocate RX descriptors, 1 RxBD at a time.
*/
Expand Down
Loading