author | Florian Pose <fp@igh-essen.com> |
Fri, 01 Feb 2008 20:26:13 +0000 | |
changeset 778 | 7fc85507f49a |
parent 627 | 4793ca94f082 |
child 792 | 3778920f61e4 |
permissions | -rw-r--r-- |
627
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1 |
/****************************************************************************** |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
2 |
* |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
3 |
* $Id$ |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
4 |
* |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
5 |
* Copyright (C) 2006 Florian Pose, Ingenieurgemeinschaft IgH |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
6 |
* |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
7 |
* This file is part of the IgH EtherCAT Master. |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
8 |
* |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
9 |
* The IgH EtherCAT Master is free software; you can redistribute it |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
10 |
* and/or modify it under the terms of the GNU General Public License |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
11 |
* as published by the Free Software Foundation; either version 2 of the |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
12 |
* License, or (at your option) any later version. |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
13 |
* |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
14 |
* The IgH EtherCAT Master is distributed in the hope that it will be |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
15 |
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
17 |
* GNU General Public License for more details. |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
18 |
* |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
19 |
* You should have received a copy of the GNU General Public License |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
20 |
* along with the IgH EtherCAT Master; if not, write to the Free Software |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
21 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
22 |
* |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
23 |
* The right to use EtherCAT Technology is granted and comes free of |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
24 |
* charge under condition of compatibility of product made by |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
25 |
* Licensee. People intending to distribute/sell products based on the |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
26 |
* code, have to sign an agreement to guarantee that products using |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
27 |
* software based on IgH EtherCAT master stay compatible with the actual |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
28 |
* EtherCAT specification (which are released themselves as an open |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
29 |
* standard) as the (only) precondition to have the right to use EtherCAT |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
30 |
* Technology, IP and trade marks. |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
31 |
* |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
32 |
*****************************************************************************/ |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
33 |
|
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
34 |
/** |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
35 |
\file |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
36 |
EtherCAT process data object methods. |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
37 |
*/ |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
38 |
|
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
39 |
/*****************************************************************************/ |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
40 |
|
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
41 |
#include <linux/slab.h> |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
42 |
|
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
43 |
#include "pdo.h" |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
44 |
|
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
45 |
/*****************************************************************************/ |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
46 |
|
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
47 |
/** |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
48 |
* PDO constructor. |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
49 |
*/ |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
50 |
|
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
51 |
void ec_pdo_init(ec_pdo_t *pdo /**< EtherCAT PDO */) |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
52 |
{ |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
53 |
pdo->name = NULL; |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
54 |
INIT_LIST_HEAD(&pdo->entries); |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
55 |
} |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
56 |
|
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
57 |
/*****************************************************************************/ |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
58 |
|
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
59 |
/** |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
60 |
* PDO destructor. |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
61 |
*/ |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
62 |
|
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
63 |
void ec_pdo_clear(ec_pdo_t *pdo /**< EtherCAT PDO */) |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
64 |
{ |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
65 |
ec_pdo_entry_t *entry, *next; |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
66 |
|
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
67 |
// free all PDO entries |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
68 |
list_for_each_entry_safe(entry, next, &pdo->entries, list) { |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
69 |
list_del(&entry->list); |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
70 |
kfree(entry); |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
71 |
} |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
72 |
} |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
73 |
|
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
74 |
/*****************************************************************************/ |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
75 |
|
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
76 |
/** |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
77 |
* Makes a deep copy of a PDO. |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
78 |
*/ |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
79 |
|
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
80 |
int ec_pdo_copy(ec_pdo_t *pdo, const ec_pdo_t *other_pdo) |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
81 |
{ |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
82 |
ec_pdo_entry_t *entry, *other_entry, *next; |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
83 |
|
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
84 |
// make flat copy |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
85 |
*pdo = *other_pdo; |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
86 |
|
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
87 |
INIT_LIST_HEAD(&pdo->entries); |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
88 |
list_for_each_entry(other_entry, &other_pdo->entries, list) { |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
89 |
if (!(entry = (ec_pdo_entry_t *) |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
90 |
kmalloc(sizeof(ec_pdo_entry_t), GFP_KERNEL))) { |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
91 |
EC_ERR("Failed to allocate memory for PDO entry copy.\n"); |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
92 |
goto out_free; |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
93 |
} |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
94 |
|
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
95 |
*entry = *other_entry; // flat copy is sufficient |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
96 |
list_add_tail(&entry->list, &pdo->entries); |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
97 |
} |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
98 |
|
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
99 |
return 0; |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
100 |
|
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
101 |
out_free: |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
102 |
list_for_each_entry_safe(entry, next, &pdo->entries, list) { |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
103 |
list_del(&entry->list); |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
104 |
kfree(entry); |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
105 |
} |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
106 |
return -1; |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
107 |
} |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
108 |
|
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
109 |
/*****************************************************************************/ |