author | Florian Pose <fp@igh-essen.com> |
Tue, 29 Jul 2008 09:30:33 +0000 | |
changeset 1170 | af068174a630 |
parent 933 | 618ab9e03321 |
child 1186 | ff481f097c97 |
permissions | -rw-r--r-- |
933
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1 |
/****************************************************************************** |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
2 |
* |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
3 |
* $Id$ |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
4 |
* |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
5 |
* Copyright (C) 2006 Florian Pose, Ingenieurgemeinschaft IgH |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
6 |
* |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
7 |
* This file is part of the IgH EtherCAT Master. |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
8 |
* |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
9 |
* The IgH EtherCAT Master is free software; you can redistribute it |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
10 |
* and/or modify it under the terms of the GNU General Public License |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
11 |
* as published by the Free Software Foundation; either version 2 of the |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
12 |
* License, or (at your option) any later version. |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
13 |
* |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
14 |
* The IgH EtherCAT Master is distributed in the hope that it will be |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
15 |
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
17 |
* GNU General Public License for more details. |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
18 |
* |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
19 |
* You should have received a copy of the GNU General Public License |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
20 |
* along with the IgH EtherCAT Master; if not, write to the Free Software |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
21 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
22 |
* |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
23 |
* The right to use EtherCAT Technology is granted and comes free of |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
24 |
* charge under condition of compatibility of product made by |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
25 |
* Licensee. People intending to distribute/sell products based on the |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
26 |
* code, have to sign an agreement to guarantee that products using |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
27 |
* software based on IgH EtherCAT master stay compatible with the actual |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
28 |
* EtherCAT specification (which are released themselves as an open |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
29 |
* standard) as the (only) precondition to have the right to use EtherCAT |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
30 |
* Technology, IP and trade marks. |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
31 |
* |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
32 |
*****************************************************************************/ |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
33 |
|
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
34 |
/** |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
35 |
\file |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
36 |
EtherCAT process data object entry methods. |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
37 |
*/ |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
38 |
|
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
39 |
/*****************************************************************************/ |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
40 |
|
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
41 |
#include <linux/slab.h> |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
42 |
|
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
43 |
#include "pdo_entry.h" |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
44 |
|
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
45 |
/*****************************************************************************/ |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
46 |
|
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
47 |
/** Pdo entry constructor. |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
48 |
*/ |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
49 |
void ec_pdo_entry_init( |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
50 |
ec_pdo_entry_t *entry /**< Pdo entry. */ |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
51 |
) |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
52 |
{ |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
53 |
entry->name = NULL; |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
54 |
} |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
55 |
|
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
56 |
/*****************************************************************************/ |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
57 |
|
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
58 |
/** Pdo entry copy constructor. |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
59 |
*/ |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
60 |
int ec_pdo_entry_init_copy( |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
61 |
ec_pdo_entry_t *entry, /**< Pdo entry. */ |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
62 |
const ec_pdo_entry_t *other /**< Pdo entry to copy from. */ |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
63 |
) |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
64 |
{ |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
65 |
entry->index = other->index; |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
66 |
entry->subindex = other->subindex; |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
67 |
entry->name = NULL; |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
68 |
entry->bit_length = other->bit_length; |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
69 |
|
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
70 |
if (ec_pdo_entry_set_name(entry, other->name)) |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
71 |
return -1; |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
72 |
|
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
73 |
return 0; |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
74 |
} |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
75 |
|
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
76 |
/*****************************************************************************/ |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
77 |
|
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
78 |
/** Pdo entry destructor. |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
79 |
*/ |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
80 |
void ec_pdo_entry_clear(ec_pdo_entry_t *entry /**< Pdo entry. */) |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
81 |
{ |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
82 |
if (entry->name) |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
83 |
kfree(entry->name); |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
84 |
} |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
85 |
|
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
86 |
/*****************************************************************************/ |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
87 |
|
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
88 |
/** Set Pdo entry name. |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
89 |
*/ |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
90 |
int ec_pdo_entry_set_name( |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
91 |
ec_pdo_entry_t *entry, /**< Pdo entry. */ |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
92 |
const char *name /**< New name. */ |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
93 |
) |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
94 |
{ |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
95 |
unsigned int len; |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
96 |
|
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
97 |
if (entry->name) |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
98 |
kfree(entry->name); |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
99 |
|
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
100 |
if (name && (len = strlen(name))) { |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
101 |
if (!(entry->name = (char *) kmalloc(len + 1, GFP_KERNEL))) { |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
102 |
EC_ERR("Failed to allocate Pdo entry name.\n"); |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
103 |
return -1; |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
104 |
} |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
105 |
memcpy(entry->name, name, len + 1); |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
106 |
} else { |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
107 |
entry->name = NULL; |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
108 |
} |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
109 |
|
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
110 |
return 0; |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
111 |
} |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
112 |
|
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
113 |
/*****************************************************************************/ |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
114 |
|
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
115 |
/** Compares two Pdo entries. |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
116 |
* |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
117 |
* \retval 1 The entries are equal. |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
118 |
* \retval 0 The entries differ. |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
119 |
*/ |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
120 |
int ec_pdo_entry_equal( |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
121 |
const ec_pdo_entry_t *entry1, /**< First Pdo entry. */ |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
122 |
const ec_pdo_entry_t *entry2 /**< Second Pdo entry. */ |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
123 |
) |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
124 |
{ |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
125 |
return entry1->index == entry2->index |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
126 |
&& entry1->subindex == entry2->subindex |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
127 |
&& entry1->bit_length == entry2->bit_length; |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
128 |
} |
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
129 |
|
618ab9e03321
Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
130 |
/*****************************************************************************/ |