📄 usrappinit.c
字号:
/* usrAppInit.c - stub application initialization routine *//* Copyright 1984-1998 Wind River Systems, Inc. *//*modification history--------------------01a,02jun98,ms written*//*DESCRIPTIONInitialize user application code.*/ /******************************************************************************** usrAppInit - initialize the users application*/ #include "config.h"#include "can20b.h"#include <logLib.h>#include <vxWorks.h>#define MSG_LENGTH 13extern void CanDrv();extern void CanDevCreate();void APP_CAN();static void can0testfun();static void can1testfun();void can0sendfun();void can1sendfun();void can0receivefun();void can1receivefun();void usrAppInit (void) {#ifdef USER_APPL_INIT myAppInit(); /* for backwards compatibility */#endif /* add application specific code here */#ifdef CAN_DRV/*init CAN_DRV*/ CanDrv(); CanDevCreate(); APP_CAN(); #endif}int Fh0=0,Fh1=0;void APP_CAN(){ /*create thead 1 for can0*/ printf("_____________________________________"); printf("_____________________________________\n"); taskSpawn("can0_test",50,0x0100,4096,can0testfun,0,0,0,0,0,0,0,0,0,0); taskSpawn("can1_test",50,0x0100,4096,can1testfun,0,0,0,0,0,0,0,0,0,0);}void can0testfun(){ CANCFG S_CanConfig1; S_CanConfig1.filter_num=1; S_CanConfig1.acc_code[0]=0x00; S_CanConfig1.acc_code[1]=0x00; S_CanConfig1.acc_code[2]=0x00; S_CanConfig1.acc_code[3]=0x00; S_CanConfig1.acc_mask[0]=0xff; S_CanConfig1.acc_mask[1]=0xff; S_CanConfig1.acc_mask[2]=0xff; S_CanConfig1.acc_mask[3]=0xff; S_CanConfig1.mode=0; S_CanConfig1.bt0=0x00;/*brp=(clk/(bt0+1))/50*/ S_CanConfig1.bt1=0x14; Fh0=open("can0",2,0x700); ioctl(Fh0,CAN_INIT,(int)(&S_CanConfig1)); printf("************************<CAN0 CONFIG PARAMETER>*************************\n"); printf(" (PeliCAN MODE)\n"); printf(" (ONE FILETER)\n"); printf(" (POLLING RECEIVE MODE)\n"); printf(" (BRP SPEED IS 1MBIT/SECOND)\n"); printf(" (ACCEPT DATA FROM ALL ID)\n"); printf("************************************************************************\n"); taskDelay(500); taskSpawn("can0_send_test",60,0x0100,4096,can0sendfun,0,0,0,0,0,0,0,0,0,0); taskSpawn("can0_receive_test",60,0x0100,4096,can0receivefun,0,0,0,0,0,0,0,0,0,0);}void can1testfun(){ CANCFG S_CanConfig2; S_CanConfig2.filter_num=1; S_CanConfig2.acc_code[0]=0x00; S_CanConfig2.acc_code[1]=0x00; S_CanConfig2.acc_code[2]=0x00; S_CanConfig2.acc_code[3]=0x00; S_CanConfig2.acc_mask[0]=0xff; S_CanConfig2.acc_mask[1]=0xff; S_CanConfig2.acc_mask[2]=0xff; S_CanConfig2.acc_mask[3]=0xff; S_CanConfig2.mode=0;/*interrupt/pollinig*/ S_CanConfig2.bt0=0x00;/*brp=(clk/(bt0+1))/50*/ S_CanConfig2.bt1=0x14; Fh1=open("can1",2,0x700); ioctl(Fh1,CAN_INIT,(int)(&S_CanConfig2)); printf("************************<CAN1 CONFIG PARAMETER>*************************\n"); printf(" (PeliCAN MODE)\n"); printf(" (ONE FILETER)\n"); printf(" (POLLING RECEIVE MODE)\n"); printf(" (BRP SPEED IS 1MBIT/SECOND)\n"); printf(" (ACCEPT DATA FROM ALL ID)\n"); printf("************************************************************************\n"); taskDelay(500); taskSpawn("can1_send_test",60,0x0100,4096,can1sendfun,0,0,0,0,0,0,0,0,0,0); taskSpawn("can1_receive_test",60,0x0100,4096,can1receivefun,0,0,0,0,0,0,0,0,0,0);}void can0sendfun(){ CANMSG S_TMSG1; BYTE Result=0; int i=0; /*send message1*/ S_TMSG1.sff=1; S_TMSG1.id[0]=0x00; S_TMSG1.id[1]=0x00; S_TMSG1.rtr=0; S_TMSG1.dlen=8; S_TMSG1.data[0]=0; S_TMSG1.data[1]=0; S_TMSG1.data[2]=0; S_TMSG1.data[3]=0; S_TMSG1.data[4]=0; S_TMSG1.data[5]=0; S_TMSG1.data[6]=0; S_TMSG1.data[7]=0; while(1){ S_TMSG1.data[0]=(S_TMSG1.data[0]+1)%128; S_TMSG1.data[1]=(S_TMSG1.data[1]+1)%128; S_TMSG1.data[2]=(S_TMSG1.data[2]+1)%128; S_TMSG1.data[3]=(S_TMSG1.data[3]+1)%128; S_TMSG1.data[4]=(S_TMSG1.data[4]+1)%128; S_TMSG1.data[5]=(S_TMSG1.data[5]+1)%128; S_TMSG1.data[6]=(S_TMSG1.data[6]+1)%128; S_TMSG1.data[7]=(S_TMSG1.data[7]+1)%128; i++; Result=write(Fh0,((char *)(&S_TMSG1)),MSG_LENGTH); printf("[CAN0 SEND DATA%d]------------------->0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",\ i,S_TMSG1.data[0],S_TMSG1.data[1],S_TMSG1.data[2],\ S_TMSG1.data[3],S_TMSG1.data[4],S_TMSG1.data[5],\ S_TMSG1.data[6],S_TMSG1.data[7]); taskDelay(500); } close(Fh0);}void can1sendfun(){ CANMSG S_TMSG2; BYTE Result=0; int i=0; /*send message1*/ S_TMSG2.sff=1; S_TMSG2.id[0]=0x00; S_TMSG2.id[1]=0x00; S_TMSG2.rtr=0; S_TMSG2.dlen=8; S_TMSG2.data[0]=1; S_TMSG2.data[1]=1; S_TMSG2.data[2]=1; S_TMSG2.data[3]=1; S_TMSG2.data[4]=1; S_TMSG2.data[5]=1; S_TMSG2.data[6]=1; S_TMSG2.data[7]=1; while(1){ S_TMSG2.data[0]=(S_TMSG2.data[0]+1)%128; S_TMSG2.data[1]=(S_TMSG2.data[1]+1)%128; S_TMSG2.data[2]=(S_TMSG2.data[2]+1)%128; S_TMSG2.data[3]=(S_TMSG2.data[3]+1)%128; S_TMSG2.data[4]=(S_TMSG2.data[4]+1)%128; S_TMSG2.data[5]=(S_TMSG2.data[5]+1)%128; S_TMSG2.data[6]=(S_TMSG2.data[6]+1)%128; S_TMSG2.data[7]=(S_TMSG2.data[7]+1)%128; Result=write(Fh1,((char *)(&S_TMSG2)),MSG_LENGTH); i++; printf("[CAN1 SEND DATA%d]------------------->0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",\ i,S_TMSG2.data[0],S_TMSG2.data[1],S_TMSG2.data[2],\ S_TMSG2.data[3],S_TMSG2.data[4],S_TMSG2.data[5],\ S_TMSG2.data[6],S_TMSG2.data[7]); taskDelay(500); } close(Fh1);}void can0receivefun(){ CANMSG S_RMSG1; int i=0; BYTE Result=0; while(1){ Result=read(Fh0,((char *)(&S_RMSG1)),MSG_LENGTH); i++; printf("{CAN0 RECEIVE DATA%d}---------------->0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",\ i,S_RMSG1.data[0],S_RMSG1.data[1],S_RMSG1.data[2],\ S_RMSG1.data[3],S_RMSG1.data[4],S_RMSG1.data[5],\ S_RMSG1.data[6],S_RMSG1.data[7]); taskDelay(500); } }void can1receivefun(){ CANMSG S_RMSG2; int i=0; BYTE Result=0; while(1){ Result=read(Fh1,((char *)(&S_RMSG2)),MSG_LENGTH); i++; printf("{CAN1 RECEIVE DATA%d}---------------->0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",\ i,S_RMSG2.data[0],S_RMSG2.data[1],S_RMSG2.data[2],\ S_RMSG2.data[3],S_RMSG2.data[4],S_RMSG2.data[5],\ S_RMSG2.data[6],S_RMSG2.data[7]); taskDelay(500); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -