Linux驱动程序

发布时间:2024年01月24日
驱动程序框架:
?
dev_t dev_num;
struct file_operations fops = 
{
    .open =  //define function
    .read =  //define function
    .write = //define function
};

struct cdev dev;

demo_init()
{
MKDEV();
cdev_init();
cdev_add();
register_chrdev_region();
//class_create(); 
//device_create();
}

demo_exit()
{
//init的反向操作
}
module_init(demo_init);    //注册函数
module_exit(demo_exit);    //注销函数
MODULE_LISENCE("GPL");    //许可证声明 

IOCTL函数接口调用

应用层:????????????????ioctl(fd, cmd, ...);
驱动程序:????????????ioctl(struct file, unsigned int, unsigned long);

cmd幻数方向序号 (类型)大小
8bit 2bit8bit14bit
Led x’ 0
Adc
‘y’
100
101
Platform总线
?
struct platform_device { 
const char * name; //匹配的名字
int id; // -1
struct device dev; 
u32 num_resources; //资源数
struct resource * resource; //资源
struct platform_device_id *id_entry; //匹配的id
/* arch specific additions */
struct pdev_archdata archdata;
};
struct resource { 
resource_size_t start;
resource_size_t end;
const char *name;
unsigned long flags;
struct resource *parent, *sibling, *child;
};
extern int platform_device_register(struct platform_device *);
extern void platform_device_unregister(struct platform_device *);
struct platform_driver {
int (*probe)(struct platform_device *);
int (*remove)(struct platform_device *);
void (*shutdown)(struct platform_device *);
int (*suspend)(struct platform_device *, pm_message_t state);
int (*resume)(struct platform_device *);
struct device_driver driver; // ------匹配的名字 ->name 
struct platform_device_id *id_table; //匹配的id
};
extern int platform_driver_register(struct platform_driver *);
extern void platform_driver_unregister(struct platform_driver *);

文章来源:https://blog.csdn.net/qq_58687815/article/details/135830698
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。