author | Florian Pose <fp@igh-essen.com> |
Tue, 22 Jul 2008 14:17:20 +0000 | |
changeset 1126 | b09fd81894cb |
parent 1092 | 69393cf60399 |
child 1186 | ff481f097c97 |
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 |
|
814 | 47 |
/** Pdo constructor. |
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
48 |
*/ |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
49 |
void ec_pdo_init( |
814 | 50 |
ec_pdo_t *pdo /**< EtherCAT Pdo */ |
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
51 |
) |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
52 |
{ |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
53 |
pdo->sync_index = -1; // not assigned |
627
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
54 |
pdo->name = NULL; |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
55 |
INIT_LIST_HEAD(&pdo->entries); |
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 |
|
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
60 |
/** Pdo copy constructor. |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
61 |
*/ |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
62 |
int ec_pdo_init_copy(ec_pdo_t *pdo, const ec_pdo_t *other_pdo) |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
63 |
{ |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
64 |
pdo->index = other_pdo->index; |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
65 |
pdo->sync_index = other_pdo->sync_index; |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
66 |
pdo->name = NULL; |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
67 |
INIT_LIST_HEAD(&pdo->entries); |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
68 |
|
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
69 |
if (ec_pdo_set_name(pdo, other_pdo->name)) |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
70 |
goto out_return; |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
71 |
|
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
72 |
if (ec_pdo_copy_entries(pdo, other_pdo)) |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
73 |
goto out_clear; |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
74 |
|
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
75 |
return 0; |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
76 |
|
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
77 |
out_clear: |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
78 |
ec_pdo_clear(pdo); |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
79 |
out_return: |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
80 |
return -1; |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
81 |
} |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
82 |
|
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
83 |
/*****************************************************************************/ |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
84 |
|
814 | 85 |
/** Pdo destructor. |
86 |
*/ |
|
842
40e27e5a8dce
Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents:
826
diff
changeset
|
87 |
void ec_pdo_clear(ec_pdo_t *pdo /**< EtherCAT Pdo. */) |
627
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
88 |
{ |
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
89 |
if (pdo->name) |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
90 |
kfree(pdo->name); |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
91 |
|
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
92 |
ec_pdo_clear_entries(pdo); |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
93 |
} |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
94 |
|
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
95 |
/*****************************************************************************/ |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
96 |
|
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
97 |
/** Clear Pdo entry list. |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
98 |
*/ |
842
40e27e5a8dce
Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents:
826
diff
changeset
|
99 |
void ec_pdo_clear_entries(ec_pdo_t *pdo /**< EtherCAT Pdo. */) |
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
100 |
{ |
627
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
101 |
ec_pdo_entry_t *entry, *next; |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
102 |
|
814 | 103 |
// free all Pdo entries |
627
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
104 |
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
|
105 |
list_del(&entry->list); |
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
106 |
ec_pdo_entry_clear(entry); |
627
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
107 |
kfree(entry); |
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 |
} |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
110 |
|
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
111 |
/*****************************************************************************/ |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
112 |
|
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
113 |
/** Set Pdo name. |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
114 |
*/ |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
115 |
int ec_pdo_set_name( |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
116 |
ec_pdo_t *pdo, /**< Pdo. */ |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
117 |
const char *name /**< New name. */ |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
118 |
) |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
119 |
{ |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
120 |
unsigned int len; |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
121 |
|
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
122 |
if (pdo->name) |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
123 |
kfree(pdo->name); |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
124 |
|
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
125 |
if (name && (len = strlen(name))) { |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
126 |
if (!(pdo->name = (char *) kmalloc(len + 1, GFP_KERNEL))) { |
814 | 127 |
EC_ERR("Failed to allocate Pdo name.\n"); |
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
128 |
return -1; |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
129 |
} |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
130 |
memcpy(pdo->name, name, len + 1); |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
131 |
} else { |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
132 |
pdo->name = NULL; |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
133 |
} |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
134 |
|
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
135 |
return 0; |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
136 |
} |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
137 |
|
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
138 |
/*****************************************************************************/ |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
139 |
|
842
40e27e5a8dce
Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents:
826
diff
changeset
|
140 |
/** Add a new Pdo entry to the configuration. |
40e27e5a8dce
Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents:
826
diff
changeset
|
141 |
*/ |
40e27e5a8dce
Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents:
826
diff
changeset
|
142 |
ec_pdo_entry_t *ec_pdo_add_entry( |
40e27e5a8dce
Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents:
826
diff
changeset
|
143 |
ec_pdo_t *pdo, |
40e27e5a8dce
Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents:
826
diff
changeset
|
144 |
uint16_t index, |
40e27e5a8dce
Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents:
826
diff
changeset
|
145 |
uint8_t subindex, |
40e27e5a8dce
Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents:
826
diff
changeset
|
146 |
uint8_t bit_length |
40e27e5a8dce
Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents:
826
diff
changeset
|
147 |
) |
40e27e5a8dce
Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents:
826
diff
changeset
|
148 |
{ |
40e27e5a8dce
Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents:
826
diff
changeset
|
149 |
ec_pdo_entry_t *entry; |
40e27e5a8dce
Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents:
826
diff
changeset
|
150 |
|
40e27e5a8dce
Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents:
826
diff
changeset
|
151 |
if (!(entry = kmalloc(sizeof(ec_pdo_entry_t), GFP_KERNEL))) { |
40e27e5a8dce
Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents:
826
diff
changeset
|
152 |
EC_ERR("Failed to allocate memory for Pdo entry.\n"); |
40e27e5a8dce
Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents:
826
diff
changeset
|
153 |
return NULL; |
40e27e5a8dce
Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents:
826
diff
changeset
|
154 |
} |
40e27e5a8dce
Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents:
826
diff
changeset
|
155 |
|
40e27e5a8dce
Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents:
826
diff
changeset
|
156 |
ec_pdo_entry_init(entry); |
40e27e5a8dce
Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents:
826
diff
changeset
|
157 |
entry->index = index; |
40e27e5a8dce
Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents:
826
diff
changeset
|
158 |
entry->subindex = subindex; |
40e27e5a8dce
Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents:
826
diff
changeset
|
159 |
entry->bit_length = bit_length; |
40e27e5a8dce
Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents:
826
diff
changeset
|
160 |
list_add_tail(&entry->list, &pdo->entries); |
40e27e5a8dce
Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents:
826
diff
changeset
|
161 |
return entry; |
40e27e5a8dce
Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents:
826
diff
changeset
|
162 |
} |
40e27e5a8dce
Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents:
826
diff
changeset
|
163 |
|
40e27e5a8dce
Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents:
826
diff
changeset
|
164 |
/*****************************************************************************/ |
40e27e5a8dce
Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents:
826
diff
changeset
|
165 |
|
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
166 |
/** Copy Pdo entries from another Pdo. |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
167 |
*/ |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
168 |
int ec_pdo_copy_entries(ec_pdo_t *pdo, const ec_pdo_t *other) |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
169 |
{ |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
170 |
ec_pdo_entry_t *entry, *other_entry; |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
171 |
|
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
172 |
ec_pdo_clear_entries(pdo); |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
173 |
|
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
174 |
list_for_each_entry(other_entry, &other->entries, list) { |
627
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
175 |
if (!(entry = (ec_pdo_entry_t *) |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
176 |
kmalloc(sizeof(ec_pdo_entry_t), GFP_KERNEL))) { |
814 | 177 |
EC_ERR("Failed to allocate memory for Pdo entry copy.\n"); |
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
178 |
return -1; |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
179 |
} |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
180 |
|
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
181 |
if (ec_pdo_entry_init_copy(entry, other_entry)) { |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
182 |
kfree(entry); |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
183 |
return -1; |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
184 |
} |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
185 |
|
627
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
186 |
list_add_tail(&entry->list, &pdo->entries); |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
187 |
} |
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
188 |
|
4793ca94f082
Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
189 |
return 0; |
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
190 |
} |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
191 |
|
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
192 |
/*****************************************************************************/ |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
627
diff
changeset
|
193 |
|
799 | 194 |
/** Compares the entries of two Pdos. |
195 |
* |
|
196 |
* \retval 1 The entries of the given Pdos are equal. |
|
197 |
* \retval 0 The entries of the given Pdos differ. |
|
198 |
*/ |
|
199 |
int ec_pdo_equal_entries( |
|
200 |
const ec_pdo_t *pdo1, /**< First Pdo. */ |
|
201 |
const ec_pdo_t *pdo2 /**< Second Pdo. */ |
|
202 |
) |
|
203 |
{ |
|
204 |
const struct list_head *head1, *head2, *item1, *item2; |
|
205 |
const ec_pdo_entry_t *entry1, *entry2; |
|
206 |
||
207 |
head1 = item1 = &pdo1->entries; |
|
208 |
head2 = item2 = &pdo2->entries; |
|
209 |
||
210 |
while (1) { |
|
211 |
item1 = item1->next; |
|
212 |
item2 = item2->next; |
|
213 |
||
214 |
if ((item1 == head1) ^ (item2 == head2)) // unequal lengths |
|
215 |
return 0; |
|
826 | 216 |
if (item1 == head1) // both finished |
799 | 217 |
break; |
218 |
||
219 |
entry1 = list_entry(item1, ec_pdo_entry_t, list); |
|
220 |
entry2 = list_entry(item2, ec_pdo_entry_t, list); |
|
221 |
if (!ec_pdo_entry_equal(entry1, entry2)) |
|
222 |
return 0; |
|
223 |
} |
|
224 |
||
225 |
return 1; |
|
226 |
} |
|
227 |
||
228 |
/*****************************************************************************/ |
|
934
96241b092fac
Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents:
933
diff
changeset
|
229 |
|
1092 | 230 |
/** Get the number of Pdo entries. |
231 |
* |
|
232 |
* \return Number of Pdo entries. |
|
934
96241b092fac
Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents:
933
diff
changeset
|
233 |
*/ |
96241b092fac
Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents:
933
diff
changeset
|
234 |
unsigned int ec_pdo_entry_count( |
96241b092fac
Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents:
933
diff
changeset
|
235 |
const ec_pdo_t *pdo /**< Pdo. */ |
96241b092fac
Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents:
933
diff
changeset
|
236 |
) |
96241b092fac
Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents:
933
diff
changeset
|
237 |
{ |
96241b092fac
Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents:
933
diff
changeset
|
238 |
const ec_pdo_entry_t *entry; |
96241b092fac
Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents:
933
diff
changeset
|
239 |
unsigned int num = 0; |
96241b092fac
Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents:
933
diff
changeset
|
240 |
|
96241b092fac
Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents:
933
diff
changeset
|
241 |
list_for_each_entry(entry, &pdo->entries, list) { |
96241b092fac
Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents:
933
diff
changeset
|
242 |
num++; |
96241b092fac
Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents:
933
diff
changeset
|
243 |
} |
96241b092fac
Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents:
933
diff
changeset
|
244 |
|
96241b092fac
Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents:
933
diff
changeset
|
245 |
return num; |
96241b092fac
Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents:
933
diff
changeset
|
246 |
} |
96241b092fac
Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents:
933
diff
changeset
|
247 |
|
96241b092fac
Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents:
933
diff
changeset
|
248 |
/*****************************************************************************/ |
96241b092fac
Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents:
933
diff
changeset
|
249 |
|
96241b092fac
Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents:
933
diff
changeset
|
250 |
/** Finds a Pdo entry via its position in the list. |
96241b092fac
Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents:
933
diff
changeset
|
251 |
* |
96241b092fac
Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents:
933
diff
changeset
|
252 |
* Const version. |
96241b092fac
Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents:
933
diff
changeset
|
253 |
*/ |
96241b092fac
Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents:
933
diff
changeset
|
254 |
const ec_pdo_entry_t *ec_pdo_find_entry_by_pos_const( |
96241b092fac
Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents:
933
diff
changeset
|
255 |
const ec_pdo_t *pdo, /**< Pdo. */ |
96241b092fac
Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents:
933
diff
changeset
|
256 |
unsigned int pos /**< Position in the list. */ |
96241b092fac
Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents:
933
diff
changeset
|
257 |
) |
96241b092fac
Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents:
933
diff
changeset
|
258 |
{ |
96241b092fac
Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents:
933
diff
changeset
|
259 |
const ec_pdo_entry_t *entry; |
96241b092fac
Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents:
933
diff
changeset
|
260 |
|
96241b092fac
Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents:
933
diff
changeset
|
261 |
list_for_each_entry(entry, &pdo->entries, list) { |
96241b092fac
Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents:
933
diff
changeset
|
262 |
if (pos--) |
96241b092fac
Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents:
933
diff
changeset
|
263 |
continue; |
96241b092fac
Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents:
933
diff
changeset
|
264 |
return entry; |
96241b092fac
Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents:
933
diff
changeset
|
265 |
} |
96241b092fac
Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents:
933
diff
changeset
|
266 |
|
96241b092fac
Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents:
933
diff
changeset
|
267 |
return NULL; |
96241b092fac
Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents:
933
diff
changeset
|
268 |
} |
96241b092fac
Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents:
933
diff
changeset
|
269 |
|
96241b092fac
Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents:
933
diff
changeset
|
270 |
/*****************************************************************************/ |