public inbox for ecos-devel@sourceware.org
 help / color / mirror / Atom feed
* cyg_io_read blocking
@ 2005-04-08 10:41 Raghu
  2005-04-08 12:33 ` Bart Veer
  0 siblings, 1 reply; 3+ messages in thread
From: Raghu @ 2005-04-08 10:41 UTC (permalink / raw)
  To: ecos

Hi, 
Sample code of "cyg_io_read", "cyg_io_write" that
blocks when a thread is spawned, but if called from a 
functions dosent.

void cyg_user_start( void )
{
    cyg_thread_create( 4, serial_thread_handler, ...
                     );
    cyg_thread_resume( handle );
}

void serial_thread_handler( cyg_addrword_t data )
{
     cyg_io_lookup( &hdl );
     for( ; ; ){
          cyg_io_read( hdl, &ch, &len );
          cyg_io_write( hdl, &ch, &len );
     }
}

But if "serial_thread_handler" is directly called from
"cyg_user_start" as a function call, there is no
issues.

Regards,
Raghu.


		
__________________________________ 
Do you Yahoo!? 
Take Yahoo! Mail with you! Get it on your mobile phone. 
http://mobile.yahoo.com/maildemo 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: cyg_io_read blocking
  2005-04-08 10:41 cyg_io_read blocking Raghu
@ 2005-04-08 12:33 ` Bart Veer
  2005-04-08 12:44   ` Gary Thomas
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Veer @ 2005-04-08 12:33 UTC (permalink / raw)
  To: raghu_dk; +Cc: ecos-devel

>>>>> "Raghu" == Raghu  <raghu_dk@yahoo.com> writes:

    Raghu> Sample code of "cyg_io_read", "cyg_io_write" that blocks
    Raghu> when a thread is spawned, but if called from a functions
    Raghu> dosent.

    Raghu> void cyg_user_start( void )
    Raghu> {
    Raghu>     cyg_thread_create( 4, serial_thread_handler, ...
    Raghu>                      );
    Raghu>     cyg_thread_resume( handle );
    Raghu> }

    Raghu> void serial_thread_handler( cyg_addrword_t data )
    Raghu> {
    Raghu>      cyg_io_lookup( &hdl );
    Raghu>      for( ; ; ){
    Raghu>           cyg_io_read( hdl, &ch, &len );
    Raghu>           cyg_io_write( hdl, &ch, &len );
    Raghu>      }
    Raghu> }

    Raghu> But if "serial_thread_handler" is directly called from
    Raghu> "cyg_user_start" as a function call, there is no
    Raghu> issues.

cyg_user_start() is run during system startup, before the scheduler is
started or interrupts are enabled. There is no way for the system to
block at this time. Blocking involves transferring control to another
thread, possibly the idle thread, and that cannot happen if the
scheduler has not yet started.

A typical cyg_user_start() performs little if any I/O. Instead it just
performs operations that affect the cpu and memory, e.g. starting one
or more threads. Sometimes I/O at this stage cannot be avoided, but it
will have to be non-blocking I/O in a polling loop.

Bart

-- 
Bart Veer                       eCos Configuration Architect
http://www.ecoscentric.com/     The eCos and RedBoot experts

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: cyg_io_read blocking
  2005-04-08 12:33 ` Bart Veer
@ 2005-04-08 12:44   ` Gary Thomas
  0 siblings, 0 replies; 3+ messages in thread
From: Gary Thomas @ 2005-04-08 12:44 UTC (permalink / raw)
  To: raghu_dk; +Cc: eCos development

On Fri, 2005-04-08 at 13:33 +0100, Bart Veer wrote:
> >>>>> "Raghu" == Raghu  <raghu_dk@yahoo.com> writes:
> 
>     Raghu> Sample code of "cyg_io_read", "cyg_io_write" that blocks
>     Raghu> when a thread is spawned, but if called from a functions
>     Raghu> dosent.
> 
>     Raghu> void cyg_user_start( void )
>     Raghu> {
>     Raghu>     cyg_thread_create( 4, serial_thread_handler, ...
>     Raghu>                      );
>     Raghu>     cyg_thread_resume( handle );
>     Raghu> }
> 
>     Raghu> void serial_thread_handler( cyg_addrword_t data )
>     Raghu> {
>     Raghu>      cyg_io_lookup( &hdl );
>     Raghu>      for( ; ; ){
>     Raghu>           cyg_io_read( hdl, &ch, &len );
>     Raghu>           cyg_io_write( hdl, &ch, &len );
>     Raghu>      }
>     Raghu> }
> 
>     Raghu> But if "serial_thread_handler" is directly called from
>     Raghu> "cyg_user_start" as a function call, there is no
>     Raghu> issues.
> 
> cyg_user_start() is run during system startup, before the scheduler is
> started or interrupts are enabled. There is no way for the system to
> block at this time. Blocking involves transferring control to another
> thread, possibly the idle thread, and that cannot happen if the
> scheduler has not yet started.
> 
> A typical cyg_user_start() performs little if any I/O. Instead it just
> performs operations that affect the cpu and memory, e.g. starting one
> or more threads. Sometimes I/O at this stage cannot be avoided, but it
> will have to be non-blocking I/O in a polling loop.

Two more things to mention:

* RedBoot uses cyg_user_start, as do most of our test programs, to
have finer grain control over the actual execution environment.  RedBoot
runs without a kernel, thus no threads, scheduler, etc.  Using 
cyg_user_start simply minimizes the setup and makes the independence
from the scheduler clear.

* If you want to do threaded operations, you'll need to use a serial
device driver that supports this - not /dev/ttydiag which does not.
It's not clear what driver/device your I/O channel is connected to,
but it needs to be a "standard serial" driver, e.g. /dev/ser0

Finally, this thread really should be on ecos-discuss since it's
an operational issue, not a development (of eCos) one.

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-04-08 12:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-08 10:41 cyg_io_read blocking Raghu
2005-04-08 12:33 ` Bart Veer
2005-04-08 12:44   ` Gary Thomas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).