Sam Grove / Mbed 2 deprecated canopen_masternode

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers lss.c Source File

lss.c

Go to the documentation of this file.
00001 /*
00002 This file is part of CanFestival, a library implementing CanOpen Stack. 
00003 
00004 
00005 Copyright (C): Jorge Berzosa
00006 
00007 
00008 See COPYING file for copyrights details.
00009 
00010 
00011 This library is free software; you can redistribute it and/or
00012 modify it under the terms of the GNU Lesser General Public
00013 License as published by the Free Software Foundation; either
00014 version 2.1 of the License, or (at your option) any later version.
00015 
00016 
00017 This library is distributed in the hope that it will be useful,
00018 but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020 Lesser General Public License for more details.
00021 
00022 
00023 You should have received a copy of the GNU Lesser General Public
00024 License along with this library; if not, write to the Free Software
00025 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026 */
00027 
00028 
00029 /*!
00030 ** @file   lss.c
00031 ** @author Jorge Berzosa
00032 ** @date   Mon Oct  22 05:44:32 2007
00033 **
00034 ** @brief
00035 **
00036 **
00037 */
00038 
00039 
00040 #include "data.h"
00041 #include "lss.h"
00042 #include "canfestival.h"
00043 #include "sysdep.h"
00044 
00045 #ifdef CO_ENABLE_LSS
00046 
00047 //#define LSS_TIMEOUT_MS    (TIMEVAL)1000  /* ms */
00048 //#define LSS_FS_TIMEOUT_MS (TIMEVAL)100  /* ms */
00049 
00050 /* Returns the LSS ident field from a Message struct */
00051 #define getLSSIdent(msg) (((UNS32)msg->data[4] << 24) | ((UNS32)msg->data[3] << 16) | (msg->data[2] << 8) | (msg->data[1]))
00052 
00053 
00054 /* Returns the LSS switch delay field from a Message struct */
00055 #define getLSSDelay(msg) ((msg->data[2] << 8) | (msg->data[1]))
00056 
00057 /* Returns the LSS FastScan BitCheck field from a Message struct */
00058 #define getLSSBitCheck(msg) msg->data[5]
00059 
00060 /* Returns the LSS FastScan LSSSub field from a Message struct */
00061 #define getLSSSub(msg) msg->data[6]
00062 
00063 /* Returns the LSS FastScan LSSNext field from a Message struct */
00064 #define getLSSNext(msg) msg->data[7]
00065 
00066 /* Prototypes for internals functions */
00067 UNS8 sendMasterLSSMessage (CO_Data* d, UNS8 command,void *dat1,void *dat2);
00068 void LssAlarmMSG(CO_Data* d, UNS32 id);
00069 void LssAlarmSDELAY (CO_Data* d, UNS32 id);
00070 
00071 
00072 #define StopLSS_MSG_TIMER(){\
00073  MSG_WAR(0x3D01, "StopLSS_MSG_TIMER", 0);\
00074  d->lss_transfer.timerMSG = DelAlarm(d->lss_transfer.timerMSG);}
00075 
00076 #define StartLSS_MSG_TIMER(){\
00077  MSG_WAR(0x3D02, "StartLSS_MSG_TIMER",0);\
00078  d->lss_transfer.timerMSG = SetAlarm(d,0,&LssAlarmMSG,MS_TO_TIMEVAL(LSS_TIMEOUT_MS),0);}
00079  
00080 #define StopLSS_SDELAY_TIMER(){\
00081  MSG_WAR(0x3D03, "StopLSS_SDELAY_TIMER", 0);\
00082  d->lss_transfer.timerSDELAY = DelAlarm(d->lss_transfer.timerSDELAY);}
00083 
00084 #define StartLSS_SDELAY_TIMER(){\
00085  MSG_WAR(0x3D04, "StartLSS_SDELAY_TIMER",0);\
00086  d->lss_transfer.timerSDELAY= SetAlarm(d,0,&LssAlarmSDELAY,MS_TO_TIMEVAL(d->lss_transfer.switchDelay),MS_TO_TIMEVAL(d->lss_transfer.switchDelay));}
00087 
00088 
00089 #ifdef CO_ENABLE_LSS_FS
00090 /* Prototypes for internals functions */
00091 void LssAlarmFS (CO_Data* d, UNS32 id);
00092 
00093 #define StopLSS_FS_TIMER(){\
00094  MSG_WAR(0x3D05, "StopLSS_FS_TIMER", id);\
00095  d->lss_transfer.timerFS = DelAlarm(d->lss_transfer.timerFS);}
00096 
00097 #define StartLSS_FS_TIMER(){\
00098  MSG_WAR(0x3D06, "StartLSS_FS_TIMER",0);\
00099  d->lss_transfer.timerFS = SetAlarm(d,0,&LssAlarmFS,MS_TO_TIMEVAL(LSS_FS_TIMEOUT_MS),0);}
00100 #endif
00101 
00102 
00103 void LssAlarmMSG(CO_Data* d, UNS32 id)
00104 {   
00105     StopLSS_MSG_TIMER();
00106 #ifdef CO_ENABLE_LSS_FS
00107     if(d->lss_transfer.command==LSS_IDENT_FASTSCAN){
00108         if(d->lss_transfer.FastScan_SM==LSS_FS_RESET){
00109             /* if at least one node had answered before the timer expired, start the FastScan protocol*/
00110             if(d->lss_transfer.LSSanswer!=0){
00111                 UNS32 Mask=0xFFFFFFFF;
00112                 d->lss_transfer.LSSanswer=0;
00113                 d->lss_transfer.BitChecked=d->lss_transfer.lss_fs_transfer.FS_BitChecked[0];
00114                 Mask=(UNS32)((UNS64)Mask<<(d->lss_transfer.BitChecked+1));
00115                 d->lss_transfer.IDNumber=d->lss_transfer.lss_fs_transfer.FS_LSS_ID[0] & Mask;
00116                 d->lss_transfer.FastScan_SM=LSS_FS_PROCESSING;
00117                 //printf("BitChecked=%d, IDNumber=%x MASK=%x\n",d->lss_transfer.BitChecked,d->lss_transfer.IDNumber,Mask);
00118                 StartLSS_FS_TIMER();
00119                 sendMasterLSSMessage (d,LSS_IDENT_FASTSCAN,0,0);
00120                 return;
00121             }
00122             else{ 
00123             
00124                 d->lss_transfer.state = LSS_FINISHED;
00125                 /* Inform the application that there aren't not configured nodes in the net  */
00126                 d->lss_transfer.dat1=1;
00127             }
00128         }
00129         else{
00130             /* This should not happen, an error ocurred*/
00131             MSG_ERR(0x1D07, "LSS FastScan timeout. FastScan_SM inconsisten state.", d->lss_transfer.FastScan_SM);
00132             d->lss_transfer.state = LSS_ABORTED_INTERNAL;
00133             d->lss_transfer.FastScan_SM=LSS_FS_RESET;
00134         }
00135     }
00136     else
00137 #endif
00138     if(d->lss_transfer.command==LSS_IDENT_REMOTE_NON_CONF){
00139             MSG_WAR(0x2D08, "LSS timeout. There are not no-configured slaves in the net", 0);
00140             d->lss_transfer.state = LSS_FINISHED;
00141             d->lss_transfer.dat1=1;
00142     }
00143     else{
00144         MSG_ERR(0x1D09, "LSS timeout. LSS response not received.", 0);
00145         MSG_WAR(0x2D0A, "LSS timeout command specifier : ", d->lss_transfer.command);
00146         /* Set aborted state */
00147         d->lss_transfer.state = LSS_ABORTED_INTERNAL;
00148 #ifdef CO_ENABLE_LSS_FS
00149         d->lss_transfer.FastScan_SM = LSS_FS_RESET;
00150 #endif
00151     }
00152         
00153     /* Call the user function to inform of the problem.*/
00154     if(d->lss_transfer.Callback){
00155         /*If there is a callback, it is responsible of the error*/
00156         (*d->lss_transfer.Callback)(d,d->lss_transfer.command);
00157     }
00158 }
00159     
00160     
00161 /*!                                                                                                
00162 **                                                                                                 
00163 **                                                                                                 
00164 ** @param d                                                                                        
00165 ** @param id                                                                                       
00166 **/   
00167 void LssAlarmSDELAY (CO_Data* d, UNS32 id)
00168 {   
00169     
00170     /* The first switch_delay period expired. Store the node state, change it 
00171      * so no CAN messages will be sent or received, call the ChangeBaudRate function*/
00172     if(d->lss_transfer.switchDelayState==SDELAY_FIRST){
00173         MSG_WAR(0x3D0B, "LSS switch delay first period expired",0);
00174         d->lss_transfer.switchDelayState=SDELAY_SECOND;
00175         //(*d->lss_ChangeBaudRate)(d,d->lss_transfer.baudRate);
00176         canChangeBaudRate(d->lss_transfer.canHandle_t, d->lss_transfer.baudRate);
00177     }
00178     else{ /* d->lss_transfer.switchDelayState==SDELAY_SECOND */
00179         MSG_WAR(0x3D0C, "LSS switch delay second period expired",0);
00180         d->lss_transfer.switchDelayState=SDELAY_OFF;
00181         StopLSS_SDELAY_TIMER();
00182             
00183         if (*(d->iam_a_slave))
00184             d->canHandle=d->lss_transfer.canHandle_t;
00185         else{
00186             d->lss_transfer.dat1=0;
00187             d->lss_transfer.state=LSS_FINISHED;
00188             /* Call the user function */
00189             if(d->lss_transfer.Callback){
00190                 (*d->lss_transfer.Callback)(d,d->lss_transfer.command);
00191             }
00192         }
00193     }
00194 } 
00195 
00196 #ifdef CO_ENABLE_LSS_FS
00197 /*!                                                                                                
00198 **                                                                                                 
00199 **                                                                                                 
00200 ** @param d                                                                                        
00201 ** @param id                                                                                       
00202 **/   
00203 void LssAlarmFS (CO_Data* d, UNS32 id)
00204 {   
00205     StopLSS_FS_TIMER();
00206         
00207     switch(d->lss_transfer.FastScan_SM){
00208     case LSS_FS_RESET:
00209     {
00210         /* This should not happen, an error ocurred*/
00211         MSG_ERR(0x1D0D, "LSS FastScan timeout. FastScan_SM inconsisten state.", d->lss_transfer.FastScan_SM);
00212     }
00213     break;
00214     case LSS_FS_PROCESSING:
00215     {
00216         /* If there isn't any answer, set the bit */
00217         if(d->lss_transfer.LSSanswer==0){
00218             UNS32 Mask=0x1;
00219             Mask<<=d->lss_transfer.BitChecked;
00220             d->lss_transfer.IDNumber|=Mask;
00221         }
00222         
00223         if(d->lss_transfer.BitChecked==0){
00224             /* We finished with the current LSS-ID[sub], confirm it */
00225             d->lss_transfer.FastScan_SM=LSS_FS_CONFIRMATION;
00226             if(d->lss_transfer.LSSNext<3)d->lss_transfer.LSSNext++;
00227         }
00228         else{
00229             d->lss_transfer.BitChecked--;
00230         }
00231         //printf("BitChecked=%d, IDNumber=%x\n",d->lss_transfer.BitChecked,d->lss_transfer.IDNumber);
00232         d->lss_transfer.LSSanswer=0;
00233         StartLSS_FS_TIMER();
00234         sendMasterLSSMessage (d,LSS_IDENT_FASTSCAN,0,0);
00235         return;
00236     }
00237     break;
00238     case LSS_FS_CONFIRMATION:
00239     {
00240         if(d->lss_transfer.LSSanswer!=0){
00241             d->lss_transfer.LSSanswer=0;
00242             
00243             if(d->lss_transfer.LSSSub==3){
00244                 /* The LSS FastScan protocol finished correctly. Restore the parameters */
00245                 d->lss_transfer.BitChecked=128;
00246                 d->lss_transfer.FastScan_SM=LSS_FS_RESET;
00247                 d->lss_transfer.LSSSub=0;
00248                 d->lss_transfer.LSSNext=0;
00249                 d->lss_transfer.IDNumber=0;
00250                 
00251                 /* Inform the application that the FastScan finished correctly */
00252                 d->lss_transfer.state = LSS_FINISHED;
00253                 d->lss_transfer.dat1=0;
00254             }
00255             else{
00256                 UNS32 Mask=0xFFFFFFFF;
00257                 /* Start with the next LSS-ID[sub] */
00258                 d->lss_transfer.LSSSub++;
00259                 d->lss_transfer.BitChecked=d->lss_transfer.lss_fs_transfer.FS_BitChecked[d->lss_transfer.LSSSub];
00260                 Mask=(UNS32)((UNS64)Mask<<(d->lss_transfer.BitChecked+1));
00261                 d->lss_transfer.IDNumber=d->lss_transfer.lss_fs_transfer.FS_LSS_ID[d->lss_transfer.LSSSub] & Mask;
00262                 d->lss_transfer.FastScan_SM=LSS_FS_PROCESSING;
00263                 //printf("BitChecked=%d, IDNumber=%x MASK=%x\n",d->lss_transfer.BitChecked,d->lss_transfer.IDNumber,Mask);
00264                 StartLSS_FS_TIMER();
00265                 sendMasterLSSMessage (d,LSS_IDENT_FASTSCAN,0,0);
00266                 return;
00267             }
00268         }
00269         else{
00270             /* This should not happen, an error ocurred*/
00271             MSG_ERR(0x1D0E, "LSS FastScan timeout. FastScan response not received.", 0);
00272             MSG_ERR(0x1D0E, "There is not any node with LSS_ID# =>", d->lss_transfer.LSSSub);
00273             MSG_ERR(0x1D0E, "with the value =>", d->lss_transfer.IDNumber);
00274             /* Set aborted state */
00275             d->lss_transfer.state = LSS_ABORTED_INTERNAL;
00276             d->lss_transfer.FastScan_SM = LSS_FS_RESET;
00277         }
00278     }
00279     break;
00280     }
00281 
00282     /* Call the user function to inform of the problem.*/
00283     if(d->lss_transfer.Callback){
00284         /*If there is a callback, it is responsible of the error*/
00285         (*d->lss_transfer.Callback)(d,d->lss_transfer.command);
00286     }
00287 }
00288 #endif
00289 
00290     
00291 /*!                                                                                                
00292 **                                                                                                 
00293 **                                                                                                 
00294 ** @param d                                                                                        
00295 **/ 
00296 void startLSS (CO_Data* d)
00297 {
00298     /*MSG_WAR(0x3D09, "LSS services started",0);*/
00299 }
00300 
00301 /*!                                                                                                
00302 **                                                                                                 
00303 **                                                                                                 
00304 ** @param d                                                                                        
00305 **/   
00306 void stopLSS (CO_Data* d)
00307 {
00308     /*MSG_WAR(0x3D09, "LSS services stopped",0);*/
00309 }
00310 
00311 /*!                                                                                                
00312 **                                                                                                 
00313 **                                                                                                 
00314 ** @param d                                                                                        
00315 ** @param cob_id                                                                                   
00316 **                                                                                                 
00317 ** @return                                                                                         
00318 **/  
00319 UNS8 sendSlaveLSSMessage (CO_Data* d, UNS8 command,void *dat1,void *dat2)
00320 {
00321   Message m;
00322   UNS8 i;
00323   
00324   if (!d->CurrentCommunicationState.csLSS){
00325     MSG_WAR(0x2D17, "unable to send the LSS message, not in the proper state =>", d->nodeState);
00326     return 0xFF;
00327   }
00328    
00329   for(i=1;i<8;i++)m.data[i]=0;
00330   m.len = 8;
00331   m.rtr = NOT_A_REQUEST;
00332   m.data[0]=command;
00333   m.cob_id=UNS16_LE(SLSS_ADRESS);
00334   
00335   /* Tha data sent with the msg depends on the command */
00336   switch(command){
00337   case LSS_INQ_NODE_ID: /* Inquire Node-ID */
00338     m.data[1]=*(UNS8 *)dat1;
00339     break;
00340   case LSS_CONF_NODE_ID: /* Configure Node-ID */
00341   case LSS_CONF_BIT_TIMING: /* Configure Bit Timing Parameters */
00342   case LSS_CONF_STORE: /* Store Configured Parameters */
00343     m.data[1]=*(UNS8 *)dat1;
00344     m.data[2]=*(UNS8 *)dat2;
00345     break; 
00346   case LSS_INQ_VENDOR_ID: /* Inquire Identity Vendor-ID */
00347   case LSS_INQ_PRODUCT_CODE: /* Inquire Identity Product-Code */
00348   case LSS_INQ_REV_NUMBER: /* Inquire Identity Revision-Number */
00349   case LSS_INQ_SERIAL_NUMBER: /* Inquire Identity Serial-Number */
00350     m.data[1]=(UNS8)(*(UNS32*)dat1 & 0xFF);
00351     m.data[2]=(UNS8)(*(UNS32*)dat1>>8 & 0xFF);
00352     m.data[3]=(UNS8)(*(UNS32*)dat1>>16 & 0xFF);
00353     m.data[4]=(UNS8)(*(UNS32*)dat1>>24 & 0xFF);
00354     break;
00355   case LSS_SM_SELECTIVE_RESP: /* Switch Mode Selective response*/
00356   case LSS_IDENT_SLAVE: /* LSS Identify Slave */
00357   case LSS_IDENT_NON_CONF_SLAVE: /* LSS identify non-configured remote slave */
00358     break;
00359   default:
00360     MSG_ERR(0x1D18, "send Slave LSS command not implemented", command);
00361     return 0xFF;
00362   }
00363   
00364   return canSend(d->canHandle,&m);
00365 }
00366             
00367 /* If a baud rate is not supported just comment the line. */
00368 static UNS8 CO_TranslateBaudRate(char* optarg){
00369     if(!strcmp( optarg, "1M")) return 0x00;
00370     if(!strcmp( optarg, "800K")) return 0x01;
00371     if(!strcmp( optarg, "500K")) return 0x02;
00372     if(!strcmp( optarg, "250K")) return 0x03;
00373     if(!strcmp( optarg, "125K")) return 0x04;
00374     if(!strcmp( optarg, "100K")) return 0x05;
00375     if(!strcmp( optarg, "50K")) return 0x06;
00376     if(!strcmp( optarg, "20K")) return 0x07;
00377     if(!strcmp( optarg, "10K")) return 0x08;
00378     return 0xFF;
00379 }
00380 
00381 /*!                                                                                                
00382 **                                                                                                 
00383 **                                                                                                 
00384 ** @param d                                                                                        
00385 ** @param cob_id                                                                                   
00386 **                                                                                                 
00387 ** @return                                                                                         
00388 **/  
00389 UNS8 sendMasterLSSMessage (CO_Data* d, UNS8 command,void *dat1,void *dat2)
00390 {
00391   Message m;
00392   UNS8 i;
00393   UNS8 res;
00394   UNS8 hasResponse=0;
00395    
00396   for(i=1;i<8;i++)m.data[i]=0;
00397   m.len = 8;
00398   m.rtr = NOT_A_REQUEST;
00399   m.data[0]=command;
00400   m.cob_id=UNS16_LE(MLSS_ADRESS);
00401   
00402   /* Tha data sent with the msg depends on the command */   
00403   switch(command){
00404   case LSS_CONF_NODE_ID: /* Configure Node-ID */
00405     hasResponse=1;
00406   case LSS_SM_GLOBAL: /* Switch Mode Global */
00407     m.data[1]=*(UNS8 *)dat1;
00408     break;
00409   case LSS_CONF_BIT_TIMING: /* Configure Bit Timing Parameters */
00410     
00411     m.data[1]=*(UNS8 *)dat1;
00412     d->lss_transfer.baudRate=*(char **)dat2;
00413     
00414     if((m.data[2]=CO_TranslateBaudRate(d->lss_transfer.baudRate))!=0xFF){
00415         hasResponse=1;
00416         break;   
00417     }
00418         
00419     MSG_ERR(0x1D19, "Master-> Baud rate not supported",0);
00420     d->lss_transfer.dat1=0xFF;
00421     
00422     /* if bit timing is not supported comment the previous code and uncomment the following one*/
00423     /*{
00424         MSG_ERR(0x1D1A, "Master-> Bit timing not supported",0);
00425         d->lss_transfer.dat1=0x01;
00426     }*/
00427     
00428     d->lss_transfer.dat2=0;
00429     /* If there is a callback, it is responsible of the error */
00430     if(d->lss_transfer.Callback)
00431         (*d->lss_transfer.Callback)(d,d->lss_transfer.command);
00432     return 0xFF;
00433     //break;
00434   case LSS_CONF_ACT_BIT_TIMING: /* Activate Bit Timing Parameters */
00435     m.data[1]=(UNS8)(*(UNS32*)dat1 & 0xFF);
00436     m.data[2]=(UNS8)(*(UNS32*)dat1>>8 & 0xFF);
00437     if(d->lss_transfer.baudRate!="none"){
00438         d->lss_transfer.switchDelay=(UNS16)(*(UNS32*)dat1 & 0xFFFF);
00439         d->lss_transfer.switchDelayState=SDELAY_FIRST;
00440         d->lss_transfer.canHandle_t=d->canHandle;
00441         res=canSend(d->canHandle,&m);
00442         if(res==0){
00443             StartLSS_SDELAY_TIMER();
00444             d->lss_transfer.state=LSS_TRANS_IN_PROGRESS;
00445         }
00446         return res; 
00447     }
00448     else{
00449         MSG_ERR(0x1D1B, "Master-> Baud rate not specified",0);
00450         d->lss_transfer.dat1=1;
00451         /* If there is a callback, it is responsible of the error */
00452         if(d->lss_transfer.Callback){
00453             (*d->lss_transfer.Callback)(d,d->lss_transfer.command);
00454         }
00455         return 0xFF;
00456     }
00457     //break;
00458   case LSS_SM_SELECTIVE_SERIAL:
00459   case LSS_IDENT_REMOTE_SERIAL_HIGH:
00460     hasResponse=1;
00461   case LSS_SM_SELECTIVE_VENDOR: /* Switch Mode Selective */
00462   case LSS_SM_SELECTIVE_PRODUCT:
00463   case LSS_SM_SELECTIVE_REVISION:
00464   case LSS_IDENT_REMOTE_VENDOR: /* LSS Identify Remote Slaves */
00465   case LSS_IDENT_REMOTE_PRODUCT:
00466   case LSS_IDENT_REMOTE_REV_LOW:
00467   case LSS_IDENT_REMOTE_REV_HIGH:
00468   case LSS_IDENT_REMOTE_SERIAL_LOW:
00469     m.data[1]=(UNS8)(*(UNS32*)dat1 & 0xFF);
00470     m.data[2]=(UNS8)(*(UNS32*)dat1>>8 & 0xFF);
00471     m.data[3]=(UNS8)(*(UNS32*)dat1>>16 & 0xFF);
00472     m.data[4]=(UNS8)(*(UNS32*)dat1>>24 & 0xFF);
00473     break;
00474     
00475   case LSS_CONF_STORE: /* Store Configured Parameters */
00476   case LSS_IDENT_REMOTE_NON_CONF: /* LSS identify non-configured remote slave */
00477   case LSS_INQ_VENDOR_ID: /* Inquire Identity Vendor-ID */
00478   case LSS_INQ_PRODUCT_CODE: /* Inquire Identity Product-Code */
00479   case LSS_INQ_REV_NUMBER: /* Inquire Identity Revision-Number */
00480   case LSS_INQ_SERIAL_NUMBER: /* Inquire Identity Serial-Number */
00481   case LSS_INQ_NODE_ID: /* Inquire Node-ID */
00482      hasResponse=1;
00483     break;
00484 #ifdef CO_ENABLE_LSS_FS
00485   case LSS_IDENT_FASTSCAN:
00486         if(d->lss_transfer.FastScan_SM==LSS_FS_RESET){
00487             UNS8 i;
00488              /* Initialize the lss_fs_transfer FastScan parameters */
00489             for(i=0;i<4;i++){
00490                 d->lss_transfer.lss_fs_transfer.FS_LSS_ID[i]=(*(lss_fs_transfer_t*)dat1).FS_LSS_ID[i];
00491                 d->lss_transfer.lss_fs_transfer.FS_BitChecked[i]=(*(lss_fs_transfer_t*)dat1).FS_BitChecked[i];
00492                 /* Adjust BitChecked from 32-1 to 31-0 */
00493                 if(d->lss_transfer.lss_fs_transfer.FS_BitChecked[i]>0)d->lss_transfer.lss_fs_transfer.FS_BitChecked[i]--;
00494             }
00495             
00496             d->lss_transfer.IDNumber=0;
00497             d->lss_transfer.BitChecked=128;
00498             d->lss_transfer.LSSSub=0;
00499             d->lss_transfer.LSSNext=0;
00500                     
00501             /* it will generate a response only if it is the start of the FastScan protocol*/
00502             hasResponse=1;
00503         }
00504         m.data[1]=(UNS8)(d->lss_transfer.IDNumber & 0xFF);
00505         m.data[2]=(UNS8)(d->lss_transfer.IDNumber>>8 & 0xFF);
00506         m.data[3]=(UNS8)(d->lss_transfer.IDNumber>>16 & 0xFF);
00507         m.data[4]=(UNS8)(d->lss_transfer.IDNumber>>24 & 0xFF);
00508         m.data[5]=d->lss_transfer.BitChecked;
00509         m.data[6]=d->lss_transfer.LSSSub;
00510         m.data[7]=d->lss_transfer.LSSNext;
00511     break;
00512 #endif
00513   default:
00514     MSG_ERR(0x1D1C, "send Master LSS command not implemented", command);
00515     return 0xFF;
00516   }
00517     
00518   res=canSend(d->canHandle,&m);
00519   if(res==0 && hasResponse==1){
00520     StartLSS_MSG_TIMER();
00521     d->lss_transfer.state=LSS_TRANS_IN_PROGRESS;
00522   }
00523   return res;
00524 }
00525 
00526 /*!                                                                                                
00527 **                                                                                                 
00528 **                                                                                                 
00529 ** @param d                                                                                        
00530 ** @param cob_id                                                                                   
00531 **                                                                                                 
00532 ** @return                                                                                         
00533 **/  
00534 UNS8 sendLSS(CO_Data* d, UNS8 command,void *dat1,void *dat2)
00535 {
00536   UNS8 res=1;
00537   
00538   /* Tha data sent with the msg depends on the command and if the sender is a master or a slave */
00539   if (*(d->iam_a_slave)){ 
00540     res = sendSlaveLSSMessage (d, command,dat1,dat2);
00541   }
00542   else {/* It is a Master */
00543     res = sendMasterLSSMessage (d, command,dat1,dat2);
00544   }
00545   return res ;
00546 }
00547 
00548 
00549 /*!                                                                                                
00550 **                                                                                                 
00551 **                                                                                                 
00552 ** @param d                                                                                        
00553 ** @param m                                                                                        
00554 **                                                                                                 
00555 ** @return                                                                                         
00556 **/ 
00557 UNS8 proceedLSS_Master(CO_Data* d, Message* m )
00558 { 
00559     UNS8 msg_cs;
00560     UNS32 Dat1=0;
00561     UNS8 Dat2=0;
00562     
00563     if(d->lss_transfer.state!=LSS_TRANS_IN_PROGRESS)
00564     {
00565         //MSG_WAR(0x3D0D, "MasterLSS proceedLSS; unexpected message arrived;command ", m->data[0]);
00566         //return 0;
00567         goto ErrorProcessMaster;
00568     }
00569     
00570     MSG_WAR(0x3D1E, "MasterLSS proceedLSS; command ", m->data[0]);
00571     
00572     switch(msg_cs=m->data[0]){
00573         case LSS_INQ_NODE_ID: /* Inquire Node-ID */
00574             if(d->lss_transfer.command!=LSS_INQ_NODE_ID)goto ErrorProcessMaster;
00575             Dat1=m->data[1];
00576             break;
00577         case LSS_CONF_NODE_ID: /* Configure Node-ID */
00578         case LSS_CONF_BIT_TIMING: /* Configure Bit Timing Parameters */
00579         case LSS_CONF_STORE: /* Store Configured Parameters */
00580             if(d->lss_transfer.command!=msg_cs)goto ErrorProcessMaster;
00581             Dat1=m->data[1];
00582             Dat2=m->data[2];
00583             break;
00584         case LSS_INQ_VENDOR_ID: /* Inquire Identity Vendor-ID */
00585         case LSS_INQ_PRODUCT_CODE: /* Inquire Identity Product-Code */
00586         case LSS_INQ_REV_NUMBER: /* Inquire Identity Revision-Number */
00587         case LSS_INQ_SERIAL_NUMBER: /* Inquire Identity Serial-Number */
00588             if(d->lss_transfer.command!=msg_cs)goto ErrorProcessMaster;
00589             Dat1=getLSSIdent(m);
00590             break;
00591         case LSS_IDENT_SLAVE: /* LSS Identify Slave */
00592 #ifdef CO_ENABLE_LSS_FS
00593             if(d->lss_transfer.command==LSS_IDENT_FASTSCAN){
00594                 /* A message arrived during the timer period */
00595                 d->lss_transfer.LSSanswer=1;
00596                 return 0;
00597             }
00598             else
00599 #endif
00600             if(d->lss_transfer.command!=LSS_IDENT_REMOTE_VENDOR && \
00601                 d->lss_transfer.command!=LSS_IDENT_REMOTE_PRODUCT && \
00602                 d->lss_transfer.command!=LSS_IDENT_REMOTE_REV_LOW && \
00603                 d->lss_transfer.command!=LSS_IDENT_REMOTE_REV_HIGH && \
00604                 d->lss_transfer.command!=LSS_IDENT_REMOTE_SERIAL_LOW && \
00605                 d->lss_transfer.command!=LSS_IDENT_REMOTE_SERIAL_HIGH )
00606                     goto ErrorProcessMaster;
00607         break;
00608         case LSS_SM_SELECTIVE_RESP: /* Switch Mode Selective response */
00609             if(d->lss_transfer.command!=LSS_SM_SELECTIVE_VENDOR && \
00610                 d->lss_transfer.command!=LSS_SM_SELECTIVE_PRODUCT && \
00611                 d->lss_transfer.command!=LSS_SM_SELECTIVE_REVISION && \
00612                 d->lss_transfer.command!=LSS_SM_SELECTIVE_SERIAL )
00613                     goto ErrorProcessMaster;
00614             break;
00615         case LSS_IDENT_NON_CONF_SLAVE: /* LSS identify non-configured remote slave */
00616             if(d->lss_transfer.command!=LSS_IDENT_REMOTE_NON_CONF)goto ErrorProcessMaster;
00617             break;
00618         default:
00619             MSG_ERR(0x1D1F, "Master LSS command not implemented", msg_cs);
00620             return 0xFF;
00621     }
00622     
00623     StopLSS_MSG_TIMER();
00624     d->lss_transfer.state = LSS_FINISHED;
00625         
00626     d->lss_transfer.dat1=Dat1;
00627     d->lss_transfer.dat2=Dat2;
00628     /* If there is a callback, it is responsible of the received response */
00629     if(d->lss_transfer.Callback)
00630         (*d->lss_transfer.Callback)(d,d->lss_transfer.command);
00631                 
00632    return 0;
00633    
00634 ErrorProcessMaster:
00635     MSG_WAR(0x3D20, "MasterLSS proceedLSS; unexpected message arrived;command ", m->data[0]);
00636     return 0xFF;
00637         
00638 }
00639 
00640 /*!                                                                                                
00641 **                                                                                                 
00642 **                                                                                                 
00643 ** @param d                                                                                        
00644 ** @param m                                                                                        
00645 **                                                                                                 
00646 ** @return                                                                                         
00647 **/ 
00648 UNS8 proceedLSS_Slave(CO_Data* d, Message* m )
00649 {  
00650     UNS8 msg_cs;
00651     
00652     MSG_WAR(0x3D21, "SlaveLSS proceedLSS; command ", m->data[0]);
00653     
00654     switch(msg_cs=m->data[0]){
00655     case LSS_SM_GLOBAL:     /* Switch Mode Global */
00656         /* if there is not a mode change break*/
00657         if(m->data[1] == d->lss_transfer.mode){
00658             MSG_WAR(0x3D22, "SlaveLSS already in the mode ", m->data[1]);
00659             break;
00660         }
00661         
00662         if(m->data[1]==LSS_CONFIGURATION_MODE)  {
00663             MSG_WAR(0x3D23, "SlaveLSS switching to configuration mode ", 0);
00664             /* Store the NodeId in case it will be changed */
00665             //d->lss_transfer.nodeID=getNodeId(d);
00666             d->lss_transfer.mode=LSS_CONFIGURATION_MODE;
00667         }
00668         else if(m->data[1]==LSS_WAITING_MODE){
00669             MSG_WAR(0x3D24, "SlaveLSS switching to operational mode ", 0);
00670             
00671             /* If the nodeID has changed update it and put the node state to Initialisation. */
00672             if(d->lss_transfer.nodeID!=getNodeId(d)){
00673                 if(getNodeId(d)==0xFF){/* The nodeID was 0xFF; initialize the application*/
00674                     MSG_WAR(0x3D25, "The node Id has changed. Reseting to Initialisation state",0);
00675                     setNodeId(d, d->lss_transfer.nodeID);
00676                     setState(d, Initialisation);
00677                 }
00678                 else{/* The nodeID will be changed on NMT_Reset_Comunication Request*/
00679                 }
00680             }
00681             d->lss_transfer.mode=LSS_WAITING_MODE;
00682         }
00683     break;
00684     case LSS_CONF_NODE_ID: /* Configure Node-ID */
00685     { 
00686         UNS8 error_code=0;
00687         UNS8 spec_error=0;
00688             
00689         if(d->lss_transfer.mode==LSS_CONFIGURATION_MODE){
00690             if(m->data[1]>127 && m->data[1]!=0xFF){
00691                 MSG_ERR(0x1D26, "NodeID out of range",0);
00692                 error_code=1; /* NodeID out of range */
00693             }
00694             else{
00695                 d->lss_transfer.nodeID=m->data[1];
00696             }
00697         }
00698         else{
00699             MSG_WAR(0x3D27, "SlaveLSS not in configuration mode",0);
00700             //error_code=0xFF;
00701             break;
00702         }
00703         sendSlaveLSSMessage (d,msg_cs,&error_code,&spec_error);
00704     }   
00705     break;
00706     case LSS_CONF_BIT_TIMING: /* Configure Bit Timing Parameters */
00707     {
00708         UNS8 error_code=0;
00709         UNS8 spec_error=0;
00710             
00711         if(d->lss_transfer.mode==LSS_CONFIGURATION_MODE){
00712             /* If a baud rate is not supported just comment the line. */
00713             switch(m->data[2]){
00714             case 0x00:d->lss_transfer.baudRate="1M";break;
00715             case 0x01:d->lss_transfer.baudRate="800K";break;
00716             case 0x02:d->lss_transfer.baudRate="500K";break;
00717             case 0x03:d->lss_transfer.baudRate="250K";break;
00718             case 0x04:d->lss_transfer.baudRate="125K";break;
00719             case 0x05:d->lss_transfer.baudRate="100K";break;
00720             case 0x06:d->lss_transfer.baudRate="50K";break;
00721             case 0x07:d->lss_transfer.baudRate="20K";break;
00722             case 0x08:d->lss_transfer.baudRate="10K";break;
00723             default:
00724                 MSG_ERR(0x1D28, "Baud rate not supported",0);
00725                 error_code=0xFF; /* Baud rate not supported*/
00726                 break;      
00727             }
00728         }
00729         else{
00730             MSG_WAR(0x3D2A, "SlaveLSS not in configuration mode",0);
00731             //error_code=0xFF;
00732             break;
00733         }
00734         
00735         /* if bit timing is not supported comment the previous code and uncomment the following */
00736         /*{
00737             MSG_ERR(0x1D29, "Bit timing not supported",0);
00738             error_code=0x01; // bit timing not supported 
00739         }*/
00740             
00741         sendSlaveLSSMessage (d,msg_cs,&error_code,&spec_error);
00742     }
00743     break;
00744     case LSS_CONF_ACT_BIT_TIMING: /* Activate Bit Timing Parameters */
00745         
00746         if(d->lss_transfer.mode!=LSS_CONFIGURATION_MODE){
00747             MSG_ERR(0x3D2B, "SlaveLSS not in configuration mode",0);
00748             break;
00749         }
00750         
00751         if(d->lss_transfer.baudRate!="none"){
00752             d->lss_transfer.switchDelay=getLSSDelay(m);
00753             MSG_WAR(0x3D2C, "Slave Switch Delay set to: ",d->lss_transfer.switchDelay);
00754             d->lss_transfer.switchDelayState=SDELAY_FIRST;
00755             //d->lss_transfer.currentState=getState(d);
00756             //setState(d, LssTimingDelay);
00757             d->lss_transfer.canHandle_t=d->canHandle;
00758             d->canHandle=NULL;
00759             StartLSS_SDELAY_TIMER();
00760         }
00761     break;
00762     case LSS_CONF_STORE: /* Store Configured Parameters */
00763     {
00764         UNS8 error_code=0;
00765         UNS8 spec_error=0;
00766         
00767         if(d->lss_transfer.mode==LSS_CONFIGURATION_MODE){ 
00768             if(d->lss_StoreConfiguration){
00769                  /* call lss_StoreConfiguration with NodeId */
00770                 (*d->lss_StoreConfiguration)(d,&error_code,&spec_error);
00771             }
00772             else{
00773                 MSG_ERR(0x1D2E, "Store configuration not supported",0);
00774                 error_code=1; /* store configuration is not supported */
00775             }   
00776         }
00777         else{
00778             MSG_WAR(0x3D2F, "SlaveLSS not in configuration mode",0);
00779             //error_code=0xFF;
00780             break;
00781         }
00782         sendSlaveLSSMessage (d,msg_cs,&error_code,&spec_error);
00783     }
00784     break;
00785     case LSS_SM_SELECTIVE_VENDOR:   /* Switch Mode Selective */
00786     case LSS_SM_SELECTIVE_PRODUCT:
00787     case LSS_SM_SELECTIVE_REVISION:
00788     case LSS_SM_SELECTIVE_SERIAL:
00789     {
00790         UNS32 errorCode;
00791         const indextable *ptrTable;
00792         ODCallback_t *Callback;
00793         UNS32 _SpecificNodeInfo;
00794   
00795         if(d->lss_transfer.mode==LSS_CONFIGURATION_MODE)
00796         {
00797             MSG_ERR(0x1D30, "Switch Mode Selective only supported in operational mode",0);
00798             break;
00799         }
00800             
00801         _SpecificNodeInfo=getLSSIdent(m);
00802                 
00803         ptrTable = (*d->scanIndexOD)(0x1018, &errorCode, &Callback);
00804         if(_SpecificNodeInfo==*(UNS32*)ptrTable->pSubindex[msg_cs-(LSS_SM_SELECTIVE_VENDOR-1)].pObject){
00805             
00806             d->lss_transfer.addr_sel_match|=(0x01<<(msg_cs-LSS_SM_SELECTIVE_VENDOR));
00807             /* If all the fields has been set */
00808             if(d->lss_transfer.addr_sel_match==0x0F){
00809                 
00810                 MSG_WAR(0x3D31, "SlaveLSS switching to configuration mode ", 0);
00811                 d->lss_transfer.addr_sel_match=0;
00812                 d->lss_transfer.nodeID=getNodeId(d);
00813                 d->lss_transfer.mode=LSS_CONFIGURATION_MODE;
00814 
00815                 sendSlaveLSSMessage (d,LSS_SM_SELECTIVE_RESP,0,0);
00816             }
00817         }   
00818         else {
00819             MSG_WAR(0x3D32, "LSS identity field doesn't match ", _SpecificNodeInfo);
00820             d->lss_transfer.addr_sel_match=0;
00821         }   
00822     }   
00823     break;
00824     case LSS_IDENT_REMOTE_VENDOR: /* LSS Identify Remote Slaves */
00825     case LSS_IDENT_REMOTE_PRODUCT:
00826     case LSS_IDENT_REMOTE_REV_LOW:
00827     case LSS_IDENT_REMOTE_REV_HIGH:
00828     case LSS_IDENT_REMOTE_SERIAL_LOW:
00829     case LSS_IDENT_REMOTE_SERIAL_HIGH:
00830     {
00831         UNS32 errorCode;
00832         const indextable *ptrTable;
00833         ODCallback_t *Callback;
00834         UNS32 _SpecificNodeInfo;
00835         
00836         _SpecificNodeInfo=getLSSIdent(m);
00837         
00838         ptrTable = (*d->scanIndexOD)(0x1018, &errorCode, &Callback);
00839             
00840         /* Check if the data match the identity object. */
00841         switch(msg_cs){
00842         case LSS_IDENT_REMOTE_VENDOR:d->lss_transfer.addr_ident_match=(_SpecificNodeInfo == *(UNS32*)ptrTable->pSubindex[1].pObject)? d->lss_transfer.addr_ident_match|0x01:0;  break;
00843         case LSS_IDENT_REMOTE_PRODUCT:d->lss_transfer.addr_ident_match=(_SpecificNodeInfo == *(UNS32*)ptrTable->pSubindex[2].pObject)? d->lss_transfer.addr_ident_match|0x02:0; break;
00844         case LSS_IDENT_REMOTE_REV_LOW:d->lss_transfer.addr_ident_match=(_SpecificNodeInfo <= *(UNS32*)ptrTable->pSubindex[3].pObject)? d->lss_transfer.addr_ident_match|0x04:0; break;
00845         case LSS_IDENT_REMOTE_REV_HIGH:d->lss_transfer.addr_ident_match=(_SpecificNodeInfo >= *(UNS32*)ptrTable->pSubindex[3].pObject)? d->lss_transfer.addr_ident_match|0x08:0;    break;
00846         case LSS_IDENT_REMOTE_SERIAL_LOW:d->lss_transfer.addr_ident_match=(_SpecificNodeInfo <= *(UNS32*)ptrTable->pSubindex[4].pObject)? d->lss_transfer.addr_ident_match|0x10:0;  break;
00847         case LSS_IDENT_REMOTE_SERIAL_HIGH:d->lss_transfer.addr_ident_match=(_SpecificNodeInfo >= *(UNS32*)ptrTable->pSubindex[4].pObject)? d->lss_transfer.addr_ident_match|0x20:0; break;
00848         }
00849         /* If all the fields has been set.. */
00850         if(d->lss_transfer.addr_ident_match==0x3F){
00851             MSG_WAR(0x3D33, "SlaveLSS identified ", 0);
00852             d->lss_transfer.addr_ident_match=0;
00853             sendSlaveLSSMessage (d,LSS_IDENT_SLAVE,0,0);
00854         }
00855         else if(d->lss_transfer.addr_ident_match==0){
00856             MSG_WAR(0x3D34, "LSS identify field doesn't match ", _SpecificNodeInfo);
00857         }
00858     }
00859     break;
00860     case LSS_IDENT_REMOTE_NON_CONF: /* LSS identify non-configured remote slave */
00861     {
00862         if(getNodeId(d)==0xFF){     
00863             MSG_WAR(0x3D35, "SlaveLSS non-configured ", 0);
00864             sendSlaveLSSMessage (d,LSS_IDENT_NON_CONF_SLAVE,0,0);
00865         }
00866         else{
00867             MSG_WAR(0x3D36, "SlaveLSS already configured ", 0);
00868         }
00869     }
00870     break;
00871     case LSS_INQ_VENDOR_ID: /* Inquire Identity Vendor-ID */
00872     case LSS_INQ_PRODUCT_CODE: /* Inquire Identity Product-Code */
00873     case LSS_INQ_REV_NUMBER: /* Inquire Identity Revision-Number */
00874     case LSS_INQ_SERIAL_NUMBER: /* Inquire Identity Serial-Number */
00875     if(d->lss_transfer.mode==LSS_CONFIGURATION_MODE)
00876     {
00877     
00878         UNS32 errorCode;
00879         const indextable *ptrTable;
00880         ODCallback_t *Callback;
00881         UNS32 _SpecificNodeInfo;
00882   
00883         ptrTable = (*d->scanIndexOD)(0x1018, &errorCode, &Callback);
00884         _SpecificNodeInfo=*(UNS32*)ptrTable->pSubindex[msg_cs-(LSS_INQ_VENDOR_ID-1)].pObject;
00885         MSG_WAR(0x3D37, "SlaveLSS identity field inquired ", _SpecificNodeInfo);
00886             
00887         sendSlaveLSSMessage (d,msg_cs,&_SpecificNodeInfo,0);
00888     }
00889     break;
00890     case LSS_INQ_NODE_ID: /* Inquire Node-ID */
00891         if(d->lss_transfer.mode==LSS_CONFIGURATION_MODE)
00892         {
00893             UNS8 NodeID;
00894     
00895             NodeID=getNodeId(d);
00896             MSG_WAR(0x3D38, "SlaveLSS Node ID inquired ", NodeID);
00897             sendSlaveLSSMessage (d,msg_cs,&NodeID,0);
00898         }
00899         else{
00900             MSG_WAR(0x3D39, "SlaveLSS not in configuration mode",0);
00901         }
00902     break;
00903 #ifdef CO_ENABLE_LSS_FS
00904     case LSS_IDENT_FASTSCAN:
00905     {
00906         /* If the nodeID isn't 0xFF the slave shall not participate  */
00907         if(getNodeId(d)!=0xFF)break;
00908         if(getLSSBitCheck(m)==128)d->lss_transfer.FastScan_SM=LSS_FS_RESET;
00909         
00910         switch(d->lss_transfer.FastScan_SM){
00911         case LSS_FS_RESET:
00912         {
00913             UNS32 errorCode;
00914             const indextable *ptrTable;
00915             ODCallback_t *Callback;
00916                 
00917             MSG_WAR(0x3D3A, "SlaveLSS Reseting LSSPos", 0);
00918             d->lss_transfer.LSSPos=0;
00919             d->lss_transfer.FastScan_SM=LSS_FS_PROCESSING;
00920             
00921             ptrTable = (*d->scanIndexOD)(0x1018, &errorCode, &Callback);
00922             d->lss_transfer.IDNumber=*(UNS32*)ptrTable->pSubindex[d->lss_transfer.LSSPos+1].pObject;
00923             
00924             sendSlaveLSSMessage (d,LSS_IDENT_SLAVE,0,0);
00925         }
00926         break;
00927         case LSS_FS_PROCESSING:/*if(getLSSBitCheck(m)<32)*/
00928             if(d->lss_transfer.LSSPos==getLSSSub(m))
00929             {
00930                 UNS32 Mask=0xFFFFFFFF<<getLSSBitCheck(m);
00931                 
00932                 MSG_WAR(0x3D3B, "SlaveLSS FastScan IDNumber", getLSSIdent(m));
00933                 MSG_WAR(0x3D3C, "SlaveLSS FastScan BitMask ", Mask);
00934                 MSG_WAR(0x3D3D, "SlaveLSS FastScan LSS-ID  ", d->lss_transfer.IDNumber);
00935                 
00936                 if((getLSSIdent(m) & Mask)==(d->lss_transfer.IDNumber & Mask))
00937                 {
00938                     sendSlaveLSSMessage (d,LSS_IDENT_SLAVE,0,0);
00939                 }
00940                 
00941                 if(getLSSBitCheck(m)==0)
00942                 {
00943                     d->lss_transfer.FastScan_SM=LSS_FS_CONFIRMATION;
00944                 }
00945             }
00946             break;
00947         case LSS_FS_CONFIRMATION:
00948             if(d->lss_transfer.LSSPos==getLSSSub(m))
00949             {
00950                 if(getLSSIdent(m)==d->lss_transfer.IDNumber)
00951                 {
00952                     /* Current LSS-ID[sub] confirmed correctly */
00953                     MSG_WAR(0x3D3E, "SlaveLSS FastScan IDNumber and LSS-ID match=>", d->lss_transfer.IDNumber);
00954                     if(d->lss_transfer.LSSPos==3)
00955                     {
00956                         /* All LSS-ID[sub] identified correctly, switching to configuration mode */
00957                         MSG_WAR(0x3D3F, "SlaveLSS switching to configuration mode ", 0);
00958                         d->lss_transfer.nodeID=getNodeId(d);
00959                         d->lss_transfer.mode=LSS_CONFIGURATION_MODE;
00960                         d->lss_transfer.FastScan_SM=LSS_FS_RESET;
00961                         d->lss_transfer.LSSPos=0xFF;
00962                     }       
00963                     else
00964                     {
00965                         /* Switch to the next LSS-ID[sub] */
00966                         UNS32 errorCode;
00967                         const indextable *ptrTable;
00968                         ODCallback_t *Callback;
00969         
00970                         d->lss_transfer.LSSPos=getLSSNext(m);
00971                         ptrTable = (*d->scanIndexOD)(0x1018, &errorCode, &Callback);
00972                         d->lss_transfer.IDNumber=*(UNS32*)ptrTable->pSubindex[d->lss_transfer.LSSPos+1].pObject;
00973                         d->lss_transfer.FastScan_SM=LSS_FS_PROCESSING;                      
00974                     }
00975                     sendSlaveLSSMessage (d,LSS_IDENT_SLAVE,0,0);
00976                 }
00977             }
00978             break;
00979         }
00980     }   
00981     break;
00982 #endif
00983     default:
00984         MSG_ERR(0x1D40, "SlaveLSS command not implemented", msg_cs);
00985         return 0xFF;
00986     }
00987    
00988     return 0;
00989 }
00990 
00991 /*UNS8 configNetworkNode(CO_Data* d, UNS8 command, void *dat1, void* dat2)
00992 {
00993     return sendMasterLSSMessage(d,command,dat1,dat2);
00994 }*/
00995 
00996 UNS8 configNetworkNode (CO_Data* d, UNS8 command, void *dat1, void* dat2, LSSCallback_t Callback)
00997 {
00998     //d->lss_transfer.state=LSS_TRANS_IN_PROGRESS;
00999     d->lss_transfer.Callback=Callback;
01000     d->lss_transfer.command=command;
01001     
01002     StopLSS_MSG_TIMER();
01003     //StartLSS_MSG_TIMER();
01004     
01005     return sendMasterLSSMessage (d,command,dat1,dat2);
01006 }
01007 
01008 UNS8 getConfigResultNetworkNode (CO_Data* d, UNS8 command, UNS32* dat1, UNS8* dat2)
01009 { 
01010   *dat1=d->lss_transfer.dat1;
01011   *dat2=d->lss_transfer.dat2;
01012   return d->lss_transfer.state;
01013 }
01014 
01015 //void _lss_StoreConfiguration(UNS8 *error, UNS8 *spec_error){printf("_lss_StoreConfiguration\n");}
01016 
01017 #endif