For the 8-bit microprocessors that have only 10 address lines, the chip can only access a maximum of 1Kb memory. For these processors it is difficult to port the uC/OS-II kernel.
5) Microprocessor has Stack Pointer and Other Instructions for Reading Registers and Store the
Contents of Register to Memory or Stack.
The ARM processor has STMFD instruction for pushing the content of registers to stack, LDMFD instruction for pulling the register contents back from stack..
3. uC/OS-II Porting Steps
1) Basic Configuration and Definition
All the basic configurations and definitions are in 0s_cup.h.
●Defines the data type related to compiler. In order to port uC/OS-II applications, there should be no int, unsigned int, etc definitions in the program. UC/OS has its own data type such as INT16U which represents 16-bit unsigned integer. For a 32-bit ARM processor, the INT16U is unsigned short. For a 16-bit ARM processor, the INT16U is unsigned int.
●Defines interrupt enable or disable.
●Defines stack growing direction. After defining the growing direction of stack, the value of OS_STK_GROWTH is defined.
●Define the micro OS_TASK_SW. OS_TASK_SW is a called when a uc/OS-II lower priority task is switched with higher priority task. There are two ways to define it. One way is by using software interrupt and make the interrupt vector to point to the OSCtxSw() function. Another way is to call the OSCrxSw() function directly.
2) Porting OS_CPU_A.ASM Assembly File
In the OS_CPU_A.ASM, there are four functions that need to be ported.
(1)OSStartHighRdy() function. This function is called by OSStart() function to start the highest priority task ready to run. OSStart() is responsible for setting the tasks in the ready status. The functions of this routine are described in the MicroC/OS-II book using pseudocode language. This pseudocode must be converted in ARM assembly language. OSStartHighRdy() function loads the stack pointer of the CPU with the top-of-stack pointer of the highest priority task. Restore all processor registers from the new task’s stack. Execute a return from interrupt instruction. Note that OSStartHighRdy() never returns to OSStart().
(2)OSCtxSw() function. This function is responsible for the context switch. OSCtxSw() is generally written in assembly language because most C compilers cannot manipulate CPU registers directly from C. This function is responsible for pushing the registers of the current task on the stack; changing the SP to the new stack value; restore the registers of the new task; execute and return from the interrupt instruction. This function is called by OS_TASK_SW which in turn is called by the OSSched() function. OSSched() function is responsible for scheduling the tasks.
(3)OSIntCtxSw() function. This function is called by OSIntExit() function to perform a context switch from an ISR. OSIntExit is called by OSTickISR() function. Because OSIntCtxSw() is called from an ISR, it is assumed that all the processor registers are already properly saved onto the interrupted task’s stack. OSIntCtxSw() function responds for switching the tasks in timer interruptions. The OSCtxSw() function and OSIntCtxSw() function are responsible for the switching between tasks. OSIntCtxSw() function is responsible for saving the current task pointer and recover the register values from the stack.