嵌入式操作系统-实验2-实验报告_第1页
嵌入式操作系统-实验2-实验报告_第2页
嵌入式操作系统-实验2-实验报告_第3页
嵌入式操作系统-实验2-实验报告_第4页
嵌入式操作系统-实验2-实验报告_第5页
已阅读5页,还剩8页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

信息学部软件学院嵌入式操作系统ADDINCNKISM.UserStyle北京工业大学2022-2023学年第一学期软件学院课程名称嵌入式操作系统报告性质实验二任课教师严海蓉课程性质专业选修课学分2.00学时32

实验2题目:用位图做优先级注册表,编写CreatTask()、SuspendTask()和Findhighestprior()函数要求:CreatTask():创建任务,优先级就绪组与就绪表相应位置置1,从空任务链表中取出一个空任务,设置优先级存入就绪链表中。SuspendTask():暂停任务,将指定优先级的任务从优先级就绪组和就绪表中清除,将任务归还于空任务链表。Findhighestprior():从任务就绪组和任务就绪表中找到最高优先级任务。代码:Tasklist.h(新增按地址删除节点函数)#include<stdio.h>#include<exception>#include<iostream>usingnamespacestd;#defineMAX_TASKLIST_NODE_NUM64typedefstructNode{chardata;Node*next;Node*pre;intpriority;}Node;Node*Creat_New_Node();Node*Creat_Tasklist(intNode_Num);boolInsertlistNode(Node**Head,Node*InsertNode_list[],intLocation[],intInsert_Num);Node*DeletelistNode(Node**Head);voidDeletelistNodebyAdd(Node**Head,Node*DeleteNode);Tasklist.cpp(新增函数)/***@brief从所给链表头Head中移出指定一个节点*@paramHead要移出节点的链表头,可能移出的是头节点,所以用Node**类型*@paramDeleteNode要移出的指定节点*/voidDeletelistNodebyAdd(Node**Head,Node*DeleteNode){//if((*Head)==DeleteNode){(*Head)=DeleteNode->next;(*Head)->pre=NULL;DeleteNode->next=NULL;}elseif(DeleteNode->next==NULL){Node*temp=DeleteNode->pre;temp->next=NULL;DeleteNode->pre=NULL;}else{Node*temp=DeleteNode->pre;temp->next=DeleteNode->next;DeleteNode->next->pre=temp;DeleteNode->next=NULL;DeleteNode->pre=NULL;}}OSRdyTbl.h/*===================================*用位图做优先级注册表===================================*/#include<stdio.h>#include<iostream>#defineMAX_NUM_OSRDYGRP8voidCreatTaskPriority(intpriority);voidSuspendTaskPriority(intpriority);intFindHighestTaskPrior();OSRdyTbl.cpp/*===================================*用位图做优先级注册表===================================*/#include<stdio.h>#include<iostream>#include<OSRdyTbl.h>charOSRdyGrp;//任务就绪组unsignedcharOSRdyTbl[MAX_NUM_OSRDYGRP];//任务就绪表unsignedintOSMapTbl[MAX_NUM_OSRDYGRP]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};unsignedintconstOSUnMapTbl[256]={0,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,/*0x00to0x0F*/4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,/*0x10to0x1F*/5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,/*0x20to0x2F*/4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,/*0x30to0x3F*/6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,/*0x40to0x4F*/4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,/*0x50to0x5F*/5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,/*0x60to0x6F*/4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,/*0x70to0x7F*/7,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,/*0x80to0x8F*/4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,/*0x90to0x9F*/5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,/*0xA0to0xAF*/4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,/*0xB0to0xBF*/6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,/*0xC0to0xCF*/4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,/*0xD0to0xDF*/5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,/*0xE0to0xEF*/4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0/*0xF0to0xFF*/};/***@brief位图优先级注册*@parampriority注册任务的优先级*/voidCreatTaskPriority(intpriority){OSRdyGrp|=OSMapTbl[priority>>3];OSRdyTbl[priority>>3]|=OSMapTbl[priority&0x07];}/***@brief位图优先级清除*@parampriority清除任务的优先级*/voidSuspendTaskPriority(intpriority){if((OSRdyTbl[priority>>3]&=~OSMapTbl[priority&0x07])==0)OSRdyGrp&=~OSMapTbl[priority>>3];}/***@brief找到位图中最高优先级*@returnint:最高优先级*/intFindHighestTaskPrior(){inthigh3Bit=OSUnMapTbl[OSRdyGrp];intlow3Bit=OSUnMapTbl[OSRdyTbl[high3Bit]];return(high3Bit<<3)+low3Bit;}Task.h#include<stdio.h>#include<iostream>voidCreatTask(Node**OSTCBFreeList,Node**OSTCBReadyList,Node*OSTCBPrioTb1[],intpriority);voidSuspendTask(Node**OSTCBFreeList,Node**OSTCBReadyList,Node*OSTCBPrioTb1[],intpriority);voidFindhighestprior(Node**highestpriorNode,Node*OSTCBPrioTb1[]);Task.cpp/*===================================*(2)用位图做优先级注册表,编写*CreatTask()*SuspendTask()*Findhighestprior()===================================*/#include<stdio.h>#include<iostream>#include<OSRdyTbl.h>#include<Tasklist.h>/***@brief创建任务,添加优先级*@paramOSTCBFreeList任务控制块链表:空任务池*@paramOSTCBReadyList任务控制块链表:就绪任务表*@paramOSTCBPrioTb1优先级映射任务地址表*@parampriority操作任务的优先级*/voidCreatTask(Node**OSTCBFreeList,Node**OSTCBReadyList,Node*OSTCBPrioTb1[],intpriority){intlocation[1]={0};Node*TempNode[1]={DeletelistNode(OSTCBFreeList)};if(TempNode==NULL){perror("Can'tfindFreeOSTCB");}TempNode[0]->priority=priority;CreatTaskPriority(priority);OSTCBPrioTb1[priority]=TempNode[0];InsertlistNode(OSTCBReadyList,TempNode,location,1);}/***@brief暂停任务,取消优先级*@paramOSTCBFreeList任务控制块链表:空任务池*@paramOSTCBReadyList任务控制块链表:就绪任务表*@paramOSTCBPrioTb1优先级映射任务地址表*@parampriority操作任务的优先级*/voidSuspendTask(Node**OSTCBFreeList,Node**OSTCBReadyList,Node*OSTCBPrioTb1[],intpriority){intlocation[1]={0};Node*TempNode[1]={OSTCBPrioTb1[priority]};DeletelistNodebyAdd(OSTCBReadyList,OSTCBPrioTb1[priority]);InsertlistNode(OSTCBFreeList,TempNode,location,1);OSTCBPrioTb1[priority]=NULL;SuspendTaskPriority(priority);}/***@brief找到最高优先级任务,存入highestpriorNode*@paramhighestpriorNode最高优先级任务地址*@paramOSTCBPrioTb1优先级映射任务地址表*/voidFindhighestprior(Node**highestpriorNode,Node*OSTCBPrioTb1[]){*highestpriorNode=OSTCBPrioTb1[FindHighestTaskPrior()];}main.cpp#include<stdio.h>#include<exception>#include<iostream>#include"Tasklist.h"#include<Task.h>usingnamespacestd;Node*OSTCBFreeList=Creat_Tasklist(MAX_TASKLIST_NODE_NUM);Node*OSTCBReadyList=NULL;Node*OSTCBPrioTb1[MAX_TASKLIST_NODE_NUM]={NULL};Node*highestpriorNode=NULL;intNode_Insert_Location[MAX_TASKLIST_NODE_NUM]=

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论