OK6410-A开发板硬件手册V2.1.pdf,P5最后一段: …… 3个‘10×2’插针扩展口。其中,一个扩展口包括1路GND、1路DA、8路AD、10路IO、1路SPI;另一个扩展口用来扩展8×8矩阵键盘;第三个扩展口可连接3个TTL电平串口和6路IO(注:3个串口中,包括1个五线串口和2个三线串口) |
6-2-3 开发板驱动源码路径 …… (4)LED驱动 drivers/char/s3c6410_leds.c |
#include #include #include //#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define DEVICE_NAME "leds" static long s3c6410_leds_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { switch(cmd) { unsigned tmp; case 0: case 1: if (arg > 4) { return -EINVAL; } tmp = readl(S3C64XX_GPMDAT); if(cmd==0) //close light { tmp &= (~(1< } else //open light { tmp |= (1< } writel(tmp,S3C64XX_GPMDAT); printk (DEVICE_NAME": %d %dn", arg, cmd); return 0; default: return -EINVAL; } } static struct file_operations dev_fops = { .owner = THIS_MODULE, .unlocked_ioctl = s3c6410_leds_ioctl, }; static struct miscdevice misc = { .minor = MISC_DYNAMIC_MINOR, .name = DEVICE_NAME, .fops = &dev_fops, }; static int __init dev_init(void) { int ret; unsigned tmp; //gpm0-3 pull up tmp = readl(S3C64XX_GPMPUD); tmp &= (~0xFF); tmp |= 0xaa; writel(tmp,S3C64XX_GPMPUD); //gpm0-3 output mode tmp =readl(S3C64XX_GPMCON); tmp &= (~0xFFFF); tmp |= 0x1111; writel(tmp,S3C64XX_GPMCON); //gpm0-3 output 0 tmp = __raw_readl(S3C64XX_GPMDAT); tmp |= 0x10; writel(tmp,S3C64XX_GPMDAT); ret = misc_register(&misc); printk (DEVICE_NAME"tinitializedn"); return ret; } static void __exit dev_exit(void) { misc_deregister(&misc); } module_init(dev_init); module_exit(dev_exit); MODULE_LICENSE("GPL"); MODULE_AUTHOR("FORLINX Inc."); |
#include #include #include //#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //以上的头文件,不管了 //#include #include //飞凌还是比较厚道的,我竟然找到了gpio-bank-c.h文件,里面都定义好了相关的东西,这下省了自己很多工作. #define DEVICE_NAME "wyjgpc"//修改为我的驱动设备名称,不能与已有设备重复 ////////////////////////////////////////////// //名称:s3c6410_wyjgpc_ioctl //功能:控制端口 //参数:*filp:设备文件;cmd:输出高低电平【1/0】,arg:端口【0/7,对应GPC0/GPC7】 static long s3c6410_wyjgpc_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { switch(cmd) { unsigned tmp; case 0: case 1: if (arg > 7) //端口号不能超过7 { return -EINVAL; } tmp = readl(S3C64XX_GPCDAT);//先读数据 if(cmd==0) //输出0 { tmp &= (~(1< } else //输出1 { tmp |= (1< } writel(tmp,S3C64XX_GPCDAT);//写回去 //printk (DEVICE_NAME": %d %dn", arg, cmd);//这行是调试用的 return 0; default: return -EINVAL; } } static struct file_operations dev_fops = { .owner = THIS_MODULE, .unlocked_ioctl = s3c6410_wyjgpc_ioctl,//改为上面的函数名称 }; static struct miscdevice misc = { .minor = MISC_DYNAMIC_MINOR, .name = DEVICE_NAME, .fops = &dev_fops, }; static int __init dev_init(void) { int ret; unsigned tmp; //先将gpc0-7 pull up,数据长度:4*8=32bit tmp = readl(S3C64XX_GPCPUD);// tmp &= (~0xFFFFFFFF); //11111111 11111111 tmp |= 0xAAAAAAAA; //10101010 10101010 writel(tmp,S3C64XX_GPCPUD); //设置gpc0-7 为输出模式,数据长度:2*8=16bit tmp =readl(S3C64XX_GPCCON);//GPCCON 2bit*8port = 16 tmp &= (~0xFFFF); //11111111 11111111 tmp |= 0x1111; //00010001 00010001 writel(tmp,S3C64XX_GPCCON); //输出数据0到gpc0-7,开始置低电平,如果愿意高电平,就输出全1,数据长度:1*8=8bit tmp = __raw_readl(S3C64XX_GPCDAT); tmp |= 0x00; //00000000 writel(tmp,S3C64XX_GPCDAT); ret = misc_register(&misc); //printk (DEVICE_NAME"tinitializedn");//调试用的 return ret; } static void __exit dev_exit(void) { misc_deregister(&misc); } module_init(dev_init); module_exit(dev_exit); MODULE_LICENSE("GPL"); MODULE_AUTHOR("QHDZC Inc.");//好不容易编写了驱动,一定要加入自己公司名称 |
obj-m := wyjgpcio.o CROSS_COMPILE=arm-linux- KERNELDIR ?= /abc/linux2.6.36.2V105/linux-2.6.36.2-v1.05 PWD := $(shell pwd) default: $(MAKE) -C $(KERNELDIR) M=$(PWD) modules clean: $(MAKE) -C $(KERNELDIR) M=$(PWD) clean |
make -C /abc/linux2.6.36.2V105/linux-2.6.36.2-v1.05 M=/abc/wyjgpio modules |
make:进入目录'/abc/linux2.6.36.2V105/linux-2.6.36.2-v1.05' CC [M] /abc/wyjgpio/wyjgpcio.o /abc/wyjgpio/wyjgpcio.c: In function 's3c6410_wyjgpc_ioctl': /abc/wyjgpio/wyjgpcio.c:62: warning: format '%d' expects type 'int', but argument 2 has type 'long unsigned int' Building modules, stage 2. MODPOST 1 modules CC /abc/wyjgpio/wyjgpcio.mod.o LD [M] /abc/wyjgpio/wyjgpcio.ko make:离开目录“/abc/linux2.6.36.2V105/linux-2.6.36.2-v1.05” |
Insmod wyjgpcio.ko |
#include #include #include #include #include #define DEVFILE "/dev/wyjgpc" int main(void) { int m_fd; int i = 0; m_fd = open(DEVFILE,O_RDWR ); if(m_fd < 0 ) { printf("Error opening gpcio!n"); return -1; } printf("gpciodev Opened. Type Enter key to turn on the ledn"); getchar(); getchar(); for(i = 0;i < 7; i++) { ioctl(m_fd, 1, i); printf("opening LED %d!n", i+1); sleep(2); } for(i = 0;i < 7; i++) { ioctl(m_fd, 0, i); printf("Closeing LED %d!n", i+1); sleep(2); } close(m_fd); printf("gpcio dev closed!n"); //system("lsmod"); return 0; } |
更多回帖