📄 gpio_do.c
字号:
//***********************************************#include <linux/fs.h>#include <linux/unistd.h>#include <linux/ioctl.h>#include <linux/module.h>#include <linux/kernel.h>#include <linux/init.h>#include <linux/fcntl.h>#include <asm/uaccess.h>#include <asm-arm/arch-pxa/pxa-regs.h>#include <asm-arm/arch-pxa/xmu255.h>#include <asm-arm/arch-pxa/hardware.h>#define GPIO_MAJOR 253#define GPIO_NAME "GPIO"#define GPIO_VERSION "VERSION0.1"#define cmd_1 0x1#define cmd_2 0x2#define cmd_3 0x3static int gpio_open(struct inode *,struct file *);static int gpio_release(struct inode *,struct file *);static int gpio_ioctl(struct inode *,struct file *,unsigned int,unsigned long);//***********************************************static struct file_operations gpio_fops={ .open = gpio_open, .release = gpio_release, .ioctl = gpio_ioctl,};static struct gpio_set_struct{ unsigned long W_GPDR0; unsigned long W_GPDR1; unsigned long W_GPDR2; unsigned long W_GPSR0; unsigned long W_GPSR1; unsigned long W_GPSR2; unsigned long W_GPCR0; unsigned long W_GPCR1; unsigned long W_GPCR2; unsigned long W_GPLR0; unsigned long W_GPLR1; unsigned long W_GPLR2; unsigned long W_GRER0; unsigned long W_GRER1; unsigned long W_GRER2; unsigned long W_GFER0; unsigned long W_GFER1; unsigned long W_GFER2; unsigned long W_GEDR0; unsigned long W_GEDR1; unsigned long W_GEDR2; unsigned long W_GAFR0_L; unsigned long W_GAFR1_L; unsigned long W_GAFR2_L; unsigned long W_GAFR0_U; unsigned long W_GAFR1_U; unsigned long W_GAFR2_U;}gpio_set1;//*****************************************************************************int __init gpio_init(void){ register_chrdev(GPIO_MAJOR,GPIO_NAME,&gpio_fops); printk("%s %s initialized.\n",GPIO_NAME,GPIO_VERSION); return 0;}module_init(gpio_init);void __exit gpio_exit(void){ unregister_chrdev(GPIO_MAJOR,GPIO_NAME); printk("%s unregisted.\n",GPIO_NAME);}module_exit(gpio_exit);//********************************************************************************static int gpio_open(struct inode *inode,struct file *file){ try_module_get(THIS_MODULE); return 0;}//*********************************************************************************static int gpio_release(struct inode *inode,struct file *file){ module_put(THIS_MODULE); return 0;}//**********************************************************************************static int gpio_ioctl(struct inode *inode,struct file *file,unsigned int cmd,unsigned long arg){ //static struct gpio_set_struct gpio_set1; copy_from_user(&gpio_set1,(void *)arg,sizeof(gpio_set1)); printk("now go int the ioctl\n"); switch(cmd) { case cmd_1: gpio_set1.W_GPLR0=GPLR0; gpio_set1.W_GPLR1=GPLR1; gpio_set1.W_GPLR2=GPLR2; gpio_set1.W_GPDR0=GEDR0; gpio_set1.W_GPDR1=GEDR1; gpio_set1.W_GPDR2=GEDR2; gpio_set1.W_GAFR0_L=GAFR0_L; gpio_set1.W_GAFR1_L=GAFR1_L; gpio_set1.W_GAFR2_L=GAFR2_L; gpio_set1.W_GAFR0_U=GAFR0_U; gpio_set1.W_GAFR1_U=GAFR1_U; gpio_set1.W_GAFR2_U=GAFR2_U; copy_to_user((void *)arg,&gpio_set1,sizeof(gpio_set1)); printk("now go in the cmd1\n"); return 0; case cmd_2: GPSR0=GPSR0|gpio_set1.W_GPSR0; GPSR1=GPSR1|gpio_set1.W_GPSR1; GPSR2=GPSR2|gpio_set1.W_GPSR2; GPCR0=GPCR0|gpio_set1.W_GPCR0; GPCR1=GPCR1|gpio_set1.W_GPCR1; GPCR2=GPCR2|gpio_set1.W_GPCR2; GPDR0=GPDR0|gpio_set1.W_GPDR0; GPDR1=GPDR1|gpio_set1.W_GPDR1; GPDR2=GPDR2|gpio_set1.W_GPDR2; GRER0=GRER0|gpio_set1.W_GRER0; GRER1=GRER1|gpio_set1.W_GRER1; GRER2=GRER2|gpio_set1.W_GRER2; GFER0=GFER0|gpio_set1.W_GFER0; GFER1=GFER1|gpio_set1.W_GFER1; GFER2=GFER2|gpio_set1.W_GFER2; GAFR0_L=GAFR0_L|gpio_set1.W_GAFR0_L; GAFR1_L=GAFR1_L|gpio_set1.W_GAFR1_L; GAFR2_L=GAFR2_L|gpio_set1.W_GAFR2_L; GAFR0_U=GAFR0_U|gpio_set1.W_GAFR0_U; GAFR1_U=GAFR1_U|gpio_set1.W_GAFR1_U; GAFR2_U=GAFR2_U|gpio_set1.W_GAFR2_U; printk("now go in the cmd2\n"); printk("now the value of GPLR1 is %x\n",GPLR1); printk("now the value of GAFR1_L is %x\n",GAFR1_L); return 1; case cmd_3: GPLR0=GPLR0&gpio_set1.W_GPLR0; GPLR1=GPLR1&gpio_set1.W_GPLR1; GPLR2=GPLR2&gpio_set1.W_GPLR2; printk("now go in the cmd3\n"); return 2; default: printk("please input the value of cmd\n"); return 3; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -