60 |
60 |
61 /* Returns the LSS FastScan LSSNext field from a Message struct */ |
61 /* Returns the LSS FastScan LSSNext field from a Message struct */ |
62 #define getLSSNext(msg) msg->data[7] |
62 #define getLSSNext(msg) msg->data[7] |
63 |
63 |
64 /* Prototypes for internals functions */ |
64 /* Prototypes for internals functions */ |
65 void LssAlarm(CO_Data* d, UNS32 id); |
65 UNS8 sendMasterLSSMessage(CO_Data* d, UNS8 command,void *dat1,void *dat2); |
66 |
66 void LssAlarmMSG(CO_Data* d, UNS32 id); |
67 #define StopLSS_TIMER(id){\ |
67 void LssAlarmSDELAY(CO_Data* d, UNS32 id); |
68 MSG_WAR(0x3D01, "StopLSS_TIMER for timer : ", id);\ |
68 |
69 d->lss_transfer.timers[id] = DelAlarm(d->lss_transfer.timers[id]);} |
69 |
|
70 #define StopLSS_MSG_TIMER(){\ |
|
71 MSG_WAR(0x3D01, "StopLSS_MSG_TIMER", 0);\ |
|
72 d->lss_transfer.timerMSG = DelAlarm(d->lss_transfer.timerMSG);} |
70 |
73 |
71 #define StartLSS_MSG_TIMER(){\ |
74 #define StartLSS_MSG_TIMER(){\ |
72 MSG_WAR(0x3D02, "StartLSS_TIMER for MSG_TIMER",0);\ |
75 MSG_WAR(0x3D02, "StartLSS_MSG_TIMER",0);\ |
73 d->lss_transfer.timers[LSS_MSG_TIMER] = SetAlarm(d,LSS_MSG_TIMER,&LssAlarm,MS_TO_TIMEVAL(LSS_TIMEOUT_MS),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);} |
74 |
81 |
75 #define StartLSS_SDELAY_TIMER(){\ |
82 #define StartLSS_SDELAY_TIMER(){\ |
76 MSG_WAR(0x3D03, "StartLSS_TIMER for SDELAY_TIMER",0);\ |
83 MSG_WAR(0x3D04, "StartLSS_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));} |
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);} |
78 |
94 |
79 #define StartLSS_FS_TIMER(){\ |
95 #define StartLSS_FS_TIMER(){\ |
80 MSG_WAR(0x3D04, "StartLSS_TIMER for FS_TIMER",0);\ |
96 MSG_WAR(0x3D06, "StartLSS_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);} |
97 d->lss_transfer.timerFS = SetAlarm(d,0,&LssAlarmFS,MS_TO_TIMEVAL(LSS_FS_TIMEOUT_MS),0);} |
82 |
98 #endif |
83 UNS8 sendMasterLSSMessage(CO_Data* d, UNS8 command,void *dat1,void *dat2); |
99 |
84 |
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 |
85 /*! |
151 /*! |
86 ** |
152 ** |
87 ** |
153 ** |
88 ** @param d |
154 ** @param d |
89 ** @param id |
155 ** @param id |
90 **/ |
156 **/ |
91 //struct timeval current_time,init_time; |
157 void LssAlarmSDELAY(CO_Data* d, UNS32 id) |
92 void LssAlarm(CO_Data* d, UNS32 id) |
|
93 { |
158 { |
94 /*unsigned long time_period; |
159 |
95 |
160 /* The first switch_delay period expired. Store the node state, change it |
96 gettimeofday(¤t_time,NULL); |
161 * so no CAN messages will be sent or received, call the ChangeBaudRate function*/ |
97 time_period=(current_time.tv_sec - init_time.tv_sec)* 1000000 + current_time.tv_usec - init_time.tv_usec; |
162 if(d->lss_transfer.switchDelayState==SDELAY_FIRST){ |
98 printf("%3ld.%3ld.%3ld --",time_period/1000000,(time_period%1000000)/1000,time_period%1000);*/ |
163 MSG_WAR(0x3D0B, "LSS switch delay first period expired",0); |
99 |
164 d->lss_transfer.switchDelayState=SDELAY_SECOND; |
100 switch(id){ |
165 (*d->lss_ChangeBaudRate)(d,d->lss_transfer.baudRate); |
101 case LSS_MSG_TIMER: |
166 } |
102 StopLSS_TIMER(LSS_MSG_TIMER); |
167 else{ /* d->lss_transfer.switchDelayState==SDELAY_SECOND */ |
|
168 MSG_WAR(0x3D0C, "LSS switch delay second period expired",0); |
|
169 d->lss_transfer.switchDelayState=SDELAY_OFF; |
|
170 StopLSS_SDELAY_TIMER(); |
|
171 |
|
172 if (*(d->iam_a_slave)) |
|
173 d->canHandle=d->lss_transfer.canHandle_t; |
|
174 else{ |
|
175 d->lss_transfer.dat1=0; |
|
176 d->lss_transfer.state=LSS_FINISHED; |
|
177 /* Call the user function */ |
|
178 if(d->lss_transfer.Callback){ |
|
179 (*d->lss_transfer.Callback)(d,d->lss_transfer.command); |
|
180 } |
|
181 } |
|
182 } |
|
183 } |
|
184 |
103 #ifdef CO_ENABLE_LSS_FS |
185 #ifdef CO_ENABLE_LSS_FS |
104 if(d->lss_transfer.command==LSS_IDENT_FASTSCAN){ |
186 /*! |
105 if(d->lss_transfer.FastScan_SM==LSS_FS_RESET){ |
187 ** |
106 /* if at least one node had answered before the timer expired, start the FastScan protocol*/ |
188 ** |
107 if(d->lss_transfer.LSSanswer!=0){ |
189 ** @param d |
108 d->lss_transfer.LSSanswer=0; |
190 ** @param id |
109 d->lss_transfer.BitChecked=31; |
191 **/ |
110 d->lss_transfer.IDNumber=0; |
192 void LssAlarmFS(CO_Data* d, UNS32 id) |
111 d->lss_transfer.FastScan_SM=LSS_FS_PROCESSING; |
193 { |
112 StartLSS_FS_TIMER(); |
194 StopLSS_FS_TIMER(); |
113 sendMasterLSSMessage(d,LSS_IDENT_FASTSCAN,0,0); |
195 |
114 return; |
196 switch(d->lss_transfer.FastScan_SM){ |
115 } |
197 case LSS_FS_RESET: |
116 else{ |
198 { |
117 |
199 /* This should not happen, an error ocurred*/ |
118 d->lss_transfer.state = LSS_FINISHED; |
200 MSG_ERR(0x1D0D, "LSS FastScan timeout. FastScan_SM inconsisten state.", d->lss_transfer.FastScan_SM); |
119 /* Inform the application that there aren't not configured nodes in the net */ |
201 } |
120 d->lss_transfer.dat1=1; |
202 break; |
121 } |
203 case LSS_FS_PROCESSING: |
122 } |
204 { |
123 else{ |
205 /* If there isn't any answer, set the bit */ |
124 /* This should not happen, an error ocurred*/ |
206 if(d->lss_transfer.LSSanswer==0){ |
125 MSG_ERR(0x1D05, "LSS FastScan timeout. FastScan_SM inconsisten state.", d->lss_transfer.FastScan_SM); |
207 UNS32 Mask=0x1; |
126 } |
208 Mask<<=d->lss_transfer.BitChecked; |
127 } |
209 d->lss_transfer.IDNumber|=Mask; |
128 else |
210 } |
|
211 |
|
212 if(d->lss_transfer.BitChecked==0){ |
|
213 /* We finished with the current LSS-ID[sub], confirm it */ |
|
214 d->lss_transfer.FastScan_SM=LSS_FS_CONFIRMATION; |
|
215 if(d->lss_transfer.LSSNext<3)d->lss_transfer.LSSNext++; |
|
216 } |
|
217 else{ |
|
218 d->lss_transfer.BitChecked--; |
|
219 } |
|
220 |
|
221 d->lss_transfer.LSSanswer=0; |
|
222 StartLSS_FS_TIMER(); |
|
223 sendMasterLSSMessage(d,LSS_IDENT_FASTSCAN,0,0); |
|
224 return; |
|
225 } |
|
226 break; |
|
227 case LSS_FS_CONFIRMATION: |
|
228 { |
|
229 if(d->lss_transfer.LSSanswer!=0){ |
|
230 d->lss_transfer.LSSanswer=0; |
|
231 |
|
232 if(d->lss_transfer.LSSSub==3){ |
|
233 /* The LSS FastScan protocol finished correctly. Restore the parameters */ |
|
234 d->lss_transfer.BitChecked=128; |
|
235 d->lss_transfer.FastScan_SM=LSS_FS_RESET; |
|
236 d->lss_transfer.LSSSub=0; |
|
237 d->lss_transfer.LSSNext=0; |
|
238 d->lss_transfer.IDNumber=0; |
|
239 |
|
240 /* Inform the application that the FastScan finished correctly */ |
|
241 d->lss_transfer.state = LSS_FINISHED; |
|
242 d->lss_transfer.dat1=0; |
|
243 } |
|
244 else{ |
|
245 /* Start with the next LSS-ID[sub] */ |
|
246 d->lss_transfer.LSSSub++; |
|
247 d->lss_transfer.BitChecked=31; |
|
248 d->lss_transfer.IDNumber=0; |
|
249 d->lss_transfer.FastScan_SM=LSS_FS_PROCESSING; |
|
250 StartLSS_FS_TIMER(); |
|
251 sendMasterLSSMessage(d,LSS_IDENT_FASTSCAN,0,0); |
|
252 return; |
|
253 } |
|
254 } |
|
255 else{ |
|
256 /* This should not happen, an error ocurred*/ |
|
257 MSG_ERR(0x1D0E, "LSS FastScan timeout. FastScan response not received.", 0); |
|
258 /* Set aborted state */ |
|
259 d->lss_transfer.state = LSS_ABORTED_INTERNAL; |
|
260 } |
|
261 } |
|
262 break; |
|
263 } |
|
264 |
|
265 /* Call the user function to inform of the problem.*/ |
|
266 if(d->lss_transfer.Callback){ |
|
267 /*If there is a callback, it is responsible of the error*/ |
|
268 (*d->lss_transfer.Callback)(d,d->lss_transfer.command); |
|
269 } |
|
270 } |
129 #endif |
271 #endif |
130 { |
272 |
131 MSG_ERR(0x1D06, "LSS timeout. LSS response not received.", 0); |
273 |
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 |
|
137 /* Call the user function to inform of the problem.*/ |
|
138 if(d->lss_transfer.Callback){ |
|
139 /*If there is a callback, it is responsible of the error*/ |
|
140 (*d->lss_transfer.Callback)(d,d->lss_transfer.command); |
|
141 } |
|
142 break; |
|
143 case LSS_SWITCH_DELAY_TIMER: |
|
144 /* The first switch_delay period expired. Store the node state, change it |
|
145 * so no CAN messages will be sent or received, call the ChangeBaudRate function*/ |
|
146 if(d->lss_transfer.switchDelayState==SDELAY_FIRST){ |
|
147 MSG_WAR(0x3D08, "LSS switch delay first period expired",0); |
|
148 d->lss_transfer.switchDelayState=SDELAY_SECOND; |
|
149 (*d->lss_ChangeBaudRate)(d->lss_transfer.baudRate); |
|
150 } |
|
151 else{ /* d->lss_transfer.switchDelayState==SDELAY_SECOND */ |
|
152 MSG_WAR(0x3D09, "LSS switch delay second period expired",0); |
|
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; |
|
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 |
|
239 } |
|
240 } |
|
241 |
|
242 /*! |
274 /*! |
243 ** |
275 ** |
244 ** |
276 ** |
245 ** @param d |
277 ** @param d |
246 **/ |
278 **/ |
325 **/ |
357 **/ |
326 UNS8 sendMasterLSSMessage(CO_Data* d, UNS8 command,void *dat1,void *dat2) |
358 UNS8 sendMasterLSSMessage(CO_Data* d, UNS8 command,void *dat1,void *dat2) |
327 { |
359 { |
328 Message m; |
360 Message m; |
329 UNS8 i; |
361 UNS8 i; |
330 |
362 UNS8 res; |
|
363 UNS8 hasResponse=0; |
|
364 |
331 for(i=1;i<8;i++)m.data[i]=0; |
365 for(i=1;i<8;i++)m.data[i]=0; |
332 m.len = 8; |
366 m.len = 8; |
333 m.rtr = NOT_A_REQUEST; |
367 m.rtr = NOT_A_REQUEST; |
334 m.data[0]=command; |
368 m.data[0]=command; |
335 m.cob_id=UNS16_LE(MLSS_ADRESS); |
369 m.cob_id=UNS16_LE(MLSS_ADRESS); |
336 |
370 |
337 /* Tha data sent with the msg depends on the command */ |
371 /* Tha data sent with the msg depends on the command */ |
338 switch(command){ |
372 switch(command){ |
|
373 case LSS_CONF_NODE_ID: /* Configure Node-ID */ |
|
374 hasResponse=1; |
339 case LSS_SM_GLOBAL: /* Switch Mode Global */ |
375 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; |
376 m.data[1]=*(UNS8 *)dat1; |
343 break; |
377 break; |
344 case LSS_CONF_BIT_TIMING: /* Configure Bit Timing Parameters */ |
378 case LSS_CONF_BIT_TIMING: /* Configure Bit Timing Parameters */ |
345 m.data[1]=*(UNS8 *)dat1; |
379 m.data[1]=*(UNS8 *)dat1; |
346 m.data[2]=*(UNS8 *)dat2; |
380 m.data[2]=*(UNS8 *)dat2; |
|
381 if(d->lss_ChangeBaudRate){ |
|
382 /* If a baud rate is not supported just comment the line. */ |
|
383 switch(m.data[2]){ |
|
384 case 0x00:d->lss_transfer.baudRate="1M";break; |
|
385 case 0x01:d->lss_transfer.baudRate="800K";break; |
|
386 case 0x02:d->lss_transfer.baudRate="500K";break; |
|
387 case 0x03:d->lss_transfer.baudRate="250K";break; |
|
388 case 0x04:d->lss_transfer.baudRate="125K";break; |
|
389 case 0x05:d->lss_transfer.baudRate="100K";break; |
|
390 case 0x06:d->lss_transfer.baudRate="50K";break; |
|
391 case 0x07:d->lss_transfer.baudRate="20K";break; |
|
392 case 0x08:d->lss_transfer.baudRate="10K";break; |
|
393 default: |
|
394 MSG_ERR(0x1D19, "Master-> Baud rate not supported",0); |
|
395 d->lss_transfer.dat1=0xFF; |
|
396 goto ErrorBitRateMaster; |
|
397 break; |
|
398 } |
|
399 hasResponse=1; |
|
400 break; |
|
401 } |
|
402 else{ |
|
403 MSG_ERR(0x1D1A, "Master-> Bit timing not supported",0); |
|
404 d->lss_transfer.dat1=0x01; |
|
405 } |
|
406 |
|
407 ErrorBitRateMaster: |
|
408 d->lss_transfer.dat2=0; |
|
409 /* If there is a callback, it is responsible of the error */ |
|
410 if(d->lss_transfer.Callback) |
|
411 (*d->lss_transfer.Callback)(d,d->lss_transfer.command); |
|
412 return 0xFF; |
347 break; |
413 break; |
348 case LSS_CONF_ACT_BIT_TIMING: /* Activate Bit Timing Parameters */ |
414 case LSS_CONF_ACT_BIT_TIMING: /* Activate Bit Timing Parameters */ |
349 m.data[1]=(UNS8)(*(UNS32*)dat1 & 0xFF); |
415 m.data[1]=(UNS8)(*(UNS32*)dat1 & 0xFF); |
350 m.data[2]=(UNS8)(*(UNS32*)dat1>>8 & 0xFF); |
416 m.data[2]=(UNS8)(*(UNS32*)dat1>>8 & 0xFF); |
|
417 if(d->lss_transfer.baudRate!="none"){ |
|
418 d->lss_transfer.switchDelay=(UNS16)(*(UNS32*)dat1 & 0xFFFF); |
|
419 d->lss_transfer.switchDelayState=SDELAY_FIRST; |
|
420 res=canSend(d->canHandle,&m); |
|
421 if(res==0){ |
|
422 StartLSS_SDELAY_TIMER(); |
|
423 d->lss_transfer.state=LSS_TRANS_IN_PROGRESS; |
|
424 } |
|
425 return res; |
|
426 } |
|
427 else{ |
|
428 MSG_ERR(0x1D1B, "Master-> Baud rate not specified",0); |
|
429 d->lss_transfer.dat1=1; |
|
430 /* If there is a callback, it is responsible of the error */ |
|
431 if(d->lss_transfer.Callback){ |
|
432 (*d->lss_transfer.Callback)(d,d->lss_transfer.command); |
|
433 } |
|
434 return 0xFF; |
|
435 } |
351 break; |
436 break; |
|
437 case LSS_SM_SELECTIVE_SERIAL: |
|
438 case LSS_IDENT_REMOTE_SERIAL_HIGH: |
|
439 hasResponse=1; |
352 case LSS_SM_SELECTIVE_VENDOR: /* Switch Mode Selective */ |
440 case LSS_SM_SELECTIVE_VENDOR: /* Switch Mode Selective */ |
353 case LSS_SM_SELECTIVE_PRODUCT: |
441 case LSS_SM_SELECTIVE_PRODUCT: |
354 case LSS_SM_SELECTIVE_REVISION: |
442 case LSS_SM_SELECTIVE_REVISION: |
355 case LSS_SM_SELECTIVE_SERIAL: |
|
356 case LSS_IDENT_REMOTE_VENDOR: /* LSS Identify Remote Slaves */ |
443 case LSS_IDENT_REMOTE_VENDOR: /* LSS Identify Remote Slaves */ |
357 case LSS_IDENT_REMOTE_PRODUCT: |
444 case LSS_IDENT_REMOTE_PRODUCT: |
358 case LSS_IDENT_REMOTE_REV_LOW: |
445 case LSS_IDENT_REMOTE_REV_LOW: |
359 case LSS_IDENT_REMOTE_REV_HIGH: |
446 case LSS_IDENT_REMOTE_REV_HIGH: |
360 case LSS_IDENT_REMOTE_SERIAL_LOW: |
447 case LSS_IDENT_REMOTE_SERIAL_LOW: |
361 case LSS_IDENT_REMOTE_SERIAL_HIGH: |
|
362 m.data[1]=(UNS8)(*(UNS32*)dat1 & 0xFF); |
448 m.data[1]=(UNS8)(*(UNS32*)dat1 & 0xFF); |
363 m.data[2]=(UNS8)(*(UNS32*)dat1>>8 & 0xFF); |
449 m.data[2]=(UNS8)(*(UNS32*)dat1>>8 & 0xFF); |
364 m.data[3]=(UNS8)(*(UNS32*)dat1>>16 & 0xFF); |
450 m.data[3]=(UNS8)(*(UNS32*)dat1>>16 & 0xFF); |
365 m.data[4]=(UNS8)(*(UNS32*)dat1>>24 & 0xFF); |
451 m.data[4]=(UNS8)(*(UNS32*)dat1>>24 & 0xFF); |
366 break; |
452 break; |
|
453 |
367 case LSS_CONF_STORE: /* Store Configured Parameters */ |
454 case LSS_CONF_STORE: /* Store Configured Parameters */ |
368 case LSS_IDENT_REMOTE_NON_CONF: /* LSS identify non-configured remote slave */ |
455 case LSS_IDENT_REMOTE_NON_CONF: /* LSS identify non-configured remote slave */ |
369 case LSS_INQ_VENDOR_ID: /* Inquire Identity Vendor-ID */ |
456 case LSS_INQ_VENDOR_ID: /* Inquire Identity Vendor-ID */ |
370 case LSS_INQ_PRODUCT_CODE: /* Inquire Identity Product-Code */ |
457 case LSS_INQ_PRODUCT_CODE: /* Inquire Identity Product-Code */ |
371 case LSS_INQ_REV_NUMBER: /* Inquire Identity Revision-Number */ |
458 case LSS_INQ_REV_NUMBER: /* Inquire Identity Revision-Number */ |
372 case LSS_INQ_SERIAL_NUMBER: /* Inquire Identity Serial-Number */ |
459 case LSS_INQ_SERIAL_NUMBER: /* Inquire Identity Serial-Number */ |
373 case LSS_INQ_NODE_ID: /* Inquire Node-ID */ |
460 case LSS_INQ_NODE_ID: /* Inquire Node-ID */ |
|
461 hasResponse=1; |
374 break; |
462 break; |
375 #ifdef CO_ENABLE_LSS_FS |
463 #ifdef CO_ENABLE_LSS_FS |
376 case LSS_IDENT_FASTSCAN: |
464 case LSS_IDENT_FASTSCAN: |
377 m.data[1]=(UNS8)(d->lss_transfer.IDNumber & 0xFF); |
465 m.data[1]=(UNS8)(d->lss_transfer.IDNumber & 0xFF); |
378 m.data[2]=(UNS8)(d->lss_transfer.IDNumber>>8 & 0xFF); |
466 m.data[2]=(UNS8)(d->lss_transfer.IDNumber>>8 & 0xFF); |
379 m.data[3]=(UNS8)(d->lss_transfer.IDNumber>>16 & 0xFF); |
467 m.data[3]=(UNS8)(d->lss_transfer.IDNumber>>16 & 0xFF); |
380 m.data[4]=(UNS8)(d->lss_transfer.IDNumber>>24 & 0xFF); |
468 m.data[4]=(UNS8)(d->lss_transfer.IDNumber>>24 & 0xFF); |
381 m.data[5]=d->lss_transfer.BitChecked; |
469 m.data[5]=d->lss_transfer.BitChecked; |
382 m.data[6]=d->lss_transfer.LSSSub; |
470 m.data[6]=d->lss_transfer.LSSSub; |
383 m.data[7]=d->lss_transfer.LSSNext; |
471 m.data[7]=d->lss_transfer.LSSNext; |
|
472 /* it will generate a response only if it is the start of the FastScan protocol*/ |
|
473 if(d->lss_transfer.FastScan_SM==LSS_FS_RESET)hasResponse=1; |
384 break; |
474 break; |
385 #endif |
475 #endif |
386 default: |
476 default: |
387 MSG_ERR(0x1D0E, "send Master LSS command not implemented", command); |
477 MSG_ERR(0x1D1C, "send Master LSS command not implemented", command); |
388 return 0xFF; |
478 return 0xFF; |
389 } |
479 } |
390 |
480 |
391 return canSend(d->canHandle,&m); |
481 res=canSend(d->canHandle,&m); |
|
482 if(res==0 && hasResponse==1){ |
|
483 StartLSS_MSG_TIMER(); |
|
484 d->lss_transfer.state=LSS_TRANS_IN_PROGRESS; |
|
485 } |
|
486 return res; |
392 } |
487 } |
393 |
488 |
394 /*! |
489 /*! |
395 ** |
490 ** |
396 ** |
491 ** |
524 **/ |
610 **/ |
525 UNS8 proceedLSS_Slave(CO_Data* d, Message* m ) |
611 UNS8 proceedLSS_Slave(CO_Data* d, Message* m ) |
526 { |
612 { |
527 UNS8 msg_cs; |
613 UNS8 msg_cs; |
528 |
614 |
529 MSG_WAR(0x3D12, "SlaveLSS proceedLSS; command ", m->data[0]); |
615 MSG_WAR(0x3D21, "SlaveLSS proceedLSS; command ", m->data[0]); |
530 |
616 |
531 switch(msg_cs=m->data[0]){ |
617 switch(msg_cs=m->data[0]){ |
532 case LSS_SM_GLOBAL: /* Switch Mode Global */ |
618 case LSS_SM_GLOBAL: /* Switch Mode Global */ |
533 /* if there is not a mode change break*/ |
619 /* if there is not a mode change break*/ |
534 if(m->data[1] == d->lss_transfer.mode){ |
620 if(m->data[1] == d->lss_transfer.mode){ |
535 MSG_WAR(0x3D13, "SlaveLSS already in the mode ", m->data[1]); |
621 MSG_WAR(0x3D22, "SlaveLSS already in the mode ", m->data[1]); |
536 break; |
622 break; |
537 } |
623 } |
538 |
624 |
539 if(m->data[1]==LSS_CONFIGURATION_MODE) { |
625 if(m->data[1]==LSS_CONFIGURATION_MODE) { |
540 MSG_WAR(0x3D14, "SlaveLSS switching to configuration mode ", 0); |
626 MSG_WAR(0x3D23, "SlaveLSS switching to configuration mode ", 0); |
541 /* Store the NodeId in case it will be changed */ |
627 /* Store the NodeId in case it will be changed */ |
542 d->lss_transfer.nodeID=getNodeId(d); |
628 //d->lss_transfer.nodeID=getNodeId(d); |
543 d->lss_transfer.mode=LSS_CONFIGURATION_MODE; |
629 d->lss_transfer.mode=LSS_CONFIGURATION_MODE; |
544 } |
630 } |
545 else if(m->data[1]==LSS_WAITING_MODE){ |
631 else if(m->data[1]==LSS_WAITING_MODE){ |
546 MSG_WAR(0x3D15, "SlaveLSS switching to operational mode ", 0); |
632 MSG_WAR(0x3D24, "SlaveLSS switching to operational mode ", 0); |
547 |
633 |
548 if(d->lss_transfer.switchDelayState==SDELAY_OFF){ |
634 /* If the nodeID has changed update it and put the node state to Initialisation. */ |
549 /* If the nodeID has changed update it and put the node state to Initialisation. */ |
635 if(d->lss_transfer.nodeID!=getNodeId(d)){ |
550 if(d->lss_transfer.nodeID!=getNodeId(d)){ |
636 if(getNodeId(d)==0xFF){/* The nodeID was 0xFF; initialize the application*/ |
551 MSG_WAR(0x3D16, "The node Id has changed. Reseting to Initialisation state",0); |
637 MSG_WAR(0x3D25, "The node Id has changed. Reseting to Initialisation state",0); |
552 setNodeId(d, d->lss_transfer.nodeID); |
638 setNodeId(d, d->lss_transfer.nodeID); |
553 setState(d, Initialisation); |
639 setState(d, Initialisation); |
|
640 } |
|
641 else{/* The nodeID will be changed on NMT_Reset Request*/ |
|
642 setNodeId(d, d->lss_transfer.nodeID); |
554 } |
643 } |
555 } |
644 } |
556 d->lss_transfer.mode=LSS_WAITING_MODE; |
645 d->lss_transfer.mode=LSS_WAITING_MODE; |
557 } |
646 } |
558 break; |
647 break; |