This is the mail archive of the ecos-discuss@sourceware.cygnus.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: printf("\n").


Sergei Organov wrote:
> 
> Hello,
> 
> I've done the initial part of porting eCos to the MPC50x processors. I even
> can run tests on my board now! But all tests that use stdio facilities output
> text strangely. The problem is that statements like 'printf("\n")' produce
> character sequence 0xA,0xD while the right sequence is 0xD,0xA. Macros like
> CYG_TEST_INFO produce right end-of-line sequence though.
> 
> Any ideas?

It's a bug. It should be CRLF, not LFCR. The bug is in
io/serial/VERSION/src/common/tty.c. Here's a not very well tested patch.
 
Index: src/common/tty.c
===================================================================
RCS file: /cvs/ecc/ecc/io/serial/current/src/common/tty.c,v
retrieving revision 1.10
diff -u -5 -p -r1.10 tty.c
--- tty.c       2000/02/02 19:12:03     1.10
+++ tty.c       2000/04/05 18:48:01
@@ -164,15 +164,16 @@ tty_write(cyg_io_handle_t handle, const
     // assert(chan)
     size = 0;
     bytes_successful = 0;
     actually_written = 0;
     while (bytes_successful++ < *len) {
-        xbuf[size++] = (c = *buf++);
+        c = *buf++;
         if ((c == '\n') &&
             (priv->dev_info.tty_out_flags & CYG_TTY_OUT_FLAGS_CRLF)) {
             xbuf[size++] = '\r';
         }
+        xbuf[size++] = c;
         // Always leave room for possible CR/LF expansion
         if ((size == (BUFSIZE-1)) ||
             (bytes_successful == *len)) {
             res = cyg_io_write(chan, xbuf, &size);
             if (res != ENOERR) {
@@ -218,11 +219,11 @@ tty_read(cyg_io_handle_t handle, void *_
                     cyg_io_write(chan, "\b \b", &clen);
                 }
             } else if ((c == '\n') || (c == '\r')) {
                 clen = 2;
                 if (priv->dev_info.tty_in_flags & CYG_TTY_IN_FLAGS_ECHO) {
-                    cyg_io_write(chan, "\n\r", &clen);
+                    cyg_io_write(chan, "\r\n", &clen);
                 }
                 if (priv->dev_info.tty_in_flags & CYG_TTY_IN_FLAGS_CRLF) {
                     c = '\n';  // Map CR -> LF
                 }
                 buf[size-1] = c;                    

A proper patch will be in anon cvs shortly.

> Attached is output of 'stdiooutput' test.
> 
> BTW, is it possible to turn off \n to <CR><LF> conversion entirely?

Look at the options for the "tty" devices in CYGPKG_IO_SERIAL_TTY.

Jifl
-- 
Red Hat, 35 Cambridge Place, Cambridge, UK. CB2 1NS  Tel: +44 (1223) 728762
"Plan to be spontaneous tomorrow."  ||  These opinions are all my own fault

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]