CANfestival - an open source CANopen framework

Dependencies:   mbed

Committer:
sam_grove
Date:
Mon May 30 07:14:41 2011 +0000
Revision:
0:6219434a0cb5
Initial public release of slave node framework port

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sam_grove 0:6219434a0cb5 1 /*
sam_grove 0:6219434a0cb5 2 This file is part of CanFestival, a library implementing CanOpen Stack.
sam_grove 0:6219434a0cb5 3
sam_grove 0:6219434a0cb5 4
sam_grove 0:6219434a0cb5 5 Copyright (C): Jorge Berzosa
sam_grove 0:6219434a0cb5 6
sam_grove 0:6219434a0cb5 7
sam_grove 0:6219434a0cb5 8 See COPYING file for copyrights details.
sam_grove 0:6219434a0cb5 9
sam_grove 0:6219434a0cb5 10
sam_grove 0:6219434a0cb5 11 This library is free software; you can redistribute it and/or
sam_grove 0:6219434a0cb5 12 modify it under the terms of the GNU Lesser General Public
sam_grove 0:6219434a0cb5 13 License as published by the Free Software Foundation; either
sam_grove 0:6219434a0cb5 14 version 2.1 of the License, or (at your option) any later version.
sam_grove 0:6219434a0cb5 15
sam_grove 0:6219434a0cb5 16
sam_grove 0:6219434a0cb5 17 This library is distributed in the hope that it will be useful,
sam_grove 0:6219434a0cb5 18 but WITHOUT ANY WARRANTY; without even the implied warranty of
sam_grove 0:6219434a0cb5 19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
sam_grove 0:6219434a0cb5 20 Lesser General Public License for more details.
sam_grove 0:6219434a0cb5 21
sam_grove 0:6219434a0cb5 22
sam_grove 0:6219434a0cb5 23 You should have received a copy of the GNU Lesser General Public
sam_grove 0:6219434a0cb5 24 License along with this library; if not, write to the Free Software
sam_grove 0:6219434a0cb5 25 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
sam_grove 0:6219434a0cb5 26 */
sam_grove 0:6219434a0cb5 27
sam_grove 0:6219434a0cb5 28
sam_grove 0:6219434a0cb5 29 /*!
sam_grove 0:6219434a0cb5 30 ** @file lss.c
sam_grove 0:6219434a0cb5 31 ** @author Jorge Berzosa
sam_grove 0:6219434a0cb5 32 ** @date Mon Oct 22 05:44:32 2007
sam_grove 0:6219434a0cb5 33 **
sam_grove 0:6219434a0cb5 34 ** @brief
sam_grove 0:6219434a0cb5 35 **
sam_grove 0:6219434a0cb5 36 **
sam_grove 0:6219434a0cb5 37 */
sam_grove 0:6219434a0cb5 38
sam_grove 0:6219434a0cb5 39
sam_grove 0:6219434a0cb5 40 #include "data.h"
sam_grove 0:6219434a0cb5 41 #include "lss.h"
sam_grove 0:6219434a0cb5 42 #include "canfestival.h"
sam_grove 0:6219434a0cb5 43 #include "sysdep.h"
sam_grove 0:6219434a0cb5 44
sam_grove 0:6219434a0cb5 45 #ifdef CO_ENABLE_LSS
sam_grove 0:6219434a0cb5 46
sam_grove 0:6219434a0cb5 47 //#define LSS_TIMEOUT_MS (TIMEVAL)1000 /* ms */
sam_grove 0:6219434a0cb5 48 //#define LSS_FS_TIMEOUT_MS (TIMEVAL)100 /* ms */
sam_grove 0:6219434a0cb5 49
sam_grove 0:6219434a0cb5 50 /* Returns the LSS ident field from a Message struct */
sam_grove 0:6219434a0cb5 51 #define getLSSIdent(msg) (((UNS32)msg->data[4] << 24) | ((UNS32)msg->data[3] << 16) | (msg->data[2] << 8) | (msg->data[1]))
sam_grove 0:6219434a0cb5 52
sam_grove 0:6219434a0cb5 53
sam_grove 0:6219434a0cb5 54 /* Returns the LSS switch delay field from a Message struct */
sam_grove 0:6219434a0cb5 55 #define getLSSDelay(msg) ((msg->data[2] << 8) | (msg->data[1]))
sam_grove 0:6219434a0cb5 56
sam_grove 0:6219434a0cb5 57 /* Returns the LSS FastScan BitCheck field from a Message struct */
sam_grove 0:6219434a0cb5 58 #define getLSSBitCheck(msg) msg->data[5]
sam_grove 0:6219434a0cb5 59
sam_grove 0:6219434a0cb5 60 /* Returns the LSS FastScan LSSSub field from a Message struct */
sam_grove 0:6219434a0cb5 61 #define getLSSSub(msg) msg->data[6]
sam_grove 0:6219434a0cb5 62
sam_grove 0:6219434a0cb5 63 /* Returns the LSS FastScan LSSNext field from a Message struct */
sam_grove 0:6219434a0cb5 64 #define getLSSNext(msg) msg->data[7]
sam_grove 0:6219434a0cb5 65
sam_grove 0:6219434a0cb5 66 /* Prototypes for internals functions */
sam_grove 0:6219434a0cb5 67 UNS8 sendMasterLSSMessage(CO_Data* d, UNS8 command,void *dat1,void *dat2);
sam_grove 0:6219434a0cb5 68 void LssAlarmMSG(CO_Data* d, UNS32 id);
sam_grove 0:6219434a0cb5 69 void LssAlarmSDELAY(CO_Data* d, UNS32 id);
sam_grove 0:6219434a0cb5 70
sam_grove 0:6219434a0cb5 71
sam_grove 0:6219434a0cb5 72 #define StopLSS_MSG_TIMER(){\
sam_grove 0:6219434a0cb5 73 MSG_WAR(0x3D01, "StopLSS_MSG_TIMER", 0);\
sam_grove 0:6219434a0cb5 74 d->lss_transfer.timerMSG = DelAlarm(d->lss_transfer.timerMSG);}
sam_grove 0:6219434a0cb5 75
sam_grove 0:6219434a0cb5 76 #define StartLSS_MSG_TIMER(){\
sam_grove 0:6219434a0cb5 77 MSG_WAR(0x3D02, "StartLSS_MSG_TIMER",0);\
sam_grove 0:6219434a0cb5 78 d->lss_transfer.timerMSG = SetAlarm(d,0,&LssAlarmMSG,MS_TO_TIMEVAL(LSS_TIMEOUT_MS),0);}
sam_grove 0:6219434a0cb5 79
sam_grove 0:6219434a0cb5 80 #define StopLSS_SDELAY_TIMER(){\
sam_grove 0:6219434a0cb5 81 MSG_WAR(0x3D03, "StopLSS_SDELAY_TIMER", 0);\
sam_grove 0:6219434a0cb5 82 d->lss_transfer.timerSDELAY = DelAlarm(d->lss_transfer.timerSDELAY);}
sam_grove 0:6219434a0cb5 83
sam_grove 0:6219434a0cb5 84 #define StartLSS_SDELAY_TIMER(){\
sam_grove 0:6219434a0cb5 85 MSG_WAR(0x3D04, "StartLSS_SDELAY_TIMER",0);\
sam_grove 0:6219434a0cb5 86 d->lss_transfer.timerSDELAY= SetAlarm(d,0,&LssAlarmSDELAY,MS_TO_TIMEVAL(d->lss_transfer.switchDelay),MS_TO_TIMEVAL(d->lss_transfer.switchDelay));}
sam_grove 0:6219434a0cb5 87
sam_grove 0:6219434a0cb5 88
sam_grove 0:6219434a0cb5 89 #ifdef CO_ENABLE_LSS_FS
sam_grove 0:6219434a0cb5 90 /* Prototypes for internals functions */
sam_grove 0:6219434a0cb5 91 void LssAlarmFS(CO_Data* d, UNS32 id);
sam_grove 0:6219434a0cb5 92
sam_grove 0:6219434a0cb5 93 #define StopLSS_FS_TIMER(){\
sam_grove 0:6219434a0cb5 94 MSG_WAR(0x3D05, "StopLSS_FS_TIMER", id);\
sam_grove 0:6219434a0cb5 95 d->lss_transfer.timerFS = DelAlarm(d->lss_transfer.timerFS);}
sam_grove 0:6219434a0cb5 96
sam_grove 0:6219434a0cb5 97 #define StartLSS_FS_TIMER(){\
sam_grove 0:6219434a0cb5 98 MSG_WAR(0x3D06, "StartLSS_FS_TIMER",0);\
sam_grove 0:6219434a0cb5 99 d->lss_transfer.timerFS = SetAlarm(d,0,&LssAlarmFS,MS_TO_TIMEVAL(LSS_FS_TIMEOUT_MS),0);}
sam_grove 0:6219434a0cb5 100 #endif
sam_grove 0:6219434a0cb5 101
sam_grove 0:6219434a0cb5 102
sam_grove 0:6219434a0cb5 103 void LssAlarmMSG(CO_Data* d, UNS32 id)
sam_grove 0:6219434a0cb5 104 {
sam_grove 0:6219434a0cb5 105 StopLSS_MSG_TIMER();
sam_grove 0:6219434a0cb5 106 #ifdef CO_ENABLE_LSS_FS
sam_grove 0:6219434a0cb5 107 if(d->lss_transfer.command==LSS_IDENT_FASTSCAN){
sam_grove 0:6219434a0cb5 108 if(d->lss_transfer.FastScan_SM==LSS_FS_RESET){
sam_grove 0:6219434a0cb5 109 /* if at least one node had answered before the timer expired, start the FastScan protocol*/
sam_grove 0:6219434a0cb5 110 if(d->lss_transfer.LSSanswer!=0){
sam_grove 0:6219434a0cb5 111 UNS32 Mask=0xFFFFFFFF;
sam_grove 0:6219434a0cb5 112 d->lss_transfer.LSSanswer=0;
sam_grove 0:6219434a0cb5 113 d->lss_transfer.BitChecked=d->lss_transfer.lss_fs_transfer.FS_BitChecked[0];
sam_grove 0:6219434a0cb5 114 Mask=(UNS32)((UNS64)Mask<<(d->lss_transfer.BitChecked+1));
sam_grove 0:6219434a0cb5 115 d->lss_transfer.IDNumber=d->lss_transfer.lss_fs_transfer.FS_LSS_ID[0] & Mask;
sam_grove 0:6219434a0cb5 116 d->lss_transfer.FastScan_SM=LSS_FS_PROCESSING;
sam_grove 0:6219434a0cb5 117 //printf("BitChecked=%d, IDNumber=%x MASK=%x\n",d->lss_transfer.BitChecked,d->lss_transfer.IDNumber,Mask);
sam_grove 0:6219434a0cb5 118 StartLSS_FS_TIMER();
sam_grove 0:6219434a0cb5 119 sendMasterLSSMessage(d,LSS_IDENT_FASTSCAN,0,0);
sam_grove 0:6219434a0cb5 120 return;
sam_grove 0:6219434a0cb5 121 }
sam_grove 0:6219434a0cb5 122 else{
sam_grove 0:6219434a0cb5 123
sam_grove 0:6219434a0cb5 124 d->lss_transfer.state = LSS_FINISHED;
sam_grove 0:6219434a0cb5 125 /* Inform the application that there aren't not configured nodes in the net */
sam_grove 0:6219434a0cb5 126 d->lss_transfer.dat1=1;
sam_grove 0:6219434a0cb5 127 }
sam_grove 0:6219434a0cb5 128 }
sam_grove 0:6219434a0cb5 129 else{
sam_grove 0:6219434a0cb5 130 /* This should not happen, an error ocurred*/
sam_grove 0:6219434a0cb5 131 MSG_ERR(0x1D07, "LSS FastScan timeout. FastScan_SM inconsisten state.", d->lss_transfer.FastScan_SM);
sam_grove 0:6219434a0cb5 132 d->lss_transfer.state = LSS_ABORTED_INTERNAL;
sam_grove 0:6219434a0cb5 133 d->lss_transfer.FastScan_SM=LSS_FS_RESET;
sam_grove 0:6219434a0cb5 134 }
sam_grove 0:6219434a0cb5 135 }
sam_grove 0:6219434a0cb5 136 else
sam_grove 0:6219434a0cb5 137 #endif
sam_grove 0:6219434a0cb5 138 if(d->lss_transfer.command==LSS_IDENT_REMOTE_NON_CONF){
sam_grove 0:6219434a0cb5 139 MSG_WAR(0x2D08, "LSS timeout. There are not no-configured slaves in the net", 0);
sam_grove 0:6219434a0cb5 140 d->lss_transfer.state = LSS_FINISHED;
sam_grove 0:6219434a0cb5 141 d->lss_transfer.dat1=1;
sam_grove 0:6219434a0cb5 142 }
sam_grove 0:6219434a0cb5 143 else{
sam_grove 0:6219434a0cb5 144 MSG_ERR(0x1D09, "LSS timeout. LSS response not received.", 0);
sam_grove 0:6219434a0cb5 145 MSG_WAR(0x2D0A, "LSS timeout command specifier : ", d->lss_transfer.command);
sam_grove 0:6219434a0cb5 146 /* Set aborted state */
sam_grove 0:6219434a0cb5 147 d->lss_transfer.state = LSS_ABORTED_INTERNAL;
sam_grove 0:6219434a0cb5 148 #ifdef CO_ENABLE_LSS_FS
sam_grove 0:6219434a0cb5 149 d->lss_transfer.FastScan_SM = LSS_FS_RESET;
sam_grove 0:6219434a0cb5 150 #endif
sam_grove 0:6219434a0cb5 151 }
sam_grove 0:6219434a0cb5 152
sam_grove 0:6219434a0cb5 153 /* Call the user function to inform of the problem.*/
sam_grove 0:6219434a0cb5 154 if(d->lss_transfer.Callback){
sam_grove 0:6219434a0cb5 155 /*If there is a callback, it is responsible of the error*/
sam_grove 0:6219434a0cb5 156 (*d->lss_transfer.Callback)(d,d->lss_transfer.command);
sam_grove 0:6219434a0cb5 157 }
sam_grove 0:6219434a0cb5 158 }
sam_grove 0:6219434a0cb5 159
sam_grove 0:6219434a0cb5 160
sam_grove 0:6219434a0cb5 161 /*!
sam_grove 0:6219434a0cb5 162 **
sam_grove 0:6219434a0cb5 163 **
sam_grove 0:6219434a0cb5 164 ** @param d
sam_grove 0:6219434a0cb5 165 ** @param id
sam_grove 0:6219434a0cb5 166 **/
sam_grove 0:6219434a0cb5 167 void LssAlarmSDELAY(CO_Data* d, UNS32 id)
sam_grove 0:6219434a0cb5 168 {
sam_grove 0:6219434a0cb5 169
sam_grove 0:6219434a0cb5 170 /* The first switch_delay period expired. Store the node state, change it
sam_grove 0:6219434a0cb5 171 * so no CAN messages will be sent or received, call the ChangeBaudRate function*/
sam_grove 0:6219434a0cb5 172 if(d->lss_transfer.switchDelayState==SDELAY_FIRST){
sam_grove 0:6219434a0cb5 173 MSG_WAR(0x3D0B, "LSS switch delay first period expired",0);
sam_grove 0:6219434a0cb5 174 d->lss_transfer.switchDelayState=SDELAY_SECOND;
sam_grove 0:6219434a0cb5 175 //(*d->lss_ChangeBaudRate)(d,d->lss_transfer.baudRate);
sam_grove 0:6219434a0cb5 176 canChangeBaudRate(d->lss_transfer.canHandle_t, d->lss_transfer.baudRate);
sam_grove 0:6219434a0cb5 177 }
sam_grove 0:6219434a0cb5 178 else{ /* d->lss_transfer.switchDelayState==SDELAY_SECOND */
sam_grove 0:6219434a0cb5 179 MSG_WAR(0x3D0C, "LSS switch delay second period expired",0);
sam_grove 0:6219434a0cb5 180 d->lss_transfer.switchDelayState=SDELAY_OFF;
sam_grove 0:6219434a0cb5 181 StopLSS_SDELAY_TIMER();
sam_grove 0:6219434a0cb5 182
sam_grove 0:6219434a0cb5 183 if (*(d->iam_a_slave))
sam_grove 0:6219434a0cb5 184 d->canHandle=d->lss_transfer.canHandle_t;
sam_grove 0:6219434a0cb5 185 else{
sam_grove 0:6219434a0cb5 186 d->lss_transfer.dat1=0;
sam_grove 0:6219434a0cb5 187 d->lss_transfer.state=LSS_FINISHED;
sam_grove 0:6219434a0cb5 188 /* Call the user function */
sam_grove 0:6219434a0cb5 189 if(d->lss_transfer.Callback){
sam_grove 0:6219434a0cb5 190 (*d->lss_transfer.Callback)(d,d->lss_transfer.command);
sam_grove 0:6219434a0cb5 191 }
sam_grove 0:6219434a0cb5 192 }
sam_grove 0:6219434a0cb5 193 }
sam_grove 0:6219434a0cb5 194 }
sam_grove 0:6219434a0cb5 195
sam_grove 0:6219434a0cb5 196 #ifdef CO_ENABLE_LSS_FS
sam_grove 0:6219434a0cb5 197 /*!
sam_grove 0:6219434a0cb5 198 **
sam_grove 0:6219434a0cb5 199 **
sam_grove 0:6219434a0cb5 200 ** @param d
sam_grove 0:6219434a0cb5 201 ** @param id
sam_grove 0:6219434a0cb5 202 **/
sam_grove 0:6219434a0cb5 203 void LssAlarmFS(CO_Data* d, UNS32 id)
sam_grove 0:6219434a0cb5 204 {
sam_grove 0:6219434a0cb5 205 StopLSS_FS_TIMER();
sam_grove 0:6219434a0cb5 206
sam_grove 0:6219434a0cb5 207 switch(d->lss_transfer.FastScan_SM){
sam_grove 0:6219434a0cb5 208 case LSS_FS_RESET:
sam_grove 0:6219434a0cb5 209 {
sam_grove 0:6219434a0cb5 210 /* This should not happen, an error ocurred*/
sam_grove 0:6219434a0cb5 211 MSG_ERR(0x1D0D, "LSS FastScan timeout. FastScan_SM inconsisten state.", d->lss_transfer.FastScan_SM);
sam_grove 0:6219434a0cb5 212 }
sam_grove 0:6219434a0cb5 213 break;
sam_grove 0:6219434a0cb5 214 case LSS_FS_PROCESSING:
sam_grove 0:6219434a0cb5 215 {
sam_grove 0:6219434a0cb5 216 /* If there isn't any answer, set the bit */
sam_grove 0:6219434a0cb5 217 if(d->lss_transfer.LSSanswer==0){
sam_grove 0:6219434a0cb5 218 UNS32 Mask=0x1;
sam_grove 0:6219434a0cb5 219 Mask<<=d->lss_transfer.BitChecked;
sam_grove 0:6219434a0cb5 220 d->lss_transfer.IDNumber|=Mask;
sam_grove 0:6219434a0cb5 221 }
sam_grove 0:6219434a0cb5 222
sam_grove 0:6219434a0cb5 223 if(d->lss_transfer.BitChecked==0){
sam_grove 0:6219434a0cb5 224 /* We finished with the current LSS-ID[sub], confirm it */
sam_grove 0:6219434a0cb5 225 d->lss_transfer.FastScan_SM=LSS_FS_CONFIRMATION;
sam_grove 0:6219434a0cb5 226 if(d->lss_transfer.LSSNext<3)d->lss_transfer.LSSNext++;
sam_grove 0:6219434a0cb5 227 }
sam_grove 0:6219434a0cb5 228 else{
sam_grove 0:6219434a0cb5 229 d->lss_transfer.BitChecked--;
sam_grove 0:6219434a0cb5 230 }
sam_grove 0:6219434a0cb5 231 //printf("BitChecked=%d, IDNumber=%x\n",d->lss_transfer.BitChecked,d->lss_transfer.IDNumber);
sam_grove 0:6219434a0cb5 232 d->lss_transfer.LSSanswer=0;
sam_grove 0:6219434a0cb5 233 StartLSS_FS_TIMER();
sam_grove 0:6219434a0cb5 234 sendMasterLSSMessage(d,LSS_IDENT_FASTSCAN,0,0);
sam_grove 0:6219434a0cb5 235 return;
sam_grove 0:6219434a0cb5 236 }
sam_grove 0:6219434a0cb5 237 break;
sam_grove 0:6219434a0cb5 238 case LSS_FS_CONFIRMATION:
sam_grove 0:6219434a0cb5 239 {
sam_grove 0:6219434a0cb5 240 if(d->lss_transfer.LSSanswer!=0){
sam_grove 0:6219434a0cb5 241 d->lss_transfer.LSSanswer=0;
sam_grove 0:6219434a0cb5 242
sam_grove 0:6219434a0cb5 243 if(d->lss_transfer.LSSSub==3){
sam_grove 0:6219434a0cb5 244 /* The LSS FastScan protocol finished correctly. Restore the parameters */
sam_grove 0:6219434a0cb5 245 d->lss_transfer.BitChecked=128;
sam_grove 0:6219434a0cb5 246 d->lss_transfer.FastScan_SM=LSS_FS_RESET;
sam_grove 0:6219434a0cb5 247 d->lss_transfer.LSSSub=0;
sam_grove 0:6219434a0cb5 248 d->lss_transfer.LSSNext=0;
sam_grove 0:6219434a0cb5 249 d->lss_transfer.IDNumber=0;
sam_grove 0:6219434a0cb5 250
sam_grove 0:6219434a0cb5 251 /* Inform the application that the FastScan finished correctly */
sam_grove 0:6219434a0cb5 252 d->lss_transfer.state = LSS_FINISHED;
sam_grove 0:6219434a0cb5 253 d->lss_transfer.dat1=0;
sam_grove 0:6219434a0cb5 254 }
sam_grove 0:6219434a0cb5 255 else{
sam_grove 0:6219434a0cb5 256 UNS32 Mask=0xFFFFFFFF;
sam_grove 0:6219434a0cb5 257 /* Start with the next LSS-ID[sub] */
sam_grove 0:6219434a0cb5 258 d->lss_transfer.LSSSub++;
sam_grove 0:6219434a0cb5 259 d->lss_transfer.BitChecked=d->lss_transfer.lss_fs_transfer.FS_BitChecked[d->lss_transfer.LSSSub];
sam_grove 0:6219434a0cb5 260 Mask=(UNS32)((UNS64)Mask<<(d->lss_transfer.BitChecked+1));
sam_grove 0:6219434a0cb5 261 d->lss_transfer.IDNumber=d->lss_transfer.lss_fs_transfer.FS_LSS_ID[d->lss_transfer.LSSSub] & Mask;
sam_grove 0:6219434a0cb5 262 d->lss_transfer.FastScan_SM=LSS_FS_PROCESSING;
sam_grove 0:6219434a0cb5 263 //printf("BitChecked=%d, IDNumber=%x MASK=%x\n",d->lss_transfer.BitChecked,d->lss_transfer.IDNumber,Mask);
sam_grove 0:6219434a0cb5 264 StartLSS_FS_TIMER();
sam_grove 0:6219434a0cb5 265 sendMasterLSSMessage(d,LSS_IDENT_FASTSCAN,0,0);
sam_grove 0:6219434a0cb5 266 return;
sam_grove 0:6219434a0cb5 267 }
sam_grove 0:6219434a0cb5 268 }
sam_grove 0:6219434a0cb5 269 else{
sam_grove 0:6219434a0cb5 270 /* This should not happen, an error ocurred*/
sam_grove 0:6219434a0cb5 271 MSG_ERR(0x1D0E, "LSS FastScan timeout. FastScan response not received.", 0);
sam_grove 0:6219434a0cb5 272 MSG_ERR(0x1D0E, "There is not any node with LSS_ID# =>", d->lss_transfer.LSSSub);
sam_grove 0:6219434a0cb5 273 MSG_ERR(0x1D0E, "with the value =>", d->lss_transfer.IDNumber);
sam_grove 0:6219434a0cb5 274 /* Set aborted state */
sam_grove 0:6219434a0cb5 275 d->lss_transfer.state = LSS_ABORTED_INTERNAL;
sam_grove 0:6219434a0cb5 276 d->lss_transfer.FastScan_SM = LSS_FS_RESET;
sam_grove 0:6219434a0cb5 277 }
sam_grove 0:6219434a0cb5 278 }
sam_grove 0:6219434a0cb5 279 break;
sam_grove 0:6219434a0cb5 280 }
sam_grove 0:6219434a0cb5 281
sam_grove 0:6219434a0cb5 282 /* Call the user function to inform of the problem.*/
sam_grove 0:6219434a0cb5 283 if(d->lss_transfer.Callback){
sam_grove 0:6219434a0cb5 284 /*If there is a callback, it is responsible of the error*/
sam_grove 0:6219434a0cb5 285 (*d->lss_transfer.Callback)(d,d->lss_transfer.command);
sam_grove 0:6219434a0cb5 286 }
sam_grove 0:6219434a0cb5 287 }
sam_grove 0:6219434a0cb5 288 #endif
sam_grove 0:6219434a0cb5 289
sam_grove 0:6219434a0cb5 290
sam_grove 0:6219434a0cb5 291 /*!
sam_grove 0:6219434a0cb5 292 **
sam_grove 0:6219434a0cb5 293 **
sam_grove 0:6219434a0cb5 294 ** @param d
sam_grove 0:6219434a0cb5 295 **/
sam_grove 0:6219434a0cb5 296 void startLSS(CO_Data* d)
sam_grove 0:6219434a0cb5 297 {
sam_grove 0:6219434a0cb5 298 /*MSG_WAR(0x3D09, "LSS services started",0);*/
sam_grove 0:6219434a0cb5 299 }
sam_grove 0:6219434a0cb5 300
sam_grove 0:6219434a0cb5 301 /*!
sam_grove 0:6219434a0cb5 302 **
sam_grove 0:6219434a0cb5 303 **
sam_grove 0:6219434a0cb5 304 ** @param d
sam_grove 0:6219434a0cb5 305 **/
sam_grove 0:6219434a0cb5 306 void stopLSS(CO_Data* d)
sam_grove 0:6219434a0cb5 307 {
sam_grove 0:6219434a0cb5 308 /*MSG_WAR(0x3D09, "LSS services stopped",0);*/
sam_grove 0:6219434a0cb5 309 }
sam_grove 0:6219434a0cb5 310
sam_grove 0:6219434a0cb5 311 /*!
sam_grove 0:6219434a0cb5 312 **
sam_grove 0:6219434a0cb5 313 **
sam_grove 0:6219434a0cb5 314 ** @param d
sam_grove 0:6219434a0cb5 315 ** @param cob_id
sam_grove 0:6219434a0cb5 316 **
sam_grove 0:6219434a0cb5 317 ** @return
sam_grove 0:6219434a0cb5 318 **/
sam_grove 0:6219434a0cb5 319 UNS8 sendSlaveLSSMessage(CO_Data* d, UNS8 command,void *dat1,void *dat2)
sam_grove 0:6219434a0cb5 320 {
sam_grove 0:6219434a0cb5 321 Message m;
sam_grove 0:6219434a0cb5 322 UNS8 i;
sam_grove 0:6219434a0cb5 323
sam_grove 0:6219434a0cb5 324 if (!d->CurrentCommunicationState.csLSS){
sam_grove 0:6219434a0cb5 325 MSG_WAR(0x2D17, "unable to send the LSS message, not in the proper state =>", d->nodeState);
sam_grove 0:6219434a0cb5 326 return 0xFF;
sam_grove 0:6219434a0cb5 327 }
sam_grove 0:6219434a0cb5 328
sam_grove 0:6219434a0cb5 329 for(i=1;i<8;i++)m.data[i]=0;
sam_grove 0:6219434a0cb5 330 m.len = 8;
sam_grove 0:6219434a0cb5 331 m.rtr = NOT_A_REQUEST;
sam_grove 0:6219434a0cb5 332 m.data[0]=command;
sam_grove 0:6219434a0cb5 333 m.cob_id=UNS16_LE(SLSS_ADRESS);
sam_grove 0:6219434a0cb5 334
sam_grove 0:6219434a0cb5 335 /* Tha data sent with the msg depends on the command */
sam_grove 0:6219434a0cb5 336 switch(command){
sam_grove 0:6219434a0cb5 337 case LSS_INQ_NODE_ID: /* Inquire Node-ID */
sam_grove 0:6219434a0cb5 338 m.data[1]=*(UNS8 *)dat1;
sam_grove 0:6219434a0cb5 339 break;
sam_grove 0:6219434a0cb5 340 case LSS_CONF_NODE_ID: /* Configure Node-ID */
sam_grove 0:6219434a0cb5 341 case LSS_CONF_BIT_TIMING: /* Configure Bit Timing Parameters */
sam_grove 0:6219434a0cb5 342 case LSS_CONF_STORE: /* Store Configured Parameters */
sam_grove 0:6219434a0cb5 343 m.data[1]=*(UNS8 *)dat1;
sam_grove 0:6219434a0cb5 344 m.data[2]=*(UNS8 *)dat2;
sam_grove 0:6219434a0cb5 345 break;
sam_grove 0:6219434a0cb5 346 case LSS_INQ_VENDOR_ID: /* Inquire Identity Vendor-ID */
sam_grove 0:6219434a0cb5 347 case LSS_INQ_PRODUCT_CODE: /* Inquire Identity Product-Code */
sam_grove 0:6219434a0cb5 348 case LSS_INQ_REV_NUMBER: /* Inquire Identity Revision-Number */
sam_grove 0:6219434a0cb5 349 case LSS_INQ_SERIAL_NUMBER: /* Inquire Identity Serial-Number */
sam_grove 0:6219434a0cb5 350 m.data[1]=(UNS8)(*(UNS32*)dat1 & 0xFF);
sam_grove 0:6219434a0cb5 351 m.data[2]=(UNS8)(*(UNS32*)dat1>>8 & 0xFF);
sam_grove 0:6219434a0cb5 352 m.data[3]=(UNS8)(*(UNS32*)dat1>>16 & 0xFF);
sam_grove 0:6219434a0cb5 353 m.data[4]=(UNS8)(*(UNS32*)dat1>>24 & 0xFF);
sam_grove 0:6219434a0cb5 354 break;
sam_grove 0:6219434a0cb5 355 case LSS_SM_SELECTIVE_RESP: /* Switch Mode Selective response*/
sam_grove 0:6219434a0cb5 356 case LSS_IDENT_SLAVE: /* LSS Identify Slave */
sam_grove 0:6219434a0cb5 357 case LSS_IDENT_NON_CONF_SLAVE: /* LSS identify non-configured remote slave */
sam_grove 0:6219434a0cb5 358 break;
sam_grove 0:6219434a0cb5 359 default:
sam_grove 0:6219434a0cb5 360 MSG_ERR(0x1D18, "send Slave LSS command not implemented", command);
sam_grove 0:6219434a0cb5 361 return 0xFF;
sam_grove 0:6219434a0cb5 362 }
sam_grove 0:6219434a0cb5 363
sam_grove 0:6219434a0cb5 364 return canSend(d->canHandle,&m);
sam_grove 0:6219434a0cb5 365 }
sam_grove 0:6219434a0cb5 366
sam_grove 0:6219434a0cb5 367 /* If a baud rate is not supported just comment the line. */
sam_grove 0:6219434a0cb5 368 static UNS8 CO_TranslateBaudRate(char* optarg){
sam_grove 0:6219434a0cb5 369 if(!strcmp( optarg, "1M")) return 0x00;
sam_grove 0:6219434a0cb5 370 if(!strcmp( optarg, "800K")) return 0x01;
sam_grove 0:6219434a0cb5 371 if(!strcmp( optarg, "500K")) return 0x02;
sam_grove 0:6219434a0cb5 372 if(!strcmp( optarg, "250K")) return 0x03;
sam_grove 0:6219434a0cb5 373 if(!strcmp( optarg, "125K")) return 0x04;
sam_grove 0:6219434a0cb5 374 if(!strcmp( optarg, "100K")) return 0x05;
sam_grove 0:6219434a0cb5 375 if(!strcmp( optarg, "50K")) return 0x06;
sam_grove 0:6219434a0cb5 376 if(!strcmp( optarg, "20K")) return 0x07;
sam_grove 0:6219434a0cb5 377 if(!strcmp( optarg, "10K")) return 0x08;
sam_grove 0:6219434a0cb5 378 return 0xFF;
sam_grove 0:6219434a0cb5 379 }
sam_grove 0:6219434a0cb5 380
sam_grove 0:6219434a0cb5 381 /*!
sam_grove 0:6219434a0cb5 382 **
sam_grove 0:6219434a0cb5 383 **
sam_grove 0:6219434a0cb5 384 ** @param d
sam_grove 0:6219434a0cb5 385 ** @param cob_id
sam_grove 0:6219434a0cb5 386 **
sam_grove 0:6219434a0cb5 387 ** @return
sam_grove 0:6219434a0cb5 388 **/
sam_grove 0:6219434a0cb5 389 UNS8 sendMasterLSSMessage(CO_Data* d, UNS8 command,void *dat1,void *dat2)
sam_grove 0:6219434a0cb5 390 {
sam_grove 0:6219434a0cb5 391 Message m;
sam_grove 0:6219434a0cb5 392 UNS8 i;
sam_grove 0:6219434a0cb5 393 UNS8 res;
sam_grove 0:6219434a0cb5 394 UNS8 hasResponse=0;
sam_grove 0:6219434a0cb5 395
sam_grove 0:6219434a0cb5 396 for(i=1;i<8;i++)m.data[i]=0;
sam_grove 0:6219434a0cb5 397 m.len = 8;
sam_grove 0:6219434a0cb5 398 m.rtr = NOT_A_REQUEST;
sam_grove 0:6219434a0cb5 399 m.data[0]=command;
sam_grove 0:6219434a0cb5 400 m.cob_id=UNS16_LE(MLSS_ADRESS);
sam_grove 0:6219434a0cb5 401
sam_grove 0:6219434a0cb5 402 /* Tha data sent with the msg depends on the command */
sam_grove 0:6219434a0cb5 403 switch(command){
sam_grove 0:6219434a0cb5 404 case LSS_CONF_NODE_ID: /* Configure Node-ID */
sam_grove 0:6219434a0cb5 405 hasResponse=1;
sam_grove 0:6219434a0cb5 406 case LSS_SM_GLOBAL: /* Switch Mode Global */
sam_grove 0:6219434a0cb5 407 m.data[1]=*(UNS8 *)dat1;
sam_grove 0:6219434a0cb5 408 break;
sam_grove 0:6219434a0cb5 409 case LSS_CONF_BIT_TIMING: /* Configure Bit Timing Parameters */
sam_grove 0:6219434a0cb5 410
sam_grove 0:6219434a0cb5 411 m.data[1]=*(UNS8 *)dat1;
sam_grove 0:6219434a0cb5 412 d->lss_transfer.baudRate=*(char **)dat2;
sam_grove 0:6219434a0cb5 413
sam_grove 0:6219434a0cb5 414 if((m.data[2]=CO_TranslateBaudRate(d->lss_transfer.baudRate))!=0xFF){
sam_grove 0:6219434a0cb5 415 hasResponse=1;
sam_grove 0:6219434a0cb5 416 break;
sam_grove 0:6219434a0cb5 417 }
sam_grove 0:6219434a0cb5 418
sam_grove 0:6219434a0cb5 419 MSG_ERR(0x1D19, "Master-> Baud rate not supported",0);
sam_grove 0:6219434a0cb5 420 d->lss_transfer.dat1=0xFF;
sam_grove 0:6219434a0cb5 421
sam_grove 0:6219434a0cb5 422 /* if bit timing is not supported comment the previous code and uncomment the following one*/
sam_grove 0:6219434a0cb5 423 /*{
sam_grove 0:6219434a0cb5 424 MSG_ERR(0x1D1A, "Master-> Bit timing not supported",0);
sam_grove 0:6219434a0cb5 425 d->lss_transfer.dat1=0x01;
sam_grove 0:6219434a0cb5 426 }*/
sam_grove 0:6219434a0cb5 427
sam_grove 0:6219434a0cb5 428 d->lss_transfer.dat2=0;
sam_grove 0:6219434a0cb5 429 /* If there is a callback, it is responsible of the error */
sam_grove 0:6219434a0cb5 430 if(d->lss_transfer.Callback)
sam_grove 0:6219434a0cb5 431 (*d->lss_transfer.Callback)(d,d->lss_transfer.command);
sam_grove 0:6219434a0cb5 432 return 0xFF;
sam_grove 0:6219434a0cb5 433 //break;
sam_grove 0:6219434a0cb5 434 case LSS_CONF_ACT_BIT_TIMING: /* Activate Bit Timing Parameters */
sam_grove 0:6219434a0cb5 435 m.data[1]=(UNS8)(*(UNS32*)dat1 & 0xFF);
sam_grove 0:6219434a0cb5 436 m.data[2]=(UNS8)(*(UNS32*)dat1>>8 & 0xFF);
sam_grove 0:6219434a0cb5 437 if(d->lss_transfer.baudRate!="none"){
sam_grove 0:6219434a0cb5 438 d->lss_transfer.switchDelay=(UNS16)(*(UNS32*)dat1 & 0xFFFF);
sam_grove 0:6219434a0cb5 439 d->lss_transfer.switchDelayState=SDELAY_FIRST;
sam_grove 0:6219434a0cb5 440 d->lss_transfer.canHandle_t=d->canHandle;
sam_grove 0:6219434a0cb5 441 res=canSend(d->canHandle,&m);
sam_grove 0:6219434a0cb5 442 if(res==0){
sam_grove 0:6219434a0cb5 443 StartLSS_SDELAY_TIMER();
sam_grove 0:6219434a0cb5 444 d->lss_transfer.state=LSS_TRANS_IN_PROGRESS;
sam_grove 0:6219434a0cb5 445 }
sam_grove 0:6219434a0cb5 446 return res;
sam_grove 0:6219434a0cb5 447 }
sam_grove 0:6219434a0cb5 448 else{
sam_grove 0:6219434a0cb5 449 MSG_ERR(0x1D1B, "Master-> Baud rate not specified",0);
sam_grove 0:6219434a0cb5 450 d->lss_transfer.dat1=1;
sam_grove 0:6219434a0cb5 451 /* If there is a callback, it is responsible of the error */
sam_grove 0:6219434a0cb5 452 if(d->lss_transfer.Callback){
sam_grove 0:6219434a0cb5 453 (*d->lss_transfer.Callback)(d,d->lss_transfer.command);
sam_grove 0:6219434a0cb5 454 }
sam_grove 0:6219434a0cb5 455 return 0xFF;
sam_grove 0:6219434a0cb5 456 }
sam_grove 0:6219434a0cb5 457 //break;
sam_grove 0:6219434a0cb5 458 case LSS_SM_SELECTIVE_SERIAL:
sam_grove 0:6219434a0cb5 459 case LSS_IDENT_REMOTE_SERIAL_HIGH:
sam_grove 0:6219434a0cb5 460 hasResponse=1;
sam_grove 0:6219434a0cb5 461 case LSS_SM_SELECTIVE_VENDOR: /* Switch Mode Selective */
sam_grove 0:6219434a0cb5 462 case LSS_SM_SELECTIVE_PRODUCT:
sam_grove 0:6219434a0cb5 463 case LSS_SM_SELECTIVE_REVISION:
sam_grove 0:6219434a0cb5 464 case LSS_IDENT_REMOTE_VENDOR: /* LSS Identify Remote Slaves */
sam_grove 0:6219434a0cb5 465 case LSS_IDENT_REMOTE_PRODUCT:
sam_grove 0:6219434a0cb5 466 case LSS_IDENT_REMOTE_REV_LOW:
sam_grove 0:6219434a0cb5 467 case LSS_IDENT_REMOTE_REV_HIGH:
sam_grove 0:6219434a0cb5 468 case LSS_IDENT_REMOTE_SERIAL_LOW:
sam_grove 0:6219434a0cb5 469 m.data[1]=(UNS8)(*(UNS32*)dat1 & 0xFF);
sam_grove 0:6219434a0cb5 470 m.data[2]=(UNS8)(*(UNS32*)dat1>>8 & 0xFF);
sam_grove 0:6219434a0cb5 471 m.data[3]=(UNS8)(*(UNS32*)dat1>>16 & 0xFF);
sam_grove 0:6219434a0cb5 472 m.data[4]=(UNS8)(*(UNS32*)dat1>>24 & 0xFF);
sam_grove 0:6219434a0cb5 473 break;
sam_grove 0:6219434a0cb5 474
sam_grove 0:6219434a0cb5 475 case LSS_CONF_STORE: /* Store Configured Parameters */
sam_grove 0:6219434a0cb5 476 case LSS_IDENT_REMOTE_NON_CONF: /* LSS identify non-configured remote slave */
sam_grove 0:6219434a0cb5 477 case LSS_INQ_VENDOR_ID: /* Inquire Identity Vendor-ID */
sam_grove 0:6219434a0cb5 478 case LSS_INQ_PRODUCT_CODE: /* Inquire Identity Product-Code */
sam_grove 0:6219434a0cb5 479 case LSS_INQ_REV_NUMBER: /* Inquire Identity Revision-Number */
sam_grove 0:6219434a0cb5 480 case LSS_INQ_SERIAL_NUMBER: /* Inquire Identity Serial-Number */
sam_grove 0:6219434a0cb5 481 case LSS_INQ_NODE_ID: /* Inquire Node-ID */
sam_grove 0:6219434a0cb5 482 hasResponse=1;
sam_grove 0:6219434a0cb5 483 break;
sam_grove 0:6219434a0cb5 484 #ifdef CO_ENABLE_LSS_FS
sam_grove 0:6219434a0cb5 485 case LSS_IDENT_FASTSCAN:
sam_grove 0:6219434a0cb5 486 if(d->lss_transfer.FastScan_SM==LSS_FS_RESET){
sam_grove 0:6219434a0cb5 487 UNS8 i;
sam_grove 0:6219434a0cb5 488 /* Initialize the lss_fs_transfer FastScan parameters */
sam_grove 0:6219434a0cb5 489 for(i=0;i<4;i++){
sam_grove 0:6219434a0cb5 490 d->lss_transfer.lss_fs_transfer.FS_LSS_ID[i]=(*(lss_fs_transfer_t*)dat1).FS_LSS_ID[i];
sam_grove 0:6219434a0cb5 491 d->lss_transfer.lss_fs_transfer.FS_BitChecked[i]=(*(lss_fs_transfer_t*)dat1).FS_BitChecked[i];
sam_grove 0:6219434a0cb5 492 /* Adjust BitChecked from 32-1 to 31-0 */
sam_grove 0:6219434a0cb5 493 if(d->lss_transfer.lss_fs_transfer.FS_BitChecked[i]>0)d->lss_transfer.lss_fs_transfer.FS_BitChecked[i]--;
sam_grove 0:6219434a0cb5 494 }
sam_grove 0:6219434a0cb5 495
sam_grove 0:6219434a0cb5 496 d->lss_transfer.IDNumber=0;
sam_grove 0:6219434a0cb5 497 d->lss_transfer.BitChecked=128;
sam_grove 0:6219434a0cb5 498 d->lss_transfer.LSSSub=0;
sam_grove 0:6219434a0cb5 499 d->lss_transfer.LSSNext=0;
sam_grove 0:6219434a0cb5 500
sam_grove 0:6219434a0cb5 501 /* it will generate a response only if it is the start of the FastScan protocol*/
sam_grove 0:6219434a0cb5 502 hasResponse=1;
sam_grove 0:6219434a0cb5 503 }
sam_grove 0:6219434a0cb5 504 m.data[1]=(UNS8)(d->lss_transfer.IDNumber & 0xFF);
sam_grove 0:6219434a0cb5 505 m.data[2]=(UNS8)(d->lss_transfer.IDNumber>>8 & 0xFF);
sam_grove 0:6219434a0cb5 506 m.data[3]=(UNS8)(d->lss_transfer.IDNumber>>16 & 0xFF);
sam_grove 0:6219434a0cb5 507 m.data[4]=(UNS8)(d->lss_transfer.IDNumber>>24 & 0xFF);
sam_grove 0:6219434a0cb5 508 m.data[5]=d->lss_transfer.BitChecked;
sam_grove 0:6219434a0cb5 509 m.data[6]=d->lss_transfer.LSSSub;
sam_grove 0:6219434a0cb5 510 m.data[7]=d->lss_transfer.LSSNext;
sam_grove 0:6219434a0cb5 511 break;
sam_grove 0:6219434a0cb5 512 #endif
sam_grove 0:6219434a0cb5 513 default:
sam_grove 0:6219434a0cb5 514 MSG_ERR(0x1D1C, "send Master LSS command not implemented", command);
sam_grove 0:6219434a0cb5 515 return 0xFF;
sam_grove 0:6219434a0cb5 516 }
sam_grove 0:6219434a0cb5 517
sam_grove 0:6219434a0cb5 518 res=canSend(d->canHandle,&m);
sam_grove 0:6219434a0cb5 519 if(res==0 && hasResponse==1){
sam_grove 0:6219434a0cb5 520 StartLSS_MSG_TIMER();
sam_grove 0:6219434a0cb5 521 d->lss_transfer.state=LSS_TRANS_IN_PROGRESS;
sam_grove 0:6219434a0cb5 522 }
sam_grove 0:6219434a0cb5 523 return res;
sam_grove 0:6219434a0cb5 524 }
sam_grove 0:6219434a0cb5 525
sam_grove 0:6219434a0cb5 526 /*!
sam_grove 0:6219434a0cb5 527 **
sam_grove 0:6219434a0cb5 528 **
sam_grove 0:6219434a0cb5 529 ** @param d
sam_grove 0:6219434a0cb5 530 ** @param cob_id
sam_grove 0:6219434a0cb5 531 **
sam_grove 0:6219434a0cb5 532 ** @return
sam_grove 0:6219434a0cb5 533 **/
sam_grove 0:6219434a0cb5 534 UNS8 sendLSS(CO_Data* d, UNS8 command,void *dat1,void *dat2)
sam_grove 0:6219434a0cb5 535 {
sam_grove 0:6219434a0cb5 536 UNS8 res=1;
sam_grove 0:6219434a0cb5 537
sam_grove 0:6219434a0cb5 538 /* Tha data sent with the msg depends on the command and if the sender is a master or a slave */
sam_grove 0:6219434a0cb5 539 if (*(d->iam_a_slave)){
sam_grove 0:6219434a0cb5 540 res = sendSlaveLSSMessage(d, command,dat1,dat2);
sam_grove 0:6219434a0cb5 541 }
sam_grove 0:6219434a0cb5 542 else {/* It is a Master */
sam_grove 0:6219434a0cb5 543 res = sendMasterLSSMessage(d, command,dat1,dat2);
sam_grove 0:6219434a0cb5 544 }
sam_grove 0:6219434a0cb5 545 return res ;
sam_grove 0:6219434a0cb5 546 }
sam_grove 0:6219434a0cb5 547
sam_grove 0:6219434a0cb5 548
sam_grove 0:6219434a0cb5 549 /*!
sam_grove 0:6219434a0cb5 550 **
sam_grove 0:6219434a0cb5 551 **
sam_grove 0:6219434a0cb5 552 ** @param d
sam_grove 0:6219434a0cb5 553 ** @param m
sam_grove 0:6219434a0cb5 554 **
sam_grove 0:6219434a0cb5 555 ** @return
sam_grove 0:6219434a0cb5 556 **/
sam_grove 0:6219434a0cb5 557 UNS8 proceedLSS_Master(CO_Data* d, Message* m )
sam_grove 0:6219434a0cb5 558 {
sam_grove 0:6219434a0cb5 559 UNS8 msg_cs;
sam_grove 0:6219434a0cb5 560 UNS32 Dat1=0;
sam_grove 0:6219434a0cb5 561 UNS8 Dat2=0;
sam_grove 0:6219434a0cb5 562
sam_grove 0:6219434a0cb5 563 if(d->lss_transfer.state!=LSS_TRANS_IN_PROGRESS)
sam_grove 0:6219434a0cb5 564 {
sam_grove 0:6219434a0cb5 565 //MSG_WAR(0x3D0D, "MasterLSS proceedLSS; unexpected message arrived;command ", m->data[0]);
sam_grove 0:6219434a0cb5 566 //return 0;
sam_grove 0:6219434a0cb5 567 goto ErrorProcessMaster;
sam_grove 0:6219434a0cb5 568 }
sam_grove 0:6219434a0cb5 569
sam_grove 0:6219434a0cb5 570 MSG_WAR(0x3D1E, "MasterLSS proceedLSS; command ", m->data[0]);
sam_grove 0:6219434a0cb5 571
sam_grove 0:6219434a0cb5 572 switch(msg_cs=m->data[0]){
sam_grove 0:6219434a0cb5 573 case LSS_INQ_NODE_ID: /* Inquire Node-ID */
sam_grove 0:6219434a0cb5 574 if(d->lss_transfer.command!=LSS_INQ_NODE_ID)goto ErrorProcessMaster;
sam_grove 0:6219434a0cb5 575 Dat1=m->data[1];
sam_grove 0:6219434a0cb5 576 break;
sam_grove 0:6219434a0cb5 577 case LSS_CONF_NODE_ID: /* Configure Node-ID */
sam_grove 0:6219434a0cb5 578 case LSS_CONF_BIT_TIMING: /* Configure Bit Timing Parameters */
sam_grove 0:6219434a0cb5 579 case LSS_CONF_STORE: /* Store Configured Parameters */
sam_grove 0:6219434a0cb5 580 if(d->lss_transfer.command!=msg_cs)goto ErrorProcessMaster;
sam_grove 0:6219434a0cb5 581 Dat1=m->data[1];
sam_grove 0:6219434a0cb5 582 Dat2=m->data[2];
sam_grove 0:6219434a0cb5 583 break;
sam_grove 0:6219434a0cb5 584 case LSS_INQ_VENDOR_ID: /* Inquire Identity Vendor-ID */
sam_grove 0:6219434a0cb5 585 case LSS_INQ_PRODUCT_CODE: /* Inquire Identity Product-Code */
sam_grove 0:6219434a0cb5 586 case LSS_INQ_REV_NUMBER: /* Inquire Identity Revision-Number */
sam_grove 0:6219434a0cb5 587 case LSS_INQ_SERIAL_NUMBER: /* Inquire Identity Serial-Number */
sam_grove 0:6219434a0cb5 588 if(d->lss_transfer.command!=msg_cs)goto ErrorProcessMaster;
sam_grove 0:6219434a0cb5 589 Dat1=getLSSIdent(m);
sam_grove 0:6219434a0cb5 590 break;
sam_grove 0:6219434a0cb5 591 case LSS_IDENT_SLAVE: /* LSS Identify Slave */
sam_grove 0:6219434a0cb5 592 #ifdef CO_ENABLE_LSS_FS
sam_grove 0:6219434a0cb5 593 if(d->lss_transfer.command==LSS_IDENT_FASTSCAN){
sam_grove 0:6219434a0cb5 594 /* A message arrived during the timer period */
sam_grove 0:6219434a0cb5 595 d->lss_transfer.LSSanswer=1;
sam_grove 0:6219434a0cb5 596 return 0;
sam_grove 0:6219434a0cb5 597 }
sam_grove 0:6219434a0cb5 598 else
sam_grove 0:6219434a0cb5 599 #endif
sam_grove 0:6219434a0cb5 600 if(d->lss_transfer.command!=LSS_IDENT_REMOTE_VENDOR && \
sam_grove 0:6219434a0cb5 601 d->lss_transfer.command!=LSS_IDENT_REMOTE_PRODUCT && \
sam_grove 0:6219434a0cb5 602 d->lss_transfer.command!=LSS_IDENT_REMOTE_REV_LOW && \
sam_grove 0:6219434a0cb5 603 d->lss_transfer.command!=LSS_IDENT_REMOTE_REV_HIGH && \
sam_grove 0:6219434a0cb5 604 d->lss_transfer.command!=LSS_IDENT_REMOTE_SERIAL_LOW && \
sam_grove 0:6219434a0cb5 605 d->lss_transfer.command!=LSS_IDENT_REMOTE_SERIAL_HIGH )
sam_grove 0:6219434a0cb5 606 goto ErrorProcessMaster;
sam_grove 0:6219434a0cb5 607 break;
sam_grove 0:6219434a0cb5 608 case LSS_SM_SELECTIVE_RESP: /* Switch Mode Selective response */
sam_grove 0:6219434a0cb5 609 if(d->lss_transfer.command!=LSS_SM_SELECTIVE_VENDOR && \
sam_grove 0:6219434a0cb5 610 d->lss_transfer.command!=LSS_SM_SELECTIVE_PRODUCT && \
sam_grove 0:6219434a0cb5 611 d->lss_transfer.command!=LSS_SM_SELECTIVE_REVISION && \
sam_grove 0:6219434a0cb5 612 d->lss_transfer.command!=LSS_SM_SELECTIVE_SERIAL )
sam_grove 0:6219434a0cb5 613 goto ErrorProcessMaster;
sam_grove 0:6219434a0cb5 614 break;
sam_grove 0:6219434a0cb5 615 case LSS_IDENT_NON_CONF_SLAVE: /* LSS identify non-configured remote slave */
sam_grove 0:6219434a0cb5 616 if(d->lss_transfer.command!=LSS_IDENT_REMOTE_NON_CONF)goto ErrorProcessMaster;
sam_grove 0:6219434a0cb5 617 break;
sam_grove 0:6219434a0cb5 618 default:
sam_grove 0:6219434a0cb5 619 MSG_ERR(0x1D1F, "Master LSS command not implemented", msg_cs);
sam_grove 0:6219434a0cb5 620 return 0xFF;
sam_grove 0:6219434a0cb5 621 }
sam_grove 0:6219434a0cb5 622
sam_grove 0:6219434a0cb5 623 StopLSS_MSG_TIMER();
sam_grove 0:6219434a0cb5 624 d->lss_transfer.state = LSS_FINISHED;
sam_grove 0:6219434a0cb5 625
sam_grove 0:6219434a0cb5 626 d->lss_transfer.dat1=Dat1;
sam_grove 0:6219434a0cb5 627 d->lss_transfer.dat2=Dat2;
sam_grove 0:6219434a0cb5 628 /* If there is a callback, it is responsible of the received response */
sam_grove 0:6219434a0cb5 629 if(d->lss_transfer.Callback)
sam_grove 0:6219434a0cb5 630 (*d->lss_transfer.Callback)(d,d->lss_transfer.command);
sam_grove 0:6219434a0cb5 631
sam_grove 0:6219434a0cb5 632 return 0;
sam_grove 0:6219434a0cb5 633
sam_grove 0:6219434a0cb5 634 ErrorProcessMaster:
sam_grove 0:6219434a0cb5 635 MSG_WAR(0x3D20, "MasterLSS proceedLSS; unexpected message arrived;command ", m->data[0]);
sam_grove 0:6219434a0cb5 636 return 0xFF;
sam_grove 0:6219434a0cb5 637
sam_grove 0:6219434a0cb5 638 }
sam_grove 0:6219434a0cb5 639
sam_grove 0:6219434a0cb5 640 /*!
sam_grove 0:6219434a0cb5 641 **
sam_grove 0:6219434a0cb5 642 **
sam_grove 0:6219434a0cb5 643 ** @param d
sam_grove 0:6219434a0cb5 644 ** @param m
sam_grove 0:6219434a0cb5 645 **
sam_grove 0:6219434a0cb5 646 ** @return
sam_grove 0:6219434a0cb5 647 **/
sam_grove 0:6219434a0cb5 648 UNS8 proceedLSS_Slave(CO_Data* d, Message* m )
sam_grove 0:6219434a0cb5 649 {
sam_grove 0:6219434a0cb5 650 UNS8 msg_cs;
sam_grove 0:6219434a0cb5 651
sam_grove 0:6219434a0cb5 652 MSG_WAR(0x3D21, "SlaveLSS proceedLSS; command ", m->data[0]);
sam_grove 0:6219434a0cb5 653
sam_grove 0:6219434a0cb5 654 switch(msg_cs=m->data[0]){
sam_grove 0:6219434a0cb5 655 case LSS_SM_GLOBAL: /* Switch Mode Global */
sam_grove 0:6219434a0cb5 656 /* if there is not a mode change break*/
sam_grove 0:6219434a0cb5 657 if(m->data[1] == d->lss_transfer.mode){
sam_grove 0:6219434a0cb5 658 MSG_WAR(0x3D22, "SlaveLSS already in the mode ", m->data[1]);
sam_grove 0:6219434a0cb5 659 break;
sam_grove 0:6219434a0cb5 660 }
sam_grove 0:6219434a0cb5 661
sam_grove 0:6219434a0cb5 662 if(m->data[1]==LSS_CONFIGURATION_MODE) {
sam_grove 0:6219434a0cb5 663 MSG_WAR(0x3D23, "SlaveLSS switching to configuration mode ", 0);
sam_grove 0:6219434a0cb5 664 /* Store the NodeId in case it will be changed */
sam_grove 0:6219434a0cb5 665 //d->lss_transfer.nodeID=getNodeId(d);
sam_grove 0:6219434a0cb5 666 d->lss_transfer.mode=LSS_CONFIGURATION_MODE;
sam_grove 0:6219434a0cb5 667 }
sam_grove 0:6219434a0cb5 668 else if(m->data[1]==LSS_WAITING_MODE){
sam_grove 0:6219434a0cb5 669 MSG_WAR(0x3D24, "SlaveLSS switching to operational mode ", 0);
sam_grove 0:6219434a0cb5 670
sam_grove 0:6219434a0cb5 671 /* If the nodeID has changed update it and put the node state to Initialisation. */
sam_grove 0:6219434a0cb5 672 if(d->lss_transfer.nodeID!=getNodeId(d)){
sam_grove 0:6219434a0cb5 673 if(getNodeId(d)==0xFF){/* The nodeID was 0xFF; initialize the application*/
sam_grove 0:6219434a0cb5 674 MSG_WAR(0x3D25, "The node Id has changed. Reseting to Initialisation state",0);
sam_grove 0:6219434a0cb5 675 setNodeId(d, d->lss_transfer.nodeID);
sam_grove 0:6219434a0cb5 676 setState(d, Initialisation);
sam_grove 0:6219434a0cb5 677 }
sam_grove 0:6219434a0cb5 678 else{/* The nodeID will be changed on NMT_Reset_Comunication Request*/
sam_grove 0:6219434a0cb5 679 }
sam_grove 0:6219434a0cb5 680 }
sam_grove 0:6219434a0cb5 681 d->lss_transfer.mode=LSS_WAITING_MODE;
sam_grove 0:6219434a0cb5 682 }
sam_grove 0:6219434a0cb5 683 break;
sam_grove 0:6219434a0cb5 684 case LSS_CONF_NODE_ID: /* Configure Node-ID */
sam_grove 0:6219434a0cb5 685 {
sam_grove 0:6219434a0cb5 686 UNS8 error_code=0;
sam_grove 0:6219434a0cb5 687 UNS8 spec_error=0;
sam_grove 0:6219434a0cb5 688
sam_grove 0:6219434a0cb5 689 if(d->lss_transfer.mode==LSS_CONFIGURATION_MODE){
sam_grove 0:6219434a0cb5 690 if(m->data[1]>127 && m->data[1]!=0xFF){
sam_grove 0:6219434a0cb5 691 MSG_ERR(0x1D26, "NodeID out of range",0);
sam_grove 0:6219434a0cb5 692 error_code=1; /* NodeID out of range */
sam_grove 0:6219434a0cb5 693 }
sam_grove 0:6219434a0cb5 694 else{
sam_grove 0:6219434a0cb5 695 d->lss_transfer.nodeID=m->data[1];
sam_grove 0:6219434a0cb5 696 }
sam_grove 0:6219434a0cb5 697 }
sam_grove 0:6219434a0cb5 698 else{
sam_grove 0:6219434a0cb5 699 MSG_WAR(0x3D27, "SlaveLSS not in configuration mode",0);
sam_grove 0:6219434a0cb5 700 //error_code=0xFF;
sam_grove 0:6219434a0cb5 701 break;
sam_grove 0:6219434a0cb5 702 }
sam_grove 0:6219434a0cb5 703 sendSlaveLSSMessage(d,msg_cs,&error_code,&spec_error);
sam_grove 0:6219434a0cb5 704 }
sam_grove 0:6219434a0cb5 705 break;
sam_grove 0:6219434a0cb5 706 case LSS_CONF_BIT_TIMING: /* Configure Bit Timing Parameters */
sam_grove 0:6219434a0cb5 707 {
sam_grove 0:6219434a0cb5 708 UNS8 error_code=0;
sam_grove 0:6219434a0cb5 709 UNS8 spec_error=0;
sam_grove 0:6219434a0cb5 710
sam_grove 0:6219434a0cb5 711 if(d->lss_transfer.mode==LSS_CONFIGURATION_MODE){
sam_grove 0:6219434a0cb5 712 /* If a baud rate is not supported just comment the line. */
sam_grove 0:6219434a0cb5 713 switch(m->data[2]){
sam_grove 0:6219434a0cb5 714 case 0x00:d->lss_transfer.baudRate="1M";break;
sam_grove 0:6219434a0cb5 715 case 0x01:d->lss_transfer.baudRate="800K";break;
sam_grove 0:6219434a0cb5 716 case 0x02:d->lss_transfer.baudRate="500K";break;
sam_grove 0:6219434a0cb5 717 case 0x03:d->lss_transfer.baudRate="250K";break;
sam_grove 0:6219434a0cb5 718 case 0x04:d->lss_transfer.baudRate="125K";break;
sam_grove 0:6219434a0cb5 719 case 0x05:d->lss_transfer.baudRate="100K";break;
sam_grove 0:6219434a0cb5 720 case 0x06:d->lss_transfer.baudRate="50K";break;
sam_grove 0:6219434a0cb5 721 case 0x07:d->lss_transfer.baudRate="20K";break;
sam_grove 0:6219434a0cb5 722 case 0x08:d->lss_transfer.baudRate="10K";break;
sam_grove 0:6219434a0cb5 723 default:
sam_grove 0:6219434a0cb5 724 MSG_ERR(0x1D28, "Baud rate not supported",0);
sam_grove 0:6219434a0cb5 725 error_code=0xFF; /* Baud rate not supported*/
sam_grove 0:6219434a0cb5 726 break;
sam_grove 0:6219434a0cb5 727 }
sam_grove 0:6219434a0cb5 728 }
sam_grove 0:6219434a0cb5 729 else{
sam_grove 0:6219434a0cb5 730 MSG_WAR(0x3D2A, "SlaveLSS not in configuration mode",0);
sam_grove 0:6219434a0cb5 731 //error_code=0xFF;
sam_grove 0:6219434a0cb5 732 break;
sam_grove 0:6219434a0cb5 733 }
sam_grove 0:6219434a0cb5 734
sam_grove 0:6219434a0cb5 735 /* if bit timing is not supported comment the previous code and uncomment the following */
sam_grove 0:6219434a0cb5 736 /*{
sam_grove 0:6219434a0cb5 737 MSG_ERR(0x1D29, "Bit timing not supported",0);
sam_grove 0:6219434a0cb5 738 error_code=0x01; // bit timing not supported
sam_grove 0:6219434a0cb5 739 }*/
sam_grove 0:6219434a0cb5 740
sam_grove 0:6219434a0cb5 741 sendSlaveLSSMessage(d,msg_cs,&error_code,&spec_error);
sam_grove 0:6219434a0cb5 742 }
sam_grove 0:6219434a0cb5 743 break;
sam_grove 0:6219434a0cb5 744 case LSS_CONF_ACT_BIT_TIMING: /* Activate Bit Timing Parameters */
sam_grove 0:6219434a0cb5 745
sam_grove 0:6219434a0cb5 746 if(d->lss_transfer.mode!=LSS_CONFIGURATION_MODE){
sam_grove 0:6219434a0cb5 747 MSG_ERR(0x3D2B, "SlaveLSS not in configuration mode",0);
sam_grove 0:6219434a0cb5 748 break;
sam_grove 0:6219434a0cb5 749 }
sam_grove 0:6219434a0cb5 750
sam_grove 0:6219434a0cb5 751 if(d->lss_transfer.baudRate!="none"){
sam_grove 0:6219434a0cb5 752 d->lss_transfer.switchDelay=getLSSDelay(m);
sam_grove 0:6219434a0cb5 753 MSG_WAR(0x3D2C, "Slave Switch Delay set to: ",d->lss_transfer.switchDelay);
sam_grove 0:6219434a0cb5 754 d->lss_transfer.switchDelayState=SDELAY_FIRST;
sam_grove 0:6219434a0cb5 755 //d->lss_transfer.currentState=getState(d);
sam_grove 0:6219434a0cb5 756 //setState(d, LssTimingDelay);
sam_grove 0:6219434a0cb5 757 d->lss_transfer.canHandle_t=d->canHandle;
sam_grove 0:6219434a0cb5 758 d->canHandle=NULL;
sam_grove 0:6219434a0cb5 759 StartLSS_SDELAY_TIMER();
sam_grove 0:6219434a0cb5 760 }
sam_grove 0:6219434a0cb5 761 break;
sam_grove 0:6219434a0cb5 762 case LSS_CONF_STORE: /* Store Configured Parameters */
sam_grove 0:6219434a0cb5 763 {
sam_grove 0:6219434a0cb5 764 UNS8 error_code=0;
sam_grove 0:6219434a0cb5 765 UNS8 spec_error=0;
sam_grove 0:6219434a0cb5 766
sam_grove 0:6219434a0cb5 767 if(d->lss_transfer.mode==LSS_CONFIGURATION_MODE){
sam_grove 0:6219434a0cb5 768 if(d->lss_StoreConfiguration){
sam_grove 0:6219434a0cb5 769 /* call lss_StoreConfiguration with NodeId */
sam_grove 0:6219434a0cb5 770 (*d->lss_StoreConfiguration)(d,&error_code,&spec_error);
sam_grove 0:6219434a0cb5 771 }
sam_grove 0:6219434a0cb5 772 else{
sam_grove 0:6219434a0cb5 773 MSG_ERR(0x1D2E, "Store configuration not supported",0);
sam_grove 0:6219434a0cb5 774 error_code=1; /* store configuration is not supported */
sam_grove 0:6219434a0cb5 775 }
sam_grove 0:6219434a0cb5 776 }
sam_grove 0:6219434a0cb5 777 else{
sam_grove 0:6219434a0cb5 778 MSG_WAR(0x3D2F, "SlaveLSS not in configuration mode",0);
sam_grove 0:6219434a0cb5 779 //error_code=0xFF;
sam_grove 0:6219434a0cb5 780 break;
sam_grove 0:6219434a0cb5 781 }
sam_grove 0:6219434a0cb5 782 sendSlaveLSSMessage(d,msg_cs,&error_code,&spec_error);
sam_grove 0:6219434a0cb5 783 }
sam_grove 0:6219434a0cb5 784 break;
sam_grove 0:6219434a0cb5 785 case LSS_SM_SELECTIVE_VENDOR: /* Switch Mode Selective */
sam_grove 0:6219434a0cb5 786 case LSS_SM_SELECTIVE_PRODUCT:
sam_grove 0:6219434a0cb5 787 case LSS_SM_SELECTIVE_REVISION:
sam_grove 0:6219434a0cb5 788 case LSS_SM_SELECTIVE_SERIAL:
sam_grove 0:6219434a0cb5 789 {
sam_grove 0:6219434a0cb5 790 UNS32 errorCode;
sam_grove 0:6219434a0cb5 791 const indextable *ptrTable;
sam_grove 0:6219434a0cb5 792 ODCallback_t *Callback;
sam_grove 0:6219434a0cb5 793 UNS32 _SpecificNodeInfo;
sam_grove 0:6219434a0cb5 794
sam_grove 0:6219434a0cb5 795 if(d->lss_transfer.mode==LSS_CONFIGURATION_MODE)
sam_grove 0:6219434a0cb5 796 {
sam_grove 0:6219434a0cb5 797 MSG_ERR(0x1D30, "Switch Mode Selective only supported in operational mode",0);
sam_grove 0:6219434a0cb5 798 break;
sam_grove 0:6219434a0cb5 799 }
sam_grove 0:6219434a0cb5 800
sam_grove 0:6219434a0cb5 801 _SpecificNodeInfo=getLSSIdent(m);
sam_grove 0:6219434a0cb5 802
sam_grove 0:6219434a0cb5 803 ptrTable = (*d->scanIndexOD)(0x1018, &errorCode, &Callback);
sam_grove 0:6219434a0cb5 804 if(_SpecificNodeInfo==*(UNS32*)ptrTable->pSubindex[msg_cs-(LSS_SM_SELECTIVE_VENDOR-1)].pObject){
sam_grove 0:6219434a0cb5 805
sam_grove 0:6219434a0cb5 806 d->lss_transfer.addr_sel_match|=(0x01<<(msg_cs-LSS_SM_SELECTIVE_VENDOR));
sam_grove 0:6219434a0cb5 807 /* If all the fields has been set */
sam_grove 0:6219434a0cb5 808 if(d->lss_transfer.addr_sel_match==0x0F){
sam_grove 0:6219434a0cb5 809
sam_grove 0:6219434a0cb5 810 MSG_WAR(0x3D31, "SlaveLSS switching to configuration mode ", 0);
sam_grove 0:6219434a0cb5 811 d->lss_transfer.addr_sel_match=0;
sam_grove 0:6219434a0cb5 812 d->lss_transfer.nodeID=getNodeId(d);
sam_grove 0:6219434a0cb5 813 d->lss_transfer.mode=LSS_CONFIGURATION_MODE;
sam_grove 0:6219434a0cb5 814
sam_grove 0:6219434a0cb5 815 sendSlaveLSSMessage(d,LSS_SM_SELECTIVE_RESP,0,0);
sam_grove 0:6219434a0cb5 816 }
sam_grove 0:6219434a0cb5 817 }
sam_grove 0:6219434a0cb5 818 else {
sam_grove 0:6219434a0cb5 819 MSG_WAR(0x3D32, "LSS identity field doesn't match ", _SpecificNodeInfo);
sam_grove 0:6219434a0cb5 820 d->lss_transfer.addr_sel_match=0;
sam_grove 0:6219434a0cb5 821 }
sam_grove 0:6219434a0cb5 822 }
sam_grove 0:6219434a0cb5 823 break;
sam_grove 0:6219434a0cb5 824 case LSS_IDENT_REMOTE_VENDOR: /* LSS Identify Remote Slaves */
sam_grove 0:6219434a0cb5 825 case LSS_IDENT_REMOTE_PRODUCT:
sam_grove 0:6219434a0cb5 826 case LSS_IDENT_REMOTE_REV_LOW:
sam_grove 0:6219434a0cb5 827 case LSS_IDENT_REMOTE_REV_HIGH:
sam_grove 0:6219434a0cb5 828 case LSS_IDENT_REMOTE_SERIAL_LOW:
sam_grove 0:6219434a0cb5 829 case LSS_IDENT_REMOTE_SERIAL_HIGH:
sam_grove 0:6219434a0cb5 830 {
sam_grove 0:6219434a0cb5 831 UNS32 errorCode;
sam_grove 0:6219434a0cb5 832 const indextable *ptrTable;
sam_grove 0:6219434a0cb5 833 ODCallback_t *Callback;
sam_grove 0:6219434a0cb5 834 UNS32 _SpecificNodeInfo;
sam_grove 0:6219434a0cb5 835
sam_grove 0:6219434a0cb5 836 _SpecificNodeInfo=getLSSIdent(m);
sam_grove 0:6219434a0cb5 837
sam_grove 0:6219434a0cb5 838 ptrTable = (*d->scanIndexOD)(0x1018, &errorCode, &Callback);
sam_grove 0:6219434a0cb5 839
sam_grove 0:6219434a0cb5 840 /* Check if the data match the identity object. */
sam_grove 0:6219434a0cb5 841 switch(msg_cs){
sam_grove 0:6219434a0cb5 842 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;
sam_grove 0:6219434a0cb5 843 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;
sam_grove 0:6219434a0cb5 844 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;
sam_grove 0:6219434a0cb5 845 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;
sam_grove 0:6219434a0cb5 846 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;
sam_grove 0:6219434a0cb5 847 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;
sam_grove 0:6219434a0cb5 848 }
sam_grove 0:6219434a0cb5 849 /* If all the fields has been set.. */
sam_grove 0:6219434a0cb5 850 if(d->lss_transfer.addr_ident_match==0x3F){
sam_grove 0:6219434a0cb5 851 MSG_WAR(0x3D33, "SlaveLSS identified ", 0);
sam_grove 0:6219434a0cb5 852 d->lss_transfer.addr_ident_match=0;
sam_grove 0:6219434a0cb5 853 sendSlaveLSSMessage(d,LSS_IDENT_SLAVE,0,0);
sam_grove 0:6219434a0cb5 854 }
sam_grove 0:6219434a0cb5 855 else if(d->lss_transfer.addr_ident_match==0){
sam_grove 0:6219434a0cb5 856 MSG_WAR(0x3D34, "LSS identify field doesn't match ", _SpecificNodeInfo);
sam_grove 0:6219434a0cb5 857 }
sam_grove 0:6219434a0cb5 858 }
sam_grove 0:6219434a0cb5 859 break;
sam_grove 0:6219434a0cb5 860 case LSS_IDENT_REMOTE_NON_CONF: /* LSS identify non-configured remote slave */
sam_grove 0:6219434a0cb5 861 {
sam_grove 0:6219434a0cb5 862 if(getNodeId(d)==0xFF){
sam_grove 0:6219434a0cb5 863 MSG_WAR(0x3D35, "SlaveLSS non-configured ", 0);
sam_grove 0:6219434a0cb5 864 sendSlaveLSSMessage(d,LSS_IDENT_NON_CONF_SLAVE,0,0);
sam_grove 0:6219434a0cb5 865 }
sam_grove 0:6219434a0cb5 866 else{
sam_grove 0:6219434a0cb5 867 MSG_WAR(0x3D36, "SlaveLSS already configured ", 0);
sam_grove 0:6219434a0cb5 868 }
sam_grove 0:6219434a0cb5 869 }
sam_grove 0:6219434a0cb5 870 break;
sam_grove 0:6219434a0cb5 871 case LSS_INQ_VENDOR_ID: /* Inquire Identity Vendor-ID */
sam_grove 0:6219434a0cb5 872 case LSS_INQ_PRODUCT_CODE: /* Inquire Identity Product-Code */
sam_grove 0:6219434a0cb5 873 case LSS_INQ_REV_NUMBER: /* Inquire Identity Revision-Number */
sam_grove 0:6219434a0cb5 874 case LSS_INQ_SERIAL_NUMBER: /* Inquire Identity Serial-Number */
sam_grove 0:6219434a0cb5 875 if(d->lss_transfer.mode==LSS_CONFIGURATION_MODE)
sam_grove 0:6219434a0cb5 876 {
sam_grove 0:6219434a0cb5 877
sam_grove 0:6219434a0cb5 878 UNS32 errorCode;
sam_grove 0:6219434a0cb5 879 const indextable *ptrTable;
sam_grove 0:6219434a0cb5 880 ODCallback_t *Callback;
sam_grove 0:6219434a0cb5 881 UNS32 _SpecificNodeInfo;
sam_grove 0:6219434a0cb5 882
sam_grove 0:6219434a0cb5 883 ptrTable = (*d->scanIndexOD)(0x1018, &errorCode, &Callback);
sam_grove 0:6219434a0cb5 884 _SpecificNodeInfo=*(UNS32*)ptrTable->pSubindex[msg_cs-(LSS_INQ_VENDOR_ID-1)].pObject;
sam_grove 0:6219434a0cb5 885 MSG_WAR(0x3D37, "SlaveLSS identity field inquired ", _SpecificNodeInfo);
sam_grove 0:6219434a0cb5 886
sam_grove 0:6219434a0cb5 887 sendSlaveLSSMessage(d,msg_cs,&_SpecificNodeInfo,0);
sam_grove 0:6219434a0cb5 888 }
sam_grove 0:6219434a0cb5 889 break;
sam_grove 0:6219434a0cb5 890 case LSS_INQ_NODE_ID: /* Inquire Node-ID */
sam_grove 0:6219434a0cb5 891 if(d->lss_transfer.mode==LSS_CONFIGURATION_MODE)
sam_grove 0:6219434a0cb5 892 {
sam_grove 0:6219434a0cb5 893 UNS8 NodeID;
sam_grove 0:6219434a0cb5 894
sam_grove 0:6219434a0cb5 895 NodeID=getNodeId(d);
sam_grove 0:6219434a0cb5 896 MSG_WAR(0x3D38, "SlaveLSS Node ID inquired ", NodeID);
sam_grove 0:6219434a0cb5 897 sendSlaveLSSMessage(d,msg_cs,&NodeID,0);
sam_grove 0:6219434a0cb5 898 }
sam_grove 0:6219434a0cb5 899 else{
sam_grove 0:6219434a0cb5 900 MSG_WAR(0x3D39, "SlaveLSS not in configuration mode",0);
sam_grove 0:6219434a0cb5 901 }
sam_grove 0:6219434a0cb5 902 break;
sam_grove 0:6219434a0cb5 903 #ifdef CO_ENABLE_LSS_FS
sam_grove 0:6219434a0cb5 904 case LSS_IDENT_FASTSCAN:
sam_grove 0:6219434a0cb5 905 {
sam_grove 0:6219434a0cb5 906 /* If the nodeID isn't 0xFF the slave shall not participate */
sam_grove 0:6219434a0cb5 907 if(getNodeId(d)!=0xFF)break;
sam_grove 0:6219434a0cb5 908 if(getLSSBitCheck(m)==128)d->lss_transfer.FastScan_SM=LSS_FS_RESET;
sam_grove 0:6219434a0cb5 909
sam_grove 0:6219434a0cb5 910 switch(d->lss_transfer.FastScan_SM){
sam_grove 0:6219434a0cb5 911 case LSS_FS_RESET:
sam_grove 0:6219434a0cb5 912 {
sam_grove 0:6219434a0cb5 913 UNS32 errorCode;
sam_grove 0:6219434a0cb5 914 const indextable *ptrTable;
sam_grove 0:6219434a0cb5 915 ODCallback_t *Callback;
sam_grove 0:6219434a0cb5 916
sam_grove 0:6219434a0cb5 917 MSG_WAR(0x3D3A, "SlaveLSS Reseting LSSPos", 0);
sam_grove 0:6219434a0cb5 918 d->lss_transfer.LSSPos=0;
sam_grove 0:6219434a0cb5 919 d->lss_transfer.FastScan_SM=LSS_FS_PROCESSING;
sam_grove 0:6219434a0cb5 920
sam_grove 0:6219434a0cb5 921 ptrTable = (*d->scanIndexOD)(0x1018, &errorCode, &Callback);
sam_grove 0:6219434a0cb5 922 d->lss_transfer.IDNumber=*(UNS32*)ptrTable->pSubindex[d->lss_transfer.LSSPos+1].pObject;
sam_grove 0:6219434a0cb5 923
sam_grove 0:6219434a0cb5 924 sendSlaveLSSMessage(d,LSS_IDENT_SLAVE,0,0);
sam_grove 0:6219434a0cb5 925 }
sam_grove 0:6219434a0cb5 926 break;
sam_grove 0:6219434a0cb5 927 case LSS_FS_PROCESSING:/*if(getLSSBitCheck(m)<32)*/
sam_grove 0:6219434a0cb5 928 if(d->lss_transfer.LSSPos==getLSSSub(m))
sam_grove 0:6219434a0cb5 929 {
sam_grove 0:6219434a0cb5 930 UNS32 Mask=0xFFFFFFFF<<getLSSBitCheck(m);
sam_grove 0:6219434a0cb5 931
sam_grove 0:6219434a0cb5 932 MSG_WAR(0x3D3B, "SlaveLSS FastScan IDNumber", getLSSIdent(m));
sam_grove 0:6219434a0cb5 933 MSG_WAR(0x3D3C, "SlaveLSS FastScan BitMask ", Mask);
sam_grove 0:6219434a0cb5 934 MSG_WAR(0x3D3D, "SlaveLSS FastScan LSS-ID ", d->lss_transfer.IDNumber);
sam_grove 0:6219434a0cb5 935
sam_grove 0:6219434a0cb5 936 if((getLSSIdent(m) & Mask)==(d->lss_transfer.IDNumber & Mask))
sam_grove 0:6219434a0cb5 937 {
sam_grove 0:6219434a0cb5 938 sendSlaveLSSMessage(d,LSS_IDENT_SLAVE,0,0);
sam_grove 0:6219434a0cb5 939 }
sam_grove 0:6219434a0cb5 940
sam_grove 0:6219434a0cb5 941 if(getLSSBitCheck(m)==0)
sam_grove 0:6219434a0cb5 942 {
sam_grove 0:6219434a0cb5 943 d->lss_transfer.FastScan_SM=LSS_FS_CONFIRMATION;
sam_grove 0:6219434a0cb5 944 }
sam_grove 0:6219434a0cb5 945 }
sam_grove 0:6219434a0cb5 946 break;
sam_grove 0:6219434a0cb5 947 case LSS_FS_CONFIRMATION:
sam_grove 0:6219434a0cb5 948 if(d->lss_transfer.LSSPos==getLSSSub(m))
sam_grove 0:6219434a0cb5 949 {
sam_grove 0:6219434a0cb5 950 if(getLSSIdent(m)==d->lss_transfer.IDNumber)
sam_grove 0:6219434a0cb5 951 {
sam_grove 0:6219434a0cb5 952 /* Current LSS-ID[sub] confirmed correctly */
sam_grove 0:6219434a0cb5 953 MSG_WAR(0x3D3E, "SlaveLSS FastScan IDNumber and LSS-ID match=>", d->lss_transfer.IDNumber);
sam_grove 0:6219434a0cb5 954 if(d->lss_transfer.LSSPos==3)
sam_grove 0:6219434a0cb5 955 {
sam_grove 0:6219434a0cb5 956 /* All LSS-ID[sub] identified correctly, switching to configuration mode */
sam_grove 0:6219434a0cb5 957 MSG_WAR(0x3D3F, "SlaveLSS switching to configuration mode ", 0);
sam_grove 0:6219434a0cb5 958 d->lss_transfer.nodeID=getNodeId(d);
sam_grove 0:6219434a0cb5 959 d->lss_transfer.mode=LSS_CONFIGURATION_MODE;
sam_grove 0:6219434a0cb5 960 d->lss_transfer.FastScan_SM=LSS_FS_RESET;
sam_grove 0:6219434a0cb5 961 d->lss_transfer.LSSPos=0xFF;
sam_grove 0:6219434a0cb5 962 }
sam_grove 0:6219434a0cb5 963 else
sam_grove 0:6219434a0cb5 964 {
sam_grove 0:6219434a0cb5 965 /* Switch to the next LSS-ID[sub] */
sam_grove 0:6219434a0cb5 966 UNS32 errorCode;
sam_grove 0:6219434a0cb5 967 const indextable *ptrTable;
sam_grove 0:6219434a0cb5 968 ODCallback_t *Callback;
sam_grove 0:6219434a0cb5 969
sam_grove 0:6219434a0cb5 970 d->lss_transfer.LSSPos=getLSSNext(m);
sam_grove 0:6219434a0cb5 971 ptrTable = (*d->scanIndexOD)(0x1018, &errorCode, &Callback);
sam_grove 0:6219434a0cb5 972 d->lss_transfer.IDNumber=*(UNS32*)ptrTable->pSubindex[d->lss_transfer.LSSPos+1].pObject;
sam_grove 0:6219434a0cb5 973 d->lss_transfer.FastScan_SM=LSS_FS_PROCESSING;
sam_grove 0:6219434a0cb5 974 }
sam_grove 0:6219434a0cb5 975 sendSlaveLSSMessage(d,LSS_IDENT_SLAVE,0,0);
sam_grove 0:6219434a0cb5 976 }
sam_grove 0:6219434a0cb5 977 }
sam_grove 0:6219434a0cb5 978 break;
sam_grove 0:6219434a0cb5 979 }
sam_grove 0:6219434a0cb5 980 }
sam_grove 0:6219434a0cb5 981 break;
sam_grove 0:6219434a0cb5 982 #endif
sam_grove 0:6219434a0cb5 983 default:
sam_grove 0:6219434a0cb5 984 MSG_ERR(0x1D40, "SlaveLSS command not implemented", msg_cs);
sam_grove 0:6219434a0cb5 985 return 0xFF;
sam_grove 0:6219434a0cb5 986 }
sam_grove 0:6219434a0cb5 987
sam_grove 0:6219434a0cb5 988 return 0;
sam_grove 0:6219434a0cb5 989 }
sam_grove 0:6219434a0cb5 990
sam_grove 0:6219434a0cb5 991 /*UNS8 configNetworkNode(CO_Data* d, UNS8 command, void *dat1, void* dat2)
sam_grove 0:6219434a0cb5 992 {
sam_grove 0:6219434a0cb5 993 return sendMasterLSSMessage(d,command,dat1,dat2);
sam_grove 0:6219434a0cb5 994 }*/
sam_grove 0:6219434a0cb5 995
sam_grove 0:6219434a0cb5 996 UNS8 configNetworkNode (CO_Data* d, UNS8 command, void *dat1, void* dat2, LSSCallback_t Callback)
sam_grove 0:6219434a0cb5 997 {
sam_grove 0:6219434a0cb5 998 //d->lss_transfer.state=LSS_TRANS_IN_PROGRESS;
sam_grove 0:6219434a0cb5 999 d->lss_transfer.Callback=Callback;
sam_grove 0:6219434a0cb5 1000 d->lss_transfer.command=command;
sam_grove 0:6219434a0cb5 1001
sam_grove 0:6219434a0cb5 1002 StopLSS_MSG_TIMER();
sam_grove 0:6219434a0cb5 1003 //StartLSS_MSG_TIMER();
sam_grove 0:6219434a0cb5 1004
sam_grove 0:6219434a0cb5 1005 return sendMasterLSSMessage(d,command,dat1,dat2);
sam_grove 0:6219434a0cb5 1006 }
sam_grove 0:6219434a0cb5 1007
sam_grove 0:6219434a0cb5 1008 UNS8 getConfigResultNetworkNode (CO_Data* d, UNS8 command, UNS32* dat1, UNS8* dat2)
sam_grove 0:6219434a0cb5 1009 {
sam_grove 0:6219434a0cb5 1010 *dat1=d->lss_transfer.dat1;
sam_grove 0:6219434a0cb5 1011 *dat2=d->lss_transfer.dat2;
sam_grove 0:6219434a0cb5 1012 return d->lss_transfer.state;
sam_grove 0:6219434a0cb5 1013 }
sam_grove 0:6219434a0cb5 1014
sam_grove 0:6219434a0cb5 1015 //void _lss_StoreConfiguration(UNS8 *error, UNS8 *spec_error){printf("_lss_StoreConfiguration\n");}
sam_grove 0:6219434a0cb5 1016
sam_grove 0:6219434a0cb5 1017 #endif