The uC/OS-II port for Keil C V6.20, V6.21 or higher
By John X. Liu, China, (johnxliu@163.com)
1. About this port.
This package contains the files of porting uC/OS-II to Keil C
environment, including the necessary head files and source
files and an example to show how to use this port.
2. Files list.
This package only included the files specific to port for
Keil C, and assumed that you have all the other uC/OS source
files.
Porting files:
OS_CPU.H Defines the data types and some macros needed
by uC/OS. Also defines some macros to work-
around the problem that some keil c keywords
were used as identifiers in uC/OS-II source
files.
OS_KC51.H Declaring the uC/OS functions with 'reentrant'
suffix, so that they are reentrant functions.
OS_KCDEF.H Reconvert Keil's keywords to make them available.
INCLUDES.H Puts all needed header files included together
so that in c source files less header files are
needed to be included.
OS_CPU_C.C The c part of porting source files.
OS_CPU_A.ASM The assembling language part.
Example files:
OS_CFG.H The configuaration file, specific to every
application, used to define what features of
the os are needed to be included
EX1L.C The example file which can be found in EX1_IX86L
directory originally, ported to keil c environment.
PC.H The PC-emulating head file, ported from \SOFTWARE\PC
PC.C The PC-emulating source file, implemented some PC
functions by emulating. ported from \SOFTWARE\PC
PC51EMU.DLL The debug dll of Keil UV2 degugger environment.
To be used to emulate the behavior of a PC display.
EX1KC51.UV2 The example's project file.
EX1KC51.OPT Option file of the project.
Document:
Readme.Txt This file.
3. About the porting files.
The required functions have been implemented according to the
description in the book '米C/OS, The Real-Time Kernel'. Mainly
the work of porting is arround how to save the statues of CPU
and restore later. The status includes the registers ACC, B,
PSW, DPTR, IE, R0-R7, SP, and the hardware stack resides in
8051 strach RAM. This work is fulfiled by c code in OS_CPU_C.C
and some assembly code in OS_CPU_A.ASM.
Due to Keil C's specific grammer, function declared by default
is non-reentrant. If you want a function to be reentrantable,
you must add a 'reentrant' after the declaration, like this:
func() reentrant
{
.
.
.
}
So it is unfortunately necessary for every keil c user to modify
the declaration of every funtions to make them work as expected in
Keil C environment. In this port the os_kcdef.h declares all uC/OS
functions reentrant. But you still need do lots of thing. You must
modify the uC/OS function declarations in both header files and
source files to make them conform to the ones in os_kcdef.h.
4. The example.
In the directory \SOFTWARE\UCOS-II\EX1_IX86L there is an example
of Borland C porting running under MS-DOS. I found that it is a
nice illustration of uC/OS multi-tasking feature, so I adopted it
to show the porting in keil c environment. Of course, 8051 chip is
quite different from PC platform. So I wrote a Keil C UV2 debugger
simulator DLL to display the result. It maps the XDATA:0-0x1000 as
PC's display buffer at B800:0 and displays the characters and
attributes whatever writen to there as same as PC does.
To see the result of the example, you should copy the PC51Emu.DLL
to the Keil's C51\Bin directory and add a '-dPC51Emu' at the
paramters editbox of dialog DLL in debug panel of the project's
options.
5. Compiling and running the example files.
First, Unzip the files in this package to a directory,
i.e. \SOFTWARE\uCOS-II\I8051\Keil, make the directory current.
then copy all uC/OS files in the directory \SOFTWARE\uCOS-II\SOURCE
to the current directory, edit the function declarations in UCOS_II.H,
OS_*.C to make them same with the ones in OS_KCDEF.H.
Second, Run Keil's UV2 IDE, open the project file "Ex1KC51.UV2",
click compile or build, let KC compile all the source files, and
build the target Ex1Kc51. If any error occurs, correct it. Mostly
circumstance it is due to incorrect modifing of uC/OS source code.
It is simple to find the mismatches out and correct them.
Third, start debugging, and check the peripheral menu, you will
see a menu item 'Virtual screen' added there. Click the menu item,
a PC-liked virtual screen window will display. Run the example in
full speed, you will see all the output of the example shown on
virtual screen.
You may run the original example in \SOFTWARE\uCOS-II\EX1_I86L,
to compare the outcome with the one shown in virtual screen.
6. Adapting this port in your application.
1) Copy the files you need from the directory of this example
to the directory of your project.
2) Read and edit the OS_CPU.H and select a critical method
best fit to you.
3) Read and edit the OS_CFG.H and decide what system services
you need in your project.
4) Write the interrupt service routines as described in
OS_CPU_C.C. If you like you may reimplement the OSTickISR.
5) At least in your first task you must write code to initialize
the timer that uC/OS uses. If you change the timer rate, you
must change the OS_TICKS_PER_SEC to the right value.
7.Limitation.
This port has some limitations. Listed as below.
1) Only large mode is supported.
2) Does not support register banking for interrupt service routine.
3) Does not support RET_PSTK or RET_XSTK, saving return address
in reentrant stack
4) Does not support multiple data pointer accessing.