[ECOS] serial output problem:cyg_io_write and printf

liu hua rongye_liu@hotmail.com
Wed Mar 9 22:23:00 GMT 2005


Thank you for your reply.

I try use cyg_io_get_config() befor cyg_io_write() and after 
cyg_io_write(),but the result is same. When I use GDB and set breakpoint in 
the line of cyg_io_write(),the output somtime is normal. So,I guess that I 
can try delay before and after cyg_io_write(). I use the 
cyg_thread_delay():
          ...
          cyg_thread_delay(2);
          cyg_io_write();
          cyg_thread_delay(1);
          ...

and the output message is normal.

If I only use the second cyg_thread_delay,the cyg_io_write() have no output 
message. If I only use the first cyg_thread_delay, the output message is:
           Starting serial example
           Found /dev/tty0. Writing string....
           serial example isI think I wrote the string. Did you see it?
           working correctly!

If I use both cyg_thread_delay,and the first cyg_thread_delay() use delay 
value "1" not "2",the result is :
           Starting serial example
           Found /dev/tty0. Writing string....
           serial example isI think I wrote the string. Did you see it?
           
Where is the problem?


>From: Andrew Lunn <andrew@lunn.ch>
>To: liu hua <rongye_liu@hotmail.com>
>CC: ecos-discuss@sources.redhat.com
>Subject: Re: [ECOS] serial output problem:cyg_io_write and printf
>Date: Wed, 9 Mar 2005 10:55:13 +0100
>
>On Wed, Mar 09, 2005 at 05:06:22PM +0800, liu hua wrote:
> > When I use cyg_io_write() write serial(/dev/tty0) in the main() 
function,it
> > is ok. But when I use cyg_io_write() in a thread created in main(),the
> > serial port have no output message.
> >
> > The simple program is:
> > 	int main(void)
> > 	{
> > 	    cyg_io_handle_t handle;
> > 	    Cyg_ErrNo err;
> > 	    char read_string[50];
> > 	    const char test_string[] = "serial example is working
> > 	    correctly!\n";
> > 	    cyg_uint32 len = strlen(test_string);
> >
> > 	    printf("Starting serial example\n");
> > 	    err = cyg_io_lookup( "/dev/tty0", &handle );
> > 	    if (ENOERR == err) {
> > 	        printf("Found /dev/tty0. Writing string....\n");
> > 	        err = cyg_io_write( handle, test_string, &len );
> > 	    }
> > 	    if (ENOERR == err) {
> > 	        printf("I think I wrote the string. Did you see it?\n");
> >
> > 	    }
> > 	}
> > the output message is:
> >           Starting serial example
> >           Found /dev/tty0. Writing string....
> >           I think I wrote the string. Did you see it?
> >           serial example is working correctly!
> >
> > But,if I use follow program:
> > 	static void simple_prog(CYG_ADDRESS data)
> > 	{
> > 	    cyg_io_handle_t handle;
> > 	    Cyg_ErrNo err;
> > 	    char read_string[50];
> > 	    const char test_string[] = "serial example is working
> > 	    correctly!\n";
> > 	    cyg_uint32 len = strlen(test_string);
> >
> > 	    printf("Starting serial example\n");
> > 	    err = cyg_io_lookup( "/dev/tty0", &handle );
> > 	    if (ENOERR == err) {
> > 	        printf("Found /dev/tty0. Writing string....\n");
> > 	        err = cyg_io_write( handle, test_string, &len );
> > 	    }
> > 	    if (ENOERR == err) {
> > 	        printf("I think I wrote the string. Did you see it?\n");
> >
> > 	    }
> > 	}
> > 	int main(void)
> > 	{
> > 	    cyg_thread_create(4, simple_prog, (cyg_addrword_t) 0, "serial",
> > 	                      (void *)stack[0], STACKSIZE, &thread[0],
> > &thread_obj[0]);
> > 	    cyg_thread_resume(thread[0]);
> > 	}
> > the output messages is:
> >          Starting serial example
> >          Found /dev/tty0. Writing string....
> >          I think I wrote the string. Did you see it?
> > There is no cyg_io_write() output message "serial example is working
> > correctly!" .
> >
> > In this program,I have two problem:
> >  1) In a thread created in main(),why cyg_io_write() cannt write serial
> > port?
> >  2) In main(),the cyg_io_write() can write serial port,but the output
> > message is in the last line (after all printf()).Why?
>
>printf() will be using the diag serial driver. This is designed to
>directly write its output to the serial hardware using polled IO.
>
>By openning /dev/tty0 you are using the interrupt driven serial driver
>and i think buffered IO. Im guessing that when main ends the serial
>drivers buffers are getting flushed and so the buffered output is then
>being sent. When you are using a thread this flushing is not
>happening.
>
>The is cyg_io_get_config you can call to force the buffer to be
>flushed. See
>
>http://ecos.sourceware.org/docs-latest/ref/io-serial-driver-details.html
>
>         Andrew.

_________________________________________________________________
ÓëÁª»úµÄÅóÓѽøÐн»Á÷£¬ÇëʹÓà MSN Messenger:  http://messenger.msn.com/cn  


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



More information about the Ecos-discuss mailing list