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

OSMemPut()
INT8U OSMemPut(OS_MEM *pmem, void *pblk);
File |
Called from |
Code enabled by |
OS_MEM.C |
Task or ISR |
OS_MEM_EN |
OSMemPut() is used to return a memory block to a memory partition. It is assumed that you will return the memory block to the appropriate memory partition.
Arguments
pmem is a pointer to the memory partition control block that was returned to your application from the OSMemCreate() call.
pblk is a pointer to the memory block to return back to the memory partition.
Returned Value
OSMemPut() returns one of the following error codes:
1)OS_NO_ERR, if a memory block was available and returned to your application.
2)OS_MEM_FULL, if the memory partition cannot accept any more memory blocks. This is surely an indication
that something went wrong as you returned more memory blocks that you obtained using OSMemGet().
Notes/Warnings
Memory partitions must be created before they are used.
Example
OS_MEM *CommMem;
INT8U *CommMsg;
void Task (void *pdata)
{
INT8U err; |
|
|
pdata = pdata; |
|
|
for (;;) { |
|
|
err = OSMemPut(CommMem, (void *)CommMsg); |
|
|
if (err == OS_NO_ERR) { |
|
|
. |
/* Memory block released |
*/ |
. |
|
|
} |
|
|
.
.
}

}
OSMemQuery()
INT8U OSMemQuery(OS_MEM *pmem, OS_MEM_DATA *pdata);
File |
Called from |
Code enabled by |
OS_MEM.C |
Task or ISR |
OS_MEM_EN |
OSMemQuery() is used to obtain information about a memory partition. Basically, this function returns the same information found in the OS_MEM data structure but, in a new data structure called OS_MEM_DATA. OS_MEM_DATA also contains an additional field that indicates the number of memory blocks in use.
Arguments
pmem is a pointer to the memory partition control block that was returned to your application from the OSMemCreate() call.
pdata is a pointer to a data structure of type OS_MEM_DATA which contains the following fields:
void |
*OSAddr; |
/* Points to beginning address of the memory partition |
*/ |
void |
*OSFreeList; /* Points to beginning of the free list of memory blocks*/ |
||
INT32U |
OSBlkSize; |
/* Size (in bytes) of each memory block |
*/ |
INT32U |
OSNBlks; |
/* Total number of blocks in the partition |
*/ |
INT32U |
OSNFree; |
/* Number of memory blocks free |
*/ |
INT32U |
OSNUsed; |
/* Number of memory blocks used |
*/ |
Returned Value
OSMemQuery() always returns OS_NO_ERR.
Notes/Warnings
Memory partitions must be created before they are used.
Example
OS_MEM *CommMem;
OS_MEM_DATA mem_data;
void Task (void *pdata)
{
INT8U err;
pdata = pdata; for (;;) {
.
.

err = OSMemQuery(CommMem, &mem_data);
.
.
}
}
OSQAccept()
void *OSQAccept(OS_EVENT *pevent);
File |
Called from |
Code enabled by |
OS_Q.C |
Task or ISR |
OS_Q_EN |
OSQAccept() allows you to check to see if a message is available from the desired message queue. Unlike OSQPend(),OSQAccept() does not suspend the calling task if a message is not available. If a message is available, the message will be returned to your application and the message will be extracted from the queue. This call is typically used by ISRs because an ISR is not allowed to wait for messages at a queue.
Arguments
pevent is a pointer to the message queue where the message is to be received from. This pointer is returned to your application when the message queue is created (see OSQCreate()).
Returned Value
A pointer to the message if one is available or, NULL if the message queue does not contain a message.
Notes/Warnings
Message queues must be created before they are used.
Example
OS_EVENT *CommQ; |
|
|
void Task (void *pdata) |
|
|
{ |
|
|
void *msg; |
|
|
pdata = pdata; |
|
|
for (;;) { |
|
|
msg = OSQAccept(CommQ); |
/* Check queue for a message |
*/ |
if (msg != (void *)0) { |
|
|
. |
/* Message received, process |
*/ |
. |
|
|
} else { |
|
|
. |
/* Message not received, do .. */ |

. |
/* .. something else |
*/ |
} |
|
|
. |
|
|
. |
|
|
}
}
OSQCreate()
OS_EVENT *OSQCreate(void **start, INT8U size);
File |
Called from |
Code enabled by |
OS_Q.C |
Task or startup code |
OS_Q_EN |
OSQCreate() is used to create a message queue. A message queue is used to allow tasks or ISRs to send pointer sized variables (messages) to one or more tasks. The meaning of the messages sent are application specific.
Arguments
start is the base address of the message storage area. A message s torage area is declared as an array of pointers to voids.
size is the size (in number of entries) of the message storage area.
Returned Value
OSQCreate() returns a pointer to the event control block allocated to the queue. If no event control block is available, OSQCreate() will return a NULL pointer.
Notes/Warnings
Queues must be created before they are used.
Example
OS_EVENT *CommQ; |
|
|
|
void |
*CommMsg[10]; |
|
|
void main(void) |
|
|
|
{ |
OSInit(); |
/* Initialize µC/OS-II |
*/ |
|
|||
|
. |
|
|
|
. |
|
|
CommQ = OSQCreate(&CommMsg[0], 10); /* Create COMM Q |
*/ |
||
|
. |
|
|
|
. |
|
|
} |
OSStart(); |
/* Start Multitasking |
*/ |
|
|
|