2013-10-05 实验之LED灯全关,全开
来源:互联网 发布:蜂群算法 pid 编辑:程序博客网 时间:2024/04/29 09:04
实验描述:LED灯全关,全开
注意事项:开发板默认已有Led点灯的示例,要将其关闭,否则,看不到效果。
内核版本:Linux 2.6.38
开发板: Mini 6410
电路原理:
驱动程序:
#include <linux/init.h> #include <linux/module.h> #include <linux/device.h>#include <asm/uaccess.h>#include <linux/kdev_t.h>#include <linux/fs.h>#include <asm/io.h>/* Kernel Version: Linux 2.6.38 Arm Version: Mini 6410*/#define MyPrintk printkstatic dev_t Leds_Major ;static char * DEVICE_NAME = "MyLeds";static struct class *leds_class;volatile unsigned long *gpkcon0 = NULL;volatile unsigned long *gpkdat = NULL;static int leds_init (struct inode *inode, struct file *file){*gpkcon0 &= ~( (0xF<<4*4) | (0xF<<5*4) | (0xF<<6*4) | (0xF<<7*4));*gpkcon0 |= ( (0x1<<4*4) |(0x1<<5*4) | (0x1<<6*4) | (0x1<<7*4)); *gpkdat |= (1<<4) | (1<<5) | (1<<6) | (1<<7) ;MyPrintk ("Leds Open gpkcon0: %lu\n",*gpkcon0); MyPrintk ("Leds Open gpkdat: %lu\n",*gpkdat); return 0;}static ssize_t leds_write (struct file *file, const char __user *buffer, size_t count, loff_t * ppos){ int val; unsigned long ret = copy_from_user(&val,buffer,count);if (ret != 0){MyPrintk ("value error%lu\n", ret); return -1;}MyPrintk ("value %d\n", val); if(val == 1){ *gpkdat &= ~ ((1<<4) | (1<<5) | (1<<6) | (1<<7)) ; MyPrintk ("Leds On gpkdat:%lu\n",*gpkdat); }else if(val == 0){*gpkdat |= (1<<4) | (1<<5) | (1<<6) | (1<<7) ;MyPrintk ("Leds Off gpkdat:%lu\n",*gpkdat); }return 0;}static struct file_operations s3c64XX_leds_fops = {.owner = THIS_MODULE,.write = leds_write,.open = leds_init,};static int myleds_init(void) { Leds_Major = register_chrdev(Leds_Major,DEVICE_NAME , &s3c64XX_leds_fops);if(Leds_Major < 0){MyPrintk (KERN_EMERG "Sorry, Can not register the leds device!\n"); }MyPrintk (KERN_EMERG " Register the leds device\n"); leds_class = class_create(THIS_MODULE, "FirstLeds"); device_create(leds_class, NULL , MKDEV(Leds_Major, 0), NULL, "XYZ"); gpkcon0 = (volatile unsigned long *)ioremap(0x7F008800, 16); gpkdat = gpkcon0 + 2; return 0; } static int myleds_exit(void) { unregister_chrdev(Leds_Major, DEVICE_NAME); device_destroy(leds_class,MKDEV(Leds_Major, 0)); class_destroy(leds_class); MyPrintk (KERN_EMERG "MyLeds ByeBye\n"); return 0; } module_init(myleds_init); module_exit(myleds_exit);MODULE_LICENSE("GPL");
测试应用程序
#include<stdio.h>#include<fcntl.h>int main(int argc, char **argv){int fd;int val = 1;fd = open("/dev/XYZ", O_RDWR);if (fd < 0){printf("Sorry, can't open!\n");}if (argc != 2){printf("Usage :\n");printf("%s <on|off>\n", argv[0]);return 0;}if (strcmp(argv[1], "on") == 0){val = 1;}else{val = 0;}write(fd, &val, 4);return 0;}
- 2013-10-05 实验之LED灯全关,全开
- 2013-10-06 实验之Led跑马灯
- 2013-10-07 实验之按键中断控制Led
- 2013-10-08 实验之定时器控制Led等闪烁
- 2013-10-13 实验之ioctl控制Led
- s5pv210裸机实验之led
- led实验
- LED实验
- 2013-11-17 实验之裸板按键控制Led灯
- Mini2440 裸机实验之LED程序、按键、中断
- 字符设备驱动之led灯的控制实验
- led灯实验之字符设备驱动poll操作
- CC2530基础实验之串口控制LED灯
- 【单片机】LED实验
- LED灯控制实验
- ARM LED实验
- 按键 led灯实验
- LED控制实验
- poj2502 Subway最短路
- [Python]使用csv dialect 读写数据
- 教孩子们编程 ——附相关有用的资料
- 【leetcode】Palindrome Partitioning
- 网络流-poj3469
- 2013-10-05 实验之LED灯全关,全开
- Oracle需要启动的服务总结
- 机房收费系统总结之7——存储过程
- ant 最基本的入门
- groovy-java
- linux 驱动中insmod与mknod各自的作用
- 异步(Asynchronous)机制(二)--异步消息机制以及Hadoop RPC
- Lead the bidirectional circular linked list——双向循环链表
- 黑马程序员高薪就业学习方法揭秘