Chinaunix首页 | 论坛 | 博客
  • 博客访问: 305783
  • 博文数量: 75
  • 博客积分: 2710
  • 博客等级: 少校
  • 技术积分: 706
  • 用 户 组: 普通用户
  • 注册时间: 2009-08-21 14:19
文章分类

全部博文(75)

文章存档

2011年(10)

2010年(22)

2009年(43)

我的朋友

分类: 嵌入式

2010-07-07 11:42:27

5、os_cfg.h配置文件
#define OS_VIEW_MODULE            0    /* When 1, indicate that uC/OS-View is present                  */

 /* ---------------------- MISCELLANEOUS ----------------------- */
#define OS_ARG_CHK_EN             1    /* Enable (1) or Disable (0) argument checking                  */
#define OS_CPU_HOOKS_EN           1    /* uC/OS-II hooks are found in the processor port files         */
#define OS_DEBUG_EN               1    /* Enable(1) debug variables                                    */
#define OS_EVENT_NAME_SIZE       32    /* Determine the size of the name of a Sem, Mutex, Mbox or Q    */
#define OS_LOWEST_PRIO           63    /* Defines the lowest priority that can be assigned ...         */
                                       /* ... MUST NEVER be higher than 254!                           */
#define OS_MAX_EVENTS            10    /* Max. number of event control blocks in your application      */
#define OS_MAX_FLAGS              5    /* Max. number of Event Flag Groups    in your application      */
#define OS_MAX_MEM_PART           5    /* Max. number of memory partitions                             */
#define OS_MAX_QS                 4    /* Max. number of queue control blocks in your application      */
#define OS_MAX_TASKS             20    /* Max. number of tasks in your application, MUST be >= 2       */
#define OS_SCHED_LOCK_EN          1    /*     Include code for OSSchedLock() and OSSchedUnlock()       */
#define OS_TASK_IDLE_STK_SIZE   128    /* Idle task stack size (# of OS_STK wide entries)              */
#define OS_TASK_STAT_EN           1    /* 统计任务 */
#define OS_TASK_STAT_STK_SIZE   128    /* Statistics task stack size (# of OS_STK wide entries)        */
#define OS_TASK_STAT_STK_CHK_EN   1    /* Check task stacks from statistic task                        */
#define OS_TICK_STEP_EN           0    /* Enable tick stepping feature for uC/OS-View                  */
#define OS_TICKS_PER_SEC        100    /* 与时钟节拍中断对应 */

                                       /* ----------------------- EVENT FLAGS ------------------------ */
#define OS_FLAG_EN                1    /* Enable (1) or Disable (0) code generation for EVENT FLAGS    */
#define OS_FLAG_WAIT_CLR_EN       1    /* Include code for Wait on Clear EVENT FLAGS                   */
#define OS_FLAG_ACCEPT_EN         1    /*     Include code for OSFlagAccept()                          */
#define OS_FLAG_DEL_EN            1    /*     Include code for OSFlagDel()                             */
#define OS_FLAG_NAME_SIZE        32    /*     Determine the size of the name of an event flag group    */
#define OS_FLAG_QUERY_EN          1    /*     Include code for OSFlagQuery()                           */
#if     OS_VERSION >= 280
#define OS_FLAGS_NBITS           16    /* Size in #bits of OS_FLAGS data type (8, 16 or 32)            */
#endif
                                       /* -------------------- MESSAGE MAILBOXES --------------------- */
#define OS_MBOX_EN                1    /* Enable (1) or Disable (0) code generation for MAILBOXES      */
#define OS_MBOX_ACCEPT_EN         1    /*     Include code for OSMboxAccept()                          */
#define OS_MBOX_DEL_EN            1    /*     Include code for OSMboxDel()                             */
#define OS_MBOX_POST_EN           1    /*     Include code for OSMboxPost()                            */
#define OS_MBOX_POST_OPT_EN       1    /*     Include code for OSMboxPostOpt()                         */
#define OS_MBOX_QUERY_EN          1    /*     Include code for OSMboxQuery()                           */

                                       /* --------------------- MEMORY MANAGEMENT -------------------- */
#define OS_MEM_EN                 1    /* Enable (1) or Disable (0) code generation for MEMORY MANAGER */
#define OS_MEM_QUERY_EN           1    /*     Include code for OSMemQuery()                            */
#define OS_MEM_NAME_SIZE         32    /*     Determine the size of a memory partition name            */

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

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

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

                                       /* --------------------- TASK MANAGEMENT ---------------------- */
#define OS_TASK_CHANGE_PRIO_EN    1    /*     Include code for OSTaskChangePrio()                      */
#define OS_TASK_CREATE_EN         1    /*     Include code for OSTaskCreate()                          */
#define OS_TASK_CREATE_EXT_EN     1    /*     Include code for OSTaskCreateExt()                       */
#define OS_TASK_DEL_EN            1    /*     Include code for OSTaskDel()                             */
#define OS_TASK_NAME_SIZE        32    /*     Determine the size of a task name                        */
#define OS_TASK_PROFILE_EN        1    /*     Include variables in OS_TCB for profiling                */
#define OS_TASK_QUERY_EN          1    /*     Include code for OSTaskQuery()                           */
#define OS_TASK_SUSPEND_EN        1    /*     Include code for OSTaskSuspend() and OSTaskResume()      */
#define OS_TASK_SW_HOOK_EN        1    /*     Include code for OSTaskSwHook()                          */

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

#if     OS_VERSION < 280
typedef INT16U             OS_FLAGS;
#endif
6、includes.h文件
//必备的头文件
#include "os_cpu.h"
#include "os_cfg.h"
#include "ucos_ii.h"
//其他
#include "string.h"
 
7、应用程序文件 main.c
OS_STK TestTask1Stk[1024];
OS_STK TestTask2Stk[1024];
 
void TestTask2(void *pdata);
void TestTask1(void *pdata)
{
#if OS_CRITICAL_METHOD==3
        OS_CPU_SR cpu_sr;
#endif
 pdata=pdata;
 startTimeTick();//开启时钟中断
 OSStatInit();//开启统计任务
 OSTaskCreateExt(TestTask2,(void *)0,&TestTask2Stk[1023],6,
   6,&TestTask2Stk[0],1024,(void *)0,
                        OS_TASK_OPT_STK_CHK|OS_TASK_OPT_STK_CLR);
 while(1){
  OS_ENTER_CRITICAL();
                putStr("In task1 !\r\n");
                OS_EXIT_CRITICAL();
  OSTimeDly(OS_TICKS_PER_SEC);
 }
}
void TestTask2(void *pdata)
{
#if OS_CRITICAL_METHOD==3
 OS_CPU_SR cpu_sr;
#endif
        pdata=pdata;
        while(1){
  OS_ENTER_CRITICAL();
                putStr("In task2 !\r\n");
  OS_EXIT_CRITICAL();
                OSTimeDlyHMSM(0,0,2,0);
        }
}
int main(void)
{
 OSInit();
 uart0_init();
 putStr("uC/OS V2.52\r\n");
 startTimer4();//初始化定时器4
 OSTaskCreateExt(TestTask1,(void *)0,&TestTask1Stk[1023],5,
   5,&TestTask1Stk[0],1024,(void *)0,
   OS_TASK_OPT_STK_CHK|OS_TASK_OPT_STK_CLR);
 OSStart();
 
 return 0;
}

8、移植测试
用仿真器和LED闪烁配合,我使用OpenJtag仿真器,开发板上有2个LED
首先保证编译正确;
接着验证OSTaskStkInit和OSStartHighRdy函数;
添加一个任务,验证OSCtxSw函数;
最后验证OSInitCtxSw和OSTickISR,这一步是最难的,先保证定时器运行正常(暂时不进行任务切换),然后单步调试这两个函数,重点观察cpu状态和寄存器以及堆栈中的内容是否如自己所想。
 
9、运行结果:
uC/OS V2.52
In task1 !
In task2 !
CPUUsage=0%
In task1 !
CPUUsage=1%
In task1 !
In task2 !
CPUUsage=1%
In task1 !
CPUUsage=1%
。。。。。。。。。。
 
所有代码下载:
文件: qt2410e_ucos2_gyh.tar.gz
大小: 557KB
下载: 下载
 
 
阅读(1405) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~