From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jonathan Larmour To: Wolfram Kattanek Cc: Gary Thomas , ecos-discuss@sourceware.cygnus.com Subject: Re: [ECOS] cyg_io_write & printf Date: Wed, 07 Feb 2001 08:42:00 -0000 Message-id: <3A817AD5.C9CD4E76@redhat.com> References: <981545501.3a81321da0c3e@imp.imms.de> <3A815DE6.8D4BF0E6@cambridge.redhat.com> <981558819.3a816623e4051@imp.imms.de> X-SW-Source: 2001-02/msg00107.html Wolfram Kattanek wrote: > > Gary Thomas : > > > > 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