?? os_task.lst
字號:
197 * memory to low memory). 'pstk' will thus point to the highest (valid) memory
198 * location of the stack. If OS_STK_GROWTH is set to 0, 'pstk' will point to the
199 * lowest memory location of the stack and the stack will grow with increasing
200 * memory locations.
201 *
202 * prio is the task's priority. A unique priority MUST be assigned to each task and the
203 * lower the number, the higher the priority.
204 *
205 * Returns : OS_ERR_NONE if the function was successful.
206 * OS_PRIO_EXIT if the task priority already exist
207 * (each task MUST have a unique priority).
208 * OS_ERR_PRIO_INVALID if the priority you specify is higher that the maximum allowed
209 * (i.e. >= OS_LOWEST_PRIO)
210 * OS_ERR_TASK_CREATE_ISR if you tried to create a task from an ISR.
211 *********************************************************************************************************
212 */
213
214 #if OS_TASK_CREATE_EN > 0
215 INT8U OSTaskCreate (void (*task)(void *p_arg), void *p_arg, OS_STK *ptos, INT8U prio) reentrant
216 {
217 1 OS_STK *psp;
218 1 INT8U err;
219 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr = 0;
#endif
222 1
223 1
224 1
225 1 #if OS_ARG_CHK_EN > 0
if (prio > OS_LOWEST_PRIO) { /* Make sure priority is within allowable range */
return (OS_ERR_PRIO_INVALID);
}
#endif
230 1 OS_ENTER_CRITICAL();
231 1 if (OSIntNesting > 0) { /* Make sure we don't create the task from within an ISR */
232 2 OS_EXIT_CRITICAL();
233 2 return (OS_ERR_TASK_CREATE_ISR);
234 2 }
235 1 if (OSTCBPrioTbl[prio] == (OS_TCB *)0) { /* Make sure task doesn't already exist at this priority */
236 2 OSTCBPrioTbl[prio] = OS_TCB_RESERVED;/* Reserve the priority to prevent others from doing ... */
237 2 /* ... the same thing until task is created. */
238 2 OS_EXIT_CRITICAL();
C51 COMPILER V8.17 OS_TASK 03/26/2009 14:24:25 PAGE 5
239 2 psp = OSTaskStkInit(task, p_arg, ptos, 0); /* Initialize the task's stack */
240 2 err = OS_TCBInit(prio, psp, (OS_STK *)0, 0, 0, (void *)0, 0);
241 2 if (err == OS_ERR_NONE) {
242 3 if (OSRunning == OS_TRUE) { /* Find highest priority task if multitasking has started */
243 4 OS_Sched();
244 4 }
245 3 } else {
246 3 OS_ENTER_CRITICAL();
247 3 OSTCBPrioTbl[prio] = (OS_TCB *)0;/* Make this priority available to others */
248 3 OS_EXIT_CRITICAL();
249 3 }
250 2 return (err);
251 2 }
252 1 OS_EXIT_CRITICAL();
253 1 return (OS_ERR_PRIO_EXIST);
254 1 }
255 #endif
256 /*$PAGE*/
257 /*
258 *********************************************************************************************************
259 * CREATE A TASK (Extended Version)
260 *
261 * Description: This function is used to have uC/OS-II manage the execution of a task. Tasks can either
262 * be created prior to the start of multitasking or by a running task. A task cannot be
263 * created by an ISR. This function is similar to OSTaskCreate() except that it allows
264 * additional information about a task to be specified.
265 *
266 * Arguments : task is a pointer to the task's code
267 *
268 * p_arg is a pointer to an optional data area which can be used to pass parameters to
269 * the task when the task first executes. Where the task is concerned it thinks
270 * it was invoked and passed the argument 'p_arg' as follows:
271 *
272 * void Task (void *p_arg)
273 * {
274 * for (;;) {
275 * Task code;
276 * }
277 * }
278 *
279 * ptos is a pointer to the task's top of stack. If the configuration constant
280 * OS_STK_GROWTH is set to 1, the stack is assumed to grow downward (i.e. from high
281 * memory to low memory). 'ptos' will thus point to the highest (valid) memory
282 * location of the stack. If OS_STK_GROWTH is set to 0, 'ptos' will point to the
283 * lowest memory location of the stack and the stack will grow with increasing
284 * memory locations. 'ptos' MUST point to a valid 'free' data item.
285 *
286 * prio is the task's priority. A unique priority MUST be assigned to each task and the
287 * lower the number, the higher the priority.
288 *
289 * id is the task's ID (0..65535)
290 *
291 * pbos is a pointer to the task's bottom of stack. If the configuration constant
292 * OS_STK_GROWTH is set to 1, the stack is assumed to grow downward (i.e. from high
293 * memory to low memory). 'pbos' will thus point to the LOWEST (valid) memory
294 * location of the stack. If OS_STK_GROWTH is set to 0, 'pbos' will point to the
295 * HIGHEST memory location of the stack and the stack will grow with increasing
296 * memory locations. 'pbos' MUST point to a valid 'free' data item.
297 *
298 * stk_size is the size of the stack in number of elements. If OS_STK is set to INT8U,
299 * 'stk_size' corresponds to the number of bytes available. If OS_STK is set to
300 * INT16U, 'stk_size' contains the number of 16-bit entries available. Finally, if
C51 COMPILER V8.17 OS_TASK 03/26/2009 14:24:25 PAGE 6
301 * OS_STK is set to INT32U, 'stk_size' contains the number of 32-bit entries
302 * available on the stack.
303 *
304 * pext is a pointer to a user supplied memory location which is used as a TCB extension.
305 * For example, this user memory can hold the contents of floating-point registers
306 * during a context switch, the time each task takes to execute, the number of times
307 * the task has been switched-in, etc.
308 *
309 * opt contains additional information (or options) about the behavior of the task. The
310 * LOWER 8-bits are reserved by uC/OS-II while the upper 8 bits can be application
311 * specific. See OS_TASK_OPT_??? in uCOS-II.H. Current choices are:
312 *
313 * OS_TASK_OPT_STK_CHK Stack checking to be allowed for the task
314 * OS_TASK_OPT_STK_CLR Clear the stack when the task is created
315 * OS_TASK_OPT_SAVE_FP If the CPU has floating-point registers, save them
316 * during a context switch.
317 *
318 * Returns : OS_ERR_NONE if the function was successful.
319 * OS_PRIO_EXIT if the task priority already exist
320 * (each task MUST have a unique priority).
321 * OS_ERR_PRIO_INVALID if the priority you specify is higher that the maximum allowed
322 * (i.e. > OS_LOWEST_PRIO)
323 * OS_ERR_TASK_CREATE_ISR if you tried to create a task from an ISR.
324 *********************************************************************************************************
325 */
326 /*$PAGE*/
327 #if OS_TASK_CREATE_EXT_EN > 0
INT8U OSTaskCreateExt (void (*task)(void *p_arg),
void *p_arg,
OS_STK *ptos,
INT8U prio,
INT16U id,
OS_STK *pbos,
INT32U stk_size,
void *pext,
INT16U opt) reentrant
{
OS_STK *psp;
INT8U err;
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr = 0;
#endif
#if OS_ARG_CHK_EN > 0
if (prio > OS_LOWEST_PRIO) { /* Make sure priority is within allowable range */
return (OS_ERR_PRIO_INVALID);
}
#endif
OS_ENTER_CRITICAL();
if (OSIntNesting > 0) { /* Make sure we don't create the task from within an ISR */
OS_EXIT_CRITICAL();
return (OS_ERR_TASK_CREATE_ISR);
}
if (OSTCBPrioTbl[prio] == (OS_TCB *)0) { /* Make sure task doesn't already exist at this priority */
OSTCBPrioTbl[prio] = OS_TCB_RESERVED;/* Reserve the priority to prevent others from doing ... */
/* ... the same thing until task is created. */
OS_EXIT_CRITICAL();
#if (OS_TASK_STAT_STK_CHK_EN > 0)
OS_TaskStkClr(pbos, stk_size, opt); /* Clear the task stack (if needed) */
C51 COMPILER V8.17 OS_TASK 03/26/2009 14:24:25 PAGE 7
#endif
psp = OSTaskStkInit(task, p_arg, ptos, opt); /* Initialize the task's stack */
err = OS_TCBInit(prio, psp, pbos, id, stk_size, pext, opt);
if (err == OS_ERR_NONE) {
if (OSRunning == OS_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_ERR_PRIO_EXIST);
}
#endif
382 /*$PAGE*/
383 /*
384 *********************************************************************************************************
385 * DELETE A TASK
386 *
387 * Description: This function allows you to delete a task. The calling task can delete itself by
388 * its own priority number. The deleted task is returned to the dormant state and can be
389 * re-activated by creating the deleted task again.
390 *
391 * Arguments : prio is the priority of the task to delete. Note that you can explicitely delete
392 * the current task without knowing its priority level by setting 'prio' to
393 * OS_PRIO_SELF.
394 *
395 * Returns : OS_ERR_NONE if the call is successful
396 * OS_ERR_TASK_DEL_IDLE if you attempted to delete uC/OS-II's idle task
397 * OS_ERR_PRIO_INVALID if the priority you specify is higher that the maximum allowed
398 * (i.e. >= OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
399 * OS_ERR_TASK_DEL if the task is assigned to a Mutex PIP.
400 * OS_ERR_TASK_NOT_EXIST if the task you want to delete does not exist.
401 * OS_ERR_TASK_DEL_ISR if you tried to delete a task from an ISR
402 *
403 * Notes : 1) To reduce interrupt latency, OSTaskDel() 'disables' the task:
404 * a) by making it not ready
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -