实验移植.docx
- 文档编号:13376909
- 上传时间:2023-06-13
- 格式:DOCX
- 页数:29
- 大小:54.59KB
实验移植.docx
《实验移植.docx》由会员分享,可在线阅读,更多相关《实验移植.docx(29页珍藏版)》请在冰点文库上搜索。
实验移植
uC/OS-II移植实验
一.实验目的
1.了解uC/OS-II内核的基本原理和主要结构;
2.掌握将uC/OS-II内核移植到ARM处理器上的基本方法;
3.掌握uC/OS-II下基本多任务应用程序的编写。
二.实验内容
1.学习uC/OS-II再ARM处理器上的移植过程;
2.编写简单的多任务应用程序,实现跑马灯和数码管显示的功能。
三.预备知识
1.了解嵌入式操作系统的构架,以及具体的uC/OS-II的组成;
2.了解操作系统的移植方法。
四.实验设备
1.硬件:
JX44B0教学实验箱、PC机;
2.软件:
ADT1000仿真器和ADTIDE集成开发环境
3.串口连接线
五.实验原理
uC/OS-II在特定处理器上的移植工作绝大部分集中在多任务切换的实现上,因为这部分代码主要是用来保存和恢复处理器现场,许多操作如读写寄存器操作不能用C语言,只能使用特定的处理器的汇编语言来完成。
将uC/OS-II移植到ARM处理器上,就是完成修改三个和体系结构相关的文件即可,这三个文件是OS_CPU_C.c、OS_CPU_C.H以及OS_CPU_A.S。
六.实验过程
1.硬件组成框图
2.程序设计流程图
移植OS_CPU_A.S
3.源程序
/*
*File:
eg1.c
*
*uC/OSReal-timemultitaskingkernelfortheARMprocessor.
*
*Simpleexampleofusingmultipletaskstoblinktheledandseginteb44b0board.
*
*Createdbycooljet()
*
*/
#include"Includes.h"/*uC/OSinterface*/
#include"option.h"
#include"44blib.h"
/*taskstack*/
OS_STKStackLED[STACKSIZE]={0,};
OS_STKStackSEG[STACKSIZE]={0,};
/*tasknamestring*/
charIdLED='1';
charIdSEG='2';
/*taskentryfunction*/
voidTaskLED(void*Id);
voidTaskSEG(void*Id);
/*
*LEDblinkfunction.
*thisfunctionblinktheled
*/
voidUser_LED_Blink(void)
{
staticintled_status=0;
led_status+=1;
if(led_status%2==0)
*(char*)0x02000000=0xff;
else
*(char*)0x02000000=0x00;
}
/*
*LEDblinkfunction.
*thisfunctionblinktheled
*/
voidUser_SEG_Blink(void)
{
staticunsignedcharseg_value[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
staticintseg_status=0;
*((unsignedchar*)0x2000006)=0x00;
*((unsignedchar*)0x2000004)=seg_value[seg_status];
seg_status+=1;
if(seg_status>15)
seg_status=0;
}
/*
*Taskentryfunction.
*thistaskblinktheledevery200ticks
*thatis2s.
*/
voidTaskLED(void*Id)
{
uHALr_printf("Task1()called\n");
for(;;)
{
OSSchedLock();
uHALr_printf("Task%c()turned\n",*(char*)Id);
User_LED_Blink();
OSSchedUnlock();
OSTimeDly(100);
}
}
/*
*Taskentryfunction.
*thistaskblinkthesegevery200ticks
*thatis1s.
*/
voidTaskSEG(void*Id)
{
uHALr_printf("Task2()called\n");
for(;;)
{
OSSchedLock();
uHALr_printf("Task%c()turned\n",*(char*)Id);
User_SEG_Blink();
OSSchedUnlock();
OSTimeDly(100);
}
}
/*
*Mainfunction.
*/
voidMain(void)
{
/*
*dotarget(uHALbasedARMsystem)initialisation
*/
ARMTargetInit();
uHALr_printf("#########Example1#########\n");
/*
*neededbyuC/OS
*/
OSInit();
/*
*createthetasksinuC/OSandassignincreasing
*prioritiestothemsothatTask3attheendof
*thepipelinehasthehighestpriority.
*/
OSTaskCreate(TaskLED,(void*)&IdLED,(OS_STK*)&StackLED[STACKSIZE-1],5);
/*Createsegblinktasks*/
OSTaskCreate(TaskSEG,(void*)&IdSEG,(OS_STK*)&StackSEG[STACKSIZE-1],13);
/*Startthe(uHALbasedARMsystem)systemrunning*/
ARMTargetStart();
/*
*startthetask
*/
OSStart();
/*
*neverreached
*/
return;
}
#defineOS_CPU_GLOBALS
#include"includes.h"
/*
*********************************************************************************************************
*INITIALIZEATASK'SSTACK
*
*Description:
ThisfunctioniscalledbyeitherOSTaskCreate()orOSTaskCreateExt()toinitializethe
*stackframeofthetaskbeingcreated.Thisfunctionishighlyprocessorspecific.
*
*Arguments:
taskisapointertothetaskcode
*
*pdataisapointertoausersupplieddataareathatwillbepassedtothetask
*whenthetaskfirstexecutes.
*
*ptosisapointertothetopofstack.Itisassumedthat'ptos'pointsto
*a'free'entryonthetaskstack.IfOS_STK_GROWTHissetto1then
*'ptos'willcontaintheHIGHESTvalidaddressofthestack.Similarly,if
*OS_STK_GROWTHissetto0,the'ptos'willcontainstheLOWESTvalidaddress
*ofthestack.
*
*optspecifiesoptionsthatcanbeusedtoalterthebehaviorofOSTaskStkInit().
*(seeuCOS_II.HforOS_TASK_OPT_?
?
?
).
*
*Returns:
Alwaysreturnsthelocationofthenewtop-of-stack'oncetheprocessorregistershave
*beenplacedonthestackintheproperorder.
*
*Note(s):
Interruptsareenabledwhenyourtaskstartsexecuting.Youcanchangethisbysettingthe
*PSWto0x0002instead.Inthiscase,interruptswouldbedisabledupontaskstartup.The
*applicationcodewouldberesponsibleforenablinginterruptsatthebeginningofthetask
*code.YouwillneedtomodifyOSTaskIdle()andOSTaskStat()sothattheyenable
*interrupts.Failuretodothiswillmakeyoursystemcrash!
*********************************************************************************************************
*/
void*OSTaskStkInit(void(*task)(void*pd),void*pdata,void*ptos,INT16Uopt)
{
unsignedint*stk;
opt=opt;/*'opt'isnotused,preventwarning*/
stk=(unsignedint*)ptos;/*Loadstackpointer*/
/*buildacontextforthenewtask*/
*--stk=(unsignedint)task;/*pc*/
*--stk=(unsignedint)task;/*lr*/
*--stk=0;/*r12*/
*--stk=0;/*r11*/
*--stk=0;/*r10*/
*--stk=0;/*r9*/
*--stk=0;/*r8*/
*--stk=0;/*r7*/
*--stk=0;/*r6*/
*--stk=0;/*r5*/
*--stk=0;/*r4*/
*--stk=0;/*r3*/
*--stk=0;/*r2*/
*--stk=0;/*r1*/
*--stk=(unsignedint)pdata;/*r0*/
*--stk=(SVC32MODE|0x0);/*cpsrIRQ,FIQdisable*/
*--stk=(SVC32MODE|0x0);/*spsrIRQ,FIQdisable*/
return((void*)stk);
}
/*$PAGE*/
#ifOS_CPU_HOOKS_EN
/*
*********************************************************************************************************
*TASKCREATIONHOOK
*
*Description:
Thisfunctioniscalledwhenataskiscreated.
*
*Arguments:
ptcbisapointertothetaskcontrolblockofthetaskbeingcreated.
*
*Note(s):
1)Interruptsaredisabledduringthiscall.
*********************************************************************************************************
*/
voidOSTaskCreateHook(OS_TCB*ptcb)
{
ptcb=ptcb;/*Preventcompilerwarning*/
}
/*
*********************************************************************************************************
*TASKDELETIONHOOK
*
*Description:
Thisfunctioniscalledwhenataskisdeleted.
*
*Arguments:
ptcbisapointertothetaskcontrolblockofthetaskbeingdeleted.
*
*Note(s):
1)Interruptsaredisabledduringthiscall.
*********************************************************************************************************
*/
voidOSTaskDelHook(OS_TCB*ptcb)
{
ptcb=ptcb;/*Preventcompilerwarning*/
}
/*
*********************************************************************************************************
*TASKSWITCHHOOK
*
*Description:
Thisfunctioniscalledwhenataskswitchisperformed.Thisallowsyoutoperformother
*operationsduringacontextswitch.
*
*Arguments:
none
*
*Note(s):
1)Interruptsaredisabledduringthiscall.
*2)Itisassumedthattheglobalpointer'OSTCBHighRdy'pointstotheTCBofthetaskthat
*willbe'switchedin'(i.e.thehighestprioritytask)and,'OSTCBCur'pointstothe
*taskbeingswitchedout(i.e.thepreemptedtask).
*********************************************************************************************************
*/
voidOSTaskSwHook(void)
{
}
/*
*********************************************************************************************************
*STATISTICTASKHOOK
*
*Description:
ThisfunctioniscalledeverysecondbyuC/OS-II'sstatisticstask.Thisallowsyour
*applicationtoaddfunctionalitytothestatisticstask.
*
*Arguments:
none
*********************************************************************************************************
*/
voidOSTaskStatHook(void)
{
}
/*
*********************************************************************************************************
*TICKHOOK
*
*Description:
Thisfunctioniscalledeverytick.
*
*Arguments:
none
*
*Note(s):
1)InterruptsmayormaynotbeENABLEDduringthiscall.
*********************************************************************************************************
*/
voidOSTimeTickHook(void)
{
}
#endif
#defineBUILD_DATE"Date:
"__DATE__"\n"
/*
*InitializeanARMTargetboard
*/
voidARMTargetInit(void)
{
rSYSCFG=CACHECFG;//Using8KBCache//
ChangePllValue(PLL_M,PLL_P,PLL_S);
Uart_Init(MCLK,BAUD);
Uart_Select(0);
//Telltheworldwhoweare//
Uart_Printf("uC/OS-II,TheReal-TimeKernelARM7Portedversion\n");
Uart_Printf("(Portedby)CVTECHLtd.,\n");
#ifdefDEBUG
Uart_Printf("Initialisingtarget\n");
#endif
//disableinterrupts(IRQs)//
ARMDisableInt();
//softvectors/
#ifdefDEBUG
Uart_Printf("Settingupsoftvectors\n");
#endif
//Definepre&post-processroutinesforInterrupt//
uHALir_DefineIRQ((void*)IrqStart,(void*)IrqFinish,(void*)0);
uHALr_InitInterrupts();
#ifdefDEBUG
Uart_Printf("Timerinit\n");
#endif
uHALr_InitTimers();
#ifdefDEBUG
Uart_Printf("targetInit()complete\n");
#endif
}//targetInit//
//starttheARMtargetrunning//
voidARMTargetStart(void)
{
#ifdefDEBUG
Uart_Printf("Startingtarget\n");
#endif
//Startsystemtimer&enabletheinterrupt.//
uHALr_InstallSystemTimer();
}
//just'notice'thatweneedtochangecontext//
intneed_to_swap_context=0;
voidOSIntCtxSw(void)
{
need_to_swap_context=1;
}
/*ThisiswhatuCOSdoesatthestartofanIRQ*/
voidIrqStart(void)
{
/*incrementnestingcounter*/
OSIntNesting++;
}
/*ThisiswhatuCOSdoesattheendofanIRQ*/
void*IrqFinish(void)
{
OSIntExit();
return(void*)0;
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 实验 移植
![提示](https://static.bingdoc.com/images/bang_tan.gif)