fp@933: /****************************************************************************** fp@933: * fp@933: * $Id$ fp@933: * fp@1326: * Copyright (C) 2006-2008 Florian Pose, Ingenieurgemeinschaft IgH fp@933: * fp@933: * This file is part of the IgH EtherCAT Master. fp@933: * fp@1326: * The IgH EtherCAT Master is free software; you can redistribute it and/or fp@1326: * modify it under the terms of the GNU General Public License version 2, as fp@1326: * published by the Free Software Foundation. fp@933: * fp@1326: * The IgH EtherCAT Master is distributed in the hope that it will be useful, fp@1326: * but WITHOUT ANY WARRANTY; without even the implied warranty of fp@1326: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General fp@1326: * Public License for more details. fp@933: * fp@1326: * You should have received a copy of the GNU General Public License along fp@1326: * with the IgH EtherCAT Master; if not, write to the Free Software fp@933: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA fp@933: * fp@1363: * --- fp@1363: * fp@1363: * The license mentioned above concerns the source code only. Using the fp@1363: * EtherCAT technology and brand is only permitted in compliance with the fp@1363: * industrial property and similar rights of Beckhoff Automation GmbH. fp@933: * fp@933: *****************************************************************************/ fp@933: fp@933: /** fp@933: \file fp@933: EtherCAT process data object entry methods. fp@933: */ fp@933: fp@933: /*****************************************************************************/ fp@933: fp@933: #include fp@933: fp@933: #include "pdo_entry.h" fp@933: fp@933: /*****************************************************************************/ fp@933: fp@1327: /** PDO entry constructor. fp@933: */ fp@933: void ec_pdo_entry_init( fp@1327: ec_pdo_entry_t *entry /**< PDO entry. */ fp@933: ) fp@933: { fp@933: entry->name = NULL; fp@933: } fp@933: fp@933: /*****************************************************************************/ fp@933: fp@1327: /** PDO entry copy constructor. fp@1313: * fp@1313: * \retval 0 Success. fp@1313: * \retval <0 Error code. fp@933: */ fp@933: int ec_pdo_entry_init_copy( fp@1327: ec_pdo_entry_t *entry, /**< PDO entry. */ fp@1327: const ec_pdo_entry_t *other /**< PDO entry to copy from. */ fp@933: ) fp@933: { fp@933: entry->index = other->index; fp@933: entry->subindex = other->subindex; fp@933: entry->name = NULL; fp@933: entry->bit_length = other->bit_length; fp@933: fp@1313: return ec_pdo_entry_set_name(entry, other->name); fp@933: } fp@933: fp@933: /*****************************************************************************/ fp@933: fp@1327: /** PDO entry destructor. fp@933: */ fp@1327: void ec_pdo_entry_clear(ec_pdo_entry_t *entry /**< PDO entry. */) fp@933: { fp@933: if (entry->name) fp@933: kfree(entry->name); fp@933: } fp@933: fp@933: /*****************************************************************************/ fp@933: fp@1327: /** Set PDO entry name. fp@1313: * fp@1313: * \retval 0 Success. fp@1313: * \retval <0 Error code. fp@933: */ fp@933: int ec_pdo_entry_set_name( fp@1327: ec_pdo_entry_t *entry, /**< PDO entry. */ fp@933: const char *name /**< New name. */ fp@933: ) fp@933: { fp@933: unsigned int len; fp@933: fp@1186: if (entry->name && name && !strcmp(entry->name, name)) fp@1186: return 0; fp@2421: fp@933: if (entry->name) fp@933: kfree(entry->name); fp@933: fp@933: if (name && (len = strlen(name))) { fp@933: if (!(entry->name = (char *) kmalloc(len + 1, GFP_KERNEL))) { fp@1327: EC_ERR("Failed to allocate PDO entry name.\n"); fp@1313: return -ENOMEM; fp@933: } fp@933: memcpy(entry->name, name, len + 1); fp@933: } else { fp@933: entry->name = NULL; fp@933: } fp@933: fp@933: return 0; fp@933: } fp@933: fp@933: /*****************************************************************************/ fp@933: fp@1327: /** Compares two PDO entries. fp@933: * fp@933: * \retval 1 The entries are equal. fp@933: * \retval 0 The entries differ. fp@933: */ fp@933: int ec_pdo_entry_equal( fp@1327: const ec_pdo_entry_t *entry1, /**< First PDO entry. */ fp@1327: const ec_pdo_entry_t *entry2 /**< Second PDO entry. */ fp@933: ) fp@933: { fp@933: return entry1->index == entry2->index fp@933: && entry1->subindex == entry2->subindex fp@933: && entry1->bit_length == entry2->bit_length; fp@933: } fp@933: fp@933: /*****************************************************************************/