IgH EtherCAT Master  1.5.3
pdo_entry.c
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * $Id$
4  *
5  * Copyright (C) 2006-2008 Florian Pose, Ingenieurgemeinschaft IgH
6  *
7  * This file is part of the IgH EtherCAT Master.
8  *
9  * The IgH EtherCAT Master is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License version 2, as
11  * published by the Free Software Foundation.
12  *
13  * The IgH EtherCAT Master is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16  * Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with the IgH EtherCAT Master; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  * ---
23  *
24  * The license mentioned above concerns the source code only. Using the
25  * EtherCAT technology and brand is only permitted in compliance with the
26  * industrial property and similar rights of Beckhoff Automation GmbH.
27  *
28  *****************************************************************************/
29 
35 /*****************************************************************************/
36 
37 #include <linux/slab.h>
38 
39 #include "pdo_entry.h"
40 
41 /*****************************************************************************/
42 
46  ec_pdo_entry_t *entry
47  )
48 {
49  entry->name = NULL;
50 }
51 
52 /*****************************************************************************/
53 
60  ec_pdo_entry_t *entry,
61  const ec_pdo_entry_t *other
62  )
63 {
64  entry->index = other->index;
65  entry->subindex = other->subindex;
66  entry->name = NULL;
67  entry->bit_length = other->bit_length;
68 
69  return ec_pdo_entry_set_name(entry, other->name);
70 }
71 
72 /*****************************************************************************/
73 
77 {
78  if (entry->name)
79  kfree(entry->name);
80 }
81 
82 /*****************************************************************************/
83 
90  ec_pdo_entry_t *entry,
91  const char *name
92  )
93 {
94  unsigned int len;
95 
96  if (entry->name && name && !strcmp(entry->name, name))
97  return 0;
98 
99  if (entry->name)
100  kfree(entry->name);
101 
102  if (name && (len = strlen(name))) {
103  if (!(entry->name = (char *) kmalloc(len + 1, GFP_KERNEL))) {
104  EC_ERR("Failed to allocate PDO entry name.\n");
105  return -ENOMEM;
106  }
107  memcpy(entry->name, name, len + 1);
108  } else {
109  entry->name = NULL;
110  }
111 
112  return 0;
113 }
114 
115 /*****************************************************************************/
116 
123  const ec_pdo_entry_t *entry1,
124  const ec_pdo_entry_t *entry2
125  )
126 {
127  return entry1->index == entry2->index
128  && entry1->subindex == entry2->subindex
129  && entry1->bit_length == entry2->bit_length;
130 }
131 
132 /*****************************************************************************/
PDO entry description.
Definition: pdo_entry.h:48
uint16_t index
PDO entry index.
Definition: pdo_entry.h:50
void ec_pdo_entry_clear(ec_pdo_entry_t *entry)
PDO entry destructor.
Definition: pdo_entry.c:76
int ec_pdo_entry_equal(const ec_pdo_entry_t *entry1, const ec_pdo_entry_t *entry2)
Compares two PDO entries.
Definition: pdo_entry.c:122
uint8_t bit_length
entry length in bit
Definition: pdo_entry.h:53
int ec_pdo_entry_init_copy(ec_pdo_entry_t *entry, const ec_pdo_entry_t *other)
PDO entry copy constructor.
Definition: pdo_entry.c:59
void ec_pdo_entry_init(ec_pdo_entry_t *entry)
PDO entry constructor.
Definition: pdo_entry.c:45
EtherCAT Process data object structure.
uint8_t subindex
PDO entry subindex.
Definition: pdo_entry.h:51
char * name
entry name
Definition: pdo_entry.h:52
#define EC_ERR(fmt, args...)
Convenience macro for printing EtherCAT-specific errors to syslog.
Definition: globals.h:215
int ec_pdo_entry_set_name(ec_pdo_entry_t *entry, const char *name)
Set PDO entry name.
Definition: pdo_entry.c:89