【文章內(nèi)容簡介】
rvice routine. Once you get multitasking going, it?s quite simple to add your application tasks. Development Tools As previously stated, you need a C piler for the processor you intend to use in order to port 181。C/OSII. Because 181。C/OSII is a preemptive kernel, you should only use a C piler that generates reentrant code. Your C piler must also be able to support assembly language programming. Most C piler designed for embedded systems will, in fact, also include an assembler, a linker, and a locator. The linker is used to bine object files (piled and assembled files) from different modules while the locator will allow you to place the code and data anywhere in the memory map of the target processor. Your C piler must also provide a mechanism to disable and enable interrupts from C. Some pilers will allow you to insert inline assembly language statements in your C source code. This makes it quite easy to insert the proper processor instructions to enable and disable interrupts. Files (1) is a MASTER include file and is found at the top of all .C files as follows: include “” allows every .C file in your project to be written without concerns about which header file will actually be needed. The only drawback to having a master include file is that may include header files that are not pertinent to the actual .C file being piled. This means that each file will require extra time to pile. This inconvenience is offset by code portability. You can edit to add your own header files but, your header files should be added at the end of the list. (2) contains processor and implementation specific defines constants, macros, and typedefs. The general layout of is shown in listing ifdef OS_CPU_GLOBALS define OS_CPU_EXT else define OS_CPU_EXT extern endif typedef unsigned char BOOLEAN。 typedef unsigned char INT8U。 /* Unsigned 8 bit quantity*/ (1) typedef signed char INT8S。 /* Signed 8 bit quantity*/ typedef unsigned int INT16U。 /* Unsigned 16 bit quantity*/ typedef signed int INT16S。 /* Signed 16 bit quantity*/ typedef unsigned long INT32U。 /* Unsigned 32 bit quantity*/ typedef signed long INT32S。 /* Signed 32 bit quantity*/ typedef float FP32。 /*Single precision floating point*/ (2) typedef double FP64。 /* Double precision floating point */ typedef unsignedint OS_STK。 /*Each stack entryis 16bit wide*/ define OS_ENTER_CRITICAL() ??? /* Disable interrupts*/ (3) define OS_EXIT_CRITICAL() ??? /* Enable interrupts*/ define OS_STK_GROWTH 1 /* Define stack growth: 1 = Down, 0 = Up*/ (4) define OS_TASK_SW() ??? ① , Compiler Specific Data Types Because different microprocessors have different word length, the port of 181。C/OSII includes a series of type definitions that ensures portability. Specifically, 181。C/OSII?s code never makes use of C?s short, int and, long data types because they are inherently nonportable. Instead, I defined integer data types that are both portable and intuitive The INT16U data type, for example, always represents a 16bit unsigned integer. 181。C/OSII and your application code can now assume that the range of values for variables declared with this type is from 0 to 65535. A 181。C/OSII port to a 32bit processor could mean that an INT16U is actually declared as an unsigned short instead of an unsigned int. Where 181。C/OSII is concerned, however, it still deals with an INT16U. You must tell 181。C/OSII the data type of a task?s stack. This is done by declaring the proper C data type for OS_STK. If stack elements on your processor are 32bit and your piler documentation specify that an int is 32bit then, you would declare OS_STK as being of type unsigned int. All task stacks MUST be declared using OS_STK as its data type. All you have to do is to consult the piler?s manual and find the standard C data types that corresponds to the types expected by 181。C/OSII. ② , OS_ENTER_CRITICAL() and OS_EXIT_CRITICAL() 181。C/OSII like all realtime kernels need to disable interrupts in order to access critical sections of code, and reenable interrupts when done. This allows 181。C/OSII to protect critical code from being entered simultaneously from either multiple tasks or Interrupt Service Routines (ISRS). Every processor generally provide instructions to disable/enable interrupts and your C piler must have a mechanism to perform these operations directly from C. Some pilers will allow you to insert inline assembly language statements in your C source code. This makes it quite easy to insert processor instructions to enable and disable interrupts. Other pilers will actually contain language