144 masterSendNMTstateChange (d, nodeId, NMT_Start_Node); |
145 masterSendNMTstateChange (d, nodeId, NMT_Start_Node); |
145 |
146 |
146 } |
147 } |
147 } |
148 } |
148 |
149 |
149 #ifdef CO_ENABLE_LSS |
|
150 static void ConfigureLSSNode(CO_Data* d); |
|
151 // Step counts number of times ConfigureLSSNode is called |
|
152 UNS8 init_step_LSS=1; |
|
153 |
|
154 static void CheckLSSAndContinue(CO_Data* d, UNS8 command) |
|
155 { |
|
156 UNS32 dat1; |
|
157 UNS8 dat2; |
|
158 printf("CheckLSS->"); |
|
159 if(getConfigResultNetworkNode (d, command, &dat1, &dat2) != LSS_FINISHED){ |
|
160 if(command==LSS_IDENT_REMOTE_NON_CONF){ |
|
161 eprintf("Master : There are not no-configured slaves in the net\n", command); |
|
162 return; |
|
163 } |
|
164 else{ |
|
165 eprintf("Master : Failed in LSS comand %d. Trying again\n", command); |
|
166 } |
|
167 } |
|
168 else |
|
169 { |
|
170 init_step_LSS++; |
|
171 |
|
172 switch(command){ |
|
173 case LSS_CONF_NODE_ID: |
|
174 switch(dat1){ |
|
175 case 0: printf("Node ID change succesful\n");break; |
|
176 case 1: printf("Node ID change error:out of range\n");break; |
|
177 case 0xFF:printf("Node ID change error:specific error\n");break; |
|
178 default:break; |
|
179 } |
|
180 break; |
|
181 case LSS_CONF_BIT_TIMING: |
|
182 switch(dat1){ |
|
183 case 0: printf("Baud rate change succesful\n");break; |
|
184 case 1: printf("Baud rate change error: change baud rate not supported\n");break; |
|
185 case 0xFF:printf("Baud rate change error:specific error\n");break; |
|
186 default:break; |
|
187 } |
|
188 break; |
|
189 case LSS_CONF_STORE: |
|
190 switch(dat1){ |
|
191 case 0: printf("Store configuration succesful\n");break; |
|
192 case 1: printf("Store configuration error:not supported\n");break; |
|
193 case 0xFF:printf("Store configuration error:specific error\n");break; |
|
194 default:break; |
|
195 } |
|
196 break; |
|
197 case LSS_SM_SELECTIVE_SERIAL: |
|
198 printf("Slave in CONFIGURATION mode\n"); |
|
199 break; |
|
200 case LSS_IDENT_REMOTE_SERIAL_HIGH: |
|
201 printf("node identified\n"); |
|
202 break; |
|
203 case LSS_IDENT_REMOTE_NON_CONF: |
|
204 printf("non-configured remote slave in the net\n"); |
|
205 break; |
|
206 case LSS_INQ_VENDOR_ID: |
|
207 printf("Slave VendorID %x\n", dat1); |
|
208 break; |
|
209 case LSS_INQ_PRODUCT_CODE: |
|
210 printf("Slave Product Code %x\n", dat1); |
|
211 break; |
|
212 case LSS_INQ_REV_NUMBER: |
|
213 printf("Slave Revision Number %x\n", dat1); |
|
214 break; |
|
215 case LSS_INQ_SERIAL_NUMBER: |
|
216 printf("Slave Serial Number %x\n", dat1); |
|
217 break; |
|
218 case LSS_INQ_NODE_ID: |
|
219 printf("Slave nodeid %x\n", dat1); |
|
220 break; |
|
221 #ifdef CO_ENABLE_LSS_FS |
|
222 case LSS_IDENT_FASTSCAN: |
|
223 if(dat1==0) |
|
224 printf("Slave node identified with FastScan\n"); |
|
225 else |
|
226 { |
|
227 printf("There is not unconfigured node in the net\n"); |
|
228 return; |
|
229 } |
|
230 init_step_LSS++; |
|
231 break; |
|
232 #endif |
|
233 } |
|
234 } |
|
235 |
|
236 printf("\n"); |
|
237 ConfigureLSSNode(d); |
|
238 } |
|
239 |
|
240 |
|
241 /* First ask if there is a node with an invalid nodeID. |
|
242 * If FastScan is activated it is used to put the node in the state “configuration�. |
|
243 * If FastScan is not activated, identification services are used to identify the node. |
|
244 * Then switch mode service is used to put it in configuration state. |
|
245 * Next all the inquire and configuration services are used. |
|
246 * Finally, the node LSS state is restored to “waiting� and all the process is repeated |
|
247 * again until there isn't any node with a invalid nodeID. |
|
248 * */ |
|
249 static void ConfigureLSSNode(CO_Data* d) |
|
250 { |
|
251 UNS32 Vendor_ID=0x12345678; |
|
252 UNS32 Product_Code=0x90123456; |
|
253 UNS32 Revision_Number=0x78901234; |
|
254 UNS32 Serial_Number=0x56789012; |
|
255 UNS32 Revision_Number_high=0x78901240; |
|
256 UNS32 Revision_Number_low=0x78901230; |
|
257 UNS32 Serial_Number_high=0x56789020; |
|
258 UNS32 Serial_Number_low=0x56789010; |
|
259 UNS8 NodeID=0x02; |
|
260 UNS8 Baud_Table=0; |
|
261 UNS8 Baud_BitTiming=3; |
|
262 UNS16 Switch_delay=1; |
|
263 UNS8 LSS_mode=LSS_WAITING_MODE; |
|
264 UNS8 res; |
|
265 eprintf("ConfigureLSSNode -> ",0); |
|
266 |
|
267 switch(init_step_LSS){ |
|
268 case 1: /* LSS=>identify non-configured remote slave */ |
|
269 eprintf("LSS=>identify non-configured remote slave\n"); |
|
270 res=configNetworkNodeCallBack(&TestMaster_Data,LSS_IDENT_REMOTE_NON_CONF,0,0,CheckLSSAndContinue); |
|
271 break; |
|
272 #ifdef CO_ENABLE_LSS_FS |
|
273 case 2: /* LSS=>FastScan */ |
|
274 eprintf("LSS=>FastScan\n"); |
|
275 res=configNetworkNodeCallBack(&TestMaster_Data,LSS_IDENT_FASTSCAN,0,0,CheckLSSAndContinue); |
|
276 break; |
|
277 #else |
|
278 case 2: /* LSS=>identify node */ |
|
279 eprintf("LSS=>identify node\n"); |
|
280 res=configNetworkNode(&TestMaster_Data,LSS_IDENT_REMOTE_VENDOR,&Vendor_ID,0); |
|
281 res=configNetworkNode(&TestMaster_Data,LSS_IDENT_REMOTE_PRODUCT,&Product_Code,0); |
|
282 res=configNetworkNode(&TestMaster_Data,LSS_IDENT_REMOTE_REV_LOW,&Revision_Number_low,0); |
|
283 res=configNetworkNode(&TestMaster_Data,LSS_IDENT_REMOTE_REV_HIGH,&Revision_Number_high,0); |
|
284 res=configNetworkNode(&TestMaster_Data,LSS_IDENT_REMOTE_SERIAL_LOW,&Serial_Number_low,0); |
|
285 res=configNetworkNodeCallBack(&TestMaster_Data,LSS_IDENT_REMOTE_SERIAL_HIGH,&Serial_Number_high,0,CheckLSSAndContinue); |
|
286 break; |
|
287 case 3: /*LSS=>put in configuration mode*/ |
|
288 eprintf("LSS=>put in configuration mode\n"); |
|
289 res=configNetworkNode(&TestMaster_Data,LSS_SM_SELECTIVE_VENDOR,&Vendor_ID,0); |
|
290 res=configNetworkNode(&TestMaster_Data,LSS_SM_SELECTIVE_PRODUCT,&Product_Code,0); |
|
291 res=configNetworkNode(&TestMaster_Data,LSS_SM_SELECTIVE_REVISION,&Revision_Number,0); |
|
292 res=configNetworkNodeCallBack(&TestMaster_Data,LSS_SM_SELECTIVE_SERIAL,&Serial_Number,0,CheckLSSAndContinue); |
|
293 break; |
|
294 #endif |
|
295 case 4: /* LSS=>inquire nodeID */ |
|
296 eprintf("LSS=>inquire nodeID\n"); |
|
297 res=configNetworkNodeCallBack(&TestMaster_Data,LSS_INQ_NODE_ID,0,0,CheckLSSAndContinue); |
|
298 break; |
|
299 case 5: /* LSS=>inquire VendorID */ |
|
300 eprintf("LSS=>inquire VendorID\n"); |
|
301 res=configNetworkNodeCallBack(&TestMaster_Data,LSS_INQ_VENDOR_ID,0,0,CheckLSSAndContinue); |
|
302 break; |
|
303 case 6: /* LSS=>inquire Product code */ |
|
304 eprintf("LSS=>inquire Product code\n"); |
|
305 res=configNetworkNodeCallBack(&TestMaster_Data,LSS_INQ_PRODUCT_CODE,0,0,CheckLSSAndContinue); |
|
306 break; |
|
307 case 7: /* LSS=>inquire Revision Number */ |
|
308 eprintf("LSS=>inquire Revision Number\n"); |
|
309 res=configNetworkNodeCallBack(&TestMaster_Data,LSS_INQ_REV_NUMBER,0,0,CheckLSSAndContinue); |
|
310 break; |
|
311 case 8: /* LSS=>inquire Serial Number */ |
|
312 eprintf("LSS=>inquire Serial Number\n"); |
|
313 res=configNetworkNodeCallBack(&TestMaster_Data,LSS_INQ_SERIAL_NUMBER,0,0,CheckLSSAndContinue); |
|
314 break; |
|
315 case 9: /* LSS=>change the nodeID */ |
|
316 eprintf("LSS=>change the nodeId\n"); |
|
317 res=configNetworkNodeCallBack(&TestMaster_Data,LSS_CONF_NODE_ID,&NodeID,0,CheckLSSAndContinue); |
|
318 break; |
|
319 case 10: /* LSS=>change the Baud rate */ |
|
320 eprintf("LSS=>change the Baud rate\n"); |
|
321 res=configNetworkNodeCallBack(&TestMaster_Data,LSS_CONF_BIT_TIMING,&Baud_Table,&Baud_BitTiming,CheckLSSAndContinue); |
|
322 break; |
|
323 case 11: |
|
324 eprintf("LSS=>Activate Bit Timing\n"); |
|
325 res=configNetworkNode(&TestMaster_Data,LSS_CONF_ACT_BIT_TIMING,&Switch_delay,0); |
|
326 /*no break;*/ |
|
327 init_step_LSS++; |
|
328 case 12: |
|
329 /*LSS=>store configuration*/ |
|
330 /* It will fail the first time (time out) due to the switch delay */ |
|
331 /* It will fail the second time because it is not implemented in the slave */ |
|
332 eprintf("LSS=>store configuration\n"); |
|
333 res=configNetworkNodeCallBack(&TestMaster_Data,LSS_CONF_STORE,0,0,CheckLSSAndContinue); |
|
334 break; |
|
335 case 13: /* LSS=>put in operation mod */ |
|
336 eprintf("LSS=>put in operation mode\n"); |
|
337 res=configNetworkNode(&TestMaster_Data,LSS_SM_GLOBAL,&LSS_mode,0); |
|
338 /* Search again for not-configured slaves*/ |
|
339 eprintf("LSS=>identify not-configured remote slave\n"); |
|
340 res=configNetworkNodeCallBack(&TestMaster_Data,LSS_IDENT_REMOTE_NON_CONF,0,0,CheckLSSAndContinue); |
|
341 init_step_LSS=1; |
|
342 break; |
|
343 } |
|
344 } |
|
345 #endif |
|
346 |
150 |
347 void TestMaster_preOperational(CO_Data* d) |
151 void TestMaster_preOperational(CO_Data* d) |
348 { |
152 { |
349 eprintf("TestMaster_preOperational\n"); |
153 eprintf("TestMaster_preOperational\n"); |
350 #ifdef CO_ENABLE_LSS |
|
351 /* Ask slave node to go in stop mode */ |
|
352 masterSendNMTstateChange (&TestMaster_Data, 0, NMT_Stop_Node); |
|
353 ConfigureLSSNode(&TestMaster_Data); |
|
354 #endif |
|
355 } |
154 } |
356 |
155 |
357 void TestMaster_operational(CO_Data* d) |
156 void TestMaster_operational(CO_Data* d) |
358 { |
157 { |
359 eprintf("TestMaster_operational\n"); |
158 eprintf("TestMaster_operational\n"); |