小结linux框架下函数如何可以使其被其他文件调用
来源:互联网 发布:牛丁手表怎么样知乎 编辑:程序博客网 时间:2024/05/19 00:09
1:通常export该函数。
2:获取结构体指针:在driver设个全局变量。
下面贴出自己写的xenon flash driver部分代码。
struct xenon_flash_chip {
struct i2c_client *xenon_flash_client;
};
static struct xenon_flash_chip *xenon_chip;
//this is just for debug
int xenon_flash_reread(void)
{
int err = 0;
u8 data;
struct xenon_flash_chip *chip;
if(xenon_chip==NULL)
return err;
chip=xenon_chip;
//read 07
err = xenon_flash_i2c_read(chip->xenon_flash_client,0x07,&data);
if (err < 0)
return err;
CDBG("[xenon_flash]reg_control reg=0x07 data=0x0%x\n",data);
//read 06
err = xenon_flash_i2c_read(chip->xenon_flash_client,0x06,&data);
if (err < 0)
return err;
CDBG("[xenon_flash]reg_control reg=0x06 data=0x0%x\n",data);
//read 04
err = xenon_flash_i2c_read(chip->xenon_flash_client,0x04,&data);
if (err < 0)
return err;
CDBG("[xenon_flash]reg_control reg=0x04 data=0x0%x\n",data);
return err;
}
EXPORT_SYMBOL(xenon_flash_reread);
static int __devinit xenon_flash_i2c_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
int rc = 0;
static const u32 i2c_funcs = I2C_FUNC_SMBUS_BYTE_DATA |
I2C_FUNC_SMBUS_WRITE_WORD_DATA;
struct xenon_flash_chip *chip;
struct xenon_flash_platform_data *pdata;
CDBG("xenon_flash_i2c_probe called!\n");
/* check */
if (client->dev.platform_data == NULL) {
dev_err(&client->dev, "xenon_flash platform data is NULL.
exiting.\n");
return -ENODEV;
}
/* Copy to global variable */
pdata = client->dev.platform_data;
/*check i2c func*/
if (!i2c_check_functionality(client->adapter, i2c_funcs))
return -ENOSYS;
/* Allocate memory for driver data */
chip = kzalloc(sizeof(struct xenon_flash_chip), GFP_KERNEL);
if (!chip)
return -ENOMEM;
xenon_chip = chip;
i2c_set_clientdata(client,chip);
chip->xenon_flash_client = client;
rc = xenon_flash_init_hw(chip,pdata);
if (rc < 0)
CDBG("xenon_flash_init_hw initlised failed!\n");
return 0;
}
在driver调试过程中,通常需要将关键函数export出来,在其他地方extern声明再调用调试。
以上摘自自己写的疝气闪光灯driver.- 小结linux框架下函数如何可以使其被其他文件调用
- 小结linux框架下函数如何可以使其被其他文件调用
- 如何配置window下的linux虚拟机使其可以相互ping
- keil 中如何调用其他文件的函数
- linux当执行程序时,其main函数是如何被调用的
- 调用其他文件py文件的函数
- c++中如何在主函数中调用其他文件内的函数?
- 在form中调用另一个form的方法,函数:fnd_function.execute 如何在form1中调用form2呢?可以使用函数fnd_function.execute。其函数定义如下: fn
- Matlab技巧----调用其他文件夹下函数
- 如何调用其他文件里面的全局变量
- 如何在某.py文件中调用其他.py内的函数
- 【python】如何在某.py文件中调用其他.py内的函数
- 【python】如何在某.py文件中调用其他.py内的函数
- 【python】如何在某.py文件中调用其他.py内的函数
- 如何为eclipse装插件 使其类似IDE 可以查看.ftl文件
- 在windows系统下修改hosts文件,使其可以修改
- python 如何调用另一个路径下py文件的函数
- 如何编写可以调用的DLL函数
- JavaScript创建对象与继承
- 字母a-z,数字0-9,现需要其中任意3个作为密码,请输出所有可能组合。
- Linux 系统内核空间与用户空间通信的实现与分析
- Huffman 编码压缩算法
- 渐渐失去了曾经所拥有的,曾经的人,都渐渐离开了
- 小结linux框架下函数如何可以使其被其他文件调用
- C# 抽取exe和dll程序图标
- 我写的函数
- Java异常处理总结
- POJ1183 公式推导
- linux下判断 串口是否通讯 最简单方法 和android kernel实时打印log方法
- No more feeble excuses!
- 我就一个彻头彻尾的笨蛋:心情日志
- new Option(text,value,true,true);