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