- 论坛徽章:
- 0
|
/*
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 |
|