📄 os_task.lst
字号:
198 1
199 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
204 1 OS_ENTER_CRITICAL();
205 1 if (OSIntNesting > 0) { /* Make sure we don't create the task from within an ISR */
206 2 OS_EXIT_CRITICAL();
207 2 return (OS_ERR_TASK_CREATE_ISR);
208 2 }
209 1 if (OSTCBPrioTbl[prio] == (OS_TCB *)0) { /* Make sure task doesn't already exist at this priority */
210 2 OSTCBPrioTbl[prio] = OS_TCB_RESERVED;/* Reserve the priority to prevent others from doing ... */
211 2 /* ... the same thing until task is created. */
212 2 OS_EXIT_CRITICAL();
213 2 psp = OSTaskStkInit(task, p_arg, ptos, 0); /* Initialize the task's stack */
*** WARNING C182 IN LINE 213 OF OS_TASK.C: pointer to different objects
214 2 err = OS_TCBInit(prio, psp, (OS_STK *)0, 0, 0, (void *)0, 0);
215 2 if (err == OS_ERR_NONE) {
216 3 if (OSRunning == OS_TRUE) { /* Find highest priority task if multitasking has started */
217 4 OS_Sched();
218 4 }
219 3 } else {
220 3 OS_ENTER_CRITICAL();
221 3 OSTCBPrioTbl[prio] = (OS_TCB *)0;/* Make this priority available to others */
222 3 OS_EXIT_CRITICAL();
223 3 }
224 2 return (err);
225 2 }
226 1 OS_EXIT_CRITICAL();
227 1 return (OS_ERR_PRIO_EXIST);
228 1 }
229 #endif
230 /*$PAGE*/
231 /*
232 *********************************************************************************************************
233 * CREATE A TASK (Extended Version)
234 *
235 * Description: This function is used to have uC/OS-II manage the execution of a task. Tasks can either
236 * be created prior to the start of multitasking or by a running task. A task cannot be
237 * created by an ISR. This function is similar to OSTaskCreate() except that it allows
238 * additional information about a task to be specified.
C51 COMPILER V7.50 OS_TASK 12/14/2007 08:25:42 PAGE 5
239 *
240 * Arguments : task is a pointer to the task's code
241 *
242 * p_arg is a pointer to an optional data area which can be used to pass parameters to
243 * the task when the task first executes. Where the task is concerned it thinks
244 * it was invoked and passed the argument 'p_arg' as follows:
245 *
246 * void Task (void *p_arg)
247 * {
248 * for (;;) {
249 * Task code;
250 * }
251 * }
252 *
253 * ptos is a pointer to the task's top of stack. If the configuration constant
254 * OS_STK_GROWTH is set to 1, the stack is assumed to grow downward (i.e. from high
255 * memory to low memory). 'ptos' will thus point to the highest (valid) memory
256 * location of the stack. If OS_STK_GROWTH is set to 0, 'ptos' will point to the
257 * lowest memory location of the stack and the stack will grow with increasing
258 * memory locations. 'ptos' MUST point to a valid 'free' data item.
259 *
260 * prio is the task's priority. A unique priority MUST be assigned to each task and the
261 * lower the number, the higher the priority.
262 *
263 * id is the task's ID (0..65535)
264 *
265 * pbos is a pointer to the task's bottom of stack. If the configuration constant
266 * OS_STK_GROWTH is set to 1, the stack is assumed to grow downward (i.e. from high
267 * memory to low memory). 'pbos' will thus point to the LOWEST (valid) memory
268 * location of the stack. If OS_STK_GROWTH is set to 0, 'pbos' will point to the
269 * HIGHEST memory location of the stack and the stack will grow with increasing
270 * memory locations. 'pbos' MUST point to a valid 'free' data item.
271 *
272 * stk_size is the size of the stack in number of elements. If OS_STK is set to INT8U,
273 * 'stk_size' corresponds to the number of bytes available. If OS_STK is set to
274 * INT16U, 'stk_size' contains the number of 16-bit entries available. Finally, if
275 * OS_STK is set to INT32U, 'stk_size' contains the number of 32-bit entries
276 * available on the stack.
277 *
278 * pext is a pointer to a user supplied memory location which is used as a TCB extension.
279 * For example, this user memory can hold the contents of floating-point registers
280 * during a context switch, the time each task takes to execute, the number of times
281 * the task has been switched-in, etc.
282 *
283 * opt contains additional information (or options) about the behavior of the task. The
284 * LOWER 8-bits are reserved by uC/OS-II while the upper 8 bits can be application
285 * specific. See OS_TASK_OPT_??? in uCOS-II.H. Current choices are:
286 *
287 * OS_TASK_OPT_STK_CHK Stack checking to be allowed for the task
288 * OS_TASK_OPT_STK_CLR Clear the stack when the task is created
289 * OS_TASK_OPT_SAVE_FP If the CPU has floating-point registers, save them
290 * during a context switch.
291 *
292 * Returns : OS_ERR_NONE if the function was successful.
293 * OS_PRIO_EXIT if the task priority already exist
294 * (each task MUST have a unique priority).
295 * OS_ERR_PRIO_INVALID if the priority you specify is higher that the maximum allowed
296 * (i.e. > OS_LOWEST_PRIO)
297 * OS_ERR_TASK_CREATE_ISR if you tried to create a task from an ISR.
298 *********************************************************************************************************
299 */
300 /*$PAGE*/
C51 COMPILER V7.50 OS_TASK 12/14/2007 08:25:42 PAGE 6
301 #if OS_TASK_CREATE_EXT_EN > 0
302 INT8U OSTaskCreateExt (void (*task)(void *p_arg),
303 void *p_arg,
304 OS_STK *ptos,
305 INT8U prio,
306 INT16U id,
307 OS_STK *pbos,
308 INT32U stk_size,
309 void *pext,
310 INT16U opt) reentrant
311 {
312 1 OS_STK *psp;
313 1 INT8U err;
314 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr = 0;
#endif
317 1
318 1
319 1
320 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
325 1 OS_ENTER_CRITICAL();
326 1 if (OSIntNesting > 0) { /* Make sure we don't create the task from within an ISR */
327 2 OS_EXIT_CRITICAL();
328 2 return (OS_ERR_TASK_CREATE_ISR);
329 2 }
330 1 if (OSTCBPrioTbl[prio] == (OS_TCB *)0) { /* Make sure task doesn't already exist at this priority */
331 2 OSTCBPrioTbl[prio] = OS_TCB_RESERVED;/* Reserve the priority to prevent others from doing ... */
332 2 /* ... the same thing until task is created. */
333 2 OS_EXIT_CRITICAL();
334 2
335 2 #if OS_TASK_STAT_STK_CHK_EN > 0
336 2 OS_TaskStkClr(pbos, stk_size, opt); /* Clear the task stack (if needed) */
337 2 #endif
338 2
339 2 psp = OSTaskStkInit(task, p_arg, ptos, opt); /* Initialize the task's stack */
*** WARNING C182 IN LINE 339 OF OS_TASK.C: pointer to different objects
340 2 err = OS_TCBInit(prio, psp, pbos, id, stk_size, pext, opt);
341 2 if (err == OS_ERR_NONE) {
342 3 if (OSRunning == OS_TRUE) { /* Find HPT if multitasking has started */
343 4 OS_Sched();
344 4 }
345 3 } else {
346 3 OS_ENTER_CRITICAL();
347 3 OSTCBPrioTbl[prio] = (OS_TCB *)0; /* Make this priority avail. to others */
348 3 OS_EXIT_CRITICAL();
349 3 }
350 2 return (err);
351 2 }
352 1 OS_EXIT_CRITICAL();
353 1 return (OS_ERR_PRIO_EXIST);
354 1 }
355 #endif
356 /*$PAGE*/
357 /*
358 *********************************************************************************************************
359 * DELETE A TASK
360 *
361 * Description: This function allows you to delete a task. The calling task can delete itself by
C51 COMPILER V7.50 OS_TASK 12/14/2007 08:25:42 PAGE 7
362 * its own priority number. The deleted task is returned to the dormant state and can be
363 * re-activated by creating the deleted task again.
364 *
365 * Arguments : prio is the priority of the task to delete. Note that you can explicitely delete
366 * the current task without knowing its priority level by setting 'prio' to
367 * OS_PRIO_SELF.
368 *
369 * Returns : OS_ERR_NONE if the call is successful
370 * OS_ERR_TASK_DEL_IDLE if you attempted to delete uC/OS-II's idle task
371 * OS_ERR_PRIO_INVALID if the priority you specify is higher that the maximum allowed
372 * (i.e. >= OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
373 * OS_ERR_TASK_DEL if the task is assigned to a Mutex PIP.
374 * OS_ERR_TASK_NOT_EXIST if the task you want to delete does not exist.
375 * OS_ERR_TASK_DEL_ISR if you tried to delete a task from an ISR
376 *
377 * Notes : 1) To reduce interrupt latency, OSTaskDel() 'disables' the task:
378 * a) by making it not ready
379 * b) by removing it from any wait lists
380 * c) by preventing OSTimeTick() from making the task ready to run.
381 * The task can then be 'unlinked' from the miscellaneous structures in uC/OS-II.
382 * 2) The function OS_Dummy() is called after OS_EXIT_CRITICAL() because, on most processors,
383 * the next instruction following the enable interrupt instruction is ignored.
384 * 3) An ISR cannot delete a task.
385 * 4) The lock nesting counter is incremented because, for a brief instant, if the current
386 * task is being deleted, the current task would not be able to be rescheduled because it
387 * is removed from the ready list. Incrementing the nesting counter prevents another task
388 * from being schedule. This means that an ISR would return to the current task which is
389 * being deleted. The rest of the deletion would thus be able to be completed.
390 *********************************************************************************************************
391 */
392 /*$PAGE*/
393 #if OS_TASK_DEL_EN > 0
394 INT8U OSTaskDel (INT8U prio) reentrant
395 {
396 1 #if OS_EVENT_EN
397 1 OS_EVENT *pevent;
398 1 #endif
399 1 #if (OS_FLAG_EN > 0) && (OS_MAX_FLAGS > 0)
OS_FLAG_NODE *pnode;
#endif
402 1 OS_TCB *ptcb;
403 1 INT8U y;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -