fp@792: /****************************************************************************** fp@792: * fp@792: * $Id$ fp@792: * fp@1685: * Copyright (C) 2006-2008 Florian Pose, Ingenieurgemeinschaft IgH fp@792: * fp@792: * This file is part of the IgH EtherCAT Master. fp@792: * fp@1685: * The IgH EtherCAT Master is free software; you can redistribute it and/or fp@1685: * modify it under the terms of the GNU General Public License version 2, as fp@1685: * published by the Free Software Foundation. fp@1685: * fp@1685: * The IgH EtherCAT Master is distributed in the hope that it will be useful, fp@1685: * but WITHOUT ANY WARRANTY; without even the implied warranty of fp@1685: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General fp@1685: * Public License for more details. fp@1685: * fp@1685: * You should have received a copy of the GNU General Public License along fp@1685: * with the IgH EtherCAT Master; if not, write to the Free Software fp@792: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA fp@792: * fp@1685: * Using the EtherCAT technology and brand is permitted in compliance with fp@1685: * the industrial property and similar rights of Beckhoff Automation GmbH. fp@792: * fp@792: *****************************************************************************/ fp@792: fp@792: /** fp@792: \file fp@792: EtherCAT slave configuration methods. fp@792: */ fp@792: fp@792: /*****************************************************************************/ fp@792: fp@995: #include fp@792: fp@792: #include "globals.h" fp@792: #include "master.h" fp@792: fp@792: #include "slave_config.h" fp@792: fp@792: /*****************************************************************************/ fp@792: fp@792: /** Slave configuration constructor. fp@792: * fp@792: * See ecrt_master_slave_config() for the usage of the \a alias and \a fp@792: * position parameters. fp@995: */ fp@995: void ec_slave_config_init( fp@995: ec_slave_config_t *sc, /**< Slave configuration. */ fp@792: ec_master_t *master, /**< EtherCAT master. */ fp@792: uint16_t alias, /**< Slave alias. */ fp@792: uint16_t position, /**< Slave position. */ fp@792: uint32_t vendor_id, /**< Expected vendor ID. */ fp@1010: uint32_t product_code /**< Expected product code. */ fp@792: ) fp@792: { fp@1055: unsigned int i; fp@792: fp@792: sc->master = master; fp@792: sc->alias = alias; fp@792: sc->position = position; fp@792: sc->vendor_id = vendor_id; fp@792: sc->product_code = product_code; fp@792: sc->slave = NULL; fp@792: fp@1082: for (i = 0; i < EC_MAX_SYNC_MANAGERS; i++) fp@1055: ec_sync_config_init(&sc->sync_configs[i]); fp@792: fp@792: INIT_LIST_HEAD(&sc->sdo_configs); fp@858: INIT_LIST_HEAD(&sc->sdo_requests); fp@792: fp@792: sc->used_fmmus = 0; fp@792: } fp@792: fp@792: /*****************************************************************************/ fp@792: fp@792: /** Slave configuration destructor. fp@792: * fp@792: * Clears and frees a slave configuration object. fp@792: */ fp@995: void ec_slave_config_clear( fp@792: ec_slave_config_t *sc /**< Slave configuration. */ fp@792: ) fp@792: { fp@1055: unsigned int i; fp@854: ec_sdo_request_t *req, *next_req; fp@792: fp@995: ec_slave_config_detach(sc); fp@792: fp@1055: // Free sync managers fp@1082: for (i = 0; i < EC_MAX_SYNC_MANAGERS; i++) fp@1055: ec_sync_config_clear(&sc->sync_configs[i]); fp@792: fp@814: // free all Sdo configurations fp@854: list_for_each_entry_safe(req, next_req, &sc->sdo_configs, list) { fp@854: list_del(&req->list); fp@854: ec_sdo_request_clear(req); fp@854: kfree(req); fp@854: } fp@792: fp@858: // free all Sdo requests fp@858: list_for_each_entry_safe(req, next_req, &sc->sdo_requests, list) { fp@858: list_del(&req->list); fp@858: ec_sdo_request_clear(req); fp@858: kfree(req); fp@858: } fp@792: } fp@792: fp@792: /*****************************************************************************/ fp@792: fp@792: /** Prepares an FMMU configuration. fp@792: * fp@792: * Configuration data for the FMMU is saved in the slave config structure and fp@792: * is written to the slave during the configuration. The FMMU configuration fp@792: * is done in a way, that the complete data range of the corresponding sync fp@792: * manager is covered. Seperate FMMUs are configured for each domain. If the fp@916: * FMMU configuration is already prepared, the function does nothing and fp@916: * returns with success. fp@916: * fp@916: * \retval >=0 Success, logical offset byte address. fp@916: * \retval -1 Error, FMMU limit reached. fp@792: */ fp@792: int ec_slave_config_prepare_fmmu( fp@792: ec_slave_config_t *sc, /**< Slave configuration. */ fp@792: ec_domain_t *domain, /**< Domain. */ fp@1055: uint8_t sync_index, /**< Sync manager index. */ fp@814: ec_direction_t dir /**< Pdo direction. */ fp@792: ) fp@792: { fp@792: unsigned int i; fp@792: ec_fmmu_config_t *fmmu; fp@792: fp@792: // FMMU configuration already prepared? fp@792: for (i = 0; i < sc->used_fmmus; i++) { fp@792: fmmu = &sc->fmmu_configs[i]; fp@1055: if (fmmu->domain == domain && fmmu->sync_index == sync_index) fp@792: return fmmu->logical_start_address; fp@792: } fp@792: fp@792: if (sc->used_fmmus == EC_MAX_FMMUS) { fp@792: EC_ERR("FMMU limit reached for slave configuration %u:%u!\n", fp@792: sc->alias, sc->position); fp@792: return -1; fp@792: } fp@792: fp@792: fmmu = &sc->fmmu_configs[sc->used_fmmus++]; fp@1075: fp@1075: down(&sc->master->master_sem); fp@1055: ec_fmmu_config_init(fmmu, sc, domain, sync_index, dir); fp@1075: up(&sc->master->master_sem); fp@1075: fp@792: return fmmu->logical_start_address; fp@792: } fp@792: fp@792: /*****************************************************************************/ fp@792: fp@792: /** Attaches the configuration to the addressed slave object. fp@792: * fp@792: * \retval 0 Success. fp@792: * \retval -1 Slave not found. fp@792: * \retval -2 Slave already configured. fp@792: * \retval -3 Invalid slave type found at the given position. fp@792: */ fp@792: int ec_slave_config_attach( fp@792: ec_slave_config_t *sc /**< Slave configuration. */ fp@792: ) fp@792: { fp@792: ec_slave_t *slave; fp@792: fp@792: if (sc->slave) fp@792: return 0; // already attached fp@792: fp@927: if (!(slave = ec_master_find_slave( fp@927: sc->master, sc->alias, sc->position))) { fp@1025: if (sc->master->debug_level) fp@1025: EC_DBG("Failed to find slave for configuration %u:%u.\n", fp@1025: sc->alias, sc->position); fp@927: return -1; fp@927: } fp@927: fp@792: if (slave->config) { fp@1025: if (sc->master->debug_level) fp@1025: EC_DBG("Failed to attach slave configuration %u:%u. Slave %u" fp@1025: " already has a configuration!\n", sc->alias, fp@1025: sc->position, slave->ring_position); fp@1025: return -2; fp@1025: } fp@1145: fp@1025: if (slave->sii.vendor_id != sc->vendor_id fp@1025: || slave->sii.product_code != sc->product_code) { fp@1025: if (sc->master->debug_level) fp@1025: EC_DBG("Slave %u has an invalid type (0x%08X/0x%08X) for" fp@1025: " configuration %u:%u (0x%08X/0x%08X).\n", fp@1025: slave->ring_position, slave->sii.vendor_id, fp@1025: slave->sii.product_code, sc->alias, sc->position, fp@1025: sc->vendor_id, sc->product_code); fp@1025: return -3; fp@792: } fp@792: fp@792: // attach slave fp@792: slave->config = sc; fp@792: sc->slave = slave; fp@1145: fp@1025: ec_slave_request_state(slave, EC_SLAVE_STATE_OP); fp@792: fp@929: if (sc->master->debug_level) fp@929: EC_DBG("Attached slave %u to config %u:%u.\n", fp@929: slave->ring_position, sc->alias, sc->position); fp@929: fp@792: return 0; fp@792: } fp@792: fp@792: /*****************************************************************************/ fp@792: fp@792: /** Detaches the configuration from a slave object. fp@792: */ fp@792: void ec_slave_config_detach( fp@792: ec_slave_config_t *sc /**< Slave configuration. */ fp@792: ) fp@792: { fp@792: if (sc->slave) { fp@792: sc->slave->config = NULL; fp@792: sc->slave = NULL; fp@792: } fp@792: } fp@792: fp@792: /*****************************************************************************/ fp@792: fp@879: /** Loads the default Pdo assignment from the slave object. fp@879: */ fp@1055: void ec_slave_config_load_default_sync_config(ec_slave_config_t *sc) fp@1055: { fp@1055: uint8_t sync_index; fp@1055: ec_sync_config_t *sync_config; fp@1055: const ec_sync_t *sync; fp@792: fp@792: if (!sc->slave) fp@792: return; fp@792: fp@1082: for (sync_index = 0; sync_index < EC_MAX_SYNC_MANAGERS; sync_index++) { fp@1055: sync_config = &sc->sync_configs[sync_index]; fp@1055: if ((sync = ec_slave_get_sync(sc->slave, sync_index))) { fp@1055: sync_config->dir = ec_sync_default_direction(sync); fp@1055: if (sync_config->dir == EC_DIR_INVALID) fp@1055: EC_WARN("SM%u of slave %u has an invalid direction field!\n", fp@1055: sync_index, sc->slave->ring_position); fp@1055: ec_pdo_list_copy(&sync_config->pdos, &sync->pdos); fp@1055: } fp@879: } fp@879: } fp@879: fp@879: /*****************************************************************************/ fp@879: fp@879: /** Loads the default mapping for a Pdo from the slave object. fp@879: */ fp@879: void ec_slave_config_load_default_mapping( fp@842: const ec_slave_config_t *sc, fp@842: ec_pdo_t *pdo fp@842: ) fp@842: { fp@1055: unsigned int i; fp@842: const ec_sync_t *sync; fp@842: const ec_pdo_t *default_pdo; fp@842: fp@1055: if (!sc->slave) fp@842: return; fp@1055: fp@1055: if (sc->master->debug_level) fp@1055: EC_DBG("Loading default mapping for Pdo 0x%04X in config %u:%u.\n", fp@1055: pdo->index, sc->alias, sc->position); fp@1055: fp@1055: // find Pdo in any sync manager (it could be reassigned later) fp@1055: for (i = 0; i < sc->slave->sii.sync_count; i++) { fp@1055: sync = &sc->slave->sii.syncs[i]; fp@1055: fp@1055: list_for_each_entry(default_pdo, &sync->pdos.list, list) { fp@1055: if (default_pdo->index != pdo->index) fp@1055: continue; fp@1055: fp@1055: if (default_pdo->name) { fp@1055: if (sc->master->debug_level) fp@1055: EC_DBG("Found Pdo name \"%s\".\n", default_pdo->name); fp@1055: fp@1055: // take Pdo name from assigned one fp@1055: ec_pdo_set_name(pdo, default_pdo->name); fp@1055: } fp@1055: fp@1055: // copy entries (= default Pdo mapping) fp@1055: if (ec_pdo_copy_entries(pdo, default_pdo)) fp@1055: return; fp@1055: fp@1055: if (sc->master->debug_level) { fp@1055: const ec_pdo_entry_t *entry; fp@1055: list_for_each_entry(entry, &pdo->entries, list) { fp@1055: EC_DBG("Entry 0x%04X:%02X.\n", fp@1055: entry->index, entry->subindex); fp@1055: } fp@1055: } fp@1055: fp@842: return; fp@842: } fp@792: } fp@1055: fp@1055: if (sc->master->debug_level) fp@1055: EC_DBG("No default mapping found.\n"); fp@792: } fp@792: fp@990: /*****************************************************************************/ fp@990: fp@1092: /** Get the number of Sdo configurations. fp@1092: * fp@1092: * \return Number of Sdo configurations. fp@1092: */ fp@990: unsigned int ec_slave_config_sdo_count( fp@990: const ec_slave_config_t *sc /**< Slave configuration. */ fp@990: ) fp@990: { fp@990: const ec_sdo_request_t *req; fp@990: unsigned int count = 0; fp@990: fp@990: list_for_each_entry(req, &sc->sdo_configs, list) { fp@990: count++; fp@990: } fp@990: fp@990: return count; fp@990: } fp@990: fp@990: /*****************************************************************************/ fp@990: fp@990: /** Finds an Sdo configuration via its position in the list. fp@990: * fp@990: * Const version. fp@990: */ fp@990: const ec_sdo_request_t *ec_slave_config_get_sdo_by_pos_const( fp@990: const ec_slave_config_t *sc, /**< Slave configuration. */ fp@990: unsigned int pos /**< Position in the list. */ fp@990: ) fp@990: { fp@990: const ec_sdo_request_t *req; fp@990: fp@990: list_for_each_entry(req, &sc->sdo_configs, list) { fp@990: if (pos--) fp@990: continue; fp@990: return req; fp@990: } fp@990: fp@990: return NULL; fp@990: } fp@990: fp@792: /****************************************************************************** fp@792: * Realtime interface fp@792: *****************************************************************************/ fp@792: fp@1055: int ecrt_slave_config_sync_manager(ec_slave_config_t *sc, uint8_t sync_index, fp@1055: ec_direction_t dir) fp@1055: { fp@1055: ec_sync_config_t *sync_config; fp@1055: fp@1055: if (sc->master->debug_level) fp@1055: EC_DBG("ecrt_slave_config_sync_manager(sc = 0x%x, sync_index = %u, " fp@1055: "dir = %u)\n", (u32) sc, sync_index, dir); fp@1055: fp@1082: if (sync_index >= EC_MAX_SYNC_MANAGERS) { fp@1055: EC_ERR("Invalid sync manager index %u!\n", sync_index); fp@1055: return -1; fp@1055: } fp@1055: fp@1055: if (dir != EC_DIR_OUTPUT && dir != EC_DIR_INPUT) { fp@1055: EC_ERR("Invalid direction %u!\n", (u32) dir); fp@1055: return -1; fp@1055: } fp@1055: fp@1055: sync_config = &sc->sync_configs[sync_index]; fp@1055: sync_config->dir = dir; fp@1055: return 0; fp@1055: } fp@1055: fp@1055: /*****************************************************************************/ fp@1055: fp@879: int ecrt_slave_config_pdo_assign_add(ec_slave_config_t *sc, fp@1055: uint8_t sync_index, uint16_t pdo_index) fp@1055: { fp@842: ec_pdo_t *pdo; fp@1055: fp@1055: if (sc->master->debug_level) fp@1055: EC_DBG("ecrt_slave_config_pdo_assign_add(sc = 0x%x, sync_index = %u, " fp@1055: "pdo_index = 0x%04X)\n", (u32) sc, sync_index, pdo_index); fp@1055: fp@1082: if (sync_index >= EC_MAX_SYNC_MANAGERS) { fp@1055: EC_ERR("Invalid sync manager index %u!\n", sync_index); fp@1055: return -1; fp@1055: } fp@1055: fp@1075: down(&sc->master->master_sem); fp@1075: fp@1075: if (!(pdo = ec_pdo_list_add_pdo(&sc->sync_configs[sync_index].pdos, fp@1075: pdo_index))) { fp@1075: up(&sc->master->master_sem); fp@1075: return -1; fp@1075: } fp@1055: pdo->sync_index = sync_index; fp@842: fp@879: ec_slave_config_load_default_mapping(sc, pdo); fp@1075: fp@1075: up(&sc->master->master_sem); fp@842: return 0; fp@842: } fp@842: fp@842: /*****************************************************************************/ fp@842: fp@879: void ecrt_slave_config_pdo_assign_clear(ec_slave_config_t *sc, fp@1055: uint8_t sync_index) fp@1055: { fp@1055: if (sc->master->debug_level) fp@1055: EC_DBG("ecrt_slave_config_pdo_assign_clear(sc = 0x%x, " fp@1055: "sync_index = %u)\n", (u32) sc, sync_index); fp@1055: fp@1082: if (sync_index >= EC_MAX_SYNC_MANAGERS) { fp@1055: EC_ERR("Invalid sync manager index %u!\n", sync_index); fp@1055: return; fp@1055: } fp@1055: fp@1075: down(&sc->master->master_sem); fp@1055: ec_pdo_list_clear_pdos(&sc->sync_configs[sync_index].pdos); fp@1075: up(&sc->master->master_sem); fp@879: } fp@879: fp@879: /*****************************************************************************/ fp@879: fp@879: int ecrt_slave_config_pdo_mapping_add(ec_slave_config_t *sc, fp@879: uint16_t pdo_index, uint16_t entry_index, uint8_t entry_subindex, fp@842: uint8_t entry_bit_length) fp@842: { fp@1055: uint8_t sync_index; fp@1055: ec_pdo_t *pdo = NULL; fp@1075: int retval = -1; fp@842: fp@843: if (sc->master->debug_level) fp@1055: EC_DBG("ecrt_slave_config_pdo_mapping_add(sc = 0x%x, " fp@1055: "pdo_index = 0x%04X, entry_index = 0x%04X, " fp@1055: "entry_subindex = 0x%02X, entry_bit_length = %u)\n", fp@1055: (u32) sc, pdo_index, entry_index, entry_subindex, fp@1055: entry_bit_length); fp@1055: fp@1082: for (sync_index = 0; sync_index < EC_MAX_SYNC_MANAGERS; sync_index++) fp@1055: if ((pdo = ec_pdo_list_find_pdo( fp@1055: &sc->sync_configs[sync_index].pdos, pdo_index))) fp@842: break; fp@842: fp@1075: if (pdo) { fp@1075: down(&sc->master->master_sem); fp@1075: retval = ec_pdo_add_entry(pdo, entry_index, entry_subindex, fp@1075: entry_bit_length) ? 0 : -1; fp@1075: up(&sc->master->master_sem); fp@1075: } else { fp@879: EC_ERR("Pdo 0x%04X is not assigned in config %u:%u.\n", fp@843: pdo_index, sc->alias, sc->position); fp@1075: } fp@1075: fp@1075: return retval; fp@842: } fp@842: fp@842: /*****************************************************************************/ fp@842: fp@879: void ecrt_slave_config_pdo_mapping_clear(ec_slave_config_t *sc, fp@879: uint16_t pdo_index) fp@879: { fp@1055: uint8_t sync_index; fp@1055: ec_pdo_t *pdo = NULL; fp@879: fp@879: if (sc->master->debug_level) fp@1055: EC_DBG("ecrt_slave_config_pdo_mapping_clear(sc = 0x%x, " fp@1055: "pdo_index = 0x%04X)\n", (u32) sc, pdo_index); fp@1055: fp@1082: for (sync_index = 0; sync_index < EC_MAX_SYNC_MANAGERS; sync_index++) fp@1055: if ((pdo = ec_pdo_list_find_pdo( fp@1055: &sc->sync_configs[sync_index].pdos, pdo_index))) fp@879: break; fp@879: fp@1075: if (pdo) { fp@1075: down(&sc->master->master_sem); fp@1075: ec_pdo_clear_entries(pdo); fp@1075: up(&sc->master->master_sem); fp@1075: } else { fp@879: EC_WARN("Pdo 0x%04X is not assigned in config %u:%u.\n", fp@879: pdo_index, sc->alias, sc->position); fp@1075: } fp@879: } fp@879: fp@879: /*****************************************************************************/ fp@879: fp@1082: int ecrt_slave_config_pdos(ec_slave_config_t *sc, fp@1055: unsigned int n_syncs, const ec_sync_info_t syncs[]) fp@1055: { fp@1055: unsigned int i, j, k; fp@1055: const ec_sync_info_t *sync_info; fp@1055: const ec_pdo_info_t *pdo_info; fp@1055: const ec_pdo_entry_info_t *entry_info; fp@1055: fp@1055: if (sc->master->debug_level) fp@1082: EC_DBG("ecrt_slave_config_pdos(sc = 0x%x, n_syncs = %u, " fp@1055: "syncs = 0x%x)\n", (u32) sc, n_syncs, (u32) syncs); fp@1055: fp@1055: if (!syncs) ha@1054: return 0; ha@1054: fp@1055: for (i = 0; i < n_syncs; i++) { fp@1055: sync_info = &syncs[i]; fp@1055: fp@1097: if (sync_info->index == (uint8_t) EC_END) fp@878: break; fp@878: fp@1082: if (sync_info->index >= EC_MAX_SYNC_MANAGERS) { fp@1055: EC_ERR("Invalid sync manager index %u!\n", sync_info->index); fp@1055: return -1; fp@879: } fp@879: fp@1055: if (ecrt_slave_config_sync_manager( fp@1055: sc, sync_info->index, sync_info->dir)) fp@879: return -1; fp@879: fp@1055: if (sync_info->n_pdos && sync_info->pdos) { fp@1055: ecrt_slave_config_pdo_assign_clear(sc, sync_info->index); fp@1055: fp@1055: for (j = 0; j < sync_info->n_pdos; j++) { fp@1055: pdo_info = &sync_info->pdos[j]; fp@1055: fp@1055: if (ecrt_slave_config_pdo_assign_add( fp@1055: sc, sync_info->index, pdo_info->index)) fp@842: return -1; fp@1055: fp@1055: if (pdo_info->n_entries && pdo_info->entries) { fp@1055: ecrt_slave_config_pdo_mapping_clear(sc, pdo_info->index); fp@1055: fp@1055: for (k = 0; k < pdo_info->n_entries; k++) { fp@1055: entry_info = &pdo_info->entries[k]; fp@1055: fp@1055: if (ecrt_slave_config_pdo_mapping_add(sc, fp@1055: pdo_info->index, entry_info->index, fp@1055: entry_info->subindex, fp@1055: entry_info->bit_length)) fp@1055: return -1; fp@1055: } fp@1055: } fp@842: } fp@842: } fp@842: } fp@842: fp@792: return 0; fp@792: } fp@792: fp@792: /*****************************************************************************/ fp@792: fp@807: int ecrt_slave_config_reg_pdo_entry( ha@923: ec_slave_config_t *sc, ha@923: uint16_t index, ha@923: uint8_t subindex, ha@923: ec_domain_t *domain, fp@925: unsigned int *bit_position fp@916: ) fp@916: { fp@1055: uint8_t sync_index; fp@1055: const ec_sync_config_t *sync_config; fp@925: unsigned int bit_offset, bit_pos; fp@807: ec_pdo_t *pdo; fp@807: ec_pdo_entry_t *entry; ha@923: int sync_offset; fp@807: fp@941: if (sc->master->debug_level) fp@941: EC_DBG("ecrt_slave_config_reg_pdo_entry(sc = 0x%x, index = 0x%04X, " fp@941: "subindex = 0x%02X, domain = 0x%x, bit_position = 0x%x)\n", fp@1055: (u32) sc, index, subindex, (u32) domain, (u32) bit_position); fp@1055: fp@1082: for (sync_index = 0; sync_index < EC_MAX_SYNC_MANAGERS; sync_index++) { fp@1055: sync_config = &sc->sync_configs[sync_index]; fp@807: bit_offset = 0; fp@1055: fp@1055: list_for_each_entry(pdo, &sync_config->pdos.list, list) { fp@807: list_for_each_entry(entry, &pdo->entries, list) { fp@807: if (entry->index != index || entry->subindex != subindex) { fp@807: bit_offset += entry->bit_length; fp@807: } else { fp@1055: bit_pos = bit_offset % 8; fp@1055: if (bit_position) { fp@1055: *bit_position = bit_pos; fp@1055: } else if (bit_pos) { fp@1055: EC_ERR("Pdo entry 0x%04X:%02X does not byte-align " fp@1055: "in config %u:%u.\n", index, subindex, fp@1055: sc->alias, sc->position); fp@1055: return -3; fp@1055: } fp@1055: fp@1075: sync_offset = ec_slave_config_prepare_fmmu( fp@1075: sc, domain, sync_index, sync_config->dir); fp@1075: if (sync_offset < 0) fp@1075: return -2; fp@1075: fp@1055: return sync_offset + bit_offset / 8; fp@807: } fp@807: } fp@807: } fp@807: } fp@807: fp@926: EC_ERR("Pdo entry 0x%04X:%02X is not mapped in slave config %u:%u.\n", fp@807: index, subindex, sc->alias, sc->position); fp@807: return -1; ha@924: } ha@923: fp@807: fp@807: /*****************************************************************************/ fp@807: fp@893: int ecrt_slave_config_sdo(ec_slave_config_t *sc, uint16_t index, fp@893: uint8_t subindex, const uint8_t *data, size_t size) fp@893: { fp@893: ec_slave_t *slave = sc->slave; fp@893: ec_sdo_request_t *req; fp@893: fp@1115: if (sc->master->debug_level) fp@1115: EC_DBG("ecrt_slave_config_sdo(sc = 0x%x, index = 0x%04X, " fp@1115: "subindex = 0x%02X, data = 0x%x, size = %u)\n", (u32) sc, fp@1115: index, subindex, (u32) data, size); fp@1115: fp@893: if (slave && !(slave->sii.mailbox_protocols & EC_MBOX_COE)) { fp@893: EC_ERR("Slave %u does not support CoE!\n", slave->ring_position); fp@893: return -1; fp@893: } fp@893: fp@893: if (!(req = (ec_sdo_request_t *) fp@893: kmalloc(sizeof(ec_sdo_request_t), GFP_KERNEL))) { fp@893: EC_ERR("Failed to allocate memory for Sdo configuration!\n"); fp@893: return -1; fp@893: } fp@893: fp@893: ec_sdo_request_init(req); fp@893: ec_sdo_request_address(req, index, subindex); fp@893: fp@893: if (ec_sdo_request_copy_data(req, data, size)) { fp@893: ec_sdo_request_clear(req); fp@893: kfree(req); fp@893: return -1; fp@893: } fp@893: fp@1075: down(&sc->master->master_sem); fp@893: list_add_tail(&req->list, &sc->sdo_configs); fp@1075: up(&sc->master->master_sem); fp@1075: fp@893: return 0; fp@893: } fp@893: fp@893: /*****************************************************************************/ fp@893: fp@893: int ecrt_slave_config_sdo8(ec_slave_config_t *sc, uint16_t index, fp@792: uint8_t subindex, uint8_t value) fp@792: { fp@792: uint8_t data[1]; fp@1115: fp@1115: if (sc->master->debug_level) fp@1115: EC_DBG("ecrt_slave_config_sdo8(sc = 0x%x, index = 0x%04X, " fp@1115: "subindex = 0x%02X, value = %u)\n", (u32) sc, fp@1115: index, subindex, (u32) value); fp@1115: fp@792: EC_WRITE_U8(data, value); fp@893: return ecrt_slave_config_sdo(sc, index, subindex, data, 1); fp@893: } fp@893: fp@893: /*****************************************************************************/ fp@893: fp@893: int ecrt_slave_config_sdo16(ec_slave_config_t *sc, uint16_t index, fp@792: uint8_t subindex, uint16_t value) fp@792: { fp@792: uint8_t data[2]; fp@1115: fp@1115: if (sc->master->debug_level) fp@1115: EC_DBG("ecrt_slave_config_sdo16(sc = 0x%x, index = 0x%04X, " fp@1115: "subindex = 0x%02X, value = %u)\n", (u32) sc, fp@1115: index, subindex, value); fp@1115: fp@792: EC_WRITE_U16(data, value); fp@893: return ecrt_slave_config_sdo(sc, index, subindex, data, 2); fp@893: } fp@893: fp@893: /*****************************************************************************/ fp@893: fp@893: int ecrt_slave_config_sdo32(ec_slave_config_t *sc, uint16_t index, fp@792: uint8_t subindex, uint32_t value) fp@792: { fp@792: uint8_t data[4]; fp@1115: fp@1115: if (sc->master->debug_level) fp@1115: EC_DBG("ecrt_slave_config_sdo32(sc = 0x%x, index = 0x%04X, " fp@1115: "subindex = 0x%02X, value = %u)\n", (u32) sc, fp@1115: index, subindex, value); fp@1115: fp@792: EC_WRITE_U32(data, value); fp@893: return ecrt_slave_config_sdo(sc, index, subindex, data, 4); fp@792: } fp@792: fp@792: /*****************************************************************************/ fp@792: fp@858: ec_sdo_request_t *ecrt_slave_config_create_sdo_request(ec_slave_config_t *sc, fp@858: uint16_t index, uint8_t subindex, size_t size) fp@858: { fp@858: ec_sdo_request_t *req; fp@858: fp@1181: if (sc->master->debug_level) fp@1181: EC_DBG("ecrt_slave_config_create_sdo_request(sc = 0x%x, " fp@1181: "index = 0x%04X, subindex = 0x%02X, size = %u)\n", (u32) sc, fp@1181: index, subindex, size); fp@1181: fp@858: if (!(req = (ec_sdo_request_t *) fp@858: kmalloc(sizeof(ec_sdo_request_t), GFP_KERNEL))) { fp@858: EC_ERR("Failed to allocate Sdo request memory!\n"); fp@858: return NULL; fp@858: } fp@858: fp@858: ec_sdo_request_init(req); fp@858: ec_sdo_request_address(req, index, subindex); fp@858: fp@858: if (ec_sdo_request_alloc(req, size)) { fp@858: ec_sdo_request_clear(req); fp@858: kfree(req); fp@858: return NULL; fp@858: } fp@859: fp@859: // prepare data for optional writing fp@859: memset(req->data, 0x00, size); fp@859: req->data_size = size; fp@858: fp@1075: down(&sc->master->master_sem); fp@858: list_add_tail(&req->list, &sc->sdo_requests); fp@1075: up(&sc->master->master_sem); fp@1075: fp@858: return req; fp@858: } fp@858: fp@858: /*****************************************************************************/ fp@858: fp@1022: void ecrt_slave_config_state(const ec_slave_config_t *sc, fp@1022: ec_slave_config_state_t *state) fp@1022: { fp@1022: state->online = sc->slave ? 1 : 0; fp@1022: if (state->online) { fp@1022: state->operational = fp@1647: sc->slave->current_state == EC_SLAVE_STATE_OP fp@1647: && !sc->slave->force_config; fp@1022: state->al_state = sc->slave->current_state; fp@1022: } else { fp@1022: state->operational = 0; fp@1022: state->al_state = EC_SLAVE_STATE_UNKNOWN; fp@1022: } fp@1022: } fp@1022: fp@1022: /*****************************************************************************/ fp@1022: fp@792: /** \cond */ fp@792: fp@1055: EXPORT_SYMBOL(ecrt_slave_config_sync_manager); fp@879: EXPORT_SYMBOL(ecrt_slave_config_pdo_assign_add); fp@879: EXPORT_SYMBOL(ecrt_slave_config_pdo_assign_clear); fp@879: EXPORT_SYMBOL(ecrt_slave_config_pdo_mapping_add); fp@879: EXPORT_SYMBOL(ecrt_slave_config_pdo_mapping_clear); fp@1082: EXPORT_SYMBOL(ecrt_slave_config_pdos); fp@807: EXPORT_SYMBOL(ecrt_slave_config_reg_pdo_entry); fp@893: EXPORT_SYMBOL(ecrt_slave_config_sdo); fp@792: EXPORT_SYMBOL(ecrt_slave_config_sdo8); fp@792: EXPORT_SYMBOL(ecrt_slave_config_sdo16); fp@792: EXPORT_SYMBOL(ecrt_slave_config_sdo32); fp@858: EXPORT_SYMBOL(ecrt_slave_config_create_sdo_request); fp@1022: EXPORT_SYMBOL(ecrt_slave_config_state); fp@792: fp@792: /** \endcond */ fp@792: fp@792: /*****************************************************************************/