# Dup echo replies 

**URL:** <https://forums.freertos.org/t/dup-echo-replies/5300>\
**Category:** Kernel\
**Created:** [April 12, 2012, 7:53am UTC](https://forums.freertos.org/t/dup-echo-replies/5300 "2012-04-12T07:53:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [April 12, 2012, 7:53am UTC](https://forums.freertos.org/t/dup-echo-replies/5300/1 "2012-04-12T07:53:33Z")

</div>

**[thomas84](https://sourceforge.net/u/thomas84/)** wrote on [Thursday, April 12, 2012](https://sourceforge.net/p/freertos/discussion/382005/thread/ec01bef0/#d502):

Hello,

i have a question referring to the Webserver Demo for CodeRed. It works fine so far, but if i send ping to the board i always get two echo replys. I can’t see them in the console (only one reply - no dup), but in wireshark i see two replies. On a Linux maschine i see both replies in the console. Has anyone had the same problem? Or a clue why the second reply is sent?  
Just to make it sure, the first reply does not get lost or anything….

thanks

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [April 12, 2012, 8:36am UTC](https://forums.freertos.org/t/dup-echo-replies/5300/2 "2012-04-12T08:36:54Z")

</div>

**[davedoors](https://sourceforge.net/u/davedoors/)** wrote on [Thursday, April 12, 2012](https://sourceforge.net/p/freertos/discussion/382005/thread/ec01bef0/#7b9e):

You will probably find that the uIP network driver is configured to send every packet twice, in which case you are receiving the same number of replies as requests. This is done sometimes as a cheap (if transmission is done by DMA) way of getting around the throughput problems caused by delayed acks when talking from a real time system to a desktop system.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [April 12, 2012, 10:48am UTC](https://forums.freertos.org/t/dup-echo-replies/5300/3 "2012-04-12T10:48:07Z")

</div>

**[thomas84](https://sourceforge.net/u/thomas84/)** wrote on [Thursday, April 12, 2012](https://sourceforge.net/p/freertos/discussion/382005/thread/ec01bef0/#494e):

I have found the part where the second reply is sent and now there’s only one reply, BUT between the request and the reply there is something on the cable 010101010101…. for one frame like uIP always wants to send two frames and if i take one frame away, it just writes 01010101 for one frame. I want to tell uIP that i only want 1 frame to be send. Any idea what i can adjust?

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [April 12, 2012, 11:00am UTC](https://forums.freertos.org/t/dup-echo-replies/5300/4 "2012-04-12T11:00:52Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Thursday, April 12, 2012](https://sourceforge.net/p/freertos/discussion/382005/thread/ec01bef0/#9ad4):

In that particular project the double send is done in the ISR void vEMAC\_ISR( void ) in emac.c

```
	if( ulStatus & INT_TX_DONE )
	{
		if( usSendLen > 0 )
		{
			/* Send the data again, using the second descriptor. As there are
			only two descriptors the index is set back to 0. */
			TX_DESC_PACKET( ( emacTX_DESC_INDEX + 1 ) ) = TX_DESC_PACKET( emacTX_DESC_INDEX );
			TX_DESC_CTRL( ( emacTX_DESC_INDEX + 1 ) ) = ( usSendLen | TCTRL_LAST | TCTRL_INT );
			LPC_EMAC->TxProduceIndex = ( emacTX_DESC_INDEX );
			/* This is the second Tx so set usSendLen to 0 to indicate that the
			Tx descriptors will be free again. */
			usSendLen = 0UL;
		}
		else
		{
			/* The Tx buffer is no longer required. */
			prvReturnBuffer( ( unsigned char * ) TX_DESC_PACKET( emacTX_DESC_INDEX ) );
            TX_DESC_PACKET( emacTX_DESC_INDEX ) = ( unsigned long ) NULL;
		}
	}

```

I haven’t tried this, but it looks like you could remove the double send by changing it to something like this:

```
	if( ulStatus & INT_TX_DONE )
	{
		/* The Tx buffer is no longer required. */
		prvReturnBuffer( ( unsigned char * ) TX_DESC_PACKET( emacTX_DESC_INDEX ) );
		TX_DESC_PACKET( emacTX_DESC_INDEX ) = ( unsigned long ) NULL;
		LPC_EMAC->TxProduceIndex = ( emacTX_DESC_INDEX );
	}

```

but I’m not 100% confident of that - you would have to look at how the transmit function was using the descriptor too.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [April 12, 2012, 11:41am UTC](https://forums.freertos.org/t/dup-echo-replies/5300/5 "2012-04-12T11:41:15Z")

</div>

**[thomas84](https://sourceforge.net/u/thomas84/)** wrote on [Thursday, April 12, 2012](https://sourceforge.net/p/freertos/discussion/382005/thread/ec01bef0/#9563):

I tried it and if i change the code like in your example above, i get no response from target.  
This is the transmit function:&nbsp;

void vSendEMACTxData( unsigned short usTxDataLen )  
{  
unsigned long ulAttempts = 0UL;

/\* Check to see if the Tx descriptor is free, indicated by its buffer being  
NULL. \*/  
while( TX\_DESC\_PACKET( emacTX\_DESC\_INDEX ) != ( unsigned long ) NULL )  
{  
/\* Wait for the Tx descriptor to become available. \*/  
vTaskDelay( emacBUFFER\_WAIT\_DELAY );

ulAttempts++;  
if( ulAttempts \> emacBUFFER\_WAIT\_ATTEMPTS )  
{  
/\* Something has gone wrong as the Tx descriptor is still in use.  
Clear it down manually, the data it was sending will probably be  
lost. \*/  
prvReturnBuffer( ( unsigned char \* ) TX\_DESC\_PACKET( emacTX\_DESC\_INDEX ) );  
break;  
}  
}

/\* Setup the Tx descriptor for transmission.&nbsp; Remember the length of the  
data being sent so the second descriptor can be used to send it again from  
within the ISR. \*/  
usSendLen = usTxDataLen;  
TX\_DESC\_PACKET( emacTX\_DESC\_INDEX ) = ( unsigned long ) uip\_buf;  
TX\_DESC\_CTRL( emacTX\_DESC\_INDEX ) = ( usTxDataLen | TCTRL\_LAST | TCTRL\_INT );  
LPC\_EMAC-\>TxProduceIndex = ( emacTX\_DESC\_INDEX + 1 );

/\* uip\_buf is being sent by the Tx descriptor.&nbsp; Allocate a new buffer. \*/  
uip\_buf = prvGetNextBuffer();  
}

and this the EMAC\_ISR:

{  
unsigned long ulStatus;  
long lHigherPriorityTaskWoken = pdFALSE;

ulStatus = LPC\_EMAC-\>IntStatus;

/\* Clear the interrupt. \*/  
LPC\_EMAC-\>IntClear = ulStatus;

if( ulStatus & INT\_RX\_DONE )  
{  
/\* Ensure the uIP task is not blocked as data has arrived. \*/  
xSemaphoreGiveFromISR( xEMACSemaphore, &lHigherPriorityTaskWoken );  
}

if( ulStatus & INT\_TX\_DONE )  
{

if( usSendLen \> 0 )  
{  
// Send the data again, using the second descriptor.&nbsp; As there are  
//only two descriptors the index is set back to 0.

TX\_DESC\_PACKET( ( emacTX\_DESC\_INDEX + 1 ) ) = TX\_DESC\_PACKET( emacTX\_DESC\_INDEX );  
TX\_DESC\_CTRL( ( emacTX\_DESC\_INDEX + 1 ) ) = ( usSendLen | TCTRL\_LAST | TCTRL\_INT );  
LPC\_EMAC-\>TxProduceIndex = ( emacTX\_DESC\_INDEX );

// This is the second Tx so set usSendLen to 0 to indicate that the  
// Tx descriptors will be free again.  
usSendLen = 0UL;  
}  
else  
{  
// The Tx buffer is no longer required.  
prvReturnBuffer( ( unsigned char \* ) TX\_DESC\_PACKET( emacTX\_DESC\_INDEX ) );  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TX\_DESC\_PACKET( emacTX\_DESC\_INDEX ) = ( unsigned long ) NULL;  
}

}

portEND\_SWITCHING\_ISR( lHigherPriorityTaskWoken );  
}

If i delete the line: TX\_DESC\_PACKET( ( emacTX\_DESC\_INDEX + 1 ) ) = TX\_DESC\_PACKET( emacTX\_DESC\_INDEX );  
in the EMAC\_ISR i can ping&nbsp; and i have only one reply, but the problem remains, that 01010101 on the cable as if the programm has to output two frames…
