UCOS_III学习笔记(二)

来源:互联网 发布:centos 7 dracut 编辑:程序博客网 时间:2024/06/16 13:13

定时器

定时器是一个内核对象–通过对OS_CFG_TMR_EN置1,定时器服务才被启动。

Notes:UCOS_III不一定非要一个时钟节拍,对于一些低功耗的应用也不需要用到节拍,相应的,这时这些个低功耗应用也就不能使用那些关于时钟节拍的系统API


OS_TMR对象的定义

struct  os_tmr {#if OS_OBJ_TYPE_REQ > 0u       OS_OBJ_TYPE          Type;                           /*Used for checking if a  element which is of the correct type has been sent to the OSTmr???()*/ #endif#if OS_CFG_DBG_EN > 0u    CPU_CHAR            *NamePtr;                           /* Name to give the timer                                 */#endif    OS_TMR_CALLBACK_PTR  CallbackPtr;                       /* Function to call when timer expires                    */    void                *CallbackPtrArg;                    /* Argument to pass to function when timer expires        */    OS_TMR              *NextPtr;                           /* Double link list pointers   for a tmr list                           */    OS_TMR              *PrevPtr;    OS_TICK              Remain;                            /* Amount of time remaining before timer expires          */    OS_TICK              Dly;                               /* Delay before start of repeat                           */    OS_TICK              Period;                            /* Period to repeat timer                                 */    OS_OPT               Opt;                               /* Options (see OS_OPT_TMR_xxx)   sent to the OSTmrStart() as an argument                        */    OS_STATE             State;#if OS_CFG_DBG_EN > 0u    OS_TMR              *DbgPrevPtr;    OS_TMR              *DbgNextPtr;#endif};

Notes:
1)回调函数的执行是在定时器任务内完成的–要确保有足够的堆栈
2)回调函数执行的顺序依赖于其在定时器列表表中的位置
3)回调函数执行的时间大幅度影响了定时器任务的执行时间
4)回调函数不允许阻塞–影响定时器任务的执行时间
5)调用回调函数时,调度器是上了锁的,所以应该尽快结束执行回调函数


定时器列表

定时器列表与时钟节拍列表的工作机制非常相似

类比时钟节拍轮的数据结构,定时器列表中也存在一个OSCfg_TmrWheel[]的结构

表中的每一个条目有三个域–NbrEntriesMax,NbrEntries,FirstPtr

且FirstPtr指向的定时器链表也是已经排好序的

新建定时器向列表中的添加是,剩余时间较少的定时器排在表头,多的在后边

OS_TmrTask()执行的时候调度器是上了锁的

UC/OS允许用户创建任意数量的定时器(只受可用RAM大小的限制)