【Linux驱动篇】驱动传参
说明
驱动传参作用:配置驱动的相关参数、模式
参数类型:
- 传递普通参数,如:char,int 类型
- 传递数组
例子
1、传递普通参数
相关函数说明
// name:表示名字;type:表示参数类型;perm:表示参数的权限
module_param(name, type, perm)
代码
#include <linux/init.h>
#include <linux/module.h>
static int a;
module_param(a, int, S_IRUSR);
static int hello_init(void)
{
printk("hello world\n");
printk("a = %d\n",a);
return 0;
}
static void hello_exit(void)
{
printk("byb byb\n");
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL");
2、传递数组
相关函数说明
// name:表示名字;type:表示参数类型;nump:实际传入的参数;perm:表示参数的权限c
module_param_array(name, type, nump, perm)
例子
#include <linux/init.h>
#include <linux/module.h>
static int b[5];
static int count;
module_param_array(b, int, &count, S_IRUSR);
static int hello_init(void)
{
printk("hello world\n");
int i;
for(i= 0;i <count;i++){
printk("b[%d]=%d\n",i,b[i]);
}
printk("count=%d\n",count);
return 0;
}
static void hello_exit(void)
{
printk("byb byb\n");
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL");