新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > s3c6410 的外部中斷實現(xiàn)

s3c6410 的外部中斷實現(xiàn)

作者: 時間:2016-11-11 來源:網(wǎng)絡(luò) 收藏
6410各個中斷寄存器的關(guān)系 圖


EINT0CON0 External Interrupt 0(Group0) Configuration Register 0
設(shè)置 外部中斷的觸發(fā)方式(高電平等)
EINT0PEND External Interrupt 0(Group0) Pending Register 屏蔽前的中斷(誰中斷,相應(yīng)位置1)
EINT0MASK External Interrupt 0(Group0) Mask Register 屏蔽(屏蔽誰,相應(yīng)位置1)
以上兩個是管腳級別(GPIO)的pending和mask寄存器;
下邊是中斷控制器的pending和mask寄存器
VIC0INTENABLE Interrupt Enable Register (VIC0) //相當于mask寄存器
VIC0IRQSTATUS IRQ Status Register (VIC0) 相當與pending寄存器

本文引用地址:http://m.butianyuan.cn/article/201611/316680.htm

程序代碼
main.c
//led
#define GPKCON (*(volatile unsigned int *)0x7f008800)
#define GPKDAT (*(volatile unsigned int *)0x7f008808)

//button
#define GPNCON (*(volatile unsigned int *)0x7F008830)
#define GPNDAT (*(volatile unsigned int *)0x7F008834)

//beep
#define GPFCON (*(volatile unsigned int *)0x7F0080A0)
#define GPFDAT (*(volatile unsigned int *)0x7F0080A4)
//
#define EINT0CON0 (*(volatile unsigned int *)0x7F008900)
#define EINT0MASK (*(volatile unsigned int *)0x7F008920)

#define EINT0PEND (*(volatile unsigned int *)0x7F008924)

//////interrupt contruller
#define VIC0IRQSTATUS (*(volatile unsigned int *)0x71200000)
#define VIC0INTENABLE (*(volatile unsigned int *)0x71200010)


#define VIC0RAWINTR (*(volatile unsigned int *)0x71200008)
int led_init(void)
{
//GPK4//
GPKCON |= 1<<16;
GPKCON &= ~(1<<17 | 1<<18 | 1<<19);
//GPK5//
GPKCON |= 1<<20;
GPKCON &= ~(1<<21 | 1<<22 | 1<<23);
//GPK6//
GPKCON |= 1<<24;
GPKCON &= ~(1<<25 | 1<<26 | 1<<27 );
//GPK7//
GPKCON |= 1<<28;
GPKCON &= ~(1<<29 | 1<<30 | (unsigned)1<<31);
return 0;
}
void led_value(int value)
{
GPKDAT = ~value << 4;
}
void led_on(void)
{
GPKDAT =0;
}
void led_off(void)
{
GPKDAT = 0xf0;
}
void delay(void)
{
int i = 0;
for(i = 0; i <500000; i++);
}
void led_blink(void)
{
led_on();
delay();
led_off();
delay();
}
void beep_init(void)
{
GPFCON |= 1<<28;
GPFCON &= ~(1<<29);
}
void beep_on(void)
{
GPFDAT |= 1<<14;
}
void beep_off(void)
{
GPFDAT &= ~(1<<14);
}
void beep(void)
{
beep_on();
delay();
beep_off();
delay();
}
void do_irq()
{
//at start, clear pending bit
EINT0PEND = 1<<0;
beep();
/*
void (*pf)(void);
pf = vicoaddress;
(*pf)();
*/
}
void irq_handler(void);

void test(void)
{
GPFDAT |= 1<<14;
}
int mymain(void)
{
int *p;
int counter = 0;
led_init();

beep_init();
//beep();
//GPFDAT |= 1<<14;

//GPNCON &= ~(1<<0 | 1<<1);
//111111GPN0[1:0] interrupt
GPNCON |= 1<<1;
GPNCON &= ~(1<<0);

//2222 EINT0CON1[2:0]
EINT0CON0 &= ~(1<<2);
EINT0CON0 |= 1<<1;

//33333 EINT0MASK[0]
EINT0MASK &= ~(1<<0);
//EINT0MASK |= 1<<0;
//444444 VIC0INTENABLE
VIC0INTENABLE |= 1<<0;
//VIC0INTENABLE &= ~(1<<0);
//555555
//VIC0RAWINTR &= ~(1<<0);
// arm core I_BIT :enable IRQ
__asm
{
mov r0, #0x53
msr CPSR_cxsf, r0
}
p = (int *)0x18;
*p = 0xe59ff000;
p = (int *)0x20;
*p = (int)irq_handler;

/*
VIC0VECADDR0 = beep1;
VIC0VECADDR0 = beep2;
*/
while(1)
{
if(VIC0IRQSTATUS &(1<<0))
{
beep();
}
led_value(counter & 0x0f);
counter++;
delay();
//if(GPNDAT & (1<<0))
//led_on();
//else
//led_off();
}
return 0;
}

start.s文件

AREA int, CODE, READONLY
import mymain

ENTRY
;sp_irq mode
mov r0, #0xd2
msr cpsr_cxsf,r0
ldr sp, =0x50200000

;sp_svc mode
mov r0, #0xd3
msr cpsr_cxsf, r0
ldr sp, =0x50100000

b mymain
import do_irq
export irq_handler
irq_handler
;push rets to stack
stmfd sp!,{r0-r12,lr} //r0-r12 和lr壓棧保護;

;handler
bl do_irq
;pop stack to regs
ldmfd sp!, {r0-r12,lr}
subs pc, lr,#4

END



關(guān)鍵詞: s3c6410外部中

評論


技術(shù)專區(qū)

關(guān)閉