• 0

LWIP Echo Server Application: KC705


Question

I need to transfer the data from the kc705 board to the PC using LWIP Echo Server.

Design Flow as follows as below:

1. Counter data from Kintex DAQ board (Part Number : XC7k160tffg676-2) is passing to the KINTEX KC705 board through optical cable [Completed]

2. KINTEX KC705 board Should pass the data to PC through LWIP Echo server [Unable to pass the received data to TCP].

I am new to Ethernet Design [Network] so apology me for asking silly question. For me doubt in Echo Coding part.

/////////////////////Function to receive Data in KC705 from DAQ board //////////////
int RxReceive (XLlFifo *InstancePtr, u32* DestinationAddr)
{

	int i;
	//int Status;
	u32 RxWord;
	static u32 ReceiveLength;

	ReceiveLength = (XLlFifo_iRxGetLen(InstancePtr))/WORD_SIZE;
	
	
	/* Start Receiving */
	if(ReceiveLength>0)
	{
		//xil_printf("@@@@@@@@@ ");

	for ( i=0; i < ReceiveLength; i++)
	{
		RxWord = 0;
		RxWord = XLlFifo_RxGetWord(InstancePtr);
	
		*(DestinationAddr+i) = RxWord;
		//*(DestinationAddr+i) = 10;
		xil_printf("received data : %d\n\r",*(DestinationAddr+i));
	}
	}

return XST_SUCCESS;
}

How to pass that received data into TCP [tcp_write() function]. I have coded Please correct if i am wrong.

extern u32 DestinationBuffer[1024];   // Globally Declared : Counter Values are stored in destination buffer. Those values i am passing to tx_func. That function is called in recv_callback. 

extern void tx_func(struct tcp_pcb *tpcb)
{
int i,Status;
Status=aurora_rx_main();
for(i=0;i<1024;i++)
	 {
    xil_printf("%d,",DestinationBuffer[i]);
     }
	 
tcp_write(tpcb, DestinationBuffer, 1024, 0); //////////////// tcp_write Function getting data from DestinationBuffer
}

err_t recv_callback(void *arg, struct tcp_pcb *tpcb,
                               struct pbuf *p, err_t err)
{
	
	/* do not read the packet if we are not in ESTABLISHED state */
	if (!p) {
		tcp_close(tpcb);
		tcp_recv(tpcb, NULL);
		return ERR_OK;
	}

	/* indicate that the packet has been received */
	tcp_recved(tpcb, p->len);

	/* echo back the payload */
	/* in this case, we assume that the payload is < TCP_SND_BUF */
	tcp_recved(tpcb, p->len); 
	{
	
	tx_func(tcp_pcb)

	} else
		xil_printf("no space in tcp_sndbuf\n\r");

	/* free the received pbuf */
	pbuf_free(p);

	return ERR_OK;
}

 

Link to post
Share on other sites

7 answers to this question

Recommended Posts

  • 0

Hi @Thausikan,

I have not altered the echo.c to transfer data as you are trying to do. I have attached an altered echo.c that looks for a specific string and returns a specific string. I did find a few xilinx forum threads that might be helpful here and here. I would also look at the added templates in SDK 2018.2 for the LWiP as well.

thank you,

Jon

echo (3).txt

Link to post
Share on other sites
  • 0

Thanks for your response.

Now i am able to read the data in PC through Hercules. But in Hercules or in Python files, i am getting same error (some junk values are printing). Can anyone explain me how tcp_write function works.

static char buf[64] = {0};
//extern u32 DestinationBuffer[50];
int transfer_data() {
	return 0;
}
char *itoa(int val, int base){

 int i = 30;
for(; val && i ; --i, val /= base)
buf[i] = "0123456789abcdef"[val % base];
return &buf[i+1];
}
err_t recv_callback(void *arg, struct tcp_pcb *tpcb,
                               struct pbuf *p, err_t err)
{
	int i,j,Status;
	Status=aurora_rx_main();         ///FUNCTION CALL

	for(i=0;i<50;i++)
     {
		xil_printf("%d,", DestinationBuffer[i]);
	}

    int base=10; // here 10 means decimal
     char *result={0};

	if (!p) {
		tcp_close(tpcb);
		tcp_recv(tpcb, NULL);
		return ERR_OK;
	}

	/* indicate that the packet has been received */
	tcp_recved(tpcb, p->len);

	if (tcp_sndbuf(tpcb) > 50) {
		 for (j=0;j<=50;j++)
		    {
		    result= itoa(DestinationBuffer[j],base);
		    err = tcp_write(tpcb,",",1,1);
		    err = tcp_write(tpcb,result,32,1);
		    }
	} else
		xil_printf("no space in tcp_sndbuf\n\r");

	/* free the received pbuf */
	pbuf_free(p);

	return ERR_OK;
}

Please tell me how to increase p->len size or else how to clear the junk values

Capture.JPG

Hercules_Error.JPG

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now