TCP/IP stack and threading question

View: New views
5 Messages — Rating Filter:   Alert me  

TCP/IP stack and threading question

by Tim Hatton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
I am trying to write a fairly straight forward eCos app and I am trouble understanding how the TCP/IP stack should behave with application threads (or vice versa).

I am using the FreeBSD TCP/IP stack and I have written a small C++ application. My app has a cyg_user_start function which currently creates and resumes a single thread. In my thread I successfully initialise the network interface with init_all_network_interfaces(); and then go into a loop which is (at the moment at least) a simple CLI (reading commands from the serial port and replies to it).

Now, what I have observed is that when I am in my thread's loop I can't ping to the eCos machine (even though the link is up). If I exit from my thread,  I can ping it no problem.

So, what am I doing wrong here? Do I need to have an application thread that handles the "background" TCP/IP stuff link answering ping? I was assuming this stuff would just work but now I suspect I've misunderstood something fundamental.
Any advice would be grately appreciated.
Thanks in advance,
Best regards,
Tim Hatton


Re: TCP/IP stack and threading question

by Gary Thomas :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Tim Hatton wrote:

> Hi,
> I am trying to write a fairly straight forward eCos app and I am trouble
> understanding how the TCP/IP stack should behave with application threads
> (or vice versa).
>
> I am using the FreeBSD TCP/IP stack and I have written a small C++
> application. My app has a cyg_user_start function which currently creates
> and resumes a single thread. In my thread I successfully initialise the
> network interface with init_all_network_interfaces(); and then go into a
> loop which is (at the moment at least) a simple CLI (reading commands from
> the serial port and replies to it).
>
> Now, what I have observed is that when I am in my thread's loop I can't ping
> to the eCos machine (even though the link is up). If I exit from my thread,
> I can ping it no problem.
>
> So, what am I doing wrong here? Do I need to have an application thread that
> handles the "background" TCP/IP stuff link answering ping? I was assuming
> this stuff would just work but now I suspect I've misunderstood something
> fundamental.

What device are you using to read commands from the serial port?

--
------------------------------------------------------------
Gary Thomas                 |  Consulting for the
MLB Associates              |    Embedded world
------------------------------------------------------------

--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss


Re: TCP/IP stack and threading question

by Tim Hatton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm using the "default" console device, which is set to "/dev/ttydiag" in the config.

Re: TCP/IP stack and threading question

by Gary Thomas :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Tim Hatton wrote:
> I'm using the "default" console device, which is set to "/dev/ttydiag" in the
> config.

There's your problem - "/dev/ttydiag" uses the RedBoot interfaces
which are polled, so while you're waiting for characters to arrive
on the CLI, the system never sees any network interrupts and thus
can't schedule the network threads, etc.

You'll need to use an interrupt-driven serial device instead.

--
------------------------------------------------------------
Gary Thomas                 |  Consulting for the
MLB Associates              |    Embedded world
------------------------------------------------------------

--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss


Re: TCP/IP stack and threading question

by Tim Hatton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Gary,
Thank you for that. I've changed the console to use tty0 and now it all seems to be working perfectly.
Thanks again for your help,
Best regards,
Tim