IgH EtherCAT Master  1.6.9
pdo_entry.c
Go to the documentation of this file.
1/*****************************************************************************
2 *
3 * Copyright (C) 2006-2008 Florian Pose, Ingenieurgemeinschaft IgH
4 *
5 * This file is part of the IgH EtherCAT Master.
6 *
7 * The IgH EtherCAT Master is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License version 2, as
9 * published by the Free Software Foundation.
10 *
11 * The IgH EtherCAT Master is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
14 * Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with the IgH EtherCAT Master; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 ****************************************************************************/
21
26
27/****************************************************************************/
28
29#include <linux/slab.h>
30
31#include "pdo_entry.h"
32
33/****************************************************************************/
34
38 ec_pdo_entry_t *entry
39 )
40{
41 entry->name = NULL;
42}
43
44/****************************************************************************/
45
52 ec_pdo_entry_t *entry,
53 const ec_pdo_entry_t *other
54 )
55{
56 entry->index = other->index;
57 entry->subindex = other->subindex;
58 entry->name = NULL;
59 entry->bit_length = other->bit_length;
60
61 return ec_pdo_entry_set_name(entry, other->name);
62}
63
64/****************************************************************************/
65
69{
70 if (entry->name)
71 kfree(entry->name);
72}
73
74/****************************************************************************/
75
82 ec_pdo_entry_t *entry,
83 const char *name
84 )
85{
86 unsigned int len;
87
88 if (entry->name && name && !strcmp(entry->name, name))
89 return 0;
90
91 if (entry->name)
92 kfree(entry->name);
93
94 if (name && (len = strlen(name))) {
95 if (!(entry->name = (char *) kmalloc(len + 1, GFP_KERNEL))) {
96 EC_ERR("Failed to allocate PDO entry name.\n");
97 return -ENOMEM;
98 }
99 memcpy(entry->name, name, len + 1);
100 } else {
101 entry->name = NULL;
102 }
103
104 return 0;
105}
106
107/****************************************************************************/
108
115 const ec_pdo_entry_t *entry1,
116 const ec_pdo_entry_t *entry2
117 )
118{
119 return entry1->index == entry2->index
120 && entry1->subindex == entry2->subindex
121 && entry1->bit_length == entry2->bit_length;
122}
123
124/****************************************************************************/
#define EC_ERR(fmt, args...)
Convenience macro for printing EtherCAT-specific errors to syslog.
Definition globals.h:224
void ec_pdo_entry_clear(ec_pdo_entry_t *entry)
PDO entry destructor.
Definition pdo_entry.c:68
int ec_pdo_entry_set_name(ec_pdo_entry_t *entry, const char *name)
Set PDO entry name.
Definition pdo_entry.c:81
void ec_pdo_entry_init(ec_pdo_entry_t *entry)
PDO entry constructor.
Definition pdo_entry.c:37
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:51
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:114
EtherCAT Process data object structure.
PDO entry description.
Definition pdo_entry.h:40
uint8_t bit_length
entry length in bit
Definition pdo_entry.h:45
uint8_t subindex
PDO entry subindex.
Definition pdo_entry.h:43
char * name
entry name
Definition pdo_entry.h:44
uint16_t index
PDO entry index.
Definition pdo_entry.h:42