As we know, uC/OS –II is a scalable, ROMable, preemptive real-time kernel that manages multiple tasks and it has been ported to more than 45 CPU architectures. In this article,you can learn the steps of porting uC/OS –II to MAPS-22.
Downloading uC/OS-II source code and application project
You will be required to register. This means that you’ll have to provide information about yourself. Download and execute the following file: Micrium-Book-uCOS-II-TWR-K53N512.exe.
Fig 1 shows the directory structure created by this executable.
All files are placed under the \Micrium directory. There are two main sub-directories: \Examples and \Software and they are described below.
Directories and Files
μC/OS-II is fairly easy to use once it is understood exactly which source files are needed to make up a μC/OS-II-based application. Fig 2 shows the μC/OS-II architecture and its relationship with hardware. Of course,
in addition to the timer and interrupt controller, hardware would most likely contain such other devices as Universal Asynchronous Receiver Transmitters (UARTs), Analog to Digital Converters (ADCs), Ethernet controller(s) and more.
The application code consists of project or product files. For convenience, these are simply called app.c and app.h, however an application can contain any number of files that do not have to be called app.*. The application code is typically where one would find the main().
The Board Support Package (BSP) code needed by μC/OS-II is typically quite simple and generally, μC/OS-II only requires that you initialize a periodic interrupt source which is used for time delays and timeouts. This functionality can be placed in a file called bsp.c along with its corresponding header file, bsp.h.
Semiconductor manufacturers often provide library functions in source form for accessing the peripherals on their CPU or MCU. These libraries are also part of the BSP.
This is the μC/OS-II processor-independent code. This code is written in highly portable ANSI C.
This is the μC/OS-II code that is adapted to a specific CPU architecture and is called a port.
Configuration files are used to define μC/OS-II features (os_cfg.h) to include in the application, specify the size of certain variables and data structures expected by μC/OS-II, such as idle task stack size and tick rate among others.
Below is a summary of all directories and files involved in a μC/OS-II-based project (Fig 3). The“<-Cfg” on the far right indicates that these files are typically copied into the application directory and edited based on the project requirements.
1. Copy uC/OS-II source code to ~\MAPSK22_SC\Libraries which includes peripheral driver files, startup code and devices header
2. Copy os_cfg.h, app_cfg.h which reside in ~\Micrium-Book-uCOS-II-TWR-K53N512\Micrium\Examples\Freescale\TWR-K53N512\(project name) to ~\MAPSK22_SC\Project\MAPSK22\1-Template\src
Summary: configuration files os_cfg.h, app_cfg.h should be adapt to the specific requirements of the application code
3. Copy lib_def.h which resides in ~\Micrium\Software\uC-LIB to ~\MAPSK22_SC\Libraries\drivers\K\inc
4. Adds systick timer initialization function in system_MK22F51212.c
void SystemTickInit (void)
cpu_clk_freq = SystemCoreClock;
cnts = cpu_clk_freq / (uint32_t)OS_TICKS_PER_SEC;
5. Modify the interrupt vector
6. Create uC/OS-II group in the workspace, then add the uC/OS-II source code and os_cfg.h, app_cfg.h
7. Add application code in the main.c and please check the attachment.
8. Modify the Include Directories
Run the uC/OS-II application
After build the modified application code, then run it on MAPS-K22 board(Fig 4).
You can find the LED3 and LED4 flash every 2s, however for the LED1 and LED2, it’s 1s. And some informations’re illustrated in the Hyper Terminal (Fig 5)