Hi,呼叫技术支持的大大们。
我们用的板子是根据imx6的sabresd改的,内核也是,用的是android4.2.2系统。
我啥都没改,就根据“h不让发url ttps://community.freescale.com/docs/DOC-1437”,这个把内核配置选项选上。然后
root@android:/data/test # ifconfig can0 up
flexcan imx6q-flexcan.0: writing ctrl=0x0e31e055
flexcan imx6q-flexcan.0: flexcan_set_bittiming: mcr=0x5980000f ctrl=0x0e31e055
flexcan imx6q-flexcan.0: flexcan_chip_start: writing mcr=0x7de2020f
flexcan imx6q-flexcan.0: flexcan_chip_start: writing ctrl=0x0e31ec55
flexcan imx6q-flexcan.0: flexcan_chip_start: reading mcr=0x6de2020f ctrl=0x0e31ec55
有这个信息我想,就是说明can能用了是吧。
但是我找了个测试程序测试,提示:flexcan imx6q-flexcan.0: Error Warning IRQ
测试就此失败。
不知道为啥。测试代码如下:
/* 1.报文发送程序 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <linux/can.h>
#include <linux/can/raw.h>
#define AF_CAN 29 /* Controller Area Network */
#define PF_CAN AF_CAN
int main()
{
int s, nbytes;
struct sockaddr_can addr;
struct ifreq ifr;
struct can_frame frame[2] = {{0}};
s = socket(PF_CAN, SOCK_RAW, CAN_RAW); //创建套接字
strcpy(ifr.ifr_name, "can0" );
ioctl(s, SIOCGIFINDEX, &ifr); //指定can0设备
addr.can_family = AF_CAN;
addr.can_ifindex = ifr.ifr_ifindex;
bind(s, (struct sockaddr *)&addr, sizeof(addr)); //将套接字与can0绑定
//禁用过滤规则,本进程不接收报文,只负责发送
setsockopt(s, SOL_CAN_RAW, CAN_RAW_FILTER, NULL, 0);
//生成两个报文
frame[0].can_id = 0x11;
frame[0]. can_dlc = 1;
frame[0].data[0] = 'Y';
frame[0].can_id = 0x22;
frame[0]. can_dlc = 1;
frame[0].data[0] = 'N';
//循环发送两个报文
while(1) {
nbytes = write(s, &frame[0], sizeof(frame[0])); //发送frame[0]
if (nbytes != sizeof(frame[0])) {
printf("Send Error frame[0]\n!");
break; //发送错误,退出
}
sleep(1);
nbytes = write(s, &frame[1], sizeof(frame[1])); //发送frame[1]
if (nbytes != sizeof(frame[0])) {
printf("Send Error frame[1]\n!");
break;
}
sleep(1);
}
close(s);
return 0;
}
|