дÁ˸ö¼òµ¥µÄÉ豸Çý¶¯£¬µ÷ÊÔ³öÁËÎÊÌ⣬Çë¸ßÊÖÖ¸Õý£¡£¡£¡
µ÷ÊÔ³öÏÖÈçÏÂÎÊÌ⣺test1.C:47: sorry, not implemented: non-trivial labeled initializers
test1.C:47: invalid conversion from `ssize_t (*)(file*, char*, unsigned int,
loff_t*)' to `loff_t (*)(file*, long long int, int)'
test1.C:47: sorry, not implemented: non-trivial labeled initializers
test1.C:47: invalid conversion from `ssize_t (*)(file*, const char*, unsigned
int, loff_t*)' to `ssize_t (*)(file*, char*, unsigned int, loff_t*)'
test1.C:47: sorry, not implemented: non-trivial labeled initializers
test1.C:47: invalid conversion from `int (*)(inode*, file*)' to `ssize_t
(*)(file*, const char*, unsigned int, loff_t*)'
test1.C:47: sorry, not implemented: non-trivial labeled initializers
test1.C:47: invalid conversion from `int (*)(inode*, file*)' to `int (*)(file*,
void*, int (*)(void*, const char*, int, long long int, long unsigned int,
unsigned int))'
Çë¸÷λ¸øµã½â¾öÒâ¼û£¬Ð»Ð»£¡:'(
$ gcc -D_KERNEL_ -DMODULE -DLINUX -I/usr/src/linux-2.4.20-8/include -c test1.C
Ô´´úÂëÈçÏ£º
#ifndef __KERNEL__
#define __KERNEL__
#endif
#ifndef MODULE
#define MODULE
#endif
#include <linux/config.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h> // printk()
#include <linux/types.h> // size_t
#include <asm/delay.h>
#include <asm/uaccess.h>
MODULE_LICENSE("GPL");
#define MAJOR_NUM 0 //Ö÷É豸ºÅ
static int test_var = 66;
static ssize_t test_read(struct file *filp, char *buf, size_t len, loff_t *f_pos);
static ssize_t test_write(struct file *filp, const char *buf, size_t len, loff_t *f_pos);
static int test_open(struct inode *inode, struct file *file);
static int test_release(struct inode *inode, struct file *file);
static int test_init(void);
static void test_exit(void);
static struct file_operations test_fops ={
owner: THIS_MODULE,
read: test_read,
write: test_write,
open: test_open,
release: test_release,
};
static int test_init(void)
{
int ret=register_chrdev(MAJOR_NUM, "test", &test_fops);
if(ret)
{
printk("test register failure");
}
else
{
printk("test register success!");
}
return ret;
}
static void test_exit(void)
{
int ret=unregister_chrdev(MAJOR_NUM, "test");
if(ret)
{
printk("test unregister failure");
}
else
{
printk("test unregister success");
}
}
static ssize_t test_read(struct file *filp, char *buf, size_t len, loff_t *f_pos)
{
if(copy_to_user(buf, &test_var, sizeof(int)))
{
return - EFAULT;
}
return sizeof(int);
}
static ssize_t test_write(struct file *filp, const char *buf, size_t len, loff_t *f_pos)
{
if(copy_from_user(&test_var, buf, sizeof(int)))
{
return - EFAULT;
}
return sizeof(int);
}
static int test_open(struct inode *inode,struct file *file)
{
MOD_INC_USE_COUNT;
return 0;
}
static int test_release(struct inode *inode,struct file *file)
{
MOD_DEC_USE_COUNT;
return (0);
}
module_init(test_init);
module_exit(test_exit); Çý¶¯ÕýÈ·
±àÒëÃüÁî»òÐí·¾¶ÓÐÎÊÌâ ¼ÈÈ»ÒѾ°ïæ»Ø´ðÁË ÄÇôÄܸø³ö¾ßÌåÏêϸµÄ²Ù×÷Âð£¿Ð»Ð»£¡ ±ÈÈç˵2¡£4¡£20£8
¿´ÆðÀ´ÊÇredhat8
ÄãµÄÈç¹û²»ÊÇ·¾¶¾ÍÓÐÎÊÌâ±àÒëÆ÷Èç¹ûÒ²²»ÊÇÒ²¿ÉÄÜÓÐÎÊÌâ ÎҵľÍÊÇredhat9µÄ
ÎÒÖªµÀÎÊÌâÁË
°Ñ test1.C ¸ÄΪ test1.c ¾ÍOKÁË
ÆäËû ûÓÐÎÊÌâ Õý³£±àÒëͨ¹ý£¡£¡:lol :lol :lol ÎÒ°ÑÄãµÄÀý×ÓÔÚÎҵĶöREDHAT9¡£0ÉϱãÒ˳öºÜ¶à´íÎó£¬ Ëµdelay.h ¡£¡£¶¼ÕÒ²»µ½£¬ ÊDz»ÊÇÎÒÄÄÀïûŪºÃ°¡£¬ Çë°ïæ¿©£¬ »¹Ã»ÔÚLINUXÉϳɹ¦±ãÒ˹ýÒ»¸öÉ豸Çý¶¯£¬ ÓôÃÆÖС£¡£:Q ÔÚregist_chardevÖУ¬Ö÷É豸ºÃΪÁãʱ±íʾ×Ô¶¯»ñÈ¡É豸ºÅ£¬·µ»ØÖµRET²ÅÊÇÄãËùÉêÇëµ½µÄÖ÷É豸ºÅ£¬ÄãÓ¦¸Ã¼°Ê±¸ü¸ÄMAJORµÄÖµ£¬²¢ÇÒÄãûÓÐʹÓÃÉ豸ÎļþϵͳÀ´½¨Á¢Îļþ½Úµã£¬É豸Îļþ½ÚµãµÄ½¨Á¢º¯ÊýΪdevfs_register,²ÎÊýÓкܶ࣬ÆäÖÐÓÐÒ»¸öÊÇ´ÎÉ豸ºÅ¡£
GPIOÇý¶¯
×î½üÔÚѧÇý¶¯£¬µ«ÊÇ¿àÓÚÎÞ´¦ÏÂÊÖ£¬Ï£Íû¸ßÊÖÄÜÌṩ¸öGPIOµÄÇý¶¯¹²Ñ§Ï°£¬Ð»Ð»£¬ÎÒµÄÓÊÏäÊÇ[email]luotuo2761@sohu.com[/email]Ò³:
[1]