主题 : S3c2440按键中断问题 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 78698
精华: 0
发帖: 10
金钱: 50 两
威望: 10 点
综合积分: 20 分
注册时间: 2012-09-24
最后登录: 2013-04-23
楼主  发表于: 2013-01-25 14:16

 S3c2440按键中断问题

各位大侠,我用的是minis3c2440的开发板,在学习光盘S6中断这部分内容,通过J-Link和USB转串口线在线调试光盘中已经写好的按键中断程序,使用Uv4软件调试,secureCRT终端显示,问题是按下开发板上的按键,终端没显示出触发哪个中断和按下了哪个按键,却显示U-Boot 2010.03 (11链?13 2011 - 03:06:31) I2C: ready DRAM: 64 MB Flash: 2 MB,能帮我解答一下不,各位大侠,感激不尽啊?
部分代码如下:
/****************************************************************************************
* File:    keyscan.c
*****************************************************************************************/

#include "def.h"
#include "option.h"
#include "2440addr.h"
#include "2440lib.h"
#include "2440slib.h"
//#include "led_test.h"

/******************************************************************************
六个按键的输入引脚:    
                EINT8 -----( GPG0  )----INPUT     K1
                EINT11-----( GPG3 ) ----INPUT      K2
                EINT13-----( GPG5  )----INPUT     K3
                EINT14-----( GPG6 )---- INPUT      K4            
                EINT15-----( GPG7  )----INPUT     K5
                EINT19-----( GPG11 )----INPUT      K6
                
二级中断源:EINT8、EINT11、EINT13、EINT14、EINT15、EINT19
对应的一级中断源为:EINT8_23

二级中断源对应的寄存器:
EXTINT1、EXTINT2、EINTPEND、EINTMASK、

一级中断源对应的寄存器:
SRCPND、INTPND、INTMSK        

GPIO对应寄存器:
GPGCON、GPGDAT        
******************************************************************************/

//扫描6按键所接GPIO口,观察GPIOx电平值,键按下:低电平; 键抬起:高电平
//返回当前按下键所对应的键值
U8 Key_Scan( void )
{
    Delay( 80 ) ;

    if(      (rGPGDAT&(1<< 0)) == 0 )     // K1按下
        return 1 ;
    else if( (rGPGDAT&(1<< 3)) == 0 )    // K2按下
        return 2;
    else if( (rGPGDAT&(1<< 5)) == 0 )      // K3按下
        return 3 ;
    else if( (rGPGDAT&(1<< 6)) == 0 )     // K4按下
        return 4 ;
    else if( (rGPGDAT&(1<< 7)) == 0 )      // K5按下
        return 5 ;
    else if( (rGPGDAT&(1<< 11)) == 0 )      // K6按下
        return 6 ;
    else
        return 0xff;      
}

// 按键中断处理程序
void __irq Key_ISR(void)
{
    U8 key;
    U32 r;
//    Uart_Printf("\nKey_ISR+!\n");
    EnterCritical(&r); // 进入临界区
    if(rINTPND==BIT_EINT8_23) {      //判断INTPEND寄存器中是否为EINT8_23触发中断,如果EINT8_23触发中断,则INTPEND寄存器中对应bit位被置一
        ClearPending(BIT_EINT8_23);     //清空BIT_EINT8_23位
        // 继续比较EINTPEND寄存器,确定外面中断源
        if(rEINTPEND&(1<<8)) {     //EINT8触发中断
            Uart_Printf("eint8\n");
            rEINTPEND |= 1<< 8;     // 清空EINTPEND寄存器中EINT8对应的位
        }
        if(rEINTPEND&(1<<11)) {       //EINT11触发中断
            Uart_Printf("eint11\n");        
            rEINTPEND |= 1<< 11;
        }
        if(rEINTPEND&(1<<13)) {       //EINT13触发中断
            Uart_Printf("eint13\n");
            rEINTPEND |= 1<< 13;
        }
        if(rEINTPEND&(1<<14)) {        //EINT14触发中断
            Uart_Printf("eint14\n");        
            rEINTPEND |= 1<< 14;
        }
        if(rEINTPEND&(1<<15)) {        //EINT15触发中断
            Uart_Printf("eint15\n");
            rEINTPEND |= 1<< 15;
        }
        if(rEINTPEND&(1<<19)) {         //EINT19触发中断
            Uart_Printf("eint19\n");        
            rEINTPEND |= 1<< 19;
        }

    }
    key = Key_Scan();    //扫描GPGx端口,返回按键键值
    if( key != 0xff )
        Uart_Printf( "Interrupt occur... K%d is pressed!\n", key) ;

    ExitCritical(&r);  // 出临界区
//    Uart_Printf("\nKey_ISR-!\n");
}
      
void KeyScan_Test(void)
{
    Uart_Printf("\nKey Scan Test, press ESC key to exit !\n");    

    // 配置GPGCON,设置6按键对应的GPGx管脚功能为外部中断引脚EINT
    rGPGCON = rGPGCON & (~((3<<0)|(3<<6))) | ((2<<0)|(2<<6)) ;        //GPG0,3 set EINT
    rGPGCON = rGPGCON & (~((3<<10)|(3<<12))) | ((2<<10)|(2<<12)) ;        //GPG5,6 set EINT
    rGPGCON = rGPGCON & (~((3<<14)|(3<<22))) | ((2<<14)|(2<<22)) ;        //GPG7,11 set EINT
    
    // 设置中断触发方式
    rEXTINT1 &= ~(7<<0);
    rEXTINT1 |= (2<<0);         //set eint8 falling edge int

    rEXTINT1 &= ~(7<<12);
    rEXTINT1 |= (2<<12);    //set eint11 falling edge int

    rEXTINT1 &= ~(7<<20);
    rEXTINT1 |= (2<<20);    //set eint13 falling edge int

    rEXTINT1 &= ~(7<<24);
    rEXTINT1 |= (2<<24);    //set eint14 falling edge int

    rEXTINT1 &= ~(7<<28);
    rEXTINT1 |= (2<<28);    //set eint15 falling edge int

    rEXTINT2 &= ~(7<<12);
    rEXTINT2 |= (2<<12);    //set eint19 falling edge int
    
/*    // 将按键中断处理程序注册,入口地址对应EINT8_23中断IRQ
    pISR_EINT8_23 = (U32)Key_ISR;     */
    
    rEINTPEND = 0xFFFFFF;      //清空 EINTPEND中断请求
    rSRCPND = BIT_EINT8_23; //to clear the previous pending states in SRCPND
    rINTPND = BIT_EINT8_23;  //  to clear the previous pending states in INTPND
    
    rEINTMASK=~( (1<<8)|(1<<11)|(1<<13)|(1<<14)|(1<<15)|(1<<19) );    //清空六个外部中断对应的中断屏蔽位
    rINTMSK=~(BIT_EINT8_23); // 清空BIT_EINT8_23对应的中断屏蔽位

    // 将按键中断处理程序注册,入口地址对应EINT8_23中断IRQ
    pISR_EINT8_23 = (U32)Key_ISR;
    

    Uart_Printf("\nPlease press the Key to test !\n");
    Uart_Printf("\nrINTMSK=0x%x\n",rINTMSK);
//    led_test();
    while( Uart_GetKey() != ESC_KEY );  // 无限循环,直到用户键入ESC键,退出。但此时可被中断打断
    Uart_Printf("\nExit Int test !\n");
    rEINTMASK=0xFFFFFF;    // 重新设置EINTMASK屏蔽位
    rINTMSK=BIT_ALLMSK;    // 重新设置INTMSK屏蔽位
}

*********************************************************************************************************************

/*********************************************************************************************
* File:    main.c
* Author:    Hanson
* 嵌入式家园   www.embedclub.com
* 上海嵌入式家园-开发板商城   http://embedclub.taobao.com
* Desc:    interrupt keys test
* History:    May 16th 2011
*        
*********************************************************************************************/

#include "def.h"
#include "option.h"
#include "2440addr.h"     //
#include "2440lib.h"
#include "2440slib.h"     //void MMU_EnableDCache();
//#include "int_test.h"
//================================

void Isr_Init(void);
void HaltUndef(void);
void HaltSwi(void);
void HaltPabort(void);
void HaltDabort(void);



void dely(U32 tt)
{
   U32 i;
   for(;tt>0;tt--)
   {
     for(i=0;i<10000;i++){}
   }
}
  

int main(int argc, char **argv)
{
    int i;
    U8 key;
    U32 mpll_val=0;
    
    i = 2 ;    //hzh, don't use 100M!
        //boot_params.cpu_clk.val = 3;
    switch ( i ) {
    case 0:    //200
        key = 12;
        mpll_val = (92<<12)|(4<<4)|(1);
        break;
    case 1:    //300
        key = 13;
        mpll_val = (67<<12)|(1<<4)|(1);
        break;
    case 2:    //400
        key = 14;
        mpll_val = (92<<12)|(1<<4)|(1);
        break;
    case 3:    //440!!!
        key = 14;
        mpll_val = (102<<12)|(1<<4)|(1);
        break;
    default:
        key = 14;
        mpll_val = (92<<12)|(1<<4)|(1);
        break;
    }
    
    //init FCLK=400M, so change MPLL first
    ChangeMPllValue((mpll_val>>12)&0xff, (mpll_val>>4)&0x3f, mpll_val&3);
    ChangeClockDivider(key, 12);      
    
    // Port Init
    Port_Init();

    // ISR init
    Isr_Init();

    Uart_Init(0,115200);
    Uart_Select(0);

    Uart_Printf("\nInt Test!!!\n");
  
    // Int test
    KeyScan_Test();    
    while(1);                    
}

//===================================================================
void Isr_Init(void)
{
    pISR_UNDEF  = (unsigned)HaltUndef;
    pISR_SWI    = (unsigned)HaltSwi;
    pISR_PABORT = (unsigned)HaltPabort;
    pISR_DABORT = (unsigned)HaltDabort;
    
   // rINTMOD     = 0x0;                     //All=IRQ mode
    //rINTMSK     = BIT_ALLMSK;              //All interrupt is masked.

    rINTMOD     = 0x0;                     // All=IRQ mode
    rSRCPND     = rSRCPND;                 // clear all interrupt
    rINTPND     = rINTPND;                 // clear all interrupt
    rINTMSK     = BIT_ALLMSK;              // All interrupt is masked.
    rINTSUBMSK  = BIT_SUB_ALLMSK;          // All sub-interrupt is masked.
// External interrupt will be falling edge triggered.
    rEXTINT0 = 0x22222222;    // EINT[7:0]
    rEXTINT1 = 0x22222222;    // EINT[15:8]
    rEXTINT2 = 0x22222222;    // EINT[23:16]      
}
//===================================================================

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);
}