小结linux框架下函数如何可以使其被其他文件调用
来源:互联网 发布:聚客网络 编辑:程序博客网 时间:2024/05/05 11:03
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函数
- 驱动学习站点
- android 发送短信
- Julia曲线的生成
- 二叉树非递归遍历
- 字符串排序
- 小结linux框架下函数如何可以使其被其他文件调用
- U-Boot中Linux的image文件头的定义(启动时间优化)
- 图像处理之图像梯度效果
- 将整数转换为字符串和将字符串转换为整数
- 工作是有计划的学习
- OSPF之五种报文协议
- .NET对存储过程的调用抽象封装
- Target Shell
- book.h的源码