uc/os--OSTaskCreate

创建一个任务时,应该传入参数:入口函数,函数所需要的参数指针,函数对应的栈指针,优先级

INT8U OSTaskCreate (void (*task)(void *pd), void *ppdata, OS_STK *ptos, INT8U prio) reentrant
{
void *psp;
INT8U err;


if (prio > OS_LOWEST_PRIO) { /* Make sure priority is within allowable range */
return (OS_PRIO_INVALID);
}
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();

//初始化任务的栈,也就是初始化函数的栈
psp = (void *)OSTaskStkInit(task, ppdata, ptos, 0); /* Initialize the task's stack */

//初始化任务对应的TCB,也就是写任务的TCB结构体
err = OSTCBInit(prio, psp, (void *)0, 0, 0, (void *)0, 0);


if (err == OS_NO_ERR) {
OS_ENTER_CRITICAL();
OSTaskCtr++; /* Increment the #tasks counter */
OSTaskCreateHook(OSTCBPrioTbl[prio]); /* Call user defined hook */
OS_EXIT_CRITICAL();

//OSRunning:如果为真,表示系统已经初始化完毕,一旦创建任务,立马调用OSsched函数
//OSRunning:如果为假,表示系统正在初始化,创建任务后不调用OSSched函数
if (OSRunning) { /* Find highest priority task if multitasking has started */
OSSched();
}
} else {
OS_ENTER_CRITICAL();
OSTCBPrioTbl[prio] = (OS_TCB *)0;/* Make this priority available to others */
OS_EXIT_CRITICAL();
}
return (err);
} else {
OS_EXIT_CRITICAL();
return (OS_PRIO_EXIST);
}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值