Common files for the HAL

From ErikaWiki

Jump to: navigation, search


During the porting of Mico32 someone thought that it could be possible to reuse a substantial part of the code of the HAL among many architectures. The files contained in ee/pkg/cpu/common can be used both as a part of a new porting, by including them, or as a base to derive code specific to a particular architecture.

All the files in cpu/common are written in standard C; they should work as they are on almost any platform or compiler. The should be decoupled enough so that if a porting requires a custom implementation of some parts, the rest could be used with no modification. A new porting should use the common implementation when possible, or an ad-hoc implementation under cpu/XXX otherwise.

Please do not modify these files to accommodate some quirks of your architecture. Instead, make a copy of them and create a branch under your cpu/XXX directory or whatever. Implementations that can potentially be useful on many platforms are welcome; e.g., ee/pkg/cpu/common/inc/ee_compiler_gcc.h works only for Gcc, but it should work across all platforms where Gcc is available.

The common layer is used by following portings:


cpu/common contains a practically complete monostack version of Erika without interrupts, with support for the multistack version and interrupts. There is one context-changing function (instead of the two of previous portings). Where possible, all parts have been written so that there is one implementation in C for all versions (mono or multistack); this is accomplished through the use of macros or small inline functions that are defined differently depending on the version. See the inline definition of EE_hal_ready2stacked() in ee/pkg/cpu/common/inc/ee_context.h for an example.

Porting to a new architecture

See Porting ERIKA Enterprise and RT-Druid to a new microcontroller for the general instructions.

  1. Create the architecture-specific directory ee/pkg/cpu/XXX
  2. Create the files inc/ee_cpu.h and inc/ee_internal.h in the above directory. They should include all the files cpu/common/inc/ee_*.h suitable for your architecture. Write any architecture-specific definition or declaration in them.
  3. Modify the files ee/pkg/ee.h and ee/pkg/ee_internal.h to include your newly create files.
  4. Modify the file cpu/common/cfg/ to compile the common C source files suitable for your architecture.
  5. Create or modify any additional file you need.
  6. Run make and enjoy.
Personal tools