uC/OS-II 移植 内核系统裁剪os_cfg.h

 
 

系统可裁剪,就是对系统的功能打开和关闭,用到的功能就打开,不用的就关闭(ENABLE& DISABLE),这个文件就在os_cfg.h中。

os_cfg.h文件位于工程uC/OS-II CONFIG结构下面。

该文件中重要的几个宏定义:

1、最低优先级OS_LOWEST_PRIO

这个与配置任务优先级有关,最低优先级任务配置的最大值。

任务优先级的关系:优先级越小,数值越大;优先级越大,数值越小。

位于os_cfg.h文件第39行:

#define OS_LOWEST_PRIO           63u   /* Defines the lowest priority that can be assigned ...         */


2.系统每秒滴答数OS_TICKS_PER_SEC

意思:系统每秒时钟滴答多少次。它与系统延时(OSTimeDly)关系比较重要,项目中该值等于10000(100us),

调用OSTimeDly(100),相当于延时100个滴答时间,即10ms。

位于os_cfg.h文件第51行:

#define OS_TICKS_PER_SEC      10000u   /* Set the number of ticks in one second                      */


3.任务堆栈大小OS_TASK_XXX_STK_SIZE

这几个宏定义在使用相应功能时有用,如果RAM资源有限,这个任务堆栈的大小最好根据任务来评估一下,

资源有限不能太大,太小程序不能正常运行。

位于os_cfg.h文件第54--57行:      

                                 /* --------------------- TASK STACK SIZE ---------------------- */
#define OS_TASK_TMR_STK_SIZE    128u   /* Timer      task stack size (# of OS_STK wide entries)        */
#define OS_TASK_STAT_STK_SIZE   128u   /* Statistics task stack size (# of OS_STK wide entries)        */
#define OS_TASK_IDLE_STK_SIZE   128u   /* Idle       task stack size (# of OS_STK wide entries)        */

4.其它内核事件开关

与系统其它资源相关的配置,正常情况下需要使用的时候开启,不用尽量关闭。一是节约资源,二是减少编译时间。

源码注解:

1.各项参数

                                       /* ---------------------- MISCELLANEOUS ----------------------- */
#define OS_APP_HOOKS_EN           0u   /* Application-defined hooks are called from the uC/OS-II hooks使能APP应用HOOK函数*/
#define OS_ARG_CHK_EN             0u   /* Enable (1) or Disable (0) argument checking  参数检查    */
#define OS_CPU_HOOKS_EN           1u   /* uC/OS-II hooks are found in the processor port files使能OS_CPU HOOK函数*/


#define OS_DEBUG_EN               0u   /* Enable(1) debug variables 使能系统调试功能                    */


#define OS_EVENT_MULTI_EN         0u   /* Include code for OSEventPendMulti()使用OSEventPendMulti()函数 */
#define OS_EVENT_NAME_EN          0u   /* Enable names for Sem, Mutex, Mbox and Q使能事件(Sem,Mutex,Mbox and Q)名称*/


#define OS_LOWEST_PRIO           63u   /* Defines the lowest priority that can be assigned ... 定义最低优先级(值)        */
                                       /* ... MUST NEVER be higher than 254!必须小于254                 */

#define OS_MAX_EVENTS            10u   /* Max. number of event control blocks in your application事件控制块的最大数(应用程序中)*/
#define OS_MAX_FLAGS              5u   /* Max. number of Event Flag Groups in your application事件标志组的最大数(应用程序中)   */
#define OS_MAX_MEM_PART           0u   /* Max. number of memory partitions 内存分区最大数                            */
#define OS_MAX_QS                 5u   /* Max. number of queue control blocks in your application队列控制块的最大数(应用程序中)*/
#define OS_MAX_TASKS             20u   /* Max. number of tasks in your application, MUST be >= 2应用程序(任务)最大数       */
/*使用OSSchedLock()和OSSchedUnLock()函数*/
#define OS_SCHED_LOCK_EN          1u   /* Include code for OSSchedLock() and OSSchedUnlock()           */


#define OS_TICK_STEP_EN           1u   /* Enable tick stepping feature for uC/OS-View使能tickstepping  */
#define OS_TICKS_PER_SEC       10000u   /* Set the number of ticks in one second 每秒滴答数                     */

HOOKS函数是os_cpu_c.c里面相关的函数,这里OS_CPU_HOOKS_EN被系统调用,将其定义为使能。

OS_DEBUG_EN 系统自带的调试功能,不使用就失能。


2.任务堆栈大小

                                       /* --------------------- TASK STACK SIZE任务堆栈大小 ---------------------- */
#define OS_TASK_TMR_STK_SIZE    128u   /* Timer      task stack size (# of OS_STK wide entries)        */
#define OS_TASK_STAT_STK_SIZE   128u   /* Statistics task stack size (# of OS_STK wide entries)        */
#define OS_TASK_IDLE_STK_SIZE   128u   /* Idle       task stack size (# of OS_STK wide entries)        */

和自己建立任务时建立任务堆栈差不多的意思。


3.任务管理

                                       /* --------------------- TASK MANAGEMENT 任务管理---------------------- */
#define OS_TASK_CHANGE_PRIO_EN    1u   /*     Include code for OSTaskChangePrio() 任务优先级切换                */
#define OS_TASK_CREATE_EN         1u   /*     Include code for OSTaskCreate() 创建任务                         */
#define OS_TASK_CREATE_EXT_EN     1u   /*     Include code for OSTaskCreateExt()创建扩展版本任务               */
#define OS_TASK_DEL_EN            1u   /*     Include code for OSTaskDel()  删除任务                           */
#define OS_TASK_NAME_EN           1u   /*     Enable task names 使用OSTaskNameGet()和OSTaskNameSet() 任务名称                                      */
#define OS_TASK_PROFILE_EN        1u   /*     Include variables in OS_TCB for profiling 包含OS_TCB性能分析     */
#define OS_TASK_QUERY_EN          1u   /*     Include code for OSTaskQuery()使用OSTaskQuety() 查询任务         */
#define OS_TASK_REG_TBL_SIZE      1u   /*     Size of task variables array (#of INT32U entries)任务数组变量大小*/
#define OS_TASK_STAT_EN           1u   /*     Enable (1) or Disable(0) the statistics task 使能统计任务        */
#define OS_TASK_STAT_STK_CHK_EN   1u   /*     Check task stacks from statistic task 使能检查任务堆栈    */
#define OS_TASK_SUSPEND_EN        1u   /*     Include code for OSTaskSuspend() and OSTaskResume()任务挂起、继续 */
#define OS_TASK_SW_HOOK_EN        1u   /*     Include code for OSTaskSwHook() 任务切换HOOK函数          */

任务管理主要针对uC/OS-ii Source结构下os_task.c文件中的源代码,os_task.c文件包含任务的建立、删除、挂起等关于任务的一些函数接口,

需要使用就打开。


4。系统其它功能

                         /* ----------------------- EVENT FLAGS事件标志 ------------------------ */

#define OS_FLAG_EN                1u   /* Enable (1) or Disable (0) code generation for EVENT FLAGS使能事件标志所有功能    */

#define OS_FLAG_ACCEPT_EN         1u   /*     Include code for OSFlagAccept()获取事件状态                          */
#define OS_FLAG_DEL_EN            1u   /*     Include code for OSFlagDel()删除事件                             */
#define OS_FLAG_NAME_EN           1u   /*     Enable names for event flag group使用事件标志名称                        */
#define OS_FLAG_QUERY_EN          1u   /*     Include code for OSFlagQuery()查询事件                           */
#define OS_FLAG_WAIT_CLR_EN       1u   /* Include code for Wait on Clear EVENT FLAGS使能事件等待清除功能                   */
#define OS_FLAGS_NBITS           16u   /* Size in #bits of OS_FLAGS data type (8, 16 or 32)定义事件数据类型            */




                                       /* -------------------- MESSAGE MAILBOXES消息邮箱 --------------------- */
#define OS_MBOX_EN                1u   /* Enable (1) or Disable (0) code generation for MAILBOXES      */
#define OS_MBOX_ACCEPT_EN         1u   /*     Include code for OSMboxAccept()                          */
#define OS_MBOX_DEL_EN            1u   /*     Include code for OSMboxDel()                             */
#define OS_MBOX_PEND_ABORT_EN     1u   /*     Include code for OSMboxPendAbort()                       */
#define OS_MBOX_POST_EN           1u   /*     Include code for OSMboxPost()                            */
#define OS_MBOX_POST_OPT_EN       1u   /*     Include code for OSMboxPostOpt()                         */
#define OS_MBOX_QUERY_EN          1u   /*     Include code for OSMboxQuery()                           */




                                       /* --------------------- MEMORY MANAGEMENT内存管理 -------------------- */
#define OS_MEM_EN                 1u   /* Enable (1) or Disable (0) code generation for MEMORY MANAGER */
#define OS_MEM_NAME_EN            1u   /*     Enable memory partition names                            */
#define OS_MEM_QUERY_EN           1u   /*     Include code for OSMemQuery()                            */




                                       /* ---------------- MUTUAL EXCLUSION SEMAPHORES互斥信号量 --------------- */
#define OS_MUTEX_EN               1u   /* Enable (1) or Disable (0) code generation for MUTEX          */
#define OS_MUTEX_ACCEPT_EN        1u   /*     Include code for OSMutexAccept()                         */
#define OS_MUTEX_DEL_EN           1u   /*     Include code for OSMutexDel()                            */
#define OS_MUTEX_QUERY_EN         1u   /*     Include code for OSMutexQuery()                          */




                                       /* ---------------------- MESSAGE QUEUES消息队列 ---------------------- */
#define OS_Q_EN                   1u   /* Enable (1) or Disable (0) code generation for QUEUES         */
#define OS_Q_ACCEPT_EN            1u   /*     Include code for OSQAccept()                             */
#define OS_Q_DEL_EN               1u   /*     Include code for OSQDel()                                */
#define OS_Q_FLUSH_EN             1u   /*     Include code for OSQFlush()                              */
#define OS_Q_PEND_ABORT_EN        1u   /*     Include code for OSQPendAbort()                          */
#define OS_Q_POST_EN              1u   /*     Include code for OSQPost()                               */
#define OS_Q_POST_FRONT_EN        1u   /*     Include code for OSQPostFront()                          */
#define OS_Q_POST_OPT_EN          1u   /*     Include code for OSQPostOpt()                            */
#define OS_Q_QUERY_EN             1u   /*     Include code for OSQQuery()                              */




                                       /* ------------------------ SEMAPHORES信号量 ------------------------ */
#define OS_SEM_EN                 1u   /* Enable (1) or Disable (0) code generation for SEMAPHORES     */
#define OS_SEM_ACCEPT_EN          1u   /*    Include code for OSSemAccept()                            */
#define OS_SEM_DEL_EN             1u   /*    Include code for OSSemDel()                               */
#define OS_SEM_PEND_ABORT_EN      1u   /*    Include code for OSSemPendAbort()                         */
#define OS_SEM_QUERY_EN           1u   /*    Include code for OSSemQuery()                             */
#define OS_SEM_SET_EN             1u   /*    Include code for OSSemSet()                               */




                                       /* --------------------- TIME MANAGEMENT时间管理 ---------------------- */
#define OS_TIME_DLY_HMSM_EN       1u   /*     Include code for OSTimeDlyHMSM()                         */
#define OS_TIME_DLY_RESUME_EN     1u   /*     Include code for OSTimeDlyResume()                       */
#define OS_TIME_GET_SET_EN        1u   /*     Include code for OSTimeGet() and OSTimeSet()             */
#define OS_TIME_TICK_HOOK_EN      1u   /*     Include code for OSTimeTickHook()                        */




                                       /* --------------------- TIMER MANAGEMENT定时器管理 --------------------- */
#define OS_TMR_EN                 0u   /* Enable (1) or Disable (0) code generation for TIMERS         */
#define OS_TMR_CFG_MAX           16u   /*     Maximum number of timers                                 */
#define OS_TMR_CFG_NAME_EN        1u   /*     Determine timer names                                    */
#define OS_TMR_CFG_WHEEL_SIZE     8u   /*     Size of timer wheel (#Spokes)                            */
#define OS_TMR_CFG_TICKS_PER_SEC 10u   /*     Rate at which timer management task runs (Hz)            */

uC/OS-ii操作系统可以进行多进程通信,每种功能都对应一个源代码文件。

每种功能都有使能全局的宏定义,只有使能了全局宏定义才可以使用里面的功能,每个模块也配置了选通开关。


猜你喜欢

转载自blog.csdn.net/li_qcxy/article/details/54920521