1、编写一个有3个任务T0、T1、T2的应用程序,其中任务T1在显示器上显示自己的姓名,任务T2在显示器上显示自己的学号,任务T0查询另外2个任务的信息,并在显示器上显示出来。(在例子1上修改代码运行和调试)
提示:
整个程序流程可以如下:
1)系统初始化,进入T0任务;
2)在T0任务中创建T1和T2任务,任务T1在显示器上显示自己的姓名,显示T1的OS_TCB个变量值,任务T2在显示器上显示自己的学号,显示T2的OS_TCB个变量值,任务T0在显示器上显示全局变量值(可利用函数OSTaskQuery(prio,*pdata)获取任务信息);
3)系统调度,多任务一直运行下去。
2、完成任务分配状况表
————————————————————————————————————————————
任务名称 优先级 堆栈大小(字节) 任务描述 延迟节拍数
————————————————————————————————————————————
3、观察并记录3个任务中每个OS_TCB各变量在运行中的值的变化,根据代码阅读和调试运行结果写出OS_TCB变化的总结报告,内容主要包括变量数值。
OS_TCB结构如下:
typedef struct os_tcb {
OS_STK *OSTCBStkPtr; /* Pointer to current top of stack */
struct os_tcb *OSTCBNext; /* Pointer to next TCB in the TCB list */
struct os_tcb *OSTCBPrev; /* Pointer to previous TCB in the TCB list */
INT16U OSTCBDly; /* Nbr ticks to delay task or, timeout waiting for event */
INT8U OSTCBStat; /* Task status */
INT8U OSTCBPrio; /* Task priority (0 == highest, 63 == lowest) */
INT8U OSTCBX; /* Bit position in group corresponding to task priority (0..7) */
INT8U OSTCBY; /* Index into ready table corresponding to task priority */
INT8U OSTCBBitX; /* Bit mask to access bit position in ready table */
INT8U OSTCBBitY; /* Bit mask to access bit position in ready group */
} OS_TCB;
4、观察并记录全局变量在运行中的变化,根据代码阅读和调试运行结果写出全局变量的总结报告,内容主要包括变量数值。
全局变量如下:
OS_EXT INT32U OSCtxSwCtr; /* Counter of number of context switches */
OS_EXT INT8U OSIntNesting; /* Interrupt nesting level */
OS_EXT INT8U OSIntExitY;
OS_EXT INT8U OSLockNesting; /* Multitasking lock nesting level */
OS_EXT INT8U OSPrioCur; /* Priority of current task */
OS_EXT INT8U OSPrioHighRdy; /* Priority of highest priority task */
OS_EXT INT8U OSRdyGrp; /* Ready list group */
OS_EXT INT8U OSRdyTbl[OS_RDY_TBL_SIZE]; /* Table of tasks which are ready to run */
OS_EXT BOOLEAN OSRunning; /* Flag indicating that kernel is running */
OS_EXT INT8U OSTaskCtr; /* Number of tasks created */
OS_EXT volatile INT32U OSIdleCtr; /* Idle counter */
OS_EXT OS_STK OSTaskIdleStk[OS_TASK_IDLE_STK_SIZE]; /* Idle task stack */
OS_EXT OS_TCB *OSTCBCur; /* Pointer to currently running TCB */
OS_EXT OS_TCB *OSTCBFreeList; /* Pointer to list of free TCBs */
OS_EXT OS_TCB *OSTCBHighRdy; /* Pointer to highest priority TCB R-to-R */
OS_EXT OS_TCB *OSTCBList; /* Pointer to doubly linked list of TCBs */
OS_EXT OS_TCB *OSTCBPrioTbl[OS_LOWEST_PRIO + 1];/* Table of pointers to created TCBs */
OS_EXT OS_TCB OSTCBTbl[OS_MAX_TASKS + OS_N_SYS_TASKS]; /* Table of TCBs */
阅读(1084) | 评论(0) | 转发(0) |