好文档 - 专业文书写作范文服务资料分享网站

实验一 ucos-ii源码结构分析

天下 分享 时间: 加入收藏 我要投稿 点赞

1

1、创建任务:

INT8U OSTaskCreate (void (*task)(void *p_arg), void *p_arg, OS_STK *ptos, INT8U prio) {

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_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)

/*task doesn't already exist at this

1

priority */ {

OSTCBPrioTbl[prio] = (OS_TCB *)1; /* Reserve the priority others from doing*/ OS_EXIT_CRITICAL();

psp = OSTaskStkInit(task, p_arg, ptos, 0); /* Initialize the task's stack */ // 初始化TCB

err = OS_TCBInit(prio, psp, (OS_STK *)0, 0, 0, (void *)0, 0); if (err == OS_NO_ERR) {

if (OSRunning == OS_TRUE) /* priority task if multitasking has started */ { OS_Sched(); } } else {

OS_ENTER_CRITICAL();

OSTCBPrioTbl[prio] = (OS_TCB *)0;/* this priority available to others OS_EXIT_CRITICAL(); }

return (err); }

OS_EXIT_CRITICAL(); return (OS_PRIO_EXIST);

1

} #endif

INT8U OSTaskDel (INT8U prio) {

#if OS_EVENT_EN

OS_EVENT *pevent; #endif

#if (OS_VERSION >= 251) && (OS_FLAG_EN > 0) && (OS_MAX_FLAGS > 0) OS_FLAG_NODE *pnode; #endif

OS_TCB *ptcb; INT8U y;

#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */ OS_CPU_SR cpu_sr = 0; #endif

if (OSIntNesting> 0) {

/* See if trying to delete from ISR

return (OS_TASK_DEL_ISR); }

if (prio == OS_TASK_IDLE_PRIO) {

/* Not allowed to delete idle task

1

return (OS_TASK_DEL_IDLE); }

#if OS_ARG_CHK_EN > 0

if (prio>= OS_LOWEST_PRIO)

{ if (prio != OS_PRIO_SELF) {

return (OS_PRIO_INVALID); } } #endif

OS_ENTER_CRITICAL(); if (prio == OS_PRIO_SELF)

*/

{

prio = OSTCBCur->OSTCBPrio; }

ptcb = OSTCBPrioTbl[prio]; if (ptcb == (OS_TCB *)0)

{ OS_EXIT_CRITICAL();

/* Task priority valid ?

/* See if requesting to delete self /* Set priority to delete to current */ /* Task to delete must exist

1

return (OS_TASK_NOT_EXIST); }

if (ptcb == (OS_TCB *)1)

/* Must not be assigned to Mutex

{ OS_EXIT_CRITICAL(); return (OS_TASK_DEL_ERR); }

y = ptcb->OSTCBY; OSRdyTbl[y] &= ~ptcb->OSTCBBitX; if (OSRdyTbl[y] == 0)

/* Make task not ready

{ OSRdyGrp&= ~ptcb->OSTCBBitY; } // 移除 #if OS_EVENT_EN

pevent = ptcb->OSTCBEventPtr;

/* If task is waiting on event

if (pevent != (OS_EVENT *)0) {

pevent->OSEventTbl[y] &= ~ptcb->OSTCBBitX; if (pevent->OSEventTbl[y] == 0) {

pevent->OSEventGrp&= ~ptcb->OSTCBBitY; /* ... event ctrl block

/* ... remove task from ...

实验一 ucos-ii源码结构分析

11、创建任务:INT8UOSTaskCreate(void(*task)(void*p_arg),void*p_arg,OS_STK*ptos,INT8Uprio){OS_STK*psp;INT8Uerr;#ifOS_CRITICAL_METHOD==3/
推荐度:
点击下载文档文档为doc格式
61tqv4197u8qp2012imx4yj364q360011m6
领取福利

微信扫码领取福利

微信扫码分享