通過IO埠讀取外部資料,帶中斷

2021-08-25 21:30:51 字數 2695 閱讀 6276

基於fl2440開發板,核心版本2.6.28

主機平台:ubuntu 11.04 核心版本2.6.39

驅動**

#include #include #include #include #include #include /*設定中斷方式*/

#include #include #include #include #include //裝置名

#define io_device_name "my_io"

//主裝置號

#define io_device_major 240

//次裝置號

#define io_device_secondary 32

//返回乙個數x的第y位

#define mybit(x,y) ((x>>y)%2)

#ifndef _linux_irqreturn_h

#define _linux_irqreturn_h

typedef int irqreturn_t;

#define irq_none (0)

#define irq_handled (1)

#define irq_retval(x) ((x) != 0)

#endif

/* * s3c2410 gpio edge detection for irqs:

* irqs are generated on falling-edge, rising-edge, both, low level or higg level.

* this must be called *before* the corresponding irq is registered.

*/#define ext_lowlevel 0

#define ext_highlevel 1

#define ext_falling_edge 2

#define ext_rising_edge 4

#define ext_both_edges 6

static int flag_0,flag_2;//中斷轉換標誌

static int cnt;

int data;

declare_wait_queue_head(io_wait);//宣告等待佇列

void io_con_set();

static irqreturn_t io_interrupt_0(int irq,void * dev_id,struct pt_regs *regs)

wake_up_interruptible(&io_wait);

} return irq_handled;

}static irqreturn_t io_interrupt_2(int irq,void * dev_id,struct pt_regs *regs)

wake_up_interruptible(&io_wait);

} return irq_handled;

}static int io_open(struct inode * inode,struct file * file)//開啟裝置函式

ret=request_irq(irq_eint2,io_interrupt_2,irqf_shared,io_device_name,1);//註冊中斷2

if(ret<0)

printk("the device is opened\n");

io_con_set();

cnt=0;

return 0;

}void io_con_set()//io埠控制暫存器初始化

static int io_close(struct inode * inode,struct file * file)//裝置關閉函式

static ssize_t io_read(struct file * filp,char * buff,size_t count,loff_t * f_ops)//讀取io埠

static struct file_operations io_device_fops =

;static int __init io_init(void)//insmod載入驅動時執行

return 0;

}static int __exit io_exit(void)//rmmod解除安裝驅動時執行

module_init(io_init);

module_exit(io_exit);

module_license("gpl");

makefile

obj-m := my_io.o

kerneldir ?= /arm/linux-2.6.28.7-2440

pwd := $(shell pwd)

default:

$(make) -c $(kerneldir) m=$(pwd) modules

clean:

rm -f *.o *.ko *.order *.symvers

呼叫**:

#include #include #include #define my_device "/dev/my_io"

int main()

close(ret);

printf("the device is closed\n");

return 0;

}

通過IO埠讀取外部資料,帶中斷

基於fl2440開發板,核心版本2.6.28 主機平台 ubuntu 11.04 核心版本2.6.39 驅動 include include include include include include 設定中斷方式 include include include include include ...

通過IO埠讀取外部資料,帶中斷

基於fl2440開發板,核心版本2.6.28 主機平台 ubuntu 11.04 核心版本2.6.39 驅動 include include include include include include 設定中斷方式 include include include include include ...

通過 sys 檔案介面操作IO埠

gpio operation 通過 sys 檔案介面操作io埠 gpio到檔案系統的對映 控制gpio的目錄位於 sys class gpio sys class gpio export檔案用於通知系統需要匯出控制的gpio引腳編號 sys class gpio unexport 用於通知系統取消匯...