143 } |
146 } |
144 } |
147 } |
145 |
148 |
146 #ifdef CO_ENABLE_LSS |
149 #ifdef CO_ENABLE_LSS |
147 static void ConfigureLSSNode(CO_Data* d); |
150 static void ConfigureLSSNode(CO_Data* d); |
|
151 // Step counts number of times ConfigureLSSNode is called |
148 UNS8 init_step_LSS=1; |
152 UNS8 init_step_LSS=1; |
149 |
153 |
150 static void CheckLSSAndContinue(CO_Data* d, UNS8 command) |
154 static void CheckLSSAndContinue(CO_Data* d, UNS8 command) |
151 { |
155 { |
152 UNS32 dat1; |
156 UNS32 dat1; |
153 UNS8 dat2; |
157 UNS8 dat2; |
154 printf("CheckLSS->"); |
158 printf("CheckLSS->"); |
155 if(getConfigResultNetworkNode (d, command, &dat1, &dat2) != LSS_FINISHED){ |
159 if(getConfigResultNetworkNode (d, command, &dat1, &dat2) != LSS_FINISHED){ |
156 if(command==LSS_IDENT_NON_CONF_SLAVE){ |
160 if(command==LSS_IDENT_REMOTE_NON_CONF){ |
157 eprintf("Master : There are not no-configured slaves in the net\n", command); |
161 eprintf("Master : There are not no-configured slaves in the net\n", command); |
158 return; |
162 return; |
159 } |
163 } |
160 else{ |
164 else{ |
161 eprintf("Master : Failed in LSS comand %d. Trying again\n", command); |
165 eprintf("Master : Failed in LSS comand %d. Trying again\n", command); |
188 case 1: printf("Store configuration error:not supported\n");break; |
192 case 1: printf("Store configuration error:not supported\n");break; |
189 case 0xFF:printf("Store configuration error:specific error\n");break; |
193 case 0xFF:printf("Store configuration error:specific error\n");break; |
190 default:break; |
194 default:break; |
191 } |
195 } |
192 break; |
196 break; |
193 case LSS_SM_SELECTIVE_RESP: |
197 case LSS_SM_SELECTIVE_SERIAL: |
194 printf("Slave in CONFIGURATION mode\n"); |
198 printf("Slave in CONFIGURATION mode\n"); |
195 break; |
199 break; |
196 case LSS_IDENT_SLAVE: |
200 case LSS_IDENT_REMOTE_SERIAL_HIGH: |
197 printf("node identified\n"); |
201 printf("node identified\n"); |
198 break; |
202 break; |
199 case LSS_IDENT_NON_CONF_SLAVE: |
203 case LSS_IDENT_REMOTE_NON_CONF: |
200 printf("non-configured remote slave in the net\n"); |
204 printf("non-configured remote slave in the net\n"); |
201 break; |
205 break; |
202 case LSS_INQ_VENDOR_ID: |
206 case LSS_INQ_VENDOR_ID: |
203 printf("Slave VendorID %x\n", dat1); |
207 printf("Slave VendorID %x\n", dat1); |
204 break; |
208 break; |
212 printf("Slave Serial Number %x\n", dat1); |
216 printf("Slave Serial Number %x\n", dat1); |
213 break; |
217 break; |
214 case LSS_INQ_NODE_ID: |
218 case LSS_INQ_NODE_ID: |
215 printf("Slave nodeid %x\n", dat1); |
219 printf("Slave nodeid %x\n", dat1); |
216 break; |
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 |
217 } |
233 } |
218 } |
234 } |
219 |
235 |
220 printf("\n"); |
236 printf("\n"); |
221 ConfigureLSSNode(d); |
237 ConfigureLSSNode(d); |
222 } |
238 } |
223 |
239 |
224 |
240 |
225 struct timeval master_prev_time,master_current_time; |
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 * */ |
226 static void ConfigureLSSNode(CO_Data* d) |
249 static void ConfigureLSSNode(CO_Data* d) |
227 { |
250 { |
228 UNS32 Vendor_ID=0x12345678; |
251 UNS32 Vendor_ID=0x12345678; |
229 UNS32 Product_Code=0x90123456; |
252 UNS32 Product_Code=0x90123456; |
230 UNS32 Revision_Number=0x78901234; |
253 UNS32 Revision_Number=0x78901234; |
237 UNS8 Baud_Table=0; |
260 UNS8 Baud_Table=0; |
238 UNS8 Baud_BitTiming=3; |
261 UNS8 Baud_BitTiming=3; |
239 UNS16 Switch_delay=1; |
262 UNS16 Switch_delay=1; |
240 UNS8 LSS_mode=LSS_WAITING_MODE; |
263 UNS8 LSS_mode=LSS_WAITING_MODE; |
241 UNS8 res; |
264 UNS8 res; |
242 eprintf("ConfigureLSSNode-> "); |
265 eprintf("ConfigureLSSNode -> ",0); |
243 |
266 |
244 switch(init_step_LSS){ |
267 switch(init_step_LSS){ |
245 case 1: /* LSS=>identify non-configured remote slave */ |
268 case 1: /* LSS=>identify non-configured remote slave */ |
246 eprintf("LSS=>identify non-configured remote slave\n"); |
269 eprintf("LSS=>identify non-configured remote slave\n"); |
247 res=configNetworkNodeCallBack(&TestMaster_Data,LSS_IDENT_REMOTE_NON_CONF,0,0,CheckLSSAndContinue); |
270 res=configNetworkNodeCallBack(&TestMaster_Data,LSS_IDENT_REMOTE_NON_CONF,0,0,CheckLSSAndContinue); |
248 break; |
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 |
249 case 2: /* LSS=>identify node */ |
278 case 2: /* LSS=>identify node */ |
250 eprintf("LSS=>identify node\n"); |
279 eprintf("LSS=>identify node\n"); |
251 res=configNetworkNode(&TestMaster_Data,LSS_IDENT_REMOTE_VENDOR,&Vendor_ID,0); |
280 res=configNetworkNode(&TestMaster_Data,LSS_IDENT_REMOTE_VENDOR,&Vendor_ID,0); |
252 res=configNetworkNode(&TestMaster_Data,LSS_IDENT_REMOTE_PRODUCT,&Product_Code,0); |
281 res=configNetworkNode(&TestMaster_Data,LSS_IDENT_REMOTE_PRODUCT,&Product_Code,0); |
253 res=configNetworkNode(&TestMaster_Data,LSS_IDENT_REMOTE_REV_LOW,&Revision_Number_low,0); |
282 res=configNetworkNode(&TestMaster_Data,LSS_IDENT_REMOTE_REV_LOW,&Revision_Number_low,0); |
254 res=configNetworkNode(&TestMaster_Data,LSS_IDENT_REMOTE_REV_HIGH,&Revision_Number_high,0); |
283 res=configNetworkNode(&TestMaster_Data,LSS_IDENT_REMOTE_REV_HIGH,&Revision_Number_high,0); |
255 res=configNetworkNode(&TestMaster_Data,LSS_IDENT_REMOTE_SERIAL_LOW,&Serial_Number_low,0); |
284 res=configNetworkNode(&TestMaster_Data,LSS_IDENT_REMOTE_SERIAL_LOW,&Serial_Number_low,0); |
256 res=configNetworkNodeCallBack(&TestMaster_Data,LSS_IDENT_REMOTE_SERIAL_HIGH,&Serial_Number_high,0,CheckLSSAndContinue); |
285 res=configNetworkNodeCallBack(&TestMaster_Data,LSS_IDENT_REMOTE_SERIAL_HIGH,&Serial_Number_high,0,CheckLSSAndContinue); |
257 break; |
286 break; |
258 case 3: /*First step : setup Slave's TPDO 1 to be transmitted on SYNC*/ |
287 case 3: /*LSS=>put in configuration mode*/ |
259 eprintf("LSS=>put in configuration mode\n"); |
288 eprintf("LSS=>put in configuration mode\n"); |
260 res=configNetworkNode(&TestMaster_Data,LSS_SM_SELECTIVE_VENDOR,&Vendor_ID,0); |
289 res=configNetworkNode(&TestMaster_Data,LSS_SM_SELECTIVE_VENDOR,&Vendor_ID,0); |
261 res=configNetworkNode(&TestMaster_Data,LSS_SM_SELECTIVE_PRODUCT,&Product_Code,0); |
290 res=configNetworkNode(&TestMaster_Data,LSS_SM_SELECTIVE_PRODUCT,&Product_Code,0); |
262 res=configNetworkNode(&TestMaster_Data,LSS_SM_SELECTIVE_REVISION,&Revision_Number,0); |
291 res=configNetworkNode(&TestMaster_Data,LSS_SM_SELECTIVE_REVISION,&Revision_Number,0); |
263 res=configNetworkNodeCallBack(&TestMaster_Data,LSS_SM_SELECTIVE_SERIAL,&Serial_Number,0,CheckLSSAndContinue); |
292 res=configNetworkNodeCallBack(&TestMaster_Data,LSS_SM_SELECTIVE_SERIAL,&Serial_Number,0,CheckLSSAndContinue); |
264 break; |
293 break; |
|
294 #endif |
265 case 4: /* LSS=>inquire nodeID */ |
295 case 4: /* LSS=>inquire nodeID */ |
266 eprintf("LSS=>inquire nodeID\n"); |
296 eprintf("LSS=>inquire nodeID\n"); |
267 res=configNetworkNodeCallBack(&TestMaster_Data,LSS_INQ_NODE_ID,0,0,CheckLSSAndContinue); |
297 res=configNetworkNodeCallBack(&TestMaster_Data,LSS_INQ_NODE_ID,0,0,CheckLSSAndContinue); |
268 break; |
298 break; |
269 case 5: /* LSS=>inquire VendorID */ |
299 case 5: /* LSS=>inquire VendorID */ |