author | greg |
Tue, 29 Jan 2008 09:02:47 +0100 | |
changeset 371 | b13cfb3c6c16 |
parent 370 | 6fecf36df407 |
child 381 | 854c43cdc24a |
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 */ |
|
65 |
void LssAlarm(CO_Data* d, UNS32 id); |
|
66 |
||
67 |
#define StopLSS_TIMER(id){\ |
|
68 |
MSG_WAR(0x3D01, "StopLSS_TIMER for timer : ", id);\ |
|
69 |
d->lss_transfer.timers[id] = DelAlarm(d->lss_transfer.timers[id]);} |
|
70 |
||
71 |
#define StartLSS_MSG_TIMER(){\ |
|
72 |
MSG_WAR(0x3D02, "StartLSS_TIMER for MSG_TIMER",0);\ |
|
73 |
d->lss_transfer.timers[LSS_MSG_TIMER] = SetAlarm(d,LSS_MSG_TIMER,&LssAlarm,MS_TO_TIMEVAL(LSS_TIMEOUT_MS),0);} |
|
74 |
||
75 |
#define StartLSS_SDELAY_TIMER(){\ |
|
76 |
MSG_WAR(0x3D03, "StartLSS_TIMER for SDELAY_TIMER",0);\ |
|
77 |
d->lss_transfer.timers[LSS_SWITCH_DELAY_TIMER] = SetAlarm(d,LSS_SWITCH_DELAY_TIMER,&LssAlarm,MS_TO_TIMEVAL(d->lss_transfer.switchDelay),MS_TO_TIMEVAL(d->lss_transfer.switchDelay));} |
|
78 |
||
361 | 79 |
#define StartLSS_FS_TIMER(){\ |
80 |
MSG_WAR(0x3D04, "StartLSS_TIMER for FS_TIMER",0);\ |
|
81 |
d->lss_transfer.timers[LSS_FS_TIMER] = SetAlarm(d,LSS_FS_TIMER,&LssAlarm,MS_TO_TIMEVAL(LSS_FS_TIMEOUT_MS),0);} |
|
82 |
||
83 |
UNS8 sendMasterLSSMessage(CO_Data* d, UNS8 command,void *dat1,void *dat2); |
|
343 | 84 |
|
85 |
/*! |
|
86 |
** |
|
87 |
** |
|
88 |
** @param d |
|
89 |
** @param id |
|
90 |
**/ |
|
91 |
//struct timeval current_time,init_time; |
|
92 |
void LssAlarm(CO_Data* d, UNS32 id) |
|
93 |
{ |
|
94 |
/*unsigned long time_period; |
|
95 |
||
96 |
gettimeofday(¤t_time,NULL); |
|
97 |
time_period=(current_time.tv_sec - init_time.tv_sec)* 1000000 + current_time.tv_usec - init_time.tv_usec; |
|
98 |
printf("%3ld.%3ld.%3ld --",time_period/1000000,(time_period%1000000)/1000,time_period%1000);*/ |
|
99 |
||
100 |
switch(id){ |
|
101 |
case LSS_MSG_TIMER: |
|
361 | 102 |
StopLSS_TIMER(LSS_MSG_TIMER); |
103 |
#ifdef CO_ENABLE_LSS_FS |
|
104 |
if(d->lss_transfer.command==LSS_IDENT_FASTSCAN){ |
|
105 |
if(d->lss_transfer.FastScan_SM==LSS_FS_RESET){ |
|
106 |
/* if at least one node had answered before the timer expired, start the FastScan protocol*/ |
|
107 |
if(d->lss_transfer.LSSanswer!=0){ |
|
108 |
d->lss_transfer.LSSanswer=0; |
|
109 |
d->lss_transfer.BitChecked=31; |
|
110 |
d->lss_transfer.IDNumber=0; |
|
111 |
d->lss_transfer.FastScan_SM=LSS_FS_PROCESSING; |
|
112 |
StartLSS_FS_TIMER(); |
|
113 |
sendMasterLSSMessage(d,LSS_IDENT_FASTSCAN,0,0); |
|
114 |
return; |
|
115 |
} |
|
116 |
else{ |
|
117 |
||
118 |
d->lss_transfer.state = LSS_FINISHED; |
|
119 |
/* Inform the application that there aren't not configured nodes in the net */ |
|
120 |
d->lss_transfer.dat1=1; |
|
121 |
} |
|
122 |
} |
|
123 |
else{ |
|
124 |
/* This should not happen, an error ocurred*/ |
|
125 |
MSG_ERR(0x1D05, "LSS FastScan timeout. FastScan_SM inconsisten state.", d->lss_transfer.FastScan_SM); |
|
126 |
} |
|
127 |
} |
|
128 |
else |
|
129 |
#endif |
|
130 |
{ |
|
131 |
MSG_ERR(0x1D06, "LSS timeout. LSS response not received.", 0); |
|
132 |
MSG_WAR(0x2D07, "LSS timeout command specifier : ", d->lss_transfer.command); |
|
133 |
/* Set aborted state */ |
|
134 |
d->lss_transfer.state = LSS_ABORTED_INTERNAL; |
|
135 |
} |
|
136 |
||
343 | 137 |
/* Call the user function to inform of the problem.*/ |
138 |
if(d->lss_transfer.Callback){ |
|
361 | 139 |
/*If there is a callback, it is responsible of the error*/ |
343 | 140 |
(*d->lss_transfer.Callback)(d,d->lss_transfer.command); |
141 |
} |
|
142 |
break; |
|
143 |
case LSS_SWITCH_DELAY_TIMER: |
|
361 | 144 |
/* The first switch_delay period expired. Store the node state, change it |
343 | 145 |
* so no CAN messages will be sent or received, call the ChangeBaudRate function*/ |
146 |
if(d->lss_transfer.switchDelayState==SDELAY_FIRST){ |
|
361 | 147 |
MSG_WAR(0x3D08, "LSS switch delay first period expired",0); |
343 | 148 |
d->lss_transfer.switchDelayState=SDELAY_SECOND; |
149 |
(*d->lss_ChangeBaudRate)(d->lss_transfer.baudRate); |
|
150 |
} |
|
151 |
else{ /* d->lss_transfer.switchDelayState==SDELAY_SECOND */ |
|
361 | 152 |
MSG_WAR(0x3D09, "LSS switch delay second period expired",0); |
343 | 153 |
d->lss_transfer.switchDelayState=SDELAY_OFF; |
154 |
StopLSS_TIMER(LSS_SWITCH_DELAY_TIMER); |
|
155 |
||
156 |
setState(d, d->lss_transfer.currentState); |
|
157 |
} |
|
158 |
break; |
|
361 | 159 |
#ifdef CO_ENABLE_LSS_FS |
160 |
case LSS_FS_TIMER: |
|
161 |
StopLSS_TIMER(LSS_FS_TIMER); |
|
162 |
||
163 |
switch(d->lss_transfer.FastScan_SM){ |
|
164 |
case LSS_FS_RESET: |
|
165 |
{ |
|
166 |
/* This should not happen, an error ocurred*/ |
|
167 |
MSG_ERR(0x1D0A, "LSS FastScan timeout. FastScan_SM inconsisten state.", d->lss_transfer.FastScan_SM); |
|
168 |
} |
|
169 |
break; |
|
170 |
case LSS_FS_PROCESSING: |
|
171 |
{ |
|
172 |
/* If there isn't any answer, set the bit */ |
|
173 |
if(d->lss_transfer.LSSanswer==0){ |
|
174 |
UNS32 Mask=0x1; |
|
175 |
Mask<<=d->lss_transfer.BitChecked; |
|
176 |
d->lss_transfer.IDNumber|=Mask; |
|
177 |
} |
|
178 |
||
179 |
if(d->lss_transfer.BitChecked==0){ |
|
180 |
/* We finished with the current LSS-ID[sub], confirm it */ |
|
181 |
d->lss_transfer.FastScan_SM=LSS_FS_CONFIRMATION; |
|
182 |
if(d->lss_transfer.LSSNext<3)d->lss_transfer.LSSNext++; |
|
183 |
} |
|
184 |
else{ |
|
185 |
d->lss_transfer.BitChecked--; |
|
186 |
} |
|
187 |
||
188 |
d->lss_transfer.LSSanswer=0; |
|
189 |
StartLSS_FS_TIMER(); |
|
190 |
sendMasterLSSMessage(d,LSS_IDENT_FASTSCAN,0,0); |
|
191 |
return; |
|
192 |
} |
|
193 |
break; |
|
194 |
case LSS_FS_CONFIRMATION: |
|
195 |
{ |
|
196 |
if(d->lss_transfer.LSSanswer!=0){ |
|
197 |
d->lss_transfer.LSSanswer=0; |
|
198 |
||
199 |
if(d->lss_transfer.LSSSub==3){ |
|
200 |
/* The LSS FastScan protocol finished correctly. Restore the parameters */ |
|
201 |
d->lss_transfer.BitChecked=128; |
|
202 |
d->lss_transfer.FastScan_SM=LSS_FS_RESET; |
|
203 |
d->lss_transfer.LSSSub=0; |
|
204 |
d->lss_transfer.LSSNext=0; |
|
205 |
d->lss_transfer.IDNumber=0; |
|
206 |
||
207 |
/* Inform the application that the FastScan finished correctly */ |
|
208 |
d->lss_transfer.state = LSS_FINISHED; |
|
209 |
d->lss_transfer.dat1=0; |
|
210 |
} |
|
211 |
else{ |
|
212 |
/* Start with the next LSS-ID[sub] */ |
|
213 |
d->lss_transfer.LSSSub++; |
|
214 |
d->lss_transfer.BitChecked=31; |
|
215 |
d->lss_transfer.IDNumber=0; |
|
216 |
d->lss_transfer.FastScan_SM=LSS_FS_PROCESSING; |
|
217 |
StartLSS_FS_TIMER(); |
|
218 |
sendMasterLSSMessage(d,LSS_IDENT_FASTSCAN,0,0); |
|
219 |
return; |
|
220 |
} |
|
221 |
} |
|
222 |
else{ |
|
223 |
/* This should not happen, an error ocurred*/ |
|
224 |
MSG_ERR(0x1D0B, "LSS FastScan timeout. FastScan response not received.", 0); |
|
225 |
/* Set aborted state */ |
|
226 |
d->lss_transfer.state = LSS_ABORTED_INTERNAL; |
|
227 |
} |
|
228 |
} |
|
229 |
break; |
|
230 |
} |
|
231 |
||
232 |
/* Call the user function to inform of the problem.*/ |
|
233 |
if(d->lss_transfer.Callback){ |
|
234 |
/*If there is a callback, it is responsible of the error*/ |
|
235 |
(*d->lss_transfer.Callback)(d,d->lss_transfer.command); |
|
236 |
} |
|
237 |
break; |
|
238 |
#endif |
|
343 | 239 |
} |
240 |
} |
|
241 |
||
242 |
/*! |
|
243 |
** |
|
244 |
** |
|
245 |
** @param d |
|
246 |
**/ |
|
247 |
void startLSS(CO_Data* d) |
|
248 |
{ |
|
249 |
/*MSG_WAR(0x3D09, "LSS services started",0);*/ |
|
250 |
} |
|
251 |
||
252 |
/*! |
|
253 |
** |
|
254 |
** |
|
255 |
** @param d |
|
256 |
**/ |
|
257 |
void stopLSS(CO_Data* d) |
|
258 |
{ |
|
259 |
/*MSG_WAR(0x3D09, "LSS services stopped",0);*/ |
|
260 |
} |
|
261 |
||
262 |
/*! |
|
263 |
** |
|
264 |
** |
|
265 |
** @param d |
|
266 |
** @param cob_id |
|
267 |
** |
|
268 |
** @return |
|
269 |
**/ |
|
270 |
UNS8 sendSlaveLSSMessage(CO_Data* d, UNS8 command,void *dat1,void *dat2) |
|
271 |
{ |
|
272 |
Message m; |
|
273 |
UNS8 i; |
|
274 |
||
275 |
if (!d->CurrentCommunicationState.csLSS){ |
|
361 | 276 |
MSG_WAR(0x2D0C, "unable to send the LSS message, not in the proper state =>", d->nodeState); |
277 |
return 0xFF; |
|
343 | 278 |
} |
279 |
||
280 |
for(i=1;i<8;i++)m.data[i]=0; |
|
281 |
m.len = 8; |
|
282 |
m.rtr = NOT_A_REQUEST; |
|
283 |
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
|
284 |
m.cob_id=UNS16_LE(SLSS_ADRESS); |
343 | 285 |
|
286 |
/* Tha data sent with the msg depends on the command */ |
|
287 |
switch(command){ |
|
288 |
case LSS_INQ_NODE_ID: /* Inquire Node-ID */ |
|
289 |
m.data[1]=*(UNS8 *)dat1; |
|
290 |
break; |
|
291 |
case LSS_CONF_NODE_ID: /* Configure Node-ID */ |
|
292 |
case LSS_CONF_BIT_TIMING: /* Configure Bit Timing Parameters */ |
|
293 |
case LSS_CONF_STORE: /* Store Configured Parameters */ |
|
294 |
m.data[1]=*(UNS8 *)dat1; |
|
295 |
m.data[2]=*(UNS8 *)dat2; |
|
296 |
break; |
|
297 |
case LSS_INQ_VENDOR_ID: /* Inquire Identity Vendor-ID */ |
|
298 |
case LSS_INQ_PRODUCT_CODE: /* Inquire Identity Product-Code */ |
|
299 |
case LSS_INQ_REV_NUMBER: /* Inquire Identity Revision-Number */ |
|
300 |
case LSS_INQ_SERIAL_NUMBER: /* Inquire Identity Serial-Number */ |
|
301 |
m.data[1]=(UNS8)(*(UNS32*)dat1 & 0xFF); |
|
302 |
m.data[2]=(UNS8)(*(UNS32*)dat1>>8 & 0xFF); |
|
303 |
m.data[3]=(UNS8)(*(UNS32*)dat1>>16 & 0xFF); |
|
304 |
m.data[4]=(UNS8)(*(UNS32*)dat1>>24 & 0xFF); |
|
305 |
break; |
|
306 |
case LSS_SM_SELECTIVE_RESP: /* Switch Mode Selective response*/ |
|
307 |
case LSS_IDENT_SLAVE: /* LSS Identify Slave */ |
|
308 |
case LSS_IDENT_NON_CONF_SLAVE: /* LSS identify non-configured remote slave */ |
|
309 |
break; |
|
310 |
default: |
|
361 | 311 |
MSG_ERR(0x1D0D, "send Slave LSS command not implemented", command); |
343 | 312 |
return 0xFF; |
313 |
} |
|
314 |
||
315 |
return canSend(d->canHandle,&m); |
|
316 |
} |
|
317 |
||
318 |
/*! |
|
319 |
** |
|
320 |
** |
|
321 |
** @param d |
|
322 |
** @param cob_id |
|
323 |
** |
|
324 |
** @return |
|
325 |
**/ |
|
326 |
UNS8 sendMasterLSSMessage(CO_Data* d, UNS8 command,void *dat1,void *dat2) |
|
327 |
{ |
|
328 |
Message m; |
|
329 |
UNS8 i; |
|
330 |
||
331 |
for(i=1;i<8;i++)m.data[i]=0; |
|
332 |
m.len = 8; |
|
333 |
m.rtr = NOT_A_REQUEST; |
|
334 |
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
|
335 |
m.cob_id=UNS16_LE(MLSS_ADRESS); |
343 | 336 |
|
337 |
/* Tha data sent with the msg depends on the command */ |
|
338 |
switch(command){ |
|
339 |
case LSS_SM_GLOBAL: /* Switch Mode Global */ |
|
340 |
d->lss_transfer.state=LSS_FINISHED; |
|
341 |
case LSS_CONF_NODE_ID: /* Configure Node-ID */ |
|
342 |
m.data[1]=*(UNS8 *)dat1; |
|
343 |
break; |
|
344 |
case LSS_CONF_BIT_TIMING: /* Configure Bit Timing Parameters */ |
|
345 |
m.data[1]=*(UNS8 *)dat1; |
|
346 |
m.data[2]=*(UNS8 *)dat2; |
|
347 |
break; |
|
348 |
case LSS_CONF_ACT_BIT_TIMING: /* Activate Bit Timing Parameters */ |
|
349 |
m.data[1]=(UNS8)(*(UNS32*)dat1 & 0xFF); |
|
350 |
m.data[2]=(UNS8)(*(UNS32*)dat1>>8 & 0xFF); |
|
351 |
break; |
|
352 |
case LSS_SM_SELECTIVE_VENDOR: /* Switch Mode Selective */ |
|
353 |
case LSS_SM_SELECTIVE_PRODUCT: |
|
354 |
case LSS_SM_SELECTIVE_REVISION: |
|
355 |
case LSS_SM_SELECTIVE_SERIAL: |
|
356 |
case LSS_IDENT_REMOTE_VENDOR: /* LSS Identify Remote Slaves */ |
|
357 |
case LSS_IDENT_REMOTE_PRODUCT: |
|
358 |
case LSS_IDENT_REMOTE_REV_LOW: |
|
359 |
case LSS_IDENT_REMOTE_REV_HIGH: |
|
360 |
case LSS_IDENT_REMOTE_SERIAL_LOW: |
|
361 |
case LSS_IDENT_REMOTE_SERIAL_HIGH: |
|
362 |
m.data[1]=(UNS8)(*(UNS32*)dat1 & 0xFF); |
|
363 |
m.data[2]=(UNS8)(*(UNS32*)dat1>>8 & 0xFF); |
|
364 |
m.data[3]=(UNS8)(*(UNS32*)dat1>>16 & 0xFF); |
|
365 |
m.data[4]=(UNS8)(*(UNS32*)dat1>>24 & 0xFF); |
|
366 |
break; |
|
367 |
case LSS_CONF_STORE: /* Store Configured Parameters */ |
|
368 |
case LSS_IDENT_REMOTE_NON_CONF: /* LSS identify non-configured remote slave */ |
|
369 |
case LSS_INQ_VENDOR_ID: /* Inquire Identity Vendor-ID */ |
|
370 |
case LSS_INQ_PRODUCT_CODE: /* Inquire Identity Product-Code */ |
|
371 |
case LSS_INQ_REV_NUMBER: /* Inquire Identity Revision-Number */ |
|
372 |
case LSS_INQ_SERIAL_NUMBER: /* Inquire Identity Serial-Number */ |
|
373 |
case LSS_INQ_NODE_ID: /* Inquire Node-ID */ |
|
374 |
break; |
|
361 | 375 |
#ifdef CO_ENABLE_LSS_FS |
343 | 376 |
case LSS_IDENT_FASTSCAN: |
377 |
m.data[1]=(UNS8)(d->lss_transfer.IDNumber & 0xFF); |
|
378 |
m.data[2]=(UNS8)(d->lss_transfer.IDNumber>>8 & 0xFF); |
|
379 |
m.data[3]=(UNS8)(d->lss_transfer.IDNumber>>16 & 0xFF); |
|
380 |
m.data[4]=(UNS8)(d->lss_transfer.IDNumber>>24 & 0xFF); |
|
381 |
m.data[5]=d->lss_transfer.BitChecked; |
|
382 |
m.data[6]=d->lss_transfer.LSSSub; |
|
383 |
m.data[7]=d->lss_transfer.LSSNext; |
|
384 |
break; |
|
361 | 385 |
#endif |
343 | 386 |
default: |
361 | 387 |
MSG_ERR(0x1D0E, "send Master LSS command not implemented", command); |
343 | 388 |
return 0xFF; |
389 |
} |
|
390 |
||
391 |
return canSend(d->canHandle,&m); |
|
392 |
} |
|
393 |
||
394 |
/*! |
|
395 |
** |
|
396 |
** |
|
397 |
** @param d |
|
398 |
** @param cob_id |
|
399 |
** |
|
400 |
** @return |
|
401 |
**/ |
|
402 |
UNS8 sendLSS(CO_Data* d, UNS8 command,void *dat1,void *dat2) |
|
403 |
{ |
|
404 |
UNS8 res=1; |
|
405 |
||
406 |
/* Tha data sent with the msg depends on the command and if the sender is a master or a slave */ |
|
407 |
if (*(d->iam_a_slave)){ |
|
408 |
res = sendSlaveLSSMessage(d, command,dat1,dat2); |
|
409 |
} |
|
410 |
else {/* It is a Master */ |
|
411 |
res = sendMasterLSSMessage(d, command,dat1,dat2); |
|
412 |
} |
|
413 |
return res ; |
|
414 |
} |
|
415 |
||
416 |
||
417 |
/*! |
|
418 |
** |
|
419 |
** |
|
420 |
** @param d |
|
421 |
** @param m |
|
422 |
** |
|
423 |
** @return |
|
424 |
**/ |
|
425 |
UNS8 proceedLSS_Master(CO_Data* d, Message* m ) |
|
426 |
{ |
|
427 |
UNS8 msg_cs; |
|
428 |
UNS32 Dat1=0; |
|
429 |
UNS8 Dat2=0; |
|
430 |
||
361 | 431 |
if(d->lss_transfer.state!=LSS_TRANS_IN_PROGRESS) |
432 |
{ |
|
433 |
//MSG_WAR(0x3D0D, "MasterLSS proceedLSS; unexpected message arrived;command ", m->data[0]); |
|
434 |
//return 0; |
|
435 |
goto ErrorProcessMaster; |
|
436 |
} |
|
437 |
||
438 |
//#ifdef CO_ENABLE_LSS_FS |
|
439 |
/* The FastScan protocol doesn't stops the timers when a message has been received */ |
|
440 |
/*if(d->lss_transfer.command!=LSS_IDENT_FASTSCAN) |
|
441 |
#endif |
|
442 |
{ |
|
443 |
StopLSS_TIMER(LSS_MSG_TIMER); |
|
444 |
d->lss_transfer.state = LSS_FINISHED; |
|
445 |
}*/ |
|
446 |
||
447 |
MSG_WAR(0x3D0F, "MasterLSS proceedLSS; command ", m->data[0]); |
|
343 | 448 |
|
449 |
switch(msg_cs=m->data[0]){ |
|
450 |
case LSS_INQ_NODE_ID: /* Inquire Node-ID */ |
|
361 | 451 |
if(d->lss_transfer.command!=LSS_INQ_NODE_ID)goto ErrorProcessMaster; |
343 | 452 |
Dat1=m->data[1]; |
453 |
break; |
|
454 |
case LSS_CONF_NODE_ID: /* Configure Node-ID */ |
|
455 |
case LSS_CONF_BIT_TIMING: /* Configure Bit Timing Parameters */ |
|
456 |
case LSS_CONF_STORE: /* Store Configured Parameters */ |
|
361 | 457 |
if(d->lss_transfer.command!=msg_cs)goto ErrorProcessMaster; |
343 | 458 |
Dat1=m->data[1]; |
459 |
Dat2=m->data[2]; |
|
460 |
break; |
|
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 */ |
|
361 | 465 |
if(d->lss_transfer.command!=msg_cs)goto ErrorProcessMaster; |
343 | 466 |
Dat1=getLSSIdent(m); |
467 |
break; |
|
468 |
case LSS_IDENT_SLAVE: /* LSS Identify Slave */ |
|
361 | 469 |
#ifdef CO_ENABLE_LSS_FS |
470 |
if(d->lss_transfer.command==LSS_IDENT_FASTSCAN){ |
|
471 |
/* A message arrived during the timer period */ |
|
472 |
d->lss_transfer.LSSanswer=1; |
|
473 |
return 0; |
|
474 |
} |
|
475 |
else |
|
476 |
#endif |
|
477 |
if(d->lss_transfer.command!=LSS_IDENT_REMOTE_VENDOR && \ |
|
478 |
d->lss_transfer.command!=LSS_IDENT_REMOTE_PRODUCT && \ |
|
479 |
d->lss_transfer.command!=LSS_IDENT_REMOTE_REV_LOW && \ |
|
480 |
d->lss_transfer.command!=LSS_IDENT_REMOTE_REV_HIGH && \ |
|
481 |
d->lss_transfer.command!=LSS_IDENT_REMOTE_SERIAL_LOW && \ |
|
482 |
d->lss_transfer.command!=LSS_IDENT_REMOTE_SERIAL_HIGH ) |
|
483 |
goto ErrorProcessMaster; |
|
343 | 484 |
break; |
485 |
case LSS_SM_SELECTIVE_RESP: /* Switch Mode Selective response */ |
|
361 | 486 |
if(d->lss_transfer.command!=LSS_SM_SELECTIVE_VENDOR && \ |
487 |
d->lss_transfer.command!=LSS_SM_SELECTIVE_PRODUCT && \ |
|
488 |
d->lss_transfer.command!=LSS_SM_SELECTIVE_REVISION && \ |
|
489 |
d->lss_transfer.command!=LSS_SM_SELECTIVE_SERIAL ) |
|
490 |
goto ErrorProcessMaster; |
|
491 |
break; |
|
343 | 492 |
case LSS_IDENT_NON_CONF_SLAVE: /* LSS identify non-configured remote slave */ |
361 | 493 |
if(d->lss_transfer.command!=LSS_IDENT_REMOTE_NON_CONF)goto ErrorProcessMaster; |
343 | 494 |
break; |
495 |
default: |
|
361 | 496 |
MSG_ERR(0x1D10, "Master LSS command not implemented", msg_cs); |
343 | 497 |
return 0xFF; |
498 |
} |
|
361 | 499 |
|
500 |
StopLSS_TIMER(LSS_MSG_TIMER); |
|
501 |
d->lss_transfer.state = LSS_FINISHED; |
|
502 |
||
343 | 503 |
d->lss_transfer.dat1=Dat1; |
504 |
d->lss_transfer.dat2=Dat2; |
|
505 |
/* If there is a callback, it is responsible of the received response */ |
|
506 |
if(d->lss_transfer.Callback) |
|
361 | 507 |
(*d->lss_transfer.Callback)(d,d->lss_transfer.command); |
343 | 508 |
|
509 |
return 0; |
|
361 | 510 |
|
511 |
ErrorProcessMaster: |
|
512 |
MSG_WAR(0x3D11, "MasterLSS proceedLSS; unexpected message arrived;command ", m->data[0]); |
|
513 |
return 0xFF; |
|
514 |
||
343 | 515 |
} |
516 |
||
517 |
/*! |
|
518 |
** |
|
519 |
** |
|
520 |
** @param d |
|
521 |
** @param m |
|
522 |
** |
|
523 |
** @return |
|
524 |
**/ |
|
525 |
UNS8 proceedLSS_Slave(CO_Data* d, Message* m ) |
|
526 |
{ |
|
527 |
UNS8 msg_cs; |
|
528 |
||
361 | 529 |
MSG_WAR(0x3D12, "SlaveLSS proceedLSS; command ", m->data[0]); |
343 | 530 |
|
531 |
switch(msg_cs=m->data[0]){ |
|
532 |
case LSS_SM_GLOBAL: /* Switch Mode Global */ |
|
533 |
/* if there is not a mode change break*/ |
|
534 |
if(m->data[1] == d->lss_transfer.mode){ |
|
361 | 535 |
MSG_WAR(0x3D13, "SlaveLSS already in the mode ", m->data[1]); |
343 | 536 |
break; |
537 |
} |
|
538 |
||
539 |
if(m->data[1]==LSS_CONFIGURATION_MODE) { |
|
361 | 540 |
MSG_WAR(0x3D14, "SlaveLSS switching to configuration mode ", 0); |
343 | 541 |
/* Store the NodeId in case it will be changed */ |
542 |
d->lss_transfer.nodeID=getNodeId(d); |
|
543 |
d->lss_transfer.mode=LSS_CONFIGURATION_MODE; |
|
544 |
} |
|
545 |
else if(m->data[1]==LSS_WAITING_MODE){ |
|
361 | 546 |
MSG_WAR(0x3D15, "SlaveLSS switching to operational mode ", 0); |
343 | 547 |
|
548 |
if(d->lss_transfer.switchDelayState==SDELAY_OFF){ |
|
549 |
/* If the nodeID has changed update it and put the node state to Initialisation. */ |
|
550 |
if(d->lss_transfer.nodeID!=getNodeId(d)){ |
|
361 | 551 |
MSG_WAR(0x3D16, "The node Id has changed. Reseting to Initialisation state",0); |
343 | 552 |
setNodeId(d, d->lss_transfer.nodeID); |
553 |
setState(d, Initialisation); |
|
554 |
} |
|
555 |
} |
|
556 |
d->lss_transfer.mode=LSS_WAITING_MODE; |
|
557 |
} |
|
558 |
break; |
|
559 |
case LSS_CONF_NODE_ID: /* Configure Node-ID */ |
|
560 |
{ |
|
561 |
UNS8 error_code=0; |
|
562 |
UNS8 spec_error=0; |
|
563 |
||
564 |
if(d->lss_transfer.mode==LSS_CONFIGURATION_MODE){ |
|
565 |
if(m->data[1]>127 && m->data[1]!=0xFF){ |
|
361 | 566 |
MSG_ERR(0x1D17, "NodeID out of range",0); |
343 | 567 |
error_code=1; /* NodeID out of range */ |
568 |
} |
|
569 |
else{ |
|
570 |
d->lss_transfer.nodeID=m->data[1]; |
|
571 |
} |
|
572 |
} |
|
573 |
else{ |
|
361 | 574 |
MSG_WAR(0x3D18, "SlaveLSS not in configuration mode",0); |
575 |
//error_code=0xFF; |
|
576 |
break; |
|
343 | 577 |
} |
578 |
sendSlaveLSSMessage(d,msg_cs,&error_code,&spec_error); |
|
579 |
} |
|
580 |
break; |
|
581 |
case LSS_CONF_BIT_TIMING: /* Configure Bit Timing Parameters */ |
|
582 |
{ |
|
583 |
UNS8 error_code=0; |
|
584 |
UNS8 spec_error=0; |
|
585 |
||
586 |
if(d->lss_transfer.mode==LSS_CONFIGURATION_MODE){ |
|
587 |
/* Change the baud rate only if the function lss_ChangeBaudRate |
|
588 |
* has been implemented. If not send an error. |
|
589 |
*/ |
|
590 |
if(d->lss_ChangeBaudRate){ |
|
591 |
/* If a baud rate is not supported just comment the line. */ |
|
592 |
switch(m->data[2]){ |
|
593 |
case 0x00:d->lss_transfer.baudRate="1M";break; |
|
594 |
case 0x01:d->lss_transfer.baudRate="800K";break; |
|
595 |
case 0x02:d->lss_transfer.baudRate="500K";break; |
|
596 |
case 0x03:d->lss_transfer.baudRate="250K";break; |
|
597 |
case 0x04:d->lss_transfer.baudRate="125K";break; |
|
598 |
case 0x05:d->lss_transfer.baudRate="100K";break; |
|
599 |
case 0x06:d->lss_transfer.baudRate="50K";break; |
|
600 |
case 0x07:d->lss_transfer.baudRate="20K";break; |
|
601 |
case 0x08:d->lss_transfer.baudRate="10K";break; |
|
602 |
default: |
|
361 | 603 |
MSG_ERR(0x1D19, "Baud rate not supported",0); |
343 | 604 |
error_code=0xFF; /* Baud rate not supported*/ |
605 |
break; |
|
606 |
} |
|
607 |
} |
|
608 |
else |
|
609 |
{ |
|
361 | 610 |
MSG_ERR(0x1D1A, "Bit timing not supported",0); |
343 | 611 |
error_code=0x01; /* bit timing not supported */ |
612 |
} |
|
613 |
} |
|
614 |
else{ |
|
361 | 615 |
MSG_WAR(0x3D1B, "SlaveLSS not in configuration mode",0); |
616 |
//error_code=0xFF; |
|
617 |
break; |
|
343 | 618 |
} |
619 |
||
620 |
sendSlaveLSSMessage(d,msg_cs,&error_code,&spec_error); |
|
621 |
} |
|
622 |
break; |
|
623 |
case LSS_CONF_ACT_BIT_TIMING: /* Activate Bit Timing Parameters */ |
|
624 |
||
625 |
if(d->lss_transfer.mode!=LSS_CONFIGURATION_MODE){ |
|
361 | 626 |
MSG_ERR(0x3D1C, "SlaveLSS not in configuration mode",0); |
343 | 627 |
break; |
628 |
} |
|
629 |
||
630 |
if(d->lss_transfer.baudRate!="none"){ |
|
631 |
d->lss_transfer.switchDelay=getLSSDelay(m); |
|
361 | 632 |
MSG_WAR(0x3D1D, "Slave Switch Delay set to: ",d->lss_transfer.switchDelay); |
343 | 633 |
d->lss_transfer.switchDelayState=SDELAY_FIRST; |
634 |
d->lss_transfer.currentState=getState(d); |
|
635 |
setState(d, LssTimingDelay); |
|
636 |
StartLSS_SDELAY_TIMER(); |
|
637 |
} |
|
638 |
break; |
|
639 |
case LSS_CONF_STORE: /* Store Configured Parameters */ |
|
640 |
{ |
|
641 |
UNS8 error_code=0; |
|
642 |
UNS8 spec_error=0; |
|
643 |
||
644 |
if(d->lss_transfer.mode==LSS_CONFIGURATION_MODE){ |
|
645 |
if(d->lss_StoreConfiguration){ |
|
646 |
/* call lss_StoreConfiguration with NodeId */ |
|
647 |
(*d->lss_StoreConfiguration)(&error_code,&spec_error); |
|
648 |
} |
|
649 |
else{ |
|
361 | 650 |
MSG_ERR(0x1D1E, "Store configuration not supported",0); |
343 | 651 |
error_code=1; /* store configuration is not supported */ |
652 |
} |
|
653 |
} |
|
654 |
else{ |
|
361 | 655 |
MSG_WAR(0x3D1F, "SlaveLSS not in configuration mode",0); |
656 |
//error_code=0xFF; |
|
657 |
break; |
|
343 | 658 |
} |
659 |
sendSlaveLSSMessage(d,msg_cs,&error_code,&spec_error); |
|
660 |
} |
|
661 |
break; |
|
662 |
case LSS_SM_SELECTIVE_VENDOR: /* Switch Mode Selective */ |
|
663 |
case LSS_SM_SELECTIVE_PRODUCT: |
|
664 |
case LSS_SM_SELECTIVE_REVISION: |
|
665 |
case LSS_SM_SELECTIVE_SERIAL: |
|
666 |
{ |
|
667 |
UNS32 errorCode; |
|
668 |
const indextable *ptrTable; |
|
669 |
ODCallback_t *Callback; |
|
670 |
UNS32 _SpecificNodeInfo; |
|
671 |
||
672 |
if(d->lss_transfer.mode==LSS_CONFIGURATION_MODE) |
|
673 |
{ |
|
361 | 674 |
MSG_ERR(0x1D20, "Switch Mode Selective only supported in operational mode",0); |
343 | 675 |
break; |
676 |
} |
|
677 |
||
678 |
_SpecificNodeInfo=getLSSIdent(m); |
|
679 |
||
680 |
ptrTable = (*d->scanIndexOD)(0x1018, &errorCode, &Callback); |
|
681 |
if(_SpecificNodeInfo==*(UNS32*)ptrTable->pSubindex[msg_cs-(LSS_SM_SELECTIVE_VENDOR-1)].pObject){ |
|
682 |
||
683 |
d->lss_transfer.addr_sel_match|=(0x01<<(msg_cs-LSS_SM_SELECTIVE_VENDOR)); |
|
684 |
/* If all the fields has been set */ |
|
685 |
if(d->lss_transfer.addr_sel_match==0x0F){ |
|
686 |
||
361 | 687 |
MSG_WAR(0x3D21, "SlaveLSS switching to configuration mode ", 0); |
343 | 688 |
d->lss_transfer.addr_sel_match=0; |
689 |
d->lss_transfer.nodeID=getNodeId(d); |
|
690 |
d->lss_transfer.mode=LSS_CONFIGURATION_MODE; |
|
691 |
||
692 |
sendSlaveLSSMessage(d,LSS_SM_SELECTIVE_RESP,0,0); |
|
693 |
} |
|
694 |
} |
|
695 |
else { |
|
361 | 696 |
MSG_WAR(0x3D22, "LSS identity field doesn't match ", _SpecificNodeInfo); |
343 | 697 |
d->lss_transfer.addr_sel_match=0; |
698 |
} |
|
699 |
} |
|
700 |
break; |
|
701 |
case LSS_IDENT_REMOTE_VENDOR: /* LSS Identify Remote Slaves */ |
|
702 |
case LSS_IDENT_REMOTE_PRODUCT: |
|
703 |
case LSS_IDENT_REMOTE_REV_LOW: |
|
704 |
case LSS_IDENT_REMOTE_REV_HIGH: |
|
705 |
case LSS_IDENT_REMOTE_SERIAL_LOW: |
|
706 |
case LSS_IDENT_REMOTE_SERIAL_HIGH: |
|
707 |
{ |
|
708 |
UNS32 errorCode; |
|
709 |
const indextable *ptrTable; |
|
710 |
ODCallback_t *Callback; |
|
711 |
UNS32 _SpecificNodeInfo; |
|
712 |
||
713 |
_SpecificNodeInfo=getLSSIdent(m); |
|
714 |
||
715 |
ptrTable = (*d->scanIndexOD)(0x1018, &errorCode, &Callback); |
|
716 |
||
717 |
/* Check if the data match the identity object. */ |
|
718 |
switch(msg_cs){ |
|
719 |
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; |
|
720 |
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; |
|
721 |
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; |
|
722 |
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; |
|
723 |
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; |
|
724 |
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; |
|
725 |
} |
|
726 |
/* If all the fields has been set.. */ |
|
727 |
if(d->lss_transfer.addr_ident_match==0x3F){ |
|
361 | 728 |
MSG_WAR(0x3D23, "SlaveLSS identified ", 0); |
343 | 729 |
d->lss_transfer.addr_ident_match=0; |
730 |
sendSlaveLSSMessage(d,LSS_IDENT_SLAVE,0,0); |
|
731 |
} |
|
732 |
else if(d->lss_transfer.addr_ident_match==0){ |
|
361 | 733 |
MSG_WAR(0x3D24, "LSS identify field doesn't match ", _SpecificNodeInfo); |
343 | 734 |
} |
735 |
} |
|
736 |
break; |
|
737 |
case LSS_IDENT_REMOTE_NON_CONF: /* LSS identify non-configured remote slave */ |
|
738 |
{ |
|
739 |
if(getNodeId(d)==0xFF){ |
|
361 | 740 |
MSG_WAR(0x3D25, "SlaveLSS non-configured ", 0); |
343 | 741 |
sendSlaveLSSMessage(d,LSS_IDENT_NON_CONF_SLAVE,0,0); |
742 |
} |
|
743 |
else{ |
|
361 | 744 |
MSG_WAR(0x3D26, "SlaveLSS already configured ", 0); |
343 | 745 |
} |
746 |
} |
|
747 |
break; |
|
748 |
case LSS_INQ_VENDOR_ID: /* Inquire Identity Vendor-ID */ |
|
749 |
case LSS_INQ_PRODUCT_CODE: /* Inquire Identity Product-Code */ |
|
750 |
case LSS_INQ_REV_NUMBER: /* Inquire Identity Revision-Number */ |
|
751 |
case LSS_INQ_SERIAL_NUMBER: /* Inquire Identity Serial-Number */ |
|
752 |
if(d->lss_transfer.mode==LSS_CONFIGURATION_MODE) |
|
753 |
{ |
|
754 |
||
755 |
UNS32 errorCode; |
|
756 |
const indextable *ptrTable; |
|
757 |
ODCallback_t *Callback; |
|
758 |
UNS32 _SpecificNodeInfo; |
|
759 |
||
760 |
ptrTable = (*d->scanIndexOD)(0x1018, &errorCode, &Callback); |
|
761 |
_SpecificNodeInfo=*(UNS32*)ptrTable->pSubindex[msg_cs-(LSS_INQ_VENDOR_ID-1)].pObject; |
|
361 | 762 |
MSG_WAR(0x3D27, "SlaveLSS identity field inquired ", _SpecificNodeInfo); |
343 | 763 |
|
764 |
sendSlaveLSSMessage(d,msg_cs,&_SpecificNodeInfo,0); |
|
765 |
} |
|
766 |
break; |
|
767 |
case LSS_INQ_NODE_ID: /* Inquire Node-ID */ |
|
768 |
if(d->lss_transfer.mode==LSS_CONFIGURATION_MODE) |
|
769 |
{ |
|
770 |
UNS8 NodeID; |
|
771 |
||
772 |
NodeID=getNodeId(d); |
|
361 | 773 |
MSG_WAR(0x3D28, "SlaveLSS Node ID inquired ", NodeID); |
343 | 774 |
sendSlaveLSSMessage(d,msg_cs,&NodeID,0); |
775 |
} |
|
776 |
else{ |
|
361 | 777 |
MSG_WAR(0x3D29, "SlaveLSS not in configuration mode",0); |
778 |
} |
|
779 |
break; |
|
780 |
#ifdef CO_ENABLE_LSS_FS |
|
343 | 781 |
case LSS_IDENT_FASTSCAN: |
782 |
{ |
|
361 | 783 |
/* If the nodeID isn't 0xFF the slave shall not participate */ |
784 |
if(getNodeId(d)!=0xFF)break; |
|
785 |
if(getLSSBitCheck(m)==128)d->lss_transfer.FastScan_SM=LSS_FS_RESET; |
|
786 |
||
787 |
switch(d->lss_transfer.FastScan_SM){ |
|
788 |
case LSS_FS_RESET: |
|
789 |
{ |
|
790 |
UNS32 errorCode; |
|
791 |
const indextable *ptrTable; |
|
792 |
ODCallback_t *Callback; |
|
793 |
||
794 |
MSG_WAR(0x3D2A, "SlaveLSS Reseting LSSPos", 0); |
|
795 |
d->lss_transfer.LSSPos=0; |
|
796 |
d->lss_transfer.FastScan_SM=LSS_FS_PROCESSING; |
|
797 |
||
798 |
ptrTable = (*d->scanIndexOD)(0x1018, &errorCode, &Callback); |
|
799 |
d->lss_transfer.IDNumber=*(UNS32*)ptrTable->pSubindex[d->lss_transfer.LSSPos+1].pObject; |
|
800 |
||
801 |
sendSlaveLSSMessage(d,LSS_IDENT_SLAVE,0,0); |
|
802 |
} |
|
803 |
break; |
|
804 |
case LSS_FS_PROCESSING:/*if(getLSSBitCheck(m)<32)*/ |
|
805 |
if(d->lss_transfer.LSSPos==getLSSSub(m)) |
|
806 |
{ |
|
807 |
UNS32 Mask=0xFFFFFFFF<<getLSSBitCheck(m); |
|
808 |
||
809 |
MSG_WAR(0x3D2B, "SlaveLSS FastScan IDNumber", getLSSIdent(m)); |
|
810 |
MSG_WAR(0x3D2C, "SlaveLSS FastScan BitMask ", Mask); |
|
811 |
MSG_WAR(0x3D2D, "SlaveLSS FastScan LSS-ID ", d->lss_transfer.IDNumber); |
|
812 |
||
813 |
if((getLSSIdent(m) & Mask)==(d->lss_transfer.IDNumber & Mask)) |
|
814 |
{ |
|
815 |
sendSlaveLSSMessage(d,LSS_IDENT_SLAVE,0,0); |
|
816 |
} |
|
817 |
||
818 |
if(getLSSBitCheck(m)==0) |
|
819 |
{ |
|
820 |
d->lss_transfer.FastScan_SM=LSS_FS_CONFIRMATION; |
|
821 |
} |
|
822 |
} |
|
823 |
break; |
|
824 |
case LSS_FS_CONFIRMATION: |
|
825 |
if(d->lss_transfer.LSSPos==getLSSSub(m)) |
|
826 |
{ |
|
827 |
if(getLSSIdent(m)==d->lss_transfer.IDNumber) |
|
828 |
{ |
|
829 |
/* Current LSS-ID[sub] confirmed correctly */ |
|
830 |
MSG_WAR(0x3D2E, "SlaveLSS FastScan IDNumber and LSS-ID match=>", d->lss_transfer.IDNumber); |
|
831 |
if(d->lss_transfer.LSSPos==3) |
|
832 |
{ |
|
833 |
/* All LSS-ID[sub] identified correctly, switching to configuration mode */ |
|
834 |
MSG_WAR(0x3D2F, "SlaveLSS switching to configuration mode ", 0); |
|
835 |
d->lss_transfer.nodeID=getNodeId(d); |
|
836 |
d->lss_transfer.mode=LSS_CONFIGURATION_MODE; |
|
837 |
d->lss_transfer.FastScan_SM=LSS_FS_RESET; |
|
838 |
d->lss_transfer.LSSPos=0xFF; |
|
839 |
} |
|
840 |
else |
|
841 |
{ |
|
842 |
/* Switch to the next LSS-ID[sub] */ |
|
843 |
UNS32 errorCode; |
|
844 |
const indextable *ptrTable; |
|
845 |
ODCallback_t *Callback; |
|
846 |
||
847 |
d->lss_transfer.LSSPos=getLSSNext(m); |
|
848 |
ptrTable = (*d->scanIndexOD)(0x1018, &errorCode, &Callback); |
|
849 |
d->lss_transfer.IDNumber=*(UNS32*)ptrTable->pSubindex[d->lss_transfer.LSSPos+1].pObject; |
|
850 |
d->lss_transfer.FastScan_SM=LSS_FS_PROCESSING; |
|
851 |
} |
|
852 |
sendSlaveLSSMessage(d,LSS_IDENT_SLAVE,0,0); |
|
853 |
} |
|
854 |
} |
|
855 |
break; |
|
856 |
} |
|
343 | 857 |
} |
858 |
break; |
|
361 | 859 |
#endif |
343 | 860 |
default: |
361 | 861 |
MSG_ERR(0x1D30, "SlaveLSS command not implemented", msg_cs); |
343 | 862 |
return 0xFF; |
863 |
} |
|
864 |
||
865 |
return 0; |
|
866 |
} |
|
867 |
||
868 |
UNS8 configNetworkNode(CO_Data* d, UNS8 command, void *dat1, void* dat2) |
|
869 |
{ |
|
870 |
return sendMasterLSSMessage(d,command,dat1,dat2); |
|
871 |
} |
|
872 |
||
873 |
UNS8 configNetworkNodeCallBack (CO_Data* d, UNS8 command, void *dat1, void* dat2, LSSCallback_t Callback) |
|
874 |
{ |
|
875 |
d->lss_transfer.state=LSS_TRANS_IN_PROGRESS; |
|
876 |
d->lss_transfer.Callback=Callback; |
|
877 |
d->lss_transfer.command=command; |
|
878 |
||
879 |
StopLSS_TIMER(LSS_MSG_TIMER); |
|
880 |
StartLSS_MSG_TIMER(); |
|
881 |
||
882 |
return sendMasterLSSMessage(d,command,dat1,dat2); |
|
883 |
} |
|
884 |
||
885 |
UNS8 getConfigResultNetworkNode (CO_Data* d, UNS8 command, UNS32* dat1, UNS8* dat2) |
|
886 |
{ |
|
887 |
*dat1=d->lss_transfer.dat1; |
|
888 |
*dat2=d->lss_transfer.dat2; |
|
889 |
return d->lss_transfer.state; |
|
890 |
} |
|
891 |
||
892 |
//void _lss_StoreConfiguration(UNS8 *error, UNS8 *spec_error){printf("_lss_StoreConfiguration\n");} |
|
893 |
//void _lss_ChangeBaudRate(char *BaudRate){printf("_lss_ChangeBaudRate\n");} |
|
894 |
||
895 |
#endif |