author | Florian Pose <fp@igh-essen.com> |
Mon, 23 Jul 2012 12:23:42 +0200 | |
branch | stable-1.5 |
changeset 2397 | 8b9be05873c1 |
parent 2242 | d23f69156cfd |
child 2380 | cf9db49bcce8 |
permissions | -rw-r--r-- |
1244
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1 |
/****************************************************************************** |
2241
0ba77ef52922
Insert port information into slave info.
Stefan Weiser <ch1010858@ch10pc584>
parents:
2124
diff
changeset
|
2 |
* |
1326
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
3 |
* $Id$ |
2241
0ba77ef52922
Insert port information into slave info.
Stefan Weiser <ch1010858@ch10pc584>
parents:
2124
diff
changeset
|
4 |
* |
1326
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
5 |
* Copyright (C) 2006-2009 Florian Pose, Ingenieurgemeinschaft IgH |
2241
0ba77ef52922
Insert port information into slave info.
Stefan Weiser <ch1010858@ch10pc584>
parents:
2124
diff
changeset
|
6 |
* |
1326
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
7 |
* This file is part of the IgH EtherCAT master userspace library. |
2241
0ba77ef52922
Insert port information into slave info.
Stefan Weiser <ch1010858@ch10pc584>
parents:
2124
diff
changeset
|
8 |
* |
1326
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
9 |
* The IgH EtherCAT master userspace library is free software; you can |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
10 |
* redistribute it and/or modify it under the terms of the GNU Lesser General |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
11 |
* Public License as published by the Free Software Foundation; version 2.1 |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
12 |
* of the License. |
1287 | 13 |
* |
1326
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
14 |
* The IgH EtherCAT master userspace library is distributed in the hope that |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
15 |
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
16 |
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
17 |
* GNU Lesser General Public License for more details. |
1287 | 18 |
* |
1326
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
19 |
* You should have received a copy of the GNU Lesser General Public License |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
20 |
* along with the IgH EtherCAT master userspace library. If not, see |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
21 |
* <http://www.gnu.org/licenses/>. |
2241
0ba77ef52922
Insert port information into slave info.
Stefan Weiser <ch1010858@ch10pc584>
parents:
2124
diff
changeset
|
22 |
* |
1363
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1341
diff
changeset
|
23 |
* --- |
2241
0ba77ef52922
Insert port information into slave info.
Stefan Weiser <ch1010858@ch10pc584>
parents:
2124
diff
changeset
|
24 |
* |
1363
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1341
diff
changeset
|
25 |
* The license mentioned above concerns the source code only. Using the |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1341
diff
changeset
|
26 |
* EtherCAT technology and brand is only permitted in compliance with the |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1341
diff
changeset
|
27 |
* industrial property and similar rights of Beckhoff Automation GmbH. |
1244
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
28 |
* |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
29 |
*****************************************************************************/ |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
30 |
|
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
31 |
#include <stdlib.h> |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
32 |
#include <sys/ioctl.h> |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
33 |
#include <stdio.h> |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
34 |
#include <errno.h> |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
35 |
#include <string.h> |
1258
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
36 |
#include <sys/mman.h> |
1244
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
37 |
|
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
38 |
#include "master.h" |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
39 |
#include "domain.h" |
1246
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
40 |
#include "slave_config.h" |
1244
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
41 |
#include "master/ioctl.h" |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
42 |
|
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
43 |
/*****************************************************************************/ |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
44 |
|
1497
c9308eb34c0e
Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
45 |
int ecrt_master_reserve(ec_master_t *master) |
c9308eb34c0e
Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
46 |
{ |
c9308eb34c0e
Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
47 |
if (ioctl(master->fd, EC_IOCTL_REQUEST, NULL) == -1) { |
c9308eb34c0e
Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
48 |
fprintf(stderr, "Failed to reserve master: %s\n", |
c9308eb34c0e
Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
49 |
strerror(errno)); |
c9308eb34c0e
Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
50 |
return -1; |
c9308eb34c0e
Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
51 |
} |
1975
8e173dddd183
Improved compiling on 2.6.34 (thanks to Malcolm Lewis).
Florian Pose <fp@igh-essen.com>
parents:
1963
diff
changeset
|
52 |
return 0; |
1497
c9308eb34c0e
Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
53 |
} |
c9308eb34c0e
Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
54 |
|
c9308eb34c0e
Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
55 |
/*****************************************************************************/ |
c9308eb34c0e
Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
56 |
|
1960
6c4269dca1c2
Clear configuration on deactivation; also in userspace.
Florian Pose <fp@igh-essen.com>
parents:
1959
diff
changeset
|
57 |
void ec_master_clear_config(ec_master_t *master) |
1959
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
58 |
{ |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
59 |
ec_domain_t *d, *next_d; |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
60 |
ec_slave_config_t *c, *next_c; |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
61 |
|
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
62 |
d = master->first_domain; |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
63 |
while (d) { |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
64 |
next_d = d->next; |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
65 |
ec_domain_clear(d); |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
66 |
d = next_d; |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
67 |
} |
1960
6c4269dca1c2
Clear configuration on deactivation; also in userspace.
Florian Pose <fp@igh-essen.com>
parents:
1959
diff
changeset
|
68 |
master->first_domain = NULL; |
1959
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
69 |
|
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
70 |
c = master->first_config; |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
71 |
while (c) { |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
72 |
next_c = c->next; |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
73 |
ec_slave_config_clear(c); |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
74 |
c = next_c; |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
75 |
} |
1960
6c4269dca1c2
Clear configuration on deactivation; also in userspace.
Florian Pose <fp@igh-essen.com>
parents:
1959
diff
changeset
|
76 |
master->first_config = NULL; |
6c4269dca1c2
Clear configuration on deactivation; also in userspace.
Florian Pose <fp@igh-essen.com>
parents:
1959
diff
changeset
|
77 |
} |
6c4269dca1c2
Clear configuration on deactivation; also in userspace.
Florian Pose <fp@igh-essen.com>
parents:
1959
diff
changeset
|
78 |
|
6c4269dca1c2
Clear configuration on deactivation; also in userspace.
Florian Pose <fp@igh-essen.com>
parents:
1959
diff
changeset
|
79 |
/*****************************************************************************/ |
6c4269dca1c2
Clear configuration on deactivation; also in userspace.
Florian Pose <fp@igh-essen.com>
parents:
1959
diff
changeset
|
80 |
|
6c4269dca1c2
Clear configuration on deactivation; also in userspace.
Florian Pose <fp@igh-essen.com>
parents:
1959
diff
changeset
|
81 |
void ec_master_clear(ec_master_t *master) |
6c4269dca1c2
Clear configuration on deactivation; also in userspace.
Florian Pose <fp@igh-essen.com>
parents:
1959
diff
changeset
|
82 |
{ |
6c4269dca1c2
Clear configuration on deactivation; also in userspace.
Florian Pose <fp@igh-essen.com>
parents:
1959
diff
changeset
|
83 |
if (master->process_data) { |
6c4269dca1c2
Clear configuration on deactivation; also in userspace.
Florian Pose <fp@igh-essen.com>
parents:
1959
diff
changeset
|
84 |
munmap(master->process_data, master->process_data_size); |
6c4269dca1c2
Clear configuration on deactivation; also in userspace.
Florian Pose <fp@igh-essen.com>
parents:
1959
diff
changeset
|
85 |
} |
6c4269dca1c2
Clear configuration on deactivation; also in userspace.
Florian Pose <fp@igh-essen.com>
parents:
1959
diff
changeset
|
86 |
|
6c4269dca1c2
Clear configuration on deactivation; also in userspace.
Florian Pose <fp@igh-essen.com>
parents:
1959
diff
changeset
|
87 |
ec_master_clear_config(master); |
1959
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
88 |
|
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
89 |
if (master->fd != -1) { |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
90 |
close(master->fd); |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
91 |
} |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
92 |
} |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
93 |
|
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
94 |
/*****************************************************************************/ |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
95 |
|
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
96 |
void ec_master_add_domain(ec_master_t *master, ec_domain_t *domain) |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
97 |
{ |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
98 |
if (master->first_domain) { |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
99 |
ec_domain_t *d = master->first_domain; |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
100 |
while (d->next) { |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
101 |
d = d->next; |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
102 |
} |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
103 |
d->next = domain; |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
104 |
} else { |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
105 |
master->first_domain = domain; |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
106 |
} |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
107 |
} |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
108 |
|
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
109 |
/*****************************************************************************/ |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
110 |
|
1244
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
111 |
ec_domain_t *ecrt_master_create_domain(ec_master_t *master) |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
112 |
{ |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
113 |
ec_domain_t *domain; |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
114 |
int index; |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
115 |
|
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
116 |
domain = malloc(sizeof(ec_domain_t)); |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
117 |
if (!domain) { |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
118 |
fprintf(stderr, "Failed to allocate memory.\n"); |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
119 |
return 0; |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
120 |
} |
2241
0ba77ef52922
Insert port information into slave info.
Stefan Weiser <ch1010858@ch10pc584>
parents:
2124
diff
changeset
|
121 |
|
1244
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
122 |
index = ioctl(master->fd, EC_IOCTL_CREATE_DOMAIN, NULL); |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
123 |
if (index == -1) { |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
124 |
fprintf(stderr, "Failed to create domain: %s\n", strerror(errno)); |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
125 |
free(domain); |
2241
0ba77ef52922
Insert port information into slave info.
Stefan Weiser <ch1010858@ch10pc584>
parents:
2124
diff
changeset
|
126 |
return 0; |
1244
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
127 |
} |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
128 |
|
1959
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
129 |
domain->next = NULL; |
1244
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
130 |
domain->index = (unsigned int) index; |
1255
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
1247
diff
changeset
|
131 |
domain->master = master; |
1258
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
132 |
domain->process_data = NULL; |
1959
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
133 |
|
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
134 |
ec_master_add_domain(master, domain); |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
135 |
|
1244
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
136 |
return domain; |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
137 |
} |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
138 |
|
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
139 |
/*****************************************************************************/ |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
140 |
|
1959
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
141 |
void ec_master_add_slave_config(ec_master_t *master, ec_slave_config_t *sc) |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
142 |
{ |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
143 |
if (master->first_config) { |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
144 |
ec_slave_config_t *c = master->first_config; |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
145 |
while (c->next) { |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
146 |
c = c->next; |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
147 |
} |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
148 |
c->next = sc; |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
149 |
} else { |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
150 |
master->first_config = sc; |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
151 |
} |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
152 |
} |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
153 |
|
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
154 |
/*****************************************************************************/ |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
155 |
|
1244
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
156 |
ec_slave_config_t *ecrt_master_slave_config(ec_master_t *master, |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
157 |
uint16_t alias, uint16_t position, uint32_t vendor_id, |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
158 |
uint32_t product_code) |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
159 |
{ |
1246
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
160 |
ec_ioctl_config_t data; |
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
161 |
ec_slave_config_t *sc; |
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
162 |
int index; |
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
163 |
|
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
164 |
sc = malloc(sizeof(ec_slave_config_t)); |
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
165 |
if (!sc) { |
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
166 |
fprintf(stderr, "Failed to allocate memory.\n"); |
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
167 |
return 0; |
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
168 |
} |
2241
0ba77ef52922
Insert port information into slave info.
Stefan Weiser <ch1010858@ch10pc584>
parents:
2124
diff
changeset
|
169 |
|
1246
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
170 |
data.alias = alias; |
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
171 |
data.position = position; |
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
172 |
data.vendor_id = vendor_id; |
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
173 |
data.product_code = product_code; |
2241
0ba77ef52922
Insert port information into slave info.
Stefan Weiser <ch1010858@ch10pc584>
parents:
2124
diff
changeset
|
174 |
|
1246
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
175 |
if (ioctl(master->fd, EC_IOCTL_CREATE_SLAVE_CONFIG, &data) == -1) { |
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
176 |
fprintf(stderr, "Failed to create slave config: %s\n", |
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
177 |
strerror(errno)); |
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
178 |
free(sc); |
2241
0ba77ef52922
Insert port information into slave info.
Stefan Weiser <ch1010858@ch10pc584>
parents:
2124
diff
changeset
|
179 |
return 0; |
1246
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
180 |
} |
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
181 |
|
1959
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
182 |
sc->next = NULL; |
1255
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
1247
diff
changeset
|
183 |
sc->master = master; |
1246
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
184 |
sc->index = data.config_index; |
1255
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
1247
diff
changeset
|
185 |
sc->alias = alias; |
38b7e05b20c1
Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
1247
diff
changeset
|
186 |
sc->position = position; |
1959
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
187 |
sc->first_sdo_request = NULL; |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
188 |
sc->first_voe_handler = NULL; |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
189 |
|
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
190 |
ec_master_add_slave_config(master, sc); |
656f114153c2
Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
191 |
|
1246
4042bda8c980
Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents:
1244
diff
changeset
|
192 |
return sc; |
1244
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
193 |
} |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
194 |
|
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
195 |
/*****************************************************************************/ |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
196 |
|
1497
c9308eb34c0e
Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
197 |
int ecrt_master(ec_master_t* master, ec_master_info_t *master_info) |
c9308eb34c0e
Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
198 |
{ |
1508 | 199 |
ec_ioctl_master_t data; |
200 |
||
201 |
if (ioctl(master->fd, EC_IOCTL_MASTER, &data) < 0) { |
|
1497
c9308eb34c0e
Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
202 |
fprintf(stderr, "Failed to get master info: %s\n", strerror(errno)); |
1508 | 203 |
return -1; |
204 |
} |
|
205 |
||
206 |
master_info->slave_count = data.slave_count; |
|
207 |
master_info->link_up = data.devices[0].link_state; |
|
1579
326d47aa986c
applied komax patch to version r1822
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
1510
diff
changeset
|
208 |
master_info->scan_busy = data.scan_busy; |
1508 | 209 |
master_info->app_time = data.app_time; |
210 |
return 0; |
|
1497
c9308eb34c0e
Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
211 |
} |
c9308eb34c0e
Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
212 |
|
c9308eb34c0e
Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
213 |
/*****************************************************************************/ |
c9308eb34c0e
Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
214 |
|
1510
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
215 |
int ecrt_master_get_slave(ec_master_t *master, uint16_t slave_position, |
1341
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
216 |
ec_slave_info_t *slave_info) |
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
217 |
{ |
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
218 |
ec_ioctl_slave_t data; |
2242
d23f69156cfd
Fixed copying port information.
Stefan Weiser <ch1010858@ch10pc584>
parents:
2241
diff
changeset
|
219 |
int index, i; |
1341
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
220 |
|
1510
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
221 |
data.position = slave_position; |
1341
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
222 |
|
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
223 |
if (ioctl(master->fd, EC_IOCTL_SLAVE, &data) == -1) { |
1497
c9308eb34c0e
Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
224 |
fprintf(stderr, "Failed to get slave info: %s\n", strerror(errno)); |
1341
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
225 |
return -1; |
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
226 |
} |
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
227 |
|
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
228 |
slave_info->position = data.position; |
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
229 |
slave_info->vendor_id = data.vendor_id; |
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
230 |
slave_info->product_code = data.product_code; |
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
231 |
slave_info->revision_number = data.revision_number; |
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
232 |
slave_info->serial_number = data.serial_number; |
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
233 |
slave_info->alias = data.alias; |
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
234 |
slave_info->current_on_ebus = data.current_on_ebus; |
2242
d23f69156cfd
Fixed copying port information.
Stefan Weiser <ch1010858@ch10pc584>
parents:
2241
diff
changeset
|
235 |
for ( i = 0; i < EC_MAX_PORTS; i++ ) { |
d23f69156cfd
Fixed copying port information.
Stefan Weiser <ch1010858@ch10pc584>
parents:
2241
diff
changeset
|
236 |
slave_info->ports[i].desc = data.ports[i].desc; |
d23f69156cfd
Fixed copying port information.
Stefan Weiser <ch1010858@ch10pc584>
parents:
2241
diff
changeset
|
237 |
slave_info->ports[i].link.link_up = data.ports[i].link.link_up; |
d23f69156cfd
Fixed copying port information.
Stefan Weiser <ch1010858@ch10pc584>
parents:
2241
diff
changeset
|
238 |
slave_info->ports[i].link.loop_closed = data.ports[i].link.loop_closed; |
d23f69156cfd
Fixed copying port information.
Stefan Weiser <ch1010858@ch10pc584>
parents:
2241
diff
changeset
|
239 |
slave_info->ports[i].link.signal_detected = data.ports[i].link.signal_detected; |
d23f69156cfd
Fixed copying port information.
Stefan Weiser <ch1010858@ch10pc584>
parents:
2241
diff
changeset
|
240 |
slave_info->ports[i].receive_time = data.ports[i].receive_time; |
d23f69156cfd
Fixed copying port information.
Stefan Weiser <ch1010858@ch10pc584>
parents:
2241
diff
changeset
|
241 |
slave_info->ports[i].next_slave = data.ports[i].next_slave; |
d23f69156cfd
Fixed copying port information.
Stefan Weiser <ch1010858@ch10pc584>
parents:
2241
diff
changeset
|
242 |
slave_info->ports[i].delay_to_next_dc = data.ports[i].delay_to_next_dc; |
d23f69156cfd
Fixed copying port information.
Stefan Weiser <ch1010858@ch10pc584>
parents:
2241
diff
changeset
|
243 |
} |
1341
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
244 |
slave_info->al_state = data.al_state; |
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
245 |
slave_info->error_flag = data.error_flag; |
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
246 |
slave_info->sync_count = data.sync_count; |
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
247 |
slave_info->sdo_count = data.sdo_count; |
1593
fb8337e664fb
Fixed string length constant bug.
Florian Pose <fp@igh-essen.com>
parents:
1585
diff
changeset
|
248 |
strncpy(slave_info->name, data.name, EC_MAX_STRING_LENGTH); |
1341
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
249 |
return 0; |
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
250 |
} |
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
251 |
|
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
252 |
/*****************************************************************************/ |
32ba7ffb6c7f
Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
253 |
|
1510
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
254 |
int ecrt_master_get_sync_manager(ec_master_t *master, uint16_t slave_position, |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
255 |
uint8_t sync_index, ec_sync_info_t *sync) |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
256 |
{ |
1804 | 257 |
ec_ioctl_slave_sync_t data; |
1510
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
258 |
|
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
259 |
if (sync_index >= EC_MAX_SYNC_MANAGERS) |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
260 |
return -ENOENT; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
261 |
|
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
262 |
memset(&data, 0x00, sizeof(ec_ioctl_slave_sync_t)); |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
263 |
data.slave_position = slave_position; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
264 |
data.sync_index = sync_index; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
265 |
|
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
266 |
if (ioctl(master->fd, EC_IOCTL_SLAVE_SYNC, &data) == -1) { |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
267 |
fprintf(stderr, "Failed to get sync manager information: %s\n", |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
268 |
strerror(errno)); |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
269 |
return -1; // FIXME |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
270 |
} |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
271 |
|
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
272 |
sync->index = sync_index; |
1804 | 273 |
sync->dir = EC_READ_BIT(&data.control_register, 2) ? |
1510
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
274 |
EC_DIR_OUTPUT : EC_DIR_INPUT; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
275 |
sync->n_pdos = data.pdo_count; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
276 |
sync->pdos = NULL; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
277 |
sync->watchdog_mode = EC_READ_BIT(&data.control_register, 6) ? |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
278 |
EC_WD_ENABLE : EC_WD_DISABLE; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
279 |
|
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
280 |
return 0; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
281 |
} |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
282 |
|
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
283 |
/*****************************************************************************/ |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
284 |
|
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
285 |
int ecrt_master_get_pdo(ec_master_t *master, uint16_t slave_position, |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
286 |
uint8_t sync_index, uint16_t pos, ec_pdo_info_t *pdo) |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
287 |
{ |
1804 | 288 |
ec_ioctl_slave_sync_pdo_t data; |
1510
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
289 |
|
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
290 |
if (sync_index >= EC_MAX_SYNC_MANAGERS) |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
291 |
return -ENOENT; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
292 |
|
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
293 |
memset(&data, 0x00, sizeof(ec_ioctl_slave_sync_pdo_t)); |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
294 |
data.slave_position = slave_position; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
295 |
data.sync_index = sync_index; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
296 |
data.pdo_pos = pos; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
297 |
|
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
298 |
if (ioctl(master->fd, EC_IOCTL_SLAVE_SYNC_PDO, &data) == -1) { |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
299 |
fprintf(stderr, "Failed to get pdo information: %s\n", |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
300 |
strerror(errno)); |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
301 |
return -1; // FIXME |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
302 |
} |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
303 |
|
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
304 |
pdo->index = data.index; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
305 |
pdo->n_entries = data.entry_count; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
306 |
pdo->entries = NULL; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
307 |
|
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
308 |
return 0; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
309 |
} |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
310 |
|
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
311 |
/*****************************************************************************/ |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
312 |
|
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
313 |
int ecrt_master_get_pdo_entry(ec_master_t *master, uint16_t slave_position, |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
314 |
uint8_t sync_index, uint16_t pdo_pos, uint16_t entry_pos, |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
315 |
ec_pdo_entry_info_t *entry) |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
316 |
{ |
1804 | 317 |
ec_ioctl_slave_sync_pdo_entry_t data; |
1510
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
318 |
|
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
319 |
if (sync_index >= EC_MAX_SYNC_MANAGERS) |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
320 |
return -ENOENT; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
321 |
|
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
322 |
memset(&data, 0x00, sizeof(ec_ioctl_slave_sync_pdo_entry_t)); |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
323 |
data.slave_position = slave_position; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
324 |
data.sync_index = sync_index; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
325 |
data.pdo_pos = pdo_pos; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
326 |
data.entry_pos = entry_pos; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
327 |
|
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
328 |
if (ioctl(master->fd, EC_IOCTL_SLAVE_SYNC_PDO_ENTRY, &data) == -1) { |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
329 |
fprintf(stderr, "Failed to get pdo entry information: %s\n", |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
330 |
strerror(errno)); |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
331 |
return -1; // FIXME |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
332 |
} |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
333 |
|
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
334 |
entry->index = data.index; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
335 |
entry->subindex = data.subindex; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
336 |
entry->bit_length = data.bit_length; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
337 |
|
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
338 |
return 0; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
339 |
} |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
340 |
|
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
341 |
/*****************************************************************************/ |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
342 |
|
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
343 |
int ecrt_master_sdo_download(ec_master_t *master, uint16_t slave_position, |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
344 |
uint16_t index, uint8_t subindex, uint8_t *data, |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
345 |
size_t data_size, uint32_t *abort_code) |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
346 |
{ |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
347 |
ec_ioctl_slave_sdo_download_t download; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
348 |
|
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
349 |
download.slave_position = slave_position; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
350 |
download.sdo_index = index; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
351 |
download.sdo_entry_subindex = subindex; |
2124
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
2062
diff
changeset
|
352 |
download.complete_access = 0; |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
2062
diff
changeset
|
353 |
download.data_size = data_size; |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
2062
diff
changeset
|
354 |
download.data = data; |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
2062
diff
changeset
|
355 |
|
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
2062
diff
changeset
|
356 |
if (ioctl(master->fd, EC_IOCTL_SLAVE_SDO_DOWNLOAD, &download) == -1) { |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
2062
diff
changeset
|
357 |
if (errno == EIO && abort_code) { |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
2062
diff
changeset
|
358 |
*abort_code = download.abort_code; |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
2062
diff
changeset
|
359 |
} |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
2062
diff
changeset
|
360 |
fprintf(stderr, "Failed to execute SDO download: %s\n", |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
2062
diff
changeset
|
361 |
strerror(errno)); |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
2062
diff
changeset
|
362 |
return -1; |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
2062
diff
changeset
|
363 |
} |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
2062
diff
changeset
|
364 |
|
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
2062
diff
changeset
|
365 |
return 0; |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
2062
diff
changeset
|
366 |
} |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
2062
diff
changeset
|
367 |
|
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
2062
diff
changeset
|
368 |
/*****************************************************************************/ |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
2062
diff
changeset
|
369 |
|
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
2062
diff
changeset
|
370 |
int ecrt_master_sdo_download_complete(ec_master_t *master, |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
2062
diff
changeset
|
371 |
uint16_t slave_position, uint16_t index, uint8_t *data, |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
2062
diff
changeset
|
372 |
size_t data_size, uint32_t *abort_code) |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
2062
diff
changeset
|
373 |
{ |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
2062
diff
changeset
|
374 |
ec_ioctl_slave_sdo_download_t download; |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
2062
diff
changeset
|
375 |
|
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
2062
diff
changeset
|
376 |
download.slave_position = slave_position; |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
2062
diff
changeset
|
377 |
download.sdo_index = index; |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
2062
diff
changeset
|
378 |
download.sdo_entry_subindex = 0; |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
2062
diff
changeset
|
379 |
download.complete_access = 1; |
1510
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
380 |
download.data_size = data_size; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
381 |
download.data = data; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
382 |
|
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
383 |
if (ioctl(master->fd, EC_IOCTL_SLAVE_SDO_DOWNLOAD, &download) == -1) { |
1911
460baca4df83
Fixed errno usage in user library.
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
384 |
if (errno == EIO && abort_code) { |
460baca4df83
Fixed errno usage in user library.
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
385 |
*abort_code = download.abort_code; |
1510
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
386 |
} |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
387 |
fprintf(stderr, "Failed to execute SDO download: %s\n", |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
388 |
strerror(errno)); |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
389 |
return -1; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
390 |
} |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
391 |
|
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
392 |
return 0; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
393 |
} |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
394 |
|
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
395 |
/*****************************************************************************/ |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
396 |
|
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
397 |
int ecrt_master_sdo_upload(ec_master_t *master, uint16_t slave_position, |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
398 |
uint16_t index, uint8_t subindex, uint8_t *target, |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
399 |
size_t target_size, size_t *result_size, uint32_t *abort_code) |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
400 |
{ |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
401 |
ec_ioctl_slave_sdo_upload_t upload; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
402 |
|
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
403 |
upload.slave_position = slave_position; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
404 |
upload.sdo_index = index; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
405 |
upload.sdo_entry_subindex = subindex; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
406 |
upload.target_size = target_size; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
407 |
upload.target = target; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
408 |
|
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
409 |
if (ioctl(master->fd, EC_IOCTL_SLAVE_SDO_UPLOAD, &upload) == -1) { |
1911
460baca4df83
Fixed errno usage in user library.
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
410 |
if (errno == EIO && abort_code) { |
460baca4df83
Fixed errno usage in user library.
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
411 |
*abort_code = upload.abort_code; |
1510
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
412 |
} |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
413 |
fprintf(stderr, "Failed to execute SDO upload: %s\n", |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
414 |
strerror(errno)); |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
415 |
return -1; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
416 |
} |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
417 |
|
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
418 |
*result_size = upload.data_size; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
419 |
return 0; |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
420 |
} |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
421 |
|
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
422 |
/*****************************************************************************/ |
88b608a1a7f3
Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents:
1508
diff
changeset
|
423 |
|
1913
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
424 |
int ecrt_master_write_idn(ec_master_t *master, uint16_t slave_position, |
1952
7d9fb723fc4b
Added drive_no parameter to SoE layer.
Florian Pose <fp@igh-essen.com>
parents:
1947
diff
changeset
|
425 |
uint8_t drive_no, uint16_t idn, uint8_t *data, size_t data_size, |
7d9fb723fc4b
Added drive_no parameter to SoE layer.
Florian Pose <fp@igh-essen.com>
parents:
1947
diff
changeset
|
426 |
uint16_t *error_code) |
1913
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
427 |
{ |
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
428 |
ec_ioctl_slave_soe_write_t io; |
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
429 |
|
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
430 |
io.slave_position = slave_position; |
1952
7d9fb723fc4b
Added drive_no parameter to SoE layer.
Florian Pose <fp@igh-essen.com>
parents:
1947
diff
changeset
|
431 |
io.drive_no = drive_no; |
1913
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
432 |
io.idn = idn; |
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
433 |
io.data_size = data_size; |
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
434 |
io.data = data; |
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
435 |
|
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
436 |
if (ioctl(master->fd, EC_IOCTL_SLAVE_SOE_WRITE, &io) == -1) { |
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
437 |
if (errno == EIO && error_code) { |
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
438 |
*error_code = io.error_code; |
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
439 |
} |
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
440 |
fprintf(stderr, "Failed to write IDN: %s\n", strerror(errno)); |
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
441 |
return -1; |
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
442 |
} |
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
443 |
|
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
444 |
return 0; |
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
445 |
} |
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
446 |
|
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
447 |
/*****************************************************************************/ |
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
448 |
|
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
449 |
int ecrt_master_read_idn(ec_master_t *master, uint16_t slave_position, |
1952
7d9fb723fc4b
Added drive_no parameter to SoE layer.
Florian Pose <fp@igh-essen.com>
parents:
1947
diff
changeset
|
450 |
uint8_t drive_no, uint16_t idn, uint8_t *target, size_t target_size, |
1947
024a3c6aa3f7
Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents:
1913
diff
changeset
|
451 |
size_t *result_size, uint16_t *error_code) |
1913
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
452 |
{ |
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
453 |
ec_ioctl_slave_soe_read_t io; |
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
454 |
|
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
455 |
io.slave_position = slave_position; |
1952
7d9fb723fc4b
Added drive_no parameter to SoE layer.
Florian Pose <fp@igh-essen.com>
parents:
1947
diff
changeset
|
456 |
io.drive_no = drive_no; |
1913
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
457 |
io.idn = idn; |
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
458 |
io.mem_size = target_size; |
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
459 |
io.data = target; |
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
460 |
|
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
461 |
if (ioctl(master->fd, EC_IOCTL_SLAVE_SOE_READ, &io) == -1) { |
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
462 |
if (errno == EIO && error_code) { |
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
463 |
*error_code = io.error_code; |
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
464 |
} |
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
465 |
fprintf(stderr, "Failed to read IDN: %s\n", strerror(errno)); |
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
466 |
return -1; |
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
467 |
} |
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
468 |
|
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
469 |
*result_size = io.data_size; |
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
470 |
return 0; |
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
471 |
} |
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
472 |
|
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
473 |
/*****************************************************************************/ |
cbef34ba142b
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents:
1911
diff
changeset
|
474 |
|
1244
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
475 |
int ecrt_master_activate(ec_master_t *master) |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
476 |
{ |
1258
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
477 |
if (ioctl(master->fd, EC_IOCTL_ACTIVATE, |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
478 |
&master->process_data_size) == -1) { |
1247
5f1f1a3e6636
Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents:
1246
diff
changeset
|
479 |
fprintf(stderr, "Failed to activate master: %s\n", |
5f1f1a3e6636
Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents:
1246
diff
changeset
|
480 |
strerror(errno)); |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1287
diff
changeset
|
481 |
return -1; // FIXME |
1247
5f1f1a3e6636
Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents:
1246
diff
changeset
|
482 |
} |
5f1f1a3e6636
Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents:
1246
diff
changeset
|
483 |
|
1258
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
484 |
if (master->process_data_size) { |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
485 |
master->process_data = mmap(0, master->process_data_size, |
1259
5f9d1abbee71
Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents:
1258
diff
changeset
|
486 |
PROT_READ | PROT_WRITE, MAP_SHARED, master->fd, 0); |
1258
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
487 |
if (master->process_data == MAP_FAILED) { |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
488 |
fprintf(stderr, "Failed to map process data: %s", strerror(errno)); |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
489 |
master->process_data = NULL; |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
490 |
master->process_data_size = 0; |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1287
diff
changeset
|
491 |
return -1; // FIXME |
1258
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
492 |
} |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
493 |
|
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
494 |
// Access the mapped region to cause the initial page fault |
2062
9cc8f64726bb
Removed "Pd: 0" output that does the initial pagefault. Write to the
Florian Pose <fp@igh-essen.com>
parents:
2009
diff
changeset
|
495 |
master->process_data[0] = 0x00; |
1258
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
496 |
} |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
497 |
|
1244
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
498 |
return 0; |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
499 |
} |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
500 |
|
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
501 |
/*****************************************************************************/ |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
502 |
|
1531
6c5478400e28
Implemented ecrt_master_deactivate() in userspace.
Florian Pose <fp@igh-essen.com>
parents:
1510
diff
changeset
|
503 |
void ecrt_master_deactivate(ec_master_t *master) |
6c5478400e28
Implemented ecrt_master_deactivate() in userspace.
Florian Pose <fp@igh-essen.com>
parents:
1510
diff
changeset
|
504 |
{ |
6c5478400e28
Implemented ecrt_master_deactivate() in userspace.
Florian Pose <fp@igh-essen.com>
parents:
1510
diff
changeset
|
505 |
if (ioctl(master->fd, EC_IOCTL_DEACTIVATE, NULL) == -1) { |
6c5478400e28
Implemented ecrt_master_deactivate() in userspace.
Florian Pose <fp@igh-essen.com>
parents:
1510
diff
changeset
|
506 |
fprintf(stderr, "Failed to deactivate master: %s\n", strerror(errno)); |
6c5478400e28
Implemented ecrt_master_deactivate() in userspace.
Florian Pose <fp@igh-essen.com>
parents:
1510
diff
changeset
|
507 |
return; |
6c5478400e28
Implemented ecrt_master_deactivate() in userspace.
Florian Pose <fp@igh-essen.com>
parents:
1510
diff
changeset
|
508 |
} |
1960
6c4269dca1c2
Clear configuration on deactivation; also in userspace.
Florian Pose <fp@igh-essen.com>
parents:
1959
diff
changeset
|
509 |
|
6c4269dca1c2
Clear configuration on deactivation; also in userspace.
Florian Pose <fp@igh-essen.com>
parents:
1959
diff
changeset
|
510 |
ec_master_clear_config(master); |
6c4269dca1c2
Clear configuration on deactivation; also in userspace.
Florian Pose <fp@igh-essen.com>
parents:
1959
diff
changeset
|
511 |
} |
1585
1f640e321ee4
ecrt_master_set_max_cycle_size: limit SDO traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
1580
diff
changeset
|
512 |
|
1f640e321ee4
ecrt_master_set_max_cycle_size: limit SDO traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
1580
diff
changeset
|
513 |
/*****************************************************************************/ |
1f640e321ee4
ecrt_master_set_max_cycle_size: limit SDO traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
1580
diff
changeset
|
514 |
|
1600
e36c92cf58a9
use given send interval to limit SDO/FOE traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
1585
diff
changeset
|
515 |
int ecrt_master_set_send_interval(ec_master_t *master,size_t send_interval_us) |
e36c92cf58a9
use given send interval to limit SDO/FOE traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
1585
diff
changeset
|
516 |
{ |
1804 | 517 |
if (ioctl(master->fd, EC_IOCTL_SET_SEND_INTERVAL, |
518 |
&send_interval_us) == -1) { |
|
519 |
fprintf(stderr, "Failed to set send interval: %s\n", |
|
1585
1f640e321ee4
ecrt_master_set_max_cycle_size: limit SDO traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
1580
diff
changeset
|
520 |
strerror(errno)); |
1f640e321ee4
ecrt_master_set_max_cycle_size: limit SDO traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
1580
diff
changeset
|
521 |
return -1; // FIXME |
1f640e321ee4
ecrt_master_set_max_cycle_size: limit SDO traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
1580
diff
changeset
|
522 |
} |
1f640e321ee4
ecrt_master_set_max_cycle_size: limit SDO traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
1580
diff
changeset
|
523 |
return 0; |
1f640e321ee4
ecrt_master_set_max_cycle_size: limit SDO traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
1580
diff
changeset
|
524 |
} |
1f640e321ee4
ecrt_master_set_max_cycle_size: limit SDO traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
1580
diff
changeset
|
525 |
|
1531
6c5478400e28
Implemented ecrt_master_deactivate() in userspace.
Florian Pose <fp@igh-essen.com>
parents:
1510
diff
changeset
|
526 |
/*****************************************************************************/ |
6c5478400e28
Implemented ecrt_master_deactivate() in userspace.
Florian Pose <fp@igh-essen.com>
parents:
1510
diff
changeset
|
527 |
|
1244
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
528 |
void ecrt_master_send(ec_master_t *master) |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
529 |
{ |
1247
5f1f1a3e6636
Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents:
1246
diff
changeset
|
530 |
if (ioctl(master->fd, EC_IOCTL_SEND, NULL) == -1) { |
5f1f1a3e6636
Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents:
1246
diff
changeset
|
531 |
fprintf(stderr, "Failed to send: %s\n", strerror(errno)); |
5f1f1a3e6636
Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents:
1246
diff
changeset
|
532 |
} |
1244
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
533 |
} |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
534 |
|
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
535 |
/*****************************************************************************/ |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
536 |
|
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
537 |
void ecrt_master_receive(ec_master_t *master) |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
538 |
{ |
1247
5f1f1a3e6636
Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents:
1246
diff
changeset
|
539 |
if (ioctl(master->fd, EC_IOCTL_RECEIVE, NULL) == -1) { |
5f1f1a3e6636
Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents:
1246
diff
changeset
|
540 |
fprintf(stderr, "Failed to receive: %s\n", strerror(errno)); |
5f1f1a3e6636
Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents:
1246
diff
changeset
|
541 |
} |
1244
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
542 |
} |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
543 |
|
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
544 |
/*****************************************************************************/ |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
545 |
|
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
546 |
void ecrt_master_state(const ec_master_t *master, ec_master_state_t *state) |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
547 |
{ |
1259
5f9d1abbee71
Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents:
1258
diff
changeset
|
548 |
if (ioctl(master->fd, EC_IOCTL_MASTER_STATE, state) == -1) { |
5f9d1abbee71
Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents:
1258
diff
changeset
|
549 |
fprintf(stderr, "Failed to get master state: %s\n", strerror(errno)); |
5f9d1abbee71
Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents:
1258
diff
changeset
|
550 |
} |
1244
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
551 |
} |
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
552 |
|
0b70040d3daa
No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
553 |
/*****************************************************************************/ |
1413
44c2b7c0ae1a
Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
554 |
|
1434
4c6fe0ae37f1
Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents:
1417
diff
changeset
|
555 |
void ecrt_master_application_time(ec_master_t *master, uint64_t app_time) |
4c6fe0ae37f1
Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents:
1417
diff
changeset
|
556 |
{ |
4c6fe0ae37f1
Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents:
1417
diff
changeset
|
557 |
ec_ioctl_app_time_t data; |
1413
44c2b7c0ae1a
Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
558 |
|
1417
7c2d5d69134c
Replaced timeval by 64-bit EtherCAT time.
Florian Pose <fp@igh-essen.com>
parents:
1413
diff
changeset
|
559 |
data.app_time = app_time; |
1413
44c2b7c0ae1a
Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
560 |
|
1434
4c6fe0ae37f1
Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents:
1417
diff
changeset
|
561 |
if (ioctl(master->fd, EC_IOCTL_APP_TIME, &data) == -1) { |
4c6fe0ae37f1
Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents:
1417
diff
changeset
|
562 |
fprintf(stderr, "Failed to set application time: %s\n", |
4c6fe0ae37f1
Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents:
1417
diff
changeset
|
563 |
strerror(errno)); |
4c6fe0ae37f1
Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents:
1417
diff
changeset
|
564 |
} |
4c6fe0ae37f1
Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents:
1417
diff
changeset
|
565 |
} |
4c6fe0ae37f1
Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents:
1417
diff
changeset
|
566 |
|
4c6fe0ae37f1
Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents:
1417
diff
changeset
|
567 |
/*****************************************************************************/ |
4c6fe0ae37f1
Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents:
1417
diff
changeset
|
568 |
|
4c6fe0ae37f1
Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents:
1417
diff
changeset
|
569 |
void ecrt_master_sync_reference_clock(ec_master_t *master) |
4c6fe0ae37f1
Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents:
1417
diff
changeset
|
570 |
{ |
4c6fe0ae37f1
Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents:
1417
diff
changeset
|
571 |
if (ioctl(master->fd, EC_IOCTL_SYNC_REF, NULL) == -1) { |
1413
44c2b7c0ae1a
Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
572 |
fprintf(stderr, "Failed to sync reference clock: %s\n", |
44c2b7c0ae1a
Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
573 |
strerror(errno)); |
44c2b7c0ae1a
Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
574 |
} |
44c2b7c0ae1a
Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
575 |
} |
44c2b7c0ae1a
Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
576 |
|
44c2b7c0ae1a
Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
577 |
/*****************************************************************************/ |
44c2b7c0ae1a
Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
578 |
|
44c2b7c0ae1a
Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
579 |
void ecrt_master_sync_slave_clocks(ec_master_t *master) |
44c2b7c0ae1a
Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
580 |
{ |
44c2b7c0ae1a
Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
581 |
if (ioctl(master->fd, EC_IOCTL_SYNC_SLAVES, NULL) == -1) { |
44c2b7c0ae1a
Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
582 |
fprintf(stderr, "Failed to sync slave clocks: %s\n", strerror(errno)); |
44c2b7c0ae1a
Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
583 |
} |
44c2b7c0ae1a
Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
584 |
} |
44c2b7c0ae1a
Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
585 |
|
44c2b7c0ae1a
Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
586 |
/*****************************************************************************/ |
1535
0c484ee12d89
DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents:
1531
diff
changeset
|
587 |
|
0c484ee12d89
DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents:
1531
diff
changeset
|
588 |
void ecrt_master_sync_monitor_queue(ec_master_t *master) |
0c484ee12d89
DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents:
1531
diff
changeset
|
589 |
{ |
0c484ee12d89
DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents:
1531
diff
changeset
|
590 |
if (ioctl(master->fd, EC_IOCTL_SYNC_MON_QUEUE, NULL) == -1) { |
0c484ee12d89
DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents:
1531
diff
changeset
|
591 |
fprintf(stderr, "Failed to queue sync monitor datagram: %s\n", |
0c484ee12d89
DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents:
1531
diff
changeset
|
592 |
strerror(errno)); |
0c484ee12d89
DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents:
1531
diff
changeset
|
593 |
} |
0c484ee12d89
DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents:
1531
diff
changeset
|
594 |
} |
0c484ee12d89
DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents:
1531
diff
changeset
|
595 |
|
0c484ee12d89
DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents:
1531
diff
changeset
|
596 |
/*****************************************************************************/ |
0c484ee12d89
DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents:
1531
diff
changeset
|
597 |
|
0c484ee12d89
DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents:
1531
diff
changeset
|
598 |
uint32_t ecrt_master_sync_monitor_process(ec_master_t *master) |
0c484ee12d89
DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents:
1531
diff
changeset
|
599 |
{ |
0c484ee12d89
DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents:
1531
diff
changeset
|
600 |
uint32_t time_diff; |
0c484ee12d89
DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents:
1531
diff
changeset
|
601 |
|
0c484ee12d89
DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents:
1531
diff
changeset
|
602 |
if (ioctl(master->fd, EC_IOCTL_SYNC_MON_PROCESS, &time_diff) == -1) { |
0c484ee12d89
DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents:
1531
diff
changeset
|
603 |
time_diff = 0xffffffff; |
0c484ee12d89
DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents:
1531
diff
changeset
|
604 |
fprintf(stderr, "Failed to process sync monitor datagram: %s\n", |
0c484ee12d89
DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents:
1531
diff
changeset
|
605 |
strerror(errno)); |
0c484ee12d89
DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents:
1531
diff
changeset
|
606 |
} |
0c484ee12d89
DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents:
1531
diff
changeset
|
607 |
|
0c484ee12d89
DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents:
1531
diff
changeset
|
608 |
return time_diff; |
0c484ee12d89
DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents:
1531
diff
changeset
|
609 |
} |
0c484ee12d89
DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents:
1531
diff
changeset
|
610 |
|
0c484ee12d89
DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents:
1531
diff
changeset
|
611 |
/*****************************************************************************/ |
2009
b5391b329b5d
Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents:
1975
diff
changeset
|
612 |
|
b5391b329b5d
Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents:
1975
diff
changeset
|
613 |
void ecrt_master_reset(ec_master_t *master) |
b5391b329b5d
Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents:
1975
diff
changeset
|
614 |
{ |
b5391b329b5d
Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents:
1975
diff
changeset
|
615 |
if (ioctl(master->fd, EC_IOCTL_RESET, NULL) == -1) { |
b5391b329b5d
Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents:
1975
diff
changeset
|
616 |
fprintf(stderr, "Failed to reset master: %s\n", strerror(errno)); |
b5391b329b5d
Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents:
1975
diff
changeset
|
617 |
} |
b5391b329b5d
Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents:
1975
diff
changeset
|
618 |
} |
b5391b329b5d
Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents:
1975
diff
changeset
|
619 |
|
b5391b329b5d
Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents:
1975
diff
changeset
|
620 |
/*****************************************************************************/ |