【Linux驱动篇】驱动传参

【Linux驱动篇】驱动传参

说明

驱动传参作用:配置驱动的相关参数、模式

参数类型:
  1. 传递普通参数,如:char,int 类型
  2. 传递数组
例子
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");
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MagicKingC

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值