出错问题现象:
jony@ubuntu:~/Desktop$ cd socket_can/usb-to-can_socketcan/
jony@ubuntu:~/Desktop/socket_can/usb-to-can_socketcan$ make
make -C /lib/modules/5.4.0-70-generic/build M=/home/jony/Desktop/socket_can/usb-to-can_socketcan modules
make[1]: Entering directory '/usr/src/linux-headers-5.4.0-70-generic'
CC [M] /home/jony/Desktop/socket_can/usb-to-can_socketcan/ixx_usb_v2.o
CC [M] /home/jony/Desktop/socket_can/usb-to-can_socketcan/ixx_usb_fd.o
CC [M] /home/jony/Desktop/socket_can/usb-to-can_socketcan/ixx_usb_core.o
/home/jony/Desktop/socket_can/usb-to-can_socketcan/ixx_usb_core.c: In function ‘ixxat_usb_set_ts_now’:
/home/jony/Desktop/socket_can/usb-to-can_socketcan/ixx_usb_core.c:141:9: error: implicit declaration of function ‘do_gettimeofday’; did you mean ‘do_settimeofday64’? [-Werror=implicit-function-declaration]
do_gettimeofday(&dev->time_ref.tv_host_0);
^~~~~~~~~~~~~~~
do_settimeofday64
cc1: some warnings being treated as errors
scripts/Makefile.build:269: recipe for target '/home/jony/Desktop/socket_can/usb-to-can_socketcan/ixx_usb_core.o' failed
make[2]: *** [/home/jony/Desktop/socket_can/usb-to-can_socketcan/ixx_usb_core.o] Error 1
Makefile:1760: recipe for target '/home/jony/Desktop/socket_can/usb-to-can_socketcan' failed
make[1]: *** [/home/jony/Desktop/socket_can/usb-to-can_socketcan] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-5.4.0-70-generic'
Makefile:6: recipe for target 'all' failed
make: *** [all] Error 2
问题分析:
高版本内核不支持do_gettimeofday函数。
解决方法:
修改文件src/usb-to-can_socketcan/ixx_usb_core.c
ixxat_usb_set_ts_now
函数,如下:
void ixxat_usb_set_ts_now(struct ixx_usb_device *dev, u32 hw_time_base)
{
dev->time_ref.ts_dev_0 = hw_time_base;
do_gettimeofday(&dev->time_ref.tv_host_0);
// linux 5.x内核 不支持
// do_gettimeofday(&dev->time_ref.tv_host_0);
// 通过jiffies 获取时间
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 3)
jiffies_to_timeval(jiffies, &dev->time_ref.tv_host_0);
#else
do_gettimeofday(&dev->time_ref.tv_host_0);
#endif
dev->time_ref.ts_dev_last = hw_time_base;
}
驱动代码下载地址
官网一直没更新。