public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] serial output problem:cyg_io_write and printf
@ 2005-03-09 11:59 liu hua
  2005-03-09 13:24 ` Andrew Lunn
  2005-03-09 14:40 ` David Brennan
  0 siblings, 2 replies; 4+ messages in thread
From: liu hua @ 2005-03-09 11:59 UTC (permalink / raw)
  To: ecos-discuss

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=gb2312; format=flowed, Size: 2613 bytes --]

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?
  
I need get some HELP !

_________________________________________________________________
Ãâ·ÑÏÂÔØ MSN Explorer:   http://explorer.msn.com/lccn  


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

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

* Re: [ECOS] serial output problem:cyg_io_write and printf
  2005-03-09 11:59 [ECOS] serial output problem:cyg_io_write and printf liu hua
@ 2005-03-09 13:24 ` Andrew Lunn
  2005-03-09 22:23   ` liu hua
  2005-03-09 14:40 ` David Brennan
  1 sibling, 1 reply; 4+ messages in thread
From: Andrew Lunn @ 2005-03-09 13:24 UTC (permalink / raw)
  To: liu hua; +Cc: ecos-discuss

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. 

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

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

* Re: [ECOS] serial output problem:cyg_io_write and printf
  2005-03-09 11:59 [ECOS] serial output problem:cyg_io_write and printf liu hua
  2005-03-09 13:24 ` Andrew Lunn
@ 2005-03-09 14:40 ` David Brennan
  1 sibling, 0 replies; 4+ messages in thread
From: David Brennan @ 2005-03-09 14:40 UTC (permalink / raw)
  To: liu hua; +Cc: ecos-discuss



liu hua wrote:
<...>

>
> 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]);

I think you probably want this to be (depending on how stack is declared):
cyg_thread_create(4, simple_prog, (cyg_addrword_t) 0, "serial",
(void *)*&*stack[0], STACKSIZE, &thread[0], &thread_obj[0]);
You are probably running with a corrupted stack in your created thread.

Dave

>

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

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

* Re: [ECOS] serial output problem:cyg_io_write and printf
  2005-03-09 13:24 ` Andrew Lunn
@ 2005-03-09 22:23   ` liu hua
  0 siblings, 0 replies; 4+ messages in thread
From: liu hua @ 2005-03-09 22:23 UTC (permalink / raw)
  To: andrew; +Cc: ecos-discuss

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=gb2312; format=flowed, Size: 4861 bytes --]

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

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

end of thread, other threads:[~2005-03-09 14:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-03-09 11:59 [ECOS] serial output problem:cyg_io_write and printf liu hua
2005-03-09 13:24 ` Andrew Lunn
2005-03-09 22:23   ` liu hua
2005-03-09 14:40 ` David Brennan

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).