Name

HAL Port — Implementation Details

Overview

This documentation explains how the eCos HAL specification has been mapped onto the AT91SAM9G20-EK hardware, and should be read in conjunction with that specification. The AT91SAM9G20-EK platform HAL package complements the ARM architectural HAL, the ARM9 variant HAL and the SAM9 processor HAL. It provides functionality which is specific to the target board.

Startup

Following a hard or soft reset, the HAL will initialize or reinitialize most of the on-chip peripherals. There is an exception for RAM startup applications which depend on a ROM monitor for certain services.

For ROM startup, the HAL will perform additional initialization. This is all done in the PLATFORM_SETUP1 macro in the assembler header file hal_platform_setup.h.

Linker Scripts and Memory Maps

The platform HAL package provides the memory layout information needed to generate the linker script. The key memory locations are as follows:

SDRAM
This is located at address 0x20000000 of the physical memory space. The HAL configures the MMU to retain the SDRAM at virtual address 0x20000000, but in order to assign hardware exception vectors vectors at address 0x00000000, the HAL also uses the MMU to create a clone of this memory at virtual address 0x00000000. The same memory is also accessible uncached and unbuffered at virtual location 0x30000000 for use by devices. The first 32 bytes are used for hardware exception vectors. The next 32 bytes are used for the VSR table and the next 256 bytes are normally used for the eCos virtual vectors, allowing RAM-based applications to use services provided by the ROM monitor. Memory is required for the MMU tables, and must be aligned on a 16Kbyte boundary. These therefore occupy memory from 0x4000 to 0x8000. For ROM startup, all remaining SDRAM is available. For RAM startup, available RAM starts at virtual location 0x20040000, with the bottom 256kB reserved for use by RedBoot.
On-chip SRAM
This is located at address 0x00200000 of the physical memory space. However the HAL uses the MMU to relocate this to virtual address 0x70000000. The same memory is also accessible uncached and unbuffered at virtual location 0x70100000 for use by devices. At present this memory is unused by eCos and is available for application use.
On-chip ROM
This is located at address 0x00100000 of the physical memory space. However the HAL uses the MMU to relocate this to virtual address 0x71000000. The same memory is also accessible uncached and unbuffered at virtual location 0x71800000.
USB host port
The USB host port (UHP) registers are located at address 0x00300000 of the physical memory space. However the HAL uses the MMU to relocate this to virtual address 0x72800000. Memory accessed at this address is uncached and unbuffered. There is no cached variant.
SPI dataflash
SPI Dataflash media can only be accessed with the Flash API. For the purposes of this API a placeholder address range has been allocated as if the Flash is present at this address. The base of this address range is 0x40000000 for the on-board flash and 0x50000000 for the dataflash slot, the extent will clearly depend on the Dataflash capacity. This reserved range is not real memory and any attempt to access it directly by the processor other than via the Flash API will result in a memory address exception.
On-chip Peripheral Registers
These are located at address 0xFF000000 in the physical memory space. When the MMU is enabled, it sets up a direct, uncached, unbuffered mapping so that these registers remain accessible at their physical locations.
Off-chip Peripherals
eCos uses the SDRAM, ethernet PHY, MCI, and SPI dataflash facilities on the AT91SAM9G20-EK board. eCos does not currently make any use of any other off-chip peripherals present on this board.

Advanced Interrupt Controller

This port has been designed to exploit benefits of the Advanced Interrupt Controller of the AT91SAM9G20, using the facilities of the SAM9 processor HAL. Consult the documentation in that package for details.

SPI Dataflash

eCos supports SPI access to Dataflash on the AT91SAM9G20-EK. An on-board device and an external card slot are provided on the board. The on-chip device is typically used to contain RedBoot and flash configuration data. The external slot is available for application use.

Accesses to Dataflash are performed via the Flash API, using 0x40000000 or 0x50000000 as the nominal address of the device, although it does not truly exist in the processor address space. For the external card slot, on driver initialisation, eCos and RedBoot can detect the presence of a card in the socket. In particular, on reset RedBoot will indicate the presence of Flash at the 0x40000000 address range in its startup banner if it has been successfully detected. Hot swapping is not possible.

Since Dataflash is not directly addressable, access from RedBoot is only possible using fis command operations.

The MCI driver cannot be enabled simultaneously with the SPI driver, as the drivers need differing pin configurations for the same pins on this board due to the shared socket.

Real-time characterization

The tm_basic kernel test gives statistics gathered about the real-time characterization and performance of the kernel. The sample output is shown here for information. The test was built in ARM mode, which provided better performance than Thumb mode.

Example 261.1. sam9g20ek Real-time characterization

INFO:<code from 0x20040040 -> 0x2004bad4, CRC eb0a>
            Startup, main stack : stack used   388 size  3920
             Startup :  Interrupt stack used   524 size  4096
             Startup : Idlethread stack used    96 size  2048

eCos Kernel Timings
Notes: all times are in microseconds (.000001) unless otherwise stated

Reading the hardware clock takes 1 'ticks' overhead
... this value will be factored out of all other measurements
Clock interrupt took    2.93 microseconds (24 raw clock ticks)

Testing parameters:
   Clock samples:            32
   Threads:                  64
   Thread switches:         128
   Mutexes:                  32
   Mailboxes:                32
   Semaphores:               32
   Scheduler operations:    128
   Counters:                 32
   Flags:                    32
   Alarms:                   32


                                 Confidence
     Ave     Min     Max     Var  Ave  Min  Function
  ======  ======  ======  ====== ========== ========
    2.60    1.82    4.84    0.40   46%  28% Create thread
    0.32    0.24    1.33    0.08   98%  50% Yield thread [all suspended]
    0.48    0.36    1.09    0.07   56%  28% Suspend [suspended] thread
    0.43    0.36    0.85    0.09   85%  68% Resume thread
    0.66    0.48    1.70    0.08   95%   1% Set priority
    0.21    0.00    0.48    0.09   79%   1% Get priority
    1.37    1.21    3.88    0.14   54%  78% Kill [suspended] thread
    0.32    0.24    0.73    0.06   54%  43% Yield [no other] thread
    0.67    0.48    1.33    0.10   79%   7% Resume [suspended low prio] thread
    0.43    0.36    0.73    0.09   85%  68% Resume [runnable low prio] thread
    0.71    0.61    1.21    0.07   54%  31% Suspend [runnable] thread
    0.31    0.24    0.85    0.07   50%  48% Yield [only low prio] thread
    0.48    0.36    0.97    0.07   53%  28% Suspend [runnable->not runnable]
    1.23    1.09    2.54    0.09   60%  20% Kill [runnable] thread
    1.25    0.97    3.39    0.14   54%  34% Destroy [dead] thread
    1.90    1.70    3.15    0.11   81%   4% Destroy [runnable] thread
    2.88    2.54    5.21    0.21   64%  29% Resume [high priority] thread
    0.90    0.85    1.94    0.07   98%  61% Thread switch

    0.02    0.00    0.61    0.03   86%  86% Scheduler lock
    0.25    0.24    0.73    0.01   98%  98% Scheduler unlock [0 threads]
    0.25    0.24    0.48    0.01   98%  98% Scheduler unlock [1 suspended]
    0.25    0.24    0.48    0.02   92%  92% Scheduler unlock [many suspended]
    0.25    0.24    0.48    0.02   92%  92% Scheduler unlock [many low prio]

    0.11    0.00    0.97    0.06   68%  28% Init mutex
    0.51    0.36    1.45    0.10   71%  25% Lock [unlocked] mutex
    0.54    0.36    1.94    0.13   75%  68% Unlock [locked] mutex
    0.44    0.36    1.21    0.09   96%  56% Trylock [unlocked] mutex
    0.39    0.24    0.61    0.07   53%  15% Trylock [locked] mutex
    0.03    0.00    0.24    0.04   81%  81% Destroy mutex
    2.08    2.06    2.66    0.04   96%  96% Unlock/Lock mutex

    0.19    0.12    1.09    0.09   96%  65% Create mbox
    0.16    0.12    0.61    0.06   75%  75% Peek [empty] mbox
    0.60    0.48    1.57    0.10   43%  40% Put [first] mbox
    0.16    0.12    0.48    0.06   81%  81% Peek [1 msg] mbox
    0.59    0.48    0.97    0.08   40%  40% Put [second] mbox
    0.15    0.00    0.36    0.08   62%  12% Peek [2 msgs] mbox
    0.63    0.48    1.70    0.10   68%  25% Get [first] mbox
    0.60    0.48    0.97    0.07   50%  31% Get [second] mbox
    0.51    0.36    1.33    0.10   65%  21% Tryput [first] mbox
    0.56    0.36    1.33    0.10   84%   6% Peek item [non-empty] mbox
    0.59    0.48    1.45    0.09   43%  43% Tryget [non-empty] mbox
    0.46    0.36    0.73    0.07   56%  34% Peek item [empty] mbox
    0.45    0.36    0.97    0.08   46%  43% Tryget [empty] mbox
    0.14    0.00    0.36    0.07   65%  15% Waiting to get mbox
    0.15    0.12    0.48    0.04   84%  84% Waiting to put mbox
    0.22    0.12    0.73    0.08   46%  40% Delete mbox
    1.48    1.45    2.30    0.05   96%  96% Put/Get mbox

    0.02    0.00    0.24    0.03   87%  87% Init semaphore
    0.31    0.24    0.85    0.08   96%  59% Post [0] semaphore
    0.42    0.36    1.09    0.08   96%  71% Wait [1] semaphore
    0.32    0.24    0.85    0.08   96%  50% Trywait [0] semaphore
    0.29    0.24    0.48    0.06   62%  62% Trywait [1] semaphore
    0.08    0.00    0.48    0.09   87%  53% Peek semaphore
    0.05    0.00    0.85    0.07   81%  81% Destroy semaphore
    1.37    1.33    2.18    0.07   93%  93% Post/Wait semaphore

    0.22    0.12    1.45    0.10   50%  46% Create counter
    0.13    0.00    0.48    0.04   75%  12% Get counter value
    0.07    0.00    0.36    0.08   90%  56% Set counter value
    0.48    0.36    0.73    0.07   46%  28% Tick counter
    0.14    0.00    0.61    0.08   59%  21% Delete counter

    0.06    0.00    0.48    0.08   93%  59% Init flag
    0.40    0.24    1.33    0.07   81%   6% Destroy flag
    0.33    0.24    1.09    0.10   87%  59% Mask bits in flag
    0.39    0.24    0.97    0.07   62%  15% Set bits in flag [no waiters]
    0.53    0.48    1.82    0.09   96%  90% Wait for flag [AND]
    0.47    0.36    0.97    0.05   75%  21% Wait for flag [OR]
    0.50    0.48    0.85    0.03   90%  90% Wait for flag [AND/CLR]
    0.47    0.36    0.85    0.05   71%  25% Wait for flag [OR/CLR]
    0.00    0.00    0.12    0.01   96%  96% Peek on flag

    0.34    0.24    1.21    0.08   53%  43% Create alarm
    0.77    0.61    2.42    0.12   75%  18% Initialize alarm
    0.42    0.36    1.09    0.08   93%  68% Disable alarm
    0.75    0.61    2.18    0.10   71%  25% Enable alarm
    0.51    0.36    1.21    0.07   65%  15% Delete alarm
    0.44    0.36    0.97    0.07   50%  46% Tick counter [1 alarm]
    2.67    2.66    2.91    0.01   96%  96% Tick counter [many alarms]
    0.82    0.73    1.33    0.07   59%  37% Tick & fire counter [1 alarm]
   14.87   14.78   15.14    0.06   65%  31% Tick & fire counters [>1 together]
    3.06    3.03    3.39    0.05   81%  81% Tick & fire counters [>1 separately]
    2.43    2.42    3.51    0.02   99%  99% Alarm latency [0 threads]
    2.56    2.42    2.91    0.07   60%  17% Alarm latency [2 threads]
    3.64    3.15    4.36    0.26   67%  39% Alarm latency [many threads]
    3.83    3.75    6.30    0.08   98%  50% Alarm -> thread resume latency

    0.81    0.73    1.94    0.00            Clock/interrupt latency

    0.87    0.61    2.18    0.00            Clock DSR latency

    4      0     260  (main stack:  1356)  Thread stack used (1360 total)
           All done, main stack : stack used  1356 size  3920
            All done :  Interrupt stack used   664 size  4096
            All done : Idlethread stack used   240 size  2048

Timing complete - 29880 ms total

PASS:<Basic timing OK>
EXIT:<done>

Other Issues

The AT91SAM9G20-EK platform HAL does not affect the implementation of other parts of the eCos HAL specification. The SAM9 processor HAL, ARM9 variant HAL, and the ARM architectural HAL documentation should be consulted for further details.