fp@39: /****************************************************************************** fp@0: * fp@54: * s l a v e . c fp@0: * fp@123: * Methoden für einen EtherCAT-Slave. fp@0: * fp@39: * $Id$ fp@0: * fp@39: *****************************************************************************/ fp@0: fp@24: #include fp@73: #include fp@0: fp@54: #include "globals.h" fp@54: #include "slave.h" fp@98: #include "command.h" fp@98: #include "master.h" fp@0: fp@39: /*****************************************************************************/ fp@0: fp@118: int ec_slave_fetch_categories(ec_slave_t *); fp@118: int ec_slave_fetch_strings(ec_slave_t *, const uint8_t *); fp@123: int ec_slave_fetch_general(ec_slave_t *, const uint8_t *); fp@126: int ec_slave_fetch_sync(ec_slave_t *, const uint8_t *, size_t); fp@126: int ec_slave_fetch_pdo(ec_slave_t *, const uint8_t *, size_t, ec_pdo_type_t); fp@123: int ec_slave_locate_string(ec_slave_t *, unsigned int, char **); fp@118: fp@118: /*****************************************************************************/ fp@118: fp@0: /** fp@0: EtherCAT-Slave-Konstruktor. fp@73: */ fp@73: fp@73: void ec_slave_init(ec_slave_t *slave, /**< EtherCAT-Slave */ fp@73: ec_master_t *master /**< EtherCAT-Master */ fp@73: ) fp@73: { fp@142: unsigned int i; fp@142: fp@73: slave->master = master; fp@73: slave->base_type = 0; fp@73: slave->base_revision = 0; fp@73: slave->base_build = 0; fp@73: slave->base_fmmu_count = 0; fp@73: slave->base_sync_count = 0; fp@142: for (i = 0; i < 2; i++) { fp@142: slave->dl_status_link[i] = 0; fp@142: slave->dl_status_loop[i] = 0; fp@142: slave->dl_status_comm[i] = 0; fp@142: } fp@73: slave->ring_position = 0; fp@73: slave->station_address = 0; fp@114: slave->sii_alias = 0; fp@73: slave->sii_vendor_id = 0; fp@73: slave->sii_product_code = 0; fp@73: slave->sii_revision_number = 0; fp@73: slave->sii_serial_number = 0; fp@136: slave->sii_rx_mailbox_offset = 0; fp@136: slave->sii_rx_mailbox_size = 0; fp@136: slave->sii_tx_mailbox_offset = 0; fp@136: slave->sii_tx_mailbox_size = 0; fp@133: slave->sii_mailbox_protocols = 0; fp@73: slave->type = NULL; fp@73: slave->registered = 0; fp@73: slave->fmmu_count = 0; fp@121: slave->eeprom_name = NULL; fp@121: slave->eeprom_group = NULL; fp@121: slave->eeprom_desc = NULL; fp@126: INIT_LIST_HEAD(&slave->eeprom_strings); fp@126: INIT_LIST_HEAD(&slave->eeprom_syncs); fp@126: INIT_LIST_HEAD(&slave->eeprom_pdos); fp@135: INIT_LIST_HEAD(&slave->sdo_dictionary); fp@73: } fp@73: fp@73: /*****************************************************************************/ fp@73: fp@73: /** fp@73: EtherCAT-Slave-Destruktor. fp@73: */ fp@73: fp@73: void ec_slave_clear(ec_slave_t *slave /**< EtherCAT-Slave */) fp@73: { fp@126: ec_eeprom_string_t *string, *next_str; fp@126: ec_eeprom_sync_t *sync, *next_sync; fp@126: ec_eeprom_pdo_t *pdo, *next_pdo; fp@126: ec_eeprom_pdo_entry_t *entry, *next_ent; fp@135: ec_sdo_t *sdo, *next_sdo; fp@139: ec_sdo_entry_t *en, *next_en; fp@118: fp@118: // Alle Strings freigeben fp@126: list_for_each_entry_safe(string, next_str, &slave->eeprom_strings, list) { fp@118: list_del(&string->list); fp@118: kfree(string); fp@118: } fp@121: fp@126: // Alle Sync-Manager freigeben fp@126: list_for_each_entry_safe(sync, next_sync, &slave->eeprom_syncs, list) { fp@126: list_del(&sync->list); fp@126: kfree(sync); fp@126: } fp@126: fp@126: // Alle PDOs freigeben fp@126: list_for_each_entry_safe(pdo, next_pdo, &slave->eeprom_pdos, list) { fp@126: list_del(&pdo->list); fp@126: if (pdo->name) kfree(pdo->name); fp@126: fp@126: // Alle Entries innerhalb eines PDOs freigeben fp@126: list_for_each_entry_safe(entry, next_ent, &pdo->entries, list) { fp@126: list_del(&entry->list); fp@126: if (entry->name) kfree(entry->name); fp@126: kfree(entry); fp@126: } fp@126: fp@126: kfree(pdo); fp@126: } fp@126: fp@121: if (slave->eeprom_name) kfree(slave->eeprom_name); fp@121: if (slave->eeprom_group) kfree(slave->eeprom_group); fp@121: if (slave->eeprom_desc) kfree(slave->eeprom_desc); fp@135: fp@135: // Alle SDOs freigeben fp@135: list_for_each_entry_safe(sdo, next_sdo, &slave->sdo_dictionary, list) { fp@135: list_del(&sdo->list); fp@135: if (sdo->name) kfree(sdo->name); fp@139: // Alle Entries freigeben fp@139: list_for_each_entry_safe(en, next_en, &sdo->entries, list) { fp@139: list_del(&en->list); fp@139: kfree(en); fp@139: } fp@135: kfree(sdo); fp@135: } fp@121: } fp@121: fp@121: /*****************************************************************************/ fp@121: fp@121: /** fp@122: Liest alle benötigten Informationen aus einem Slave. fp@91: fp@91: \return 0 wenn alles ok, < 0 bei Fehler. fp@73: */ fp@73: fp@73: int ec_slave_fetch(ec_slave_t *slave /**< EtherCAT-Slave */) fp@73: { fp@98: ec_command_t command; fp@142: unsigned int i; fp@142: uint16_t dl_status; fp@73: fp@73: // Read base data fp@98: ec_command_init_nprd(&command, slave->station_address, 0x0000, 6); fp@98: if (unlikely(ec_master_simple_io(slave->master, &command))) { fp@142: EC_ERR("Reading base data from slave %i failed!\n", fp@84: slave->ring_position); fp@73: return -1; fp@73: } fp@73: fp@98: slave->base_type = EC_READ_U8 (command.data); fp@98: slave->base_revision = EC_READ_U8 (command.data + 1); fp@98: slave->base_build = EC_READ_U16(command.data + 2); fp@98: slave->base_fmmu_count = EC_READ_U8 (command.data + 4); fp@98: slave->base_sync_count = EC_READ_U8 (command.data + 5); fp@73: fp@73: if (slave->base_fmmu_count > EC_MAX_FMMUS) fp@73: slave->base_fmmu_count = EC_MAX_FMMUS; fp@73: fp@142: // Read DL status fp@142: ec_command_init_nprd(&command, slave->station_address, 0x0110, 2); fp@142: if (unlikely(ec_master_simple_io(slave->master, &command))) { fp@142: EC_ERR("Reading DL status from slave %i failed!\n", fp@142: slave->ring_position); fp@142: return -1; fp@142: } fp@142: fp@142: dl_status = EC_READ_U16(command.data); fp@142: for (i = 0; i < 2; i++) { fp@142: slave->dl_status_link[i] = dl_status & (1 << (4 + i)) ? 1 : 0; fp@142: slave->dl_status_loop[i] = dl_status & (1 << (8 + i * 2)) ? 1 : 0; fp@142: slave->dl_status_comm[i] = dl_status & (1 << (9 + i * 2)) ? 1 : 0; fp@142: } fp@142: fp@142: // Read EEPROM data fp@136: if (ec_slave_sii_read16(slave, 0x0004, &slave->sii_alias)) fp@136: return -1; fp@136: if (ec_slave_sii_read32(slave, 0x0008, &slave->sii_vendor_id)) fp@136: return -1; fp@136: if (ec_slave_sii_read32(slave, 0x000A, &slave->sii_product_code)) fp@136: return -1; fp@136: if (ec_slave_sii_read32(slave, 0x000C, &slave->sii_revision_number)) fp@136: return -1; fp@136: if (ec_slave_sii_read32(slave, 0x000E, &slave->sii_serial_number)) fp@136: return -1; fp@136: if (ec_slave_sii_read16(slave, 0x0018, &slave->sii_rx_mailbox_offset)) fp@136: return -1; fp@136: if (ec_slave_sii_read16(slave, 0x0019, &slave->sii_rx_mailbox_size)) fp@136: return -1; fp@136: if (ec_slave_sii_read16(slave, 0x001A, &slave->sii_tx_mailbox_offset)) fp@136: return -1; fp@136: if (ec_slave_sii_read16(slave, 0x001B, &slave->sii_tx_mailbox_size)) fp@136: return -1; fp@136: if (ec_slave_sii_read16(slave, 0x001C, &slave->sii_mailbox_protocols)) fp@136: return -1; fp@133: fp@118: if (unlikely(ec_slave_fetch_categories(slave))) { fp@136: EC_ERR("Failed to fetch category data!\n"); fp@118: return -1; fp@118: } fp@118: fp@73: return 0; fp@73: } fp@73: fp@73: /*****************************************************************************/ fp@73: fp@73: /** fp@136: Liest 16 Bit aus dem Slave-Information-Interface fp@73: eines EtherCAT-Slaves. fp@73: fp@73: \return 0 bei Erfolg, sonst < 0 fp@73: */ fp@73: fp@136: int ec_slave_sii_read16(ec_slave_t *slave, fp@136: /**< EtherCAT-Slave */ fp@136: uint16_t offset, fp@136: /**< Adresse des zu lesenden SII-Registers */ fp@136: uint16_t *target fp@136: /**< Speicher für Wert (16-Bit) */ fp@136: ) fp@73: { fp@98: ec_command_t command; fp@101: uint8_t data[10]; fp@98: cycles_t start, end, timeout; fp@73: fp@73: // Initiate read operation fp@73: fp@114: EC_WRITE_U8 (data, 0x00); // read-only access fp@114: EC_WRITE_U8 (data + 1, 0x01); // request read operation fp@114: EC_WRITE_U32(data + 2, offset); fp@73: fp@98: ec_command_init_npwr(&command, slave->station_address, 0x502, 6, data); fp@98: if (unlikely(ec_master_simple_io(slave->master, &command))) { fp@89: EC_ERR("SII-read failed on slave %i!\n", slave->ring_position); fp@73: return -1; fp@73: } fp@73: fp@73: // Der Slave legt die Informationen des Slave-Information-Interface fp@122: // in das Datenregister und löscht daraufhin ein Busy-Bit. Solange fp@73: // den Status auslesen, bis das Bit weg ist. fp@73: fp@98: start = get_cycles(); fp@119: timeout = (cycles_t) 100 * cpu_khz; // 100ms fp@98: fp@113: while (1) fp@73: { fp@113: udelay(10); fp@113: fp@98: ec_command_init_nprd(&command, slave->station_address, 0x502, 10); fp@98: if (unlikely(ec_master_simple_io(slave->master, &command))) { fp@89: EC_ERR("Getting SII-read status failed on slave %i!\n", fp@84: slave->ring_position); fp@73: return -1; fp@73: } fp@73: fp@98: end = get_cycles(); fp@98: fp@98: if (likely((EC_READ_U8(command.data + 1) & 0x81) == 0)) { fp@136: *target = EC_READ_U16(command.data + 6); fp@136: return 0; fp@136: } fp@136: fp@136: if (unlikely((end - start) >= timeout)) { fp@136: EC_ERR("SII-read. Slave %i timed out!\n", slave->ring_position); fp@136: return -1; fp@136: } fp@136: } fp@136: } fp@136: fp@136: /*****************************************************************************/ fp@136: fp@136: /** fp@136: Liest 32 Bit aus dem Slave-Information-Interface fp@136: eines EtherCAT-Slaves. fp@136: fp@136: \return 0 bei Erfolg, sonst < 0 fp@136: */ fp@136: fp@136: int ec_slave_sii_read32(ec_slave_t *slave, fp@136: /**< EtherCAT-Slave */ fp@136: uint16_t offset, fp@136: /**< Adresse des zu lesenden SII-Registers */ fp@136: uint32_t *target fp@136: /**< Speicher für Wert (32-Bit) */ fp@136: ) fp@136: { fp@136: ec_command_t command; fp@136: uint8_t data[10]; fp@136: cycles_t start, end, timeout; fp@136: fp@136: // Initiate read operation fp@136: fp@136: EC_WRITE_U8 (data, 0x00); // read-only access fp@136: EC_WRITE_U8 (data + 1, 0x01); // request read operation fp@136: EC_WRITE_U32(data + 2, offset); fp@136: fp@136: ec_command_init_npwr(&command, slave->station_address, 0x502, 6, data); fp@136: if (unlikely(ec_master_simple_io(slave->master, &command))) { fp@136: EC_ERR("SII-read failed on slave %i!\n", slave->ring_position); fp@136: return -1; fp@136: } fp@136: fp@136: // Der Slave legt die Informationen des Slave-Information-Interface fp@136: // in das Datenregister und löscht daraufhin ein Busy-Bit. Solange fp@136: // den Status auslesen, bis das Bit weg ist. fp@136: fp@136: start = get_cycles(); fp@136: timeout = (cycles_t) 100 * cpu_khz; // 100ms fp@136: fp@136: while (1) fp@136: { fp@136: udelay(10); fp@136: fp@136: ec_command_init_nprd(&command, slave->station_address, 0x502, 10); fp@136: if (unlikely(ec_master_simple_io(slave->master, &command))) { fp@136: EC_ERR("Getting SII-read status failed on slave %i!\n", fp@136: slave->ring_position); fp@136: return -1; fp@136: } fp@136: fp@136: end = get_cycles(); fp@136: fp@136: if (likely((EC_READ_U8(command.data + 1) & 0x81) == 0)) { fp@114: *target = EC_READ_U32(command.data + 6); fp@113: return 0; fp@113: } fp@113: fp@113: if (unlikely((end - start) >= timeout)) { fp@118: EC_ERR("SII-read. Slave %i timed out!\n", slave->ring_position); fp@113: return -1; fp@113: } fp@113: } fp@73: } fp@73: fp@73: /*****************************************************************************/ fp@73: fp@73: /** fp@136: Schreibt 16 Bit Daten in das Slave-Information-Interface fp@114: eines EtherCAT-Slaves. fp@114: fp@114: \return 0 bei Erfolg, sonst < 0 fp@114: */ fp@114: fp@136: int ec_slave_sii_write16(ec_slave_t *slave, fp@136: /**< EtherCAT-Slave */ fp@136: uint16_t offset, fp@136: /**< Adresse des zu lesenden SII-Registers */ fp@136: uint16_t value fp@136: /**< Zu schreibender Wert */ fp@136: ) fp@114: { fp@114: ec_command_t command; fp@114: uint8_t data[8]; fp@114: cycles_t start, end, timeout; fp@114: fp@114: EC_INFO("SII-write (slave %i, offset 0x%04X, value 0x%04X)\n", fp@114: slave->ring_position, offset, value); fp@114: fp@114: // Initiate write operation fp@114: fp@114: EC_WRITE_U8 (data, 0x01); // enable write access fp@114: EC_WRITE_U8 (data + 1, 0x02); // request write operation fp@114: EC_WRITE_U32(data + 2, offset); fp@114: EC_WRITE_U16(data + 6, value); fp@114: fp@114: ec_command_init_npwr(&command, slave->station_address, 0x502, 8, data); fp@114: if (unlikely(ec_master_simple_io(slave->master, &command))) { fp@114: EC_ERR("SII-write failed on slave %i!\n", slave->ring_position); fp@114: return -1; fp@114: } fp@114: fp@114: // Der Slave legt die Informationen des Slave-Information-Interface fp@122: // in das Datenregister und löscht daraufhin ein Busy-Bit. Solange fp@114: // den Status auslesen, bis das Bit weg ist. fp@114: fp@114: start = get_cycles(); fp@119: timeout = (cycles_t) 100 * cpu_khz; // 100ms fp@114: fp@114: while (1) fp@114: { fp@114: udelay(10); fp@114: fp@114: ec_command_init_nprd(&command, slave->station_address, 0x502, 2); fp@114: if (unlikely(ec_master_simple_io(slave->master, &command))) { fp@114: EC_ERR("Getting SII-write status failed on slave %i!\n", fp@114: slave->ring_position); fp@114: return -1; fp@114: } fp@114: fp@114: end = get_cycles(); fp@114: fp@114: if (likely((EC_READ_U8(command.data + 1) & 0x82) == 0)) { fp@114: if (EC_READ_U8(command.data + 1) & 0x40) { fp@114: EC_ERR("SII-write failed!\n"); fp@114: return -1; fp@114: } fp@114: else { fp@114: EC_INFO("SII-write succeeded!\n"); fp@114: return 0; fp@114: } fp@114: } fp@114: fp@114: if (unlikely((end - start) >= timeout)) { fp@118: EC_ERR("SII-write: Slave %i timed out!\n", slave->ring_position); fp@118: return -1; fp@118: } fp@118: } fp@118: } fp@118: fp@118: /*****************************************************************************/ fp@118: fp@118: /** fp@118: Holt Daten aus dem EEPROM. fp@118: fp@118: \return 0, wenn alles ok, sonst < 0 fp@118: */ fp@118: fp@118: int ec_slave_fetch_categories(ec_slave_t *slave /**< EtherCAT-Slave */) fp@118: { fp@126: uint16_t word_offset, cat_type, word_count; fp@118: uint32_t value; fp@118: uint8_t *cat_data; fp@118: unsigned int i; fp@118: fp@118: word_offset = 0x0040; fp@118: fp@118: if (!(cat_data = (uint8_t *) kmalloc(0x10000, GFP_KERNEL))) { fp@118: EC_ERR("Failed to allocate 64k bytes for category data.\n"); fp@118: return -1; fp@118: } fp@118: fp@118: while (1) { fp@126: // read category type fp@136: if (ec_slave_sii_read32(slave, word_offset, &value)) { fp@126: EC_ERR("Unable to read category header.\n"); fp@123: goto out_free; fp@118: } fp@118: fp@118: // Last category? fp@118: if ((value & 0xFFFF) == 0xFFFF) break; fp@118: fp@126: cat_type = value & 0x7FFF; fp@118: word_count = (value >> 16) & 0xFFFF; fp@118: fp@118: // Fetch category data fp@118: for (i = 0; i < word_count; i++) { fp@136: if (ec_slave_sii_read32(slave, word_offset + 2 + i, &value)) { fp@118: EC_ERR("Unable to read category data word %i.\n", i); fp@123: goto out_free; fp@118: } fp@118: fp@118: cat_data[i * 2] = (value >> 0) & 0xFF; fp@118: cat_data[i * 2 + 1] = (value >> 8) & 0xFF; fp@118: fp@118: // read second word "on the fly" fp@118: if (i + 1 < word_count) { fp@118: i++; fp@118: cat_data[i * 2] = (value >> 16) & 0xFF; fp@118: cat_data[i * 2 + 1] = (value >> 24) & 0xFF; fp@118: } fp@118: } fp@118: fp@126: switch (cat_type) fp@118: { fp@118: case 0x000A: fp@123: if (ec_slave_fetch_strings(slave, cat_data)) fp@123: goto out_free; fp@118: break; fp@118: case 0x001E: fp@123: if (ec_slave_fetch_general(slave, cat_data)) fp@123: goto out_free; fp@118: break; fp@118: case 0x0028: fp@118: break; fp@118: case 0x0029: fp@126: if (ec_slave_fetch_sync(slave, cat_data, word_count)) fp@126: goto out_free; fp@118: break; fp@118: case 0x0032: fp@126: if (ec_slave_fetch_pdo(slave, cat_data, word_count, EC_TX_PDO)) fp@126: goto out_free; fp@118: break; fp@118: case 0x0033: fp@126: if (ec_slave_fetch_pdo(slave, cat_data, word_count, EC_RX_PDO)) fp@126: goto out_free; fp@118: break; fp@118: default: fp@126: EC_WARN("Unknown category type 0x%04X in slave %i.\n", fp@126: cat_type, slave->ring_position); fp@118: } fp@118: fp@118: word_offset += 2 + word_count; fp@118: } fp@118: fp@118: kfree(cat_data); fp@118: return 0; fp@123: fp@123: out_free: fp@123: kfree(cat_data); fp@123: return -1; fp@118: } fp@118: fp@118: /*****************************************************************************/ fp@118: fp@118: /** fp@118: Holt die Daten einer String-Kategorie. fp@118: fp@118: \return 0 wenn alles ok, sonst < 0 fp@118: */ fp@118: fp@118: int ec_slave_fetch_strings(ec_slave_t *slave, /**< EtherCAT-Slave */ fp@118: const uint8_t *data /**< Kategoriedaten */ fp@118: ) fp@118: { fp@118: unsigned int string_count, i; fp@118: size_t size; fp@118: off_t offset; fp@126: ec_eeprom_string_t *string; fp@118: fp@118: string_count = data[0]; fp@118: offset = 1; fp@118: for (i = 0; i < string_count; i++) { fp@118: size = data[offset]; fp@122: // Speicher für String-Objekt und Daten in einem Rutsch allozieren fp@126: if (!(string = (ec_eeprom_string_t *) fp@126: kmalloc(sizeof(ec_eeprom_string_t) + size + 1, GFP_KERNEL))) { fp@118: EC_ERR("Failed to allocate string memory.\n"); fp@118: return -1; fp@118: } fp@121: string->size = size; fp@126: string->data = (char *) string + sizeof(ec_eeprom_string_t); fp@118: memcpy(string->data, data + offset + 1, size); fp@118: string->data[size] = 0x00; fp@121: list_add_tail(&string->list, &slave->eeprom_strings); fp@118: offset += 1 + size; fp@118: } fp@118: fp@118: return 0; fp@118: } fp@118: fp@118: /*****************************************************************************/ fp@118: fp@118: /** fp@118: Holt die Daten einer General-Kategorie. fp@118: */ fp@118: fp@123: int ec_slave_fetch_general(ec_slave_t *slave, /**< EtherCAT-Slave */ fp@123: const uint8_t *data /**< Kategorie-Daten */ fp@123: ) fp@123: { fp@123: if (ec_slave_locate_string(slave, data[0], &slave->eeprom_group)) fp@123: return -1; fp@123: if (ec_slave_locate_string(slave, data[1], &slave->eeprom_name)) fp@123: return -1; fp@123: if (ec_slave_locate_string(slave, data[3], &slave->eeprom_desc)) fp@123: return -1; fp@123: fp@123: return 0; fp@118: } fp@118: fp@118: /*****************************************************************************/ fp@118: fp@118: /** fp@118: Holt die Daten einer Sync-Manager-Kategorie. fp@118: */ fp@118: fp@126: int ec_slave_fetch_sync(ec_slave_t *slave, /**< EtherCAT-Slave */ fp@126: const uint8_t *data, /**< Kategorie-Daten */ fp@126: size_t word_count /**< Anzahl Words */ fp@126: ) fp@126: { fp@126: unsigned int sync_count, i; fp@126: ec_eeprom_sync_t *sync; fp@126: fp@126: sync_count = word_count / 4; // Sync-Manager-Strunktur ist 4 Worte lang fp@126: fp@126: for (i = 0; i < sync_count; i++, data += 8) { fp@127: if (!(sync = (ec_eeprom_sync_t *) fp@127: kmalloc(sizeof(ec_eeprom_sync_t), GFP_KERNEL))) { fp@126: EC_ERR("Failed to allocate Sync-Manager memory.\n"); fp@126: return -1; fp@126: } fp@126: fp@126: sync->index = i; fp@126: sync->physical_start_address = *((uint16_t *) (data + 0)); fp@126: sync->length = *((uint16_t *) (data + 2)); fp@126: sync->control_register = data[4]; fp@126: sync->enable = data[6]; fp@126: fp@126: list_add_tail(&sync->list, &slave->eeprom_syncs); fp@126: } fp@126: fp@126: return 0; fp@118: } fp@118: fp@118: /*****************************************************************************/ fp@118: fp@118: /** fp@118: Holt die Daten einer TXPDO-Kategorie. fp@118: */ fp@118: fp@126: int ec_slave_fetch_pdo(ec_slave_t *slave, /**< EtherCAT-Slave */ fp@126: const uint8_t *data, /**< Kategorie-Daten */ fp@126: size_t word_count, /**< Anzahl Worte */ fp@126: ec_pdo_type_t pdo_type /**< PDO-Typ */ fp@126: ) fp@126: { fp@126: ec_eeprom_pdo_t *pdo; fp@126: ec_eeprom_pdo_entry_t *entry; fp@126: unsigned int entry_count, i; fp@126: fp@126: while (word_count >= 4) { fp@127: if (!(pdo = (ec_eeprom_pdo_t *) fp@127: kmalloc(sizeof(ec_eeprom_pdo_t), GFP_KERNEL))) { fp@126: EC_ERR("Failed to allocate PDO memory.\n"); fp@126: return -1; fp@126: } fp@126: fp@126: INIT_LIST_HEAD(&pdo->entries); fp@126: pdo->type = pdo_type; fp@126: fp@126: pdo->index = *((uint16_t *) data); fp@126: entry_count = data[2]; fp@126: pdo->sync_manager = data[3]; fp@126: pdo->name = NULL; fp@126: ec_slave_locate_string(slave, data[5], &pdo->name); fp@126: fp@126: list_add_tail(&pdo->list, &slave->eeprom_pdos); fp@126: fp@126: word_count -= 4; fp@126: data += 8; fp@126: fp@126: for (i = 0; i < entry_count; i++) { fp@126: if (!(entry = (ec_eeprom_pdo_entry_t *) fp@126: kmalloc(sizeof(ec_eeprom_pdo_entry_t), GFP_KERNEL))) { fp@126: EC_ERR("Failed to allocate PDO entry memory.\n"); fp@126: return -1; fp@126: } fp@126: fp@126: entry->index = *((uint16_t *) data); fp@126: entry->subindex = data[2]; fp@126: entry->name = NULL; fp@126: ec_slave_locate_string(slave, data[3], &entry->name); fp@126: entry->bit_length = data[5]; fp@126: fp@126: list_add_tail(&entry->list, &pdo->entries); fp@126: fp@126: word_count -= 4; fp@126: data += 8; fp@126: } fp@126: } fp@126: fp@126: return 0; fp@114: } fp@114: fp@114: /*****************************************************************************/ fp@114: fp@114: /** fp@123: Durchsucht die temporären Strings und dupliziert den gefundenen String. fp@123: */ fp@123: fp@123: int ec_slave_locate_string(ec_slave_t *slave, unsigned int index, char **ptr) fp@123: { fp@126: ec_eeprom_string_t *string; fp@126: char *err_string; fp@126: fp@126: // Erst alten Speicher freigeben fp@123: if (*ptr) { fp@123: kfree(*ptr); fp@123: *ptr = NULL; fp@123: } fp@123: fp@126: // Index 0 bedeutet "nicht belegt" fp@123: if (!index) return 0; fp@123: fp@126: // EEPROM-String mit Index finden und kopieren fp@123: list_for_each_entry(string, &slave->eeprom_strings, list) { fp@126: if (--index) continue; fp@126: fp@126: if (!(*ptr = (char *) kmalloc(string->size + 1, GFP_KERNEL))) { fp@126: EC_ERR("Unable to allocate string memory.\n"); fp@126: return -1; fp@126: } fp@126: memcpy(*ptr, string->data, string->size + 1); fp@126: return 0; fp@126: } fp@126: fp@126: EC_WARN("String %i not found in slave %i.\n", index, slave->ring_position); fp@126: fp@126: err_string = "(string not found)"; fp@126: fp@126: if (!(*ptr = (char *) kmalloc(strlen(err_string) + 1, GFP_KERNEL))) { fp@126: EC_ERR("Unable to allocate string memory.\n"); fp@126: return -1; fp@126: } fp@126: fp@126: memcpy(*ptr, err_string, strlen(err_string) + 1); fp@123: return 0; fp@123: } fp@123: fp@123: /*****************************************************************************/ fp@123: fp@123: /** fp@122: Bestätigt einen Fehler beim Zustandswechsel. fp@73: fp@91: \todo Funktioniert noch nicht... fp@73: */ fp@73: fp@73: void ec_slave_state_ack(ec_slave_t *slave, fp@122: /**< Slave, dessen Zustand geändert werden soll */ fp@73: uint8_t state fp@73: /**< Alter Zustand */ fp@73: ) fp@73: { fp@98: ec_command_t command; fp@101: uint8_t data[2]; fp@98: cycles_t start, end, timeout; fp@73: fp@77: EC_WRITE_U16(data, state | EC_ACK); fp@73: fp@98: ec_command_init_npwr(&command, slave->station_address, 0x0120, 2, data); fp@98: if (unlikely(ec_master_simple_io(slave->master, &command))) { fp@89: EC_WARN("State %02X acknowledge failed on slave %i!\n", fp@89: state, slave->ring_position); fp@73: return; fp@73: } fp@73: fp@98: start = get_cycles(); fp@119: timeout = (cycles_t) 10 * cpu_khz; // 10ms fp@98: fp@113: while (1) fp@73: { fp@113: udelay(100); // Dem Slave etwas Zeit lassen... fp@113: fp@98: ec_command_init_nprd(&command, slave->station_address, 0x0130, 2); fp@98: if (unlikely(ec_master_simple_io(slave->master, &command))) { fp@89: EC_WARN("State %02X acknowledge checking failed on slave %i!\n", fp@89: state, slave->ring_position); fp@73: return; fp@73: } fp@73: fp@98: end = get_cycles(); fp@98: fp@98: if (unlikely(EC_READ_U8(command.data) != state)) { fp@84: EC_WARN("Could not acknowledge state %02X on slave %i (code" fp@84: " %02X)!\n", state, slave->ring_position, fp@98: EC_READ_U8(command.data)); fp@73: return; fp@73: } fp@73: fp@98: if (likely(EC_READ_U8(command.data) == state)) { fp@84: EC_INFO("Acknowleged state %02X on slave %i.\n", state, fp@84: slave->ring_position); fp@73: return; fp@73: } fp@113: fp@113: if (unlikely((end - start) >= timeout)) { fp@113: EC_WARN("Could not check state acknowledgement %02X of slave %i -" fp@113: " Timeout while checking!\n", state, slave->ring_position); fp@113: return; fp@113: } fp@73: } fp@73: } fp@73: fp@73: /*****************************************************************************/ fp@73: fp@73: /** fp@122: Ändert den Zustand eines Slaves. fp@73: fp@73: \return 0 bei Erfolg, sonst < 0 fp@73: */ fp@73: fp@73: int ec_slave_state_change(ec_slave_t *slave, fp@122: /**< Slave, dessen Zustand geändert werden soll */ fp@73: uint8_t state fp@73: /**< Neuer Zustand */ fp@73: ) fp@73: { fp@98: ec_command_t command; fp@101: uint8_t data[2]; fp@98: cycles_t start, end, timeout; fp@73: fp@77: EC_WRITE_U16(data, state); fp@73: fp@98: ec_command_init_npwr(&command, slave->station_address, 0x0120, 2, data); fp@98: if (unlikely(ec_master_simple_io(slave->master, &command))) { fp@89: EC_ERR("Failed to set state %02X on slave %i!\n", fp@89: state, slave->ring_position); fp@73: return -1; fp@73: } fp@73: fp@98: start = get_cycles(); fp@119: timeout = (cycles_t) 10 * cpu_khz; // 10ms fp@98: fp@113: while (1) fp@73: { fp@98: udelay(100); // Dem Slave etwas Zeit lassen... fp@98: fp@98: ec_command_init_nprd(&command, slave->station_address, 0x0130, 2); fp@98: if (unlikely(ec_master_simple_io(slave->master, &command))) { fp@89: EC_ERR("Failed to check state %02X on slave %i!\n", fp@84: state, slave->ring_position); fp@73: return -1; fp@73: } fp@73: fp@98: end = get_cycles(); fp@98: fp@98: if (unlikely(EC_READ_U8(command.data) & 0x10)) { // State change error fp@84: EC_ERR("Could not set state %02X - Slave %i refused state change" fp@84: " (code %02X)!\n", state, slave->ring_position, fp@98: EC_READ_U8(command.data)); fp@98: ec_slave_state_ack(slave, EC_READ_U8(command.data) & 0x0F); fp@73: return -1; fp@73: } fp@73: fp@98: if (likely(EC_READ_U8(command.data) == (state & 0x0F))) { fp@73: // State change successful fp@113: return 0; fp@113: } fp@113: fp@113: if (unlikely((end - start) >= timeout)) { fp@113: EC_ERR("Could not check state %02X of slave %i - Timeout!\n", fp@113: state, slave->ring_position); fp@113: return -1; fp@113: } fp@113: } fp@73: } fp@73: fp@73: /*****************************************************************************/ fp@73: fp@73: /** fp@73: Merkt eine FMMU-Konfiguration vor. fp@73: fp@73: Die FMMU wird so konfiguriert, dass sie den gesamten Datenbereich des fp@122: entsprechenden Sync-Managers abdeckt. Für jede Domäne werden separate fp@73: FMMUs konfiguriert. fp@73: fp@73: Wenn die entsprechende FMMU bereits konfiguriert ist, wird dies als fp@122: Erfolg zurückgegeben. fp@73: fp@73: \return 0 bei Erfolg, sonst < 0 fp@73: */ fp@73: fp@73: int ec_slave_set_fmmu(ec_slave_t *slave, /**< EtherCAT-Slave */ fp@122: const ec_domain_t *domain, /**< Domäne */ fp@73: const ec_sync_t *sync /**< Sync-Manager */ fp@73: ) fp@73: { fp@73: unsigned int i; fp@73: fp@73: // FMMU schon vorgemerkt? fp@73: for (i = 0; i < slave->fmmu_count; i++) fp@73: if (slave->fmmus[i].domain == domain && slave->fmmus[i].sync == sync) fp@73: return 0; fp@73: fp@91: // Neue FMMU reservieren... fp@91: fp@73: if (slave->fmmu_count >= slave->base_fmmu_count) { fp@84: EC_ERR("Slave %i FMMU limit reached!\n", slave->ring_position); fp@73: return -1; fp@73: } fp@73: fp@73: slave->fmmus[slave->fmmu_count].domain = domain; fp@73: slave->fmmus[slave->fmmu_count].sync = sync; fp@73: slave->fmmus[slave->fmmu_count].logical_start_address = 0; fp@73: slave->fmmu_count++; fp@73: slave->registered = 1; fp@73: fp@73: return 0; fp@73: } fp@73: fp@73: /*****************************************************************************/ fp@73: fp@73: /** fp@122: Gibt alle Informationen über einen EtherCAT-Slave aus. fp@140: fp@140: Verbosity: fp@140: 0 - Nur Slavetypen und Adressen fp@140: 1 - mit EEPROM-Informationen fp@140: >1 - mit SDO-Dictionaries fp@140: */ fp@140: fp@140: void ec_slave_print(const ec_slave_t *slave, /**< EtherCAT-Slave */ fp@140: unsigned int verbosity /**< Geschwätzigkeit */ fp@140: ) fp@73: { fp@126: ec_eeprom_sync_t *sync; fp@126: ec_eeprom_pdo_t *pdo; fp@139: ec_eeprom_pdo_entry_t *pdo_entry; fp@135: ec_sdo_t *sdo; fp@139: ec_sdo_entry_t *sdo_entry; fp@142: int first, i; fp@126: fp@123: EC_INFO("x-- EtherCAT slave information ---------------\n"); fp@73: fp@73: if (slave->type) { fp@123: EC_INFO("| Vendor \"%s\", Product \"%s\": %s\n", fp@84: slave->type->vendor_name, slave->type->product_name, fp@84: slave->type->description); fp@73: } fp@73: else { fp@123: EC_INFO("| *** This slave has no type information! ***\n"); fp@123: } fp@123: fp@123: EC_INFO("| Ring position: %i, Station address: 0x%04X\n", fp@84: slave->ring_position, slave->station_address); fp@84: fp@140: if (verbosity > 0) // Etwas geschwätziger fp@140: { fp@142: EC_INFO("| Data link status:\n"); fp@142: for (i = 0; i < 2; i++) { fp@142: EC_INFO("| Port %i: link %s, loop %s, %s\n", i, fp@142: slave->dl_status_link[i] ? "up" : "down", fp@142: slave->dl_status_loop[i] ? "closed" : "open", fp@142: slave->dl_status_comm[i] ? "comm. establ." : "no comm."); fp@142: } fp@142: fp@140: EC_INFO("| Base information:\n"); fp@140: EC_INFO("| Type %u, Revision %i, Build %i\n", fp@140: slave->base_type, slave->base_revision, slave->base_build); fp@140: EC_INFO("| Supported FMMUs: %i, Sync managers: %i\n", fp@140: slave->base_fmmu_count, slave->base_sync_count); fp@140: fp@140: if (slave->sii_mailbox_protocols) { fp@140: EC_INFO("| Mailbox communication:\n"); fp@140: EC_INFO("| RX mailbox: 0x%04X/%i, TX mailbox: 0x%04X/%i\n", fp@140: slave->sii_rx_mailbox_offset, slave->sii_rx_mailbox_size, fp@140: slave->sii_tx_mailbox_offset, slave->sii_tx_mailbox_size); fp@140: EC_INFO("| Supported protocols: "); fp@140: fp@140: first = 1; fp@140: if (slave->sii_mailbox_protocols & EC_MBOX_AOE) { fp@140: printk("AoE"); fp@140: first = 0; fp@140: } fp@140: if (slave->sii_mailbox_protocols & EC_MBOX_EOE) { fp@140: if (!first) printk(", "); fp@140: printk("EoE"); fp@140: first = 0; fp@140: } fp@140: if (slave->sii_mailbox_protocols & EC_MBOX_COE) { fp@140: if (!first) printk(", "); fp@140: printk("CoE"); fp@140: first = 0; fp@140: } fp@140: if (slave->sii_mailbox_protocols & EC_MBOX_FOE) { fp@140: if (!first) printk(", "); fp@140: printk("FoE"); fp@140: first = 0; fp@140: } fp@140: if (slave->sii_mailbox_protocols & EC_MBOX_SOE) { fp@140: if (!first) printk(", "); fp@140: printk("SoE"); fp@140: first = 0; fp@140: } fp@140: if (slave->sii_mailbox_protocols & EC_MBOX_VOE) { fp@140: if (!first) printk(", "); fp@140: printk("VoE"); fp@140: } fp@140: printk("\n"); fp@140: } fp@140: fp@140: EC_INFO("| EEPROM data:\n"); fp@140: fp@140: if (slave->sii_alias) fp@140: EC_INFO("| Configured station alias: 0x%04X (%i)\n", fp@140: slave->sii_alias, slave->sii_alias); fp@140: fp@140: EC_INFO("| Vendor-ID: 0x%08X, Product code: 0x%08X\n", fp@140: slave->sii_vendor_id, slave->sii_product_code); fp@140: EC_INFO("| Revision number: 0x%08X, Serial number: 0x%08X\n", fp@140: slave->sii_revision_number, slave->sii_serial_number); fp@140: fp@140: if (slave->eeprom_name) fp@140: EC_INFO("| Name: %s\n", slave->eeprom_name); fp@140: if (slave->eeprom_group) fp@140: EC_INFO("| Group: %s\n", slave->eeprom_group); fp@140: if (slave->eeprom_desc) fp@140: EC_INFO("| Description: %s\n", slave->eeprom_desc); fp@140: fp@140: if (!list_empty(&slave->eeprom_syncs)) { fp@140: EC_INFO("| Sync-Managers:\n"); fp@140: list_for_each_entry(sync, &slave->eeprom_syncs, list) { fp@140: EC_INFO("| %i: 0x%04X, length %i, control 0x%02X, %s\n", fp@140: sync->index, sync->physical_start_address, fp@140: sync->length, sync->control_register, fp@140: sync->enable ? "enable" : "disable"); fp@140: } fp@140: } fp@140: fp@140: list_for_each_entry(pdo, &slave->eeprom_pdos, list) { fp@140: EC_INFO("| %s \"%s\" (0x%04X), -> Sync-Manager %i\n", fp@140: pdo->type == EC_RX_PDO ? "RXPDO" : "TXPDO", fp@140: pdo->name ? pdo->name : "???", fp@140: pdo->index, pdo->sync_manager); fp@140: fp@140: list_for_each_entry(pdo_entry, &pdo->entries, list) { fp@140: EC_INFO("| \"%s\" 0x%04X:%X, %i Bit\n", fp@140: pdo_entry->name ? pdo_entry->name : "???", fp@140: pdo_entry->index, pdo_entry->subindex, fp@140: pdo_entry->bit_length); fp@140: } fp@140: } fp@140: } fp@140: fp@140: if (verbosity > 1) // sehr geschwätzig fp@140: { fp@140: if (!list_empty(&slave->sdo_dictionary)) { fp@140: EC_INFO("| SDO-Dictionary:\n"); fp@140: list_for_each_entry(sdo, &slave->sdo_dictionary, list) { fp@140: EC_INFO("| 0x%04X \"%s\"\n", sdo->index, fp@140: sdo->name ? sdo->name : ""); fp@140: EC_INFO("| Type 0x%04X, features: 0x%02X\n", fp@140: sdo->type, sdo->features); fp@140: list_for_each_entry(sdo_entry, &sdo->entries, list) { fp@140: EC_INFO("| 0x%04X:%i \"%s\", type 0x%04X, %i bits\n", fp@140: sdo->index, sdo_entry->subindex, fp@140: sdo_entry->name ? sdo_entry->name : "", fp@140: sdo_entry->data_type, sdo_entry->bit_length); fp@140: } fp@139: } fp@135: } fp@135: } fp@135: fp@123: EC_INFO("x---------------------------------------------\n"); fp@123: } fp@123: fp@123: /*****************************************************************************/ fp@123: fp@123: /** fp@123: Gibt die Zählerstände der CRC-Fault-Counter aus und setzt diese zurück. fp@74: fp@74: \return 0 bei Erfolg, sonst < 0 fp@74: */ fp@74: fp@74: int ec_slave_check_crc(ec_slave_t *slave /**< EtherCAT-Slave */) fp@74: { fp@98: ec_command_t command; fp@74: uint8_t data[4]; fp@74: fp@98: ec_command_init_nprd(&command, slave->station_address, 0x0300, 4); fp@98: if (unlikely(ec_master_simple_io(slave->master, &command))) { fp@89: EC_WARN("Reading CRC fault counters failed on slave %i!\n", fp@84: slave->ring_position); fp@74: return -1; fp@74: } fp@74: fp@74: // No CRC faults. fp@132: if (!EC_READ_U32(command.data)) return 0; fp@132: fp@132: if (EC_READ_U8(command.data)) fp@132: EC_WARN("%3i RX-error%s on slave %i, channel A.\n", fp@132: EC_READ_U8(command.data), fp@132: EC_READ_U8(command.data) == 1 ? "" : "s", fp@132: slave->ring_position); fp@132: if (EC_READ_U8(command.data + 1)) fp@132: EC_WARN("%3i invalid frame%s on slave %i, channel A.\n", fp@132: EC_READ_U8(command.data + 1), fp@132: EC_READ_U8(command.data + 1) == 1 ? "" : "s", fp@132: slave->ring_position); fp@132: if (EC_READ_U8(command.data + 2)) fp@132: EC_WARN("%3i RX-error%s on slave %i, channel B.\n", fp@132: EC_READ_U8(command.data + 2), fp@132: EC_READ_U8(command.data + 2) == 1 ? "" : "s", fp@132: slave->ring_position); fp@132: if (EC_READ_U8(command.data + 3)) fp@132: EC_WARN("%3i invalid frame%s on slave %i, channel B.\n", fp@132: EC_READ_U8(command.data + 3), fp@132: EC_READ_U8(command.data + 3) == 1 ? "" : "s", fp@132: slave->ring_position); fp@74: fp@74: // Reset CRC counters fp@132: EC_WRITE_U32(data, 0x00000000); fp@98: ec_command_init_npwr(&command, slave->station_address, 0x0300, 4, data); fp@98: if (unlikely(ec_master_simple_io(slave->master, &command))) { fp@89: EC_WARN("Resetting CRC fault counters failed on slave %i!\n", fp@84: slave->ring_position); fp@74: return -1; fp@74: } fp@74: fp@74: return 0; fp@74: } fp@74: fp@74: /*****************************************************************************/ fp@74: fp@133: /** fp@133: Sendet ein Mailbox-Kommando. fp@133: */ fp@133: fp@133: int ec_slave_mailbox_send(ec_slave_t *slave, /**< EtherCAT-Slave */ fp@133: uint8_t type, /**< Unterliegendes Protokoll */ fp@133: const uint8_t *prot_data, /**< Protokoll-Daten */ fp@133: size_t size /**< Datengröße */ fp@133: ) fp@133: { fp@136: size_t total_size; fp@136: uint8_t *data; fp@133: ec_command_t command; fp@133: fp@136: if (unlikely(!slave->sii_mailbox_protocols)) { fp@136: EC_ERR("Slave %i does not support mailbox communication!\n", fp@136: slave->ring_position); fp@136: return -1; fp@136: } fp@136: fp@136: total_size = size + 6; fp@136: if (unlikely(total_size > slave->sii_rx_mailbox_size)) { fp@133: EC_ERR("Data size does not fit in mailbox!\n"); fp@133: return -1; fp@133: } fp@133: fp@136: if (!(data = kmalloc(slave->sii_rx_mailbox_size, GFP_KERNEL))) { fp@136: EC_ERR("Failed to allocate %i bytes of memory for mailbox data!\n", fp@136: slave->sii_rx_mailbox_size); fp@136: return -1; fp@136: } fp@136: fp@136: memset(data, 0x00, slave->sii_rx_mailbox_size); fp@133: EC_WRITE_U16(data, size); // Length of the Mailbox service data fp@133: EC_WRITE_U16(data + 2, slave->station_address); // Station address fp@133: EC_WRITE_U8 (data + 4, 0x00); // Channel & priority fp@133: EC_WRITE_U8 (data + 5, type); // Underlying protocol type fp@133: memcpy(data + 6, prot_data, size); fp@133: fp@136: ec_command_init_npwr(&command, slave->station_address, fp@136: slave->sii_rx_mailbox_offset, fp@136: slave->sii_rx_mailbox_size, data); fp@133: if (unlikely(ec_master_simple_io(slave->master, &command))) { fp@133: EC_ERR("Mailbox sending failed on slave %i!\n", slave->ring_position); fp@136: kfree(data); fp@136: return -1; fp@136: } fp@136: fp@136: kfree(data); fp@133: return 0; fp@133: } fp@133: fp@133: /*****************************************************************************/ fp@133: fp@133: /** fp@133: Sendet ein Mailbox-Kommando. fp@133: */ fp@133: fp@133: int ec_slave_mailbox_receive(ec_slave_t *slave, /**< EtherCAT-Slave */ fp@133: uint8_t type, /**< Unterliegendes Protokoll */ fp@133: uint8_t *prot_data, /**< Protokoll-Daten */ fp@133: size_t *size /**< Datengröße des Puffers, später fp@133: Größe der gelesenen Daten */ fp@133: ) fp@133: { fp@133: ec_command_t command; fp@133: size_t data_size; fp@133: cycles_t start, end, timeout; fp@133: fp@133: // Read "written bit" of Sync-Manager fp@133: start = get_cycles(); fp@133: timeout = (cycles_t) 100 * cpu_khz; // 100ms fp@133: fp@133: while (1) fp@133: { fp@136: // FIXME: Zweiter Sync-Manager nicht immer TX-Mailbox? fp@133: ec_command_init_nprd(&command, slave->station_address, 0x808, 8); fp@133: if (unlikely(ec_master_simple_io(slave->master, &command))) { fp@133: EC_ERR("Mailbox checking failed on slave %i!\n", fp@133: slave->ring_position); fp@133: return -1; fp@133: } fp@133: fp@133: end = get_cycles(); fp@133: fp@136: if (EC_READ_U8(command.data + 5) & 8) fp@136: break; // Proceed with received data fp@133: fp@133: if ((end - start) >= timeout) { fp@133: EC_ERR("Mailbox check - Slave %i timed out.\n", fp@133: slave->ring_position); fp@133: return -1; fp@133: } fp@133: fp@133: udelay(100); fp@133: } fp@133: fp@136: ec_command_init_nprd(&command, slave->station_address, fp@136: slave->sii_tx_mailbox_offset, fp@136: slave->sii_tx_mailbox_size); fp@133: if (unlikely(ec_master_simple_io(slave->master, &command))) { fp@133: EC_ERR("Mailbox receiving failed on slave %i!\n", fp@133: slave->ring_position); fp@133: return -1; fp@133: } fp@133: fp@136: if ((EC_READ_U8(command.data + 5) & 0x0F) != type) { fp@136: EC_ERR("Unexpected mailbox protocol 0x%02X (exp.: 0x%02X) at" fp@136: " slave %i!\n", EC_READ_U8(command.data + 5), type, fp@133: slave->ring_position); fp@133: return -1; fp@133: } fp@133: fp@136: if (unlikely(slave->master->debug_level) > 1) fp@136: EC_DBG("Mailbox receive took %ius.\n", ((u32) (end - start) * 1000 fp@136: / cpu_khz)); fp@136: fp@133: if ((data_size = EC_READ_U16(command.data)) > *size) { fp@136: EC_ERR("Mailbox service data does not fit into buffer (%i > %i).\n", fp@133: data_size, *size); fp@133: return -1; fp@133: } fp@133: fp@136: if (data_size > slave->sii_tx_mailbox_size - 6) { fp@136: EC_ERR("Currupt mailbox response detected!\n"); fp@136: return -1; fp@136: } fp@136: fp@133: memcpy(prot_data, command.data + 6, data_size); fp@133: *size = data_size; fp@133: return 0; fp@133: } fp@133: fp@133: /*****************************************************************************/ fp@133: fp@138: /** fp@138: Schreibt den "Configured station alias". fp@138: \return 0, wenn alles ok, sonst < 0 fp@138: */ fp@138: fp@138: int ecrt_slave_write_alias(ec_slave_t *slave, /** EtherCAT-Slave */ fp@138: uint16_t alias /** Neuer Alias */ fp@138: ) fp@138: { fp@138: return ec_slave_sii_write16(slave, 0x0004, alias); fp@138: } fp@138: fp@138: /*****************************************************************************/ fp@138: fp@138: EXPORT_SYMBOL(ecrt_slave_write_alias); fp@138: fp@138: /*****************************************************************************/ fp@138: fp@42: /* Emacs-Konfiguration fp@42: ;;; Local Variables: *** fp@73: ;;; c-basic-offset:4 *** fp@42: ;;; End: *** fp@42: */ fp@114: