[ECOS] serial output problem:cyg_io_write and printf

liu hua rongye_liu@hotmail.com
Wed Mar 9 11:59:00 GMT 2005


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



More information about the Ecos-discuss mailing list