有触摸屏驱动程序源代码,怎么写一个命令行的程序测试驱动程序?

skywoo 2004-04-14 05:48:50
驱动中的read函数如下:
struct ts_event {
u16 pressure;
u16 x;
u16 y;
u16 pad;
struct timeval stamp;
};
static ssize_t
ucb1x00_ts_read(struct file *filp, char *buffer, size_t count, loff_t *ppos)
{
DECLARE_WAITQUEUE(wait, current);
struct ucb1x00_ts *ts = filp->private_data;
char *ptr = buffer;
int err = 0;

add_wait_queue(&ts->read_wait, &wait);
while (count >= sizeof(struct ts_event)) {
err = -ERESTARTSYS;
if (signal_pending(current))
break;

if (ucb1x00_ts_evt_pending(ts)) {
struct ts_event *evt = ucb1x00_ts_evt_get(ts);

printk("ucb1x00_ts: x = %d y = %d \n", evt->x, evt->y);
err = copy_to_user(ptr, evt, sizeof(struct ts_event));
ucb1x00_ts_evt_pull(ts);

if (err)
break;

ptr += sizeof(struct ts_event);
count -= sizeof(struct ts_event);
continue;
}

set_current_state(TASK_INTERRUPTIBLE);
err = -EAGAIN;
if (filp->f_flags & O_NONBLOCK)
break;
schedule();
}
current->state = TASK_RUNNING;
remove_wait_queue(&ts->read_wait, &wait);

return ptr == buffer ? err : ptr - buffer;
}

设备文件是:/dev/touchscreen/ucb1x00
如果需要更详细的代码可以访问:http://its.letfree.com/ts.txt

大虾快帮帮我,毕业设计快没时间了。3x!!!!
...全文
232 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
skywoo 2004-04-21
  • 打赏
  • 举报
回复
to aria:
请问poll和select在应用程序中怎么用?
aria 2004-04-21
  • 打赏
  • 举报
回复
一段测试代码:
struct ts_event evt;
fd_set rfds;
...
fd = open("/dev/ts", O_RDONLY | O_NONBLOCK);
...
while (1) {
FD_ZERO(&rfds);
FD_SET(fd, &rfds);
ret = select(fd + 1, &rfds, NULL, NULL, NULL);
if (FD_ISSET(fd, &rfds)) {
read(fd, &evt, sizeof(struct ts_event));
printf("x=%d, y=%d\n", evt.x, evt.y);
}
}
其他诸如判断open()/select()等的错误处理man一下就知道怎么处理了。
关于函数怎么使用建议自己man一把吧,要不网上也有一堆的例子...
loveisbug 2004-04-15
  • 打赏
  • 举报
回复
楼主问的是如何去测试这个驱动程序吗?从已有的回复看好象不是的。
jack_wq 2004-04-15
  • 打赏
  • 举报
回复
struct timeval我想应该在time.h中定义
struct ts_event的接收:只要当作普通结构体处理就可以了!
skywoo 2004-04-15
  • 打赏
  • 举报
回复
我只想知道struct ts_event 在应用程序中怎么接收?
struct timeval在那个头文件里才用啊?
jack_wq 2004-04-15
  • 打赏
  • 举报
回复
呵呵~~~我不是什么高手,没有看明白楼主的程序!
LinHanLao 2004-04-15
  • 打赏
  • 举报
回复
在你的应用程序里,你把读到buffer里的数据强制转换一下
struct ts_event te;
te = (struct ts_event)buffer;
LinHanLao 2004-04-15
  • 打赏
  • 举报
回复
struct ts_event在你的驱动程序里已经定义了,
如果做你的驱动的应用开发的话,
你在驱动里定义的一些变量就应该导出,
你的应用程序应该包含驱动的头文件
skywoo 2004-04-14
  • 打赏
  • 举报
回复
我看不懂为什么read函数中向用户copy的是一个ts_event指针了?
接受的时候用什么数据类型?
aria 2004-04-14
  • 打赏
  • 举报
回复
直接打开/dev/touchscreen/ucb1x00获得fd,然后使用select()等到fd可读时就读取一个
struct ts_event 即可。

4,441

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 内核源代码研究区
社区管理员
  • 内核源代码研究区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧