public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] Serial I/O on the MBX860
@ 2000-02-03  0:40 Erik Theisen
  2000-02-03  2:41 ` Jamie Guinan
  0 siblings, 1 reply; 6+ messages in thread
From: Erik Theisen @ 2000-02-03  0:40 UTC (permalink / raw)
  To: ecos-discuss

Hi,

I have been trying to get stdin working on
the MBX860 using fgets().  This seems to result in
a hung CPU.

How do I make stdin work?

Thanks,
Erik

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

* Re: [ECOS] Serial I/O on the MBX860
  2000-02-03  0:40 [ECOS] Serial I/O on the MBX860 Erik Theisen
@ 2000-02-03  2:41 ` Jamie Guinan
  2000-02-03  7:51   ` Jonathan Larmour
  2000-02-03 12:15   ` Erik Theisen
  0 siblings, 2 replies; 6+ messages in thread
From: Jamie Guinan @ 2000-02-03  2:41 UTC (permalink / raw)
  To: Erik Theisen; +Cc: ecos-discuss

On Thu, 3 Feb 2000, Erik Theisen wrote:

> Hi,
> 
> I have been trying to get stdin working on
> the MBX860 using fgets().  This seems to result in
> a hung CPU.
> 
> How do I make stdin work?

Hi Erik,

In a nutshell, I think line buffering is broken in the eCos stdiostream
code. 

Try entering several lines of text until you pass 256 bytes, and
see if your code continues after that.

In a test program of mine, the call stack during a call to fgets() 
is,

#0  0x6d4 in serial_read (handle=0x97a4, _buf=0xa114, len=0xc3f0)
    at
/usr/local/ecos-1.2.1/packages/io/serial/v1_2_1/src/common/serial.c:161
#1  0xa20 in cyg_io_read (handle=0x97a4, buf=0xa114, len=0xc3f0)
    at /usr/local/ecos-1.2.1/packages/io/common/v1_2_1/src/iosys.c:182
#2  0x4869 in Cyg_StdioStream::refill_read_buffer (this=0xa108)
    at
/usr/local/ecos-1.2.1/packages/language/c/libc/v1_2_1/src/stdio/common/stream.cxx:248
#3  0x4eb2 in _fgets (s=0xc430 "", n=128, stream=0xa108)
    at
/usr/local/ecos-1.2.1/packages/language/c/libc/v1_2_1/src/stdio/input/fgets.cxx:77
#4  0x38 in main () at testcase.c:14
#5  0x78fb in cyg_libc_invoke_main ()
    at
/usr/local/ecos-1.2.1/packages/language/c/libc/v1_2_1/src/support/invokemain.cxx:82
#6  0x1ca1 in Cyg_HardwareThread::thread_entry (thread=0xa448)
    at
/usr/local/ecos-1.2.1/packages/kernel/v1_2_1/src/common/thread.cxx:92
#7  0xdeadbeef in ?? ()


At level #0, the code in serial_read() is doing,

        while (size++ < *len) {
            *buf++ = (funs->getc)(chan);
        }


where *len is 256.  Not only is there no check for \r or \n,
but serial_read() intends to read 256 characters when I only
asked for 128 in fgets.

Same thing happens in fgetc.

Where did the 256 come from?  Go up a few more levels.

serial_read (handle=0x9784, _buf=0xa0f4, len=0xc3d4)
cyg_io_read (handle=0x9784, buf=0xa0f4, len=0xc3d4)
Cyg_StdioStream::refill_read_buffer (this=0xa0e8)  <=======
_fgetc (stream=0xa0e8)
main ()
cyg_libc_invoke_main ()


In Cyg_StdioStream::refill_read_buffer(), when flags.buffering
is set, "len" is assigned 256 here,

    if (flags.buffering) {
        len = io_buf.get_buffer_addr_to_write( (cyg_uint8**)&buffer );
        if (!len) { // no buffer space available
            unlock_me();
            return ENOERR;  // isn't an error, just needs user to read out
data
        } // if
    }


You can try setvbuf(_IONBF), but I think that does something weird,
too.

The test program is below, try defining TEST1 or TEST2 (not both)
and see what happens.

I reported this to my former supervisor (before I became
the Cygnus contact on the project) but he might have
failed to report it to Cygnus.  I started fiddling with the 
serial port after I encountered this so I kind of forgot about
it.

-Jamie

---------------------------------------------------------------

/*
 * testcase.c stdio input test case
 */

#include <stdio.h>

#define TEST1

int main()
{
  char buffer[128];
#ifdef TEST1
  char bufx[512];
#endif

#ifdef TEST1
  setvbuf(stdin, bufx, _IOLBF, sizeof(bufx));
#endif

#ifdef TEST2
  setvbuf(stdin, NULL, _IONBF, 0);  
#endif

  while (1)
    {
      printf("$ ");
      fflush(stdout);
      fgets(buffer, sizeof(buffer), stdin);
      printf("you entered: %s\n", buffer);
    }
  return 0;
}


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

* Re: [ECOS] Serial I/O on the MBX860
  2000-02-03  2:41 ` Jamie Guinan
@ 2000-02-03  7:51   ` Jonathan Larmour
  2000-02-03  8:06     ` Andrew Lunn
  2000-02-03 12:19     ` Erik Theisen
  2000-02-03 12:15   ` Erik Theisen
  1 sibling, 2 replies; 6+ messages in thread
From: Jonathan Larmour @ 2000-02-03  7:51 UTC (permalink / raw)
  To: guinan; +Cc: Erik Theisen, ecos-discuss

Jamie Guinan wrote:
> 
> On Thu, 3 Feb 2000, Erik Theisen wrote:
> 
> > Hi,
> >
> > I have been trying to get stdin working on
> > the MBX860 using fgets().  This seems to result in
> > a hung CPU.
> >
> > How do I make stdin work?
> 
> Hi Erik,
> 
> In a nutshell, I think line buffering is broken in the eCos stdiostream
> code.
> 
> Try entering several lines of text until you pass 256 bytes, and
> see if your code continues after that.

I think I know the eCos 1.2.1 problem you mean - it was because of a poorly
chosen default for CYGDAT_LIBC_STDIO_DEFAULT_CONSOLE, which was set to
/dev/haldiag instead of /dev/ttydiag. Try the second one and see what
happens. If it's still broke, then I'll have a closer look :-).

Jifl

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

* Re: [ECOS] Serial I/O on the MBX860
  2000-02-03  7:51   ` Jonathan Larmour
@ 2000-02-03  8:06     ` Andrew Lunn
  2000-02-03 12:19     ` Erik Theisen
  1 sibling, 0 replies; 6+ messages in thread
From: Andrew Lunn @ 2000-02-03  8:06 UTC (permalink / raw)
  To: Jonathan Larmour; +Cc: guinan, etheisen, ecos-discuss

> > Try entering several lines of text until you pass 256 bytes, and
> > see if your code continues after that.
> 
OA> I think I know the eCos 1.2.1 problem you mean - it was because of a poorly
> chosen default for CYGDAT_LIBC_STDIO_DEFAULT_CONSOLE, which was set to
> /dev/haldiag instead of /dev/ttydiag. Try the second one and see what
> happens. If it's still broke, then I'll have a closer look :-).

That fixed it for me on the synthetic target a few months ago. 

        Andrew

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

* Re: [ECOS] Serial I/O on the MBX860
  2000-02-03  2:41 ` Jamie Guinan
  2000-02-03  7:51   ` Jonathan Larmour
@ 2000-02-03 12:15   ` Erik Theisen
  1 sibling, 0 replies; 6+ messages in thread
From: Erik Theisen @ 2000-02-03 12:15 UTC (permalink / raw)
  To: guinan, ecos-discuss

Jamie Guinan wrote:
> 
> In a nutshell, I think line buffering is broken in the eCos stdiostream
> code.
> 
> Try entering several lines of text until you pass 256 bytes, and
> see if your code continues after that.

No, still doesn't work.  It seems someone is trying
to access an invalid location as the 860 is completely
hung.


> At level #0, the code in serial_read() is doing,
> 
>         while (size++ < *len) {
>             *buf++ = (funs->getc)(chan);
>         }
> 

I got to the same point in the code.  I beleive that
the function pointer getc is NULL.  But it maybe gdb
screwing up.

Erik

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

* Re: [ECOS] Serial I/O on the MBX860
  2000-02-03  7:51   ` Jonathan Larmour
  2000-02-03  8:06     ` Andrew Lunn
@ 2000-02-03 12:19     ` Erik Theisen
  1 sibling, 0 replies; 6+ messages in thread
From: Erik Theisen @ 2000-02-03 12:19 UTC (permalink / raw)
  To: Jonathan Larmour, ecos-discuss

Jonathan Larmour wrote:

> I think I know the eCos 1.2.1 problem you mean - it was because of a poorly
> chosen default for CYGDAT_LIBC_STDIO_DEFAULT_CONSOLE, which was set to
> /dev/haldiag instead of /dev/ttydiag. Try the second one and see what
> happens. If it's still broke, then I'll have a closer look :-).

That is fixed in anoncvs.  I am using the later device
as specified in libc.h.

I beleive there is a bad memory access going on.  See
my previous post to ecos-discuss.

Is getc implemented for the MBX's QUICC driver?

Erik

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

end of thread, other threads:[~2000-02-03 12:19 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-02-03  0:40 [ECOS] Serial I/O on the MBX860 Erik Theisen
2000-02-03  2:41 ` Jamie Guinan
2000-02-03  7:51   ` Jonathan Larmour
2000-02-03  8:06     ` Andrew Lunn
2000-02-03 12:19     ` Erik Theisen
2000-02-03 12:15   ` Erik Theisen

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