Hi Julio,
To be honest I never used LwIP without OS I always use FreeRTOS. I hope I will
not make any errors in my replies.
Lets se...
To make it simpler to understand. Think on the following scenario... main has
some endless loop that does something...
Assume it is turning on/off a LED... so the LED is blinks at a constant rate.
Now you have an interrupt, any interrupt.
The code changes context and control is changing to the interrupt level.
Until you do not finish handling the interrupt code the main code that was
causing the LED to blink will not run and
The LED will stop blinking !
LwIP in RAW mode works in a similar manner as the simple example above.
LwIP in RAW mode works either as a single task when you have an OS or it is
ticking by its own when you do not have
an OS... you have a timer interrupt ticking or some other way depending on the
driver you have and environment.
The example in the following link simply has an endless loop in main, see here:
http://lwip.wikia.com/wiki/LwIP_with_or_without_an_operating_system
As you can see in the above example main is running an infinite loot that
call's LwIP all the time. This is actually
running the internal TCP timers, allocating buffers, freeing buffers when they
are no longer needed etc...
LwIP in RAW mode works with call-back function. For example when the TCP stack
receives a packet destined
to your code (IP + port) your own receive function is called. This is like an
interrupt. Until you do not exit from the
function (the call-back) the internal handling is not running.
Now how to handle sending data depends on you system architecture. Meaning, if
you response to data received
this is one scenario, if you want to send some data periodically it is a bit
different etc...
LwIP has an internal mechanism to add call-backs on the fly or in other words
it enables you to call your own code
from within the LwIP context.
One way of doing it is using the following:
This is LwIP call-back function prototype:
/** Function prototype for functions passed to tcpip_callback() */
typedef void (*tcpip_callback_fn)(void *ctx);
I am assuming you use TCP, so you can create a function like this:
// create your own call back function that will be added to LwIP list of
internal handling.
void MyTcpServerSend(void *ctx)
{
static char data[] = "TEST_DATA";
err_t err;
struct tcp_pcb *tcp_pcb = (struct tcp_pcb *) ctx; // transfer the
connection pcb from recv function
// add the data to TCP stack and check if operation is ok, no need to
allocate anything your data is static
err = tcp_write(tcp_pcb, data, sizeof(data), 0);
if(err == ERR_OK)
{
// ask the TCP stack to send data now.
tcp_output(pTcpUdpConData->tcp_pcb);
}
else
{
// if error you can close the connection here by calling tcp_close etc...
}
}
In your recv call back you get some data and decide to send something back,
What you do is something like this:
err_t My_tcp_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
{
// do something ....
// decide to send something so add your own call bacl
tcpip_callback(MyTcpServerSend, pcb);
}
Another way to send something periodically is create a timer call back, this is
done once and if you want it
To happen every X seconds you need to add the call again in your timeout
function.
Your timer function looks like this:
void MyPeriodicalFunctionCall(struct tcp_pcb *pcb)
{
sys_timeout(TimIntervalInMs, MyTcpServerSend, pcb);
}
In your main or somewhere you call this once and it will then run periodically
MyPeriodicalFunctionCall(pcb);
Hope that helps :)
BR,
Noam.
From: lwip-users [mailto:[email protected]] On
Behalf Of Julio Cesar Aguilar Zerpa
Sent: Monday, October 31, 2016 11:00 AM
To: Mailing list for lwIP users
Subject: Re: [lwip-users] Tcp Server on Texas Instrument RM57
Hi Noam,
Thank you for helping me.
1. First of all are you running with an OS or without?
I am using the RM57 Microprocessor -> without OS
2. Secondly do you understand that with RAW API you should not call any LwIP if
the call is not from within the LwIP own context?
That is a very important point that I didn't know about! So, then how
should I send data? How do I initialize the pbuf pointer?
3. As far as I see you are not copying the data into the new buffer. How is the
send itself? does the function tcpecho_raw_send copying the data to the buffer?
Yes, you are right. I noticed that. I then tried it with "TEST_DATA" as
global. Same problem (but at least the data was correct at tcpecho_raw_send)
4. The code is just partial so I cannot see the picture
You can see the code if you have the examples. It's the 'tcpecho_raw'. I
will attach it just in case you don't have it. I made some minor modifications
to check if there's a connection and also added the function already described.
(Again: the 'echo' part works -> received data is being sent back correctly,
but sending data that wasn't received is not working)
5. Secondly check if tcp_write uses the copy mode into an internal buffer or
use a reference to data.
Yes, it uses the copy mode.
I also tried to send the data using the 'tcp_write' function directly instead
of calling tcpecho_raw_send and it returned error -11 (no connection) but was
receiving and sending data over the callbacks.
It appears your second statement is one of the reason my program is not
working. I don't have any current docu, do you have any?
How do I send data? Is there another example that receives data over callbacks
and is able to send data created on its own memory space?
Best regards,
Julio
Am 29.10.2016 um 02:04 schrieb Noam Weissman:
Hi,
First of all are you running with an OS or without ?
Secondly do you understand that with RAW API you should not call any LwIP
if the call is not from within the LwIP own context ?
As far as I see you are not copying the data into the new buffer. How is the
send itself ?
does the function tcpecho_raw_send copying the data to the buffer ?
RAW API means that everything you do is in the same context. If you block on
the function
tcpecho_raw_send and/or do something that takes too much time yes the data will
not properly
handled.
The code is just partial so I cannot see the picture.
I would start with setting your uint8 data[] = "TEST_DATA"; to static OUTSIDE
of the function. This way
it will not change when you exit from the function.
Secondly check if tcp_write uses the copy mode into an internal buffer or use a
reference to data.
BR,
Noam.
________________________________
From: lwip-users
<[email protected]><mailto:[email protected]>
on behalf of Julio Cesar Aguilar Zerpa
<[email protected]><mailto:[email protected]>
Sent: Friday, October 28, 2016 4:56 PM
To: [email protected]<mailto:[email protected]>
Subject: [lwip-users] Tcp Server on Texas Instrument RM57
Hi there,
I am trying to use the LwIP library (1.4.1) to create a simple tcp
server on a Texas Instrument RM57.
So far, I could make the "tcpecho_raw" example to work using an static ip.
I also added the following function (which did not work), to be able to
send data that wasn't an echo:
void tcpServer_send()
{
uint8 data[] = "TEST_DATA";
struct pbuf* buffer = pbuf_alloc(PBUF_RAW, sizeof(data), PBUF_POOL);
if (buffer)
{
sciDisplayText(sciREG1, txt_new_line, sizeof(txt_new_line));
sciDisplayText(sciREG1, "buffer created", sizeof("buffer
created"));
buffer->tot_len = sizeof(data);
buffer->len = sizeof(data);
buffer->payload = data;
tcpecho_es->p = buffer;
tcpecho_raw_send(tcpecho_raw_pcb, tcpecho_es);
}
}
As you can see, the function prints a debug msg ("buffer created"). I
modified the function 'tcpecho_raw_send' to also print a debug msg (the
data being sent).
When I run the program, I can see the msg "buffer created" every time
the function is called, but the msg from 'tcpecho_raw_send' comes only
when I close the client! (And the msg is missing the acutal data, btw).
NOTE: I want to build a server that receives some commands and sends a
block of data (4KB) every 60 ms. I am using the raw API because I don't
want to use blocking functions (from what I understood the netconn API
uses blocking functions).
I would appreciate any help.
Best regards,
Julio Aguilar
_______________________________________________
lwip-users mailing list
[email protected]<mailto:[email protected]>
https://lists.nongnu.org/mailman/listinfo/lwip-users
lwip-users -- Mailing list for lwIP users -
lists.nongnu.org<https://lists.nongnu.org/mailman/listinfo/lwip-users>
lists.nongnu.org
Welcome to the lwip-users mailing list. Use it to ask questions, share your
experience and discuss new ideas. To see the collection of prior postings to
the list ...
_______________________________________________
lwip-users mailing list
[email protected]<mailto:[email protected]>
https://lists.nongnu.org/mailman/listinfo/lwip-users
Mit freundlichen Grüßen
Götting KG
i.A. Julio Cesar Aguilar Zerpa
--
M.Sc. Julio Cesar Aguilar Zerpa
Forschung & Entwicklung
[email protected]<mailto:[email protected]>
Tel. +49(0)-5136-8096-39
--------------------
Götting KG
Celler Str. 5, D-31275 Lehrte/Röddensen
Geschäftsführer H.-H. Götting
HR A 31127 | Amtsgericht Hildesheim
Gerichtsstand Lehrte
USt.-Id. Nr. DE 115055039
USt.-Nr. 16-226-13403
Phone +49(0)-5136-8096-0
Fax +49(0)-5136-8096-80
[email protected]<mailto:[email protected]> |
www.goetting.de<http://www.goetting.de>
--------------------
_______________________________________________
lwip-users mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/lwip-users