fp@64: /****************************************************************************** fp@64: * fp@64: * $Id$ fp@64: * fp@1618: * Copyright (C) 2006 Florian Pose, Ingenieurgemeinschaft IgH fp@1618: * fp@1618: * This file is part of the IgH EtherCAT Master. fp@1618: * fp@1618: * The IgH EtherCAT Master is free software; you can redistribute it fp@1618: * and/or modify it under the terms of the GNU General Public License fp@1619: * as published by the Free Software Foundation; either version 2 of the fp@1619: * License, or (at your option) any later version. fp@1618: * fp@1618: * The IgH EtherCAT Master is distributed in the hope that it will be fp@1618: * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of fp@1618: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the fp@1618: * GNU General Public License for more details. fp@1618: * fp@1618: * You should have received a copy of the GNU General Public License fp@1618: * along with the IgH EtherCAT Master; if not, write to the Free Software fp@1618: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA fp@1618: * fp@1619: * The right to use EtherCAT Technology is granted and comes free of fp@1619: * charge under condition of compatibility of product made by fp@1619: * Licensee. People intending to distribute/sell products based on the fp@1619: * code, have to sign an agreement to guarantee that products using fp@1619: * software based on IgH EtherCAT master stay compatible with the actual fp@1619: * EtherCAT specification (which are released themselves as an open fp@1619: * standard) as the (only) precondition to have the right to use EtherCAT fp@1619: * Technology, IP and trade marks. fp@1619: * fp@64: *****************************************************************************/ fp@64: fp@1618: /** fp@1618: \file fp@1618: Canopen-over-EtherCAT functions. fp@1618: */ fp@1618: fp@1618: /*****************************************************************************/ fp@1618: fp@64: #include fp@80: #include fp@80: #include fp@64: fp@64: #include "master.h" fp@145: #include "mailbox.h" fp@64: fp@64: /*****************************************************************************/ fp@64: fp@138: void ec_canopen_abort_msg(uint32_t); fp@1624: int ec_slave_fetch_sdo_descriptions(ec_slave_t *, ec_datagram_t *); fp@1624: int ec_slave_fetch_sdo_entries(ec_slave_t *, ec_datagram_t *, fp@1621: ec_sdo_t *, uint8_t); fp@138: fp@138: /*****************************************************************************/ fp@138: fp@138: /** fp@195: Reads 32 bit of a CANopen SDO in expedited mode. fp@195: \return 0 in case of success, else < 0 fp@1618: */ fp@195: fp@195: int ec_slave_sdo_read_exp(ec_slave_t *slave, /**< EtherCAT slave */ fp@195: uint16_t sdo_index, /**< SDO index */ fp@195: uint8_t sdo_subindex, /**< SDO subindex */ fp@195: uint8_t *target /**< 4-byte memory */ fp@139: ) fp@139: { fp@1624: ec_datagram_t datagram; fp@139: size_t rec_size; fp@144: uint8_t *data; fp@144: fp@1624: ec_datagram_init(&datagram); fp@1624: fp@1624: if (!(data = ec_slave_mbox_prepare_send(slave, &datagram, 0x03, 6))) fp@1621: goto err; fp@145: fp@139: EC_WRITE_U16(data, 0x2 << 12); // SDO request fp@139: EC_WRITE_U8 (data + 2, (0x1 << 1 // expedited transfer fp@195: | 0x2 << 5)); // initiate upload request fp@139: EC_WRITE_U16(data + 3, sdo_index); fp@139: EC_WRITE_U8 (data + 5, sdo_subindex); fp@145: fp@1624: if (!(data = ec_slave_mbox_simple_io(slave, &datagram, &rec_size))) fp@1621: goto err; fp@139: fp@139: if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request fp@195: EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort SDO transfer request fp@157: EC_ERR("SDO upload 0x%04X:%X aborted on slave %i.\n", fp@139: sdo_index, sdo_subindex, slave->ring_position); fp@139: ec_canopen_abort_msg(EC_READ_U32(data + 6)); fp@1621: goto err; fp@139: } fp@139: fp@139: if (EC_READ_U16(data) >> 12 != 0x3 || // SDO response fp@195: EC_READ_U8 (data + 2) >> 5 != 0x2 || // upload response fp@195: EC_READ_U16(data + 3) != sdo_index || // index fp@195: EC_READ_U8 (data + 5) != sdo_subindex) { // subindex fp@159: EC_ERR("SDO upload 0x%04X:%X failed:\n", sdo_index, sdo_subindex); fp@139: EC_ERR("Invalid SDO upload response at slave %i!\n", fp@139: slave->ring_position); fp@157: ec_print_data(data, rec_size); fp@1621: goto err; fp@139: } fp@139: fp@139: memcpy(target, data + 6, 4); fp@1621: fp@1624: ec_datagram_clear(&datagram); fp@1621: return 0; fp@1621: err: fp@1624: ec_datagram_clear(&datagram); fp@1621: return -1; fp@139: } fp@139: fp@139: /*****************************************************************************/ fp@139: fp@139: /** fp@195: Writes a CANopen SDO using expedited mode. fp@195: \return 0 in case of success, else < 0 fp@1618: */ fp@195: fp@195: int ec_slave_sdo_write_exp(ec_slave_t *slave, /**< EtherCAT slave */ fp@195: uint16_t sdo_index, /**< SDO index */ fp@195: uint8_t sdo_subindex, /**< SDO subindex */ fp@195: const uint8_t *sdo_data, /**< new value */ fp@1618: size_t size /**< Data size in bytes (1 - 4) */ fp@138: ) fp@64: { fp@144: uint8_t *data; fp@133: size_t rec_size; fp@1624: ec_datagram_t datagram; fp@1624: fp@1624: ec_datagram_init(&datagram); fp@64: fp@64: if (size == 0 || size > 4) { fp@138: EC_ERR("Invalid data size!\n"); fp@1621: goto err; fp@1621: } fp@1621: fp@1624: if (!(data = ec_slave_mbox_prepare_send(slave, &datagram, 0x03, 0x0A))) fp@1621: goto err; fp@145: fp@139: EC_WRITE_U16(data, 0x2 << 12); // SDO request fp@139: EC_WRITE_U8 (data + 2, (0x1 // size specified fp@139: | 0x1 << 1 // expedited transfer fp@139: | (4 - size) << 2 // data set size fp@139: | 0x1 << 5)); // initiate download request fp@133: EC_WRITE_U16(data + 3, sdo_index); fp@133: EC_WRITE_U8 (data + 5, sdo_subindex); fp@138: memcpy(data + 6, sdo_data, size); fp@138: if (size < 4) memset(data + 6 + size, 0x00, 4 - size); fp@145: fp@1624: if (!(data = ec_slave_mbox_simple_io(slave, &datagram, &rec_size))) fp@1621: goto err; fp@133: fp@139: if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request fp@195: EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort SDO transfer request fp@157: EC_ERR("SDO download 0x%04X:%X (%i bytes) aborted on slave %i.\n", fp@157: sdo_index, sdo_subindex, size, slave->ring_position); fp@133: ec_canopen_abort_msg(EC_READ_U32(data + 6)); fp@133: return -1; fp@133: } fp@133: fp@139: if (EC_READ_U16(data) >> 12 != 0x3 || // SDO response fp@195: EC_READ_U8 (data + 2) >> 5 != 0x3 || // download response fp@195: EC_READ_U16(data + 3) != sdo_index || // index fp@195: EC_READ_U8 (data + 5) != sdo_subindex) { // subindex fp@157: EC_ERR("SDO download 0x%04X:%X (%i bytes) failed:\n", fp@157: sdo_index, sdo_subindex, size); fp@111: EC_ERR("Invalid SDO download response at slave %i!\n", fp@73: slave->ring_position); fp@157: ec_print_data(data, rec_size); fp@64: return -1; fp@64: } fp@64: fp@1624: ec_datagram_clear(&datagram); fp@1621: return 0; fp@1621: err: fp@1624: ec_datagram_clear(&datagram); fp@1621: return -1; fp@64: } fp@64: fp@64: /*****************************************************************************/ fp@64: fp@80: /** fp@195: Reads a CANopen SDO in normal mode. fp@195: \return 0 in case of success, else < 0 fp@1618: \ingroup RealtimeInterface fp@1618: \todo Make size non-pointer. fp@1618: */ fp@195: fp@195: int ecrt_slave_sdo_read(ec_slave_t *slave, /**< EtherCAT slave */ fp@195: uint16_t sdo_index, /**< SDO index */ fp@195: uint8_t sdo_subindex, /**< SDO subindex */ fp@195: uint8_t *target, /**< memory for value */ fp@195: size_t *size /**< target memory size */ fp@137: ) fp@137: { fp@144: uint8_t *data; fp@137: size_t rec_size, data_size; fp@137: uint32_t complete_size; fp@1624: ec_datagram_t datagram; fp@1624: fp@1624: ec_datagram_init(&datagram); fp@1624: fp@1624: if (!(data = ec_slave_mbox_prepare_send(slave, &datagram, 0x03, 6))) fp@1621: goto err; fp@145: fp@139: EC_WRITE_U16(data, 0x2 << 12); // SDO request fp@139: EC_WRITE_U8 (data + 2, 0x2 << 5); // initiate upload request fp@137: EC_WRITE_U16(data + 3, sdo_index); fp@137: EC_WRITE_U8 (data + 5, sdo_subindex); fp@145: fp@1624: if (!(data = ec_slave_mbox_simple_io(slave, &datagram, &rec_size))) fp@1621: goto err; fp@137: fp@139: if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request fp@195: EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort SDO transfer request fp@157: EC_ERR("SDO upload 0x%04X:%X aborted on slave %i.\n", fp@137: sdo_index, sdo_subindex, slave->ring_position); fp@137: ec_canopen_abort_msg(EC_READ_U32(data + 6)); fp@1621: goto err; fp@137: } fp@137: fp@139: if (EC_READ_U16(data) >> 12 != 0x3 || // SDO response fp@195: EC_READ_U8 (data + 2) >> 5 != 0x2 || // initiate upload response fp@195: EC_READ_U16(data + 3) != sdo_index || // index fp@195: EC_READ_U8 (data + 5) != sdo_subindex) { // subindex fp@157: EC_ERR("SDO upload 0x%04X:%X failed:\n", sdo_index, sdo_subindex); fp@137: EC_ERR("Invalid SDO upload response at slave %i!\n", fp@137: slave->ring_position); fp@157: ec_print_data(data, rec_size); fp@1621: goto err; fp@137: } fp@137: fp@137: if (rec_size < 10) { fp@137: EC_ERR("Received currupted SDO upload response!\n"); fp@157: ec_print_data(data, rec_size); fp@1621: goto err; fp@137: } fp@137: fp@137: if ((complete_size = EC_READ_U32(data + 6)) > *size) { fp@137: EC_ERR("SDO data does not fit into buffer (%i / %i)!\n", fp@137: complete_size, *size); fp@1621: goto err; fp@137: } fp@137: fp@137: data_size = rec_size - 10; fp@137: fp@157: if (data_size != complete_size) { fp@157: EC_ERR("SDO data incomplete - Fragmenting not implemented.\n"); fp@1621: goto err; fp@157: } fp@157: fp@157: memcpy(target, data + 10, data_size); fp@1621: fp@1624: ec_datagram_clear(&datagram); fp@1621: return 0; fp@1621: err: fp@1624: ec_datagram_clear(&datagram); fp@1621: return -1; fp@137: } fp@137: fp@137: /*****************************************************************************/ fp@137: fp@137: /** fp@195: Fetches the SDO dictionary of a slave. fp@195: \return 0 in case of success, else < 0 fp@133: */ fp@133: fp@195: int ec_slave_fetch_sdo_list(ec_slave_t *slave /**< EtherCAT slave */) fp@133: { fp@144: uint8_t *data; fp@133: size_t rec_size; fp@135: unsigned int i, sdo_count; fp@135: ec_sdo_t *sdo; fp@135: uint16_t sdo_index; fp@1624: ec_datagram_t datagram; fp@1624: fp@1624: ec_datagram_init(&datagram); fp@1624: fp@1624: if (!(data = ec_slave_mbox_prepare_send(slave, &datagram, 0x03, 8))) fp@1621: goto err; fp@145: fp@139: EC_WRITE_U16(data, 0x8 << 12); // SDO information fp@139: EC_WRITE_U8 (data + 2, 0x01); // Get OD List Request fp@139: EC_WRITE_U8 (data + 3, 0x00); fp@138: EC_WRITE_U16(data + 4, 0x0000); fp@195: EC_WRITE_U16(data + 6, 0x0001); // deliver all SDOs! fp@145: fp@1624: if (unlikely(ec_master_simple_io(slave->master, &datagram))) { fp@157: EC_ERR("Mailbox checking failed on slave %i!\n", slave->ring_position); fp@1621: goto err; fp@144: } fp@133: fp@135: do { fp@1624: if (!(data = ec_slave_mbox_simple_receive(slave, &datagram, fp@1621: 0x03, &rec_size))) fp@1621: goto err; fp@133: fp@139: if (EC_READ_U16(data) >> 12 == 0x8 && // SDO information fp@195: (EC_READ_U8(data + 2) & 0x7F) == 0x07) { // error response fp@133: EC_ERR("SDO information error response at slave %i!\n", fp@133: slave->ring_position); fp@133: ec_canopen_abort_msg(EC_READ_U32(data + 6)); fp@1621: goto err; fp@133: } fp@133: fp@139: if (EC_READ_U16(data) >> 12 != 0x8 || // SDO information fp@133: (EC_READ_U8 (data + 2) & 0x7F) != 0x02) { // Get OD List response fp@133: EC_ERR("Invalid SDO list response at slave %i!\n", fp@133: slave->ring_position); fp@157: ec_print_data(data, rec_size); fp@1621: goto err; fp@133: } fp@133: fp@133: if (rec_size < 8) { fp@133: EC_ERR("Invalid data size!\n"); fp@157: ec_print_data(data, rec_size); fp@1621: goto err; fp@133: } fp@133: fp@135: sdo_count = (rec_size - 8) / 2; fp@135: for (i = 0; i < sdo_count; i++) { fp@135: sdo_index = EC_READ_U16(data + 8 + i * 2); fp@195: if (!sdo_index) continue; // sometimes index is 0... ??? fp@135: fp@135: if (!(sdo = (ec_sdo_t *) kmalloc(sizeof(ec_sdo_t), GFP_KERNEL))) { fp@135: EC_ERR("Failed to allocate memory for SDO!\n"); fp@1621: goto err; fp@135: } fp@157: fp@157: // Initialize SDO object fp@135: sdo->index = sdo_index; fp@175: //sdo->unkown = 0x0000; fp@175: sdo->object_code = 0x00; fp@135: sdo->name = NULL; fp@157: INIT_LIST_HEAD(&sdo->entries); fp@157: fp@135: list_add_tail(&sdo->list, &slave->sdo_dictionary); fp@135: } fp@157: } fp@157: while (EC_READ_U8(data + 2) & 0x80); fp@135: fp@195: // Fetch all SDO descriptions fp@1624: if (ec_slave_fetch_sdo_descriptions(slave, &datagram)) goto err; fp@1624: fp@1624: ec_datagram_clear(&datagram); fp@1621: return 0; fp@1621: err: fp@1624: ec_datagram_clear(&datagram); fp@1621: return -1; fp@135: } fp@135: fp@135: /*****************************************************************************/ fp@135: fp@135: /** fp@195: Fetches the SDO descriptions for the known SDOs. fp@195: \return 0 in case of success, else < 0 fp@135: */ fp@135: fp@1621: int ec_slave_fetch_sdo_descriptions(ec_slave_t *slave, /**< EtherCAT slave */ fp@1624: ec_datagram_t *datagram /**< datagram */ fp@1621: ) fp@135: { fp@144: uint8_t *data; fp@135: size_t rec_size, name_size; fp@135: ec_sdo_t *sdo; fp@135: fp@135: list_for_each_entry(sdo, &slave->sdo_dictionary, list) { fp@1624: if (!(data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 8))) fp@1621: return -1; fp@139: EC_WRITE_U16(data, 0x8 << 12); // SDO information fp@139: EC_WRITE_U8 (data + 2, 0x03); // Get object description request fp@139: EC_WRITE_U8 (data + 3, 0x00); fp@138: EC_WRITE_U16(data + 4, 0x0000); fp@135: EC_WRITE_U16(data + 6, sdo->index); // SDO index fp@145: fp@1624: if (!(data = ec_slave_mbox_simple_io(slave, datagram, &rec_size))) fp@1621: return -1; fp@135: fp@139: if (EC_READ_U16(data) >> 12 == 0x8 && // SDO information fp@195: (EC_READ_U8 (data + 2) & 0x7F) == 0x07) { // error response fp@135: EC_ERR("SDO information error response at slave %i while" fp@135: " fetching SDO 0x%04X!\n", slave->ring_position, fp@135: sdo->index); fp@135: ec_canopen_abort_msg(EC_READ_U32(data + 6)); fp@135: return -1; fp@135: } fp@135: fp@139: if (EC_READ_U16(data) >> 12 != 0x8 || // SDO information fp@139: (EC_READ_U8 (data + 2) & 0x7F) != 0x04 || // Object desc. response fp@135: EC_READ_U16(data + 6) != sdo->index) { // SDO index fp@135: EC_ERR("Invalid object description response at slave %i while" fp@135: " fetching SDO 0x%04X!\n", slave->ring_position, fp@135: sdo->index); fp@157: ec_print_data(data, rec_size); fp@135: return -1; fp@135: } fp@135: fp@135: if (rec_size < 12) { fp@135: EC_ERR("Invalid data size!\n"); fp@157: ec_print_data(data, rec_size); fp@135: return -1; fp@135: } fp@135: fp@1621: #if 0 fp@175: EC_DBG("object desc response:\n"); fp@175: ec_print_data(data, rec_size); fp@1621: #endif fp@175: fp@175: //sdo->unknown = EC_READ_U16(data + 8); fp@175: sdo->object_code = EC_READ_U8(data + 11); fp@135: fp@135: name_size = rec_size - 12; fp@139: if (name_size) { fp@139: if (!(sdo->name = kmalloc(name_size + 1, GFP_KERNEL))) { fp@139: EC_ERR("Failed to allocate SDO name!\n"); fp@139: return -1; fp@139: } fp@139: fp@139: memcpy(sdo->name, data + 12, name_size); fp@139: sdo->name[name_size] = 0; fp@139: } fp@139: fp@139: if (EC_READ_U8(data + 2) & 0x80) { fp@139: EC_ERR("Fragment follows (not implemented)!\n"); fp@139: return -1; fp@139: } fp@139: fp@195: // Fetch all entries (subindices) fp@1624: if (ec_slave_fetch_sdo_entries(slave, datagram, sdo, fp@1621: EC_READ_U8(data + 10))) fp@139: return -1; fp@139: } fp@139: fp@139: return 0; fp@139: } fp@139: fp@139: /*****************************************************************************/ fp@139: fp@139: /** fp@195: Fetches all entries (subindices) to an SDO. fp@195: \return 0 in case of success, else < 0 fp@139: */ fp@139: fp@195: int ec_slave_fetch_sdo_entries(ec_slave_t *slave, /**< EtherCAT slave */ fp@1624: ec_datagram_t *datagram, /**< datagram */ fp@139: ec_sdo_t *sdo, /**< SDO */ fp@195: uint8_t subindices /**< number of subindices */ fp@139: ) fp@139: { fp@144: uint8_t *data; fp@139: size_t rec_size, data_size; fp@139: uint8_t i; fp@139: ec_sdo_entry_t *entry; fp@139: fp@139: for (i = 1; i <= subindices; i++) { fp@1624: if (!(data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 10))) fp@145: return -1; fp@145: fp@139: EC_WRITE_U16(data, 0x8 << 12); // SDO information fp@139: EC_WRITE_U8 (data + 2, 0x05); // Get entry description request fp@139: EC_WRITE_U8 (data + 3, 0x00); fp@139: EC_WRITE_U16(data + 4, 0x0000); fp@139: EC_WRITE_U16(data + 6, sdo->index); // SDO index fp@139: EC_WRITE_U8 (data + 8, i); // SDO subindex fp@139: EC_WRITE_U8 (data + 9, 0x00); // value info (no values) fp@145: fp@1624: if (!(data = ec_slave_mbox_simple_io(slave, datagram, &rec_size))) fp@1621: return -1; fp@139: fp@139: if (EC_READ_U16(data) >> 12 == 0x8 && // SDO information fp@195: (EC_READ_U8 (data + 2) & 0x7F) == 0x07) { // error response fp@139: EC_ERR("SDO information error response at slave %i while" fp@139: " fetching SDO entry 0x%04X:%i!\n", slave->ring_position, fp@139: sdo->index, i); fp@139: ec_canopen_abort_msg(EC_READ_U32(data + 6)); fp@139: return -1; fp@139: } fp@139: fp@139: if (EC_READ_U16(data) >> 12 != 0x8 || // SDO information fp@195: (EC_READ_U8(data + 2) & 0x7F) != 0x06 || // Entry desc. response fp@139: EC_READ_U16(data + 6) != sdo->index || // SDO index fp@139: EC_READ_U8(data + 8) != i) { // SDO subindex fp@139: EC_ERR("Invalid entry description response at slave %i while" fp@161: " fetching SDO entry 0x%04X:%i!\n", slave->ring_position, fp@139: sdo->index, i); fp@157: ec_print_data(data, rec_size); fp@139: return -1; fp@139: } fp@139: fp@139: if (rec_size < 16) { fp@139: EC_ERR("Invalid data size!\n"); fp@157: ec_print_data(data, rec_size); fp@139: return -1; fp@139: } fp@139: fp@139: if (!EC_READ_U16(data + 12)) // bit length = 0 fp@135: continue; fp@139: fp@139: data_size = rec_size - 16; fp@139: fp@139: if (!(entry = (ec_sdo_entry_t *) fp@139: kmalloc(sizeof(ec_sdo_entry_t) + data_size + 1, GFP_KERNEL))) { fp@161: EC_ERR("Failed to allocate entry!\n"); fp@139: return -1; fp@139: } fp@139: fp@139: entry->subindex = i; fp@139: entry->data_type = EC_READ_U16(data + 10); fp@139: entry->bit_length = EC_READ_U16(data + 12); fp@161: fp@161: // memory for name string appended to entry fp@161: entry->name = (uint8_t *) entry + sizeof(ec_sdo_entry_t); fp@161: fp@161: memcpy(entry->name, data + 16, data_size); fp@161: entry->name[data_size] = 0; fp@139: fp@139: list_add_tail(&entry->list, &sdo->entries); fp@135: } fp@133: fp@133: return 0; fp@133: } fp@133: fp@133: /*****************************************************************************/ fp@133: fp@133: /** fp@1623: SDO abort messages. fp@1623: The "abort SDO transfer request" supplies an abort code, fp@1623: which can be translated to clear text. This table does fp@1623: the mapping of the codes and messages. fp@1623: */ fp@133: fp@164: const ec_code_msg_t sdo_abort_messages[] = { fp@111: {0x05030000, "Toggle bit not changed"}, fp@111: {0x05040000, "SDO protocol timeout"}, fp@111: {0x05040001, "Client/Server command specifier not valid or unknown"}, fp@111: {0x05040005, "Out of memory"}, fp@111: {0x06010000, "Unsupported access to an object"}, fp@111: {0x06010001, "Attempt to read a write-only object"}, fp@111: {0x06010002, "Attempt to write a read-only object"}, fp@111: {0x06020000, "This object does not exist in the object directory"}, fp@111: {0x06040041, "The object cannot be mapped into the PDO"}, fp@111: {0x06040042, "The number and length of the objects to be mapped would" fp@111: " exceed the PDO length"}, fp@111: {0x06040043, "General parameter incompatibility reason"}, fp@111: {0x06040047, "Gerneral internal incompatibility in device"}, fp@111: {0x06060000, "Access failure due to a hardware error"}, fp@111: {0x06070010, "Data type does not match, length of service parameter does" fp@111: " not match"}, fp@111: {0x06070012, "Data type does not match, length of service parameter too" fp@111: " high"}, fp@111: {0x06070013, "Data type does not match, length of service parameter too" fp@111: " low"}, fp@111: {0x06090011, "Subindex does not exist"}, fp@111: {0x06090030, "Value range of parameter exceeded"}, fp@111: {0x06090031, "Value of parameter written too high"}, fp@111: {0x06090032, "Value of parameter written too low"}, fp@111: {0x06090036, "Maximum value is less than minimum value"}, fp@111: {0x08000000, "General error"}, fp@111: {0x08000020, "Data cannot be transferred or stored to the application"}, fp@111: {0x08000021, "Data cannot be transferred or stored to the application" fp@111: " because of local control"}, fp@111: {0x08000022, "Data cannot be transferred or stored to the application" fp@111: " because of the present device state"}, fp@111: {0x08000023, "Object dictionary dynamic generation fails or no object" fp@111: " dictionary is present"}, fp@111: {} fp@111: }; fp@111: fp@1623: /*****************************************************************************/ fp@1623: fp@1623: /** fp@1623: Outputs an SDO abort message. fp@1623: */ fp@1623: fp@1623: void ec_canopen_abort_msg(uint32_t abort_code) fp@1623: { fp@1623: const ec_code_msg_t *abort_msg; fp@1623: fp@1623: for (abort_msg = sdo_abort_messages; abort_msg->code; abort_msg++) { fp@1623: if (abort_msg->code == abort_code) { fp@1623: EC_ERR("SDO abort message 0x%08X: \"%s\".\n", fp@1623: abort_msg->code, abort_msg->message); fp@1623: return; fp@1623: } fp@1623: } fp@1623: fp@1623: EC_ERR("Unknown SDO abort code 0x%08X.\n", abort_code); fp@1623: } fp@1623: fp@195: /****************************************************************************** fp@195: * Realtime interface fp@195: *****************************************************************************/ fp@195: fp@195: /** fp@195: Reads an 8-bit SDO in expedited mode. fp@195: See ec_slave_sdo_read_exp() fp@195: \return 0 in case of success, else < 0 fp@1618: \ingroup RealtimeInterface fp@1618: */ fp@195: fp@195: int ecrt_slave_sdo_read_exp8(ec_slave_t *slave, /**< EtherCAT slave */ fp@195: uint16_t sdo_index, /**< SDO index */ fp@195: uint8_t sdo_subindex, /**< SDO subindex */ fp@195: uint8_t *target /**< memory for read value */ fp@138: ) fp@138: { fp@138: uint8_t data[4]; fp@138: if (ec_slave_sdo_read_exp(slave, sdo_index, sdo_subindex, data)) return -1; fp@138: *target = EC_READ_U8(data); fp@138: return 0; fp@138: } fp@138: fp@138: /*****************************************************************************/ fp@138: fp@138: /** fp@195: Reads a 16-bit SDO in expedited mode. fp@195: See ec_slave_sdo_read_exp() fp@195: \return 0 in case of success, else < 0 fp@1618: \ingroup RealtimeInterface fp@1618: */ fp@195: fp@195: int ecrt_slave_sdo_read_exp16(ec_slave_t *slave, /**< EtherCAT slave */ fp@195: uint16_t sdo_index, /**< SDO index */ fp@195: uint8_t sdo_subindex, /**< SDO subindex */ fp@195: uint16_t *target /**< memory for read value */ fp@138: ) fp@138: { fp@138: uint8_t data[4]; fp@138: if (ec_slave_sdo_read_exp(slave, sdo_index, sdo_subindex, data)) return -1; fp@138: *target = EC_READ_U16(data); fp@138: return 0; fp@138: } fp@138: fp@138: /*****************************************************************************/ fp@138: fp@138: /** fp@195: Reads a 32-bit SDO in expedited mode. fp@195: See ec_slave_sdo_read_exp() fp@195: \return 0 in case of success, else < 0 fp@1618: \ingroup RealtimeInterface fp@1618: */ fp@195: fp@195: int ecrt_slave_sdo_read_exp32(ec_slave_t *slave, /**< EtherCAT slave */ fp@195: uint16_t sdo_index, /**< SDO index */ fp@195: uint8_t sdo_subindex, /**< SDO subindex */ fp@195: uint32_t *target /**< memory for read value */ fp@138: ) fp@138: { fp@138: uint8_t data[4]; fp@138: if (ec_slave_sdo_read_exp(slave, sdo_index, sdo_subindex, data)) return -1; fp@138: *target = EC_READ_U32(data); fp@138: return 0; fp@138: } fp@138: fp@138: /*****************************************************************************/ fp@138: fp@138: /** fp@195: Writes an 8-bit SDO in expedited mode. fp@195: \return 0 in case of success, else < 0 fp@1618: \ingroup RealtimeInterface fp@1618: */ fp@195: fp@195: int ecrt_slave_sdo_write_exp8(ec_slave_t *slave, /**< EtherCAT slave */ fp@195: uint16_t sdo_index, /**< SDO index */ fp@195: uint8_t sdo_subindex, /**< SDO subindex */ fp@195: uint8_t value /**< new value */ fp@138: ) fp@138: { fp@138: return ec_slave_sdo_write_exp(slave, sdo_index, sdo_subindex, &value, 1); fp@138: } fp@138: fp@138: /*****************************************************************************/ fp@138: fp@138: /** fp@195: Writes a 16-bit SDO in expedited mode. fp@195: \return 0 in case of success, else < 0 fp@1618: \ingroup RealtimeInterface fp@1618: */ fp@195: fp@195: int ecrt_slave_sdo_write_exp16(ec_slave_t *slave, /**< EtherCAT slave */ fp@195: uint16_t sdo_index, /**< SDO index */ fp@195: uint8_t sdo_subindex, /**< SDO subindex */ fp@195: uint16_t value /**< new value */ fp@138: ) fp@138: { fp@138: uint8_t data[2]; fp@138: EC_WRITE_U16(data, value); fp@138: return ec_slave_sdo_write_exp(slave, sdo_index, sdo_subindex, data, 2); fp@138: } fp@138: fp@138: /*****************************************************************************/ fp@138: fp@138: /** fp@195: Writes a 32-bit SDO in expedited mode. fp@195: \return 0 in case of success, else < 0 fp@1618: \ingroup RealtimeInterface fp@1618: */ fp@195: fp@195: int ecrt_slave_sdo_write_exp32(ec_slave_t *slave, /**< EtherCAT slave */ fp@195: uint16_t sdo_index, /**< SDO index */ fp@195: uint8_t sdo_subindex, /**< SDO subindex */ fp@195: uint32_t value /**< new value */ fp@138: ) fp@138: { fp@138: uint8_t data[4]; fp@138: EC_WRITE_U32(data, value); fp@138: return ec_slave_sdo_write_exp(slave, sdo_index, sdo_subindex, data, 4); fp@138: } fp@138: fp@138: /*****************************************************************************/ fp@138: fp@1618: /** \cond */ fp@1618: fp@138: EXPORT_SYMBOL(ecrt_slave_sdo_read_exp8); fp@138: EXPORT_SYMBOL(ecrt_slave_sdo_read_exp16); fp@138: EXPORT_SYMBOL(ecrt_slave_sdo_read_exp32); fp@138: EXPORT_SYMBOL(ecrt_slave_sdo_write_exp8); fp@138: EXPORT_SYMBOL(ecrt_slave_sdo_write_exp16); fp@138: EXPORT_SYMBOL(ecrt_slave_sdo_write_exp32); fp@104: EXPORT_SYMBOL(ecrt_slave_sdo_read); fp@64: fp@1618: /** \endcond */ fp@1618: fp@1618: /*****************************************************************************/