我不熟悉Linux内核开发,但我的任务是更新内核驱动程序,使其返回一个可由应用程序读取的状态代码。这将要求驱动程序每秒轮询硬件几次,以查看正在发送的相机格式(PAL、NTSC或none)。
然而,我对如何实现这一点感到困惑。我知道驱动程序如何与硬件通信,但我不知道如何将这些数据传递给应用程序。这种类型的行为是否需要使用ioctl()调用,或者这是一个读文件操作?另外,如果应用程序正在调用IOCTL或read函数,然后需要等待硬件响应,这是否会产生性能问题?
另外,为了获得更多信息,我正在开发2.6版本的内核。我正在学习"Linux设备驱动程序第三版“,但在如何解决这个特定问题上没有什么特别之处。LDD3让它听起来像ioctl(),只是为了向驱动程序发送命令。因为这是一个V4L驱动程序,所以我认为打开文件会返回图像数据,而不是我想要的状态信息。
发布于 2015-11-20 05:04:47
我建议查看托管在linuxtv.org上的最新V4L2应用程序接口文档:http://linuxtv.org/downloads/v4l-dvb-apis/
用户空间应用程序可以调用IOCTL来查询当前的输入格式。以下用户空间代码可用于查询当前视频标准的内核驱动:
(引用http://www.linuxtv.org/downloads/legacy/video4linux/API/V4L2_API/spec-single/v4l2.html#standard)
Example 1.5. Information about the current video standard
v4l2_std_id std_id;
struct v4l2_standard standard;
if (-1 == ioctl (fd, VIDIOC_G_STD, &std_id)) {
/* Note when VIDIOC_ENUMSTD always returns EINVAL this
is no video device or it falls under the USB exception,
and VIDIOC_G_STD returning EINVAL is no error. */
perror ("VIDIOC_G_STD");
exit (EXIT_FAILURE);
}
memset (&standard, 0, sizeof (standard));
standard.index = 0;
while (0 == ioctl (fd, VIDIOC_ENUMSTD, &standard)) {
if (standard.id & std_id) {
printf ("Current video standard: %s\n", standard.name);
exit (EXIT_SUCCESS);
}
standard.index++;
}
/* EINVAL indicates the end of the enumeration, which cannot be
empty unless this device falls under the USB exception. */
if (errno == EINVAL || standard.index == 0) {
perror ("VIDIOC_ENUMSTD");
exit (EXIT_FAILURE);
}https://stackoverflow.com/questions/33698571
复制相似问题