• 大小: 47.55 KB
    文件类型: .rar
    金币: 2
    下载: 0 次
    发布日期: 2024-08-01
  • 语言: 其他
  • 标签: CAN  LINUX  驱动  

资源简介

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


评论

共有 条评论