免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 753 | 回复: 0
打印 上一主题 下一主题

led [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-03-05 23:31 |只看该作者 |倒序浏览
/*
the program works on my ARM, i am so happy!
when i insmod led2.ko (led2 is this file), two leds extingushed at once.
then i#mknod /dev/leds c 231 0  #./ledapp 0 1
one of them is lighted again.
*/
#include
#include
#include
#include
#include
#include
//Please configure your kernel first to use the following headers, because the directory "asm" is a short cut to your arch's "asm" directory.
//So do the headers in the "hardware" sub directory.
#include   //This header is for ioremap(), iounmap().
#include   //This header is for get_user(), put_user().
#define NAME "led_test"
static int major = 231;  //Define device major
unsigned long * pREG;  //Definition of register base.
static ssize_t led_test_write(struct file *file, const char __user *data, size_t len, loff_t *ppos)
{
char buf[256];
size_t i;
for (i = 0; i > 8) % 256;
rbuf[2] = (tmp >> 16) % 256;
rbuf[3] = (tmp >> 24) % 256;

if (len > 4)
  return 0;
for (i = 0; i  3)
    return -EINVAL;
   if (!cmd)
    * (volatile unsigned long *)(pREG + 1) |= (0x10  63)
  return -EINVAL;
printk("LED Test driver opened!\n");
return nonseekable_open(inode, file);
}
static int led_test_release(struct inode *inode, struct file *file)
{
printk("LED Test driver released!\n");
return 0;
}
static struct file_operations led_test_fops = {
.owner   = THIS_MODULE,
.ioctl   = led_test_ioctl,
.write   = led_test_write,
.read    = led_test_read,
.open    = led_test_open,
.release = led_test_release,
};
static int __init led_test_init(void)
{
int ret;
unsigned long tmp;

printk("LXZ LED Test Driver.\n");
ret = register_chrdev(major, NAME, &led_test_fops);
if (ret
#include
  
int main(int argc, char **argv)
{
  int fd;
  int on, led_no;
  char buf[256] = {"1234567890"};
  unsigned long tmp;

if (argc != 3 || sscanf(argv[1], "%d", &led_no) != 1 || sscanf(argv[2], "%d", &on) != 1 || on  1 || led_no 3)
{
  fprintf(stderr, "Usage: leds led_no 0|1\n");
  exit(1);
}

fd = open("/dev/leds", O_RDWR);
if (fd


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/56913/showart_490189.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP