s3c44b0的中断(uclinux中断)

arm-linux中断驱动程序:                                                             

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
 
#include 
 
#include 
#include 
#include 
 
 
//#define S3C44B0X_INTERRUPT_EINT4567   21      //INTPND bit 21
//irq_number defined in arch/riqs.h 这个头文件被arch/irq.h包含
// asm/irq.h头文件中又包含了arch/irq.h头文件
//中断号是指INTPND寄存器对应的各自的位
 
 
#define MY_44B0_EINT    "myextint"
#define MY_44B0_EINT_MAJOR 230
 
 
static char *dev_idledflash=MY_44B0_EINT;
int led_state,timer_state;
 
 
static ssize_t led_flash_read(struct file *filp,char *buf,size_t cout,loff_t *l)
{
        put_user(led_state,buf);
        return 0;
}
 
 
static ssize_t led_flash_write(struct file *filp,const char *buf,size_t count,loff_t *l)
{
        return 0;
}
 
static void led_flash_irq4(int irq,void *dev_idledflash,struct pt_regs *regs)
{
        disable_irq(S3C44B0X_INTERRUPT_EINT4567);
        if(led_state==0)
        {
                printk("led on\n");
                (*(volatile unsigned int *)S3C44B0X_PDATC) |=0xe;
                //S3C44B0X_PDATC and so on register defined in arch/s3c44b0x.h
                led_state=1;
        }else if(led_state==1){
                printk("led off\n");
                (*(volatile unsigned int *)S3C44B0X_PDATC) &=(~0xe);
                led_state=0;
        }
        mdelay(100);
        enable_irq(S3C44B0X_INTERRUPT_EINT4567);
              (*(volatile unsigned int *)S3C44B0X_EXTINPND)=0xf;  //先清零EXTINPND
        (*(volatile unsigned int *)S3C44B0X_I_ISPC) = \           //然后再清零I_ISPC
(1<

驱动测试程序:

#include 
#include 
#include 
 
static int fd =-1;
 
static int stop=0;
static void *comMonitor(void *data)
{
        getchar();
        stop=1;
        return NULL;
}
 
int main(void)
{
        pthread_t th_com;
        void * retval;
        fd=open("/dev/myextint",O_NONBLOCK,0);
        if(fd<0)
        {
                printf("Can't open\n");
                return -1;
        }
        pthread_create(&th_com,NULL,comMonitor,0);
        printf("\nPress Enter key exit!\n");
        while(stop==0)
        {
                 sleep(1);
        }
        pthread_join(th_com,&retval);
        printf("\n");
        close(fd);
}


你可能感兴趣的:(arm)