diff --git a/master/ethernet.c b/master/ethernet.c index 7f03cebb6f8bfdb4c7d52982896f7ae7a39ffb65..d5ae7c50d94afbab955765faa22c053bdb9e1a81 100644 --- a/master/ethernet.c +++ b/master/ethernet.c @@ -120,9 +120,9 @@ int ec_eoe_init( /* device name eoe<MASTER>[as]<SLAVE>, because networking scripts don't * like hyphens etc. in interface names. */ - if (slave->sii_alias) { + if (slave->sii.alias) { snprintf(name, EC_DATAGRAM_NAME_SIZE, - "eoe%ua%u", slave->master->index, slave->sii_alias); + "eoe%ua%u", slave->master->index, slave->sii.alias); } else { snprintf(name, EC_DATAGRAM_NAME_SIZE, "eoe%us%u", slave->master->index, slave->ring_position); @@ -153,7 +153,7 @@ int ec_eoe_init( // so the MTU is left on the Ethernet standard value and fragmenting // is done "manually". #if 0 - eoe->dev->mtu = slave->sii_rx_mailbox_size - ETH_HLEN - 10; + eoe->dev->mtu = slave->sii.rx_mailbox_size - ETH_HLEN - 10; #endif // connect the net_device to the kernel @@ -237,12 +237,12 @@ int ec_eoe_send(ec_eoe_t *eoe /**< EoE handler */) remaining_size = eoe->tx_frame->skb->len - eoe->tx_offset; - if (remaining_size <= eoe->slave->sii_tx_mailbox_size - 10) { + if (remaining_size <= eoe->slave->sii.tx_mailbox_size - 10) { current_size = remaining_size; last_fragment = 1; } else { - current_size = ((eoe->slave->sii_tx_mailbox_size - 10) / 32) * 32; + current_size = ((eoe->slave->sii.tx_mailbox_size - 10) / 32) * 32; last_fragment = 0; } @@ -704,7 +704,7 @@ int ec_eoedev_tx(struct sk_buff *skb, /**< transmit socket buffer */ ec_eoe_frame_t *frame; #if 0 - if (skb->len > eoe->slave->sii_tx_mailbox_size - 10) { + if (skb->len > eoe->slave->sii.tx_mailbox_size - 10) { EC_WARN("EoE TX frame (%i octets) exceeds MTU. dropping.\n", skb->len); dev_kfree_skb(skb); eoe->stats.tx_dropped++; diff --git a/master/fsm_coe.c b/master/fsm_coe.c index 5d8bbf39908b40c2f1b194c19d13e1ca3223293d..e355172d504d6a4c71f0cfa7a4753e64adbfa8dc 100644 --- a/master/fsm_coe.c +++ b/master/fsm_coe.c @@ -249,7 +249,7 @@ void ec_fsm_coe_dict_start(ec_fsm_coe_t *fsm /**< finite state machine */) ec_slave_t *slave = fsm->slave; uint8_t *data; - if (!(slave->sii_mailbox_protocols & EC_MBOX_COE)) { + if (!(slave->sii.mailbox_protocols & EC_MBOX_COE)) { EC_ERR("Slave %u does not support CoE!\n", slave->ring_position); fsm->state = ec_fsm_coe_error; return; @@ -961,13 +961,13 @@ void ec_fsm_coe_down_start(ec_fsm_coe_t *fsm /**< finite state machine */) EC_DBG("Downloading Sdo 0x%04X:%i to slave %i.\n", sdodata->index, sdodata->subindex, slave->ring_position); - if (!(slave->sii_mailbox_protocols & EC_MBOX_COE)) { + if (!(slave->sii.mailbox_protocols & EC_MBOX_COE)) { EC_ERR("Slave %u does not support CoE!\n", slave->ring_position); fsm->state = ec_fsm_coe_error; return; } - if (slave->sii_rx_mailbox_size < 6 + 10 + sdodata->size) { + if (slave->sii.rx_mailbox_size < 6 + 10 + sdodata->size) { EC_ERR("Sdo fragmenting not supported yet!\n"); fsm->state = ec_fsm_coe_error; return; @@ -1181,7 +1181,7 @@ void ec_fsm_coe_up_start(ec_fsm_coe_t *fsm /**< finite state machine */) EC_DBG("Uploading Sdo 0x%04X:%i from slave %i.\n", request->index, request->subindex, slave->ring_position); - if (!(slave->sii_mailbox_protocols & EC_MBOX_COE)) { + if (!(slave->sii.mailbox_protocols & EC_MBOX_COE)) { EC_ERR("Slave %u does not support CoE!\n", slave->ring_position); fsm->state = ec_fsm_coe_error; return; diff --git a/master/fsm_master.c b/master/fsm_master.c index 7c0c9f1a31a926d85a282dc3e2818db01aa92607..1d1cc2d678e28dcf3c44ade9687293ab0dc69518 100644 --- a/master/fsm_master.c +++ b/master/fsm_master.c @@ -503,7 +503,7 @@ void ec_fsm_master_action_process_states(ec_fsm_master_t *fsm // check, if slaves have an Sdo dictionary to read out. list_for_each_entry(slave, &master->slaves, list) { - if (!(slave->sii_mailbox_protocols & EC_MBOX_COE) + if (!(slave->sii.mailbox_protocols & EC_MBOX_COE) || slave->sdo_dictionary_fetched || slave->current_state == EC_SLAVE_STATE_INIT || jiffies - slave->jiffies_preop < EC_WAIT_SDO_DICT * HZ @@ -673,7 +673,7 @@ void ec_fsm_master_state_validate_vendor(ec_fsm_master_t *fsm /**< master state return; } - if (EC_READ_U32(fsm->fsm_sii.value) != slave->sii_vendor_id) { + if (EC_READ_U32(fsm->fsm_sii.value) != slave->sii.vendor_id) { EC_ERR("Slave %i has an invalid vendor ID!\n", slave->ring_position); fsm->state = ec_fsm_master_state_error; return; @@ -738,9 +738,9 @@ void ec_fsm_master_state_validate_product(ec_fsm_master_t *fsm /**< master state return; } - if (EC_READ_U32(fsm->fsm_sii.value) != slave->sii_product_code) { + if (EC_READ_U32(fsm->fsm_sii.value) != slave->sii.product_code) { EC_ERR("Slave %i: invalid product code!\n", slave->ring_position); - EC_ERR("expected 0x%08X, got 0x%08X.\n", slave->sii_product_code, + EC_ERR("expected 0x%08X, got 0x%08X.\n", slave->sii.product_code, EC_READ_U32(fsm->fsm_sii.value)); fsm->state = ec_fsm_master_state_error; return; @@ -865,7 +865,7 @@ void ec_fsm_master_state_scan_slaves( return; #ifdef EC_EOE - if (slave->sii_mailbox_protocols & EC_MBOX_EOE) { + if (slave->sii.mailbox_protocols & EC_MBOX_EOE) { // create EoE handler for this slave ec_eoe_t *eoe; if (!(eoe = kmalloc(sizeof(ec_eoe_t), GFP_KERNEL))) { diff --git a/master/fsm_slave_config.c b/master/fsm_slave_config.c index e1082c92021e7274052af774aa4ead683729614e..33bbd44657f14534a6eb4f1ae38ab2fb89a6755d 100644 --- a/master/fsm_slave_config.c +++ b/master/fsm_slave_config.c @@ -283,7 +283,7 @@ void ec_fsm_slave_config_enter_mbox_sync( return; } - if (!slave->sii_mailbox_protocols) { + if (!slave->sii.mailbox_protocols) { // no mailbox protocols supported if (master->debug_level) EC_DBG("Slave %u does not support mailbox communication.\n", @@ -297,14 +297,14 @@ void ec_fsm_slave_config_enter_mbox_sync( slave->ring_position); } - if (slave->sii_sync_count >= 2) { // mailbox configuration provided + if (slave->sii.sync_count >= 2) { // mailbox configuration provided ec_datagram_fpwr(datagram, slave->station_address, 0x0800, - EC_SYNC_PAGE_SIZE * slave->sii_sync_count); + EC_SYNC_PAGE_SIZE * slave->sii.sync_count); memset(datagram->data, 0x00, - EC_SYNC_PAGE_SIZE * slave->sii_sync_count); + EC_SYNC_PAGE_SIZE * slave->sii.sync_count); for (i = 0; i < 2; i++) { - ec_sync_config(&slave->sii_syncs[i], slave->sii_syncs[i].length, + ec_sync_config(&slave->sii.syncs[i], slave->sii.syncs[i].length, datagram->data + EC_SYNC_PAGE_SIZE * i); } } else { // no mailbox sync manager configurations provided @@ -320,17 +320,17 @@ void ec_fsm_slave_config_enter_mbox_sync( memset(datagram->data, 0x00, EC_SYNC_PAGE_SIZE * 2); ec_sync_init(&sync, slave, 0); - sync.physical_start_address = slave->sii_rx_mailbox_offset; + sync.physical_start_address = slave->sii.rx_mailbox_offset; sync.control_register = 0x26; sync.enable = 1; - ec_sync_config(&sync, slave->sii_rx_mailbox_size, + ec_sync_config(&sync, slave->sii.rx_mailbox_size, datagram->data + EC_SYNC_PAGE_SIZE * sync.index); ec_sync_init(&sync, slave, 1); - sync.physical_start_address = slave->sii_tx_mailbox_offset; + sync.physical_start_address = slave->sii.tx_mailbox_offset; sync.control_register = 0x22; sync.enable = 1; - ec_sync_config(&sync, slave->sii_tx_mailbox_size, + ec_sync_config(&sync, slave->sii.tx_mailbox_size, datagram->data + EC_SYNC_PAGE_SIZE * sync.index); } @@ -569,17 +569,17 @@ void ec_fsm_slave_config_enter_pdo_sync( ec_direction_t dir; uint16_t size; - if (!slave->sii_sync_count) { + if (!slave->sii.sync_count) { ec_fsm_slave_config_enter_fmmu(fsm); return; } - if (slave->sii_mailbox_protocols) { + if (slave->sii.mailbox_protocols) { offset = 2; // slave has mailboxes } else { offset = 0; } - num_syncs = slave->sii_sync_count - offset; + num_syncs = slave->sii.sync_count - offset; // configure sync managers for process data ec_datagram_fpwr(datagram, slave->station_address, @@ -588,7 +588,7 @@ void ec_fsm_slave_config_enter_pdo_sync( memset(datagram->data, 0x00, EC_SYNC_PAGE_SIZE * num_syncs); for (i = 0; i < num_syncs; i++) { - sync = &slave->sii_syncs[i + offset]; + sync = &slave->sii.syncs[i + offset]; dir = ec_sync_direction(sync); size = ec_pdo_mapping_total_size(&slave->config->mapping[dir]); ec_sync_config(sync, size, datagram->data + EC_SYNC_PAGE_SIZE * i); diff --git a/master/fsm_slave_scan.c b/master/fsm_slave_scan.c index 07fdaf651925dbb64bb06305041d39a74a1b2b3c..c39c895034fbd9cf81354c851301e6d80444acd6 100644 --- a/master/fsm_slave_scan.c +++ b/master/fsm_slave_scan.c @@ -465,25 +465,25 @@ void ec_fsm_slave_scan_state_eeprom_data(ec_fsm_slave_scan_t *fsm /**< slave sta // Evaluate EEPROM contents - slave->sii_alias = + slave->sii.alias = EC_READ_U16(slave->eeprom_data + 2 * 0x0004); - slave->sii_vendor_id = + slave->sii.vendor_id = EC_READ_U32(slave->eeprom_data + 2 * 0x0008); - slave->sii_product_code = + slave->sii.product_code = EC_READ_U32(slave->eeprom_data + 2 * 0x000A); - slave->sii_revision_number = + slave->sii.revision_number = EC_READ_U32(slave->eeprom_data + 2 * 0x000C); - slave->sii_serial_number = + slave->sii.serial_number = EC_READ_U32(slave->eeprom_data + 2 * 0x000E); - slave->sii_rx_mailbox_offset = + slave->sii.rx_mailbox_offset = EC_READ_U16(slave->eeprom_data + 2 * 0x0018); - slave->sii_rx_mailbox_size = + slave->sii.rx_mailbox_size = EC_READ_U16(slave->eeprom_data + 2 * 0x0019); - slave->sii_tx_mailbox_offset = + slave->sii.tx_mailbox_offset = EC_READ_U16(slave->eeprom_data + 2 * 0x001A); - slave->sii_tx_mailbox_size = + slave->sii.tx_mailbox_size = EC_READ_U16(slave->eeprom_data + 2 * 0x001B); - slave->sii_mailbox_protocols = + slave->sii.mailbox_protocols = EC_READ_U16(slave->eeprom_data + 2 * 0x001C); if (eeprom_word_size == EC_FIRST_EEPROM_CATEGORY_OFFSET) { @@ -568,7 +568,7 @@ void ec_fsm_slave_scan_state_eeprom_data(ec_fsm_slave_scan_t *fsm /**< slave sta } } - if (slave->sii_mailbox_protocols & EC_MBOX_COE) { + if (slave->sii.mailbox_protocols & EC_MBOX_COE) { ec_fsm_slave_scan_enter_preop(fsm); } else { fsm->state = ec_fsm_slave_scan_state_end; diff --git a/master/mailbox.c b/master/mailbox.c index feb02a452624956b6d7504d87653d1d68a06f8c3..4e7a847ffbe697616cabbf9c5dcebeee0110fc22 100644 --- a/master/mailbox.c +++ b/master/mailbox.c @@ -60,21 +60,21 @@ uint8_t *ec_slave_mbox_prepare_send(const ec_slave_t *slave, /**< slave */ { size_t total_size; - if (unlikely(!slave->sii_mailbox_protocols)) { + if (unlikely(!slave->sii.mailbox_protocols)) { EC_ERR("Slave %i does not support mailbox communication!\n", slave->ring_position); return NULL; } total_size = size + 6; - if (unlikely(total_size > slave->sii_rx_mailbox_size)) { + if (unlikely(total_size > slave->sii.rx_mailbox_size)) { EC_ERR("Data size does not fit in mailbox!\n"); return NULL; } if (ec_datagram_fpwr(datagram, slave->station_address, - slave->sii_rx_mailbox_offset, - slave->sii_rx_mailbox_size)) + slave->sii.rx_mailbox_offset, + slave->sii.rx_mailbox_size)) return NULL; EC_WRITE_U16(datagram->data, size); // mailbox service data length @@ -127,8 +127,8 @@ int ec_slave_mbox_prepare_fetch(const ec_slave_t *slave, /**< slave */ ) { if (ec_datagram_fprd(datagram, slave->station_address, - slave->sii_tx_mailbox_offset, - slave->sii_tx_mailbox_size)) return -1; + slave->sii.tx_mailbox_offset, + slave->sii.tx_mailbox_size)) return -1; return 0; } @@ -167,10 +167,10 @@ uint8_t *ec_slave_mbox_fetch(const ec_slave_t *slave, /**< slave */ data_size = EC_READ_U16(datagram->data); - if (data_size > slave->sii_tx_mailbox_size - 6) { + if (data_size > slave->sii.tx_mailbox_size - 6) { EC_ERR("Corrupt mailbox response received from slave %i!\n", slave->ring_position); - ec_print_data(datagram->data, slave->sii_tx_mailbox_size); + ec_print_data(datagram->data, slave->sii.tx_mailbox_size); return NULL; } diff --git a/master/slave.c b/master/slave.c index e1d602c054cf0ef633d50ef46dadd65357339f26..b9051af0130c4ca9afea42ecde1a76d001431c65 100644 --- a/master/slave.c +++ b/master/slave.c @@ -130,27 +130,27 @@ int ec_slave_init(ec_slave_t *slave, /**< EtherCAT slave */ slave->eeprom_data = NULL; slave->eeprom_size = 0; - slave->sii_alias = 0; - slave->sii_vendor_id = 0; - slave->sii_product_code = 0; - slave->sii_revision_number = 0; - slave->sii_serial_number = 0; - slave->sii_rx_mailbox_offset = 0; - slave->sii_rx_mailbox_size = 0; - slave->sii_tx_mailbox_offset = 0; - slave->sii_tx_mailbox_size = 0; - slave->sii_mailbox_protocols = 0; - slave->sii_group = NULL; - slave->sii_image = NULL; - slave->sii_order = NULL; - slave->sii_name = NULL; - slave->sii_current_on_ebus = 0; - - slave->sii_strings = NULL; - slave->sii_string_count = 0; - slave->sii_syncs = NULL; - slave->sii_sync_count = 0; - INIT_LIST_HEAD(&slave->sii_pdos); + slave->sii.alias = 0; + slave->sii.vendor_id = 0; + slave->sii.product_code = 0; + slave->sii.revision_number = 0; + slave->sii.serial_number = 0; + slave->sii.rx_mailbox_offset = 0; + slave->sii.rx_mailbox_size = 0; + slave->sii.tx_mailbox_offset = 0; + slave->sii.tx_mailbox_size = 0; + slave->sii.mailbox_protocols = 0; + slave->sii.group = NULL; + slave->sii.image = NULL; + slave->sii.order = NULL; + slave->sii.name = NULL; + slave->sii.current_on_ebus = 0; + + slave->sii.strings = NULL; + slave->sii.string_count = 0; + slave->sii.syncs = NULL; + slave->sii.sync_count = 0; + INIT_LIST_HEAD(&slave->sii.pdos); INIT_LIST_HEAD(&slave->sdo_dictionary); slave->sdo_dictionary_fetched = 0; @@ -160,7 +160,7 @@ int ec_slave_init(ec_slave_t *slave, /**< EtherCAT slave */ slave->dl_link[i] = 0; slave->dl_loop[i] = 0; slave->dl_signal[i] = 0; - slave->sii_physical_layer[i] = 0xFF; + slave->sii.physical_layer[i] = 0xFF; } // init kobject and add it to the hierarchy @@ -247,22 +247,22 @@ void ec_slave_clear(struct kobject *kobj /**< kobject of the slave */) slave = container_of(kobj, ec_slave_t, kobj); // free all strings - if (slave->sii_strings) { - for (i = 0; i < slave->sii_string_count; i++) - kfree(slave->sii_strings[i]); - kfree(slave->sii_strings); + if (slave->sii.strings) { + for (i = 0; i < slave->sii.string_count; i++) + kfree(slave->sii.strings[i]); + kfree(slave->sii.strings); } // free all sync managers - if (slave->sii_syncs) { - for (i = 0; i < slave->sii_sync_count; i++) { - ec_sync_clear(&slave->sii_syncs[i]); + if (slave->sii.syncs) { + for (i = 0; i < slave->sii.sync_count; i++) { + ec_sync_clear(&slave->sii.syncs[i]); } - kfree(slave->sii_syncs); + kfree(slave->sii.syncs); } // free all SII Pdos - list_for_each_entry_safe(pdo, next_pdo, &slave->sii_pdos, list) { + list_for_each_entry_safe(pdo, next_pdo, &slave->sii.pdos, list) { list_del(&pdo->list); ec_pdo_clear(pdo); kfree(pdo); @@ -367,40 +367,40 @@ int ec_slave_fetch_sii_strings( size_t size; off_t offset; - slave->sii_string_count = data[0]; + slave->sii.string_count = data[0]; - if (!slave->sii_string_count) + if (!slave->sii.string_count) return 0; - if (!(slave->sii_strings = - kmalloc(sizeof(char *) * slave->sii_string_count, + if (!(slave->sii.strings = + kmalloc(sizeof(char *) * slave->sii.string_count, GFP_KERNEL))) { EC_ERR("Failed to allocate string array memory.\n"); goto out_zero; } offset = 1; - for (i = 0; i < slave->sii_string_count; i++) { + for (i = 0; i < slave->sii.string_count; i++) { size = data[offset]; // allocate memory for string structure and data at a single blow - if (!(slave->sii_strings[i] = + if (!(slave->sii.strings[i] = kmalloc(sizeof(char) * size + 1, GFP_KERNEL))) { EC_ERR("Failed to allocate string memory.\n"); goto out_free; } - memcpy(slave->sii_strings[i], data + offset + 1, size); - slave->sii_strings[i][size] = 0x00; // append binary zero + memcpy(slave->sii.strings[i], data + offset + 1, size); + slave->sii.strings[i][size] = 0x00; // append binary zero offset += 1 + size; } return 0; out_free: - for (i--; i >= 0; i--) kfree(slave->sii_strings[i]); - kfree(slave->sii_strings); - slave->sii_strings = NULL; + for (i--; i >= 0; i--) kfree(slave->sii.strings[i]); + kfree(slave->sii.strings); + slave->sii.strings = NULL; out_zero: - slave->sii_string_count = 0; + slave->sii.string_count = 0; return -1; } @@ -425,16 +425,16 @@ int ec_slave_fetch_sii_general( return -1; } - slave->sii_group = ec_slave_sii_string(slave, data[0]); - slave->sii_image = ec_slave_sii_string(slave, data[1]); - slave->sii_order = ec_slave_sii_string(slave, data[2]); - slave->sii_name = ec_slave_sii_string(slave, data[3]); + slave->sii.group = ec_slave_sii_string(slave, data[0]); + slave->sii.image = ec_slave_sii_string(slave, data[1]); + slave->sii.order = ec_slave_sii_string(slave, data[2]); + slave->sii.name = ec_slave_sii_string(slave, data[3]); for (i = 0; i < 4; i++) - slave->sii_physical_layer[i] = + slave->sii.physical_layer[i] = (data[4] & (0x03 << (i * 2))) >> (i * 2); - slave->sii_current_on_ebus = EC_READ_S16(data + 0x0C); + slave->sii.current_on_ebus = EC_READ_S16(data + 0x0C); return 0; } @@ -463,18 +463,18 @@ int ec_slave_fetch_sii_syncs( return -1; } - slave->sii_sync_count = data_size / 8; + slave->sii.sync_count = data_size / 8; - memsize = sizeof(ec_sync_t) * slave->sii_sync_count; - if (!(slave->sii_syncs = kmalloc(memsize, GFP_KERNEL))) { + memsize = sizeof(ec_sync_t) * slave->sii.sync_count; + if (!(slave->sii.syncs = kmalloc(memsize, GFP_KERNEL))) { EC_ERR("Failed to allocate %u bytes for sync managers.\n", memsize); - slave->sii_sync_count = 0; + slave->sii.sync_count = 0; return -1; } - for (i = 0; i < slave->sii_sync_count; i++, data += 8) { - sync = &slave->sii_syncs[i]; + for (i = 0; i < slave->sii.sync_count; i++, data += 8) { + sync = &slave->sii.syncs[i]; ec_sync_init(sync, slave, i); sync->physical_start_address = EC_READ_U16(data); @@ -521,7 +521,7 @@ int ec_slave_fetch_sii_pdos( kfree(pdo); return -1; } - list_add_tail(&pdo->list, &slave->sii_pdos); + list_add_tail(&pdo->list, &slave->sii.pdos); data_size -= 8; data += 8; @@ -552,12 +552,12 @@ int ec_slave_fetch_sii_pdos( if (pdo->sync_index >= 0) { ec_sync_t *sync; - if (pdo->sync_index >= slave->sii_sync_count) { + if (pdo->sync_index >= slave->sii.sync_count) { EC_ERR("Invalid SM index %i for Pdo 0x%04X in slave %u.", pdo->sync_index, pdo->index, slave->ring_position); return -1; } - sync = &slave->sii_syncs[pdo->sync_index]; + sync = &slave->sii.syncs[pdo->sync_index]; if (ec_pdo_mapping_add_pdo(&sync->mapping, pdo)) return -1; @@ -584,14 +584,14 @@ char *ec_slave_sii_string( if (!index--) return NULL; - if (index >= slave->sii_string_count) { + if (index >= slave->sii.string_count) { if (slave->master->debug_level) EC_WARN("String %u not found in slave %u.\n", index, slave->ring_position); return NULL; } - return slave->sii_strings[index]; + return slave->sii.strings[index]; } /*****************************************************************************/ @@ -627,8 +627,8 @@ ssize_t ec_slave_info(const ec_slave_t *slave, /**< EtherCAT slave */ buf += sprintf(buf, "Data link status:\n"); for (i = 0; i < 4; i++) { buf += sprintf(buf, " Port %u: Phy %u (", - i, slave->sii_physical_layer[i]); - switch (slave->sii_physical_layer[i]) { + i, slave->sii.physical_layer[i]); + switch (slave->sii.physical_layer[i]) { case 0x00: buf += sprintf(buf, "EBUS"); break; @@ -648,53 +648,53 @@ ssize_t ec_slave_info(const ec_slave_t *slave, /**< EtherCAT slave */ } buf += sprintf(buf, "\n"); - if (slave->sii_alias) + if (slave->sii.alias) buf += sprintf(buf, "Configured station alias:" - " 0x%04X (%u)\n\n", slave->sii_alias, slave->sii_alias); + " 0x%04X (%u)\n\n", slave->sii.alias, slave->sii.alias); buf += sprintf(buf, "Identity:\n"); buf += sprintf(buf, " Vendor ID: 0x%08X (%u)\n", - slave->sii_vendor_id, slave->sii_vendor_id); + slave->sii.vendor_id, slave->sii.vendor_id); buf += sprintf(buf, " Product code: 0x%08X (%u)\n", - slave->sii_product_code, slave->sii_product_code); + slave->sii.product_code, slave->sii.product_code); buf += sprintf(buf, " Revision number: 0x%08X (%u)\n", - slave->sii_revision_number, slave->sii_revision_number); + slave->sii.revision_number, slave->sii.revision_number); buf += sprintf(buf, " Serial number: 0x%08X (%u)\n\n", - slave->sii_serial_number, slave->sii_serial_number); + slave->sii.serial_number, slave->sii.serial_number); - if (slave->sii_mailbox_protocols) { + if (slave->sii.mailbox_protocols) { buf += sprintf(buf, "Mailboxes:\n"); buf += sprintf(buf, " RX: 0x%04X/%u, TX: 0x%04X/%u\n", - slave->sii_rx_mailbox_offset, slave->sii_rx_mailbox_size, - slave->sii_tx_mailbox_offset, slave->sii_tx_mailbox_size); + slave->sii.rx_mailbox_offset, slave->sii.rx_mailbox_size, + slave->sii.tx_mailbox_offset, slave->sii.tx_mailbox_size); buf += sprintf(buf, " Supported protocols: "); first = 1; - if (slave->sii_mailbox_protocols & EC_MBOX_AOE) { + if (slave->sii.mailbox_protocols & EC_MBOX_AOE) { buf += sprintf(buf, "AoE"); first = 0; } - if (slave->sii_mailbox_protocols & EC_MBOX_EOE) { + if (slave->sii.mailbox_protocols & EC_MBOX_EOE) { if (!first) buf += sprintf(buf, ", "); buf += sprintf(buf, "EoE"); first = 0; } - if (slave->sii_mailbox_protocols & EC_MBOX_COE) { + if (slave->sii.mailbox_protocols & EC_MBOX_COE) { if (!first) buf += sprintf(buf, ", "); buf += sprintf(buf, "CoE"); first = 0; } - if (slave->sii_mailbox_protocols & EC_MBOX_FOE) { + if (slave->sii.mailbox_protocols & EC_MBOX_FOE) { if (!first) buf += sprintf(buf, ", "); buf += sprintf(buf, "FoE"); first = 0; } - if (slave->sii_mailbox_protocols & EC_MBOX_SOE) { + if (slave->sii.mailbox_protocols & EC_MBOX_SOE) { if (!first) buf += sprintf(buf, ", "); buf += sprintf(buf, "SoE"); first = 0; } - if (slave->sii_mailbox_protocols & EC_MBOX_VOE) { + if (slave->sii.mailbox_protocols & EC_MBOX_VOE) { if (!first) buf += sprintf(buf, ", "); buf += sprintf(buf, "VoE"); } @@ -702,29 +702,29 @@ ssize_t ec_slave_info(const ec_slave_t *slave, /**< EtherCAT slave */ } buf += sprintf(buf, "Current consumption: %i mA\n\n", - slave->sii_current_on_ebus); + slave->sii.current_on_ebus); - if (slave->sii_group || slave->sii_image || slave->sii_order - || slave->sii_name) { + if (slave->sii.group || slave->sii.image || slave->sii.order + || slave->sii.name) { buf += sprintf(buf, "General:\n"); - if (slave->sii_group) - buf += sprintf(buf, " Group: %s\n", slave->sii_group); - if (slave->sii_image) - buf += sprintf(buf, " Image: %s\n", slave->sii_image); - if (slave->sii_order) + if (slave->sii.group) + buf += sprintf(buf, " Group: %s\n", slave->sii.group); + if (slave->sii.image) + buf += sprintf(buf, " Image: %s\n", slave->sii.image); + if (slave->sii.order) buf += sprintf(buf, " Order number: %s\n", - slave->sii_order); - if (slave->sii_name) - buf += sprintf(buf, " Name: %s\n", slave->sii_name); + slave->sii.order); + if (slave->sii.name) + buf += sprintf(buf, " Name: %s\n", slave->sii.name); buf += sprintf(buf, "\n"); } - if (slave->sii_sync_count) { + if (slave->sii.sync_count) { buf += sprintf(buf, "Sync managers / Pdo mapping:\n"); - for (i = 0; i < slave->sii_sync_count; i++) { - sync = &slave->sii_syncs[i]; + for (i = 0; i < slave->sii.sync_count; i++) { + sync = &slave->sii.syncs[i]; buf += sprintf(buf, " SM%u: addr 0x%04X, size %u, control 0x%02X, %s\n", sync->index, sync->physical_start_address, @@ -758,10 +758,10 @@ ssize_t ec_slave_info(const ec_slave_t *slave, /**< EtherCAT slave */ } // type-cast to avoid warnings on some compilers - if (!list_empty((struct list_head *) &slave->sii_pdos)) { + if (!list_empty((struct list_head *) &slave->sii.pdos)) { buf += sprintf(buf, "Available Pdos from SII:\n"); - list_for_each_entry(pdo, &slave->sii_pdos, list) { + list_for_each_entry(pdo, &slave->sii.pdos, list) { buf += sprintf(buf, " %s 0x%04X \"%s\"", pdo->dir == EC_DIR_OUTPUT ? "RxPdo" : "TxPdo", pdo->index, pdo->name ? pdo->name : "???"); @@ -1005,7 +1005,7 @@ ssize_t ec_slave_write_alias(ec_slave_t *slave, /**< EtherCAT slave */ if ((ret = ec_slave_schedule_eeprom_writing(&request))) return ret; // error code - slave->sii_alias = alias; // FIXME: do this in state machine + slave->sii.alias = alias; // FIXME: do this in state machine return size; // success } @@ -1056,7 +1056,7 @@ ssize_t ec_show_slave_attribute(struct kobject *kobj, /**< slave's kobject */ } } else if (attr == &attr_alias) { - return sprintf(buffer, "%u\n", slave->sii_alias); + return sprintf(buffer, "%u\n", slave->sii.alias); } return 0; @@ -1127,12 +1127,12 @@ ec_sync_t *ec_slave_get_pdo_sync( } sync_index = (unsigned int) dir; - if (slave->sii_mailbox_protocols) sync_index += 2; + if (slave->sii.mailbox_protocols) sync_index += 2; - if (sync_index >= slave->sii_sync_count) + if (sync_index >= slave->sii.sync_count) return NULL; - return &slave->sii_syncs[sync_index]; + return &slave->sii.syncs[sync_index]; } /*****************************************************************************/ @@ -1146,12 +1146,12 @@ int ec_slave_validate(const ec_slave_t *slave, /**< EtherCAT slave */ uint32_t product_code /**< product code */ ) { - if (vendor_id != slave->sii_vendor_id || - product_code != slave->sii_product_code) { + if (vendor_id != slave->sii.vendor_id || + product_code != slave->sii.product_code) { EC_ERR("Invalid slave type at position %u:\n", slave->ring_position); EC_ERR(" Requested: 0x%08X 0x%08X\n", vendor_id, product_code); EC_ERR(" Found: 0x%08X 0x%08X\n", - slave->sii_vendor_id, slave->sii_product_code); + slave->sii.vendor_id, slave->sii.product_code); return -1; } return 0; @@ -1220,8 +1220,8 @@ const ec_pdo_t *ec_slave_find_pdo( const ec_sync_t *sync; const ec_pdo_t *pdo; - for (i = 0; i < slave->sii_sync_count; i++) { - sync = &slave->sii_syncs[i]; + for (i = 0; i < slave->sii.sync_count; i++) { + sync = &slave->sii.syncs[i]; if (!(pdo = ec_pdo_mapping_find_pdo(&sync->mapping, index))) continue; diff --git a/master/slave.h b/master/slave.h index 78cd190a46fc2f6472a3e26ac61d9f308dc5fc92..211236f5b78be75b7ea8086b7ec5325504298274 100644 --- a/master/slave.h +++ b/master/slave.h @@ -103,6 +103,43 @@ enum { /*****************************************************************************/ +/** Slave information interface data. + */ +typedef struct { + // Non-category data + uint16_t alias; /**< Configured station alias. */ + uint32_t vendor_id; /**< Vendor ID. */ + uint32_t product_code; /**< Vendor-specific product code. */ + uint32_t revision_number; /**< Revision number. */ + uint32_t serial_number; /**< Serial number. */ + uint16_t rx_mailbox_offset; /**< Mailbox address (master to slave). */ + uint16_t rx_mailbox_size; /**< Mailbox size (master to slave). */ + uint16_t tx_mailbox_offset; /**< Mailbox address (slave to master). */ + uint16_t tx_mailbox_size; /**< Mailbox size (slave to master). */ + uint16_t mailbox_protocols; /**< Supported mailbox protocols. */ + + // Strings + char **strings; /**< Strings in EEPROM categories. */ + unsigned int string_count; /**< number of EEPROM strings */ + + // General + uint8_t physical_layer[4]; /**< port media */ + char *group; /**< slave group acc. to EEPROM */ + char *image; /**< slave image name acc. to EEPROM */ + char *order; /**< slave order number acc. to EEPROM */ + char *name; /**< slave name acc. to EEPROM */ + int16_t current_on_ebus; /**< power consumption */ + + // SyncM + ec_sync_t *syncs; /**< EEPROM SYNC MANAGER categories */ + unsigned int sync_count; /**< number of sync managers in EEPROM */ + + // [RT]XPDO + struct list_head pdos; /**< EEPROM [RT]XPDO categories */ +} ec_sii_t; + +/*****************************************************************************/ + /** EtherCAT slave. */ struct ec_slave @@ -139,27 +176,7 @@ struct ec_slave size_t eeprom_size; /**< size of the EEPROM contents in bytes */ // slave information interface - uint16_t sii_alias; /**< configured station alias */ - uint32_t sii_vendor_id; /**< vendor id */ - uint32_t sii_product_code; /**< vendor's product code */ - uint32_t sii_revision_number; /**< revision number */ - uint32_t sii_serial_number; /**< serial number */ - uint16_t sii_rx_mailbox_offset; /**< mailbox address (master to slave) */ - uint16_t sii_rx_mailbox_size; /**< mailbox size (master to slave) */ - uint16_t sii_tx_mailbox_offset; /**< mailbox address (slave to master) */ - uint16_t sii_tx_mailbox_size; /**< mailbox size (slave to master) */ - uint16_t sii_mailbox_protocols; /**< supported mailbox protocols */ - uint8_t sii_physical_layer[4]; /**< port media */ - char **sii_strings; /**< strings in EEPROM categories */ - unsigned int sii_string_count; /**< number of EEPROM strings */ - ec_sync_t *sii_syncs; /**< EEPROM SYNC MANAGER categories */ - unsigned int sii_sync_count; /**< number of sync managers in EEPROM */ - struct list_head sii_pdos; /**< EEPROM [RT]XPDO categories */ - char *sii_group; /**< slave group acc. to EEPROM */ - char *sii_image; /**< slave image name acc. to EEPROM */ - char *sii_order; /**< slave order number acc. to EEPROM */ - char *sii_name; /**< slave name acc. to EEPROM */ - int16_t sii_current_on_ebus; /**< power consumption */ + ec_sii_t sii; /**< SII data. */ struct kobject sdo_kobj; /**< kobject for Sdos */ struct list_head sdo_dictionary; /**< Sdo dictionary list */ diff --git a/master/slave_config.c b/master/slave_config.c index eaf3aae25a74ea3c8cec54c2e1b381f1ae6c5d42..4064b41a2a3d210cc1984383070bc55a399c0f27 100644 --- a/master/slave_config.c +++ b/master/slave_config.c @@ -312,7 +312,7 @@ int ec_slave_config_sdo(ec_slave_config_t *sc, uint16_t index, ec_slave_t *slave = sc->slave; ec_sdo_data_t *sdodata; - if (slave && !(slave->sii_mailbox_protocols & EC_MBOX_COE)) { + if (slave && !(slave->sii.mailbox_protocols & EC_MBOX_COE)) { EC_ERR("Slave %u does not support CoE!\n", slave->ring_position); return -1; } @@ -359,7 +359,7 @@ int ec_slave_config_attach( list_for_each_entry(slave, &sc->master->slaves, list) { if (!alias_found) { - if (sc->alias && slave->sii_alias != sc->alias) + if (sc->alias && slave->sii.alias != sc->alias) continue; alias_found = 1; relative_position = 0; @@ -380,12 +380,12 @@ found: sc->position, slave->ring_position); return -2; } - if (slave->sii_vendor_id != sc->vendor_id - || slave->sii_product_code != sc->product_code) { + if (slave->sii.vendor_id != sc->vendor_id + || slave->sii.product_code != sc->product_code) { EC_ERR("Slave %u has an invalid type (0x%08X/0x%08X) for" " configuration %u:%u (0x%08X/0x%08X).\n", - slave->ring_position, slave->sii_vendor_id, - slave->sii_product_code, sc->alias, sc->position, + slave->ring_position, slave->sii.vendor_id, + slave->sii.product_code, sc->alias, sc->position, sc->vendor_id, sc->product_code); return -3; } diff --git a/master/sync.c b/master/sync.c index 6e902fc0a5b2dd6fe057bbaf53a747379745fa8b..96b6ab7304be2417998fa7c3e341545c419e56fb 100644 --- a/master/sync.c +++ b/master/sync.c @@ -122,7 +122,7 @@ ec_direction_t ec_sync_direction( { int index = sync->index; - if (sync->slave && sync->slave->sii_mailbox_protocols) { + if (sync->slave && sync->slave->sii.mailbox_protocols) { index -= 2; }