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