📄 read.me
字号:
Copyright 1995, Jean J. Labrosse, Plantation, FL
All Rights Reserved
uC/OS, The Real-Time Kernel
for the
Intel MCS-251
Jean J. Labrosse
October 24, 1995
1.00 MCS-251 Architecture
Introduced almost 15 years ago, one of Intel抯 original embedded control devices was the 8051
microcontroller. Today, the 8051 is still going strong with the support of numerous licensees and
customers. According to Dataquest (May 1994), suppliers shipped more than 126 million 8051 devices
in 1993. Intel has launched its MCS-51 architecture into the future with a new core design called the
MCS-251 architecture. Proliferations based on this new architecture will provide unequaled value,
performance and ease of design for 8-bit designers.
The new MCS-251 architecture brings high performance, an increased memory mix and addressing, low
power, low noise, efficient high-level language support, enhanced instruction set, integrated features and
functionality to the 8-bit embedded control market segment.
2.00 uC/OS, The Real-Time Kernel
uC/OS is a portable, ROMable, preemptive, real-time, multitasking kernel for microprocessors. uC/OS is
written in C with assembly language code for the target microprocessor kept to a minimum. uC/OS
manages up to 63 user tasks, with performance comparable to many commercially available kernels.
uC/OS (V1.08) has been ported to the Intel MCS-251 microcontroller family.
Intel Corporation, Inc., R&D Publications, Inc. and Jean J. Labrosse do not offer any warranties and do
not guarantee the accuracy, adequacy, or completeness of any information and is not responsible for any
errors or omissions or the results obtained from use of such information.
3.00 Hardware/Software Requirements
To use the MCS-251 port of uC/OS, you MUST obtain the book describing the internals of uC/OS and
the full source code for uC/OS. Both the book and the diskette are available from R&D Publications, Inc.
(or from your favorite bookstore) for only $49.95 (U.S.).
Hardware: IBM-PC/AT (or compatible system)
2 Megabytes of free hard disk space
640 KBytes of RAM
Software: IBM PC-DOS or MS-DOS version 6.1 (or higher)
Windows 3.1 (or higher)
Production Languages Corp. Compass/251 Software Development Tools
uC/OS, The Real-Time Kernel diskette
(available from R&D Publications, Inc., see contacts)
uC/OS, The Real-Time Kernel for the Intel MCS-251
(available from the Intel Corporation's BBS)
4.00 Installation
You should obtain and install uC/OS, The Real-Time Kernel (available from R&D Publications, Inc. : see
Section 15.00, Contacts) on your system BEFORE installing this software. The installation of uC/OS will
create a directory tree which is assumed to exist when you install the Intel MCS-251 port. Basically, the
source code for uC/OS is assumed to reside in the \SOFTWARE\UCOS\SOURCE directory of your hard-
disk. The files related to the Intel MCS-251 port will be located in the \SOFTWARE\UCOS\MCS251
directory.
You will need to delete the 'uC/OS CONFIGURATION' section in UCOS.H because the #define
constants defined in this section are actually found in the file OS_CFG.H (see MCS-251 related files).
5.00 uC/OS assumptions about the MCS-251
uC/OS assumes very little about the underlying processor. I have, however, made a few assumptions
about how the MCS-251 is used.
At this time, the MCS-251 port has only been tested using the PLC MCS-251 simulator (included with the
PLC software development tools). The MCS-251 has not been tested on actual hardware.
5.01 uC/OS assumptions about the MCS-251, Source mode
uC/OS assumes that your application code will run in SOURCE mode. On the MCS-251, SOURCE
mode means that the MCS-251 will only recognize instructions which are unique to the MCS-251
architecture. The PLC C compiler was thus directed to produce native MCS-251 instructions when
compiling uC/OS.
5.02 uC/OS assumptions about the MCS-251, LARGE memory model
uC/OS has been compiled using the LARGE memory model as defined by the PLC software
development tools. This means that your application is capable of addressing up to 64 KBytes of ROM
and 64 KBytes of RAM. To address up to 16 MBytes, uC/OS will need to be ported to the HUGE model.
The LARGE model was chosen because it is the fastest mode of operation for the MCS-251.
5.03 uC/OS assumptions about the MCS-251, INTR bit set to 0
It is also assumed that the INTR bit in the CONFIG register is set to 0. This means that only the PC
(Program Counter) is pushed onto the stack when an interrupt occurs. It is up to your startup code to
ensure that INTR is set to 0.
5.04 uC/OS assumptions about the MCS-251, Register bank #0
During a context switch, uC/OS will only save the registers in bank 0. If your application uses a different
register bank during an ISR, you must ensure that you restore register bank 0 prior to giving control back
to uC/OS.
5.05 uC/OS assumptions about the MCS-251, System Tick
Your application code MUST provide a 'tick' source which will vector to OSTickISR() (defined in
MCS251.C). In TEST.C Timer #0 was used to provide a tick source but you can change this to
accomodate your own requirements. You should choose a tick rate between 10 and 100 Hz.
5.06 uC/OS assumptions about the MCS-251, Application Tasks
A task MUST always be written as an infinite loop as shown below (see also TEST.C). Setting pdata to
itself is done to prevent a compiler warning in case you do not actually use the argument passed to the
task. Before the infinite loop starts, you must enable interrupts by invoking the macro
OS_EXIT_CRITICAL(). Once in the infinite loop, your application code MUST (at some point) invoke a
service provided by uC/OS to either delay itself for an integral number of ticks, wait for a semaphore,
wait for a message at a mailbox or a queue or, explicitly suspend the task.
void OS_FAR Task(void *pdata)
{
pdata = pdata; /* Prevent compiler warning! */
OS_EXIT_CRITICAL(); /* Enable interrupts */
while (TRUE) {
/* User code goes here ...! */
/* You MUST make a service call to uC/OS to: */
/* ... a) delay for 'n' ticks */
/* ... b) wait on a semaphore */
/* ... c) wait for a message from a task or ISR */
/* ... d) suspend this task. */
}
}
5.07 uC/OS assumptions about the MCS-251, Idle Task
When all of your application tasks are waiting for some event to occur, uC/OS executes an internal task
called the Idle Task. The size of the IDLE task stack has been set to 256 bytes by the #define
OS_IDLE_TASK_STK_SIZE constant (see OS_CFG.H). You will need to modify this constant if you
need change the stack requirements of the idle task to suit your application.
6.00 Software Development Tools
The port of uC/OS for the Intel MCS-251 assumes the presence of the Production Languages
Corporation PLC Compass/251 Software Development Tools V2.20 (or higher). This package is a
Microsoft Windows hosted integrated software development environment (IDE) for the MCS-251
microcontroller. All of the tools can be accessed through the IDE control panel and contains:
An optimizing ANSI C cross-compiler,
A Macro Assembler,
A Linker/Locator,
A Librarian and,
A Source-Level Debugger.
The PLC development tools are assumed to reside in the C:\WINDOWS\251IDE directory. You may
need to modify some files if you install the PLC development tools in a different directory. All source
files were compiled from within the PLC IDE.
7.00 Directories and Files
The MCS-251 port is assumed to reside in the \SOFTWARE\UCOS\MCS251 directory. This directory
will contain the following files:
INCLUDES.H
OS_CFG.H
MCS251.H
MCS251.C
TEST.C
8.00 INCLUDES.H
The following statement is included at the top of all my .C files.
#include "INCLUDES.H"
INCLUDES.H allows every .C file in your project to be written without concerns about which header file
will actually be needed. In other words, INCLUDES.H is a MASTER include file. The only drawback to
having a master include file is that INCLUDES.H may include header files that are not pertinent to the
actual .C file being compiled. This means that each file will require extra time to compile. This
inconvenience is offset by code portability and ease of use. For the MCS251 port, INCLUDES.H should
contain the following statements:
#include <80251.H>
#include "\SOFTWARE\UCOS\MCS251\OS_CFG.H"
#include "\SOFTWARE\UCOS\MCS251\MCS251.H"
#include "\SOFTWARE\UCOS\MCS251\UCOS.H"
#include "your own header files"
You should list the header files in the order shown above. 80251.H is a header file provided by PLC and
is used to allow MCS-251 registers to be accessible from C.
You can edit INCLUDES.H to add your own header files.
9.00 OS_CFG.H
OS_CFG.H is a header file which is used to configure uC/OS. I assume that the #defines in this file
are used to configure uC/OS for your product and thus, OS_CFG.H can change from product to product.
OS_CFG.H contains the following #defines.
/*
*********************************************************************************************************
* uC/OS CONFIGURATION
*********************************************************************************************************
*/
#define OS_MAX_TASKS 63 /* Maximum number of tasks in your application */
#define OS_MAX_EVENTS 20 /* Maximum number of event control blocks in your application */
#define OS_MAX_QS 5 /* Maximum number of queue control blocks in your application */
#define OS_IDLE_TASK_STK_SIZE 256 /* Idle task stack size (BYTEs) */
#define OS_IDLE_TASK_STK_TOP 0 /* Index into idle task top of stack */
#define OS_TASK_CHANGE_PRIO_EN 1 /* Include code for OSTaskChangePrio() */
#define OS_TASK_DEL_EN 1 /* Include code for OSTaskDel() */
#define OS_SEM_EN 1 /* Include code for SEMAPHORES */
#define OS_MBOX_EN 1 /* Include code for MAILBOXES */
#define OS_Q_EN 1 /* Include code for QUEUES */
#define OS_TASK_SUSPEND_EN 1 /* Include code for OSTaskSuspend() and OSTaskResume() */
If you have uC/OS V1.08 or an earlier version, you will need to delete the 'uC/OS CONFIGURATION'
section which is found in UCOS.H in order to use OS_CFG.H. Failure to do this will result in a multiple
definition of the #define constants.
9.01 OS_CFG.H, OS_MAX_???
These #define are used to specify the maximum number of tasks, event control blocks and queues
supported by uC/OS, respectively. These #defines were created to keep the amount of RAM to a
minimum. For example, if your application only requires 10 tasks then, why allocate storage for internal
data structures to support 63 tasks?
9.02 OS_CFG.H, OS_IDLE_TASK_STK_???
These #defines are used to specify the size of the idle task stack and where the top-of-stack starts,
respectively. The value to set for OS_IDLE_TASK_STK_SIZE generally depends on the stack growth
associated with interrupt nesting of your application's ISRs. This is because the idle task doesn't use
much stack space for itself.
OS_IDLE_TASK_STK_TOP defines the index into the array OSTaskIdleStk[] to establish the initial
top-of-stack. On the MCS-251, the stack grows upwards (i.e. from low memory to high memory) and
thus, you need to set the top-of-stack to &OSTaskIdleStk[0].
9.03 OS_CFG.H, OS_???_EN
These #defines are used to specify whether whether certain uC/OS services will be provided to your
application. This allows the code size to be reduce when some services provided by uC/OS are not
used.
10.00 MCS251.H
The header file MCS251.H must be included in the master header file called INCLUDES.H and must
precede UCOS.H. MCS251.H is a processor specific file and should not change from product to product.
10.01 MCS251.H, TRUE and FALSE
MCS251.H defines the constants TRUE and FALSE unless they are already defined in another header
file. uC/OS assumes the presence of these constants.
10.02 MCS251.H, Data Types
Because different microprocessors have different word length, MCS251.H declares the following data
types which I use throughout the code instead of the standard C types char, int, long, float and
double.
/*
*********************************************************************************************************
* DATA TYPES
*********************************************************************************************************
*/
typedef unsigned char BOOLEAN; /* TRUE or FALSE */
typedef unsigned char UBYTE; /* Unsigned 8 bit quantity (0 to 255) */
typedef signed char BYTE; /* Signed 8 bit quantity (-128 to 127) */
typedef unsigned int UWORD; /* Unsigned 16 bit quantity (0 to 65,535) */
typedef signed int WORD; /* Signed 16 bit quantity (-32,768 to 32,767) */
typedef unsigned long ULONG; /* Unsigned 32 bit quantity (0 to 4,294,967,295) */
typedef signed long LONG; /* Signed 32 bit quantity (-2,147,483,648 to 2,147,483,647) */
By declaring these data types, I don't need to make any assumptions about the size of any of the C data
types for the particular compiler or microprocessor; for example, are ints 8, 16 or 32 bits? The data
type UWORD, for instance, makes it clear that I intend to use a 16-bit unsigned value.
10.03 MCS251.H, OS_STK_TYPE
This #define is used to specify the data type of the stacks used for each task. This #define has been
included because some processors have BYTE aligned stacks, others are more efficient with WORD or
LONG aligned stacks. The stacks on the MCS-251 are considered BYTE aligned and thus, OS_STK_TYPE
is set to UBYTE.
10.04 MCS251.H, OS_ENTER_CRITICAL() and OS_EXIT_CRITICAL()
To guaranty that uC/OS has exclusive access to critical sections of code, uC/OS needs to disable
interrupts prior to executing this code. uC/OS re-enables interrupts when it is done with the critical
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -