微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > ARM学习笔记--初识uC/OS(一)

ARM学习笔记--初识uC/OS(一)

时间:11-10 来源:互联网 点击:

浮点数据,保存它们
*
* Returns : OS_ERR_NONE if the function was successful.
* OS_PRIO_EXIT if the task priority already exist
* (each task MUST have a unique priority).
* OS_ERR_PRIO_INVALID if the priority you specify is higher that the maximum allowed
* (i.e. > OS_LOWEST_PRIO)
* OS_ERR_TASK_CREATE_ISR if you tried to create a task from an ISR.
*
* 返回值 : OS_ERR_NONE 函数执行成功范围的内容
* OS_PRIO_EXIT 该任务的优先级已经存在返回该值
* (每个任务都有一个唯一的优先级).
* OS_ERR_PRIO_INVALID 设置的优先级大于最大的优先级别返回该值
* (即 > OS_LOWEST_PRIO)
* OS_ERR_TASK_CREATE_ISR 当在ISR中创建任务时返回该值(ISR中不允许进行任务创建)
*********************************************************************************************************
*/
/*$PAGE*/
#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)
{
OS_STK *psp;
INT8U err;
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
/* 分配CPU状态寄存器的存储 */
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 dont create the task from within an ISR */
/* 确保不在ISR中创建任务 */
OS_EXIT_CRITICAL();
return (OS_ERR_TASK_CREATE_ISR);
}
if (OSTCBPrioTbl[prio] == (OS_TCB *)0) { /* Make sure task doesnt 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) */
/* 清栈 (如需) */
#endif

psp = OSTaskStkInit(task, p_arg, ptos, opt); /* Initialize the tasks 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 */
/* 在多任务开始后发现HPT */
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

学习创建任务这个函数,我们就要了解的更多,首先必须对每一个传参要有所了解,在注释中我已经写清楚了;第二要知道我们在uC/OS中能创建最多64个进程,由于系统占用了4个还有4个备用,所以我们能创建的只有56个;第三也是最终要的,在任务中我们可以创建新的任务,但是在中断函数中绝不能创建新的任务,这将会引起未知错误。

再来看函数OSStart()

/*
*********************************************************************************************************
* START MULTITASKING
* 开始多任务运行
*
* Description: This function is used to start the multitasking process which lets uC/OS-II manages the
* task that you have created. Before you can call OSStart(), you MUST have called OSInit()
* and you MUST have created at least one task.
*
×描述:该函数用于开启你已经在uC/OS-II中创建的多任务进程.在调用该函数前,必须已经调用了OSInit()函
* 数和创建了至少一个进程.
×
* Arguments : none
*传参 :无
*
* Returns : none
*返回 : 无
*
* Note : OSStartHighRdy() MUST:
* a) Call OSTaskSwHook() then,
* b) Set OSRunning to OS_TRUE.
* c) Load the context of the task pointed to by OSTCBHighRdy.
* d_ Execute the task.
* 说明 : OSStartHighRdy() 函数必须使用:
* a) 然后调用函数OSTaskSwHook(),
* b) 设置 OSRunning为 OS_TRUE.
* c) 加载被OSTCBHighRdy指向的内容.
* d_ 运行任务
*********************************************************************************************************
*/

void OSStart (void)
{
if (OSRunning == OS_FALSE) {
OS_SchedNew(); /* Find highest prioritys task priority number */
OSPrioCur = OSPrioHighRdy;
OSTCBHighRdy = OSTCBPrioTbl[OSPrioHighRdy]; /* Point to highest priority task ready to run */
OSTCBCur = OSTCBHighRdy;
OSStartHighRdy(); /* Execute target specific code to start task */
}
}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top