📄 os_task.lst
字号:
185 3 OS_ENTER_CRITICAL();
186 3 OSTCBPrioTbl[prio] = (OS_TCB *)0;/* Make this priority available to others */
187 3 OS_EXIT_CRITICAL();
188 3 }
189 2 return (err);
190 2 }
191 1 OS_EXIT_CRITICAL();
192 1 return (OS_PRIO_EXIST);
193 1 }
194 #endif
195 /*$PAGE*/
196 /*
197 *********************************************************************************************************
198 * CREATE A TASK (Extended Version)
199 *
200 * Description: This function is used to have uC/OS-II manage the execution of a task. Tasks can either
201 * be created prior to the start of multitasking or by a running task. A task cannot be
202 * created by an ISR. This function is similar to OSTaskCreate() except that it allows
203 * additional information about a task to be specified.
204 *
205 * Arguments : task is a pointer to the task's code
206 *
207 * ppdata is a pointer to an optional data area which can be used to pass parameters to
208 * the task when the task first executes. Where the task is concerned it thinks
209 * it was invoked and passed the argument 'pdata' as follows:
210 *
211 * void Task (void *ppdata)
212 * {
213 * for (;;) {
214 * Task code;
215 * }
216 * }
217 *
218 * ptos is a pointer to the task's top of stack. If the configuration constant
219 * OS_STK_GROWTH is set to 1, the stack is assumed to grow downward (i.e. from high
220 * memory to low memory). 'pstk' will thus point to the highest (valid) memory
221 * location of the stack. If OS_STK_GROWTH is set to 0, 'pstk' will point to the
222 * lowest memory location of the stack and the stack will grow with increasing
223 * memory locations. 'pstk' MUST point to a valid 'free' data item.
224 *
225 * prio is the task's priority. A unique priority MUST be assigned to each task and the
226 * lower the number, the higher the priority.
227 *
228 * id is the task's ID (0..65535)
229 *
230 * pbos is a pointer to the task's bottom of stack. If the configuration constant
231 * OS_STK_GROWTH is set to 1, the stack is assumed to grow downward (i.e. from high
232 * memory to low memory). 'pbos' will thus point to the LOWEST (valid) memory
233 * location of the stack. If OS_STK_GROWTH is set to 0, 'pbos' will point to the
234 * HIGHEST memory location of the stack and the stack will grow with increasing
235 * memory locations. 'pbos' MUST point to a valid 'free' data item.
236 *
237 * stk_size is the size of the stack in number of elements. If OS_STK is set to INT8U,
238 * 'stk_size' corresponds to the number of bytes available. If OS_STK is set to
239 * INT16U, 'stk_size' contains the number of 16-bit entries available. Finally, if
C51 COMPILER V8.08 OS_TASK 08/19/2008 10:59:10 PAGE 5
240 * OS_STK is set to INT32U, 'stk_size' contains the number of 32-bit entries
241 * available on the stack.
242 *
243 * pext is a pointer to a user supplied memory location which is used as a TCB extension.
244 * For example, this user memory can hold the contents of floating-point registers
245 * during a context switch, the time each task takes to execute, the number of times
246 * the task has been switched-in, etc.
247 *
248 * opt contains additional information (or options) about the behavior of the task. The
249 * LOWER 8-bits are reserved by uC/OS-II while the upper 8 bits can be application
250 * specific. See OS_TASK_OPT_??? in uCOS-II.H.
251 *
252 * Returns : OS_NO_ERR if the function was successful.
253 * OS_PRIO_EXIT if the task priority already exist
254 * (each task MUST have a unique priority).
255 * OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed
256 * (i.e. > OS_LOWEST_PRIO)
257 *********************************************************************************************************
258 */
259 /*$PAGE*/
260 #if OS_TASK_CREATE_EXT_EN > 0
261 INT8U OSTaskCreateExt (void (*task)(void *pd) reentrant,
262 void *ppdata,
263 OS_STK *ptos,
264 INT8U prio,
265 INT16U id,
266 OS_STK *pbos,
267 INT32U stk_size,
268 void *pext,
269 INT16U opt) reentrant
270 {
271 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
274 1 OS_STK *psp;
275 1 INT8U err;
276 1
277 1
278 1 #if OS_ARG_CHK_EN > 0
279 1 if (prio > OS_LOWEST_PRIO) { /* Make sure priority is within allowable range */
280 2 return (OS_PRIO_INVALID);
281 2 }
282 1 #endif
283 1 OS_ENTER_CRITICAL();
284 1 if (OSTCBPrioTbl[prio] == (OS_TCB *)0) { /* Make sure task doesn't already exist at this priority */
285 2 OSTCBPrioTbl[prio] = (OS_TCB *)1; /* Reserve the priority to prevent others from doing ... */
*** WARNING C196 IN LINE 285 OF UCOSII\OS_TASK.C: mspace probably invalid
286 2 /* ... the same thing until task is created. */
287 2 OS_EXIT_CRITICAL();
288 2
289 2 if (((opt & OS_TASK_OPT_STK_CHK) != 0x0000) || /* See if stack checking has been enabled */
290 2 ((opt & OS_TASK_OPT_STK_CLR) != 0x0000)) { /* See if stack needs to be cleared */
291 3 #if OS_STK_GROWTH == 1
(void)memset(pbos, 0, stk_size * sizeof(OS_STK));
#else
294 3 (void)memset(ptos, 0, stk_size * sizeof(OS_STK));
295 3 #endif
296 3 }
297 2
298 2 psp = (OS_STK *)OSTaskStkInit(task, ppdata, ptos, opt); /* Initialize the task's stack */
299 2 err = OS_TCBInit(prio, psp, pbos, id, stk_size, pext, opt);
300 2 if (err == OS_NO_ERR) {
C51 COMPILER V8.08 OS_TASK 08/19/2008 10:59:10 PAGE 6
301 3 OS_ENTER_CRITICAL();
302 3 OSTaskCtr++; /* Increment the #tasks counter */
303 3 OS_EXIT_CRITICAL();
304 3 if (OSRunning == TRUE) { /* Find HPT if multitasking has started */
305 4 OS_Sched();
306 4 }
307 3 } else {
308 3 OS_ENTER_CRITICAL();
309 3 OSTCBPrioTbl[prio] = (OS_TCB *)0; /* Make this priority avail. to others */
310 3 OS_EXIT_CRITICAL();
311 3 }
312 2 return (err);
313 2 }
314 1 OS_EXIT_CRITICAL();
315 1 return (OS_PRIO_EXIST);
316 1 }
317 #endif
318 /*$PAGE*/
319 /*
320 *********************************************************************************************************
321 * DELETE A TASK
322 *
323 * Description: This function allows you to delete a task. The calling task can delete itself by
324 * its own priority number. The deleted task is returned to the dormant state and can be
325 * re-activated by creating the deleted task again.
326 *
327 * Arguments : prio is the priority of the task to delete. Note that you can explicitely delete
328 * the current task without knowing its priority level by setting 'prio' to
329 * OS_PRIO_SELF.
330 *
331 * Returns : OS_NO_ERR if the call is successful
332 * OS_TASK_DEL_IDLE if you attempted to delete uC/OS-II's idle task
333 * OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed
334 * (i.e. >= OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
335 * OS_TASK_DEL_ERR if the task you want to delete does not exist
336 * OS_TASK_DEL_ISR if you tried to delete a task from an ISR
337 *
338 * Notes : 1) To reduce interrupt latency, OSTaskDel() 'disables' the task:
339 * a) by making it not ready
340 * b) by removing it from any wait lists
341 * c) by preventing OSTimeTick() from making the task ready to run.
342 * The task can then be 'unlinked' from the miscellaneous structures in uC/OS-II.
343 * 2) The function OS_Dummy() is called after OS_EXIT_CRITICAL() because, on most processors,
344 * the next instruction following the enable interrupt instruction is ignored.
345 * 3) An ISR cannot delete a task.
346 * 4) The lock nesting counter is incremented because, for a brief instant, if the current
347 * task is being deleted, the current task would not be able to be rescheduled because it
348 * is removed from the ready list. Incrementing the nesting counter prevents another task
349 * from being schedule. This means that an ISR would return to the current task which is
350 * being deleted. The rest of the deletion would thus be able to be completed.
351 *********************************************************************************************************
352 */
353 /*$PAGE*/
354 #if OS_TASK_DEL_EN > 0
INT8U OSTaskDel (INT8U prio) reentrant
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
#if OS_EVENT_EN > 0
OS_EVENT *pevent;
C51 COMPILER V8.08 OS_TASK 08/19/2008 10:59:10 PAGE 7
#endif
#if (OS_VERSION >= 251) && (OS_FLAG_EN > 0) && (OS_MAX_FLAGS > 0)
OS_FLAG_NODE *pnode;
#endif
OS_TCB *ptcb;
if (OSIntNesting > 0) { /* See if trying to delete from ISR */
return (OS_TASK_DEL_ISR);
}
#if OS_ARG_CHK_EN > 0
if (prio == OS_IDLE_PRIO) { /* Not allowed to delete idle task */
return (OS_TASK_DEL_IDLE);
}
if (prio >= OS_LOWEST_PRIO && prio != OS_PRIO_SELF) { /* Task priority valid ? */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -