《实时操作系统.doc》由会员分享,可在线阅读,更多相关《实时操作系统.doc(33页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、实时操作系统实习报告实时操作系统实验报告 实验一 任务管理实验实验目的:l 理解任务管理的基本原理,了解任务的各个基本状态及其变迁过程;l 掌握C/OS-II系统的编程方法,包括main函数的书写方法,任务组成、创建、启动和时间函数,主要包括:n OSInit; OSStart; OSTaskCreate; PC_DispStr; PC_GetKey; OSTimeDlyHMSM; OSTimeDly; OSTimeGet等。实验要求与思路:设计一个任务,利用OSTimeGet实现时间的获取,同时利用PC_DispStr实现时间的显示,同时需要编写一个启动任务实现对时间任务的启动。实验程序:/
2、* uC/OS-II* The Real-Time Kernel* EXAMPLE*/#include includes.h/* CONSTANTS*/#define TASK_STK_SIZE 512 /* Size of each tasks stacks (# of WORDs) */* VARIABLES*/OS_STK TaskStkTASK_STK_SIZE; /* Tasks stacks */OS_STK TaskStartStkTASK_STK_SIZE;/* FUNCTION PROTOTYPES*/void Task(void *data); /* Function pr
3、ototypes of tasks */void TaskStart(void *data); /* Function prototypes of Startup task */static void TaskStartCreateTasks(void);static void TaskStartDispInit(void);/* MAIN*/void main (void) PC_DispClrScr(DISP_FGND_WHITE + DISP_BGND_BLACK); /* Clear the screen */ OSInit(); /* Initialize uC/OS-II */ P
4、C_DOSSaveReturn(); /* Save environment to return to DOS */ PC_VectSet(uCOS, OSCtxSw); /* Install uC/OS-IIs context switch vector */ OSTaskCreate(TaskStart, (void *)0, &TaskStartStkTASK_STK_SIZE - 1, 2); OSStart(); /* Start multitasking */* STARTUP TASK*/void TaskStart (void *pdata)#if OS_CRITICAL_ME
5、THOD = 3 /* Allocate storage for CPU status register */ OS_CPU_SR cpu_sr;#endif char s100; INT16S key; pdata = pdata; /* Prevent compiler warning */ TaskStartDispInit(); /* Initialize the display */ OS_ENTER_CRITICAL(); PC_VectSet(0x08, OSTickISR); /* Install uC/OS-IIs clock tick ISR */ PC_SetTickRa
6、te(OS_TICKS_PER_SEC); /* Reprogram tick rate */ OS_EXIT_CRITICAL(); OSStatInit(); /* Initialize uC/OS-IIs statistics */ OSTaskCreate(Task, (void *)0, &TaskStkTASK_STK_SIZE - 1, 0); for (;) if (PC_GetKey(&key) = TRUE) /* See if key has been pressed */ if (key = 0x1B) /* Yes, see if its the ESCAPE key
7、 */PC_DOSReturn(); /* Return to DOS */ OSCtxSwCtr = 0; /* Clear context switch counter */OSTimeDly(1); /* INITIALIZE THE DISPLAY*/static void TaskStartDispInit (void) PC_DispStr( 0, 0, uC/OS-II, The Real-Time Kernel , DISP_FGND_WHITE + DISP_BGND_RED + DISP_BLINK); PC_DispStr( 0, 1, , DISP_FGND_BLACK
8、 + DISP_BGND_LIGHT_GRAY); PC_DispStr( 0, 2, , DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY); PC_DispStr( 0, 3, Time EXAMPLE , DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY); PC_DispStr( 0, 4, , DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY); PC_DispStr( 0, 5, , DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY); PC_DispStr( 0, 6,
9、 , DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY); PC_DispStr( 0, 7, , DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY); PC_DispStr( 0, 8, , DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY); PC_DispStr( 0, 9, , DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY); PC_DispStr( 0, 10, , DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY); PC_DispStr(
10、 0, 11, , DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY); PC_DispStr( 0, 12, , DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY); PC_DispStr( 0, 13, , DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY); PC_DispStr( 0, 14, , DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY); PC_DispStr( 0, 15, , DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY); P
11、C_DispStr( 0, 16, , DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY); PC_DispStr( 0, 17, , DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY); PC_DispStr( 0, 18, , DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY); PC_DispStr( 0, 19, , DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY); PC_DispStr( 0, 20, , DISP_FGND_BLACK + DISP_BGND_LIGH
12、T_GRAY); PC_DispStr( 0, 21, , DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY); PC_DispStr( 0, 22, , DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY + DISP_BLINK);/* TASKS*/void Task (void *pdata) char ss30; INT8U err; pdata=pdata; for (;) sprintf(ss,Time = %ld,OSTimeGet();PC_DispStr(40, 10, ss, DISP_FGND_BLACK + DIS
13、P_BGND_LIGHT_GRAY);OSTimeDlyHMSM(0, 0, 1, 0); /* Wait one second */ /* Delay 1 clock tick */ 实验输出:实验感想:通过这次的实验,我大致的了解了如何的实现bc的调试,同时对于u/cos II有了直观的了解,同时我知道了对于任务的建立和如何的进行形式的输出,对于Pc_DispStr输出函数的了解。实验二 任务管理实验实验目的:1.理解任务管理的基本原理,了解任务的各个基本状态及其变迁过程;2.掌握C/OS-II 中任务管理的基本方法(挂起、解挂);3.熟练使用C/OS-II 任务管理的基本系统调用。实验要
14、求与思路:为了体现任务的各个基本状态及其变迁过程,本实验设计了T0、T1 和T3三个任务,它们交替运行,如图所示说明:在系统完成初始化后,可以先创建并启动优先级最低的TaskStart,由它创建其他3 个应用任务T0、T1 和T2,之后整个系统的运行流程如下:1) 优先级最高的T0 开始执行,之后T0 挂起自己;2) 然后系统调度选中T1 开始执行,之后T1 挂起自己;3) 接着系统调度选中T2,之后唤醒T0;4) 如此循环实验程序:* uC/OS-II* The Real-Time Kernel* EX #1 Task Management*#include includes.h* CONS
15、TANTS*#define TASK_STK_SIZE 512 /* Size of each tasks stacks (# of WORDs) */#define N_TASKS 2 /* Number of identical tasks * VARIABLES*/OS_STK TaskStkN_TASKSTASK_STK_SIZE; /* Tasks stacks OS_STK TaskStartStkTASK_STK_SIZE; /* TaskStart task stack INT8U TaskDataN_TASKS; /* Parameters to pass to each t
16、ask /* FUNCTION PROTOTYPES*/void Task0(void *pdata); /* Function prototypes of tasks */void Task1(void *pdata);void Task2(void *pdata);void TaskStart(void *pdata); /* Function prototypes of Startup task */static void TaskStartCreateTasks(void); /* Function prototypes of creat task */static void Task
17、StartDispInit(void); /* Function prototypes of Initialization the display */*$PAGE*/* MAIN*/void main (void) PC_DispClrScr(DISP_FGND_WHITE + DISP_BGND_BLACK); /* Clear the screen */ OSInit(); /* Initialize uC/OS-II */ PC_DOSSaveReturn(); /* Save environment to return to DOS */ PC_VectSet(uCOS, OSCtx
18、Sw); /* Install uC/OS-IIs context switch vector */ /创建初始任务 OSTaskCreate(TaskStart, (void *)0, &TaskStartStkTASK_STK_SIZE - 1, 4); OSStart(); /* Start multitasking */* STARTUP TASK*/void TaskStart (void *pdata)#if OS_CRITICAL_METHOD = 3 /* Allocate storage for CPU status register */ OS_CPU_SR cpu_sr;
19、#endif INT16S key; pdata = pdata; /* Prevent compiler warning */ TaskStartDispInit(); /* Initialize the display */ OS_ENTER_CRITICAL(); PC_VectSet(0x08, OSTickISR); /* Install uC/OS-IIs clock tick ISR */ PC_SetTickRate(OS_TICKS_PER_SEC); /* Reprogram tick rate */ OS_EXIT_CRITICAL(); OSStatInit(); /*
20、 Initialize uC/OS-IIs statistics */ TaskStartCreateTasks(); /* Create all the application tasks */ for (;) if (PC_GetKey(&key) = TRUE) /* See if key has been pressed */ if (key = 0x1B) /* Yes, see if its the ESCAPE key */PC_DOSReturn(); /* Return to DOS */ OSCtxSwCtr = 0; /* Clear context switch cou
21、nter */OSTimeDlyHMSM(0, 0, 1, 0); /* Wait one second */ /*$PAGE*/* INITIALIZE THE DISPLAY*/static void TaskStartDispInit (void)/* 1111111111222222222233333333334444444444555555555566666666667777777777 */* 01234567890123456789012345678901234567890123456789012345678901234567890123456789 */PC_DispStr( 0, 0, uC/OS-II, The Real-Time Kernel , DISP_FGND_WHITE + DISP_BGND_RED + DISP_BLINK);PC_DispStr( 0, 1, , DISP_FGND_BLACK + DISP_BGND_LI