uC/OS-51 - Documentation

Author: Gianpaolo Macario <gianpi@geocities.com>
$Id: ucos51.htm,v 1.3 1997/07/14 13:19:55 gianpi Exp $


File Structure

Filename Description
includes.h Included by Test Programs
readme.txt Original documentation
by Jean Labrosse (was read.me)
test1.c Test Program #1 (MS-DOS)
test2.c Test Program #2 (MS-DOS)
ucos.c Target-independent
uC/OS Functions (Ansi C)
ucos.h Constants and prototypes
for ucos.c
ucos186a.asm Target-dependent (80x86)
uC/OS Functions (ASM-86)
ucos186c.c Target-dependent (80x86)
uC/OS Functions (Borland C)
ucos186c.h Constants and prototypes
for ucos186a.asm and ucos186c.c
ucos51.htm Documentation for uC/OS-51 (this file)
ucos51a.asm Target-dependent (8051)
uC/OS Functions (ASM-51)
ucos51c.c Target-dependent (8051)
uC/OS Functions (CC51)
ucos51c.h Constants and prototypes
for ucos51a.asm and ucos51c.c


uC/OS Limits

  1. Maximum number of tasks: 64
  2. Each task must have a different priority

uC/OS System Declarations

#define OS_LO_PRIO 63 /* IDLE task priority */ 

OS_Task_Status

#define OS_STAT_RDY  0x00 /* Ready to run */
#define OS_STAT_MBOX 0x01 /* Pending on mailbox */
#define OS_STAT_SEM  0x02 /* Pending on semaphore */
#define OS_STAT_Q    0x04 /* Pending on queue */ 
#define OS_STAT_RES1 0x08 /* Reserved */
#define OS_STAT_RES2 0x10 /* Reserved */
#define OS_STAT_RES3 0x20 /* Reserved */
#define OS_STAT_RES4 0x40 /* Reserved */
#define OS_STAT_RES5 0x80 /* Reserved */

OS_Error_Code

#define OS_NO_ERR      0 
#define OS_TIMEOUT    10 
#define OS_MBOX_FULL  20 
#define OS_Q_FULL     30
#define OS_PRIO_EXIST 40 
#define OS_SEM_ERR    50 
#define OS_SEM_OVF    51

uC/OS Task Control Block Data Structure

This structure must be accessed by assembler code as well (at least for OSTCBStkPtr), so OSTCBStkPtr must be allocated as the first field in structure.

typedef struct os_tcb {
    void          *OSTCBStkPtr;
    UBYTE          OSTCBStat;         /* According to OS_Task_Status */
    UBYTE          OSTCBPrio; 
    UWORD          OSTCBDly;          /* Delay in system ticks */
    struct os_tcb *OSTCBNext; 
    struct os_tcb *OSTCBPrev; 
} OS_TCB; 

Semaphore Data Structure

typedef struct os_sem {
    WORD  OSSemCnt; 
    UBYTE OSSemGrp; 
    UBYTE OSSemTbl[8]; 
} OS_SEM; 

Mailbox Data Structure

typedef struct os_mbox {
    void  *OSMboxMsg;
    UBYTE  OSMboxGrp; 
    UBYTE  OSMboxTbl[8]; 
} OS_MBOX;

Queue Data Structure

typedef struct os_q { 
    void **OSQStart; 
    void **OSQEnd; 
    void **OSQIn; 
    void **OSQOut; 
    UBYTE  OSQSize; 
    UBYTE  OSQEntries; 
    UBYTE  OSQGrp; 
    UBYTE  OSQTbl[8]; 
} OS_Q;

uC/OS Global Variables

extern BOOLEAN  OSRunning;            /* TRUE if a task is running             */
extern OS_TCB  *OSTCBCur;             /* Ptr to TCB of Current Running task    */
extern OS_TCB  *OSTCBHighRdy;         /* Ptr to TCB of Highest Priority Task   */
extern UBYTE    OSRdyGrp;             /* Bitmap with a 1 for each ready group  */
extern UBYTE    OSRdyTbl[];           /* Bitmap with a 1 for each ready Task   */
extern OS_TCB  *OSTCBPrioTbl[];       /* Priority Table (OS_MAX_PRIO elements) */
extern OS_TCB   OSTCBTbl[];           /* TCB Table (OS_MAX_TASKS elements)     */ 
extern OS_TCB  *OSTCBList;            /* List of Task Control Blocks           */
extern UBYTE    OSLockNesting;        /* Lock nesting level                    */ 
extern UBYTE    OSIntNesting;         /* Interrupt nesting level               */
extern OS_TCB  *OSTCBFreeList;        /* List of Free TCBs                     */
extern UBYTE _rom OSMapTbl[];         /* Table to quickly get...               */
extern UBYTE _rom OSUnMapTbl[];       /* ... the Highest Priority Task         */

uC/OS Macros

Invoke the Task Switcher

OS_TASK_SW()

Enter a critical region (disable interrupts)

OS_ENTER_CRITICAL()

Exit a critical region (enable interrupts)

OS_EXIT_CRITICAL()

uCOS Functions - Alphabetical

  1. OSChangePrio
  2. OSCtxSw
  3. OSInit
  4. OSIntCtxSw
  5. OSIntEnter
  6. OSIntExit
  7. OSLock
  8. OSMboxInit
  9. OSMboxPend
  10. OSMboxPost
  11. OSQInit
  12. OSQPend
  13. OSQPost
  14. OSSched
  15. OSSemInit
  16. OSSemPend
  17. OSSemPost
  18. OSStart
  19. OSStartHighRdy
  20. OSTCBGetFree
  21. OSTCBPutFree
  22. OSTaskCreate
  23. OSTaskDelete
  24. OSTickISR
  25. OSTimeDly
  26. OSTimeTick
  27. OSUnlock

uC/OS Function Descriptions

uC/OS Initialization

Start Multitasking

Create Task

Parameters:

Return OS_Error_Code

Delay Task 'n' Ticks (n = 1..65535)

Process System Tick

Enter ISR

Exit ISR

Perform a Context Switch (From task level)

Perform a Context Switch (From an ISR)

Handle Tick ISR

Run Highest Priority Task (Low-level)

Run Highest Priority Task

Get TCB From Free TCB List

Change Priority of Running Task

Delete Running Task

Prevent Scheduling

Enable Scheduling

Initialize Semaphore

Post to a Semaphore

Pend on Semaphore

Initialize Mailbox

Post to a Mailbox

Pend on Mailbox

Initialize Queue

Post to a Queue

Pend on a Queue

Put TCB To Free TCB List

Not implemented (coded in OSTaskDelete).



References