?? cantxrx.c
字號:
#include <stdio.h>#include <stdlib.h>//#include <unistd.h>#include <fcntl.h>#include <pthread.h>#include <asm-arm/arch-s3c2410/S3C2410_2.h>//#include <asm-arm/arch/hardware.h>//#inclued <asm-arm/arch/bitfield.h>#include "mcpcan.h"#include "spi_cmd.h"
#include "def.h"
//#include "2410addr.h"
#include "directio.h"//#include "option.h"
//#include "2410lib.h"
#define DEBUG#ifdef DEBUG#define dbgprintf(S) printf(S)#else#define dbgprintf(S)#endifint fd;void send(void * arg){ struct mcpcan_data *datagramptr = (struct mcpcan_data *)arg; while(1) { sleep(2); write(fd, datagramptr, sizeof(struct mcpcan_data)); printf("send datagram.\n"); printf("the data sended is %s.\n", datagramptr->data); } }int main(){ pthread_t id; int ret; struct mcpcan_data data_receive; struct mcpcan_data data_send; /* 打印提示信息 */
printf("---can總線測試程序---\n");
data_send.BufNo = TXBUF0; data_send.IdType = STANDID; data_send.id = 23; data_send.DataLen = 8; strcpy(data_send.data, "-CVTECH-"); data_receive.BufNo = 0;
data_receive.IdType = 0;
data_receive.id = 0;
data_receive.DataLen = 0;
memset(data_receive.data,9,0x0);
fd = open("/dev/can",O_RDWR); if(fd < 0) { printf("Open device failed.\n"); return fd; } printf("Open device success.\n");
ret=pthread_create(&id,NULL,(void *)send, &data_send); if(ret!=0){ printf ("Create pthread error!\n"); exit (1); }
printf("Create pthread success.\n"); while(1)
{ int datalen;
read(fd, &data_receive, sizeof(struct mcpcan_data));
printf("data_receive.BufNo = %d\n",data_receive.BufNo); printf("data_receive.IdType = %d\n",data_receive.IdType); printf("data_receive.id = %d\n",data_receive.id); printf("data_receive.DataLen = %d\n",data_receive.DataLen); printf("data_receive.data = %s\n",data_receive.data); } return 0;}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -