資源簡介
linux下的CAN驅動程序。分三個文件夾:include,driver,app,分別存放頭文件、驅動程序和應用程序。里邊還有驅動程序的簡要介紹,介紹了驅動程序的組成和編寫應用過程。<br>很詳細的一份驅動資料。
代碼片段和文件信息
#include?
#include?
//#include?
#include?
#include?
#include?
//#include?
//#inclued?
#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)
#endif
int?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.data90x0);
fd?=?open(“/dev/can“O_RDWR);
if(fd?0)
{
printf(“Open?device?failed.\n“);
return?fd;
}
printf(“Open?device?success.\n“);
ret=pthread_create(&idNULL(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;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????445??2006-03-16?08:56??代碼\app\Makefile
?????文件???????2157??2006-03-15?18:38??代碼\app\cantxrx.c
?????目錄??????????0??2006-03-15?18:21??代碼\app
?????文件????????630??2006-03-16?08:38??代碼\driver\Makefile
?????文件??????20271??2006-03-16?08:54??代碼\driver\mcpcan.c
?????文件??????16173??2006-03-15?17:07??代碼\driver\spi.c
?????文件???????2201??2006-03-15?17:07??代碼\driver\spi_cmd.c
?????目錄??????????0??2006-03-15?18:21??代碼\driver
?????文件???????1798??2006-03-16?08:35??代碼\include\2410addr.h
?????文件???????3250??2006-03-16?08:35??代碼\include\spi.h
?????文件???????5956??2006-03-16?08:41??代碼\include\mcpcan.h
?????文件???????1054??2006-03-16?08:35??代碼\include\spi_cmd.h
?????文件???????2302??2006-03-16?08:35??代碼\include\directio.h
?????文件????????408??2006-03-16?08:35??代碼\include\def.h
?????文件???????2195??2006-03-16?08:35??代碼\include\2410lib.h
?????文件???????1651??2006-03-16?08:35??代碼\include\option.h
?????文件???????3100??2006-03-16?08:35??代碼\include\hardware.h
?????文件??????84079??2006-03-16?08:35??代碼\include\S3C2410.h
?????目錄??????????0??2006-03-16?08:37??代碼\include
?????目錄??????????0??2006-03-15?18:21??代碼
?????文件??????41984??2006-03-16?08:54??代碼\CAN程序說明.doc
?????文件????????630??2006-03-16?08:38??代碼\driver\Makefile.txt
-----------?---------??----------?-----??----
???????????????190284????????????????????22
- 上一篇:多線程實例:桌面智能彈球小游戲
- 下一篇:DES的C 源碼
評論
共有 條評論