EXPORT_SYMBOL是导出符号.导出给在kernel中别的的模块使用.
Linux symbol export method:
[1] If we want export the symbol in a module, just use theEXPORT_SYMBOL(xxxx)in the C or H file.
And compile the module by adding the compile flag-DEXPORT_SYMTAB.
Then we can use thexxxxin the other module.
[2] If we want export some symbol in Kernel that is not in a module such asxxxxin the/arch/ppc/fec.c.
Firstly, define thexxxxin thefec.c;
Secondly, make a new file which contain the"extern"define thexxxx(for example, extern intxxxx);
Lastly, in theppc_ksyms.cwe includes the new file, and add theEXPORT_SYMBOL(xxxx).
Then we can use thexxxx.
使用时注意事项:
在使用EXPORT_SYMBOL 的.c文件中 需要 #include <linux/module.h> 文件。
实际遇到的例子:
gpio口做一个Fn按键,在按下Fn按键的时候,需要gpio_matrix按键矩阵模块来处理.
gpio按键模块在
gpio_keys.c (kernel/drivers/input/keyboard)
定义一个flag
unsigned int Fn_flag =0;//liwei
在static void gpio_keys_gpio_report_event函数中处理GPIO的按键,如果有按下,就设置flag
static void gpio_keys_gpio_report_event(struct gpio_button_data *bdata)
{
......
printk("%s :%d button->code=%d\n",__func__,__LINE__,button->code);//liwei
if(button->code == 302)//KEY_GPIO_KEY_FN=302 in input.h
{
Fn_flag =1;
}
......
}
为了这个Fn _flag可以在别的模块使用, 做两个函数用来改变和记录flag的值:
/*static*/ int get_fn_flag_status()
{
printk("get_fn_flag_status = %d \n",Fn_flag);
return Fn_flag;
}
/*static*/ void clear_fn_flag_status()
{
Fn_flag = 0;
printk("clear_fn_flag_status = %d \n",Fn_flag);
return;
}
使用EXPORT_SYMBOL:
EXPORT_SYMBOL(get_fn_flag_status);
EXPORT_SYMBOL(clear_fn_flag_status);
同时要在gpio_keys.h文件中声明一下这两个函数:
/*static*/ int get_fn_flag_status(void);
/*static*/ void clear_fn_flag_status(void);
按键矩阵在gpio_matrix.c文件中 (kernel/drivers/input/misc/gpio_matrix.c)
在report_key函数里面使用
static void report_key(struct gpio_kp *kp, int key_index, int out, int in)
{
......
if(get_fn_flag_status())
{
clear_fn_flag_status();
if(keycode == 2)// 1
keycode = 59;//F1
else if (keycode == 3)// 2
keycode = 60;//F2
else if (keycode == 4)// 3
keycode = 61;//F3
else if (keycode == 5)// 4
keycode = 62;//F4
else if (keycode == 6)// 5
keycode = 63;//F5
else if (keycode == 7)// 6
keycode = 64;//F6
else if (keycode == 8)// 7
keycode = 65;//F7
else if (keycode == 9)// 8
keycode = 66;//F8
else if (keycode == 10)// 9
keycode = 67;//F9
else if (keycode == 11)// 0
keycode = 68;//F10
else if (keycode == 522)// *
keycode = 87;//F11
else if (keycode == 523)// #
keycode = 88;//F12
printk("changed keycode =%d \n",keycode);
}
......
}
Linux symbol export method:
[1] If we want export the symbol in a module, just use theEXPORT_SYMBOL(xxxx)in the C or H file.
And compile the module by adding the compile flag-DEXPORT_SYMTAB.
Then we can use thexxxxin the other module.
[2] If we want export some symbol in Kernel that is not in a module such asxxxxin the/arch/ppc/fec.c.
Firstly, define thexxxxin thefec.c;
Secondly, make a new file which contain the"extern"define thexxxx(for example, extern intxxxx);
Lastly, in theppc_ksyms.cwe includes the new file, and add theEXPORT_SYMBOL(xxxx).
Then we can use thexxxx.
使用时注意事项:
在使用EXPORT_SYMBOL 的.c文件中 需要 #include <linux/module.h> 文件。
实际遇到的例子:
gpio口做一个Fn按键,在按下Fn按键的时候,需要gpio_matrix按键矩阵模块来处理.
gpio按键模块在
gpio_keys.c (kernel/drivers/input/keyboard)
定义一个flag
unsigned int Fn_flag =0;//liwei
在static void gpio_keys_gpio_report_event函数中处理GPIO的按键,如果有按下,就设置flag
static void gpio_keys_gpio_report_event(struct gpio_button_data *bdata)
{
......
printk("%s :%d button->code=%d\n",__func__,__LINE__,button->code);//liwei
if(button->code == 302)//KEY_GPIO_KEY_FN=302 in input.h
{
Fn_flag =1;
}
......
}
为了这个Fn _flag可以在别的模块使用, 做两个函数用来改变和记录flag的值:
/*static*/ int get_fn_flag_status()
{
printk("get_fn_flag_status = %d \n",Fn_flag);
return Fn_flag;
}
/*static*/ void clear_fn_flag_status()
{
Fn_flag = 0;
printk("clear_fn_flag_status = %d \n",Fn_flag);
return;
}
使用EXPORT_SYMBOL:
EXPORT_SYMBOL(get_fn_flag_status);
EXPORT_SYMBOL(clear_fn_flag_status);
同时要在gpio_keys.h文件中声明一下这两个函数:
/*static*/ int get_fn_flag_status(void);
/*static*/ void clear_fn_flag_status(void);
按键矩阵在gpio_matrix.c文件中 (kernel/drivers/input/misc/gpio_matrix.c)
在report_key函数里面使用
static void report_key(struct gpio_kp *kp, int key_index, int out, int in)
{
......
if(get_fn_flag_status())
{
clear_fn_flag_status();
if(keycode == 2)// 1
keycode = 59;//F1
else if (keycode == 3)// 2
keycode = 60;//F2
else if (keycode == 4)// 3
keycode = 61;//F3
else if (keycode == 5)// 4
keycode = 62;//F4
else if (keycode == 6)// 5
keycode = 63;//F5
else if (keycode == 7)// 6
keycode = 64;//F6
else if (keycode == 8)// 7
keycode = 65;//F7
else if (keycode == 9)// 8
keycode = 66;//F8
else if (keycode == 10)// 9
keycode = 67;//F9
else if (keycode == 11)// 0
keycode = 68;//F10
else if (keycode == 522)// *
keycode = 87;//F11
else if (keycode == 523)// #
keycode = 88;//F12
printk("changed keycode =%d \n",keycode);
}
......
}