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