fp@933: /****************************************************************************** fp@933: * fp@933: * $Id$ fp@933: * fp@933: * Copyright (C) 2006 Florian Pose, Ingenieurgemeinschaft IgH fp@933: * fp@933: * This file is part of the IgH EtherCAT Master. fp@933: * fp@933: * The IgH EtherCAT Master is free software; you can redistribute it fp@933: * and/or modify it under the terms of the GNU General Public License fp@933: * as published by the Free Software Foundation; either version 2 of the fp@933: * License, or (at your option) any later version. fp@933: * fp@933: * The IgH EtherCAT Master is distributed in the hope that it will be fp@933: * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of fp@933: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the fp@933: * GNU General Public License for more details. fp@933: * fp@933: * You should have received a copy of the GNU General Public License fp@933: * along 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@933: * The right to use EtherCAT Technology is granted and comes free of fp@933: * charge under condition of compatibility of product made by fp@933: * Licensee. People intending to distribute/sell products based on the fp@933: * code, have to sign an agreement to guarantee that products using fp@933: * software based on IgH EtherCAT master stay compatible with the actual fp@933: * EtherCAT specification (which are released themselves as an open fp@933: * standard) as the (only) precondition to have the right to use EtherCAT fp@933: * Technology, IP and trade marks. 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@933: /** Pdo entry constructor. fp@933: */ fp@933: void ec_pdo_entry_init( fp@933: 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@933: /** Pdo entry copy constructor. fp@933: */ fp@933: int ec_pdo_entry_init_copy( fp@933: ec_pdo_entry_t *entry, /**< Pdo entry. */ fp@933: 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@933: if (ec_pdo_entry_set_name(entry, other->name)) fp@933: return -1; fp@933: fp@933: return 0; fp@933: } fp@933: fp@933: /*****************************************************************************/ fp@933: fp@933: /** Pdo entry destructor. fp@933: */ fp@933: 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@933: /** Set Pdo entry name. fp@933: */ fp@933: int ec_pdo_entry_set_name( fp@933: 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@1186: 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@933: EC_ERR("Failed to allocate Pdo entry name.\n"); fp@933: return -1; 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@933: /** 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@933: const ec_pdo_entry_t *entry1, /**< First Pdo entry. */ fp@933: 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: /*****************************************************************************/