ucosii移植实验报告.docx
- 文档编号:5013578
- 上传时间:2022-12-12
- 格式:DOCX
- 页数:12
- 大小:27.05KB
ucosii移植实验报告.docx
《ucosii移植实验报告.docx》由会员分享,可在线阅读,更多相关《ucosii移植实验报告.docx(12页珍藏版)》请在冰豆网上搜索。
ucosii移植实验报告
一、实验目的
●了解uC/OS-II内核的主要结构。
●掌握将uC/OS-II内核移植到Cortex-M3处理器上的基本方法。
二、实验环境与设备
●硬件:
Cortex-M3嵌入式开发平台、用于Cortex-M3的JTAG仿真器或者内嵌的JTAG仿真器、PC机Pentium100以上。
●软件:
PC机操作系统win98、Win2000或WinXP、KeilforARM或IARforARM集成开发环境、仿真器驱动程序、超级终端通讯程序等。
三、预备知识
●掌握在KeilforARM或IARforARM集成开发环境中编写和调试程序的基本过程。
●了解Cortex-M3处理器的结构。
●理解uC/OS-II系统结构。
四、实验内容
●将uC/OS-II内核移植到Cortex-M3微处理器上。
●编写两个简单任务,在超级终端上观察两个任务的切换。
五、流程图
六、实验代码
修改后的Os_cpu.h
#ifndefOS_CPU_H
#defineOS_CPU_H
#ifdefOS_CPU_GLOBALS
#defineOS_CPU_EXT
#else
#defineOS_CPU_EXTextern
#endif
typedefunsignedcharBOOLEAN;
typedefunsignedcharINT8U;/*Unsigned8bitquantity*/
typedefsignedcharINT8S;/*Signed8bitquantity*/
typedefunsignedshortINT16U;/*Unsigned16bitquantity*/
typedefsignedshortINT16S;/*Signed16bitquantity*/
typedefunsignedintINT32U;/*Unsigned32bitquantity*/
typedefsignedintINT32S;/*Signed32bitquantity*/
typedeffloatFP32;/*Singleprecisionfloatingpoint*/
typedefdoubleFP64;/*Doubleprecisionfloatingpoint*/
typedefunsignedintOS_STK;/*Eachstackentryis32-bitwide*/
typedefunsignedintOS_CPU_SR;/*DefinesizeofCPUstatusregister(PSR=32bits)*/
#defineOS_CRITICAL_METHOD3u
#ifOS_CRITICAL_METHOD==3u
#defineOS_ENTER_CRITICAL(){cpu_sr=OS_CPU_SR_Save();}
#defineOS_EXIT_CRITICAL(){OS_CPU_SR_Restore(cpu_sr);}
#endif
#defineOS_STK_GROWTH1u/*StackgrowsfromHIGHtoLOWmemoryonARM*/
#defineOS_TASK_SW()OSCtxSw()
#ifOS_CRITICAL_METHOD==3u/*SeeOS_CPU_A.ASM*/
OS_CPU_SROS_CPU_SR_Save(void);
voidOS_CPU_SR_Restore(OS_CPU_SRcpu_sr);
#endif
voidOSCtxSw(void);
voidOSIntCtxSw(void);
voidOSStartHighRdy(void);
voidOSPendSV(void);
#endif
修改后的Os_cpu_c.c
#defineOS_CPU_GLOBALS
#include
#include
#ifOS_TMR_EN>0u
staticINT16UOSTmrCtr;
#endif
#ifOS_CPU_HOOKS_EN>0u
voidOSInitHookBegin(void)
{
#ifOS_TMR_EN>0u
OSTmrCtr=0u;
#endif
}
#endif
#ifOS_CPU_HOOKS_EN>0u
voidOSInitHookEnd(void)
{
}
#endif
#ifOS_CPU_HOOKS_EN>0u
voidOSTaskCreateHook(OS_TCB*ptcb)
{
#ifOS_APP_HOOKS_EN>0u
App_TaskCreateHook(ptcb);
#else
(void)ptcb;/*Preventcompilerwarning*/
#endif
}
#endif
#ifOS_CPU_HOOKS_EN>0u
voidOSTaskDelHook(OS_TCB*ptcb)
{
#ifOS_APP_HOOKS_EN>0u
App_TaskDelHook(ptcb);
#else
(void)ptcb;/*Preventcompilerwarning*/
#endif
}
#endif
#ifOS_CPU_HOOKS_EN>0u
voidOSTaskIdleHook(void)
{
#ifOS_APP_HOOKS_EN>0u
App_TaskIdleHook();
#endif
}
#endif
#ifOS_CPU_HOOKS_EN>0u
voidOSTaskStatHook(void)
{
#ifOS_APP_HOOKS_EN>0u
App_TaskStatHook();
#endif
}
#endif
OS_STK*OSTaskStkInit(void(*task)(void*p_arg),void*p_arg,OS_STK*ptos,INT16Uopt)
{
OS_STK*stk;
(void)opt;/*'opt'isnotused,preventwarning*/
stk=ptos;/*Loadstackpointer*/
/*Registersstackedasifauto-savedonexception*/
*(stk)=(INT32U)0x01000000uL;/*xPSR*/
*(--stk)=(INT32U)task;/*EntryPoint*/
*(--stk)=(INT32U)0xFFFFFFFEL;/*R14(LR)(initvaluewill*/
/*causefaultifeverused)*/
*(--stk)=(INT32U)0x12121212uL;/*R12*/
*(--stk)=(INT32U)0x03030303uL;/*R3*/
*(--stk)=(INT32U)0x02020202uL/*R2*/
*(--stk)=(INT32U)0x01010101uL;/*R1*/
*(--stk)=(INT32U)p_arg;/*R0:
argument*/
/*Remainingregisterssavedonprocessstack*/
*(--stk)=(INT32U)0x11111111uL;/*R11*/
*(--stk)=(INT32U)0x10101010uL;/*R10*/
*(--stk)=(INT32U)0x09090909uL;/*R9*/
*(--stk)=(INT32U)0x08080808uL;/*R8*/
*(--stk)=(INT32U)0x07070707uL;/*R7*/
*(--stk)=(INT32U)0x06060606uL;/*R6*/
*(--stk)=(INT32U)0x05050505uL;/*R5*/
*(--stk)=(INT32U)0x04040404uL;/*R4*/
return(stk);
}
#if(OS_CPU_HOOKS_EN>0u)&&(OS_TASK_SW_HOOK_EN>0u)
voidOSTaskSwHook(void)
{
#ifOS_APP_HOOKS_EN>0u
App_TaskSwHook();
#endif
}
#endif
#ifOS_CPU_HOOKS_EN>0u
voidOSTCBInitHook(OS_TCB*ptcb)
{
#ifOS_APP_HOOKS_EN>0u
App_TCBInitHook(ptcb);
#else
(void)ptcb;/*Preventcompilerwarning*/
#endif
}
#endif
#if(OS_CPU_HOOKS_EN>0u)&&(OS_TIME_TICK_HOOK_EN>0u)
voidOSTimeTickHook(void)
{
#ifOS_APP_HOOKS_EN>0u
App_TimeTickHook();
#endif
#ifOS_TMR_EN>0u
OSTmrCtr++;
if(OSTmrCtr>=(OS_TICKS_PER_SEC/OS_TMR_CFG_TICKS_PER_SEC)){
OSTmrCtr=0;
OSTmrSignal();
}
#endif
}
#endif
修改后的Os_cpu_a.asm
EXTERNOSRunning
EXTERNOSPrioCur
EXTERNOSPrioHighRdy
EXTERNOSTCBCur
EXTERNOSTCBHighRdy
EXTERNOSIntExit
EXTERNOSTaskSwHook
EXPORTOS_CPU_SR_Save
EXPORTOS_CPU_SR_Restore
EXPORTOSStartHighRdy
EXPORTOSCtxSw
EXPORTOSIntCtxSw
EXPORTOSPendSV
NVIC_INT_CTRLEQU0xE000ED04;Interruptcontrolstateregister.
NVIC_SYSPRI14EQU0xE000ED22Systempriorityregister(priority14).
NVIC_PENDSV_PRIEQU0xFF;PendSVpriorityvalue(lowest).
NVIC_PENDSVSETEQU0x10000000;ValuetotriggerPendSVexception.
PRESERVE8;TheAAPCSrequiresthatthestack-pointerbe8-bytealignedonentrytoaconformingfunction.
AREAUCOSII_ASM,CODE,READONLYTHUMB
OS_CPU_SR_Save
MRSR0,PRIMASK;Setpriointmasktomaskall(exceptfaults)
CPSIDI
BXLR
OS_CPU_SR_Restore
MSRPRIMASK,R0
BXLR
OSStartHighRdy
LDRR0,=NVIC_SYSPRI14;SetthePendSVexceptionpriority
LDRR1,=NVIC_PENDSV_PRI
STRBR1,[R0]
MOVR0,#;SetthePSPto0forinitialcontextswitchcall
MSRPSP,R0
LDRR0,=OSRunning;OSRunning=TRUE
MOVR1,#1
STRBR1,[R0]
LDRR0,=NVIC_INT_CTRL;TriggerthePendSVexception(causescontextswitch)
LDRR1,=NVIC_PENDSVSET
STRR1,[R0]
CPSIEI;Enableinterruptsatprocessorlevel
OSStartHang
BOSStartHang;Shouldnevergethere
OSCtxSw
LDRR0,=NVIC_INT_CTRL;TriggerthePendSVexception(causescontextswitch)
LDRR1,=NVIC_PENDSVSET
STRR1,[R0]
BXLR
OSIntCtxSw
LDRR0,=NVIC_INT_CTRL;TriggerthePendSVexception(causescontextswitch)
LDRR1,=NVIC_PENDSVSET
STRR1,[R0]
BXLR
OSPendSV
CPSIDI;Preventinterruptionduringcontextswitch
MRSR0,PSP;PSPisprocessstackpointer
CBZR0,OSPendSV_nosave;Skipregistersavethefirsttime
SUBR0,R0,#0x20;Saveremainingregsr4-11onprocessstack
STMR0,{R4-R11}
LDRR1,=OSTCBCur;OSTCBCur->OSTCBStkPtr=SP;
LDRR1,[R1]
STRR0,[R1];R0isSPofprocessbeingswitchedout;Atthispoint,entirecontextofprocesshasbeensaved
OSPendSV_nosave
PUSH{R14};SaveLRexc_returnvalue
LDRR0,=OSTaskSwHook;OSTaskSwHook();
BLXR0
POP{R14}
LDRR0,=OSPrioCur;OSPrioCur=OSPrioHighRdy;
LDRR1,=OSPrioHighRdy
LDRBR2,[R1]
STRBR2,[R0]
LDRR0,=OSTCBCur;OSTCBCur=OSTCBHighRdy;
LDRR1,=OSTCBHighRdy
LDRR2,[R1]
STRR2,[R0]
LDRR0,[R2];R0isnewprocessSP;SP=OSTCBHighRdy->OSTCBStkPtr;
LDMR0,{R4-R11};Restorer4-11fromnewprocessstack
ADDSR0,R0,#0x20
MSRPSP,R0;LoadPSPwithnewprocessSP
ORRLR,LR,#0x04Ensureexceptionreturnusesprocessstack
CPSIEI
BXLR;Exceptionreturnwillrestoreremainingcontext
ALIG
主函数APP.C
#include
#include"utils/uartstdio.h"
#include"lwip/sys.h"
#defineTASK1_PRIO11
#defineTASK2_PRIO3
#definetask1stck1024
#definetask2stck1024
#include"systemInit.h"
#defineLED_PERIPHSYSCTL_PERIPH_GPIOF
#defineLED_PORTGPIO_PORTF_BASE
#defineLED_PINGPIO_PIN_2
#defineLED_PINNGPIO_PIN_3
voidLED0_stack(void*p_arg)
{
//jtagWait();
clockInit();
SysCtlPeriEnable(LED_PERIPH);
GPIOPinTypeOut(LED_PORT,LED_PIN);
for(;;)
{
GPIOPinWrite(LED_PORT,LED_PIN,0x00);
OSTimeDly(OS_TICKS_PER_SEC/4);
GPIOPinWrite(LED_PORT,LED_PIN,0xFF);
OSTimeDly(OS_TICKS_PER_SEC/4);
}
}
voidLED1_stack(void*p_arg)
{
//jtagWait();
clockInit();
SysCtlPeriEnable(LED_PERIPH);
GPIOPinTypeOut(LED_PORT,LED_PINN);
for(;;)
{
GPIOPinWrite(LED_PORT,LED_PINN,0x00);
OSTimeDly(OS_TICKS_PER_SEC/4);z
GPIOPinWrite(LED_PORT,LED_PINN,0xFF);
OSTimeDly(OS_TICKS_PER_SEC/4);
}
}
staticvoidApp_TaskStart(void*p_arg);
intmain(void)
{
BSP_PreInit();
BSP_IntDisAll();
OSInit();
OSTaskCreateExt((void(*)(void*))App_TaskStart,
(void*)0,
(OS_STK*)&App_TaskStartStk[APP_CFG_TASK_START_STK_SIZE-1],
(INT8U)APP_CFG_TASK_START_PRIO,
(INT16U)APP_CFG_TASK_START_PRIO,
(OS_STK*)&App_TaskStartStk[0],
(INT32U)APP_CFG_TASK_START_STK_SIZE,
(void*)0,
(INT16U)(OS_TASK_OPT_STK_CHK|OS_TASK_OPT_STK_CLR));
OSTaskCreate(LED0_stack,(void*)0,
&App_TaskStartStk1[APP_CFG_TASK_START_STK_SIZE-1],0);
OSTaskCreate(LED1_stack,(void*)0,
&App_TaskStartStk2[APP_CFG_TASK_START_STK_SIZE-1],1);
OSStart();//4osstart
}
staticvoidApp_TaskStart(void*p_arg)
{
(void)p_arg;
BSP_PostInit();
Tmr_TickInit();
#if(OS_TASK_STAT_EN>0)
OSStatInit();#endif
for(;;)
{
OSTimeDlyHMSM(0,0,2,0);UARTprintf("\033[2JIamtask1\n");
}
}
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- ucosii 移植 实验 报告
![提示](https://static.bdocx.com/images/bang_tan.gif)