Linux 的 Input Device 是重要的一個 subsystem,在進行實例介紹前,先大略了解一下相關的 API。input.c是Linux的输入驅動程式,主要支援鍵盤與滑鼠的輸入;input.c介面特殊的地方是採用了事件(event)的方式來處理輸入,以下是input.c介面重要的資料結構與函數:
* struct input_dev
* void input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
* void input_register_device(struct input_dev *);
* void input_unregister_device(struct input_dev *);
* void input_register_handler(struct input_handler *);
* void input_unregister_handler(struct input_handler *);
(1) struct input_dev是用來描述輸入事件的重要資料結構,其原型如下:
struct input_dev {
const char *name;
const char *phys;
const char *uniq;
struct input_id id;
unsigned long evbit[BITS_TO_LO ......
Linux 的 Input Device 是重要的一個 subsystem,在進行實例介紹前,先大略了解一下相關的 API。input.c是Linux的输入驅動程式,主要支援鍵盤與滑鼠的輸入;input.c介面特殊的地方是採用了事件(event)的方式來處理輸入,以下是input.c介面重要的資料結構與函數:
* struct input_dev
* void input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
* void input_register_device(struct input_dev *);
* void input_unregister_device(struct input_dev *);
* void input_register_handler(struct input_handler *);
* void input_unregister_handler(struct input_handler *);
(1) struct input_dev是用來描述輸入事件的重要資料結構,其原型如下:
struct input_dev {
const char *name;
const char *phys;
const char *uniq;
struct input_id id;
unsigned long evbit[BITS_TO_LONGS(E ......
(1)在\drivers\input\Input.c中。
A,subsys_initcall(input_init);
B,static int __init input_init(void)中完成几个重要的操作:
err = class_register(&input_class);以输入类方式注册类
input_proc_init(); //创建proc下的目录和文件
register_chrdev(INPUT_MAJOR, "input", &input_fops); //注册字符设备驱动程序到内核
(2)在drivers\input\keyboard\S3c-keypad.c中,是自己的按键处理文件。
A,定义给android上层的码值
#define KEYCODE_HOME 58
#define KEYCODE_POWER 50
struct s3c_keypad_gpio_key gpio_key_smdk6410[] = {
{IRQ_EINT(6), S3C64XX_GPN(6), 2, KEYCODE_POWER, 1},
{IRQ_EINT(7), S3C64XX_GPN(7), 2, KEYCODE_HOME, 1},
};
分别是外部中断号,GPIO口号,码值。
......
转自http://blog.csdn.net/colorant/archive/2007/04/12/1561837.aspx
1 输入子系统架构Overview
输入子系统(Input Subsystem)的架构如下图所示
输入子系统由 输入子系统核心层( Input Core ),驱动层和事件处理层(Event Handler)三部份组成。一个输入事件,如鼠标移动,键盘按键按下,joystick的移动等等通过 Driver -> InputCore -> Eventhandler -> userspace 的顺序到达用户空间传给应用程序。
其中Input Core 即 Input Layer 由 driver/input/input.c及相关头文件实现。对下提供了设备驱动的接口,对上提供了Event Handler层的编程接口。
1.1 主要数据结构
&n ......
alarm(设置信号传送闹钟)
相关函数 signal,sleep
表头文件 #include<unistd.h>
定义函数 unsigned int alarm(unsigned int seconds);
函数说明 alarm()用来设置信号SIGALRM在经过参数seconds指定的秒数后传送给目前的进程。如果参数seconds 为0,则之前设置的闹钟会被取消,并将剩下的时间返回。
返回值 返回之前闹钟的剩余秒数,如果之前未设闹钟则返回0。
范例 #include<unistd.h>
#include<signal.h>
void handler() {
printf(“hello\n”);
}
main()
{
int i;
signal(SIGALRM,handler);
alarm(5);
for(i=1;i<7;i++){
printf(“sleep %d ...\n”,i);
sleep(1);
}
}
执行 sleep 1 ...
sleep 2 ...
sleep 3 ...
sleep 4 ...
sleep 5 ...
hello
sleep 6 ...
kill(传送信号给指定的进程)
相关函数 raise,signal
表头文件 #include<sys/types.h>
#include<signal.h>
定义函数 int kill(pid_t pid,int sig);
函数说明 &n ......
一、POSIX 线程详解
1、
一种支持内存共享的简捷工具
2、称作互斥对象的小玩意
3、使用条件变量提高效率
二、Posix线程编程指南
1、
线程创建与取消
2、
线程私有数据
3、线程同步
4、线程终止
5、杂项
......