This is the mail archive of the ecos-discuss@sources.redhat.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: cyg_io_write & printf


Wolfram Kattanek wrote:
> 
> Gary Thomas <gthomas@cambridge.redhat.com>:
> 
> > > So here are my questions:
> > >
> > > - Why is the behavior so different when using main or cyg_user_start?
> >
> > It depends on when interrupts get enabled.
> 
> But when do they get enabled when using main() or cyg_user_start() without
> creating some user threads?

main() _is_ a thread. Or rather a thread is created solely to call main().
cyg_user_start() is not a thread, and before the scheduler is started,
interrupts are disabled.
 
> When I put the example code inside a user thread (created in cyg_user_start)
> everything seems to work fine. Does that mean that (only) the scheduler enables
> interrupts?

To all intents and purposes yes. You can arrange otherwise by directly
enabling interrupts, but you may have to deal with handling e.g. clock
interrupts.

> Can the scheduler also be started from inside main() (via creating
> a user thread)? When trying to do so I get the following assertion failure:
> 
> ASSERT FAIL: <2>intr.cxx   [571] static void Cyg_Interrupt::enable_interrupts()
> 
> Am I missing something fundamental about eCos?

Trying to start the scheduler from within main() is pointless as it is
alraedy started.

> > > - Is it possible to use both cyg_io_write and printf when only one physical
> > >   serial port is available?
> >
> > Yes, there is an option to get diagnostic output to basically go through 'cyg_io'
> 
> But this doesn't solve the above problems concerning mix of interrupt driven and
> polled output or am I wrong about that?

The point really is don't use printf or cyg_io_write from cyg_user_start().
Create a thread (or use main() ) and do it from there.

You can make printf() stop using the diagnostic output, and instead use the
interrupt-driven serial driver by setting CYGDAT_LIBC_STDIO_DEFAULT_CONSOLE
to /dev/tty0 from /dev/ttydiag in the configuration tool (or CDL).
 
Another thing that explains the behaviour you were getting before when the
output was done in the wrong order (but not mixed) is that when you drop
off the end of cyg_user_start(), the scheduler is then started. That's why
the polled output works, immediately, but the cyg_io_write() had to wait
until interrupts were enabled, which happens when the scheduler is started.

Jifl
-- 
Red Hat, Rustat House, Clifton Road, Cambridge, UK. Tel: +44 (1223) 271062
Maybe this world is another planet's Hell -Aldous Huxley || Opinions==mine

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