自己整理一个canfestival包

链接:https://pan.baidu.com/s/1rqfTsDy8SMOYqDX_Gb-pWQ 
提取码:twh9

趁没忘赶紧整理一下

1.解压软件包,上传到虚拟机

2.在源文件目录输入配置命令

1)使用虚拟机编译

./configure --cc=gcc --arch=x86_64  --os=unix --kerneldir=$HOME/dy/linux --prefix=$PWD/myinstall --target=unix --can=socket --timers=unix --debug=WAR,MSG

2)使用交叉编译器编译

./configure --cc=arm-linux-gnueabihf-gcc --arch=arm  --os=unix --kerneldir=$HOME/dy/linux --prefix=$PWD/myinstall --target=unix --can=socket --timers=unix --debug=WAR,MSG

输入./configure --help可获得帮助文件

3)

Options:
 --cc=foo      Use C compiler 'foo' instead of defaults gcc or cc.
 --cxx=foo     Use C++ compiler 'foo' instead of defaults g++.
 --ld=foo      Use linker 'foo' instead of ld.
 --python=foo  Use python interpreter 'foo' instead of defaults python.
 --arch=foo    Use architecture 'foo' instead of trying to autodetect.
 --os=foo      Use operative system 'foo' instead of trying to autodetect.
 --kerneldir=foo   Use 'foo' as kernel source directory instead of default
 --prefix=foo  Use prefix 'foo' instead of default .
 --target=foo  Use 'foo' as build target.
               "unix" for unix-like systems (Linux, Cygwin)
               "win32" for win32 systems (native, mingw or VC++)
               "hcs12" for HCS12 micro-controller
 --can=foo	Use 'foo' as CAN driver
               "anagate_linux" use AnaGate CAN(duo) driver for linux
               "anagate_win32" use AnaGate CAN(duo) driver for win32
               "peak_linux" use Linux build host installed Peak driver and library
                 see http://www.peak-system.com/linux/
               "peak_win32" use win32 PcanLight Peak driver and library with Cygwin
                 see http://www.peak-system.com/themen/download_gb.html
               "virtual" use unix pipe based virtual can driver
               "virtual_kernel" use kernel module virtual can driver
               "socket" use socket-can  
                 see http://developer.berlios.de/projects/socketcan/
               "lincan" lincan driver
                 see http://www.ocera.org/download/components/WP7/lincan-0.3.3.html
               "can4linux" can4linux driver
                 see http://www.port.de/engl/canprod/hw_can4linux.html
               "copcican_linux" user space driver interface for CO-PCICAN card
                 see http://www.cosateq.com/
               "copcican_comedi" COMEDI driver interface for CO-PCICAN card
                 see http://www.cosateq.com/
 --timers=foo  Use 'foo' as TIMERS driver (can be 'unix', 'xeno', 'rtai', 'kernel' or 'kernel_xeno')
 --wx=foo      Force result of WxWidgets detection (0 or 1)
 --binutils=path   Override binutils path detection (as regards $CC content)
 --disable-dll Disable run-time dynamic linking of can, led and nvram drivers
 --enable-lss  Enable the LSS services
 --enable-lss-fs  Enable the LSS FastScan service
 --disable-Ox  Disable gcc "-Ox" optimizations.
 --enable-shared Enable shared library compilation.
 --debug=foo,foo,..   Enable debug messages, ERR -> only errors, WAR).
               "PDO" send errors and warnings through PDO messages
               "ERR" print errors only, to stdout
               "WAR" print errors and warnings, to stdout
               "MSG" print messages content, to stdout

Stack compilation constants
 --MAX_CAN_BUS_ID [=1] Number of can bus to use
 --SDO_MAX_LENGTH_TRANSFER [=32] max bytes to transmit by SDO
 --SDO_BLOCK_SIZE [=16] max CAN frames transmitted at once for block transfer
 --SDO_MAX_SIMULTANEOUS_TRANSFERS [=4] Number of SDO that the node can manage concurrently
 --NMT_MAX_NODE_ID [=128] can be reduced to gain memory on small network
 --SDO_TIMEOUT_MS [=3000] Timeout in milliseconds for SDO (None to disable the feature)
 --EMCY_MAX_ERRORS [=8] Max number of active errors managed in error_data structure
 --LSS_TIMEOUT_MS [=1000] Timeout in milliseconds for LSS services.
                          LSS must be enabled with "--enable-lss"
 --LSS_FS_TIMEOUT_MS [=100] Timeout in milliseconds for LSS FastScan service.
                          LSS FastScan must be enabled with "--enable-lss-fs"
 --SDO_DYNAMIC_BUFFER_ALLOCATION_SIZE [=0] Max size of dynamic memory to use if SDO_MAX_LENGTH_TRANSFER exceeded
                          (0 to disable feature)

 

3.然后 make && make install 生成

4.创建一个工程移植

include文件内容

src文件内容

lib文件内容

makefile文件链接内容

虚拟vcan的创建方式

sudo modprobe vcan
sudo ip link add dev vcan0 type vcan
sudo ip link set up vcan0

一段测试代码


  文 件 名   : main.c
  版 本 号   : 初稿
  作    者   : DY
  生成日期   : 2020年8月23日
  最近修改   :
  功能描述   : 测试
  函数列表   :
              main
  修改历史   :
  1.日    期   : 2020年8月23日
    作    者   : DY
    修改内容   : 创建文件

******************************************************************************/

/*----------------------------------------------*
 * 包含头文件                                   *
 *----------------------------------------------*/

#include "main.h"

/*----------------------------------------------*
 * 全局变量                                     *
 *----------------------------------------------*/

s_BOARD MasterBoard = {"vcan0", "125K"};


UNS32 OnMasterMap1Update(CO_Data* d, UNS16 unsused_indextable, UNS8 unsused_bSubindex)
{
	printf("OnMasterMap1Update:%d\n", 0);
	return 0;
}


/***************************  INIT  *****************************************/
void InitNodes(CO_Data* d, UNS32 id)
{

	/****************************** INITIALISATION MASTER *******************************/
	if(strcmp(MasterBoard.baudrate, "none")){
 		RegisterSetODentryCallBack(&TestMaster_Data, 0x2000, 0, &OnMasterMap1Update);
		/* Defining the node Id */
		setNodeId(&TestMaster_Data, 0x01);

		/* init */
		setState(&TestMaster_Data, Initialisation);
			
	}
}

/***************************  EXIT  *****************************************/
void Exit(CO_Data* d, UNS32 id)
{
	if(strcmp(MasterBoard.baudrate, "none")){
		masterSendNMTstateChange(&TestMaster_Data, 0x02, NMT_Reset_Node);    
    
    	//Stop master
		setState(&TestMaster_Data, Stopped);
	}
}

  
int main(int argc, char*argv[]) 

{
  char* LibraryPath="./lib/libcanfestival_can_socket.so";

	TimerInit();
	if (LoadCanDriver(LibraryPath) == NULL)
    printf("Unable to load library: %s\n",LibraryPath);
	if(!canOpen(&MasterBoard,&TestMaster_Data)){
		printf("Cannot open Master Board (%s,%s)\n",MasterBoard.busname, MasterBoard.baudrate);
		goto fail_master;
	}
	
	// Start timer thread
	StartTimerLoop(&InitNodes);

	// wait Ctrl-C
	pause();

	// Stop timer thread
	StopTimerLoop(&Exit);
fail_master:
	if(strcmp(MasterBoard.baudrate, "none")) canClose(&TestMaster_Data);
	
	TimerCleanup();
}


 

Logo

华为AI开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐