S3C2440启动代码 中断分析

长平狐 发布于 2013/06/03 14:56
阅读 277
收藏 0

1.建立中断向量表

b     ResetHandler;hereis the first instrument 0x00这是第一条执行的指令                  

b     HandlerUndef ;handler for Undefined mode

b     HandlerSWI   ;handler for SWI interrupt

b     HandlerPabort ;handler for PAbort

b     HandlerDabort       ;handler for DAbort

b     .             ;reserved

b     HandlerIRQ    ;handler for IRQ interrupt

b     HandlerFIQ    ;handler for FIQ interrupt

2. 设置缺省中断处理函数

;将普通中断判断程序的入口地址给HandleIRQ

ldr   r0,=HandleIRQ       ;This routine is needed

ldr   r1,=IsrIRQ       ;ifthere isn't 'subs pc,lr,#4' at 0x18, 0x1c

str    r1,[r0]

3.IRQ的中断服务程序

IsrIRQ 

    sub  sp,sp,#4      ;reserved for PC

       stmfd      sp!,{r8-r9}

       ldr   r9,=INTOFFSET   ;地址为0x4a000014的空间存着中断的偏移

       ldr   r9,[r9]

       ldr   r8,=HandleEINT0

       add  r8,r8,r9,lsl#2

       ldr   r8,[r8]

       str    r8,[sp,#8]

       ldmfd      sp!,{r8-r9,pc}

       ;外部中断号判断,通过中断服务程序入口地址存储器的地址偏移确定

   ;PC=[HandleEINT0+[INTOFFSET]]

 

4.中断处理

HandlerFIQ    HANDLER HandleFIQ

HandlerIRQ    HANDLER HandleIRQ

HandlerUndef HANDLER HandleUndef

HandlerSWI   HANDLER HandleSWI

HandlerDabort       HANDLER HandleDabort

HandlerPabort HANDLER HandlePabort

5.将$HandleLabel地址空间中的数据给PC

MACRO

$HandlerLabel HANDLER $HandleLabel

$HandlerLabel

       sub  sp,sp,#4   ;decrementsp(to store jump address)    sp=sp-4

       stmfd      sp!,{r0}  ;PUSH the work register to stack(lr does't push because it return to originaladdress)  r0进栈

       ldr     r0,=$HandleLabel;load the address ofHandleXXX to r0

       ldr     r0,[r0]      ;load the contents(service routine start address) of HandleXXX

       str     r0,[sp,#4]      ;store the contents(ISR) of HandleXXX tostack  r0进栈,将ro中的数据写入sp+4为地址的存储器中

       ldmfd   sp!,{r0,pc}     ;POP the work register and pc(jump to ISR)  恢复r0的值,同时也将$HandleLabel地址空间中的数据给PC

MEND

 ;将$HandleLabel地址空间中的数据给PC,中断服务程序的入口

6 中断向量表

ALIGN

       AREARamData, DATA, READWRITE

       ^   _ISR_STARTADDRESS              ; _ISR_STARTADDRESS=0x33FF_FF00

                                    ;表定位在 RAM 高端,基地址为 _ISR_STARTADDRESS

                                      ;^是MAP的同义词,#是FIELD的同义词

HandleReset   #   4

HandleUndef  #   4

HandleSWI     #   4

HandlePabort    #   4

HandleDabort    #   4

HandleReserved  #   4

HandleIRQ     #   4

HandleFIQ     #   4

HandleEINT0        #  4

HandleEINT1        #  4

HandleEINT2        #  4

HandleEINT3        #  4

HandleEINT4_7            #   4

HandleEINT8_23          #   4

HandleCAM          #  4            ; Added for 2440.

HandleBATFLT             #   4

HandleTICK          #  4

HandleWDT          #  4

HandleTIMER0             #  4

HandleTIMER1             #  4

HandleTIMER2             #  4

HandleTIMER3             #  4

HandleTIMER4         #   4

HandleUART2           #   4

;@0x33FF_FF60

HandleLCD           #  4

HandleDMA0        #  4

HandleDMA1        #  4

HandleDMA2        #  4

HandleDMA3        #  4

HandleMMC          #  4

HandleSPI0           #  4

HandleUART1              #  4

HandleNFCON             #  4            ; Added for 2440.

HandleUSBD         #  4

HandleUSBH         #  4

HandleIIC             #  4

HandleUART0               #  4

HandleSPI1          #  4

HandleRTC           #  4

HandleADC          #   4

7映射(定义一个指针的指针)

/ Exception vector

#define pISR_RESET           (*(unsigned *)(_ISR_STARTADDRESS+0x0))

#define pISR_UNDEF          (*(unsigned *)(_ISR_STARTADDRESS+0x4))

#define pISR_SWI        (*(unsigned *)(_ISR_STARTADDRESS+0x8))

#define pISR_PABORT         (*(unsigned *)(_ISR_STARTADDRESS+0xc))

#define pISR_DABORT        (*(unsigned *)(_ISR_STARTADDRESS+0x10))

#define pISR_RESERVED    (*(unsigned *)(_ISR_STARTADDRESS+0x14))

#define pISR_IRQ         (*(unsigned *)(_ISR_STARTADDRESS+0x18))

#define pISR_FIQ         (*(unsigned *)(_ISR_STARTADDRESS+0x1c))

// Interrupt vector

#define pISR_EINT0            (*(unsigned *)(_ISR_STARTADDRESS+0x20))

#define pISR_EINT1            (*(unsigned *)(_ISR_STARTADDRESS+0x24))

#define pISR_EINT2            (*(unsigned *)(_ISR_STARTADDRESS+0x28))

#define pISR_EINT3            (*(unsigned *)(_ISR_STARTADDRESS+0x2c))

#define pISR_EINT4_7 (*(unsigned *)(_ISR_STARTADDRESS+0x30))

#define pISR_EINT8_23       (*(unsigned *)(_ISR_STARTADDRESS+0x34))

#define pISR_CAM              (*(unsigned *)(_ISR_STARTADDRESS+0x38))         // Added for 2440.

#define pISR_BAT_FLT (*(unsigned *)(_ISR_STARTADDRESS+0x3c))

#define pISR_TICK              (*(unsigned *)(_ISR_STARTADDRESS+0x40))

#define pISR_WDT_AC97           (*(unsigned*)(_ISR_STARTADDRESS+0x44))   //Changedto pISR_WDT_AC97 for 2440A

#define pISR_TIMER0        (*(unsigned*)(_ISR_STARTADDRESS+0x48))

#define pISR_TIMER1        (*(unsigned*)(_ISR_STARTADDRESS+0x4c))

#define pISR_TIMER2         (*(unsigned *)(_ISR_STARTADDRESS+0x50))

#define pISR_TIMER3         (*(unsigned *)(_ISR_STARTADDRESS+0x54))

#define pISR_TIMER4         (*(unsigned *)(_ISR_STARTADDRESS+0x58))

#define pISR_UART2           (*(unsigned *)(_ISR_STARTADDRESS+0x5c))

#define pISR_LCD        (*(unsigned *)(_ISR_STARTADDRESS+0x60))

#define pISR_DMA0            (*(unsigned *)(_ISR_STARTADDRESS+0x64))

#define pISR_DMA1            (*(unsigned *)(_ISR_STARTADDRESS+0x68))

#define pISR_DMA2            (*(unsigned *)(_ISR_STARTADDRESS+0x6c))

#define pISR_DMA3            (*(unsigned *)(_ISR_STARTADDRESS+0x70))

#define pISR_SDI         (*(unsigned *)(_ISR_STARTADDRESS+0x74))

#define pISR_SPI0        (*(unsigned *)(_ISR_STARTADDRESS+0x78))

#define pISR_UART1           (*(unsigned *)(_ISR_STARTADDRESS+0x7c))

#define pISR_NFCON          (*(unsigned *)(_ISR_STARTADDRESS+0x80))         // Added for 2440.

#define pISR_USBD            (*(unsigned *)(_ISR_STARTADDRESS+0x84))

#define pISR_USBH            (*(unsigned *)(_ISR_STARTADDRESS+0x88))

#define pISR_IIC          (*(unsigned *)(_ISR_STARTADDRESS+0x8c))

#define pISR_UART0           (*(unsigned *)(_ISR_STARTADDRESS+0x90))

#define pISR_SPI1        (*(unsigned *)(_ISR_STARTADDRESS+0x94))

#define pISR_RTC        (*(unsigned *)(_ISR_STARTADDRESS+0x98))

#define pISR_ADC              (*(unsigned *)(_ISR_STARTADDRESS+0x9c))

8.一个中断实例

Main()

{

      KeyScan_Test;

}

void KeyScan_Test(void)

{

   pISR_EINT0 =pISR_EINT2 = pISR_EINT8_23 = (U32)Key_ISR;

}

static void __irq Key_ISR(void)

{

 

}


原文链接:http://blog.csdn.net/ce123/article/details/6581270
加载中
返回顶部
顶部