Skip to content

Commit c2ebaee

Browse files
committed
Merge branch 'master' of rmc-github.robotic.dlr.de:common/libethercat
2 parents cd303cb + 64d88ea commit c2ebaee

11 files changed

Lines changed: 190 additions & 39 deletions

File tree

debian/changelog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
libethercat (0.7.4) unstable; urgency=low
22

3+
* fix: timeout waiting for cyclic loop
34
* autotools: cmake find package from autotools
45
* cmake: add generation of pkg-config file from cmake
56

include/libethercat/error_codes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
#define EC_ERROR_SLAVE_STATE_SWITCH (EC_ERROR_SLAVE_MASK | 0x00000001) //!< \brief State switch on slave failed.
7070
#define EC_ERROR_SLAVE_NOT_RESPONDING (EC_ERROR_SLAVE_MASK | 0x00000002) //!< \brief Slave is not responding.
7171
#define EC_ERROR_SLAVE_TRANSITION_ACTIVE (EC_ERROR_SLAVE_MASK | 0x00000004) //!< \brief Slave state transition currently active.
72+
#define EC_ERROR_SLAVE_NOT_FOUND (EC_ERROR_SLAVE_MASK | 0x00000008) //!< \brief Slave is not found in the network
7273

7374
#define EC_ERROR_EEPROM_MASK (0x00040000) //!< \brief Slave EEPROM error mask.
7475
#define EC_ERROR_EEPROM_READ_ERROR (EC_ERROR_EEPROM_MASK | 0x00000001) //!< \brief Slave EEPROM read error.

src/coe.c

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,11 @@ int ec_coe_sdo_read(ec_t *pec, osal_uint16_t slave, osal_uint16_t index,
352352
assert(pec != NULL);
353353
assert(buf != NULL);
354354
assert(len != NULL);
355-
assert(slave < pec->slave_cnt);
355+
356+
if(slave >= pec->slave_cnt)
357+
{
358+
return EC_ERROR_SLAVE_NOT_FOUND ;
359+
}
356360

357361
pool_entry_t *p_entry = NULL;
358362
int ret = EC_ERROR_MAILBOX_TIMEOUT;
@@ -470,7 +474,11 @@ static int ec_coe_sdo_write_expedited(ec_t *pec, osal_uint16_t slave, osal_uint1
470474
{
471475
assert(pec != NULL);
472476
assert(buf != NULL);
473-
assert(slave < pec->slave_cnt);
477+
478+
if(slave >= pec->slave_cnt)
479+
{
480+
return EC_ERROR_SLAVE_NOT_FOUND ;
481+
}
474482

475483
pool_entry_t *p_entry = NULL;
476484
int ret = EC_ERROR_MAILBOX_TIMEOUT;
@@ -566,7 +574,11 @@ static int ec_coe_sdo_write_normal(ec_t *pec, osal_uint16_t slave, osal_uint16_t
566574
{
567575
assert(pec != NULL);
568576
assert(buf != NULL);
569-
assert(slave < pec->slave_cnt);
577+
578+
if(slave >= pec->slave_cnt)
579+
{
580+
return EC_ERROR_SLAVE_NOT_FOUND ;
581+
}
570582

571583
pool_entry_t *p_entry = NULL;
572584
int ret = EC_ERROR_MAILBOX_TIMEOUT;
@@ -787,7 +799,11 @@ int ec_coe_odlist_read(ec_t *pec, osal_uint16_t slave, osal_uint8_t *buf, osal_s
787799
assert(pec != NULL);
788800
assert(buf != NULL);
789801
assert(len != NULL);
790-
assert(slave < pec->slave_cnt);
802+
803+
if(slave >= pec->slave_cnt)
804+
{
805+
return EC_ERROR_SLAVE_NOT_FOUND ;
806+
}
791807

792808
pool_entry_t *p_entry = NULL;
793809
int ret = EC_OK;
@@ -904,7 +920,11 @@ int ec_coe_sdo_desc_read(ec_t *pec, osal_uint16_t slave, osal_uint16_t index,
904920
ec_coe_sdo_desc_t *desc, osal_uint32_t *error_code) {
905921
assert(pec != NULL);
906922
assert(desc != NULL);
907-
assert(slave < pec->slave_cnt);
923+
924+
if(slave >= pec->slave_cnt)
925+
{
926+
return EC_ERROR_SLAVE_NOT_FOUND ;
927+
}
908928

909929
pool_entry_t *p_entry = NULL;
910930
int ret = EC_OK;
@@ -1026,7 +1046,11 @@ int ec_coe_sdo_entry_desc_read(ec_t *pec, osal_uint16_t slave, osal_uint16_t ind
10261046
{
10271047
assert(pec != NULL);
10281048
assert(desc != NULL);
1029-
assert(slave < pec->slave_cnt);
1049+
1050+
if(slave >= pec->slave_cnt)
1051+
{
1052+
return EC_ERROR_SLAVE_NOT_FOUND ;
1053+
}
10301054

10311055
pool_entry_t *p_entry = NULL;
10321056
int ret = EC_ERROR_MAILBOX_READ;
@@ -1125,7 +1149,11 @@ int ec_coe_sdo_entry_desc_read(ec_t *pec, osal_uint16_t slave, osal_uint16_t ind
11251149

11261150
int ec_coe_generate_mapping(ec_t *pec, osal_uint16_t slave) {
11271151
assert(pec != NULL);
1128-
assert(slave < pec->slave_cnt);
1152+
1153+
if(slave >= pec->slave_cnt)
1154+
{
1155+
return EC_ERROR_SLAVE_NOT_FOUND ;
1156+
}
11291157

11301158
int ret = EC_ERROR_MAILBOX_TIMEOUT;
11311159
osal_uint8_t *buf = NULL;
@@ -1311,9 +1339,13 @@ void ec_coe_emergency_enqueue(ec_t *pec, osal_uint16_t slave, pool_entry_t *p_en
13111339
*/
13121340
int ec_coe_emergency_get_next(ec_t *pec, osal_uint16_t slave, ec_coe_emergency_message_t *msg) {
13131341
assert(pec != NULL);
1314-
assert(slave < pec->slave_cnt);
13151342
assert(msg != NULL);
13161343

1344+
if(slave >= pec->slave_cnt)
1345+
{
1346+
return EC_ERROR_SLAVE_NOT_FOUND ;
1347+
}
1348+
13171349
ec_slave_ptr(slv, pec, slave);
13181350
int ret = EC_ERROR_UNAVAILABLE;
13191351

src/dc.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,11 @@ int ec_dc_sync(ec_t *pec, osal_uint16_t slave, osal_uint8_t active,
185185
osal_uint32_t cycle_time_0, osal_uint32_t cycle_time_1, osal_int32_t cycle_shift)
186186
{
187187
assert(pec != NULL);
188-
assert(slave < pec->slave_cnt);
188+
189+
if(slave >= pec->slave_cnt)
190+
{
191+
return EC_ERROR_SLAVE_NOT_FOUND ;
192+
}
189193

190194
int ret = EC_OK;
191195
ec_slave_ptr(slv, pec, slave);
@@ -200,7 +204,7 @@ int ec_dc_sync(ec_t *pec, osal_uint16_t slave, osal_uint8_t active,
200204
osal_timer_init(&dc_time_to, 1000000000); // wait 1 sec for cyclic loop
201205

202206
do {
203-
if (osal_timer_expired(&dc_time_to) != OSAL_ERR_TIMEOUT) {
207+
if (osal_timer_expired(&dc_time_to) == OSAL_ERR_TIMEOUT) {
204208
ec_log(1, "DC_SYNC", "slave %2d: ERROR calculating start time because there's no cyclic "
205209
"loop running right now! DC will not work correctly!\n", slave);
206210

src/eeprom.c

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@
6060
// set eeprom control to pdi
6161
int ec_eeprom_to_pdi(ec_t *pec, osal_uint16_t slave) {
6262
assert(pec != NULL);
63-
assert(slave < pec->slave_cnt);
63+
64+
if(slave >= pec->slave_cnt)
65+
{
66+
return EC_ERROR_SLAVE_NOT_FOUND ;
67+
}
6468

6569
int ret = EC_OK;
6670
osal_uint16_t wkc;
@@ -79,7 +83,11 @@ int ec_eeprom_to_pdi(ec_t *pec, osal_uint16_t slave) {
7983
// set eeprom control to ec
8084
int ec_eeprom_to_ec(struct ec *pec, osal_uint16_t slave) {
8185
assert(pec != NULL);
82-
assert(slave < pec->slave_cnt);
86+
87+
if(slave >= pec->slave_cnt)
88+
{
89+
return EC_ERROR_SLAVE_NOT_FOUND ;
90+
}
8391

8492
int ret = EC_OK;
8593
osal_uint16_t wkc;
@@ -136,8 +144,12 @@ int ec_eeprom_to_ec(struct ec *pec, osal_uint16_t slave) {
136144
// read 32-bit word of eeprom
137145
int ec_eepromread(ec_t *pec, osal_uint16_t slave, osal_uint32_t eepadr, osal_uint32_t *data) {
138146
assert(pec != NULL);
139-
assert(slave < pec->slave_cnt);
140147
assert(data != NULL);
148+
149+
if(slave >= pec->slave_cnt)
150+
{
151+
return EC_ERROR_SLAVE_NOT_FOUND ;
152+
}
141153

142154
int ret = EC_OK;
143155
osal_uint16_t wkc = 0;
@@ -239,9 +251,13 @@ int ec_eepromread(ec_t *pec, osal_uint16_t slave, osal_uint32_t eepadr, osal_uin
239251
// write 32-bit word of eeprom
240252
int ec_eepromwrite(ec_t *pec, osal_uint16_t slave, osal_uint32_t eepadr, osal_uint16_t *data) {
241253
assert(pec != NULL);
242-
assert(slave < pec->slave_cnt);
243254
assert(data != NULL);
244255

256+
if(slave >= pec->slave_cnt)
257+
{
258+
return EC_ERROR_SLAVE_NOT_FOUND ;
259+
}
260+
245261
int ret = EC_OK;
246262
osal_uint16_t wkc = 0;
247263
osal_uint16_t eepcsr = 0x0100; // write access
@@ -390,9 +406,13 @@ int ec_eepromread_len(ec_t *pec, osal_uint16_t slave, osal_uint32_t eepadr,
390406
osal_uint8_t *buf, osal_size_t buflen)
391407
{
392408
assert(pec != NULL);
393-
assert(slave < pec->slave_cnt);
394409
assert(buf != NULL);
395410

411+
if(slave >= pec->slave_cnt)
412+
{
413+
return EC_ERROR_SLAVE_NOT_FOUND ;
414+
}
415+
396416
osal_off_t offset = 0;
397417
int ret = EC_OK;
398418

@@ -422,9 +442,13 @@ int ec_eepromwrite_len(ec_t *pec, osal_uint16_t slave, osal_uint32_t eepadr,
422442
const osal_uint8_t *buf, osal_size_t buflen)
423443
{
424444
assert(pec != NULL);
425-
assert(slave < pec->slave_cnt);
426445
assert(buf != NULL);
427446

447+
if(slave >= pec->slave_cnt)
448+
{
449+
return EC_ERROR_SLAVE_NOT_FOUND ;
450+
}
451+
428452
osal_off_t offset = 0;
429453
int i;
430454
int ret = EC_OK;

src/eoe.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,11 @@ int ec_eoe_set_ip_parameter(ec_t *pec, osal_uint16_t slave, osal_uint8_t *mac,
341341
osal_uint8_t *dns, osal_char_t *dns_name)
342342
{
343343
assert(pec != NULL);
344-
assert(slave < pec->slave_cnt);
344+
345+
if(slave >= pec->slave_cnt)
346+
{
347+
return EC_ERROR_SLAVE_NOT_FOUND ;
348+
}
345349

346350
pool_entry_t *p_entry;
347351
int ret = EC_ERROR_MAILBOX_TIMEOUT;
@@ -437,9 +441,14 @@ static void ec_eoe_send_sync(struct ec *pec, pool_entry_t *p_entry, ec_datagram_
437441
int ec_eoe_send_frame(ec_t *pec, osal_uint16_t slave, osal_uint8_t *frame, osal_size_t frame_len)
438442
{
439443
assert(pec != NULL);
440-
assert(slave < pec->slave_cnt);
441444
assert(frame != NULL);
442445

446+
if(slave >= pec->slave_cnt)
447+
{
448+
return EC_ERROR_SLAVE_NOT_FOUND ;
449+
}
450+
451+
443452
int ret = EC_ERROR_MAILBOX_TIMEOUT;
444453
int counter;
445454
ec_slave_ptr(slv, pec, slave);
@@ -516,7 +525,11 @@ int ec_eoe_send_frame(ec_t *pec, osal_uint16_t slave, osal_uint8_t *frame, osal_
516525
*/
517526
int ec_eoe_process_recv(ec_t *pec, osal_uint16_t slave) {
518527
assert(pec != NULL);
519-
assert(slave < pec->slave_cnt);
528+
529+
if(slave >= pec->slave_cnt)
530+
{
531+
return EC_ERROR_SLAVE_NOT_FOUND ;
532+
}
520533

521534
int ret = EC_OK;
522535
ec_slave_ptr(slv, pec, slave);

src/foe.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,14 @@ int ec_foe_read(ec_t *pec, osal_uint16_t slave, osal_uint32_t password,
237237
osal_size_t *file_data_len, const osal_char_t **error_message)
238238
{
239239
assert(pec != NULL);
240-
assert(slave < pec->slave_cnt);
241240
assert(file_data != NULL);
242241
assert(file_data_len != NULL);
243242

243+
if(slave >= pec->slave_cnt)
244+
{
245+
return EC_ERROR_SLAVE_NOT_FOUND ;
246+
}
247+
244248
int ret = EC_OK;
245249
int counter;
246250
ec_slave_ptr(slv, pec, slave);
@@ -359,9 +363,13 @@ int ec_foe_write(ec_t *pec, osal_uint16_t slave, osal_uint32_t password,
359363
{
360364
(void)error_message;
361365
assert(pec != NULL);
362-
assert(slave < pec->slave_cnt);
363366
assert(file_data != NULL);
364367

368+
if(slave >= pec->slave_cnt)
369+
{
370+
return EC_ERROR_SLAVE_NOT_FOUND ;
371+
}
372+
365373
int ret = EC_OK;
366374
int counter;
367375
ec_slave_ptr(slv, pec, slave);

src/mbx.c

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,11 @@ int ec_mbx_is_full(ec_t *pec, osal_uint16_t slave, osal_uint8_t mbx_nr, osal_uin
273273
ec_slave_ptr(slv, pec, slave);
274274

275275
assert(pec != NULL);
276-
assert(slave < pec->slave_cnt);
276+
277+
if(slave >= pec->slave_cnt)
278+
{
279+
return EC_ERROR_SLAVE_NOT_FOUND ;
280+
}
277281

278282
osal_uint64_t timeout = nsec;
279283
osal_timer_t timer;
@@ -320,7 +324,11 @@ int ec_mbx_is_empty(ec_t *pec, osal_uint16_t slave, osal_uint8_t mbx_nr, osal_ui
320324
int ret = EC_ERROR_MAILBOX_TIMEOUT;
321325

322326
assert(pec != NULL);
323-
assert(slave < pec->slave_cnt);
327+
328+
if(slave >= pec->slave_cnt)
329+
{
330+
return EC_ERROR_SLAVE_NOT_FOUND ;
331+
}
324332

325333
osal_uint64_t timeout = nsec;
326334
osal_timer_t timer;
@@ -358,9 +366,13 @@ int ec_mbx_send(ec_t *pec, osal_uint16_t slave, osal_uint8_t *buf, osal_size_t b
358366
ec_slave_ptr(slv, pec, slave);
359367

360368
assert(pec != NULL);
361-
assert(slave < pec->slave_cnt);
362369
assert(buf != NULL);
363370

371+
if(slave >= pec->slave_cnt)
372+
{
373+
return EC_ERROR_SLAVE_NOT_FOUND ;
374+
}
375+
364376
osal_uint64_t timeout = nsec;
365377
osal_timer_t timer;
366378
osal_timer_init(&timer, timeout);
@@ -410,9 +422,13 @@ int ec_mbx_receive(ec_t *pec, osal_uint16_t slave, osal_uint8_t *buf, osal_size_
410422
ec_slave_ptr(slv, pec, slave);
411423

412424
assert(pec != NULL);
413-
assert(slave < pec->slave_cnt);
414425
assert(buf != NULL);
415-
426+
427+
if(slave >= pec->slave_cnt)
428+
{
429+
return EC_ERROR_SLAVE_NOT_FOUND ;
430+
}
431+
416432
// wait for receive mailbox available
417433
if (ec_mbx_is_full(pec, slave, MAILBOX_READ, nsec) == EC_OK) {
418434
(void)ec_fprd(pec, slv->fixed_address, slv->sm[MAILBOX_READ].adr,
@@ -686,9 +702,13 @@ void ec_mbx_handler(ec_t *pec, osal_uint16_t slave) {
686702
*/
687703
int ec_mbx_get_free_send_buffer(ec_t *pec, osal_uint16_t slave, pool_entry_t **pp_entry, osal_timer_t *timeout) {
688704
assert(pec != NULL);
689-
assert(slave < pec->slave_cnt);
690705
assert(pp_entry != NULL);
691706

707+
if(slave >= pec->slave_cnt)
708+
{
709+
return EC_ERROR_SLAVE_NOT_FOUND ;
710+
}
711+
692712
(void)slave;
693713

694714
int ret = pool_get(&pec->mbx_message_pool_send_free, pp_entry, timeout);
@@ -715,9 +735,13 @@ int ec_mbx_get_free_send_buffer(ec_t *pec, osal_uint16_t slave, pool_entry_t **p
715735
*/
716736
int ec_mbx_next_counter(ec_t *pec, int slave, int *seq_counter) {
717737
assert(pec != NULL);
718-
assert(slave < pec->slave_cnt);
719738
assert(seq_counter != NULL);
720739

740+
if(slave >= pec->slave_cnt)
741+
{
742+
return EC_ERROR_SLAVE_NOT_FOUND ;
743+
}
744+
721745
ec_slave_ptr(slv, pec, slave);
722746

723747
if ((++slv->mbx.seq_counter) > 7) {

0 commit comments

Comments
 (0)