Skip to content
Snippets Groups Projects
NuttxPortingGuide.html 141 KiB
Newer Older
patacongo's avatar
patacongo committed
<html>
<head>
<title>NuttX Porting Guide</title>
patacongo's avatar
patacongo committed
<meta name="author" content="Gregory Nutt">
</head>

patacongo's avatar
patacongo committed
<body background="backgd.gif">
patacongo's avatar
patacongo committed
<hr><hr>
<table width ="100%">
  <tr align="center" bgcolor="#e4e4e4">
    <td>
      <h1><big><font color="#3c34ec">
        <i>NuttX RTOS Porting Guide</i>
      </font></big></h1>
      <p>Last Updated: February 24, 2011</p>
    </td>
  </tr>
</table>
patacongo's avatar
patacongo committed
<hr><hr>

<table width ="100%">
  <tr bgcolor="#e4e4e4">
    <td>
  <h1>Table of Contents</h1>
    </td>
  </tr>
</table>

patacongo's avatar
patacongo committed
<ul>
  <a href="#Introduction">1.0 Introduction</a><br>
  <a href="#DirectoryStructure">2.0 Directory Structure</a>
    <a href="#DirStructDocumentation">2.1 Documentation</a></br>
    <a href="#DirStructArch">2.2 arch/</a>
patacongo's avatar
patacongo committed
    <ul>
      <a href="#archdirectorystructure">2.2.1 Subdirectory Structure</a><br>
      <a href="#summaryofarchfiles">2.2.2 Summary of Files</a><br>
      <a href="#supportedarchitectures">2.2.3 Supported Architectures</a>
patacongo's avatar
patacongo committed
    </ul>
    <a href="#DirStructBinFmt">2.2 binfmt/</a><br>
    <a href="#DirStructConfigs">2.4 configs/</a>
    <ul>
      <a href="#configsdirectorystructure">2.3.1 Subdirectory Structure</a><br>
      <a href="#summaryofconfigfiles">2.3.2 Summary of Files</a>
      <ul>
        <a href="#boardlogic">2.4.2.1 Board Specific Logic</a><br>
        <a href="#boardconfigsubdirs">2.3.2.2 Board Specific Configuration Sub-Directories</a>
      </ul>
      <a href="#supportedboards">2.4.3 Supported Boards</a>
    </ul>
    <a href="#DirStructDrivers">2.5 drivers/</a><br>
    <a href="#DirStructExamples">2.6 examples/</a><br>
    <a href="#DirStructFs">2.7 fs/</a><br>
    <a href="#DirStructGraphics">2.8 graphics/</a><br>
    <a href="#DirStructInclude">2.9 include/</a><br>
    <a href="#DirStructLib">2.10 lib/</a><br>
    <a href="#DirStructLibXX">2.11 libxx/</a><br>
    <a href="#DirStructMm">2.12 mm/</a><br>
    <a href="#DirStructNet">2.13 net</a><br>
    <a href="#DirStructNetUtils">2.14 netutils</a><br>
    <a href="#DirStructSched">2.15 sched/</a><br>
    <a href="#DirStructTools">2.16 tools/</a><br>
    <a href="#topmakefile">2.17 Makefile</a>
  <a href="#configandbuild">3.0 Configuring and Building</a>
patacongo's avatar
patacongo committed
  <ul>
    <a href="#configuringnuttx">3.1 Configuring NuttX</a><br>
    <a href="#buildingnuttx">3.2 Building NuttX</a>
patacongo's avatar
patacongo committed
  </ul>
  <a href="#ArchAPIs">4.0 Architecture APIs</a>
patacongo's avatar
patacongo committed
  <ul>
    <a href="#imports">4.1 APIs Exported by Architecture-Specific Logic to NuttX</a>
    <ul>
      <a href="#upinitialize">4.1.1 <code>up_initialize()</code></a><br>
      <a href="#upidle">4.1.2 <code>up_idle()</code></a><br>
      <a href="#upinitialstate">4.1.3 <code>up_initial_state()</code></a><br>
      <a href="#upcreatestack">4.1.4 <code>up_create_stack()</code></a><br>
      <a href="#upusestack">4.1.5 <code>up_use_stack()</code></a><br>
      <a href="#upreleasestack">4.1.6 <code>up_release_stack()</code></a><br>
      <a href="#upunblocktask">4.1.7 <code>up_unblock_task()</code></a><br>
      <a href="#upblocktask">4.1.8 <code>up_block_task()</code></a><br>
      <a href="#upreleasepending">4.1.9 <code>up_release_pending()</code></a><br>
      <a href="#upreprioritizertr">4.1.10 <code>up_reprioritize_rtr()</code></a><br>
      <a href="#_exit">4.1.11 <code>_exit()</code></a><br>
      <a href="#upassert">4.1.12 <code>up_assert()</code></a><br>
      <a href="#upschedulesigaction">4.1.13 <code>up_schedule_sigaction()</code></a><br>
      <a href="#upallocateheap">4.1.14 <code>up_allocate_heap()</code></a><br>
      <a href="#upinterruptcontext">4.1.15 <code>up_interrupt_context()</code></a><br>
      <a href="#updisableirq">4.1.16 <code>up_disable_irq()</code></a><br>
      <a href="#upenableirq">4.1.17 <code>up_enable_irq()</code></a><br>
      <a href="#upprioritizeirq">4.1.18 <code>up_prioritize_irq()</code></a></br>
      <a href="#upputc">4.1.19 <code>up_putc()</code></a>
    </ul>
    <a href="#exports">4.2 APIs Exported by NuttX to Architecture-Specific Logic</a>
    <ul>
      <a href="#osstart">4.2.1 <code>os_start()</code></a><br>
      <a href="#listmgmt">4.2.2 OS List Management APIs</a><br>
      <a href="#schedprocesstimer">4.2.3 <code>sched_process_timer()</code></a><br>
      <a href="#irqdispatch">4.2.4 <code>irq_dispatch()</code></a>
    </ul>
patacongo's avatar
patacongo committed
    <a href="#demandpaging">4.3 On-Demand Paging</a><br>
    <a href="#ledsupport">4.4 LED Support</a>
    <ul>
      <a href="#ledheaders">4.3.1 Header Files</a><br>
      <a href="#leddefinitions">4.3.2 LED Definitions</a><br>
      <a href="#ledapis">4.3.3 Common LED interfaces</a>
    </ul>
patacongo's avatar
patacongo committed
  </ul>
  <a href="#NxFileSystem">5.0 NuttX File System</a><br>
  <a href="#DeviceDrivers">6.0 NuttX Device Drivers</a><br>
  <ul>
    <a href="#chardrivers">6.1 Character Device Drivers</a><br>
    <a href="#blockdrivers">6.2 Block Device Drivers</a><br>
    <a href="#blockdrivers">6.3 Specialized Device Drivers</a>
    <ul>
       <a href="#ethdrivers">6.3.1 Ethernet Device Drivers</a><br>
       <a href="#spidrivers">6.3.2 SPI Device Drivers</a><br>
       <a href="#i2cdrivers">6.3.3 I2C Device Drivers</a><br>
patacongo's avatar
patacongo committed
       <a href="#serialdrivers">6.3.4 Serial Device Drivers</a><br>
       <a href="#fbdrivers">6.3.5 Frame Buffer Drivers</a><br>
patacongo's avatar
patacongo committed
       <a href="#lcddrivers">6.3.6 LCD Drivers</a><br>
       <a href="#mtddrivers">6.3.7 Memory Technology Device Drivers</a><br>
       <a href="#sdiodrivers">6.3.8 SDIO Device Drivers</a><br>
       <a href="#usbhostdrivers">6.3.9 USB Host-Side Drivers</a><br>
       <a href="#usbdevdrivers">6.3.10 USB Device-Side Drivers</a><br>
  <a href="#apndxconfigs">Appendix A: NuttX Configuration Settings</a><br>
  <a href="#apndxtrademarks">Appendix B:  Trademarks</a>
patacongo's avatar
patacongo committed
</ul>

<table width ="100%">
  <tr bgcolor="#e4e4e4">
    <td>
      <h1>1.0 <a name="Introduction">Introduction</a></h1>
    </td>
  </tr>
</table>
patacongo's avatar
patacongo committed

<p><b>Overview</b>
patacongo's avatar
patacongo committed
  This document provides and overview of the NuttX build and configuration
patacongo's avatar
patacongo committed
  logic and provides hints for the incorporation of new processor/board architectures
patacongo's avatar
patacongo committed
  into the build.
</p>
<p>
patacongo's avatar
patacongo committed
  See also <code>arch/README.txt</code> and <code>configs/README.txt</code>.
patacongo's avatar
patacongo committed
</p>

<table width ="100%">
  <tr bgcolor="#e4e4e4">
    <td>
      <h1>2.0 <a name="DirectoryStructure">Directory Structure</a></h1>
    </td>
  </tr>
</table>
patacongo's avatar
patacongo committed

patacongo's avatar
patacongo committed
<p>
  <b>Directory Structure</b>.
  The general directly layout for NuttX is very similar to the directory structure
  of the Linux kernel -- at least at the most superficial layers.
  At the top level is the main makefile and a series of sub-directories identified
  below and discussed in the following paragraphs:
</p>
patacongo's avatar
patacongo committed
<ul><pre>
.
patacongo's avatar
patacongo committed
|-- <a href="#topmakefile">Makefile</a>
patacongo's avatar
patacongo committed
|-- <a href="#DirStructDocumentation">Documentation</a>
patacongo's avatar
patacongo committed
|   `-- <i>(documentation files)</i>/
|-- <a href="#DirStructArch">arch</a>/
|   |-- <i>&lt;arch-name&gt;</i>/
|   |   |-- include/
|   |   |   |--<i>&lt;chip-name&gt;</i>/
|   |   |   |  `-- <i>(chip-specific header files)</i>
|   |   |   |--<i>&lt;other-chips&gt;</i>/
|   |   |   `-- <i>(architecture-specific header files)</i>
|   |   `-- src/
|   |       |--<i>&lt;chip-name&gt;</i>/
|   |       |  `-- <i>(chip-specific source files)</i>
|   |       |--<i>&lt;other-chips&gt;</i>/
|   |       `-- <i>(architecture-specific source files)</i>
patacongo's avatar
patacongo committed
|   `-- <i>&lt;other-architecture directories&gt;</i>/
|-- <a href="#DirStructBinFmt">binfmt</a>/
|   |-- Makefile
|   |-- <i>(binfmt-specific sub-directories)</i>/
|   |   `-- <i>(binfmt-specific source files)</i>
|   `-- <i>(common binfmt source files)</i>
patacongo's avatar
patacongo committed
|-- <a href="#DirStructConfigs">configs</a>/
|   |-- <i>&lt;board-name&gt;</i>/
|   |   |-- include/
|   |   |   `-- <i>(other board-specific header files)</i>
patacongo's avatar
patacongo committed
|   |   |-- src/
|   |   |   `-- <i>(board-specific source files)</i>
|   |   |---<i>&lt;config-name&gt;</i>/
|   |   |   `-- <i>(board configuration-specific source files)</i>
|   |   `---<i>(other configuration sub-directories for this board)</i>/
patacongo's avatar
patacongo committed
|   `-- <i>&lt;(other board directories)&gt;</i>/
patacongo's avatar
patacongo committed
|-- <a href="#DirStructDrivers">drivers</a>/
|   |-- Makefile
|   |-- <i>(driver-specific sub-directories)/</i>
|   |   `-- <i>(driver-specific source files)</i>
patacongo's avatar
patacongo committed
|   `-- <i>(common driver source files)</i>
|-- <a href="#DirStructExamples">examples</a>/
|   `-- <i>(example)</i>/
patacongo's avatar
patacongo committed
|       |-- Makefile
|       `-- <i>(example source files)</i>
patacongo's avatar
patacongo committed
|-- <a href="#DirStructFs">fs</a>/
patacongo's avatar
patacongo committed
|   |-- Makefile
|   |-- <i>(file system-specific sub-directories)</i>/
|   |   `-- <i>(file system-specific source files)</i>
patacongo's avatar
patacongo committed
|   `-- <i>(common file system source files)</i>
|-- <a href="#DirStructGraphics">graphics</a>/
|   |-- Makefile
|   |-- <i>(feature-specific sub-directories)</i>/
|   |   `-- <i>(feature-specific source files library source files)</i>
|   `-- <i>(common graphics-related source files)</i>
patacongo's avatar
patacongo committed
|-- <a href="#DirStructInclude">include</a>/
patacongo's avatar
patacongo committed
|   |-- <i>(standard header files)</i>
|   |-- <i>(standard include sub-directories)</i>
patacongo's avatar
patacongo committed
|   |   `-- <i>(more standard header files)</i>
|   |-- <i>(non-standard include sub-directories)</i>
|       `-- <i>(non-standard header files)</i>
patacongo's avatar
patacongo committed
|-- <a href="#DirStructLib">lib</a>/
patacongo's avatar
patacongo committed
|   |-- Makefile
|   `-- <i>(lib source files)</i>
|-- <a href="#DirStructLibXX">libxx</a>/
|   |-- Makefile
|   `-- <i>(libxx management source files)</i>
patacongo's avatar
patacongo committed
|-- <a href="#DirStructMm">mm</a>/
patacongo's avatar
patacongo committed
|   |-- Makefile
patacongo's avatar
patacongo committed
|   `-- <i>(memory management source files)</i>
|-- <a href="#DirStructNet">net</a>/
|   |-- Makefile
|   |-- uip/
|   |   `-- <i>(uip source files)</i>
|   `-- <i>(BSD socket source files)</i>
patacongo's avatar
patacongo committed
|-- <a href="#DirStructNetUtils">netutils</a>/
|   |-- Makefile
|   |-- <i>(network feature sub-directories)</i>/
|   |   `-- <i>(network feature source files)</i>
|   `-- <i>(netutils common files)</i>
patacongo's avatar
patacongo committed
|-- <a href="#DirStructSched">sched</a>/
patacongo's avatar
patacongo committed
|   |-- Makefile
|   `-- <i>(sched source files)</i>
`-- <a href="#DirStructTools">tools</a>/
    `-- <i>(miscellaneous scripts and programs)</i>
patacongo's avatar
patacongo committed
</pre></ul>

patacongo's avatar
patacongo committed
<p>
  <b>Configuration Files</b>.
  The NuttX configuration consists of:
</p>
<ul>
  <li>
    <i>Processor architecture specific files</i>.
    These are the files contained in the <code>arch/</code><i>&lt;arch-name&gt;</i><code>/</code> directory
    and are discussed in a paragraph <a href="#archdirectorystructure">below</a>.
  </li>
  <li>
    <i>Chip/SoC specific files</i>.
    Each processor processor architecture is embedded in chip or <i>System-on-a-Chip</i> (SoC) architecture.
    The full chip architecture includes the processor architecture plus chip-specific interrupt logic,
    clocking logic, general purpose I/O (GIO) logic, and specialized, internal peripherals (such as UARTs, USB, etc.).
    <p>
      These chip-specific files are contained within chip-specific sub-directories in the
      <code>arch/</code><i>&lt;arch-name&gt;</i><code>/</code> directory and are selected via
      the <code>CONFIG_ARCH_name</code> selection.
    </p>
  </li>
  <li>
patacongo's avatar
patacongo committed
    <i>Board specific configurations</i>.
patacongo's avatar
patacongo committed
    In order to be usable, the chip must be contained in a board environment.
    The board configuration defines additional properties of the board including such things as
    peripheral LEDs, external peripherals (such as network, USB, etc.).
    <p>
      These board-specific configuration files can be found in the
      <code>configs/</code><i>&lt;board-name&gt;</i><code>/</code> sub-directories and are discussed
patacongo's avatar
patacongo committed
      in a paragraph <a href="#configsdirectorystructure">below</a>.
patacongo's avatar
patacongo committed
    </p>
  </li>
</ul>

patacongo's avatar
patacongo committed
<h2>2.1 <a name="DirStructDocumentation">Documentation</a></h2>
patacongo's avatar
patacongo committed

<p>
  General documentation for the NuttX OS resides in this directory.
</p>

patacongo's avatar
patacongo committed
<h2>2.2 <a name="DirStructArch">arch</a></h2>
patacongo's avatar
patacongo committed

<h3><a name="archdirectorystructure">2.2.1 Subdirectory Structure</a></h3>
patacongo's avatar
patacongo committed
<p>
  This directory contains several sub-directories, each containing
  architecture-specific logic.
  The task of porting NuttX to a new processor consists of
patacongo's avatar
patacongo committed
  add a new subdirectory under <code>arch/</code> containing logic specific
  to the new architecture.
  The complete board port in is defined by the architecture-specific code in this
  directory (plus the board-specific configurations in the <code>config/</code>
  subdirectory).
patacongo's avatar
patacongo committed
  Each architecture must provide a subdirectory, <i>&lt;arch-name&gt;</i>
  under <code>arch/</code> with the following characteristics:
patacongo's avatar
patacongo committed
</p>
<ul><pre>
<i>&lt;arch-name&gt;</i>/
|-- include/
|   |--<i>&lt;chip-name&gt;</i>/
|   |  `-- <i>(chip-specific header files)</i>
|   |--<i>&lt;other-chips&gt;</i>/
|   |-- arch.h
|   |-- irq.h
|   |-- types.h
|   `-- limits.h
`-- src/
    |--<i>&lt;chip-name&gt;</i>/
    |  `-- <i>(chip-specific source files)</i>
    |--<i>&lt;other-chips&gt;</i>/
    |-- Makefile
    `-- <i>(architecture-specific source files)</i>
patacongo's avatar
patacongo committed
</pre></ul>

<h3><a name="summaryofarchfiles">2.2.2 Summary of Files</a></h3>
patacongo's avatar
patacongo committed
<ul>
patacongo's avatar
patacongo committed
  <li>
    <code>include/</code><i>&lt;chip-name&gt;</i><code>/</code>
    This sub-directory contains chip-specific header files.
  </li>
patacongo's avatar
patacongo committed
  <li>
    <code>include/arch.h</code>:
    This is a hook for any architecture specific definitions that may
    be needed by the system.  It is included by <code>include/nuttx/arch.h</code>.
  </li>
  <li>
    <code>include/types.h</code>:
    This provides architecture/toolchain-specific definitions for
    standard types.  This file should <code>typedef</code>:
    <ul><code>
      _int8_t, _uint8_t, _int16_t, _uint16_t, _int32_t, _uint32_t_t
patacongo's avatar
patacongo committed
    </code></ul>
    <p>and if the architecture supports 24- or 64-bit integers</p>
patacongo's avatar
patacongo committed
    <ul><code>
patacongo's avatar
patacongo committed
    </code></ul>
    <p>
      NOTE that these type names have a leading underscore character.  This
      file will be included(indirectly) by include/stdint.h and typedef'ed to
      the final name without the underscore character.  This roundabout way of
      doings things allows the stdint.h to be removed from the include/
      directory in the event that the user prefers to use the definitions
      provided by their toolchain header files
    </p>
    <p>
      And finally
patacongo's avatar
patacongo committed
    </p>
    <ul><code>
      irqstate_t
    </code></ul>
    <p>
      Must be defined to the be the size required to hold the interrupt
     enable/disable state.
    </p>
    <p>
      This file will be included by include/sys/types.h and be made
      available to all files.
    </p>
  </li>
  <li>
    <code>include/irq.h</code>:
    This file needs to define some architecture specific functions (usually
    inline if the compiler supports inlining) and structure.  These include:
    <ul>
      <li>
        <code>struct xcptcontext</code>:
        This structures represents the saved context of a thread.
      </li>
      <li>
        <code>irqstate_t irqsave(void)</code>:
        Used to disable all interrupts.
      </li>
      <li>
patacongo's avatar
patacongo committed
        <code>void irqrestore(irqstate_t flags)</code>:
patacongo's avatar
patacongo committed
        Used to restore interrupt enables to the same state as before <code>irqsave()</code> was called.
      </li>
    </ul>
    <p>
      This file must also define <code>NR_IRQS</code>, the total number of IRQs supported
       by the board.
    </p>
  </li>
patacongo's avatar
patacongo committed
  <li>
    <code>src/</code><i>&lt;chip-name&gt;</i><code>/</code>
    This sub-directory contains chip-specific source files.
  </li>
patacongo's avatar
patacongo committed
  <li>
    <code>src/Makefile</code>:
    This makefile will be executed to build the targets <code>src/libup.a</code> and
    <code>src/up_head.o</code>.  The <code>up_head.o</code> file holds the entry point into the system
    (power-on reset entry point, for example).  It will be used in
    the final link with <code>libup.a</code> and other system archives to generate the
    final executable.
  </li>
  <li>
    <i>(architecture-specific source files)</i>.
    The file <code>include/nuttx/arch.h</code> identifies all of the APIs that must
    be provided by the architecture specific logic.  (It also includes
patacongo's avatar
patacongo committed
    <code>arch/</code><i>&lt;arch-name&gt;</i><code>/arch.h</code> as described above).
patacongo's avatar
patacongo committed
</ul>

<h3><a name="supportedarchitectures">2.2.3 Supported Architectures</a></h3>
patacongo's avatar
patacongo committed
   <b>Architecture- and Chip-Specific Directories</b>.
   All processor architecture-specific directories are maintained in sub-directories of
   the <code>arch/</code> directory.
   Different chips or SoC's may implement the same processor core.
   Chip-specific logic can be found in sub-directories under the architecture
   directory.
   Current architecture/chip directories are summarized below:
</p>
patacongo's avatar
patacongo committed
<ul>
  <li><code>arch/sim</code>:
    A user-mode port of NuttX to the x86 Linux platform is available.
patacongo's avatar
patacongo committed
    The purpose of this port is primarily to support OS feature development.
patacongo's avatar
patacongo committed
    This port does not support interrupts or a real timer (and hence no
    round robin scheduler)  Otherwise, it is complete.
  </li>
patacongo's avatar
patacongo committed
  <p>NOTE: This target will not run on Cygwin probably for many reasons but
    first off because it uses some of the same symbols as does cygwind.dll.
  </p>
  <li><code>arch/arm</code>:
    This directory holds common ARM architectures.  At present, this includes
    the following subdirectories:
    <ul>
patacongo's avatar
patacongo committed
      <li><code>arch/arm/include</code> and <code>arch/arm/src/common</code>:
          Common ARM logic.
      </li>

      <li><code>arch/arm/include/c5471</code> and <code>arch/arm/src/c5471</code>:
        TI TMS320C5471 (also called TMS320DM180 or just C5471).
        NuttX operates on the ARM7 of this dual core processor.
        This port is complete, verified, and included in the NuttX release 0.1.1.
      </li>

      <li><code>arch/arm/include/dm320</code> and <code>arch/arm/src/dm320</code>:
        TI TMS320DM320 (also called just DM320).
        NuttX operates on the ARM9EJS of this dual core processor.
        This port complete, verified, and included in the NuttX release 0.2.1.
      </li>

      <li><code>arch/arm/include/lpc214x</code> and <code>arch/arm/src/lpc214x</code>:
        These directories provide support for NXP LPC214x family of
        processors.
        STATUS: This port boots and passes the OS test (examples/ostest).
        The port is complete and verified.  As of NuttX 0.3.17, the port includes:
        timer interrupts, serial console, USB driver, and SPI-based MMC/SD card
        support.  A verified NuttShell configuration is also available.
    </ul>
  </li>

  <li><code>configs/mcu123-lpc214x</code>:
    The mcu123.com lpc214x development board.
    This is a work in progress.
  </li>
patacongo's avatar
patacongo committed
    A work in progress.
  </li>
  <li><code>arch/8051</code>:
patacongo's avatar
patacongo committed
    8051 Microcontroller.  This port is not quite ready for prime time.
  </li>
patacongo's avatar
patacongo committed

patacongo's avatar
patacongo committed
  <li><code>arch/z16f</code>:
    Zilog z16f Microcontroller.
    This port uses the Zilog z16f2800100zcog Development Kit.
patacongo's avatar
patacongo committed
    This port was released with nuttx-0.3.7.
patacongo's avatar
patacongo committed
  </li>

    <li><code>arch/z80</code>:
patacongo's avatar
patacongo committed
    This directory holds 8-bit ZiLOG architectures.  At present, this includes the
    Zilog z80, ez80Acclaim! and z8Encore! Microcontrollers.
patacongo's avatar
patacongo committed
    <ul>
      <li><code>arch/z80/include</code> and <code>arch/z80/src/common</code>:
          Common logic.
      </li>

      <li><code>arch/z80/include/z80</code> and <code>arch/z80/src/z80</code>:
        The Z80 port was released in nuttx-0.3.6 has been verified using only a
        z80 instruction simulator.
        The set simulator  can be found in the NuttX SVN at
        http://nuttx.svn.sourceforge.net/viewvc/nuttx/trunk/misc/sims/z80sim.
        This port also uses the SDCC toolchain (http://sdcc.sourceforge.net/")
patacongo's avatar
patacongo committed
        (verified with version 2.6.0 and 2.7.0).
      </li>

      <li><code>arch/z80/include/ez80</code> and <code>arch/z80/src/ez80</code>:
        The ez80Acclaim! port uses the ZiLOG ez80f0910200kitg development kit, eZ80F091 part,
        with the Zilog ZDS-II Windows command line tools.
        The development environment is Cygwin under WinXP.
        This is a work in progress.  Verified ez80 support will be announced in a future NuttX release.
      </li>

patacongo's avatar
patacongo committed
      <li><code>arch/z80/include/z8</code> and <code>arch/z80/src/z8</code>:
        The Z8Encore! port uses either the ZiLOG z8encore000zco development kit, Z8F6403 part,
        or the z8f64200100kit development kit, Z8F6423 part with the Zilog ZDS-II Windows command line
patacongo's avatar
patacongo committed
        tools.  The development environment is Cygwin under WinXP.
        The initial release, verified only on the ZDS-II ez8 simulator, was released in nuttx-0.3.9.
patacongo's avatar
patacongo committed
      </li>
    </ul>
    </li>
</ul>

<p>
  <b>Deprecated Architecture Directories</b>.
  The following architecture directories are deprecated.  They have been
  replaced by the logic in <code>arm/arm</code> and will deleted when
  <code>arch/arm</code> is fully verified.
</p>
<ul>
  <li><code>arch/c5471</code>:
    Replaced with <code>arch/arm/include/c5471</code> and
patacongo's avatar
patacongo committed
    <code>arch/arm/src/c5471</code>.
  </li>

  <li><code>arch/dm320</code>:
    Replaced with <code>arch/arm/include/dm320</code> and
patacongo's avatar
patacongo committed
    <code>arch/arm/src/dm320</code>.
  </li>
patacongo's avatar
patacongo committed
</ul>
<p>
  Other ports for the for the TI TMS320DM270 and for MIPS are in various states
  of progress
</p>

<h2>2.3 <a name="DirStructBinFmt">binfmt</a></h2>

<p>
  The <code>binfmt/</code> subdirectory contains logic for loading binaries in the file
  system into memory in a form that can be used to execute them.
</p>

<h2>2.4 <a name="DirStructConfigs">configs</a></h2>
<p>
  The <code>configs/</code> subdirectory contains configuration data for each board.
  These board-specific configurations plus the architecture-specific configurations in
  the <code>arch/</code> subdirectory complete define a customized port of NuttX.
</p>

<h3><a name="configsdirectorystructure">2.3.1 Subdirectory Structure</a></h3>
<p>
  The configs directory contains board specific configuration files.  Each board must
  provide a subdirectory &lt;board-name&gt; under <code>configs/</code> with the following characteristics:
</p>
<ul><pre>
<i>&lt;board-name&gt;</i>
|-- include/
|   |-- board.h
|   `-- <i>(board-specific header files)</i>
|-- src/
|   |-- Makefile
|   `-- <i>(board-specific source files)</i>
|-- <i>&lt;config1-dir&gt;</i>
|   |-- Make.defs
|   |-- defconfig
|   `-- setenv.sh
|-- <i>&lt;config2-dir&gt;</i>
|   |-- Make.defs
|   |-- defconfig
|   `-- setenv.sh
|   ...
`-- <i>(other board-specific configuration sub-directories)</i>/
patacongo's avatar
patacongo committed
<h3><a name="summaryofconfigfiles">2.3.2 Summary of Files</a></h3>
<h4><a name="boardlogic">2.3.2.1 Board Specific Logic</a></h4>
  <li>
    <code>include/</code>:
    This directory contains board specific header files.
    This directory will be linked as <code>include/arch/board</code> at configuration time
    and can be included via <code>#include &lt;arch/board/header.h&gt;</code>.
patacongo's avatar
patacongo committed
    These header file can only be included by files in <code>arch/</code><i>&lt;arch-name&gt;</i><code>/include/</code>
    and <code>arch/</code><i>&lt;arch-name&gt;</i><code>/src/</code>.
  <li>
    <code>src/</code>:
    This directory contains board specific drivers.
patacongo's avatar
patacongo committed
    This directory will be linked as <config>arch/</code><i>&lt;arch-name&gt;</i><code>/src/board</code> at configuration
    time and will be integrated into the build system.
  </li>
  <li>
    <code>src/Makefile</code>:
    This makefile will be invoked to build the board specific drivers.
    It must support the following targets:  <code>libext$(LIBEXT)</code>, <code>clean</code>, and <code>distclean</code>.
  </li>
patacongo's avatar
patacongo committed
</ul>
patacongo's avatar
patacongo committed
<h4><a name="boardconfigsubdirs">2.3.2.2 Board Specific Configuration Sub-Directories</a></h4>
patacongo's avatar
patacongo committed
<p>
  The <code>configs/</code><i>&lt;board-name&gt;</i><code>/</code> sub-directory holds all of the
patacongo's avatar
patacongo committed
  files that are necessary to configure NuttX for the particular board.
patacongo's avatar
patacongo committed
  A board may have various different configurations using the common source files.
  Each board configuration is described by three files:  <code>Make.defs</code>, <code>defconfig</code>, and <code>setenv.sh</code>.
  Typically, each set of configuration files is retained in a separate configuration sub-directory
  (<i>&lt;config1-dir&gt;</i>, <i>&lt;config2-dir&gt;</i>, .. in the above diagram).

patacongo's avatar
patacongo committed
  The procedure for configuring NuttX is described <a href="#configuringnuttx">below</a>,
  This paragraph will describe the contents of these configuration files.
</p>
<ul>
  <li>
    <code>Make.defs</code>: This makefile fragment provides architecture and
    tool-specific build options.  It will be included by all other
    makefiles in the build (once it is installed).  This make fragment
    should define:
    <ul>
      <li>Tools: CC, LD, AR, NM, OBJCOPY, OBJDUMP</li>
      <li>Tool options: CFLAGS, LDFLAGS</li>
      <li>COMPILE, ASSEMBLE, ARCHIVE, CLEAN, and MKDEP macros</li>
    </ul>
    <p>
      When this makefile fragment runs, it will be passed TOPDIR which
      is the path to the root directory of the build.  This makefile
      fragment may include ${TOPDIR}/.config to perform configuration
      specific settings.  For example, the CFLAGS will most likely be
      different if CONFIG_DEBUG=y.
  </li>
  <li>
    <code>defconfig</code>: This is a configuration file similar to the Linux
patacongo's avatar
patacongo committed
    configuration file.  In contains variable/value pairs like:
    <ul>
      <li><code>CONFIG_VARIABLE</code>=value</li>
    </ul>
    <p>
      This configuration file will be used at build time:
    </p>
    <ol>
      <li>As a makefile fragment included in other makefiles, and</li>
      <li>to generate <code>include/nuttx/config.h</code> which is included by
          most C files in the system.</li>
    </ol>
  </li>
  <li>
    <code>setenv.sh</code>: This is a script that you can include that will be installed at
patacongo's avatar
patacongo committed
    the top level of the directory structure and can be sourced to set any
patacongo's avatar
patacongo committed
<h3><a name="supportedboards">2.3.3 Supported Boards</a></h3>
<p>
  All of the specific boards supported by NuttX are identified below.
  These are the specific <i>&lt;board-name&gt;</i>'s that may be used to configure NuttX
patacongo's avatar
patacongo committed
  as described <a href="#configuringnuttx">below</a>.
</p>
<ul>
  <li><code>configs/c5471evm</code>:
    This is a port to the Spectrum Digital C5471 evaluation board.  The
    C5471 is a dual core processor from TI with an ARM7TDMI general purpose
    processor and a c54 SDP.  NuttX runs on the ARM core and is built with
patacongo's avatar
patacongo committed
    with a GNU arm-elf toolchain* under Linux or Cygwin.
    This port is complete, verified, and included in the NuttX release.
  <li><code>configs/ez80f0910200kitg</code>
    ez80Acclaim! Microcontroller.  This port use the Zilog ez80f0910200kitg
    development kit, eZ80F091 part, and the Zilog ZDS-II Windows command line
    tools.  The development environment is Cygwin under WinXP.
  </li>

  <li><code>configs/m68322evb</code>:
    This is a work in progress for the venerable m68322evb board from
    Motorola.
  </li>

  <li><code>configs/mcu123-lpc214x</code>:
    This port is for the NXP LPC2148 as provided on the mcu123.com
    lpc214x development board.
patacongo's avatar
patacongo committed
    This OS is also built with the arm-elf toolchain* under Linux or Cygwin.
    The port supports serial, timer0, spi, and usb.
  <li><code>configs/ntosd-dm320</code>:
patacongo's avatar
patacongo committed
    This port uses the Neuros OSD with a GNU arm-elf toolchain* under Linux or Cygwin.
    See <a href="http://wiki.neurostechnology.com/index.php/Developer_Welcome">Neuros Wiki</a>
patacongo's avatar
patacongo committed
    for further information.
    NuttX operates on the ARM9EJS of this dual core processor.
    STATUS: This port is code complete, verified, and included in the
  <li><code>configs/olimex-strp711</code>:
    This port uses the Olimex STR-P711 board arm-elf toolchain* under Linux or Cygwin.
    See the <a href="http://www.olimex.com/dev/str-p711.html">Olimex</a> web site
patacongo's avatar
patacongo committed
    for further information.
    STATUS: Coding for the basic port -- serial console and system timer -- is complete
    but untested to problems I am having using OpenOCD with a wiggler clone JTAG.

  <li><code>configs/pjrc-8051</code>:
    8051 Microcontroller.  This port uses the PJRC 87C52 development system
patacongo's avatar
patacongo committed
    and the <a href="http://sdcc.sourceforge.net/">SDCC</a> toolchain under Linux or Cygwin.
patacongo's avatar
patacongo committed
    This port is not quite ready for prime time.
  </li>

  <li><code>configs/sim</code>:
    A user-mode port of NuttX to the x86 Linux platform is available.
patacongo's avatar
patacongo committed
    The purpose of this port is primarily to support OS feature development.
    This port does not support interrupts or a real timer (and hence no
    round robin scheduler)  Otherwise, it is complete.
  </li>

  <li><code>configs/us7032evb1</code>:
    This is a port of the Hitachi SH-1 on the Hitachi SH-1/US7032EVB1 board.
    STATUS:  This port is available as of release 0.3.18 of NuttX.  The port is basically
    complete and many examples run correctly.  However, there are remaining instabilities
    that make the port un-usable.  The nature of these is not understood; the behavior is
    that certain SH-1 instructions stop working as advertised.  This could be a silicon
    problem, some pipeline issue that is not handled properly by the gcc 3.4.5 toolchain
    (which has very limited SH-1 support to begin with), or perhaps with the CMON debugger.
    At any rate, I have exhausted all of the energy that I am willing to put into this cool
    old processor for the time being.
  </li>

  <li><code>configs/xtrs</code>:
    TRS80 Model 3.  This port uses a vintage computer based on the Z80.
    An emulator for this computer is available to run TRS80 programs on a 
patacongo's avatar
patacongo committed
    Linux platform (http://www.tim-mann.org/xtrs.html).
patacongo's avatar
patacongo committed
  <li><code>configs/z16f2800100zcog</code>
    z16f Microcontroller.
patacongo's avatar
patacongo committed
    This port use the Zilog z16f2800100zcog development kit and the
    Zilog ZDS-II Windows command line tools.
    The development environment is Cygwin under WinXP.
patacongo's avatar
patacongo committed
  </li>

  <li><code>configs/z80sim</code>:
    z80 Microcontroller.  This port uses a Z80 instruction set simulator.
    That simulator can be found in the NuttX SVN
    <a href="http://nuttx.svn.sourceforge.net/viewvc/nuttx/trunk/misc/sims/z80sim">here</a>.
    This port also the <a href="http://sdcc.sourceforge.net/">SDCC</a> toolchain
patacongo's avatar
patacongo committed
    under Linux or Cygwin(verified with version 2.6.0).
patacongo's avatar
patacongo committed
  <li><code>configs/z8encore000zco</code>
    z8Encore! Microcontroller.  This port use the Zilog z8encore000zco
patacongo's avatar
patacongo committed
    development kit, Z8F6403 part, and the Zilog ZDS-II Windows command line
patacongo's avatar
patacongo committed
    tools.  The development environment is Cygwin under WinXP.
  </li>
  <li><code>configs/z8encore000zco</code>
    z8Encore! Microcontroller.  This port use the Zilog z8f64200100kit
    development kit, Z8F6423 part, and the Zilog ZDS-II Windows command line
    tools.  The development environment is Cygwin under WinXP.
  </li>
</ul>

<p><small><blockquote>
  * A customized version of the <a href="http://www.buildroot.org">buildroot</a>
patacongo's avatar
patacongo committed
  is available to build these toolchains under Linux or Cygwin.
<h2>2.5 <a name="DirStructDrivers">drivers</a></h2>
patacongo's avatar
patacongo committed

<p>
  This directory holds architecture-independent device drivers.
</p>
<ul><pre>
drivers/
|-- Makefile
|-- bch/
|   |-- Make.defs
|   `-- <i>(bch driver source files)</i>
|-- mmcsd/
|   |-- Make.defs
|   `-- <i>(mmcsd driver source files)</i>
|-- net/
|   |-- Make.defs
|   `-- <i>(net driver source files)</i>
|-- usbdev/
|   |-- Make.defs
patacongo's avatar
patacongo committed
|   `-- <i>(USB device driver source files)</i>
|-- usbhost/
|   |-- Make.defs
|   `-- <i>(USB host driver source files)</i>
`-- <i>(common driver source files)</i>
</pre></ul>
patacongo's avatar
patacongo committed

<h2>2.6 <a name="DirStructExamples">examples</a></h2>
patacongo's avatar
patacongo committed

<p>
  Example and test programs to build against.
</p>

<h2>2.7 <a name="DirStructFs">fs</a></h2>
patacongo's avatar
patacongo committed

<p>
patacongo's avatar
patacongo committed
  This directory contains the NuttX file system.
  This file system is described <a href="#NxFileSystem">below</a>.
patacongo's avatar
patacongo committed
</p>
<ul><pre>
fs/
|-- Makefile
|-- fat/
|   |-- Make.defs
|   `-- <i>(fat file system source files)</i>
|-- romfs/
|   |-- Make.defs
|   `-- <i>(romfs file system source files)</i>
 `-- <i>(common file system source files)</i>
</pre></ul>

<h2>2.8 <a name="DirStructGraphics">graphics</a></h2>

<p>
  This directory contains files for graphics/video support under NuttX.
</p>
<ul><pre>
graphics/
|-- Makefile
|-- nxglib/
|   |-- Make.defs
|   `-- <i>(NuttX graphics library source files)</i>
|-- nx/
|   |-- Make.defs
patacongo's avatar
patacongo committed
|   `-- <i>(NuttX X-server source files)</i>
`-- <i>(common file system source files)</i>
</pre></ul>
patacongo's avatar
patacongo committed

<h2>2.9 <a name="DirStructInclude">include</a></h2>
patacongo's avatar
patacongo committed
<p>
  This directory holds NuttX header files.
  Standard header files file retained in can be included in the <i>normal</i> fashion:
</p>
<ul>
  <code>include &lt;stdio.h&gt;</code><br>
patacongo's avatar
patacongo committed
  <code>include &lt;sys/types.h&gt;</code><br>
  etc.
</ul>
<p>
  Directory structure:
</p>
<ul><pre>
include/
|-- <i>(standard header files)</i>
|-- arpa/
|   `-- <i>(standard header files)</i>
|-- net/
|   `-- uip/
|       `-- <i>(uIP specific header files)</i>
|-- netinet/
|   `-- <i>(standard header files)</i>
|-- nuttx/
|   `-- <i>(nuttx specific header files)</i>
`- sys/
    `-- <i>(more standard header files)</i>
</per></ul>

<h2>2.10 <a name="DirStructLib">lib</a></h2>
patacongo's avatar
patacongo committed
<p>
  This directory holds a collection of standard libc-like functions with custom
patacongo's avatar
patacongo committed
  interfaces into NuttX.
patacongo's avatar
patacongo committed
</p>

<h2>2.11 <a name="DirStructLibXX">libxx</a></h2>
<p>
  This directory holds a tiny, minimal standard std C++ that can be used to
  build some, simple C++ applications in NuttX.
</p>

<h2>2.12 <a name="DirStructMm">mm</a></h2>
patacongo's avatar
patacongo committed
<p>
  This is the NuttX memory manager.
</p>

<h2>2.13 <a name="DirStructNet">net</a></h2>
patacongo's avatar
patacongo committed
<p>
  This directory contains the implementation of the socket APIs.
patacongo's avatar
patacongo committed
  The subdirectory, <code>uip</code> contains the uIP port.
patacongo's avatar
patacongo committed
</P>

<h2>2.14 <a name="DirStructNetUtils">netutils</a></h2>
patacongo's avatar
patacongo committed
<p>
  This directory contains most of the network applications.
patacongo's avatar
patacongo committed
  Some of these are original with NuttX (like tftpc and dhcpd) and others were leveraged from the uIP-1.0 apps directory.
  As the uIP apps/README says, these applications &quot;are not all heavily tested.&quot;
patacongo's avatar
patacongo committed
</p>
<ul><pre>
netutils/
|-- Makefile
|-- dhcp/
|   |-- Make.defs
|   `-- <i>(dhcp source files)</i>
|-- dhcpd/
|   |-- Make.defs
|   `-- <i>(dhcpd source files)</i>
|-- resolv/
|   |-- Make.defs
|   `-- <i>(resolv source files)</i>
|-- smtp/
|   |-- Make.defs
|   `-- <i>(smtp source files)</i>
|-- telnetd/
|   |-- Make.defs
|   `-- <i>(telnetd source files)</i>
|-- tftpc/
|   |-- Make.defs
|   `-- <i>(tftpc source files)</i>
|-- uiplib/
|   |-- Make.defs
|   `-- <i>(uiplib source files)</i>
|-- weblclient/
|   |-- Make.defs
|   `-- <i>(webclient source files)</i>
|-- webserver/
|   |-- Make.defs
|   `-- <i>(webserver source files)</i>
`-- <i>(netutils common files)</i>
</pre></ul>
patacongo's avatar
patacongo committed

<h2>2.15 <a name="DirStructSched">sched</a></h2>
patacongo's avatar
patacongo committed
<p>
  The files forming core of the NuttX RTOS reside here.
</p>

<h2>2.16 <a name="DirStructTools">tools</a></h2>
patacongo's avatar
patacongo committed
<p>
  This directory holds a collection of tools and scripts to simplify
  configuring, building and maintaining NuttX.
patacongo's avatar
patacongo committed
</p>
<ul><pre>
tools/
|-- Makefile.mkconfig
|-- configure.sh
|-- incdir.sh
|-- indent.sh
|-- link.sh
|-- mkconfig.c
|-- mkdeps.sh
|-- mkimage.sh
|-- mknulldeps.sh
|-- unlink.sh
|-- winlink.sh
`-- zipme
</pre></ul>
patacongo's avatar
patacongo committed

<h2>2.17 <a name="topmakefile">Makefile</a></h2>
patacongo's avatar
patacongo committed
<p>
  The top-level <code>Makefile</code> in the <code>${TOPDIR}</code> directory contains all of the top-level control
  logic to build NuttX.
  Use of this <code>Makefile</code> to build NuttX is described <a href="#buildingnuttx">below</a>.
</p>

<table width ="100%">
  <tr bgcolor="#e4e4e4">
    <td>
      <h1>3.0 <a name="configandbuild">Configuring and Building</a></h1>
    </td>
  </tr>
</table>

patacongo's avatar
patacongo committed
<h2><a name="configuringnuttx">3.1 Configuring NuttX</a></h2>
<p>
  <b>Manual Configuration</b>.
  Configuring NuttX requires only copying the
patacongo's avatar
patacongo committed
  <a href="#boardconfigsubdirs">board-specific configuration files</a> into the top level directory which appears in the make files as the make variable, <code>${TOPDIR}</code>.
patacongo's avatar
patacongo committed
  This could be done manually as follows:
</p>
<ul>
patacongo's avatar
patacongo committed
  <li>Copy <code>configs/</code><i>&lt;board-name&gt;</i><code>/[</code><i>&lt;config-dir&gt;</i><code>/]Make.def</code> to <code>${TOPDIR}/Make.defs</code>,<li>
  <li>Copy <code>configs/</code><i>&lt;board-name&gt;</i><code>/[</code><i>&lt;config-dir&gt;</i><code>/]setenv.sh</code> to <code>${TOPDIR}/setenv.sh</code>, and</li>
  <li>Copy <code>configs/</code><i>&lt;board-name&gt;</i><code>/[</code><i>&lt;config-dir&gt;</i><code>/]defconfig</code> to <code>${TOPDIR}/.config</code></li>
patacongo's avatar
patacongo committed
</ul>
<p>
  Where <i>&lt;board-name&gt;</i> is the name of one of the sub-directories of the
  NuttX <a href="#DirStructConfigs"><code>configs/</code></a> directory.
  This sub-directory name corresponds to one of the supported boards
  identified <a href="#supportedboards">above</a>.
patacongo's avatar
patacongo committed
  And &lt;config-dir&gt; is the optional, specific configuration directory for the board.
patacongo's avatar
patacongo committed
</p>
<p>
  <b>Automated Configuration</b>.
  There is a script that automates these steps.  The following steps will
  accomplish the same configuration:
</p>
<ul><pre>
  cd tools
patacongo's avatar
patacongo committed
  ./configure.sh <i>&lt;board-name&gt;</i></i><code>[/</code><i>&lt;config-dir&gt;</i><code>]</code>
patacongo's avatar
patacongo committed
</pre></ul>

<p>
  <b>Additional Configuration Steps</b>.
  The remainder of configuration steps will be performed by <a href="#topmakefile"><code>${TOPDIR}/Makefile</code></a>
  the first time the system is built as described below.
</p>

<h2><a name="buildingnuttx">3.2 Building NuttX</a></h2>
<p>
  <b>Building NuttX</b>.
   Once NuttX has been configured as described <a href="#configuringnuttx">above</a>, it may be built as follows:
</p>
<ul><pre>
cd ${TOPDIR}
source ./setenv.sh
make
</pre></ul>
<p>
  The <code>${TOPDIR}</code> directory holds:
</p>
<ul>
  <li>The top level <a href="#topmakefile"><code>Makefile</code></a> that controls the NuttX build.
</ul>
<p>
  That directory also holds:
</p>
<ul>
patacongo's avatar
patacongo committed
  <li>The makefile fragment <a href="#boardconfigsubdirs"><code>.config</code></a> that describes the current configuration.</li>
patacongo's avatar
patacongo committed
  <li>The makefile fragment <a href="#boardconfigsubdirs"><code>Make.defs</code></a> that provides customized build targets, and</li>
patacongo's avatar
patacongo committed
  <li>The shell script <a href="#boardconfigsubdirs"><code>setenv.sh</code></a> that sets up the configuration environment for the build.</li>
patacongo's avatar
patacongo committed
</ul>
<p>
patacongo's avatar
patacongo committed
The <a href="#boardconfigsubdirs"><code>setenv.sh</code></a> contains Linux/Cygwin environmental settings that are needed for the build.
The specific environmental definitions are unique for each board but should include, as a minimum, updates to the <code>PATH</code> variable to include the full path to the architecture-specific toolchain identified in <a href="#boardconfigsubdirs"><code>Make.defs</code></a>.
The <a href="#boardconfigsubdirs"><code>setenv.sh</code></a> only needs to be source'ed at the beginning of a session.
patacongo's avatar
patacongo committed
The system can be re-made subsequently by just typing <code>make</code>.
</p>
<p>
  <b>First Time Make.</b>
  Additional configuration actions will be taken the first time that system is built.
  These additional steps include:
</p>
<ul>
  <li>Auto-generating the file <code>include/nuttx/config.</code> using the <code>${TOPDIR}/.config</code> file.
  <li>Creating a link to <code>${TOPDIR}/arch/</code><i>&lt;arch-name&gt;</i><code>/include</code> at <code>${TOPDIR}/include/arch</code>.
  <li>Creating a link to <code>${TOPDIR}/configs/</code><i>&lt;board-name&gt;</i><code>/include</code> at <code>${TOPDIR}/include/arch/board</code>.
  <li>Creating a link to <code>${TOPDIR}/configs/</code><i>&lt;board-name&gt;</i><code>/src</code> at <code>${TOPDIR}/arch/</code><i>&lt;arch-name&gt;</i><code>/src/board</code>
  <li>Creating make dependencies.
</ul>
patacongo's avatar
patacongo committed

<table width ="100%">
  <tr bgcolor="#e4e4e4">
    <td>
      <h1>4.0 <a name="ArchAPIs">Architecture APIs</a></h1>
    </td>
  </tr>
</table>
patacongo's avatar
patacongo committed

<p>
  The file <code>include/nuttx/arch.h</code> identifies by prototype all of the APIs that must
  be provided by the architecture specific logic.
  The internal OS APIs that architecture-specific logic must
  interface with also also identified in <code>include/nuttx/arch.h</code> or in
  other header files.
</p>

<h2><a name="imports">4.1 APIs Exported by Architecture-Specific Logic to NuttX</a></h2>
<h3><a name="upinitialize">4.1.1 <code>up_initialize()</code></a></h3>

<p><b>Prototype</b>: <code>void up_initialize(void);</code></p>

<p><b>Description</b>.
  <code>up_initialize()</code> will be called once during OS
  initialization after the basic OS services have been
  initialized.  The architecture specific details of
  initializing the OS will be handled here.  Such things as
  setting up interrupt service routines, starting the
patacongo's avatar
patacongo committed
  clock, and registering <a href="#DeviceDrivers">device drivers</a> are some of the
patacongo's avatar
patacongo committed
  things that are different for each processor and hardware
  platform.
</p>
<p>
  <code>up_initialize()</code> is called after the OS initialized but
  before the init process has been started and before the
  libraries have been initialized.  OS services and driver
  services are available.
</p>

<h3><a name="upidle">4.1.2 <code>up_idle()</code></a></h3>
<p><b>Prototype</b>: <code>void up_idle(void);</code></p>

<p><b>Description</b>.
  <code>up_idle()</code> is the logic that will be executed
  when their is no other ready-to-run task.  This is processor
  idle time and will continue until some interrupt occurs to
  cause a context switch from the idle task.
</p>
<p>
  Processing in this state may be processor-specific. e.g.,
  this is where power management operations might be performed.
</p>

<h3><a name="upinitialstate">4.1.3 <code>up_initial_state()</code></a></h3>
<p><b>Prototype</b>: <code>void up_initial_state(FAR _TCB *tcb);</code></p>

<p><b>Description</b>.
  A new thread is being started and a new TCB
  has been created. This function is called to initialize
  the processor specific portions of the new TCB.
</p>
<p>
patacongo's avatar
patacongo committed
  This function must setup the initial architecture registers
patacongo's avatar
patacongo committed
  and/or  stack so that execution will begin at tcb->start
  on the next context switch.
</p>

<h3><a name="upcreatestack">4.1.4 <code>up_create_stack()</code></a></h3>
<p><b>Prototype</b>: <code>STATUS up_create_stack(FAR _TCB *tcb, size_t stack_size);</code></p>

<p><b>Description</b>.
  Allocate a stack for a new thread and setup
  up stack-related information in the TCB.
</p>
<p>
  The following TCB fields must be initialized:
</p>
<ul>
  <li><code>adj_stack_size</code>: Stack size after adjustment for hardware,
    processor, etc.  This value is retained only for debug
    purposes.</li>
  <li><code>stack_alloc_ptr</code>: Pointer to allocated stack</li>
  <li><code>adj_stack_ptr</code>: Adjusted <code>stack_alloc_ptr</code> for HW.  The
    initial value of the stack pointer.
</ul>
<p>
  This API is <i>NOT</i> required if <code>CONFIG_CUSTOM_STACK</code>
  is defined.
</p>

patacongo's avatar
patacongo committed
<p><b>Inputs</b>:</p>
patacongo's avatar
patacongo committed
<ul>
  <li>
    <code>tcb</code>: The TCB of new task.
  </li>
  <li>
    <code>stack_size</code>:  The requested stack size.  At least this much
    must be allocated.
  </li>
</ul>

<h3><a name="upusestack">4.1.5 <code>up_use_stack()</code></a></h3>
<p><b>Prototype</b>: 
  <code>STATUS up_use_stack(FAR _TCB *tcb, FAR void *stack, size_t stack_size);</code>
</p>

<p><b>Description</b>.
  Setup up stack-related information in the TCB
  using pre-allocated stack memory.
</p>
<p>
  The following TCB fields must be initialized:
</p>
<ul>
  <li><code>adj_stack_size</code>: Stack size after adjustment for hardware,
    processor, etc.  This value is retained only for debug
    purposes.</li>
  <li><code>stack_alloc_ptr</code>: Pointer to allocated stack</li>
  <li><code>adj_stack_ptr</code>: Adjusted <code>stack_alloc_ptr</code> for HW.  The
    initial value of the stack pointer.
</ul>
<p>
  This API is <i>NOT</i> required if <code>CONFIG_CUSTOM_STACK</code>
  is defined.
</p>

<p><b>Inputs:</b></p>
<ul>
  <li>
    <code>tcb</code>: The TCB of new task.
  </li>
  <li>
    <code>stack_size</code>:  The allocated stack size.
  </li>
</ul>

<h3><a name="upreleasestack">4.1.6 <code>up_release_stack()</code></a></h3>
<p><b>Prototype</b>: <code>void up_release_stack(FAR _TCB *dtcb);</code></p>

<p><b>Description</b>.
  A task has been stopped. Free all stack
  related resources retained int the defunct TCB.
</p>
<p>
  This API is <i>NOT</i> required if <code>CONFIG_CUSTOM_STACK</code>
  is defined.
</p>

<h3><a name="upunblocktask">4.1.7 <code>up_unblock_task()</code></a></h3>
<p><b>Prototype</b>: <code>void up_unblock_task(FAR _TCB *tcb);</code></p>

<p><b>Description</b>.
  A task is currently in an inactive task list
  but has been prepped to execute.  Move the TCB to the
  ready-to-run list, restore its context, and start execution.
</p>
<p>
  This function is called only from the NuttX scheduling
  logic.  Interrupts will always be disabled when this
  function is called.
</p>

<p><b>Inputs</b>:
<ul>
  <li><code>tcb</code>: Refers to the tcb to be unblocked.  This tcb is
    in one of the waiting tasks lists.  It must be moved to
    the ready-to-run list and, if it is the highest priority
patacongo's avatar
patacongo committed
    ready to run tasks, executed.
patacongo's avatar
patacongo committed
  </li>
</ul>

<h3><a name="upblocktask">4.1.8 <code>up_block_task()</code></a></h3>
<p><b>Prototype</b>: <code>void up_block_task(FAR _TCB *tcb, tstate_t task_state);</code></p>

<p><b>Description</b>.
  The currently executing task at the head of
  the ready to run list must be stopped.  Save its context
  and move it to the inactive list specified by task_state.

  This function is called only from the NuttX scheduling
  logic.  Interrupts will always be disabled when this
  function is called.

<p><b>Inputs:</b></p>
<ul>
  <li><code>tcb</code>: Refers to a task in the ready-to-run list (normally
    the task at the head of the list).  It most be
patacongo's avatar
patacongo committed
    stopped, its context saved and moved into one of the
    waiting task lists.  It it was the task at the head
    of the ready-to-run list, then a context to the new
    ready to run task must be performed.
  </li>
  <li><code>task_state</code>: Specifies which waiting task list should be
    hold the blocked task TCB.
  </li>
</ul>

<h3><a name="upreleasepending">4.1.9 <code>up_release_pending()</code></a></h3>
<p><b>Prototype</b>: <code>void up_release_pending(void);</code></p>

<p><b>Description</b>.
  When tasks become ready-to-run but cannot run because pre-emption
  is disabled, they are placed into a pending task list.
  This function releases and makes ready-to-run all of the tasks that have
  collected in the pending task list.  This can cause a
  context switch if a new task is placed at the head of
  the ready to run list.
</p>
<p>
  This function is called only from the NuttX scheduling logic when
  pre-emption is re-enabled.  Interrupts will always be disabled when this
  function is called.
</p>

<h3><a name="upreprioritizertr">4.1.10 <code>up_reprioritize_rtr()</code></a></h3>
<p><b>Prototype</b>: <code>void up_reprioritize_rtr(FAR _TCB *tcb, uint8_t priority);</code></p>
patacongo's avatar
patacongo committed

<p><b>Description</b>.
  Called when the priority of a running or
  ready-to-run task changes and the reprioritization will 
  cause a context switch.  Two cases:
</p>
<ol>
  <li>
    The priority of the currently running task drops and the next
    task in the ready to run list has priority.
  </li>
  <li>
    An idle, ready to run task's priority has been raised above the
    the priority of the current, running task and it now has the
    priority.
  </li>
</ol>
<p>
  This function is called only from the NuttX scheduling
  logic.  Interrupts will always be disabled when this
  function is called.
</p>

<p><b>Inputs:</b></p>
<ul>
  <li>
    <code>tcb</code>: The TCB of the task that has been reprioritized
  </li>
  <li>
    <code>priority</code>: The new task priority
  </li>
</ul>

<h3><a name="_exit">4.1.11 <code>_exit()</code></a></h3>
<p><b>Prototype</b>: <code>void _exit(int status) noreturn_function;</code></p>

<p><b>Description</b>.
  This function causes the currently executing task to cease
  to exist.  This is a special case of task_delete().
</p>
<p>
  Unlike other UP APIs, this function may be called
  directly from user programs in various states.  The
patacongo's avatar
patacongo committed
  implementation of this function should disable interrupts
patacongo's avatar
patacongo committed
  before performing scheduling operations.
</p>

<h3><a name="upassert">4.1.12 <code>up_assert()</code></a></h3>
<p><b>Prototype</b>:<br>
  <code>void up_assert(FAR const uint8_t *filename, int linenum);</code></br>
  <code>void up_assert_code(FAR const uint8_t *filename, int linenum, int error_code);</code></br>
patacongo's avatar
patacongo committed
</p>

<p><b>Description</b>.
  Assertions may be handled in an architecture-specific
  way.
</p>

<h3><a name="upschedulesigaction">4.1.13 <code>up_schedule_sigaction()</code></a></h3>
<p><b>Prototype</b>:
  <code>void up_schedule_sigaction(FAR _TCB *tcb, sig_deliver_t sigdeliver);</code>
</p>

<p><b>Description</b>.
  This function is called by the OS when one or more
  signal handling actions have been queued for execution.
  The architecture specific code must configure things so
patacongo's avatar
patacongo committed
  that the 'sigdeliver' callback is executed on the thread
patacongo's avatar
patacongo committed
  specified by 'tcb' as soon as possible.
</p>
<p>
  This function may be called from interrupt handling logic.
</p>
<p>
  This operation should not cause the task to be unblocked
  nor should it cause any immediate execution of sigdeliver.
  Typically, a few cases need to be considered:
</p>
<ol>
  <li>
    This function may be called from an interrupt handler
    During interrupt processing, all xcptcontext structures
    should be valid for all tasks.  That structure should
    be modified to invoke sigdeliver() either on return
    from (this) interrupt or on some subsequent context
    switch to the recipient task.
  </li>
  <li>
    If not in an interrupt handler and the tcb is NOT
    the currently executing task, then again just modify
    the saved xcptcontext structure for the recipient
    task so it will invoke sigdeliver when that task is
    later resumed.
  </li>
  <li>
    If not in an interrupt handler and the tcb IS the
    currently executing task -- just call the signal
    handler now.
  </li>
</ol>
<p>
  This API is <i>NOT</i> required if <code>CONFIG_DISABLE_SIGNALS</code>
  is defined.
</p>

<h3><a name="upallocateheap">4.1.14 <code>up_allocate_heap()</code></a></h3>
<p><b>Prototype</b>: <code>void up_allocate_heap(FAR void **heap_start, size_t *heap_size);</code></p>

<p><b>Description</b>.
  The heap may be statically allocated by
  defining CONFIG_HEAP_BASE and CONFIG_HEAP_SIZE.  If these
  are not defined, then this function will be called to
  dynamically set aside the heap region.
</p>
<p>
  This API is <i>NOT</i> required if <code>CONFIG_HEAP_BASE</code>
  is defined.
</p>

<h3><a name="upinterruptcontext">4.1.15 <code>up_interrupt_context()</code></a></h3>
<p><b>Prototype</b>: <code>bool up_interrupt_context(void)</code></p>
patacongo's avatar
patacongo committed

<p><b>Description</b>.
  Return true if we are currently executing in the interrupt handler context.
patacongo's avatar
patacongo committed
</p>

<h3><a name="updisableirq">4.1.16 <code>up_disable_irq()</code></a></h3>
<p><b>Prototype</b>:</p>
<ul><pre>
#ifndef CONFIG_ARCH_NOINTC
  void up_disable_irq(int irq);
patacongo's avatar
patacongo committed
#endif
</pre></ul>
patacongo's avatar
patacongo committed

<p><b>Description</b>.
  Disable the IRQ specified by 'irq'
  On many architectures, there are three levels of interrupt enabling: (1)
  at the global level, (2) at the level of the interrupt controller,
  and (3) at the device level.  In order to receive interrupts, they
  must be enabled at all three levels.
</p>
<p>
  This function implements enabling of the device specified by 'irq'
  at the interrupt controller level if supported by the architecture
  (irqsave() supports the global level, the device level is hardware
  specific).
<p>
  If the architecture does not support <code>up_disable_irq</code>,
  <code>CONFIG_ARCH_NOINTC</code> should be defined in the NuttX configuration file.
  Since this API cannot be supported on all architectures, it should be
  avoided in common implementations where possible.
patacongo's avatar
patacongo committed
</p>

<h3><a name="upenableirq">4.1.17 <code>up_enable_irq()</code></a></h3>
<p><b>Prototype</b>:</p>
<ul><pre>
#ifndef CONFIG_ARCH_NOINTC
  void up_enable_irq(int irq);
patacongo's avatar
patacongo committed
#endif
</pre></ul>

<p><b>Description</b>.
  This function implements disabling of the device specified by 'irq'
  at the interrupt controller level if supported by the architecture
  (irqrestore() supports the global level, the device level is hardware
  specific).
</p>
<p>
  If the architecture does not support <code>up_disable_irq</code>,
  <code>CONFIG_ARCH_NOINTC</code> should be defined in the NuttX configuration file.
  Since this API cannot be supported on all architectures, it should be
  avoided in common implementations where possible.
</p>
patacongo's avatar
patacongo committed

<h3><a name="upprioritizeirq">4.1.18 <code>up_prioritize_irq()</code></a></h3>
<p><b>Prototype</b>:</p>
<ul><pre>
#ifdef CONFIG_ARCH_IRQPRIO
  void up_enable_irq(int irq);
patacongo's avatar
patacongo committed
#endif
</pre></ul>
patacongo's avatar
patacongo committed
<p><b>Description</b>.
  Set the priority of an IRQ.
</p>
<p>
  If the architecture supports <code>up_enable_irq</code>,
  <code>CONFIG_ARCH_IRQPRIO</code> should be defined in the NuttX configuration file.
  Since this API cannot be supported on all architectures, it should be
  avoided in common implementations where possible.
patacongo's avatar
patacongo committed
</p>

<h3><a name="upputc">4.1.19 <code>up_putc()</code></a></h3>
patacongo's avatar
patacongo committed

<p><b>Prototype</b>: <code>int up_putc(int ch);</code></p>
<p><b>Description</b>.
  This is a debug interface exported by the architecture-specific logic.
  Output one character on the console
</p>

<h2><a name="exports">4.2 APIs Exported by NuttX to Architecture-Specific Logic</a></h2>
<p>
  These are standard interfaces that are exported by the OS
  for use by the architecture specific logic.
</p>

<h3><a name="osstart">4.2.1 <code>os_start()</code></a></h3>
<p>
  <b><i>To be provided</i></b>
</p>

<h3><a name="listmgmt">4.2.2 OS List Management APIs</a></h3></h3>
<p>
  <b><i>To be provided</i></b>
</p>

<h3><a name="schedprocesstimer">4.2.3 <code>sched_process_timer()</code></a></h3>
<p><b>Prototype</b>: <code>void sched_process_timer(void);</code></p>

<p><b>Description</b>.
  This function handles system timer events.
  The timer interrupt logic itself is implemented in the
  architecture specific code, but must call the following OS
  function periodically -- the calling interval must be
  <code>MSEC_PER_TICK</code>.
</p>

<h3><a name="irqdispatch">4.2.4 <code>irq_dispatch()</code></a></h3>
<p><b>Prototype</b>: <code>void irq_dispatch(int irq, FAR void *context);</code></p>

<p><b>Description</b>.
patacongo's avatar
patacongo committed
  This function must be called from the architecture-
  specific logic in order to display an interrupt to
patacongo's avatar
patacongo committed
  the appropriate, registered handling logic.
</p>

patacongo's avatar
patacongo committed
<h2><a name="demandpaging">4.3 On-Demand Paging</a></h2>

<p>
  The NuttX On-Demand Paging feature permits embedded MCUs with some limited RAM space to execute large programs from some non-random access media.
  If the platform meets certiain requirements, then NuttX can provide on-demand paging:
  It can copy .text from the large program in non-volatile media into RAM as needed to execute a huge program from the small RAM.
  Design and porting issues for this feature are discussed in a sepate document.
  Please see the <a href="NuttXDemandPaging.html">NuttX Demand Paging</a> design document for further information.
</p>

<h2><a name="ledsupport">4.4 LED Support</a></h2>

<p>
  A board architecture may or may not have LEDs.
  If the board does have LEDs, then most architectures provide similar LED support that is enabled when <code>CONFIG_ARCH_LEDS</code>
  is selected in the NuttX configuration file.
  This LED support is part of architecture-specific logic and is not managed by the core NuttX logic.
  However, the support provided by each architecture is sufficiently similar that it can be documented here.
</p>

<h3><a name="ledheaders">4.3.1 Header Files</a></h3>

<p>
  LED-related definitions are provided in two header files:
  <ul>
    <li>
       LED definitions are provided for each board in the <code>board.h</code> that resides
       in the <code><i>&lt;board-name&gt;</i>/include/board.h</code> file (which is also
       linked to <code>include/arch/board/board.h</code> when the RTOS is configured).
       Those definitions are discussed <a href="#leddefinitions">below</a>.
    </li>
    <li>
       The board-specific logic provides unique instances of the LED interfaces.
       This is because the implementation of LED support may be very different
       on different boards.
       Prototypes for these board-specific implementations are, however, provided
       in architecture-common header files.
       That header file is usually at <code><i>&lt;arch-name&gt;</i>/src/common/up_internal.h</code>,
       but could be at other locations in particular architectures.
       These prototypes are discussed <a href="#ledapis">below</a>.
    </li>
  </ul>
</p>

<h3><a name="leddefinitions">4.3.2 LED Definitions</a></h3>

<p>
   The implementation of LED support is very specific to a board architecture. 
   Some boards have several LEDS, others have only one or two. 
   Some have none. 
patacongo's avatar
patacongo committed
   Others LED matrices and show alphanumeric data, etc.
   The NuttX logic does not refer to specific LEDS, rather, it refers to an event to be shown on the LEDS
   in whatever manner is appropriate for the board;
   the way that this event is presented depends upon the hardware available on the board.
</p>
<p>
   The model used by NuttX is that the board can show 8 events defined as follows in <code><i>&lt;board-name&gt;</i>/include/board.h</code>:
</p>
<ul><pre>
#define LED_STARTED       ??
#define LED_HEAPALLOCATE  ??
#define LED_IRQSENABLED   ??
#define LED_STACKCREATED  ??
#define LED_INIRQ         ??
#define LED_SIGNAL        ??
#define LED_ASSERTION     ??
#define LED_PANIC         ??
</pre></ul>
<p>
  The specific value assigned to each pre-processor variable can be whatever makes the implementation easiest for the board logic.
  The <i>meaning</i> associated with each definition is as follows:
</p>
<ul>
  <li>
    <code>LED_STARTED</code> is the value that describes the setting of the LEDs when the LED logic is first initialized.
    This LED value is set but never cleared.
  </li>
  <li>
    <code>LED_HEAPALLOCATE</code> indicates that the NuttX heap has been configured.
    This is an important place in the boot sequence because if the memory is configured wrong, it will probably crash leaving this LED setting.
    This LED value is set but never cleared.
  </li>
  <li>
    <code>LED_IRQSENABLED</code> indicates that interrupts have been enabled.
    Again, during bring-up (or if there are hardware problems), it is very likely that the system may crash just when interrupts are enabled, leaving this setting on the LEDs.
    This LED value is set but never cleared.
  </li>
  <li>
    <code>LED_STACKCREATED</code> is set each time a new stack is created.
    If set, it means that the system attempted to start at least one new thread.
    This LED value is set but never cleared.
  </li>
  <li>
    <code>LED_INIRQ</code> is set and cleared on entry and exit from each interrupt.
    If interrupts are working okay, this LED will have a dull glow.
  </li>
  <li>
    <code>LED_SIGNAL</code> is set and cleared on entry and exit from a signal handler.
    Signal handlers are tricky so this is especially useful during bring-up or a new architecture.
  </li>
  <li>
    <code>LED_ASSERTION</code> is set if an assertion occurs.
  </li>
  <li>
    <code>LED_PANIC</code> will blink at around 1Hz if the system panics and hangs.
  </li>
</ul>

<h3><a name="ledapis">4.3.3 Common LED interfaces</a></h3>

<p>
  The <code><i>&lt;arch-name&gt;</i>/src/common/up_internal.h</code> probably has definitions
  like:
</p>
<ul><pre>
/* Defined in board/up_leds.c */

#ifdef CONFIG_ARCH_LEDS
extern void up_ledinit(void);
extern void up_ledon(int led);
extern void up_ledoff(int led);
#else
# define up_ledinit()
# define up_ledon(led)
# define up_ledoff(led)
#endif
</pre></ul>
<p>
   Where:
<p>
<ul>
  <li>
    <code>void up_ledinit(void)</code> is called early in power-up initialization to initialize the LED hardware.
  </li>
  <li>
    <code>up_ledon(int led)</code> is called to instantiate the LED presentation of the event.
    The <code>led</code> argument is one of the definitions provided in <code><i>&lt;board-name&gt;</i>/include/board.h</code>.
  </li>
  <li>
    <code>up_ledoff(int led</code>is called to terminate the LED presentation of the event.
    The <code>led</code> argument is one of the definitions provided in <code><i>&lt;board-name&gt;</i>/include/board.h</code>.
    Note that only <code>LED_INIRQ</code>, <code>LED_SIGNAL</code>, <code>LED_ASSERTION</code>, and <code>LED_PANIC</code>
    indications are terminated.
  </li>
</ul>

<table width ="100%">
  <tr bgcolor="#e4e4e4">
    <td>
      <h1><a name="NxFileSystem">5.0 NuttX File System</a></h1>
    </td>
  </tr>
</table>
patacongo's avatar
patacongo committed

<p><b>Overview</b>.
  NuttX includes an optional, scalable file system.
patacongo's avatar
patacongo committed
  This file-system may be omitted altogether; NuttX does not depend on the presence
patacongo's avatar
patacongo committed
  of any file system.
</p>

<p><b>Pseudo Root File System</b>.
patacongo's avatar
patacongo committed
  Or, a simple <i>in-memory</i>, <i>pseudo</i> file system can be enabled.
patacongo's avatar
patacongo committed
  This simple file system can be enabled setting the CONFIG_NFILE_DESCRIPTORS
  option to a non-zero value (see <a href="#apndxconfigs">Appendix A</a>).
  This is an <i>in-memory</i> file system because it does not require any
  storage medium or block driver support.
  Rather, file system contents are generated on-the-fly as referenced via
  standard file system operations (open, close, read, write, etc.).
patacongo's avatar
patacongo committed
  In this sense, the file system is <i>pseudo</i> file system (in the
patacongo's avatar
patacongo committed
  same sense that the Linux <code>/proc</code> file system is also
patacongo's avatar
patacongo committed
  referred to as a pseudo file system).
patacongo's avatar
patacongo committed
</p>

<p>
patacongo's avatar
patacongo committed
  Any user supplied data or logic can be accessed via the pseudo-file system.
patacongo's avatar
patacongo committed
  Built in support is provided for character and block <a href="#DeviceDrivers">drivers</a> in the
patacongo's avatar
patacongo committed
  <code>/dev</code> pseudo file system directory.
patacongo's avatar
patacongo committed
</p>

<p><b>Mounted File Systems</b>
  The simple in-memory file system can be extended my mounting block
  devices that provide access to true file systems backed up via some
  mass storage device.
  NuttX supports the standard <code>mount()</code> command that allows
patacongo's avatar
patacongo committed
  a block driver to be bound to a mountpoint within the pseudo file system
patacongo's avatar
patacongo committed
  and to a file system.
patacongo's avatar
patacongo committed
  At present, NuttX supports only the VFAT file system.
</p>

<p><b>Comparison to Linux</b>
  From a programming perspective, the NuttX file system appears very similar
  to a Linux file system.
  However, there is a fundamental difference:
patacongo's avatar
patacongo committed
  The NuttX root file system is a pseudo file system and true file systems may be
  mounted in the pseudo file system.
patacongo's avatar
patacongo committed
  In the typical Linux installation by comparison, the Linux root file system
patacongo's avatar
patacongo committed
  is a true file system and pseudo file systems may be mounted in the true,
patacongo's avatar
patacongo committed
  root file system.
  The approach selected by NuttX is intended to support greater scalability
  from the very tiny platform to the moderate platform.
</p>

<table width ="100%">
  <tr bgcolor="#e4e4e4">
    <td>
      <h1><a name="DeviceDrivers">6.0 NuttX Device Drivers</a></h1>
    </td>
  </tr>
</table>

<p>
  NuttX supports a variety of device drivers including:
  <ul>
    <li><i>Character</i> Device Drivers,</li>
    <li><i>Block</i> Device Drivers, and</li>
    <li>Other <i>Specialized</i> Drivers.</li>
  </ul>
patacongo's avatar
patacongo committed
  These different device driver types are discussed in the following paragraphs.
patacongo's avatar
patacongo committed
  Note: device driver support requires that the <i>in-memory</i>, <i>pseudo</i> file system
patacongo's avatar
patacongo committed
  is enabled by setting the CONFIG_NFILE_DESCRIPTORS in the NuttX configuration file to a 
  non-zero value.
</p>

<h2><a name="chardrivers">6.1 Character Device Drivers</a></h2>

<p>
  Character device drivers have these properties:
</p>
<ul>
  <li>
patacongo's avatar
patacongo committed
    <p>
    <b><code>include/nuttx/fs.h</code></b>.
    All structures and APIs needed to work with character drivers are provided in this header file.
patacongo's avatar
patacongo committed
    </p>
patacongo's avatar
patacongo committed
    <p>
    <b><code>struct file_operations</code></b>.
    Each character device driver must implement an instance of <code>struct file_operations</code>.
    That structure defines a call table with the following methods:
    <ul>
patacongo's avatar
patacongo committed
     <p><code>int open(FAR struct file *filp);</code><br>
     <code>int close(FAR struct file *filp);</code><br>
     <code>ssize_t read(FAR struct file *filp, FAR char *buffer, size_t buflen);</code><br>
     <code>ssize_t write(FAR struct file *filp, FAR const char *buffer, size_t buflen);</code><br>
     <code>off_t seek(FAR struct file *filp, off_t offset, int whence);</code><br>
     <code>int ioctl(FAR struct file *filp, int cmd, unsigned long arg);</code><br>
     <code>int poll(FAR struct file *filp, struct pollfd *fds, bool setup);</code></p>
patacongo's avatar
patacongo committed
    </p>
patacongo's avatar
patacongo committed
    <p>
    <b><code>int register_driver(const char *path, const struct file_operations *fops, mode_t mode, void *priv);</code></b>.
    Each character driver registers itself by calling <code>register_driver()</code>, passing it the
    <code>path</code> where it will appear in the <a href="#NxFileSystem">pseudo-file-system</a> and it's
    initialized instance of <code>struct file_operations</code>.
patacongo's avatar
patacongo committed
    </p>
patacongo's avatar
patacongo committed
    <p>
    <b>User Access</b>.
patacongo's avatar
patacongo committed
    After it has been registered, the character driver can be accessed by user code using the standard
    <a href="NuttxUserGuide.html#driveroperations">driver operations</a> including
    <code>open()</code>, <code>close()</code>, <code>read()</code>, <code>write()</code>, etc.
patacongo's avatar
patacongo committed
    </p>
patacongo's avatar
patacongo committed
    <p>
patacongo's avatar
patacongo committed
    <b>Examples</b>:
    <code>drivers/dev_null.c</code>, <code>drivers/fifo.c</code>, <code>drivers/serial.c</code>, etc.
patacongo's avatar
patacongo committed
    </p>
 </li>
</ul>

<h2><a name="blockdrivers">6.2 Block Device Drivers</a></h2>

<p>
  Block device drivers have these properties:
</p>
<ul>
  <li>
patacongo's avatar
patacongo committed
    <p>
    <b><code>include/nuttx/fs.h</code></b>.
    All structures and APIs needed to work with block drivers are provided in this header file.
patacongo's avatar
patacongo committed
    </p>
patacongo's avatar
patacongo committed
    <p>
    <b><code>struct block_operations</code></b>.
    Each block device driver must implement an instance of <code>struct block_operations</code>.
    That structure defines a call table with the following methods:
    <ul>
patacongo's avatar
patacongo committed
     <p><code>int open(FAR struct inode *inode);</code><br>
     <code>int close(FAR struct inode *inode);</code><br>
     <code>ssize_t read(FAR struct inode *inode, FAR unsigned char *buffer, size_t start_sector, unsigned int nsectors);</code><br>
     <code>ssize_t write(FAR struct inode *inode, FAR const unsigned char *buffer, size_t start_sector, unsigned int nsectors);</code><br>
     <code>int geometry(FAR struct inode *inode, FAR struct geometry *geometry);</code><br>
     <code>int ioctl(FAR struct inode *inode, int cmd, unsigned long arg);</code></p>
patacongo's avatar
patacongo committed
    </p>
patacongo's avatar
patacongo committed
    <p>
    <b><code>int register_blockdriver(const char *path, const struct block_operations *bops, mode_t mode, void *priv);</code></b>.
    Each block driver registers itself by calling <code>register_blockdriver()</code>, passing it the
    <code>path</code> where it will appear in the <a href="#NxFileSystem">pseudo-file-system</a> and it's
    initialized instance of <code>struct block_operations</code>.
patacongo's avatar
patacongo committed
    </p>
patacongo's avatar
patacongo committed
    <p>
    <b>User Access</b>.
    Users do not normally access block drivers directly, rather, they access block drivers
    indirectly through the <code>mount()</code> API.
    The <code>mount()</code> API binds a block driver instance with a file system and with a mountpoint.
    Then the user may use the block driver to access the file system on the underlying media.
patacongo's avatar
patacongo committed
    <i>Example</i>: See the <code>cmd_mount()</code> implementation in <code>examples/nsh/nsh_fscmds.c</code>.
patacongo's avatar
patacongo committed
    </p>
patacongo's avatar
patacongo committed
    <p>
    <b>Accessing a Character Driver as a Block Device</b>.
    See the loop device at <code>drivers/loop.c</code>.
patacongo's avatar
patacongo committed
    <i>Example</i>: See the <code>cmd_losetup()</code> implementation in <code>examples/nsh/nsh_fscmds.c</code>.
patacongo's avatar
patacongo committed
    </p>
patacongo's avatar
patacongo committed
    <p>
    <b>Accessing a Block Driver as Character Device</b>.
    See the Block-to-Character (BCH) conversion logic in <code>drivers/bch/</code>.
patacongo's avatar
patacongo committed
    <i>Example</i>: See the <code>cmd_dd()</code> implementation in <code>examples/nsh/nsh_ddcmd.c</code>.
patacongo's avatar
patacongo committed
    </p>
patacongo's avatar
patacongo committed
    <p>
    <b>Examples</b>.
patacongo's avatar
patacongo committed
    <code>drivers/loop.c</code>, <code>drivers/mmcsd/mmcsd_spi.c</code>, <code>drivers/ramdisk.c</code>, etc.
patacongo's avatar
patacongo committed
    </p>
  </li>
</ul>

<h2><a name="blockdrivers">6.3 Specialized Device Drivers</a></h2>

<h3><a name="ethdrivers">6.3.1 Ethernet Device Drivers</a></h3>

<ul>
  <li>
patacongo's avatar
patacongo committed
    <p>
    <b><code>include/net/uip/uip-arch.h</code></b>.
    All structures and APIs needed to work with Ethernet drivers are provided in this header file.
    The structure <code>struct uip_driver_s</code> defines the interface and is passed to uIP via
    <code>netdev_register()</code>.
patacongo's avatar
patacongo committed
    </p>
patacongo's avatar
patacongo committed
    <p>
    <b><code>int netdev_register(FAR struct uip_driver_s *dev);</code></b>.
patacongo's avatar
patacongo committed
    Each Ethernet driver registers itself by calling <code>netdev_register()</code>.
patacongo's avatar
patacongo committed
    </p>
patacongo's avatar
patacongo committed
    <p>
patacongo's avatar
patacongo committed
    <b>Examples</b>:
    <code>drivers/net/dm90x0.c</code>, <code>arch/drivers/arm/src/c5471/c5471_ethernet.c</code>, <code>arch/z80/src/ez80/ez80_emac.c</code>, etc.
patacongo's avatar
patacongo committed
    </p>
  </li>
</ul>

<h3><a name="spidrivers">6.3.2 SPI Device Drivers</a></h3>

<ul>
  <li>
patacongo's avatar
patacongo committed
    <p>
    <b><code>include/nuttx/spi.h</code></b>.
    All structures and APIs needed to work with SPI drivers are provided in this header file.
patacongo's avatar
patacongo committed
    </p>
patacongo's avatar
patacongo committed
    <p>
    <b><code>struct spi_ops_s</code></b>.
    Each SPI device driver must implement an instance of <code>struct spi_ops_s</code>.
    That structure defines a call table with the following methods:
    <ul>
     <p><code>void lock(FAR struct spi_dev_s *dev);</code></p>
     <p><code>void select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected);</code><br>
     <code>uint32_t setfrequency(FAR struct spi_dev_s *dev, uint32_t frequency);</code><br>
patacongo's avatar
patacongo committed
     <code>void setmode(FAR struct spi_dev_s *dev, enum spi_mode_e mode);</code><br>
     <code>void setbits(FAR struct spi_dev_s *dev, int nbits);</code><br>
     <code>uint8_t status(FAR struct spi_dev_s *dev, enum spi_dev_e devid);</code><br>
     <code>uint16_t send(FAR struct spi_dev_s *dev, uint16_t wd);</code><br>
patacongo's avatar
patacongo committed
     <code>void exchange(FAR struct spi_dev_s *dev, FAR const void *txbuffer, FAR void *rxbuffer, size_t nwords);</code><br>
patacongo's avatar
patacongo committed
     <p><code>int registercallback(FAR struct spi_dev_s *dev, mediachange_t callback, void *arg);</code></p>
    </ul>
patacongo's avatar
patacongo committed
    </p>
  <li>
    <p>
      <b>Binding SPI Drivers</b>.
      SPI drivers are not normally directly accessed by user code, but are usually bound to another,
      higher level device driver.
      See for example, <code>int mmcsd_spislotinitialize(int minor, int slotno, FAR struct spi_dev_s *spi)</code> in <code>drivers/mmcsd/mmcsd_spi.c</code>.
      In general, the binding sequence is:
    </p>
    <p>
      <ol>
        <li>Get an instance of <code>struct spi_dev_s</code> from the hardware-specific SPI device driver, and </li>
        <li>Provide that instance to the initialization method of the higher level device driver.</li>
      </ol>
    </p>
patacongo's avatar
patacongo committed
    <p>
      <b>Examples</b>:
      <code>drivers/loop.c</code>, <code>drivers/mmcsd/mmcsd_spi.c</code>, <code>drivers/ramdisk.c</code>, etc.
    </p>
  </li>
</ul>

<h3><a name="i2cdrivers">6.3.3 I2C Device Drivers</a></h3>

<ul>
  <li>
patacongo's avatar
patacongo committed
    <p>
    <b><code>include/nuttx/i2c.h</code></b>.
    All structures and APIs needed to work with I2C drivers are provided in this header file.
patacongo's avatar
patacongo committed
    </p>
patacongo's avatar
patacongo committed
    <p>
    <b><code>struct i2c_ops_s</code></b>.
    Each I2C device driver must implement an instance of <code>struct i2c_ops_s</code>.
    That structure defines a call table with the following methods:
    <ul>
     <p><code>uint32_t setfrequency(FAR struct i2c_dev_s *dev, uint32_t frequency);</code><br>
patacongo's avatar
patacongo committed
     <code>int setaddress(FAR struct i2c_dev_s *dev, int addr, int nbits);</code><br>
     <code>int write(FAR struct i2c_dev_s *dev, const uint8_t *buffer, int buflen);</code><br>
     <code>int read(FAR struct i2c_dev_s *dev, uint8_t *buffer, int buflen);</code></p>
patacongo's avatar
patacongo committed
    </p>
patacongo's avatar
patacongo committed
    <p>
      <b>Binding I2C Drivers</b>.
      I2C drivers are not normally directly accessed by user code, but are usually bound to another,
      higher level device driver.
      In general, the binding sequence is:
    </p>
    <p>
      <ol>
        <li>Get an instance of <code>struct i2c_dev_s</code> from the hardware-specific I2C device driver, and </li>
        <li>Provide that instance to the initialization method of the higher level device driver.</li>
      </ol>
    </p>
patacongo's avatar
patacongo committed
    <p>
      <b>Examples</b>:
      <code>arch/z80/src/ez80/ez80_i2c.c</code>, <code>arch/z80/src/z8/z8_i2c.c</code>, etc.
    </p>
  </li>
</ul>

<h3><a name="serialdrivers">6.3.4 Serial Device Drivers</a></h3>

<ul>
  <li>
patacongo's avatar
patacongo committed
    <p>
    <b><code>include/nuttx/serial.h</code></b>.
    All structures and APIs needed to work with serial drivers are provided in this header file.
patacongo's avatar
patacongo committed
    </p>
patacongo's avatar
patacongo committed
    <p>
    <b><code>struct uart_ops_s</code></b>.
    Each serial device driver must implement an instance of <code>struct uart_ops_s</code>.
    That structure defines a call table with the following methods:
    <ul>
patacongo's avatar
patacongo committed
     <p><code>int setup(FAR struct uart_dev_s *dev);</code><br>
     <code>void shutdown(FAR struct uart_dev_s *dev);</code><br>
     <code>int attach(FAR struct uart_dev_s *dev);</code><br>
     <code>void detach(FAR struct uart_dev_s *dev);</code><br>
     <code>int ioctl(FAR struct file *filep, int cmd, unsigned long arg);</code><br>
     <code>int receive(FAR struct uart_dev_s *dev, unsigned int *status);</code><br>
     <code>void rxint(FAR struct uart_dev_s *dev, bool enable);</code><br>
     <code>bool rxavailable(FAR struct uart_dev_s *dev);</code><br>
patacongo's avatar
patacongo committed
     <code>void send(FAR struct uart_dev_s *dev, int ch);</code><br>
     <code>void txint(FAR struct uart_dev_s *dev, bool enable);</code><br>
     <code>bool txready(FAR struct uart_dev_s *dev);</code><br>
     <code>bool txempty(FAR struct uart_dev_s *dev);</code></p>
patacongo's avatar
patacongo committed
    </p>
patacongo's avatar
patacongo committed
    <p>
    <b><code>int uart_register(FAR const char *path, FAR uart_dev_t *dev);</code></b>.
    A serial driver may register itself by calling <code>uart_register()</code>, passing it the
    <code>path</code> where it will appear in the <a href="#NxFileSystem">pseudo-file-system</a> and it's
    initialized instance of <code>struct uart_ops_s</code>.
patacongo's avatar
patacongo committed
    By convention, serial device drivers are registered at paths like <code>/dev/ttyS0</code>, <code>/dev/ttyS1</code>, etc.
    See the <code>uart_register()</code> implementation in <code>drivers/serial.c</code>.
patacongo's avatar
patacongo committed
    </p>
patacongo's avatar
patacongo committed
    <p>
    <b>User Access</b>.
    Serial drivers are, ultimately, normal <a href="#chardrivers">character drivers</a> and are accessed as other character drivers.
patacongo's avatar
patacongo committed
    </p>
patacongo's avatar
patacongo committed
    <p>
patacongo's avatar
patacongo committed
    <b>Examples</b>:
    <code>arch/arm/src/chip/lm3s_serial.c</code>, <code>arch/arm/src/lpc214x/lpc214x_serial.c</code>, <code>arch/z16/src/z16f/z16f_serial.c</code>, etc.
patacongo's avatar
patacongo committed
    </p>
patacongo's avatar
patacongo committed
<h3><a name="fbdrivers">6.3.5 Frame Buffer Drivers</a></h3>

<ul>
  <li>
patacongo's avatar
patacongo committed
    <p>
      <b><code>include/nuttx/fb.h</code></b>.
      All structures and APIs needed to work with frame buffer drivers are provided in this header file.
    </p>
patacongo's avatar
patacongo committed
  </li>
  <li>
patacongo's avatar
patacongo committed
    <p>
      <b><code>struct fb_vtable_s</code></b>.
      Each frame buffer device driver must implement an instance of <code>struct fb_vtable_s</code>.
      That structure defines a call table with the following methods:
    </p>
patacongo's avatar
patacongo committed
    <p>
      Get information about the video controller configuration and the configuration of each color plane.
    </p>
    <ul>
     <p><code>int (*getvideoinfo)(FAR struct fb_vtable_s *vtable, FAR struct fb_videoinfo_s *vinfo);</code><br>
     <code>int (*getplaneinfo)(FAR struct fb_vtable_s *vtable, int planeno, FAR struct fb_planeinfo_s *pinfo);</code></p>
    </ul>
    <p>
      The following are provided only if the video hardware supports RGB color mapping:
patacongo's avatar
patacongo committed
    </p>
patacongo's avatar
patacongo committed
    <ul>
     <p><code>int (*getcmap)(FAR struct fb_vtable_s *vtable, FAR struct fb_cmap_s *cmap);</code><br>
     <code>int (*putcmap)(FAR struct fb_vtable_s *vtable, FAR const struct fb_cmap_s *cmap);</code></p>
    </ul>
    <p>
      The following are provided only if the video hardware supports a hardware cursor:
    </p>
    <ul>
     <p><code>int (*getcursor)(FAR struct fb_vtable_s *vtable, FAR struct fb_cursorattrib_s *attrib);</code><br>
     <code>int (*setcursor)(FAR struct fb_vtable_s *vtable, FAR struct fb_setcursor_s *settings);</code></p>
    </ul>
  </li>
  <li>
patacongo's avatar
patacongo committed
    <p>
      <b>Binding Frame Buffer Drivers</b>.
      Frame buffer drivers are not normally directly accessed by user code, but are usually bound to another,
      higher level device driver.
      In general, the binding sequence is:
    </p>
    <p>
      <ol>
        <li>Get an instance of <code>struct fb_vtable_s</code> from the hardware-specific frame buffer device driver, and </li>
        <li>Provide that instance to the initialization method of the higher level device driver.</li>
      </ol>
    </p>
  </li>
  <li>
    <p>
      <b>Examples</b>:
      <code>arch/sim/src/up_framebuffer.c</code>.
      See also the usage of the frame buffer driver in the <code>graphics/</code> directory.
    </p>
  </li>
</ul>

<h3><a name="lcddrivers">6.3.6 LCD Drivers</a></h3>

<ul>
  <li>
    <p>
      <b><code>include/nuttx/lcd/lcd.h</code></b>.
      Structures and APIs needed to work with LCD drivers are provided in this header file.
      This header file also depends on some of the same definitions used for the frame buffer driver as privided in <code>include/nuttx/fb.h</code>.
    </p>
  </li>
  <li>
    <p>
      <b><code>struct lcd_dev_s</code></b>.
      Each LCD device driver must implement an instance of <code>struct lcd_dev_s</code>.
      That structure defines a call table with the following methods:
    </p>
    <p>
      Get information about the LCD video controller configuration and the configuration of each LCD color plane.
    </p>
    <ul>
    <p>
       <code>int (*getvideoinfo)(FAR struct lcd_dev_s *dev, FAR struct fb_videoinfo_s *vinfo);</code><br>
       <code>int (*getplaneinfo)(FAR struct lcd_dev_s *dev, unsigned int planeno, FAR struct lcd_planeinfo_s *pinfo);</code>
     </p>
    </ul>
    <p>
      The following are provided only if the video hardware supports RGB color mapping:
    </p>
    <ul>
     <p>
       <code>int (*getcmap)(FAR struct lcd_dev_s *dev, FAR struct fb_cmap_s *cmap);</code><br>
       <code>int (*putcmap)(FAR struct lcd_dev_s *dev, FAR const struct fb_cmap_s *cmap);</code>
     </p>
    </ul>
    <p>
      The following are provided only if the video hardware supports a hardware cursor:
    </p>
patacongo's avatar
patacongo committed
    <ul>
patacongo's avatar
patacongo committed
     <p>
       <code>int (*getcursor)(FAR struct lcd_dev_s *dev, FAR struct fb_cursorattrib_s *attrib);</code><br>
       <code>int (*setcursor)(FAR struct lcd_dev_s *dev, FAR struct fb_setcursor_s *settings)</code>
     </p>
patacongo's avatar
patacongo committed
    </ul>
patacongo's avatar
patacongo committed
    <p>
      Get the LCD panel power status (0: full off - <code>CONFIG_LCD_MAXPOWER</code>: full on).
      On backlit LCDs, this setting may correspond to the backlight setting.
    </p>
    <ul>
     <p>
       <code>int (*getpower)(struct lcd_dev_s *dev);</code>
     </p>
    </ul>
    <p>
      Enable/disable LCD panel power (0: full off - <code>CONFIG_LCD_MAXPOWER</code>: full on).
      On backlit LCDs, this setting may correspond to the backlight setting.
    </p>
    <ul>
     <p>
       <code>int (*setpower)(struct lcd_dev_s *dev, int power);</code>
     </p>
    </ul>
    <p>
      Get the current contrast setting (0-CONFIG_LCD_MAXCONTRAST) */
    </p>
    <ul>
     <p>
       <code>int (*getcontrast)(struct lcd_dev_s *dev);</code>
     </p>
    </ul>
    <p>
      Set LCD panel contrast (0-CONFIG_LCD_MAXCONTRAST)
    </p>
    <ul>
     <p>
       <code>int (*setcontrast)(struct lcd_dev_s *dev, unsigned int contrast);</code>
     </p>
    </ul>
  </p>
  <li>
    <p>
      <b>Binding LCD Drivers</b>.
      LCD drivers are not normally directly accessed by user code, but are usually bound to another,
      higher level device driver.
      In general, the binding sequence is:
    </p>
    <p>
      <ol>
        <li>Get an instance of <code>struct lcd_dev_s</code> from the hardware-specific LCD device driver, and </li>
        <li>Provide that instance to the initialization method of the higher level device driver.</li>
      </ol>
    </p>
patacongo's avatar
patacongo committed
  </li>
  <li>
patacongo's avatar
patacongo committed
    <p>
      <b>Examples</b>:
      <code>drivers/lcd/nokia6100.c</code>, <code>drivers/lcd/p14201.c</code>, <code>configs/sam3u-ek/src/up_lcd.c.</code>
      See also the usage of the LCD driver in the <code>graphics/</code> directory.
    </p>
patacongo's avatar
patacongo committed
  </li>
</ul>

patacongo's avatar
patacongo committed
<h3><a name="mtddrivers">6.3.7 Memory Technology Device Drivers</a></h3>
patacongo's avatar
patacongo committed

<ul>
  <li>
patacongo's avatar
patacongo committed
    <p>
      <b><code>include/nuttx/mtd.h</code></b>.
      All structures and APIs needed to work with MTD drivers are provided in this header file.
    </p>
patacongo's avatar
patacongo committed
  </li>
  <li>
patacongo's avatar
patacongo committed
    <p>
      <b><code>struct mtd_dev_s</code></b>.
      Each MTD device driver must implement an instance of <code>struct mtd_dev_s</code>.
      That structure defines a call table with the following methods:
    </p>
patacongo's avatar
patacongo committed
    <p>
      Erase the specified erase blocks (units are erase blocks):
    </p>
    <ul>
     <p><code>int (*erase)(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks);</code></p>
    </ul>
    <p>
      Read/write from the specified read/write blocks:
patacongo's avatar
patacongo committed
    </p>
patacongo's avatar
patacongo committed
    <ul>
     <p><code>ssize_t (*bread)(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks, FAR uint8_t *buffer);</code><br>
     <code>ssize_t (*bwrite)(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks, FAR const uint8_t *buffer);</code></p>
patacongo's avatar
patacongo committed
    </ul>
    <p>
      Some devices may support byte oriented reads (optional).
      Most MTD devices are inherently block oriented so byte-oriented writing is not supported.
      It is recommended that low-level drivers not support read() if it requires buffering.
Loading
Loading full blame...