µC/OS-II Quick Reference

This appendix provides a summary of the services provided by µC/OS-II assuming you enabled everything (I didn’t want to clutter this reference with conditional compilation statements). Of course, some of the services might not be included in your application depending on the contents of OS_CFG.H.

Miscellaneous

Function Prototypes:

void         OSInit(void);
void         OSIntEnter(void);
void         OSIntExit(void);
void         OSSchedLock(void);
void         OSSchedUnlock(void);
void         OSStart(void);
void         OSStatInit(void);
INT16U       OSVersion(void);

Macros:

OS_ENTER_CRITICAL()
OS_EXIT_CRITICAL()

Global Variables:

INT8S     OSCPUUsage                 // CPU usage in percent (%)
INT8U     OSIntNesting               // Interrupt nesting level (0..255)
INT8U     OSLockNesting              // OSSchedLock() nesting level.
BOOLEAN   OSRunning                  // Flag indicating multitasking running
INT8U     OSTaskCtr                  // Number of tasks created
OS_TCB   *OSTCBCur                   // Pointer to current task’s TCB
OS_TCB   *OSTCBHighRdy               // Pointer to highest priority task’s TCB
INT8U     OSTaskCtr                  // Number of tasks created

Task Management

Function Prototypes:

INT8U         OSTaskChangePrio(INT8U oldprio, INT8U newprio);

INT8U         OSTaskCreate(void   (*task)(void *pd), 
                           void    *pdata, 
                           OS_STK  *ptos, 
                           INT8U    prio);

INT8U         OSTaskCreateExt(void  (*task)(void *pd),
                              void   *pdata,
                              OS_STK *ptos,
                              INT8U   prio,
                              INT16U  id,
                              OS_STK *pbos,
                              INT32U  stk_size,
                              void   *pext,
                              INT16U  opt);

INT8U         OSTaskDel(INT8U prio);

INT8U         OSTaskDelReq(INT8U prio);

INT8U         OSTaskResume(INT8U prio);

INT8U         OSTaskSuspend(INT8U prio);

INT8U         OSTaskStkChk(INT8U prio, OS_STK_DATA *pdata);

INT8U         OSTaskQuery(INT8U prio, OS_TCB *pdata);

OSTaskCreateExt() ‘opt’ argument:

OS_TASK_OPT_STK_CHK          // Enable stack checking for the task               
OS_TASK_OPT_STK_CLR          // Clear the stack when the task is create          
OS_TASK_OPT_SAVE_FP          // Save Floating-Point registers

OSTaskDelReq() return values:

OS_NO_ERR                    // The request has been registered
OS_TASK_NOT_EXIST            // The task has been deleted
OS_TASK_DEL_IDLE             // Can’t delete the Idle task!
OS_PRIO_INVALID              // Invalid priority

OSTaskStkChk() data structure:

typedef struct {
    INT32U  OSFree;          // # of free bytes on the stack
    INT32U  OSUsed;          // # of bytes used on the stack
} OS_STK_DATA;

OSTaskQuery() data structure:

typedef struct os_tcb {

    OS_STK        *OSTCBStkPtr;        // Stack Pointer

    void          *OSTCBExtPtr;        // TCB extension pointer

    OS_STK        *OSTCBStkBottom;     // Ptr to bottom of stack
    INT32U         OSTCBStkSize;       // Size of task stack (#elements)

    INT16U         OSTCBOpt;           // Task options 

    INT16U         OSTCBId;            // Task ID (0..65535)

    struct os_tcb *OSTCBNext;          // Pointer to next     TCB 
    struct os_tcb *OSTCBPrev;          // Pointer to previous TCB 

    OS_EVENT      *OSTCBEventPtr;      // Pointer to ECB                               

    void          *OSTCBMsg;           // Message received 

    OS_FLAG_NODE  *OSTCBFlagNode;      // Pointer to event flag node
    OS_FLAGS       OSTCBFlagsRdy;      // Event flags that made task ready 

    INT16U         OSTCBDly;           // Nbr ticks to delay task or, timeout
    INT8U          OSTCBStat;          // Task status
    INT8U          OSTCBPrio;          // Task priority (0 == highest) 

    INT8U          OSTCBX;
    INT8U          OSTCBY;
    INT8U          OSTCBBitX;
    INT8U          OSTCBBitY;

    BOOLEAN        OSTCBDelReq;        // Flag to tell task to delete itself

} OS_TCB;

Time Management

Function Prototypes:

void          OSTimeDly(INT16U ticks);

INT8U         OSTimeDlyHMSM(INT8U  hours, 
                            INT8U  minutes, 
                            INT8U  seconds, 
                            INT16U milli);

INT8U         OSTimeDlyResume(INT8U prio);

INT32U        OSTimeGet(void);

void          OSTimeSet(INT32U ticks);

void          OSTimeTick(void);

Semaphore Management

Function Prototypes:

INT16U        OSSemAccept(OS_EVENT *pevent);

OS_EVENT     *OSSemCreate(INT16U cnt);

OS_EVENT     *OSSemDel(OS_EVENT *pevent, INT8U opt, INT8U *err);

void          OSSemPend(OS_EVENT *pevent, INT16U timeout, INT8U *err);

INT8U         OSSemPost(OS_EVENT *pevent);

INT8U         OSSemQuery(OS_EVENT *pevent, OS_SEM_DATA *pdata);

OSSemDel() ‘opt’ argument:

OS_DEL_NO_PEND                              // Delete only if no task pending
OS_DEL_ALWAYS                               // Always delete

OSSemQuery() data structure:

typedef struct {
    INT16U  OSCnt;                          // Semaphore count                                        
    INT8U   OSEventTbl[OS_EVENT_TBL_SIZE];  // Wait list
    INT8U   OSEventGrp;                     
} OS_SEM_DATA;

Mutual Exclusion Semaphore Management

Function Prototypes:

INT8U         OSMutexAccept(OS_EVENT *pevent, INT8U *err);
OS_EVENT     *OSMutexCreate(INT8U prio, INT8U *err);
OS_EVENT     *OSMutexDel(OS_EVENT *pevent, INT8U opt, INT8U *err);
void          OSMutexPend(OS_EVENT *pevent, INT16U timeout, INT8U *err);
INT8U         OSMutexPost(OS_EVENT *pevent);
INT8U         OSMutexQuery(OS_EVENT *pevent, OS_MUTEX_DATA *pdata);

OSMutexDel() ‘opt’ argument:

OS_DEL_NO_PEND                             // Delete only if no task pending
OS_DEL_ALWAYS                              // Always delete

OSMutexQuery() data structure:

typedef struct {
    INT8U   OSEventTbl[OS_EVENT_TBL_SIZE]; // Wait List
    INT8U   OSEventGrp;                     
    INT8U   OSValue;                       // Mutex value 
                                           //      (0=used, 1=available)
    INT8U   OSOwnerPrio;                   // Mutex owner's task priority 
    INT8U   OSMutexPIP;                    // Priority Inheritance Priority or
                                           //      0xFF if no owner   
} OS_MUTEX_DATA;

Event Flags Management

Function Prototypes:

OS_FLAGS      OSFlagAccept(OS_FLAG_GRP *pgrp, 
                           OS_FLAGS     flags, 
                           INT8U        wait_type, 
                           INT8U       *err);

OS_FLAG_GRP  *OSFlagCreate(OS_FLAGS     flags, 
                           INT8U       *err);

OS_FLAG_GRP  *OSFlagDel(OS_FLAG_GRP    *pgrp, 
                        INT8U           opt, 
                        INT8U          *err);

OS_FLAGS      OSFlagPend(OS_FLAG_GRP   *pgrp,
                         OS_FLAGS       flags,
                         INT8U          wait_type,
                         INT16U         timeout,
                         INT8U         *err);

OS_FLAGS      OSFlagPost(OS_FLAG_GRP   *pgrp, 
                         OS_FLAGS       flags, 
                         INT8U          operation, 
                         INT8U         *err);

OS_FLAGS      OSFlagQuery(OS_FLAG_GRP  *pgrp, 
                          INT8U        *err);

OSFlagDel() ‘opt’ argument:

OS_DEL_NO_PEND                             // Delete only if no task pending
OS_DEL_ALWAYS                              // Always delete

Message Mailbox Management

Function Prototypes:

void         *OSMboxAccept(OS_EVENT *pevent);

OS_EVENT     *OSMboxCreate(void *msg);

OS_EVENT     *OSMboxDel(OS_EVENT *pevent, INT8U opt, INT8U *err);

void         *OSMboxPend(OS_EVENT *pevent, INT16U timeout, INT8U *err);

INT8U         OSMboxPost(OS_EVENT *pevent, void *msg);

INT8U         OSMboxPostOpt(OS_EVENT *pevent, void *msg, INT8U opt);

INT8U         OSMboxQuery(OS_EVENT *pevent, OS_MBOX_DATA *pdata);

OSMboxDel() ‘opt’ argument:

OS_DEL_NO_PEND                             // Delete only if no task pending
OS_DEL_ALWAYS                              // Always delete

OSMboxPostOpt() ‘opt’ argument:

OS_POST_OPT_NONE                           // POST to a single waiting task 
                                           //    (Identical to OSMboxPost())
OS_POST_OPT_BROADCAST                      // POST to ALL waiting on mailbox

OSMboxQuery() data structure:

typedef struct {
    void   *OSMsg;                         // Pointer to message in mailbox                            
    INT8U   OSEventTbl[OS_EVENT_TBL_SIZE]; // Waiting List
    INT8U   OSEventGrp;                    
} OS_MBOX_DATA;

Message Queue Management

Function Prototypes:

void         *OSQAccept(OS_EVENT *pevent);
OS_EVENT     *OSQCreate(void **start, INT16U size);
OS_EVENT     *OSQDel(OS_EVENT *pevent, INT8U opt, INT8U *err);
INT8U         OSQFlush(OS_EVENT *pevent);
void         *OSQPend(OS_EVENT *pevent, INT16U timeout, INT8U *err);
INT8U         OSQPost(OS_EVENT *pevent, void *msg);
INT8U         OSQPostFront(OS_EVENT *pevent, void *msg);
INT8U         OSQPostOpt(OS_EVENT *pevent, void *msg, INT8U opt);
INT8U         OSQQuery(OS_EVENT *pevent, OS_Q_DATA *pdata);

OSQDel() ‘opt’ argument:

OS_DEL_NO_PEND                             // Delete only if no task pending
OS_DEL_ALWAYS                              // Always delete
OS_POST_OPT_FRONT                          // Simulate OSQPostFront()

OSQPostOpt() ‘opt’ argument:

OS_POST_OPT_NONE                           // POST to a single waiting task 
                                           //    (Identical to OSMboxPost())
OS_POST_OPT_BROADCAST                      // POST to ALL waiting on mailbox

OSQQuery() data structure:

typedef struct {
    void          *OSMsg;                          // Pointer to next message 
    INT16U         OSNMsgs;                        // # messages in queue                   
    INT16U         OSQSize;                        // Size of message queue
    INT8U          OSEventTbl[OS_EVENT_TBL_SIZE];  // Waiting List
    INT8U          OSEventGrp;
} OS_Q_DATA;

Memory Management

Function Prototypes:

OS_MEM       *OSMemCreate(void   *addr, 
                          INT32U  nblks, 
                          INT32U  blksize, 
                          INT8U  *err);
void         *OSMemGet(OS_MEM *pmem, INT8U *err);
INT8U         OSMemPut(OS_MEM *pmem, void *pblk);
INT8U         OSMemQuery(OS_MEM *pmem, OS_MEM_DATA *pdata);

OSMemQuery() data structure:

typedef struct {
    void   *OSAddr;              // Ptr to start of memory partition
    void   *OSFreeList;          // Ptr to start free list of memory blocks
    INT32U  OSBlkSize;           // Size (in bytes) of each memory block
    INT32U  OSNBlks;             // # blocks in the Partition
    INT32U  OSNFree;             // # free blocks
    INT32U  OSNUsed;             // # blocks used
} OS_MEM_DATA;