s3c44b0的中断(裸板中断)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/chenyefei/article/details/48053333

ads软件的整版测试程序的main.c文件                                            

#include <string.h>
#include "..\inc\option.h"
#include "..\inc\44b.h"
#include "..\inc\44blib.h"
#include "..\inc\def.h"
#include "..\inc\cache.h"
#include "..\inc\uart.h"
#include "..\inc\power.h"
#include "..\inc\dma.h"
#include "..\inc\timer.h"
#include "..\inc\rtc.h"
#include "..\inc\etc.h"
#include "..\inc\iic.h"
#include "..\inc\stop.h"
#include "..\inc\extdma.h"
#include "..\inc\tp.h"
#include "..\inc\usb.h"
#include "..\inc\kb.h"
#include "..\inc\Pwm.h"
#include "..\inc\led.h"
 
extern int Image$$RO$$Base;
void Isr_Init(void);
void HaltUndef(void);
void HaltSwi(void);
void HaltPabort(void);     
void HaltDabort(void);
 
typedef STATUS (* TEST_FUNC)(void);
 
typedef struct tagMenuItem
{
  void* pFunc;
  char* szMenuString;
}MENUITEM, *PMENUITEM;

//****************************************************************
// *           S3C44B0X developer's notes                     * 
// ***************************************************************
MENUITEM g_Menus[] =
{
  { (void *)Test_Cache,            "Cache           " },
  { (void *)Test_Kb,             "keyboard        " },
  { (void *)Test_Uart0,            "UART 0          " },
  { (void *)Test_Uart0Fifo,      "UART 0 FIFO     " },
  { (void *)Test_Uart1,        "UART 1          " },
  { (void *)Test_Uart1Fifo,      "UART 1 FIFO     " },
  { (void *)Test_SlowMode,     "SLOW Mode       " },
  { (void *)Test_HoldMode,       "HOLD Mode       " },
  { (void *)Test_Zdma0,             "Zdma0           " },
  { (void *)Test_Zdma1,             "Zdma1           " },
  { (void *)Test_WDTimer,         "WDTimer         " },
  { (void *)Display_Rtc,           "RTC(display)    " },
  { (void *)Test_Rtc_Alarm,     "RTC(Test)       " },
  { (void *)Test_Rtc_Tick,         "RTC Tick        " },
  { (void *)Test_Iic,              "IIC(AT24C01)    " },
  { (void *)Test_PLL,         "Change PLL      " },
  { (void *)Test_Pwm,         "Test PWM (BEEP) " },
  { (void *)Test_Led,         "Test LED        " },
};
 
void Main(void)
{
  int i;
  int nMenuSize;
  int nMenuSel = 0;
  rSYSCFG=SYSCFG_8KB;//定义缓冲区大小
 
#if (PLLON==1)
  ChangePllValue(PLL_M,PLL_P,PLL_S);
#endif
 
  Isr_Init();
  Port_Init (); 
  Uart_Init (0,115200);
  Uart_Select (0);//选择串口0
  Delay (0);  //calibrate Delay()
  Delay (5000);
 
  nMenuSize = sizeof(g_Menus) / sizeof (MENUITEM);//计算菜单项数目
  for (;;)
  {
    Uart_Printf("\n\n\n             ITSN S3C44B0 Test Program V1.0 (2006-1-20 )\n\n");
    Uart_Printf("\nS3C44B0X Test Program Ver 1.00 rSYSCFG=0x%x MCLK=%d\n\n",rSYSCFG,MCLK);
    for (i = 1; i <= nMenuSize; ++ i)
    {  
      //显示每一项菜单
      Uart_Printf("%2d:%s", i, g_Menus[i - 1].szMenuString);
      if((i%4)==0)
        Uart_Printf("\n");
    }
    //DisplayRtc ();
    Uart_Printf ("\n\nSelect the function to test?");
    nMenuSel = Uart_GetIntNum1 () - 1;
    Uart_Printf("\n");
    if ((nMenuSel >=0) && (nMenuSel <= nMenuSize))
    {
      ((TEST_FUNC)(g_Menus[nMenuSel].pFunc)) ();//执行对应菜单号的函数
    }
  }
}
 
void Isr_Init(void)
{
    U32 i;
   
    pISR_UNDEF=(unsigned)HaltUndef;
    pISR_SWI  =(unsigned)HaltSwi;
    pISR_PABORT=(unsigned)HaltPabort;
    pISR_DABORT=(unsigned)HaltDabort;
    //异常向量重映射
     for(i=_RAM_STARTADDRESS;i<(_RAM_STARTADDRESS+0x20);i+=4)
    {
           *((volatile unsigned *)i)=0xEA000000+((unsigned int) Image$$RO$$Base – \
0x0c000000 -0x08)/4;
    }
       //0xEA000000其实是b指令的反汇编,相对跳转指令。
    //rINTCON=0x1;         // Vectored Int. IRQ enable,FIQ disable   
    rINTCON=0x5;         // Non-vectored,IRQ enable,FIQ disable   
    rINTMOD=0x0;         // All=IRQ mode
    rINTMSK|=BIT_GLOBAL|BIT_EINT4567;       // All interrupt is masked.
}
 
void HaltUndef(void)
{
    Uart_Printf("Undefined instruction exception!!!\n");
    while(1);
}
void HaltSwi(void)
{
    Uart_Printf("SWI exception!!!\n");
    while(1);
}
void HaltPabort(void)
{
    Uart_Printf("Pabort exception!!!\n");
    while(1);
}
void HaltDabort(void)
{
    Uart_Printf("Dabort exception!!!\n");
    while(1);
}

44b0LIB.S                                                                     

; ***********************************************
; * NAME    : assembly function library              *
; * Version : 07.JUL.2000                 *
; ***********************************************
 
       AREA |C$$code|, CODE, READONLY
 
       EXPORT       ChangeMemCon
 
;void ChangeMemCon();
ChangeMemCon
    stmfd   sp!,{r4-r9}           ;Assembler uses the high registers(r4~).
    ldmia   r0,{r1-r9}
    ldr       r0,=0x01c80004  ;BANKCON0 Address
    stmia   r0,{r1-r9}
    ldmfd   sp!,{r4-r9}
mov     pc,lr
 
       EXPORT       DisableInterrupt
DisableInterrupt
;This function works only if the processor is in previliged mode.
NOINT       EQU       0xc0
    mrs      r0,cpsr
    orr       r0,r0,#NOINT
    msr      cpsr_cxsf,r0         
    mov     pc,lr
 
       EXPORT       EnableInterrupt
EnableInterrupt
;This function works only if the processor is in previliged mode.
    mrs      r0,cpsr
    bic       r0,r0,#NOINT
    msr      cpsr_cxsf,r0         
    mov     pc,lr
       END

ads软件中断测试程序                                                                  

void Eint4567_Test( void )
{
       Uart_Printf( "\n外部中断4567 测试!\n" );
       Uart_Printf("本程序的测试之前保证uboot已经在flash中并且可以运行\n\n");
       rINTCON = 0x5 ;           //无向量中断模式
       rINTMOD = 0x0 ;           //All=IRQ mode
 
       //rPCONG = rPCONG | ( 0x3f << 10 );                     //EINT7~5
       //rPUPG = rPUPG & (~(7 << 5)) ;                        //pull up resister is enable
       //rEXTINT = rEXTINT & (~(0xfff << 20)) ;              //EINT567低电平触发中断
      
       rPCONG = rPCONG | ( 0xff << 8 );                  //EINT7~4
       rPUPG = rPUPG & (~(0xf << 4)) ;                        //pull up resister is enable
       rEXTINT = rEXTINT & (~(0xffff << 16)) ;             //EINT4567低电平触发中断
 
       pISR_EINT4567 = (unsigned)Key_Interrupt ;
       rINTMSK = ~( BIT_GLOBAL | BIT_EINT4567 ) ;    //start INT
       Uart_Printf( "\nPlease press the button key1 key2,key3,key4!   Press ESC to Exit!\n" );
       while ( Uart_GetKey() != ESC_KEY)
       {
              Delay(160);
       }
       rINTMSK = BIT_GLOBAL ;                                          //disable INT
}
volatile char which_int_key = 0 ;
void __irq Key_Interrupt(void)
{
       which_int_key = rEXTINTPND;
       rEXTINTPND = 0xf ;            //clear EXTINTPND reg by writing 1(same rI_ISPC)
       rI_ISPC = BIT_EINT4567 ;       //clear pending_bit(rI_ISPC) after clear EXTINTPND
       rPCONG = rPCONG & (~(0x3f << 10));       //GPC567 is input
       switch (which_int_key)
       {//因为Eint4567共享一个中断源,所以用rEXTINTPND来区分是Eint4567的哪个发生
       case 1:
              Uart_Printf("EINT4 had been occured...\r");
              Light_Led (LED_ALL, FALSE);//Light_Led (LED3, TRUE);
              which_int_key = 0;
              break;
       case 2:
              Uart_Printf("EINT5 had been occured...\r");
              Light_Led (LED3, TRUE);
              which_int_key = 0;
              break;
       case 4:
              Uart_Printf("EINT6 had been occured...\r");
              Light_Led (LED2, TRUE);
              which_int_key = 0;
              break;
       case 8:
              Uart_Printf("EINT7 had been occured...\r");
              Light_Led (LED1, TRUE);
              which_int_key = 0;
              break;
       default :
              break;
       }
       while ( (rPDATG&0x00e0) != 0x00e0 ) ;
      Delay( 50 ) ;              //
       //rPCONG = rPCONG | ( 0x3f << 10 );              //EINT7~5
       rPCONG = rPCONG | ( 0xff << 8 );           //EINT7~4
}


猜你喜欢

转载自blog.csdn.net/chenyefei/article/details/48053333