This is a implementation of some system calls required by
newlib. It uses services provided by pico]OS pico & nano layers and
should be usable for any pico]OS port which uses gcc as compiler
and supports nano layer.

Documentation for newlib can be found at
http://sources.redhat.com/newlib. Ideas for this layer were
taken from unix-like operating systems (for the device io layer) and
from excellent examples provided by Bill Gatliff's article
about using newlib in embedded systems
(see http://billgatliff.com/drupal/node/25).

If you compile newlib yourself, following configure options are recommended:

configure    --prefix=your-crosscompiler-directory
             --target=your-platform (for example arm-elf)
             --disable-libssp
             --disable-newlib-supplied-syscalls
You can also add --enable-target-optspace if you want to
optimize space instead of speed. If you want to use
malloc wrapper which uses nano layer nosMemAlloc & co,
you'll have to add -DMALLOC_PROVIDED to compile flags
(I think Makefile must be edited after configure)
Also, alternative for --disable-newlib-supplied-syscalls
is to compile newlib with -DREENTRANT_SYSCALLS_PROVIDED.

I have been both compiling my own newlib with options
above (for FreeBSD) and using readily compiled version
from WinArm project.

Before using any newlib-supplied stuff program must initialize
the layer by calling nosNewlibIoInit:

  nosNewlibIoInit(NULL);

If you want add support for new devices (by default
there is only console default providing stdin/out/err),
you must write functions for device open, close, read and write
and provide them with NOSIOCLASS_t structure to newlib
layer. As an example I'll provide a led device, which
sets the led when "1" is written to it and clears it
when "0" is written. After writing necessary functions,
create an ioclass structure:

  const NOSIOCLASS_t ledClass = { "led",
                                  ledOpen,
                                  NULL,
                                  ledWrite,
                                  NULL };

nosNewlibIoInit accepts an array of these structures:


  NOSIOCLASS_t* devTab[] = { &ledClass,
                              NULL };

  nosNewlibIoInit(devTab);

After that, you can open the "led" device and write to it:

  FILE* led = fopen("/dev/led", "w");
  fprintf(led, "1\n");
  printf ("led set\n");
  posTaskSleep(2000);
  fprintf(led, "0\n");
  printf ("led cleared\n");
  fclose(led);


