00001 /****************************************************************************** 00002 * 00003 * $Id$ 00004 * 00005 * Copyright (C) 2006-2008 Florian Pose, Ingenieurgemeinschaft IgH 00006 * 00007 * This file is part of the IgH EtherCAT Master. 00008 * 00009 * The IgH EtherCAT Master is free software; you can redistribute it and/or 00010 * modify it under the terms of the GNU General Public License version 2, as 00011 * published by the Free Software Foundation. 00012 * 00013 * The IgH EtherCAT Master is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 00016 * Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License along 00019 * with the IgH EtherCAT Master; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00021 * 00022 * --- 00023 * 00024 * The license mentioned above concerns the source code only. Using the 00025 * EtherCAT technology and brand is only permitted in compliance with the 00026 * industrial property and similar rights of Beckhoff Automation GmbH. 00027 * 00028 *****************************************************************************/ 00029 00035 /*****************************************************************************/ 00036 00037 #include <linux/slab.h> 00038 00039 #include "pdo_entry.h" 00040 00041 /*****************************************************************************/ 00042 00045 void ec_pdo_entry_init( 00046 ec_pdo_entry_t *entry 00047 ) 00048 { 00049 entry->name = NULL; 00050 } 00051 00052 /*****************************************************************************/ 00053 00059 int ec_pdo_entry_init_copy( 00060 ec_pdo_entry_t *entry, 00061 const ec_pdo_entry_t *other 00062 ) 00063 { 00064 entry->index = other->index; 00065 entry->subindex = other->subindex; 00066 entry->name = NULL; 00067 entry->bit_length = other->bit_length; 00068 00069 return ec_pdo_entry_set_name(entry, other->name); 00070 } 00071 00072 /*****************************************************************************/ 00073 00076 void ec_pdo_entry_clear(ec_pdo_entry_t *entry ) 00077 { 00078 if (entry->name) 00079 kfree(entry->name); 00080 } 00081 00082 /*****************************************************************************/ 00083 00089 int ec_pdo_entry_set_name( 00090 ec_pdo_entry_t *entry, 00091 const char *name 00092 ) 00093 { 00094 unsigned int len; 00095 00096 if (entry->name && name && !strcmp(entry->name, name)) 00097 return 0; 00098 00099 if (entry->name) 00100 kfree(entry->name); 00101 00102 if (name && (len = strlen(name))) { 00103 if (!(entry->name = (char *) kmalloc(len + 1, GFP_KERNEL))) { 00104 EC_ERR("Failed to allocate PDO entry name.\n"); 00105 return -ENOMEM; 00106 } 00107 memcpy(entry->name, name, len + 1); 00108 } else { 00109 entry->name = NULL; 00110 } 00111 00112 return 0; 00113 } 00114 00115 /*****************************************************************************/ 00116 00122 int ec_pdo_entry_equal( 00123 const ec_pdo_entry_t *entry1, 00124 const ec_pdo_entry_t *entry2 00125 ) 00126 { 00127 return entry1->index == entry2->index 00128 && entry1->subindex == entry2->subindex 00129 && entry1->bit_length == entry2->bit_length; 00130 } 00131 00132 /*****************************************************************************/
1.5.6