您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 酒店餐饮 > 基于ARM7TDMI内核的芯片里多数硬件模块都是可配置的
基于ARM7TDMI内核的芯片里多数硬件模块都是可配置的,需要由软件来设置其需要的工作状态。因此在用户的应用程序之前,需要由专门的一段代码来完成对系统的初始化。由于这类代码直接面对处理器内核和硬件控制器进行编程,一般都是用汇编语言。一般通用的内容包括:中断向量表初始化存储器系统初始化堆栈初始化有特殊要求的断口,设备初始化用户程序执行环境改变处理器模式呼叫主应用程一.中断向量表ARM要求中断向量表必须放置在从0地址开始,连续8X4字节的空间内。每当一个中断发生以后,ARM处理器便强制把PC指针置为向量表中对应中断类型的地址值。因为每个中断只占据向量表中1个字的存储空间,只能放置一条ARM指令,使程序跳转到存储器的其他地方,再执行中断处理。中断向量表的程序实现通常如下表示:AREABoot,CODE,READONLYENTRYBResetHandlerBUndefHandlerBSWIHandlerBPreAbortHandlerBDataAbortHandlerBBIRQHandlerBFIQHandler其中关键字ENTRY是指定编译器保留这段代码,因为编译器可能会认为这是一段亢余代码而加以优化。链接的时候要确保这段代码被链接在0地址处,并且作为整个程序的入口。放在0地址处的中断向量表的ResetHandler一般放在FLASH内,其他中断向量的入口地址可以是FLASH内的,也可以是SDRAM内的,但是在为操作系统初始化时应该为SDRAM的地址。例如作为uClinux的启动代码,此处应该为内存地址。一般有两种实现方式:1.11.第一种实现方式bresetaddpc,pc,#0x0c000000addpc,pc,#0x0c000000addpc,pc,#0x0c000000addpc,pc,#0x0c000000addpc,pc,#0x0c000000addpc,pc,#0x0c000000addpc,pc,#0x0c0000000x0c000000为内存起始地址,uClinux将中断向量放入地址0x0c000008,因为cpu发生中断时仍然会跳转到0地址处的中断向量表中去,所以此处要修改中断向量表的地址,使程序能正确跳转到uClinux实现的中断向量处。此处需要注意,由于ARM系统的三级流水线技术,当程序执行到x地址处,pc指针的值其实等于x+8.在uClinux中实现如下:#ifdefCONFIG_ARCH_S3C44B0#undefvectors_base()#definevectors_base()(0x0c000008)#endif所以addpc,pc,#0x0c000000这条语句将会有8的偏移量。1.22.第二种实现方式:brestldrpc,=0x0c000004ldrpc,=0x0c000008ldrpc,=0x0c00000cldrpc,=0x0c000010b.ldrpc,=0x0c000018//irq中断ldrpc,=0x0c00001c但相应的linux源代码应作修改,这时uClinux中实现如下:#ifdefCONFIG_ARCH_S3C44B0#undefvectors_base()#definevectors_base()(0x0c000000)#endif即只要当发生中断时,cpu发生中断时跳转到0地址处的中断向量表中去,再这里能跳转到uClinux的vectors_base()地址处。ARM7有两种IRQ中断模式(1).向量中断时0地址代码如下:其中从0x20开始处一定要按顺序放入ENTRYbResetHandler;0x00bHandlerUndef;0x04bHandlerSWI;0x08bHandlerPabort;0x0cbHandlerDabort;0x10b.;0x14bHandlerIRQ;0x18bHandlerFIQ;0x1cldrpc,=HandlerEINT0;0x20ldrpc,=HandlerEINT1ldrpc,=HandlerEINT2ldrpc,=HandlerEINT3ldrpc,=HandlerEINT4567ldrpc,=HandlerTICK;0x34b.b.ldrpc,=HandlerZDMA0;0x40ldrpc,=HandlerZDMA1ldrpc,=HandlerBDMA0ldrpc,=HandlerBDMA1ldrpc,=HandlerWDTldrpc,=HandlerUERR01;0x54b.b.ldrpc,=HandlerTIMER0;0x60ldrpc,=HandlerTIMER1ldrpc,=HandlerTIMER2ldrpc,=HandlerTIMER3ldrpc,=HandlerTIMER4ldrpc,=HandlerTIMER5;0x74b.b.ldrpc,=HandlerURXD0;0x80ldrpc,=HandlerURXD1ldrpc,=HandlerIICldrpc,=HandlerSIOldrpc,=HandlerUTXD0ldrpc,=HandlerUTXD1;0x94b.b.ldrpc,=HandlerRTC;0xa0b.b.b.b.b.b.ldrpc,=HandlerADC;0xb42.非向量IRQ中断模式ENTRYbResetHandler;fordebugbHandlerUndef;handlerUndefbHandlerSWI;SWIinterrupthandlerbHandlerPabort;handlerPAbortbHandlerDabort;handlerDAbortb.;handlerReservedbIsrIRQbHandlerFIQ......IsrIRQsubsp,sp,#4;reservedforPCstmfdsp!,{r8-r9}ldrr9,=I_ISPRldrr9,[r9]movr8,#0x00movsr9,r9,lsr#1bcs%F1addr8,r8,#4b%B01ldrr9,=HandleADCaddr9,r9,r8ldrr9,[r9]strr9,[sp,#8]ldmfdsp!,{r8-r9,pc}......HandleADC#4HandleRTC#4HandleUTXD1#4HandleUTXD0#4......HandleEINT3#4HandleEINT2#4HandleEINT1#4HandleEINT0#4;此处通过判断I_ISPR的值可以跳到相应的中断处理函数处。此处的Bootloader采用非向量IRQ中断方式,通过以下头文件的定义可以方便的把中断向量处理函数的地址传入:/*ISR*/#definepISR_RESET(*(unsigned*)(_ISR_STARTADDRESS+0x0))#definepISR_UNDEF(*(unsigned*)(_ISR_STARTADDRESS+0x4))#definepISR_SWI(*(unsigned*)(_ISR_STARTADDRESS+0x8))#definepISR_PABORT(*(unsigned*)(_ISR_STARTADDRESS+0xc))#definepISR_DABORT(*(unsigned*)(_ISR_STARTADDRESS+0x10))#definepISR_RESERVED(*(unsigned*)(_ISR_STARTADDRESS+0x14))#definepISR_IRQ(*(unsigned*)(_ISR_STARTADDRESS+0x18))#definepISR_FIQ(*(unsigned*)(_ISR_STARTADDRESS+0x1c))#definepISR_ADC(*(unsigned*)(_ISR_STARTADDRESS+0x20))#definepISR_RTC(*(unsigned*)(_ISR_STARTADDRESS+0x24))#definepISR_UTXD1(*(unsigned*)(_ISR_STARTADDRESS+0x28))#definepISR_UTXD0(*(unsigned*)(_ISR_STARTADDRESS+0x2c))#definepISR_SIO(*(unsigned*)(_ISR_STARTADDRESS+0x30))#definepISR_IIC(*(unsigned*)(_ISR_STARTADDRESS+0x34))#definepISR_URXD1(*(unsigned*)(_ISR_STARTADDRESS+0x38))#definepISR_URXD0(*(unsigned*)(_ISR_STARTADDRESS+0x3c))#definepISR_TIMER5(*(unsigned*)(_ISR_STARTADDRESS+0x40))#definepISR_TIMER4(*(unsigned*)(_ISR_STARTADDRESS+0x44))#definepISR_TIMER3(*(unsigned*)(_ISR_STARTADDRESS+0x48))#definepISR_TIMER2(*(unsigned*)(_ISR_STARTADDRESS+0x4c))#definepISR_TIMER1(*(unsigned*)(_ISR_STARTADDRESS+0x50))#definepISR_TIMER0(*(unsigned*)(_ISR_STARTADDRESS+0x54))#definepISR_UERR01(*(unsigned*)(_ISR_STARTADDRESS+0x58))#definepISR_WDT(*(unsigned*)(_ISR_STARTADDRESS+0x5c))#definepISR_BDMA1(*(unsigned*)(_ISR_STARTADDRESS+0x60))#definepISR_BDMA0(*(unsigned*)(_ISR_STARTADDRESS+0x64))#definepISR_ZDMA1(*(unsigned*)(_ISR_STARTADDRESS+0x68))#definepISR_ZDMA0(*(unsigned*)(_ISR_STARTADDRESS+0x6c))#definepISR_TICK(*(unsigned*)(_ISR_STARTADDRESS+0x70))#definepISR_EINT4567(*(unsigned*)(_ISR_STARTADDRESS+0x74))#definepISR_EINT3(*(unsigned*)(_ISR_STARTADDRESS+0x78))#definepISR_EINT2(*(unsigned*)(_ISR_STARTADDRESS+0x7c))#definepISR_EINT1(*(unsigned*)(_ISR_STARTADDRESS+0x80))#definepISR_EINT0(*(unsigned*)(_ISR_STARTADDRESS+0x84))通过如下代码就可以实现UART0口的中断处理了:rINTCON=0x5;//Non-vectored,IRQenable,FIQdisablerINTMOD=0x0;//All=IRQmodepISR_URXD0=(unsigned)Uart0_RxInt;当在地址0处将中断向量跳到内存后,相应的中断向量就应该拷贝到内存地址处。把以下代码从FLASH拷贝到SDRAM中:real_vectors:bresetbundefined_instructionbsoftware_interruptbprefetch_abortbdata_abortbnot_usedbirqbfiqundefined_instruction:movr6,#3bendless_blinksoftware_interrupt:movr6,#4
本文标题:基于ARM7TDMI内核的芯片里多数硬件模块都是可配置的
链接地址:https://www.777doc.com/doc-359558 .html