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

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

时间:11-10 来源:互联网 点击:
下面就直接进程序看吧,首先看mian函数

int main(void)
{
INT8U os_err;//OS error
Bsp_init();//Embedded development board Initialization//开发板初始化
OSInit();//uC/OS initialization//系统初始化
os_err = OSTaskCreateExt((void (*)(void *)) App_Task_LCD,//创建任务
(void * ) 0,
(OS_STK * )&App_TaskLCDStk[APP_TASK_LCD_STK_SIZE-1],
(INT8U ) APP_TASK_LCD_PRIO,
(INT16U ) APP_TASK_LCD_PRIO,
(OS_STK * )&App_TaskLCDStk[0],
(INT32U ) APP_TASK_LCD_STK_SIZE,
(void * ) 0,
(INT16U )(OS_TASK_OPT_STK_CLR | OS_TASK_OPT_STK_CHK));

OSStart(); //uC/OS start multitasking//开始任务运行
}

开发板的初始化就是对arm单片机的引脚和时钟等等运行必要条件进行初始化,这里就不看了,我们来看看OSInit()

/*
*********************************************************************************************************
* INITIALIZATION
* 初始化
*
* Description: This function is used to initialize the internals of uC/OS-II and MUST be called prior to
* creating any uC/OS-II object and, prior to calling OSStart().
× 描述:该函数用于uC/OS-II系统的内部初始化,它必须在调用uC/OS-II系统的任何创建对象之前,也必须在
* 函数OSStart()之前执行。也就是说使用uC/OS-II系统的第一步就是执行这个函数,这是一个约定。
*
* Arguments : none
× 传参 : 无
*
* Returns : none
× 返回值 : 无
*********************************************************************************************************
*/

void OSInit (void)
{
OSInitHookBegin(); /* Call port specific initialization code */

OS_InitMisc(); /* Initialize miscellaneous variables */

OS_InitRdyList(); /* Initialize the Ready List */

OS_InitTCBList(); /* Initialize the free list of OS_TCBs */

OS_InitEventList(); /* Initialize the free list of OS_EVENTs */

#if (OS_FLAG_EN > 0) && (OS_MAX_FLAGS > 0)
OS_FlagInit(); /* Initialize the event flag structures */
#endif

#if (OS_MEM_EN > 0) && (OS_MAX_MEM_PART > 0)
OS_MemInit(); /* Initialize the memory manager */
#endif

#if (OS_Q_EN > 0) && (OS_MAX_QS > 0)
OS_QInit(); /* Initialize the message queue structures */
#endif

OS_InitTaskIdle(); /* Create the Idle Task */
#if OS_TASK_STAT_EN > 0
OS_InitTaskStat(); /* Create the Statistic Task */
#endif

#if OS_TMR_EN > 0
OSTmr_Init(); /* Initialize the Timer Manager */
#endif

OSInitHookEnd(); /* Call port specific init. code */

#if OS_DEBUG_EN > 0
OSDebugInit();
#endif
}

我们学习的时候不用管这个函数里面到底执行了什么,但是我们必须要学会一点:知道这个函数是在使用uC/OS系统前的第一个需要调用的函数,只要知道这个我们就算知道怎么用它了。

看下一个函数OSTaskCreateExt

/*
*********************************************************************************************************
* CREATE A TASK (Extended Version)
* 创建任务(扩展版本)
*
* Description: This function is used to have uC/OS-II manage the execution of a task. Tasks can either
* be created prior to the start of multitasking or by a running task. A task cannot be
* created by an ISR. This function is similar to OSTaskCreate() except that it allows
* additional information about a task to be specified.
* 描述: 该函数用于创建一个 uC/OS-II管理的可执行任务.它不是在多个任务执行前被创建就是在一个运行
* 的任务中被创建.在中断服务函数中不能创建任务(也就是说在ISR中不能调用该函数). 除了该函数允许一
*个任务的附加信息被列出外,该函数类同于函数OSTaskCreate().
*
* Arguments : task is a pointer to the tasks code
*
* p_arg is a pointer to an optional data area which can be used to pass parameters to
* the task when the task first executes. Where the task is concerned it thinks
* it was invoked and passed the argument p_arg as follows:
*
* void Task (void *p_arg)
* {
* for (;;) {
* Task code;
* }
* }
*
* ptos is a pointer to the tasks top of stack. If the configuration constant
* OS_STK_GROWTH is set to 1, the stack is assumed to grow downward (i.e. from high
* memory to low memory). ptos will thus point to the highest (valid) memory
* location of the stack. If OS_STK_GROWTH is set to 0, ptos will point to the
* lowest memory location of the stack and the stack will grow with increasing
* memory locations. ptos MUST point to a valid free data item.
*
* prio is the tasks priority. A unique priority MUST be assigned to each task and the
* lower the number, the higher the priority.
*
* id is the tasks ID (0..65535)
*
* pbos is a pointer to the tasks bottom of stack. If the configuration constant
* OS_STK_GROWTH is set to 1, the stack is assumed to grow downward (i.e. from high
* memory to low memory). pbos will thus point to the LOWEST (valid) memory
* location of the stack. If OS_STK_GROWTH is set to 0, pbos will point to the
* HIGHEST memory location of the stack and the stack will grow with increasing
* memory locations. pbos MUST point to a valid free data item.
*
* stk_size is the size of the stack in number of elements. If OS_STK is set to INT8U,
* stk_size corresponds to the number of bytes available. If OS_STK is set to
* INT16U, stk_size contains the number of 16-bit entries available. Finally, if
* OS_STK is set to INT32U, stk_size contains the number of 32-bit entries
* available on the stack.
*
* pext is a pointer to a user supplied memory location which is used as a TCB extension.
* For example, this user memory can hold the contents of floating-point registers
* during a context switch, the time each task takes to execute, the number of times
* the task has been switched-in, etc.
*
* opt contains additional information (or options) about the behavior of the task. The
* LOWER 8-bits are reserved by uC/OS-II while the upper 8 bits can be application
* specific. See OS_TASK_OPT_??? in uCOS-II.H. Current choices are:
*
* OS_TASK_OPT_STK_CHK Stack checking to be allowed for the task
* OS_TASK_OPT_STK_CLR Clear the stack when the task is created
* OS_TASK_OPT_SAVE_FP If the CPU has floating-point registers, save them
* during a context switch.
* 传参:task 任务代码的一个指针(指向任务代码段)
*
* p_arg 当task第一次运行时,它代表指向一个用于向task传递参数的可选数据区域的指针.当task
* 在连接数据的时候,它被要求和像下面的例子这样传递参数p_arg :
*
* void Task (void *p_arg)
* {
* for (;;) {
* Task code;
* }
* }
*
* ptos 任务栈顶指针.假如OS_STK_GROWTH设置为1,则栈被认为是向低地址推移的(即从高存储到低
* 存储位置).栈顶指针将指向栈所在的存储器的最高位置.假如OS_STK_GROWTH设置为0,则栈被
* 认为是向高地址推移的(即从低存储到高存储位置).栈顶指针随内存增加增加. ptos一定指向
* 一个可用的空闲的数据项.
*
* prio 任务的优先级. 每个任务都必须有一个唯一的优先级.优先级数字越小,优先级别越高.
*
* id 任务的ID号(0..65535)
*
* pbos 任务的栈底指针. 假如OS_STK_GROWTH设置为1,则栈被认为是向低地址推移的(即从高存储到低
* 存储位置).栈底指针将指向栈所在的存储器的最低位置.假如OS_STK_GROWTH设置为0,则栈被
* 认为是向高地址推移的(即从低存储到高存储位置).栈底指针随内存增加增加. ptos一定指向
* 一个可用的空闲的数据项.
*
* stk_size 栈的长度.如果OS_STK设置为INT8U,stk_size则为字节数允许.若OS_STK设置为INT16U,stk_size则为十
* 六位数允许.最后若OS_STK设置为INT32U,stk_size则为32位二进制允许.(指明栈的宽度)
*
* pext 是一个指针,指向用户提供的用于TCB扩展部分的内存空间. 例如:通过上下文切换用户存储器能
* 保持住浮点寄存器的内容、每次任务运行的时间、任务被开关的次数等等.
*
* opt 包含任务行为的附加信息(或选项).低八位被uC/OS-II系统作为保留字.高八位作为特殊的应用.这个
* 选项的设置查看uCOS-II.H.中的OS_TASK_OPT_???.当前选项是:
* OS_TASK_OPT_STK_CHK 需要进行栈的检查
* OS_TASK_OPT_STK_CLR 任务创建时清除栈
* OS_TASK_OPT_SAVE_FP 假如处理器有

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

网站地图

Top