
- •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()

OSSemAccept()
INT16U OSSemAccept(OS_EVENT *pevent);
File |
Called from |
Code enabled by |
OS_SEM.C |
Task or ISR |
OS_SEM_EN |
OSSemAccept() allows you to check to see if a resource is available or an event occurred. Unlike OSSemPend(), OSSemAccept() does not suspend the calling task if the resource is not available. You would use OSSemAccept() from an ISR to obtain the semaphore.
Arguments
pevent is a pointer to the semaphore that guards the resource. This pointer is returned to your application when the semaphore is created (see OSSemCreate()).
Returned Value
When the semaphore value is greater than 0 when OSSemAccept() is called then, the semaphore value is decremented and the value of the semaphore before the decrement is returned to your application. If, however, the semaphore value is 0 then, the resource is not available and 0 is returned to your application.
Notes/Warnings
Semaphores must be created before they are used.
Example
OS_EVENT *DispSem;
void Task (void *pdata)
{
INT16U value;
pdata = pdata; for (;;) {
value = OSSemAccept(DispSem); /* Check resource availability */
if (value > 0) { |
|
. |
/* Resource available, process */ |
. |
|
} |
|
. |
|
. |
|
} |
|
}
OSSemCreate()
OS_EVENT *OSSemCreate(WORD value);
File |
Called from |
Code enabled by |
OS_SEM.C |
Task or startup code |
OS_SEM_EN |
OSSemCreate() is used to create and initialize a semaphore. A semaphore is usedto:
1)Allow a task to synchronize with either an ISR or a task
2)Gain exclusive access to a resource
3)Signal the occurrence of an event
Arguments
value is the initial value of the semaphore. The initial value of the semaphore is allowed to be between 0 and 65535.
Returned Value
A pointer to the event control block allocated to the semaphore. If no event control block is available, OSSemCreate() will return a NULL pointer.
Notes/Warnings
Semaphores must be created before they are used.
Example
OS_EVENT *DispSem; |
|
|
void main(void) |
|
|
{ |
|
|
. |
|
|
. |
|
|
OSInit(); |
/* Initialize µC/OS-II |
*/ |
. |
|
|
. |
|
|
DispSem = OSSemCreate(1); |
/* Create Display Semaphore |
*/ |
. |
|
|
. |
|
|
OSStart(); |
/* Start Multitasking |
*/ |
} |
|
|
OSSemPend()
void OSSemPend(OS_EVENT *pevent, INT16U timeout, INT8U *err);
File |
Called from |
Code enabled by |

OS_SEM.C |
Task only |
OS_SEM_EN |
OSSemPend()is used when a task desires to get exclusive access to a resource, synchronize its activities with an ISR, a task or until an event occurs. If a task callsOSSemPend() and the value of the semaphore is greater than 0, then OSSemPend() will decrement the semaphore and return to its caller. However, if the value of the semaphore is equal to zero, OSSemPend() places the calling task in the waiting list for the semaphore. The task will thus wait until a task or an ISR signals the semaphore or, the specified timeout expires. If the semaphore is signaled before the timeout expires,
µC/OS-II will resume the highest priority task that is waiting for the semaphore. A pended task that has been suspended with OSTaskSuspend()can obtain the semaphore. The task will, however, remain suspended until the task is
resumed by calling OSTaskResume().
Arguments
pevent is a pointer to the semaphore. This pointer is returned to your application when the semaphore is created (see
OSSemCreate()).
timeout is used to allow the task to resume execution if a message is not received from the mailbox within the specified number of clock ticks. A timeout value of 0 indicates that the task desires to wait forever for the message. The maximum timeout is 65535 clock ticks. The timeout value is not synchronized with the clock tick. The timeout count starts being decremented on the next clock tick which could potentially occur immediately.
err is a pointer to a variable which will be used to hold an error code. OSSemPend() sets *err to either:
1)OS_NO_ERR, the semaphore is available
2)OS_TIMEOUT, the semaphore was not signaled within the specified timeout
3)OS_ERR_PEND_ISR, you called this function from an ISR and µC/OS-II would have to suspend the ISR. In general, you should not call OSMboxPend(). µC/OS-II checks for this situation in case you do anyway.
Returned Value
NONE
Notes/Warnings
Semaphores must be created before they are used.
Example
OS_EVENT *DispSem;
void DispTask(void *pdata)
{
INT8U err;
pdata = pdata; for (;;) {
.

.
OSSemPend(DispSem, 0, &err);
. |
/* |
The only way this task continues is if … */ |
|
. |
/* |
… the semaphore is signaled! |
*/ |
}
}
OSSemPost()
INT8U OSSemPost(OS_EVENT *pevent);
File |
Called from |
Code enabled by |
OS_SEM .C |
Task or ISR |
OS_SEM_EN |
A semaphore is signaled by calling OSSemPost(). If the semaphore value is greater than or equal to zero, the semaphore is incremented andOSSemPost() returns to its caller. If tasks are waiting for the semaphore to be signaled then, OSSemPost() removes the highest priority task pending (waiting) for the semaphore from the waiting list and makes this task ready to run. The scheduler is then called to determine if the awakened task is now the highest priority task ready to run.
Arguments
pevent is a pointer to the semaphore. This pointer is returned to your application when the semaphore is created (see
OSSemCreate()).
Returned Value
OSSemPost() returns one of these two error codes
1)OS_NO_ERR, if the semaphore was successfully signaled
2)OS_SEM_OVF, if the semaphore count overflowed
Notes/Warnings
Semaphores must be created before they are used.
Example
OS_EVENT *DispSem;
void TaskX(void *pdata)
{
INT8U err;
pdata = pdata; for (;;) {
.
.
err = OSSemPost(DispSem);