# HG changeset patch # User groke6 # Date 1202376315 -3600 # Node ID 83793fc7ce48f27106c52cd2bf3e1e67edfa0379 # Parent 7d8afedb87699b6bb89c56267017bdcea64a27ca added canChangeBaudRate to the driver interface diff -r 7d8afedb8769 -r 83793fc7ce48 drivers/AVR/can_AVR.c --- a/drivers/AVR/can_AVR.c Tue Feb 05 10:18:25 2008 +0100 +++ b/drivers/AVR/can_AVR.c Thu Feb 07 10:25:15 2008 +0100 @@ -156,6 +156,13 @@ } } +/***************************************************************************/ +unsigned char canChangeBaudRate_driver( CAN_HANDLE fd, char* baud) +{ + + return 0; +} + #ifdef __IAR_SYSTEMS_ICC__ #pragma type_attribute = __interrupt #pragma vector=CANIT_vect diff -r 7d8afedb8769 -r 83793fc7ce48 drivers/can_can4linux/can_can4linux.c --- a/drivers/can_can4linux/can_can4linux.c Tue Feb 05 10:18:25 2008 +0100 +++ b/drivers/can_can4linux/can_can4linux.c Thu Feb 07 10:25:15 2008 +0100 @@ -32,14 +32,14 @@ #include "can4linux.h" #include "can_driver.h" -struct timeval init_time,current_time; +//struct timeval init_time,current_time; /*********functions which permit to communicate with the board****************/ UNS8 canReceive_driver(CAN_HANDLE fd0, Message *m) { int res,i; canmsg_t canmsg; - long int time_period; + //long int time_period; canmsg.flags = 0; do{ @@ -104,26 +104,9 @@ return 0; } -/***************************************************************************/ -int set_bitrate( CAN_HANDLE fd, int baud) -{ - Config_par_t cfg; - volatile Command_par_t cmd; - - cmd.cmd = CMD_STOP; - ioctl(fd, COMMAND, &cmd); - - cfg.target = CONF_TIMING; - cfg.val1 = baud; - ioctl(fd, CONFIG, &cfg); - - cmd.cmd = CMD_START; - ioctl(fd, COMMAND, &cmd); - return 0; -} /***************************************************************************/ -int TranslateBaudeRate(char* optarg){ +int TranslateBaudRate(char* optarg){ if(!strcmp( optarg, "1M")) return (int)1000; if(!strcmp( optarg, "500K")) return (int)500; if(!strcmp( optarg, "250K")) return (int)250; @@ -133,8 +116,35 @@ if(!strcmp( optarg, "20K")) return (int)20; if(!strcmp( optarg, "10K")) return (int)10; if(!strcmp( optarg, "5K")) return (int)5; - if(!strcmp( optarg, "none")) return 0; - return 0x0000; + return 0; +} + +UNS8 _canChangeBaudRate( CAN_HANDLE fd, int baud) +{ + Config_par_t cfg; + volatile Command_par_t cmd; + + cmd.cmd = CMD_STOP; + ioctl(fd, COMMAND, &cmd); + + cfg.target = CONF_TIMING; + cfg.val1 = baud; + ioctl(fd, CONFIG, &cfg); + + cmd.cmd = CMD_START; + ioctl(fd, COMMAND, &cmd); + + return 0; +} + +UNS8 canChangeBaudRate_driver( CAN_HANDLE fd, char* baud) +{ + int temp=TranslateBaudRate(baud); + + if(temp==0)return 1; + _canChangeBaudRate(fd, temp); + printf("Baudrate changed to=>%s\n", baud); + return 0; } /***************************************************************************/ @@ -146,8 +156,9 @@ int prefix_len = strlen(lnx_can_dev_prefix); char dev_name[prefix_len+name_len+1]; int o_flags = 0; - int baud = TranslateBaudeRate(board->baudrate); + //int baud = TranslateBaudeRate(board->baudrate); int fd0; + int res; /*o_flags = O_NONBLOCK;*/ @@ -162,7 +173,13 @@ goto error_ret; } - set_bitrate((CAN_HANDLE)fd0, baud); + res=TranslateBaudRate(board->baudrate); + if(res == 0){ + fprintf(stderr,"!!! %s baudrate not supported. See can4linux.c\n", board->baudrate); + goto error_ret; + } + + _canChangeBaudRate( (CAN_HANDLE)fd0, res); printf("CAN device dev/can%s opened. Baudrate=>%s\n",board->busname, board->baudrate); diff -r 7d8afedb8769 -r 83793fc7ce48 drivers/can_ixxat_win32/ixxat.cpp --- a/drivers/can_ixxat_win32/ixxat.cpp Tue Feb 05 10:18:25 2008 +0100 +++ b/drivers/can_ixxat_win32/ixxat.cpp Thu Feb 07 10:25:15 2008 +0100 @@ -325,3 +325,10 @@ delete reinterpret_cast(inst); return 1; } + +extern "C" + UNS8 canChangeBaudRate_driver( CAN_HANDLE fd, char* baud) + { + //printf("canChangeBaudRate not yet supported by this driver\n"); + return 0; + } \ No newline at end of file diff -r 7d8afedb8769 -r 83793fc7ce48 drivers/can_lincan/can_lincan.c --- a/drivers/can_lincan/can_lincan.c Tue Feb 05 10:18:25 2008 +0100 +++ b/drivers/can_lincan/can_lincan.c Thu Feb 07 10:25:15 2008 +0100 @@ -90,6 +90,13 @@ } /***************************************************************************/ +UNS8 canChangeBaudRate_driver( CAN_HANDLE fd, char* baud) +{ + printf("canChangeBaudRate not yet supported by this driver\n"); + return 0; +} + +/***************************************************************************/ static const char lnx_can_dev_prefix[] = "/dev/can"; CAN_HANDLE canOpen_driver(s_BOARD *board) diff -r 7d8afedb8769 -r 83793fc7ce48 drivers/can_peak_linux/can_peak_linux.c --- a/drivers/can_peak_linux/can_peak_linux.c Tue Feb 05 10:18:25 2008 +0100 +++ b/drivers/can_peak_linux/can_peak_linux.c Thu Feb 07 10:25:15 2008 +0100 @@ -100,6 +100,12 @@ return 0x0000; } +UNS8 canChangeBaudRate_driver( CAN_HANDLE fd, char* baud) +{ + printf("canChangeBaudRate not yet supported by this driver\n"); + return 0; +} + /***************************************************************************/ CAN_HANDLE canOpen_driver(s_BOARD *board) { diff -r 7d8afedb8769 -r 83793fc7ce48 drivers/can_peak_win32/can_peak_win32.c --- a/drivers/can_peak_win32/can_peak_win32.c Tue Feb 05 10:18:25 2008 +0100 +++ b/drivers/can_peak_win32/can_peak_win32.c Thu Feb 07 10:25:15 2008 +0100 @@ -211,6 +211,13 @@ } /***************************************************************************/ +UNS8 canChangeBaudRate_driver( CAN_HANDLE fd, char* baud) +{ + printf("canChangeBaudRate not yet supported by this driver\n"); + return 0; +} + +/***************************************************************************/ CAN_HANDLE canOpen_driver (s_BOARD * board) { diff -r 7d8afedb8769 -r 83793fc7ce48 drivers/can_socket/can_socket.c --- a/drivers/can_socket/can_socket.c Tue Feb 05 10:18:25 2008 +0100 +++ b/drivers/can_socket/can_socket.c Thu Feb 07 10:25:15 2008 +0100 @@ -153,6 +153,12 @@ } #endif +UNS8 canChangeBaudRate_driver( CAN_HANDLE fd, char* baud) +{ + printf("canChangeBaudRate not yet supported by this driver\n"); + return 0; +} + /***************************************************************************/ CAN_HANDLE canOpen_driver (s_BOARD * board) diff -r 7d8afedb8769 -r 83793fc7ce48 drivers/can_tcp_win32/can_tcp_win32.cpp --- a/drivers/can_tcp_win32/can_tcp_win32.cpp Tue Feb 05 10:18:25 2008 +0100 +++ b/drivers/can_tcp_win32/can_tcp_win32.cpp Thu Feb 07 10:25:15 2008 +0100 @@ -117,4 +117,9 @@ delete reinterpret_cast(inst); return 1; } - +extern "C" + UNS8 canChangeBaudRate_driver( CAN_HANDLE fd, char* baud) + { + cerr << "canChangeBaudRate not yet supported by this driver\n"; + return 0; + } \ No newline at end of file diff -r 7d8afedb8769 -r 83793fc7ce48 drivers/can_uvccm_win32/can_uvccm_win32.cpp --- a/drivers/can_uvccm_win32/can_uvccm_win32.cpp Tue Feb 05 10:18:25 2008 +0100 +++ b/drivers/can_uvccm_win32/can_uvccm_win32.cpp Thu Feb 07 10:25:15 2008 +0100 @@ -348,5 +348,8 @@ return 1; } - - \ No newline at end of file +extern "C" + UNS8 canChangeBaudRate_driver( CAN_HANDLE fd, char* baud) + { + return 0; + } \ No newline at end of file diff -r 7d8afedb8769 -r 83793fc7ce48 drivers/can_virtual/can_virtual.c --- a/drivers/can_virtual/can_virtual.c Tue Feb 05 10:18:25 2008 +0100 +++ b/drivers/can_virtual/can_virtual.c Thu Feb 07 10:25:15 2008 +0100 @@ -76,20 +76,28 @@ } return 0; } -/* -int TranslateBaudeRate(char* optarg){ - if(!strcmp( optarg, "1M")) return 1000; - if(!strcmp( optarg, "500K")) return 500; - if(!strcmp( optarg, "250K")) return 250; - if(!strcmp( optarg, "125K")) return 125; - if(!strcmp( optarg, "100K")) return 100; - if(!strcmp( optarg, "50K")) return 50; - if(!strcmp( optarg, "20K")) return 20; - if(!strcmp( optarg, "10K")) return 10; - if(!strcmp( optarg, "5K")) return 5; + +/***************************************************************************/ +int TranslateBaudRate(char* optarg){ + if(!strcmp( optarg, "1M")) return (int)1000; + if(!strcmp( optarg, "500K")) return (int)500; + if(!strcmp( optarg, "250K")) return (int)250; + if(!strcmp( optarg, "125K")) return (int)125; + if(!strcmp( optarg, "100K")) return (int)100; + if(!strcmp( optarg, "50K")) return (int)50; + if(!strcmp( optarg, "20K")) return (int)20; + if(!strcmp( optarg, "10K")) return (int)10; + if(!strcmp( optarg, "5K")) return (int)5; if(!strcmp( optarg, "none")) return 0; - return 0; -}*/ + return 0x0000; +} + +UNS8 canChangeBaudRate_driver( CAN_HANDLE fd0, char* baud) +{ + printf("%x-> changing to baud rate %s[%d]\n", (CANPipe*)fd0 - &canpipes[0],baud,TranslateBaudRate(baud)); + return 0; +} + /***************************************************************************/ CAN_HANDLE canOpen_driver(s_BOARD *board) { diff -r 7d8afedb8769 -r 83793fc7ce48 drivers/hcs12/canOpenDriver.c --- a/drivers/hcs12/canOpenDriver.c Tue Feb 05 10:18:25 2008 +0100 +++ b/drivers/hcs12/canOpenDriver.c Thu Feb 07 10:25:15 2008 +0100 @@ -134,7 +134,7 @@ char * hex_convert (char *buf, unsigned long value, char lastCar) { - //Thanks to Stéphane Carrez for this function + //Thanks to Stphane Carrez for this function char num[32]; int pos; @@ -508,7 +508,10 @@ return 0; } - +UNS8 canChangeBaudRate_driver( CAN_HANDLE fd, char* baud) +{ + return 0; +} /**************************************************************************/ UNS8 f_can_receive(UNS8 notused, Message *msgRcv) { diff -r 7d8afedb8769 -r 83793fc7ce48 drivers/unix/unix.c --- a/drivers/unix/unix.c Tue Feb 05 10:18:25 2008 +0100 +++ b/drivers/unix/unix.c Thu Feb 07 10:25:15 2008 +0100 @@ -101,6 +101,7 @@ DLSYM(canReceive) DLSYM(canSend) DLSYM(canOpen) + DLSYM(canChangeBaudRate) DLSYM(canClose) return handle; @@ -188,3 +189,16 @@ WaitReceiveTaskEnd(tmp->receiveTask); return res; } + + +UNS8 canChangeBaudRate(CAN_PORT port, char* baud) +{ + if(port){ + UNS8 res; + //LeaveMutex(); + res = DLL_CALL(canChangeBaudRate)(((CANPort*)port)->fd, baud); + //EnterMutex(); + return res; // OK + } + return 1; // NOT OK +} diff -r 7d8afedb8769 -r 83793fc7ce48 examples/TestMasterSlaveLSS/Master.c --- a/examples/TestMasterSlaveLSS/Master.c Tue Feb 05 10:18:25 2008 +0100 +++ b/examples/TestMasterSlaveLSS/Master.c Thu Feb 07 10:25:15 2008 +0100 @@ -23,10 +23,9 @@ #include "Master.h" #include "SlaveA.h" #include "SlaveB.h" -#include "TestMasterSlaveLSS.h" - -extern s_BOARD MasterBoard; - +#include "TestMasterSlaveLSS.h" + +extern s_BOARD MasterBoard; /*****************************************************************************/ void TestMaster_heartbeatError(CO_Data* d, UNS8 heartbeatID) { @@ -217,15 +216,16 @@ /* The slaves are now configured (nodeId and Baudrate) via the LSS services. * Switch the LSS state to WAITING and restart the slaves. */ + MasterBoard.baudrate="250K"; printf("Master : Switch Delay period finished. Switching to LSS WAITING state\n"); - configNetworkNode(&TestMaster_Data,LSS_SM_GLOBAL,&LSS_mode,0,NULL); + configNetworkNode(d,LSS_SM_GLOBAL,&LSS_mode,0,NULL); printf("Master : Restarting all the slaves\n"); - masterSendNMTstateChange (&TestMaster_Data, 0x00, NMT_Reset_Node); + masterSendNMTstateChange (d, 0x00, NMT_Reset_Node); printf("Master : Starting the SYNC producer\n"); - writeLocalDict( &TestMaster_Data, /*CO_Data* d*/ + writeLocalDict( d, /*CO_Data* d*/ 0x1006, /*UNS16 index*/ 0x00, /*UNS8 subind*/ &SINC_cicle, /*void * pSourceData,*/ @@ -235,8 +235,12 @@ return; } else{ - printf("Master : unable to activate bit timing. trying again\n"); - init_step_LSS--; + UNS16 Switch_delay=1; + UNS8 LSS_mode=LSS_CONFIGURATION_MODE; + + eprintf("Master : unable to activate bit timing. trying again\n"); + configNetworkNode(d,LSS_CONF_ACT_BIT_TIMING,&Switch_delay,0,CheckLSSAndContinue); + return; } break; case LSS_SM_SELECTIVE_SERIAL: @@ -257,9 +261,9 @@ * Start the configuration of the baud rate. */ eprintf("Master : There are not no-configured slaves in the net\n", command); eprintf("Switching all the nodes to LSS CONFIGURATION state\n"); - configNetworkNode(&TestMaster_Data,LSS_SM_GLOBAL,&LSS_mode,0,NULL); + configNetworkNode(d,LSS_SM_GLOBAL,&LSS_mode,0,NULL); eprintf("LSS=>Activate Bit Timing\n"); - configNetworkNode(&TestMaster_Data,LSS_CONF_ACT_BIT_TIMING,&Switch_delay,0,CheckLSSAndContinue); + configNetworkNode(d,LSS_CONF_ACT_BIT_TIMING,&Switch_delay,0,CheckLSSAndContinue); return; } break; @@ -326,7 +330,8 @@ UNS32 Serial_Number_low=0x56789010; UNS8 LSS_mode=LSS_WAITING_MODE; UNS8 Baud_Table=0; - UNS8 Baud_BitTiming=3; + //UNS8 Baud_BitTiming=3; + char* Baud_BitTiming="250K"; UNS8 res; eprintf("ConfigureLSSNode step %d -> ",init_step_LSS); @@ -450,9 +455,3 @@ ConfigureSlaveNode(d, nodeid); } -void TestMaster_ChangeBaudRate(CO_Data* d, char *baudrate) -{ - eprintf("TestMaster_ChangeBaudRate from %s to %s\n", MasterBoard.baudrate, baudrate); - MasterBoard.baudrate=baudrate; - /* something to do with the new baudrate */ -} diff -r 7d8afedb8769 -r 83793fc7ce48 examples/TestMasterSlaveLSS/Master.h --- a/examples/TestMasterSlaveLSS/Master.h Tue Feb 05 10:18:25 2008 +0100 +++ b/examples/TestMasterSlaveLSS/Master.h Thu Feb 07 10:25:15 2008 +0100 @@ -13,4 +13,4 @@ void TestMaster_post_TPDO(CO_Data* d); void TestMaster_post_emcy(CO_Data* d, UNS8 nodeID, UNS16 errCode, UNS8 errReg); void TestMaster_post_SlaveBootup(CO_Data* d, UNS8 nodeid); -void TestMaster_ChangeBaudRate(CO_Data* d,char *baudrate); + diff -r 7d8afedb8769 -r 83793fc7ce48 examples/TestMasterSlaveLSS/SlaveA.c --- a/examples/TestMasterSlaveLSS/SlaveA.c Tue Feb 05 10:18:25 2008 +0100 +++ b/examples/TestMasterSlaveLSS/SlaveA.c Thu Feb 07 10:25:15 2008 +0100 @@ -24,7 +24,6 @@ #include "Master.h" #include "TestMasterSlaveLSS.h" -extern s_BOARD SlaveBoardA; /*****************************************************************************/ void TestSlaveA_heartbeatError(CO_Data* d, UNS8 heartbeatID) { @@ -87,9 +86,3 @@ printf("TestSlaveA_StoreConfiguration\n"); } -void TestSlaveA_ChangeBaudRate(CO_Data* d, char *baudrate) -{ - eprintf("TestSlaveA_ChangeBaudRate from %s to %s\n", SlaveBoardA.baudrate, baudrate); - SlaveBoardA.baudrate=baudrate; - /* something to do with the new baudrate */ -} diff -r 7d8afedb8769 -r 83793fc7ce48 examples/TestMasterSlaveLSS/SlaveA.h --- a/examples/TestMasterSlaveLSS/SlaveA.h Tue Feb 05 10:18:25 2008 +0100 +++ b/examples/TestMasterSlaveLSS/SlaveA.h Thu Feb 07 10:25:15 2008 +0100 @@ -14,4 +14,3 @@ void TestSlaveA_storeODSubIndex(CO_Data* d, UNS16 wIndex, UNS8 bSubindex); void TestSlaveA_post_emcy(CO_Data* d, UNS8 nodeID, UNS16 errCode, UNS8 errReg); void TestSlaveA_StoreConfiguration(CO_Data* d, UNS8 *error, UNS8 *spec_error); -void TestSlaveA_ChangeBaudRate(CO_Data* d, char *baudrate); diff -r 7d8afedb8769 -r 83793fc7ce48 examples/TestMasterSlaveLSS/SlaveB.c --- a/examples/TestMasterSlaveLSS/SlaveB.c Tue Feb 05 10:18:25 2008 +0100 +++ b/examples/TestMasterSlaveLSS/SlaveB.c Thu Feb 07 10:25:15 2008 +0100 @@ -24,7 +24,6 @@ #include "Master.h" #include "TestMasterSlaveLSS.h" -extern s_BOARD SlaveBoardB; /*****************************************************************************/ void TestSlaveB_heartbeatError(CO_Data* d, UNS8 heartbeatID) { @@ -86,9 +85,3 @@ printf("TestSlaveB_StoreConfiguration\n"); } -void TestSlaveB_ChangeBaudRate(CO_Data* d, char *baudrate) -{ - eprintf("TestSlave2_ChangeBaudRate from %s to %s\n", SlaveBoardB.baudrate, baudrate); - SlaveBoardB.baudrate=baudrate; - /* something to do with the new baudrate */ -} diff -r 7d8afedb8769 -r 83793fc7ce48 examples/TestMasterSlaveLSS/SlaveB.h --- a/examples/TestMasterSlaveLSS/SlaveB.h Tue Feb 05 10:18:25 2008 +0100 +++ b/examples/TestMasterSlaveLSS/SlaveB.h Thu Feb 07 10:25:15 2008 +0100 @@ -14,4 +14,3 @@ void TestSlaveB_storeODSubIndex(CO_Data* d, UNS16 wIndex, UNS8 bSubindex); void TestSlaveB_post_emcy(CO_Data* d, UNS8 nodeID, UNS16 errCode, UNS8 errReg); void TestSlaveB_StoreConfiguration(CO_Data* d, UNS8 *error, UNS8 *spec_error); -void TestSlaveB_ChangeBaudRate(CO_Data* d, char *baudrate); diff -r 7d8afedb8769 -r 83793fc7ce48 examples/TestMasterSlaveLSS/TestMasterSlaveLSS.c --- a/examples/TestMasterSlaveLSS/TestMasterSlaveLSS.c Tue Feb 05 10:18:25 2008 +0100 +++ b/examples/TestMasterSlaveLSS/TestMasterSlaveLSS.c Thu Feb 07 10:25:15 2008 +0100 @@ -203,7 +203,6 @@ TestSlaveA_Data.post_emcy = TestSlaveA_post_emcy; /* in this example the slave doesn't support Store configuration*/ TestSlaveA_Data.lss_StoreConfiguration = TestSlaveA_StoreConfiguration; - TestSlaveA_Data.lss_ChangeBaudRate=TestSlaveA_ChangeBaudRate; if(!canOpen(&SlaveBoardA,&TestSlaveA_Data)){ eprintf("Cannot open SlaveA Board (%s,%s)\n",SlaveBoardA.busname, SlaveBoardA.baudrate); @@ -223,8 +222,6 @@ TestSlaveB_Data.storeODSubIndex = TestSlaveB_storeODSubIndex; TestSlaveB_Data.post_emcy = TestSlaveB_post_emcy; TestSlaveB_Data.lss_StoreConfiguration = TestSlaveB_StoreConfiguration; - TestSlaveB_Data.lss_ChangeBaudRate=TestSlaveB_ChangeBaudRate; - if(!canOpen(&SlaveBoardB,&TestSlaveB_Data)){ eprintf("Cannot open SlaveB Board (%s,%s)\n",SlaveBoardB.busname, SlaveBoardB.baudrate); @@ -243,7 +240,6 @@ TestMaster_Data.post_TPDO = TestMaster_post_TPDO; TestMaster_Data.post_emcy = TestMaster_post_emcy; TestMaster_Data.post_SlaveBootup=TestMaster_post_SlaveBootup; - TestMaster_Data.lss_ChangeBaudRate=TestMaster_ChangeBaudRate; if(!canOpen(&MasterBoard,&TestMaster_Data)){ eprintf("Cannot open Master Board (%s,%s)\n",MasterBoard.busname, MasterBoard.baudrate); diff -r 7d8afedb8769 -r 83793fc7ce48 include/AVR/can_AVR.h --- a/include/AVR/can_AVR.h Tue Feb 05 10:18:25 2008 +0100 +++ b/include/AVR/can_AVR.h Thu Feb 07 10:25:15 2008 +0100 @@ -51,4 +51,5 @@ unsigned char canInit(unsigned int bitrate); unsigned char canSend(CAN_PORT notused, Message *m); unsigned char canReceive(Message *m); +unsigned char canChangeBaudRate_driver( CAN_HANDLE fd, char* baud); #endif diff -r 7d8afedb8769 -r 83793fc7ce48 include/AVR/canfestival.h --- a/include/AVR/canfestival.h Tue Feb 05 10:18:25 2008 +0100 +++ b/include/AVR/canfestival.h Thu Feb 07 10:25:15 2008 +0100 @@ -30,5 +30,6 @@ // --------- to be called by user app --------- void initTimer(void); UNS8 canSend(CAN_PORT notused, Message *m); +UNS8 canChangeBaudRate(CAN_PORT port, char* baud); #endif diff -r 7d8afedb8769 -r 83793fc7ce48 include/can_driver.h --- a/include/can_driver.h Tue Feb 05 10:18:25 2008 +0100 +++ b/include/can_driver.h Thu Feb 07 10:25:15 2008 +0100 @@ -48,6 +48,7 @@ UNS8 DLL_CALL(canSend)(CAN_HANDLE, Message *)FCT_PTR_INIT; CAN_HANDLE DLL_CALL(canOpen)(s_BOARD *)FCT_PTR_INIT; int DLL_CALL(canClose)(CAN_HANDLE)FCT_PTR_INIT; +UNS8 DLL_CALL(canChangeBaudRate)(CAN_HANDLE, char *)FCT_PTR_INIT; #if defined DEBUG_MSG_CONSOLE_ON || defined NEED_PRINT_MESSAGE #include "def.h" diff -r 7d8afedb8769 -r 83793fc7ce48 include/data.h --- a/include/data.h Tue Feb 05 10:18:25 2008 +0100 +++ b/include/data.h Thu Feb 07 10:25:15 2008 +0100 @@ -117,7 +117,6 @@ /* LSS */ lss_transfer_t lss_transfer; lss_StoreConfiguration_t lss_StoreConfiguration; - lss_ChangeBaudRate_t lss_ChangeBaudRate; #endif }; @@ -180,8 +179,7 @@ 0 /* LSSanswer */\ lss_fs_Initializer /*FastScan service initialization */\ },\ - NULL, /* _lss_StoreConfiguration*/\ - NULL /* _lss_ChangeBaudRate */ + NULL /* _lss_StoreConfiguration*/ #else #define lss_Initializer #endif diff -r 7d8afedb8769 -r 83793fc7ce48 include/hcs12/canOpenDriver.h --- a/include/hcs12/canOpenDriver.h Tue Feb 05 10:18:25 2008 +0100 +++ b/include/hcs12/canOpenDriver.h Thu Feb 07 10:25:15 2008 +0100 @@ -39,5 +39,6 @@ (see include/hcs12/canOpenDriver.c) */ UNS8 f_can_receive(UNS8 notused, Message *m); +UNS8 canChangeBaudRate_driver( CAN_HANDLE fd, char* baud); #endif diff -r 7d8afedb8769 -r 83793fc7ce48 include/lss.h --- a/include/lss.h Tue Feb 05 10:18:25 2008 +0100 +++ b/include/lss.h Thu Feb 07 10:25:15 2008 +0100 @@ -74,7 +74,7 @@ typedef void (*lss_StoreConfiguration_t)(CO_Data* d,UNS8*,UNS8*); //void _lss_StoreConfiguration(UNS8 *error, UNS8 *spec_error); -typedef void (*lss_ChangeBaudRate_t)(CO_Data* d,char*); +//typedef void (*lss_ChangeBaudRate_t)(CO_Data* d,char*); //void _lss_ChangeBaudRate(char *BaudRate); diff -r 7d8afedb8769 -r 83793fc7ce48 include/unix/canfestival.h --- a/include/unix/canfestival.h Tue Feb 05 10:18:25 2008 +0100 +++ b/include/unix/canfestival.h Thu Feb 07 10:25:15 2008 +0100 @@ -18,6 +18,7 @@ UNS8 canSend(CAN_PORT port, Message *m); CAN_PORT canOpen(s_BOARD *board, CO_Data * d); int canClose(CO_Data * d); +UNS8 canChangeBaudRate(CAN_PORT port, char* baud); #ifdef __cplusplus }; diff -r 7d8afedb8769 -r 83793fc7ce48 include/win32/canfestival.h --- a/include/win32/canfestival.h Tue Feb 05 10:18:25 2008 +0100 +++ b/include/win32/canfestival.h Thu Feb 07 10:25:15 2008 +0100 @@ -36,5 +36,6 @@ UNS8 canSend(CAN_PORT port, Message *m); CAN_PORT canOpen(s_BOARD *board, CO_Data * d); int canClose(CO_Data * d); +UNS8 canChangeBaudRate(CAN_PORT port, char* baud); #endif /*CANFESTIVAL_H_*/ diff -r 7d8afedb8769 -r 83793fc7ce48 src/lss.c --- a/src/lss.c Tue Feb 05 10:18:25 2008 +0100 +++ b/src/lss.c Thu Feb 07 10:25:15 2008 +0100 @@ -162,7 +162,8 @@ if(d->lss_transfer.switchDelayState==SDELAY_FIRST){ MSG_WAR(0x3D0B, "LSS switch delay first period expired",0); d->lss_transfer.switchDelayState=SDELAY_SECOND; - (*d->lss_ChangeBaudRate)(d,d->lss_transfer.baudRate); + //(*d->lss_ChangeBaudRate)(d,d->lss_transfer.baudRate); + canChangeBaudRate(d->lss_transfer.canHandle_t, d->lss_transfer.baudRate); } else{ /* d->lss_transfer.switchDelayState==SDELAY_SECOND */ MSG_WAR(0x3D0C, "LSS switch delay second period expired",0); @@ -346,6 +347,20 @@ return canSend(d->canHandle,&m); } + +/* If a baud rate is not supported just comment the line. */ +static UNS8 CO_TranslateBaudRate(char* optarg){ + if(!strcmp( optarg, "1M")) return 0x00; + if(!strcmp( optarg, "800K")) return 0x01; + if(!strcmp( optarg, "500K")) return 0x02; + if(!strcmp( optarg, "250K")) return 0x03; + if(!strcmp( optarg, "125K")) return 0x04; + if(!strcmp( optarg, "100K")) return 0x05; + if(!strcmp( optarg, "50K")) return 0x06; + if(!strcmp( optarg, "20K")) return 0x07; + if(!strcmp( optarg, "10K")) return 0x08; + return -1; +} /*! ** @@ -376,39 +391,28 @@ m.data[1]=*(UNS8 *)dat1; break; case LSS_CONF_BIT_TIMING: /* Configure Bit Timing Parameters */ + m.data[1]=*(UNS8 *)dat1; - m.data[2]=*(UNS8 *)dat2; - if(d->lss_ChangeBaudRate){ - /* If a baud rate is not supported just comment the line. */ - switch(m.data[2]){ - case 0x00:d->lss_transfer.baudRate="1M";break; - case 0x01:d->lss_transfer.baudRate="800K";break; - case 0x02:d->lss_transfer.baudRate="500K";break; - case 0x03:d->lss_transfer.baudRate="250K";break; - case 0x04:d->lss_transfer.baudRate="125K";break; - case 0x05:d->lss_transfer.baudRate="100K";break; - case 0x06:d->lss_transfer.baudRate="50K";break; - case 0x07:d->lss_transfer.baudRate="20K";break; - case 0x08:d->lss_transfer.baudRate="10K";break; - default: - MSG_ERR(0x1D19, "Master-> Baud rate not supported",0); - d->lss_transfer.dat1=0xFF; - goto ErrorBitRateMaster; - break; - } - hasResponse=1; - break; - } - else{ + d->lss_transfer.baudRate=*(char **)dat2; + + if((m.data[2]=CO_TranslateBaudRate(d->lss_transfer.baudRate))>0){ + hasResponse=1; + break; + } + + MSG_ERR(0x1D19, "Master-> Baud rate not supported",0); + d->lss_transfer.dat1=0xFF; + + /* if bit timing is not supported comment the previous code and uncomment the following one*/ + /*{ MSG_ERR(0x1D1A, "Master-> Bit timing not supported",0); d->lss_transfer.dat1=0x01; - } - -ErrorBitRateMaster: + }*/ + d->lss_transfer.dat2=0; /* If there is a callback, it is responsible of the error */ if(d->lss_transfer.Callback) - (*d->lss_transfer.Callback)(d,d->lss_transfer.command); + (*d->lss_transfer.Callback)(d,d->lss_transfer.command); return 0xFF; break; case LSS_CONF_ACT_BIT_TIMING: /* Activate Bit Timing Parameters */ @@ -417,6 +421,7 @@ if(d->lss_transfer.baudRate!="none"){ d->lss_transfer.switchDelay=(UNS16)(*(UNS32*)dat1 & 0xFFFF); d->lss_transfer.switchDelayState=SDELAY_FIRST; + d->lss_transfer.canHandle_t=d->canHandle; res=canSend(d->canHandle,&m); if(res==0){ StartLSS_SDELAY_TIMER(); @@ -673,31 +678,21 @@ UNS8 spec_error=0; if(d->lss_transfer.mode==LSS_CONFIGURATION_MODE){ - /* Change the baud rate only if the function lss_ChangeBaudRate - * has been implemented. If not send an error. - */ - if(d->lss_ChangeBaudRate){ - /* If a baud rate is not supported just comment the line. */ - switch(m->data[2]){ - case 0x00:d->lss_transfer.baudRate="1M";break; - case 0x01:d->lss_transfer.baudRate="800K";break; - case 0x02:d->lss_transfer.baudRate="500K";break; - case 0x03:d->lss_transfer.baudRate="250K";break; - case 0x04:d->lss_transfer.baudRate="125K";break; - case 0x05:d->lss_transfer.baudRate="100K";break; - case 0x06:d->lss_transfer.baudRate="50K";break; - case 0x07:d->lss_transfer.baudRate="20K";break; - case 0x08:d->lss_transfer.baudRate="10K";break; - default: - MSG_ERR(0x1D28, "Baud rate not supported",0); - error_code=0xFF; /* Baud rate not supported*/ - break; - } - } - else - { - MSG_ERR(0x1D29, "Bit timing not supported",0); - error_code=0x01; /* bit timing not supported */ + /* If a baud rate is not supported just comment the line. */ + switch(m->data[2]){ + case 0x00:d->lss_transfer.baudRate="1M";break; + case 0x01:d->lss_transfer.baudRate="800K";break; + case 0x02:d->lss_transfer.baudRate="500K";break; + case 0x03:d->lss_transfer.baudRate="250K";break; + case 0x04:d->lss_transfer.baudRate="125K";break; + case 0x05:d->lss_transfer.baudRate="100K";break; + case 0x06:d->lss_transfer.baudRate="50K";break; + case 0x07:d->lss_transfer.baudRate="20K";break; + case 0x08:d->lss_transfer.baudRate="10K";break; + default: + MSG_ERR(0x1D28, "Baud rate not supported",0); + error_code=0xFF; /* Baud rate not supported*/ + break; } } else{ @@ -706,6 +701,12 @@ break; } + /* if bit timing is not supported comment the previous code and uncomment the following */ + /*{ + MSG_ERR(0x1D29, "Bit timing not supported",0); + error_code=0x01; // bit timing not supported + }*/ + sendSlaveLSSMessage(d,msg_cs,&error_code,&spec_error); } break; @@ -981,6 +982,5 @@ } //void _lss_StoreConfiguration(UNS8 *error, UNS8 *spec_error){printf("_lss_StoreConfiguration\n");} -//void _lss_ChangeBaudRate(char *BaudRate){printf("_lss_ChangeBaudRate\n");} #endif