6410之點燈驅動

2021-06-16 13:59:04 字數 1695 閱讀 6884

寫乙個點led的驅動分為下面幾個步驟:

1.框架

2.完善硬體的操作

a.看原理圖

b.看6410手冊

c.寫**:

檢視6410原理圖led sch如下:

所以要操作的工作有:

1.設定gpm0 - gpm3為輸出引腳 

2.點燈或者滅燈,對gpmdat 進行操作即可。

3.使用ioremap和iounmap對實體地址進行對映和取消對映。

具體**如下:

#include #include #include #include #include #include #include struct class *first_dev_class;

struct device *first_dev;

volatile unsigned long *gpmcon = null;

volatile unsigned long *gpmdat = null;

static int first_drv_open(struct inode *inode, struct file *file) //裝置節點的相關操作函式

static int first_drv_read(struct file *filp, char __user *buff,

size_t count, loff_t *offp)

ssize_t first_drv_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)

else if(val == 0)

return sizeof(buf);

}static struct file_operations first_drv_fops = ;

int major;

static int __init first_drv_init(void)//入口函式

static void __exit first_drv_exit(void)

module_init(first_drv_init);//入口修飾函式

module_exit(first_drv_exit);

module_license("gpl"); //證書

測試**:

#include #include int main(int argc , char **argv)

if(!strcmp(argv[1],"on"))else if(!strcmp(argv[1],"off"))

fd = open("/dev/shanl",o_rdwr); //開啟裝置節點/dev/shanl

if(fd < 0)

write(fd,&val,4);//向裝置節點做寫操作

return 0;

}

led點燈驅動

核心版本 linux 2.6.32.2 開發板 mini2440 include include include include include include include include include include include include define device name le...

linux系統之字元裝置驅動 點燈

底板核心板 rgb red gpioa28 rgb green gpioe13 rgb blue gpiob12 驅動 程式led dev.c author your name date 2021 02 06 00 06 43 lastedittime 2021 02 23 20 06 05 las...

6410之字元裝置驅動的框架

寫乙個驅動的框架的步驟 file operations,用上面的裝置操作函式來填充它 2.通過 register chrdev將這個file operations結構體告訴核心。3.在驅動的入口函式中呼叫register chrdev,比如first drv init 4.用module init ...