📄 os_core.lst
字号:
C51 COMPILER V7.10 OS_CORE 08/23/2004 01:45:17 PAGE 1
C51 COMPILER V7.10, COMPILATION OF MODULE OS_CORE
OBJECT MODULE PLACED IN OS_CORE.OBJ
COMPILER INVOKED BY: D:\keil51\C51\BIN\C51.EXE OS_CORE.C BROWSE DEBUG OBJECTEXTEND
line level source
1 /*
2 *********************************************************************************************************
3 * uC/OS-II
4 * The Real-Time Kernel
5 * CORE FUNCTIONS
6 *
7 * (c) Copyright 1992-1998, Jean J. Labrosse, Plantation, FL
8 * All Rights Reserved
9 *
10 * V2.00
11 *
12 * File : OS_CORE.C
13 * By : Jean J. Labrosse
14 *********************************************************************************************************
15 */
16
17 #ifndef OS_MASTER_FILE
18 #define OS_GLOBALS
19 #include "INCLUDES.H"
20 #endif
21
22 /*
23 *********************************************************************************************************
24 * LOCAL GLOBAL VARIABLES
25 *********************************************************************************************************
26 */
27
28 static INT8U OSIntExitY; /* Variable used by 'OSIntExit' to prevent using locals */
29
30 static OS_STK OSTaskIdleStk[OS_TASK_IDLE_STK_SIZE]; /* Idle task stack */
31
32 #if OS_TASK_STAT_EN
static OS_STK OSTaskStatStk[OS_TASK_STAT_STK_SIZE]; /* Statistics task stack */
#endif
35
36 static OS_TCB OSTCBTbl[OS_MAX_TASKS + OS_N_SYS_TASKS]; /* Table of TCBs */
37
38 /*$PAGE*/
39 /*
40 *********************************************************************************************************
41 * MAPPING TABLE TO MAP BIT POSITION TO BIT MASK
42 *
43 * Note: Index into table is desired bit position, 0..7
44 * Indexed value corresponds to bit mask
45 *********************************************************************************************************
46 */
47
48 INT8U const code OSMapTbl[] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
49
50 /*
51 *********************************************************************************************************
52 * PRIORITY RESOLUTION TABLE
53 *
54 * Note: Index into table is bit pattern to resolve highest priority
55 * Indexed value corresponds to highest priority bit position (i.e. 0..7)
C51 COMPILER V7.10 OS_CORE 08/23/2004 01:45:17 PAGE 2
56 *********************************************************************************************************
57 */
58
59 INT8U const code OSUnMapTbl[] = {
60 0, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
61 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
62 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
63 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
64 6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
65 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
66 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
67 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
68 7, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
69 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
70 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
71 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
72 6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
73 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
74 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
75 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0
76 };
77
78 /*$PAGE*/
79 /*
80 *********************************************************************************************************
81 * MAKE TASK READY TO RUN BASED ON EVENT OCCURING
82 *
83 * Description: This function is called by other uC/OS-II services and is used to ready a task that was
84 * waiting for an event to occur.
85 *
86 * Arguments : pevent is a pointer to the event control block corresponding to the event.
87 *
88 * msg is a pointer to a message. This pointer is used by message oriented services
89 * such as MAILBOXEs and QUEUEs. The pointer is not used when called by other
90 * service functions.
91 *
92 * msk is a mask that is used to clear the status byte of the TCB. For example,
93 * OSSemPost() will pass OS_STAT_SEM, OSMboxPost() will pass OS_STAT_MBOX etc.
94 *
95 * Returns : none
96 *
97 * Note : This function is INTERNAL to uC/OS-II and your application should not call it.
98 *********************************************************************************************************
99 */
100 #if (OS_Q_EN && (OS_MAX_QS >= 2)) || OS_MBOX_EN || OS_Sem_EN
101 void OSEventTaskRdy (OS_EVENT *pevent, void *msg, INT8U msk)reentrant
102 {
103 1 OS_TCB *ptcb;
104 1 INT8U x;
105 1 INT8U y;
106 1 INT8U bitx;
107 1 INT8U bity;
108 1 INT8U prio;
109 1
110 1
111 1 y = OSUnMapTbl[pevent->OSEventGrp]; /* Find highest prio. task waiting for message */
112 1 bity = OSMapTbl[y];
113 1 x = OSUnMapTbl[pevent->OSEventTbl[y]];
114 1 bitx = OSMapTbl[x];
115 1 prio = (INT8U)((y << 3) + x); /* Find priority of task getting the msg */
116 1 if ((pevent->OSEventTbl[y] &= ~bitx) == 0) { /* Remove this task from the waiting list */
117 2 pevent->OSEventGrp &= ~bity;
C51 COMPILER V7.10 OS_CORE 08/23/2004 01:45:17 PAGE 3
118 2 }
119 1 ptcb = OSTCBPrioTbl[prio]; /* Point to this task's OS_TCB */
120 1 ptcb->OSTCBDly = 0; /* Prevent OSTimeTick() from readying task */
121 1 ptcb->OSTCBEventPtr = (OS_EVENT *)0; /* Unlink ECB from this task */
122 1 #if (OS_Q_EN && (OS_MAX_QS >= 2)) || OS_MBOX_EN
ptcb->OSTCBMsg = msg; /* Send message directly to waiting task */
#else
125 1 msg = msg; /* Prevent compiler warning if not used */
-
126 1 #endif
127 1 ptcb->OSTCBStat &= ~msk; /* Clear bit associated with event type */
128 1 if (ptcb->OSTCBStat == OS_STAT_RDY) { /* See if task is ready (could be susp'd) */
129 2 OSRdyGrp |= bity; /* Put task in the ready to run list */
130 2 OSRdyTbl[y] |= bitx;
131 2 }
132 1 }
133 #endif
134 /*$PAGE*/
135 /*
136 *********************************************************************************************************
137 * MAKE TASK WAIT FOR EVENT TO OCCUR
138 *
139 * Description: This function is called by other uC/OS-II services to suspend a task because an event has
140 * not occurred.
141 *
142 * Arguments : pevent is a pointer to the event control block for which the task will be waiting for.
143 *
144 * Returns : none
145 *
146 * Note : This function is INTERNAL to uC/OS-II and your application should not call it.
147 *********************************************************************************************************
148 */
149 #if (OS_Q_EN && (OS_MAX_QS >= 2)) || OS_MBOX_EN || OS_Sem_EN
150 void OSEventTaskWait (OS_EVENT *pevent)reentrant
151 {
152 1 OSTCBCur->OSTCBEventPtr = pevent; /* Store pointer to event control block in TCB */
153 1 if ((OSRdyTbl[OSTCBCur->OSTCBY] &= ~OSTCBCur->OSTCBBitX) == 0) { /* Task no longer ready */
154 2 OSRdyGrp &= ~OSTCBCur->OSTCBBitY;
155 2 }
156 1 pevent->OSEventTbl[OSTCBCur->OSTCBY] |= OSTCBCur->OSTCBBitX; /* Put task in waiting list */
157 1 pevent->OSEventGrp |= OSTCBCur->OSTCBBitY;
158 1 }
159 #endif
160 /*$PAGE*/
161 /*
162 *********************************************************************************************************
163 * MAKE TASK READY TO RUN BASED ON EVENT TIMEOUT
164 *
165 * Description: This function is called by other uC/OS-II services to make a task ready to run because a
166 * timeout occurred.
167 *
168 * Arguments : pevent is a pointer to the event control block which is readying a task.
169 *
170 * Returns : none
171 *
172 * Note : This function is INTERNAL to uC/OS-II and your application should not call it.
173 *********************************************************************************************************
174 */
175 #if (OS_Q_EN && (OS_MAX_QS >= 2)) || OS_MBOX_EN || OS_Sem_EN
176 void OSEventTO (OS_EVENT *pevent)reentrant
177 {
178 1 if ((pevent->OSEventTbl[OSTCBCur->OSTCBY] &= ~OSTCBCur->OSTCBBitX) == 0) {
C51 COMPILER V7.10 OS_CORE 08/23/2004 01:45:17 PAGE 4
179 2 pevent->OSEventGrp &= ~OSTCBCur->OSTCBBitY;
180 2 }
181 1 OSTCBCur->OSTCBStat = OS_STAT_RDY; /* Set status to ready */
182 1 OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0; /* No longer waiting for event */
183 1 }
184 #endif
185 /*$PAGE*/
186 /*
187 *********************************************************************************************************
188 * INITIALIZE EVENT CONTROL BLOCK'S WAIT LIST
189 *
190 * Description: This function is called by other uC/OS-II services to initialize the event wait list.
191 *
192 * Arguments : pevent is a pointer to the event control block allocated to the event.
193 *
194 * Returns : none
195 *
196 * Note : This function is INTERNAL to uC/OS-II and your application should not call it.
197 *********************************************************************************************************
198 */
199 #if (OS_Q_EN && (OS_MAX_QS >= 2)) || OS_MBOX_EN || OS_Sem_EN
200 void OSEventWaitListInit (OS_EVENT *pevent)reentrant
201 {
202 1 INT8U i;
203 1
204 1
205 1 pevent->OSEventGrp = 0x00; /* No task waiting on event */
206 1 for (i = 0; i < OS_EVENT_TBL_SIZE; i++) {
207 2 pevent->OSEventTbl[i] = 0x00;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -