1、xilentz 的网络文摘博客园 首页 新随笔 联系 订阅 管理 随笔 - 204 文章 - 0 评论 - 10 trackbacks - 0 uCOS_II.H/* uC/OS-II* The Real-Time Kernel* (c) Copyright 1992-2002, Jean J. Labrosse, Weston, FL* All Rights Reserved* File : uCOS_II.H* By : Jean J. Labrosse*/ /* MISCELLANEOUS*/ #define OS_VERSION 252 /* Version of uC/OS-II (
2、Vx.yy mult. by 100) */ #ifdef OS_GLOBALS#define OS_EXT#else#define OS_EXT extern#endif #ifndef FALSE#define FALSE 0#endif #ifndef TRUE#define TRUE 1#endif #define OS_PRIO_SELF 0xFF /* Indicate SELF priority */ #if OS_TASK_STAT_EN 0#define OS_N_SYS_TASKS 2 /* Number of system tasks */#else#define OS_
3、N_SYS_TASKS 1#endif #define OS_STAT_PRIO (OS_LOWEST_PRIO - 1) /* Statistic task priority */#define OS_IDLE_PRIO (OS_LOWEST_PRIO) /* IDLE task priority */ #define OS_EVENT_TBL_SIZE (OS_LOWEST_PRIO) / 8 + 1) /* Size of event table */#define OS_RDY_TBL_SIZE (OS_LOWEST_PRIO) / 8 + 1) /* Size of ready ta
4、ble */ #define OS_TASK_IDLE_ID 65535 /* I.D. numbers for Idle and Stat tasks */#define OS_TASK_STAT_ID 65534 #define OS_EVENT_EN (OS_Q_EN 0) /* Type of event control block (see OS_EVENT_TYPE_?) */事件控制块类型(见 OS_EVENT_TYPE)INT8U OSEventGrp; /* Group corresponding to tasks waiting for event to occur */事
5、件群体响应去等待任务事件发生INT16U OSEventCnt; /* Semaphore Count (not used if other EVENT type) */信号量,在其它事件中不用void *OSEventPtr; /* Pointer to message or queue structure */消息或者队列结构指针INT8U OSEventTblOS_EVENT_TBL_SIZE; /* List of tasks waiting for event to occur */任务列表等待事件发生 OS_EVENT;#endif /* EVENT FLAGS CONTROL B
6、LOCK*/ #if (OS_VERSION = 251) /* Should be set to OS_EVENT_TYPE_FLAG */void *OSFlagWaitList; /* Pointer to first NODE of task waiting on event flag */OS_FLAGS OSFlagFlags; /* 8, 16 or 32 bit flags */ OS_FLAG_GRP; typedef struct /* Event Flag Wait List Node */void *OSFlagNodeNext; /* Pointer to next
7、NODE in wait list */void *OSFlagNodePrev; /* Pointer to previous NODE in wait list */void *OSFlagNodeTCB; /* Pointer to TCB of waiting task */ void *OSFlagNodeFlagGrp; /* Pointer to Event Flag Group */ OS_FLAGS OSFlagNodeFlags; /* Event flag to wait on */ INT8U OSFlagNodeWaitType; /* Type of wait: *
8、/* OS_FLAG_WAIT_AND */* OS_FLAG_WAIT_ALL */* OS_FLAG_WAIT_OR */* OS_FLAG_WAIT_ANY */ OS_FLAG_NODE;#endif /* MESSAGE MAILBOX DATA*/ #if OS_MBOX_EN 0typedef struct void *OSMsg; /* Pointer to message in mailbox */INT8U OSEventTblOS_EVENT_TBL_SIZE; /* List of tasks waiting for event to occur */INT8U OSE
9、ventGrp; /* Group corresponding to tasks waiting for event to occur */ OS_MBOX_DATA;#endif /* MEMORY PARTITION DATA STRUCTURES*/ #if (OS_MEM_EN 0) /* Pointer to beginning of memory partition */void *OSMemFreeList; /* Pointer to list of free memory blocks */INT32U OSMemBlkSize; /* Size (in bytes) of
10、each block of memory */INT32U OSMemNBlks; /* Total number of blocks in this partition */INT32U OSMemNFree; /* Number of memory blocks remaining in this partition */ OS_MEM; typedef struct void *OSAddr; /* Pointer to the beginning address of the memory partition */void *OSFreeList; /* Pointer to the
11、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 */ OS_MEM_DATA;#endif /*$PAGE*/ /*
12、MUTUAL EXCLUSION SEMAPHORE DATA*/ #if OS_MUTEX_EN 0typedef struct INT8U OSEventTblOS_EVENT_TBL_SIZE; /* List of tasks waiting for event to occur */INT8U OSEventGrp; /* Group corresponding to tasks waiting for event to occur */INT8U OSValue; /* Mutex value (0 = used, 1 = available) */INT8U OSOwnerPri
13、o; /* Mutex owners task priority or 0xFF if no owner */INT8U OSMutexPIP; /* Priority Inheritance Priority or 0xFF if no owner */ OS_MUTEX_DATA;#endif /* MESSAGE QUEUE DATA*/ #if OS_Q_EN 0typedef struct os_q /* QUEUE CONTROL BLOCK */struct os_q *OSQPtr; /* Link to next queue control block in list of
14、free blocks */void *OSQStart; /* Pointer to start of queue data */void *OSQEnd; /* Pointer to end of queue data */void *OSQIn; /* Pointer to where next message will be inserted in the Q */void *OSQOut; /* Pointer to where next message will be extracted from the Q */INT16U OSQSize; /* Size of queue (
15、maximum number of entries) */INT16U OSQEntries; /* Current number of entries in the queue */ OS_Q; typedef struct void *OSMsg; /* Pointer to next message to be extracted from queue */INT16U OSNMsgs; /* Number of messages in message queue */INT16U OSQSize; /* Size of message queue */INT8U OSEventTblO
16、S_EVENT_TBL_SIZE; /* List of tasks waiting for event to occur */INT8U OSEventGrp; /* Group corresponding to tasks waiting for event to occur */ OS_Q_DATA;#endif /* SEMAPHORE DATA*/ #if OS_SEM_EN 0typedef struct INT16U OSCnt; /* Semaphore count */INT8U OSEventTblOS_EVENT_TBL_SIZE; /* List of tasks wa
17、iting for event to occur */INT8U OSEventGrp; /* Group corresponding to tasks waiting for event to occur */ OS_SEM_DATA;#endif /* TASK STACK DATA*/ #if OS_TASK_CREATE_EXT_EN 0typedef struct INT32U OSFree; /* Number of free bytes on the stack */INT32U OSUsed; /* Number of bytes used on the stack */ OS
18、_STK_DATA;#endif /*$PAGE*/ /* TASK CONTROL BLOCK*/ typedef struct os_tcb OS_STK *OSTCBStkPtr; /* Pointer to current top of stack */OS_STK 为 unsigned int 指向当前堆顶部的指针 #if OS_TASK_CREATE_EXT_EN 0 / 使 OS_TASK_CREATE_EXT 中包含代码void *OSTCBExtPtr; /* Pointer to user definable data for TCB extension */用户定义用于
19、TCB 扩展的数据指针OS_STK *OSTCBStkBottom; /* Pointer to bottom of stack */堆底部指针INT32U OSTCBStkSize; /* Size of task stack (in number of stack elements) */任务堆栈大小INT16U OSTCBOpt; /* Task options as passed by OSTaskCreateExt() */由 OSTaskCreateExt() 传递的任务选项INT16U OSTCBId; /* Task ID (065535) */任务 ID#endif stru
20、ct os_tcb *OSTCBNext; /* Pointer to next TCB in the TCB list */在 TCB 列表中指向下一个 TCBstruct os_tcb *OSTCBPrev; /* Pointer to previous TCB in the TCB list */指向前一个 TCB #if (OS_Q_EN 0) /* Pointer to event control block */事件控制块指针#endif #if (OS_Q_EN 0) /* Message received from OSMboxPost() or OSQPost() */从邮箱
21、或者队列中接收消息#endif #if (OS_VERSION = 251) /* Pointer to event flag node */事件标志结点指针#endif OS_FLAGS OSTCBFlagsRdy; /* Event flags that made task ready to run */ OS_FLAGS 即为 unsigned int 任务就绪事件标志#endif INT16U OSTCBDly; /* Nbr ticks to delay task or, timeout waiting for event */延时任务或者等待任务时间溢出INT8U OSTCBSta
22、t; /* Task status */任务状态INT8U OSTCBPrio; /* Task priority (0 = highest, 63 = lowest) */任务优先级INT8U OSTCBX; /* Bit position in group corresponding to task priority (07) */在组中位的位置,与任务优先级对应INT8U OSTCBY; /* Index into ready table corresponding to task priority */与任务优先级对应的就绪列表索引INT8U OSTCBBitX; /* Bit mas
23、k to access bit position in ready table */在就绪列表中存取位位置的位掩码INT8U OSTCBBitY; /* Bit mask to access bit position in ready group */在就绪组中存取位位置的位掩码 #if OS_TASK_DEL_EN 0BOOLEAN OSTCBDelReq; /* Indicates whether a task needs to delete itself */#endif OS_TCB; /*$PAGE*/ /* GLOBAL VARIABLES*/ OS_EXT INT32U OSCt
24、xSwCtr; /* Counter of number of context switches */ #if (OS_EVENT_EN 0) /* Pointer to list of free EVENT control blocks */OS_EXT OS_EVENT OSEventTblOS_MAX_EVENTS;/* Table of EVENT control blocks */#endif #if (OS_VERSION = 251) /* Table containing event flag groups */OS_EXT OS_FLAG_GRP *OSFlagFreeLis
25、t; /* Pointer to free list of event flag groups */#endif #if OS_TASK_STAT_EN 0OS_EXT INT8S OSCPUUsage; /* Percentage of CPU used */OS_EXT INT32U OSIdleCtrMax; /* Max. value that idle ctr can take in 1 sec. */OS_EXT INT32U OSIdleCtrRun; /* Val. reached by idle ctr at run time in 1 sec. */OS_EXT BOOLE
26、AN OSStatRdy; /* Flag indicating that the statistic task is rdy */OS_EXT OS_STK OSTaskStatStkOS_TASK_STAT_STK_SIZE; /* Statistics task stack */#endif OS_EXT INT8U OSIntNesting; /* Interrupt nesting level */OS_EXT INT8U OSIntExitY; OS_EXT INT8U OSLockNesting; /* Multitasking lock nesting level */ OS_
27、EXT INT8U OSPrioCur; /* Priority of current task */OS_EXT INT8U OSPrioHighRdy; /* Priority of highest priority task */ OS_EXT INT8U OSRdyGrp; /* Ready list group */OS_EXT INT8U OSRdyTblOS_RDY_TBL_SIZE; /* Table of tasks which are ready to run */ OS_EXT BOOLEAN OSRunning; /* Flag indicating that kern
28、el is running */BOOLEAN 即:unsigned char ,OS_EXT 即为 extern OS_EXT INT8U OSTaskCtr; /* Number of tasks created */ OS_EXT volatile INT32U OSIdleCtr; /* Idle counter */ OS_EXT OS_STK OSTaskIdleStkOS_TASK_IDLE_STK_SIZE; /* Idle task stack */ OS_EXT OS_TCB *OSTCBCur; /* Pointer to currently running TCB */
29、OS_EXT OS_TCB *OSTCBFreeList; /* Pointer to list of free TCBs */OS_EXT OS_TCB *OSTCBHighRdy; /* Pointer to highest priority TCB R-to-R */OS_EXT OS_TCB *OSTCBList; /* Pointer to doubly linked list of TCBs */OS_EXT OS_TCB *OSTCBPrioTblOS_LOWEST_PRIO + 1;/* Table of pointers to created TCBs */OS_EXT OS
30、_TCB OSTCBTblOS_MAX_TASKS + OS_N_SYS_TASKS; /* Table of TCBs */ #if (OS_MEM_EN 0) /* Pointer to free list of memory partitions */OS_EXT OS_MEM OSMemTblOS_MAX_MEM_PART;/* Storage for memory partition manager */#endif #if (OS_Q_EN 0) /* Pointer to list of free QUEUE control blocks */OS_EXT OS_Q OSQTbl
31、OS_MAX_QS; /* Table of QUEUE control blocks */#endif #if OS_TIME_GET_SET_EN 0 OS_EXT volatile INT32U OSTime; /* Current value of system time (in ticks) */#endif extern INT8U const OSMapTbl; /* Priority-Bit Mask lookup table */extern INT8U const OSUnMapTbl; /* Priority-Index lookup table */ /*$PAGE*/
32、 /* FUNCTION PROTOTYPES* (Target Independent Functions)*/ /* EVENT FLAGS MANAGEMENT*/ #if (OS_VERSION = 251) #endif OS_FLAG_GRP *OSFlagCreate(OS_FLAGS flags, INT8U *err); #if OS_FLAG_DEL_EN 0OS_FLAG_GRP *OSFlagDel(OS_FLAG_GRP *pgrp, INT8U opt, INT8U *err);#endif 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); #if OS_FLAG_QUERY_EN 0