cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Voyager
Voyager
9,430 Views
Registered: ‎10-25-2012

Where can I find the read (receive) and write (transmit) functions in standalone LwIP template project?

Jump to solution

I try to use Ethernet in ZC702 to achieve data receie and transmit. In C template project, it looks there is only one project relevant to Ethernet which is Lwip. However, it just do echo. I  wonder whether I can find the functions for trasmit and receive in this application?

 

Hope somebody who has experience can help me.  Thanks advance! 

0 Kudos
35 Replies
Highlighted
Voyager
Voyager
4,229 Views
Registered: ‎10-25-2012

Even I can't believe, I do the exact programming as we discussed, but it still does not work.

int transfer_data() {

char c[5]={1,2,3,4,5};
tcp_write(globalTCP_pcb,c,5,1);
return 0;
}

It still does not work. I can not receive anything in terminal. Even weird, if I keep the command in "recv_callback()" function,

err = tcp_write(tpcb,p->payload,p->len, 1);

When I put "tcp_write()" in "transfer_data()", "tcp_write()" in ""recv_callback()" does not work either. The echo disappear.

It looks like PCB pointer does not work after I assign it to a new global pointer but I don't knwo why.

 

I attached the "echo.c" file, you can have a look if you have time and are interested.

 

Thanks a lot.

0 Kudos
Highlighted
Visitor
Visitor
3,666 Views
Registered: ‎05-18-2014

I've been modifying the echo server also. I want it to return a "large" amount of data in response to a command sent to it from the client (on the PC). My server runs on a Zynq (ZC702 borad).  The server seems limited to sending back at most 8KByte of data in response to a packet from the client.  It seems that  tcp_write only moves data to an buffer of size 8KByte.  How do I force the data to get transmitted?  I want my client to request a large amount of data, and I want the recv_callback function to return this large amount of data. It seems that the data placed in some buffer by tcp_write only actually gets transmitted when rec_callback exits.

0 Kudos
Highlighted
Voyager
Voyager
3,659 Views
Registered: ‎02-10-2012

Hey

 

Okay so your question can be answered in two parts.

 

First : You can change the settings of your size of tcp_snd_buf in the BSP settings --> lwip--> tcp_options--> tcp_send_buf size. The default is set to 8192 bytes. So you are correct when you say that it is able to send only 8k of data.

 

Second : The tcp_write function writs the data for sending. But it does not send it immediately due to due the Nagle's algorithm and waits for more data so that it can send them efficiently. If you want to force the data out you have to call the tcp_output() afetr the tcp_write() call.

 

It is unadvisable to go against Nagle's algorithm in MOST cases. If you are fine tuning your lwip settings I advice you to follow these guidlines : http://lwip.wikia.com/wiki/Tuning_TCP

 

Hope it helps .

 

Regards

Arvind

0 Kudos
Highlighted
Visitor
Visitor
3,654 Views
Registered: ‎05-18-2014

Thanks arvindr.

 

However, I did try to call tcp_output()  (I forgot to mention that in the previous post) and that failed.  Then I found this that explains why (to a certain extent):

 

"tcp_write() merely enqueues TCP data for later transmission; it does not actually start transmitting. Nevertheless, when tcp_write() is called from within a recv callback as in this example, there is no need to call tcp_output() to start transmission of sent data (indeed, tcp_output() specifically declines to do anything if it is called from within the recv callback)."

http://lwip.wikia.com/wiki/Raw/TCP

 

This seems like a hint from the designers of lwIP that if you want to send more than 8KB, don't do it from recv_callback.

What's the recommended way of sending a large block of data, in response to a TCP message from the client? How does an FTP server send a large amount of data to a client?

 

Note that on the client side, I have a Python program that opens a TCP socket and keeps it open (there's only ever one computer controling the FPGA board). The client presents a GUI to a user.  The user selects one of several functions (buttons).  Selecting a function leads to the transmission of a command packet (a unique 32 bit value).  The server decodes the command in the recv_callback function.  Then it returns data (based on the command).  The client expect this data (and it knows the amount of data), so right after sending the command, the client calls "receive" on the socket.  And it keeps calling "receive" until all the data is received. Something like this:

 

    data = ''
    while len(data) < n:
        packet = sock.recv(n - len(data))
        if not packet:
            return None
        data += packet

 

A timeout of 1 sec is configured on the socket.

 

thanks

 

0 Kudos
Highlighted
Visitor
Visitor
597 Views
Registered: ‎10-10-2018

@buddha1987  @arvindnr 

 

could you kindly share what changes you finally made to transmit and receive data via ethernet using lwip echo server?

 

thank you in advance.

0 Kudos
Highlighted
Visitor
Visitor
579 Views
Registered: ‎10-10-2018

Hi @arvindnr @savula 

Thanks for your earlier replies, proved very useful.

But suppose i have data in BRAM, how to i load the packets (tcp/ethernet) with that data?

How to access BRAM data through ethernet? I want to read the written data from BRAM in the SDK terminal through ethernet.

 

Kindly help.

0 Kudos