2010-03-22

Port microC/OS-II to AVR32 UC3

We should understand that a software can be called kernel must fulfill at least these four tasks:
  • Task management, sometime call it scheduler.
  • Time management, handle timer, delay.
  • Intertask communication, how to share the resource between mutiple tasks.
  • Memory Management, e.g. how to allocation of memory.
However, these functionalities are implemented in a general way, so that it can be used in hopefully all kinds of CPU archtectures. Porting is to finish the rest job, namely, to make the kernel more specific to a certain CPU archtectures with a given toolchain.

Let's see a concrete example: Porting micro C/OS-II to AVR32UC3 microcontroller. The codes in the first block (uC/OS-II book) are the general implementation of kernel, implemented in standard C. If you check the code more closely, you may find that some used functions (or macros) are not yet implemented there. For example:
  • OS_TASK_SW()
The macro is used everywhere to switch context, saving the processor registers of task be suspended and restoring the registers of higher-priority task. The exact implemented is done in OS_CPU.H, you may notice that it is in the porting block (section 3). According to the used toolchains,

For GUN toolchains
  • #define OS_TASK_SW() __asm__ __volatile__ ("scall")

For IAR toolchians
  • #define OS_TASK_SW() (OSCtxSw())
If uC/OS is ported to Intel 80x86 architecture, the macro is defined by assambly instructions
  • #define uCOS 0x80
  • #define OS_TASK_SW() asm INT uCOS
In the graphic, BSP(Board Support Package) codes usually encapulate the utility functions for convenient access or configure the hardwares, e.g. timer, led and so on.

Usually, the porting is provided by vendor of chips, because these guys know it best and want their product as compatible as possible to all kernels.

Reference:

No comments:

Post a Comment