- •Preface
- •Introduction
- •1.01 INCLUDES.H
- •1.02 Compiler Independent Data Types
- •1.03 Global Variables
- •1.04 OS_ENTER_CRITICAL() and OS_EXIT_CRITICAL()
- •1.05 PC Based Services
- •1.05.01 PC Based Services, Character Based Display
- •1.05.02 PC Based Services, Elapsed Time Measurement
- •1.05.03 PC Based Services, Miscellaneous
- •1.07 Example #1
- •1.08 Example #2
- •1.09 Example #3
- •2.00 Foreground/Background Systems
- •2.01 Critical Section of Code
- •2.02 Resource
- •2.03 Shared Resource
- •2.04 Multitasking
- •2.05 Task
- •2.06 Context Switch (or Task Switch)
- •2.07 Kernel
- •2.08 Scheduler
- •2.09 Non-Preemptive Kernel
- •2.10 Preemptive Kernel
- •2.11 Reentrancy
- •2.12 Round Robin Scheduling
- •2.13 Task Priority
- •2.14 Static Priorities
- •2.15 Dynamic Priorities
- •2.16 Priority Inversions
- •2.17 Assigning Task Priorities
- •2.19 Mutual Exclusion
- •2.20 Deadlock (or Deadly Embrace)
- •2.21 Synchronization
- •2.22 Event Flags
- •2.23 Intertask Communication
- •2.24 Message Mailboxes
- •2.25 Message Queues
- •2.26 Interrupts
- •2.27 Interrupt Latency
- •2.28 Interrupt Response
- •2.29 Interrupt Recovery
- •2.30 Interrupt Latency, Response, and Recovery
- •2.31 ISR Processing Time
- •2.32 Non-Maskable Interrupts (NMIs)
- •2.33 Clock Tick
- •2.34 Memory Requirements
- •2.35 Advantages and Disadvantages of Real-Time Kernels
- •2.36 Real-Time Systems Summary
- •3.00 Critical Sections
- •3.01 Tasks
- •3.02 Task States
- •3.03 Task Control Blocks (OS_TCBs)
- •3.04 Ready List
- •3.05 Task Scheduling
- •3.06 Locking and Unlocking the Scheduler
- •3.07 Idle Task
- •3.08 Statistics Task
- •3.10 Clock Tick
- •3.14 OSEvent???() functions
- •4.00 Creating a Task, OSTaskCreate()
- •4.01 Creating a Task, OSTaskCreateExt()
- •4.02 Task Stacks
- •4.03 Stack Checking, OSTaskStkChk()
- •4.04 Deleting a Task, OSTaskDel()
- •4.05 Requesting to delete a task, OSTaskDelReq()
- •4.06 Changing a Task’s Priority, OSTaskChangePrio()
- •4.07 Suspending a Task, OSTaskSuspend()
- •4.08 Resuming a Task, OSTaskResume()
- •4.09 Getting Information about a Task, OSTaskQuery()
- •5.00 Delaying a task, OSTimeDly()
- •5.01 Delaying a task, OSTimeDlyHMSM()
- •5.02 Resuming a delayed task, OSTimeDlyResume()
- •5.03 System time, OSTimeGet() and OSTimeSet()
- •6.00 Event Control Blocks
- •6.01 Initializing an ECB, OSEventWaitListInit()
- •6.02 Making a task ready, OSEventTaskRdy()
- •6.03 Making a task wait for an event, OSEventTaskWait()
- •6.04 Making a task ready because of a timeout, OSEventTO()
- •6.05 Semaphores
- •6.06 Message Mailboxes
- •6.07 Message Queues
- •7.00 Memory Control Blocks
- •7.01 Creating a partition, OSMemCreate()
- •7.02 Obtaining a memory block, OSMemGet()
- •7.03 Returning a memory block, OSMemPut()
- •7.04 Obtaining status about memory partition, OSMemQuery()
- •7.05 Using memory partitions
- •7.06 Waiting for memory blocks from a partition
- •8.00 Development Tools
- •8.01 Directories and Files
- •8.02 INCLUDES.H
- •9.00 Development Tools
- •9.01 Directories and Files
- •9.02 INCLUDES.H
- •9.06 Memory requirements
- •9.07 Execution times
- •10.00 Directories and Files
- •10.01 INCLUDES.H
- •10.02.01 OS_CPU.H, Compiler specific data types
- •10.02.02 OS_CPU.H, OS_ENTER_CRITICAL() and OS_EXIT_CRITICAL()
- •10.02.03 OS_CPU.H, OS_STK_GROWTH
- •10.02.04 OS_CPU.H, OS_TASK_SW()
- •10.03.01 OS_CPU_A.ASM, OSStartHighRdy()
- •10.03.02 OS_CPU_A.ASM, OSCtxSw()
- •10.03.03 OS_CPU_A.ASM, OSIntCtxSw()
- •10.03.04 OS_CPU_A.ASM, OSTickISR()
- •10.04.01 OS_CPU_C.C, OSTaskStkInit()
- •10.04.02 OS_CPU_C.C, OSTaskCreateHook()
- •10.04.03 OS_CPU_C.C, OSTaskDelHook()
- •10.04.04 OS_CPU_C.C, OSTaskSwHook()
- •10.04.05 OS_CPU_C.C, OSTaskStatHook()
- •10.04.06 OS_CPU_C.C, OSTimeTickHook()
- •10.05 Summary
- •OSInit()
- •OSIntEnter()
- •OSIntExit()
- •OSMboxAccept()
- •OSMboxCreate()
- •OSMboxPend()
- •OSMboxPost()
- •OSMboxQuery()
- •OSMemCreate()
- •OSMemGet()
- •OSMemPut()
- •OSMemQuery()
- •OSQAccept()
- •OSQCreate()
- •OSQFlush()
- •OSQPend()
- •OSQPost()
- •OSQPostFront()
- •OSQQuery()
- •OSSchedLock()
- •OSSchedUnlock()
- •OSSemAccept()
- •OSSemCreate()
- •OSSemPend()
- •OSSemPost()
- •OSSemQuery()
- •OSStart()
- •OSStatInit()
- •OSTaskChangePrio()
- •OSTaskCreate()
- •OSTaskCreateExt()
- •OSTaskDel()
- •OSTaskDelReq()
- •OSTaskResume()
- •OSTaskStkChk()
- •OSTaskSuspend()
- •OSTaskQuery()
- •OSTimeDly()
- •OSTimeDlyHMSM()
- •OSTimeDlyResume()
- •OSTimeGet()
- •OSTimeSet()
- •OSTimeTick()
- •OSVersion()
10.05Summary
Table 10.3 provides a summary of the changes needed to bring a port for µC/OS towork with µC/OS-II. You should note that ‘processor_name.?’Is the name of the µC/OS file containing the port.
µC/OS |
µC/OS-II |
Processor_name.H |
OS_CPU.H |
Data types: |
Data types |
Change UBYTE to |
INT8U |
Change BYTE to |
INT8S |
Change UWORD to |
INT16U |
Change WORD to |
INT16S |
Change ULONG to |
INT32U |
Change LONG to |
INT32S |
Change OS_STK_TYPE to |
OS_STK |
OS_ENTER_CRITICAL( |
No change |
) |
|
OS_EXIT_CRITICAL() |
No change |
- |
Add OS_STK_GROWTH |
OS_TASK_SW() |
No change |
OS_FAR |
Define OS_FAR to nothing or, |
|
Remove all references to OS_FAR |
Processor_name.ASM |
OS_CPU_A.ASM |
OSStartHighRdy() |
Add call to OSTaskSwHook() |
|
Set OSRunning to 1 (8-bit) |
OSCtxSw() |
Add call to OSTaskSwHook() |
|
Copy OSPrioHighRdy to OSPrioCur (8-bit) |
OSIntCtxSw() |
Add call to OSTaskSwHook() |
|
Copy OSPrioHighRdy to OSPrioCur (8-bit) |
OSTickISR() |
No change |
Processor_name.C |
OS_CPU_C.C |
OSTaskCreate() |
Extract stack initialization code and put this code in a function called |
|
OSTaskStkInit(). |
- |
Add an empty function called OSTaskCreateHook(). |
- |
Add an empty function called OSTaskDelHook(). |
- |
Add an empty function called OSTaskSwHook(). |
- |
Add an empty function called OSTaskStatHook(). |
- |
Add an empty function called OSTimeTickHook(). |
Table 10.3, Summary of migrating a µC/OS port to µC/OS-II.
Chapter 11
Reference Manual
This chapter provides a user's guide to µC/OS-II services. Each of the user accessible kernel services is presented in alphabetical order and the following information is provided for each of the services:
1)A brief description
2)The function prototype
3)The file name where the source code is found
4)The #define constant needed to enable the code for the service
5)A description of the arguments passed to the function
6)A description of the return value(s)
7)Specific notes and warning on the usage of the service
8)One or two examples on how to use the function
OSInit()
void OSInit(void)
File |
Called from |
Code enabled by |
OS_CORE.C |
Startup code only |
N/A |
OSInit() is used to initialize µC/OS-II. OSInit() must be called prior to calling OSStart() which will actually start multitasking.
Arguments
NONE
Returned Value
NONE
Notes/Warnings
OSInit() must be called before OSStart().
|
Example |
|
|
void main (void) |
|
{ |
|
. |
|
. |
|
OSInit(); |
/* Initialize uC/OS-II */ |
. |
|
. |
|
OSStart(); |
/* Start Multitasking */ |
} |
|
OSIntEnter()
void OSIntEnter(void)
File |
Called from |
Code enabled by |
OS_CORE.C |
ISR only |
N/A |
OSIntEnter() is used to notify µC/OS-II that an ISR is being processed. This allows µC/OS-II to keep track of interrupt nesting. OSIntEnter() is used in conjunction with OSIntExit().
Arguments
NONE
Returned Value
NONE
Notes/Warnings
1)This function must not be called by task level code.
2)You can actually increment the interrupt nesting counter ( OSIntNesting) directly if your processor can perform this operation indivisibly. In other words, if your processor can perform a read-modify-write as an atomic operation then you don't need to call OSIntEnter() and instead, directly increment OSIntNesting. This would avoid the overhead associated with calling a function.
Example #1
(Intel 80x86, Real-Mode, Large Model)
Here we call OSIntEnter() because of backward compatibility with µC/OS. Also, you would do this if the processor you are using does not allow you to increment OSIntNesting using a single instruction.
ISRx |
PROC |
FAR |
|
|
|
PUSHA |
|
; Save interrupted task's context |
|
|
PUSH |
ES |
|
|
; |
PUSH |
DS |
|
|
MOV |
AX, DGROUP |
; Reload DS |
||
|
||||
; |
MOV |
DS, AX |
|
|
CALL |
FAR PTR _OSIntEnter ; Notify µC/OS-II of start of ISR |
|||
|
||||
|
. |
|
|
|
|
. |
|
|
|
|
POP |
DS |
; Restore processor registers |
|
|
POP |
ES |
|
|
|
POPA |
|
|
|
|
IRET |
|
; Return from interrupt |
|
ISRx |
ENDP |
|
|
Example #2
(Intel 80x86, Real-Mode, Large Model)
Here we increment OSIntNesting because the 80x86 allow you to perform this operation indivisibly.
ISRx PROC |
FAR |
|
PUSHA |
|
; Save interrupted task's context |
PUSH |
ES |
|
PUSH |
DS |
|
; |
|
|
MOV |
AX, DGROUP |
; Reload DS |
MOV |
DS, AX |
|
; |
|
|
INC |
BYTE PTR _OSIntNesting ; Notify µC/OS-II of start of ISR |
|
. |
|
|
.
.