author | Florian Pose <fp@igh-essen.com> |
Fri, 17 Oct 2008 13:35:56 +0000 | |
changeset 1278 | b93ceb5ebe37 |
parent 1266 | dd1f501c4070 |
child 1287 | cc7b679c74e9 |
permissions | -rw-r--r-- |
1255
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1 |
/****************************************************************************** |
1266
dd1f501c4070
Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1259
diff
changeset
|
2 |
* |
dd1f501c4070
Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1259
diff
changeset
|
3 |
* $Id$ |
dd1f501c4070
Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1259
diff
changeset
|
4 |
* |
dd1f501c4070
Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1259
diff
changeset
|
5 |
* Copyright (C) 2006-2008 Florian Pose, Ingenieurgemeinschaft IgH |
dd1f501c4070
Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1259
diff
changeset
|
6 |
* |
dd1f501c4070
Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1259
diff
changeset
|
7 |
* This file is part of the IgH EtherCAT master userspace library. |
dd1f501c4070
Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1259
diff
changeset
|
8 |
* |
dd1f501c4070
Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1259
diff
changeset
|
9 |
* The IgH EtherCAT master userspace library is free software: you can |
dd1f501c4070
Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1259
diff
changeset
|
10 |
* redistribute it and/or modify it under the terms of the GNU Lesser General |
dd1f501c4070
Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1259
diff
changeset
|
11 |
* Public License as published by the Free Software Foundation, version 2 of |
dd1f501c4070
Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1259
diff
changeset
|
12 |
* the License. |
dd1f501c4070
Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1259
diff
changeset
|
13 |
* |
dd1f501c4070
Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1259
diff
changeset
|
14 |
* The IgH EtherCAT master userspace library is distributed in the hope that |
dd1f501c4070
Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1259
diff
changeset
|
15 |
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
dd1f501c4070
Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1259
diff
changeset
|
16 |
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
dd1f501c4070
Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1259
diff
changeset
|
17 |
* GNU Lesser General Public License for more details. |
dd1f501c4070
Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1259
diff
changeset
|
18 |
* |
dd1f501c4070
Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1259
diff
changeset
|
19 |
* You should have received a copy of the GNU Lesser General Public License |
dd1f501c4070
Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1259
diff
changeset
|
20 |
* along with the IgH EtherCAT master userspace library. If not, see |
dd1f501c4070
Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1259
diff
changeset
|
21 |
* <http://www.gnu.org/licenses/>. |
dd1f501c4070
Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1259
diff
changeset
|
22 |
* |
dd1f501c4070
Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1259
diff
changeset
|
23 |
* The right to use EtherCAT Technology is granted and comes free of charge |
dd1f501c4070
Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1259
diff
changeset
|
24 |
* under condition of compatibility of product made by Licensee. People |
dd1f501c4070
Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1259
diff
changeset
|
25 |
* intending to distribute/sell products based on the code, have to sign an |
dd1f501c4070
Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1259
diff
changeset
|
26 |
* agreement to guarantee that products using software based on IgH EtherCAT |
dd1f501c4070
Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1259
diff
changeset
|
27 |
* master stay compatible with the actual EtherCAT specification (which are |
dd1f501c4070
Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1259
diff
changeset
|
28 |
* released themselves as an open standard) as the (only) precondition to have |
dd1f501c4070
Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1259
diff
changeset
|
29 |
* the right to use EtherCAT Technology, IP and trade marks. |
1255
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
30 |
* |
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
31 |
*****************************************************************************/ |
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
32 |
|
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
33 |
/** |
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
34 |
\file |
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
35 |
EtherCAT domain methods. |
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
36 |
*/ |
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
37 |
|
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
38 |
/*****************************************************************************/ |
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
39 |
|
1258
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1257
diff
changeset
|
40 |
#include <sys/ioctl.h> |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1257
diff
changeset
|
41 |
#include <sys/mman.h> |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1257
diff
changeset
|
42 |
#include <stdio.h> |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1257
diff
changeset
|
43 |
#include <errno.h> |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1257
diff
changeset
|
44 |
#include <string.h> |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1257
diff
changeset
|
45 |
|
1255
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
46 |
#include "domain.h" |
1258
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1257
diff
changeset
|
47 |
#include "master.h" |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1257
diff
changeset
|
48 |
#include "master/ioctl.h" |
1255
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
49 |
|
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
50 |
/*****************************************************************************/ |
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
51 |
|
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
52 |
int ecrt_domain_reg_pdo_entry_list(ec_domain_t *domain, |
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
53 |
const ec_pdo_entry_reg_t *regs) |
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
54 |
{ |
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
55 |
const ec_pdo_entry_reg_t *reg; |
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
56 |
ec_slave_config_t *sc; |
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
57 |
int ret; |
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
58 |
|
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
59 |
for (reg = regs; reg->index; reg++) { |
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
60 |
if (!(sc = ecrt_master_slave_config(domain->master, reg->alias, |
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
61 |
reg->position, reg->vendor_id, reg->product_code))) |
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
62 |
return -1; |
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
63 |
|
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
64 |
if ((ret = ecrt_slave_config_reg_pdo_entry(sc, reg->index, |
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
65 |
reg->subindex, domain, reg->bit_position)) < 0) |
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
66 |
return -1; |
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
67 |
|
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
68 |
*reg->offset = ret; |
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
69 |
} |
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
70 |
|
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
71 |
return 0; |
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
72 |
} |
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
73 |
|
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
74 |
/*****************************************************************************/ |
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
75 |
|
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
76 |
uint8_t *ecrt_domain_data(ec_domain_t *domain) |
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
77 |
{ |
1258
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1257
diff
changeset
|
78 |
if (!domain->process_data) { |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1257
diff
changeset
|
79 |
int offset = 0; |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1257
diff
changeset
|
80 |
|
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1257
diff
changeset
|
81 |
offset = ioctl(domain->master->fd, EC_IOCTL_DOMAIN_OFFSET, |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1257
diff
changeset
|
82 |
domain->index); |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1257
diff
changeset
|
83 |
if (offset == -1) { |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1257
diff
changeset
|
84 |
fprintf(stderr, "Failed to get domain offset: %s\n", |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1257
diff
changeset
|
85 |
strerror(errno)); |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1257
diff
changeset
|
86 |
return NULL; |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1257
diff
changeset
|
87 |
} |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1257
diff
changeset
|
88 |
|
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1257
diff
changeset
|
89 |
domain->process_data = domain->master->process_data + offset; |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1257
diff
changeset
|
90 |
} |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1257
diff
changeset
|
91 |
|
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1257
diff
changeset
|
92 |
return domain->process_data; |
1255
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
93 |
} |
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
94 |
|
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
95 |
/*****************************************************************************/ |
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
96 |
|
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
97 |
void ecrt_domain_process(ec_domain_t *domain) |
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
98 |
{ |
1258
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1257
diff
changeset
|
99 |
if (ioctl(domain->master->fd, EC_IOCTL_DOMAIN_PROCESS, |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1257
diff
changeset
|
100 |
domain->index) == -1) { |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1257
diff
changeset
|
101 |
fprintf(stderr, "Failed to process domain offset: %s\n", |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1257
diff
changeset
|
102 |
strerror(errno)); |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1257
diff
changeset
|
103 |
} |
1255
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
104 |
} |
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
105 |
|
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
106 |
/*****************************************************************************/ |
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
107 |
|
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
108 |
void ecrt_domain_queue(ec_domain_t *domain) |
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
109 |
{ |
1258
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1257
diff
changeset
|
110 |
if (ioctl(domain->master->fd, EC_IOCTL_DOMAIN_QUEUE, |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1257
diff
changeset
|
111 |
domain->index) == -1) { |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1257
diff
changeset
|
112 |
fprintf(stderr, "Failed to queue domain offset: %s\n", |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1257
diff
changeset
|
113 |
strerror(errno)); |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1257
diff
changeset
|
114 |
} |
1255
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
115 |
} |
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
116 |
|
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
117 |
/*****************************************************************************/ |
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
118 |
|
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
119 |
void ecrt_domain_state(const ec_domain_t *domain, ec_domain_state_t *state) |
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
120 |
{ |
1259
5f9d1abbee71
Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents:
1258
diff
changeset
|
121 |
ec_ioctl_domain_state_t data; |
5f9d1abbee71
Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents:
1258
diff
changeset
|
122 |
|
5f9d1abbee71
Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents:
1258
diff
changeset
|
123 |
data.domain_index = domain->index; |
5f9d1abbee71
Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents:
1258
diff
changeset
|
124 |
data.state = state; |
5f9d1abbee71
Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents:
1258
diff
changeset
|
125 |
|
5f9d1abbee71
Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents:
1258
diff
changeset
|
126 |
if (ioctl(domain->master->fd, EC_IOCTL_DOMAIN_STATE, &data) == -1) { |
5f9d1abbee71
Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents:
1258
diff
changeset
|
127 |
fprintf(stderr, "Failed to get domain state: %s\n", |
5f9d1abbee71
Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents:
1258
diff
changeset
|
128 |
strerror(errno)); |
5f9d1abbee71
Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents:
1258
diff
changeset
|
129 |
} |
1255
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
130 |
} |
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
131 |
|
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
132 |
/*****************************************************************************/ |