s3c6410 的外部中断实现
EINT0CON0 External Interrupt 0(Group0) Configuration Register 0
设置 外部中断的触发方式(高电平等)
EINT0PEND External Interrupt 0(Group0) Pending Register 屏蔽前的中断(谁中断,相应位置1)
EINT0MASK External Interrupt 0(Group0) Mask Register 屏蔽(屏蔽谁,相应位置1)
以上两个是管脚级别(GPIO)的pending和mask寄存器;
下边是中断控制器的pending和mask寄存器
VIC0INTENABLE Interrupt Enable Register (VIC0) //相当于mask寄存器
VIC0IRQSTATUS IRQ Status Register (VIC0) 相当与pending寄存器
程序代码
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
s3c6410外部中 相关文章:
- 深入理解ARM体系架构S3C6410外部中断控制实例(11-20)
- s3c6410---外部中断---key (基于OK6410)(11-09)
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)