|
Linux下CAN驱动问题(HMs30c7202) c_candrv-1.2.0
[复制链接]
目前接手一项目,头有点大,CAN在运行过程中,会出现不能收发的情况,从新上电后正常
使用的是c_candrv-1.2.0驱动程序,个人感觉可能是使用方法不对
- #define can0file "/dev/can0"
- #define can1file "/dev/can1"
- #define can2file "/dev/can2"
- #define can3file "/dev/can3"
- /*CAN初始化*/
- void initcan(void)
- {
- int counts = 0;
-
- do {
- if ((can0_sndid = open(can0file, O_WRONLY))<0) {
- counts++;
- } else break;
- } while (counts < 10);
- counts = 0;
-
- do {
- if ((can0_rcvid = open(can1file, O_RDONLY))<0) {
- counts++;
- } else break;
- } while (counts < 10);
- counts = 0;
- do {
- if ((can1_sndid = open(can2file, O_RDWR))<0) {
- counts++;
- } else break;
- } while (counts < 10);
- counts = 0;
- do {
- if ((can1_rcvid = open(can3file, O_RDWR))<0) {
- counts++;
- } else break;
- } while (counts < 10);
- }
- void * thread_com_can0(void *arg)
- {
- int count = 0;
-
- while (ioctl( can0_rcvid, IOCTL_CAN_SET_READ_MODE, 0 ) < 0) {
- count++;
- if (count > 100) break;
- }
- count = 0;
- while (ioctl( can0_rcvid, IOCTL_CAN_SET_FILTER, 0) < 0) {
- count++;
- if (count > 100) break;
- }
- .....//应用程序
- }
复制代码
看完c_candrv-1.2.0的 readme后,觉得IOCTL_CAN_SET_FILTER应该是设置验收滤波器的参数啊
应用程序中不管什么节点的数据都需要接收,是不是根本不需要设置IOCTL_CAN_SET_READ_MODE和IOCTL_CAN_SET_FILTER
这种initcan会不会存在问题,为什么can会down掉,有时能发不能收,有时既不能发也不能收,重新上电后又正常了!
|
|