author | Florian Pose <fp@igh-essen.com> |
Thu, 24 Jul 2008 08:15:44 +0000 | |
changeset 1141 | 7ffbca63fc72 |
parent 986 | a486591ba86b |
child 1217 | e8a9785e63c3 |
child 1685 | 399ef727bf62 |
permissions | -rw-r--r-- |
145
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1 |
/****************************************************************************** |
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
2 |
* |
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
3 |
* $Id$ |
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
4 |
* |
197
b9a6e2c22745
GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents:
195
diff
changeset
|
5 |
* Copyright (C) 2006 Florian Pose, Ingenieurgemeinschaft IgH |
b9a6e2c22745
GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents:
195
diff
changeset
|
6 |
* |
b9a6e2c22745
GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents:
195
diff
changeset
|
7 |
* This file is part of the IgH EtherCAT Master. |
b9a6e2c22745
GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents:
195
diff
changeset
|
8 |
* |
b9a6e2c22745
GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents:
195
diff
changeset
|
9 |
* The IgH EtherCAT Master is free software; you can redistribute it |
b9a6e2c22745
GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents:
195
diff
changeset
|
10 |
* and/or modify it under the terms of the GNU General Public License |
246
0bf7c769de06
Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents:
199
diff
changeset
|
11 |
* as published by the Free Software Foundation; either version 2 of the |
0bf7c769de06
Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents:
199
diff
changeset
|
12 |
* License, or (at your option) any later version. |
197
b9a6e2c22745
GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents:
195
diff
changeset
|
13 |
* |
b9a6e2c22745
GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents:
195
diff
changeset
|
14 |
* The IgH EtherCAT Master is distributed in the hope that it will be |
b9a6e2c22745
GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents:
195
diff
changeset
|
15 |
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
b9a6e2c22745
GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents:
195
diff
changeset
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b9a6e2c22745
GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents:
195
diff
changeset
|
17 |
* GNU General Public License for more details. |
b9a6e2c22745
GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents:
195
diff
changeset
|
18 |
* |
b9a6e2c22745
GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents:
195
diff
changeset
|
19 |
* You should have received a copy of the GNU General Public License |
b9a6e2c22745
GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents:
195
diff
changeset
|
20 |
* along with the IgH EtherCAT Master; if not, write to the Free Software |
b9a6e2c22745
GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents:
195
diff
changeset
|
21 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
b9a6e2c22745
GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents:
195
diff
changeset
|
22 |
* |
246
0bf7c769de06
Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents:
199
diff
changeset
|
23 |
* The right to use EtherCAT Technology is granted and comes free of |
0bf7c769de06
Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents:
199
diff
changeset
|
24 |
* charge under condition of compatibility of product made by |
0bf7c769de06
Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents:
199
diff
changeset
|
25 |
* Licensee. People intending to distribute/sell products based on the |
0bf7c769de06
Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents:
199
diff
changeset
|
26 |
* code, have to sign an agreement to guarantee that products using |
0bf7c769de06
Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents:
199
diff
changeset
|
27 |
* software based on IgH EtherCAT master stay compatible with the actual |
0bf7c769de06
Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents:
199
diff
changeset
|
28 |
* EtherCAT specification (which are released themselves as an open |
0bf7c769de06
Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents:
199
diff
changeset
|
29 |
* standard) as the (only) precondition to have the right to use EtherCAT |
0bf7c769de06
Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents:
199
diff
changeset
|
30 |
* Technology, IP and trade marks. |
0bf7c769de06
Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents:
199
diff
changeset
|
31 |
* |
145
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
32 |
*****************************************************************************/ |
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
33 |
|
199
04ecf40fc2e9
Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents:
197
diff
changeset
|
34 |
/** |
04ecf40fc2e9
Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents:
197
diff
changeset
|
35 |
\file |
04ecf40fc2e9
Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents:
197
diff
changeset
|
36 |
Mailbox functionality. |
04ecf40fc2e9
Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents:
197
diff
changeset
|
37 |
*/ |
04ecf40fc2e9
Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents:
197
diff
changeset
|
38 |
|
04ecf40fc2e9
Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents:
197
diff
changeset
|
39 |
/*****************************************************************************/ |
04ecf40fc2e9
Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents:
197
diff
changeset
|
40 |
|
145
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
41 |
#include <linux/slab.h> |
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
42 |
#include <linux/delay.h> |
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
43 |
|
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
44 |
#include "mailbox.h" |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
279
diff
changeset
|
45 |
#include "datagram.h" |
145
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
46 |
#include "master.h" |
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
47 |
|
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
48 |
/*****************************************************************************/ |
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
49 |
|
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
50 |
/** |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
279
diff
changeset
|
51 |
Prepares a mailbox-send datagram. |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
279
diff
changeset
|
52 |
\return pointer to mailbox datagram data |
195
674071846ee3
Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents:
154
diff
changeset
|
53 |
*/ |
674071846ee3
Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents:
154
diff
changeset
|
54 |
|
279
12f48c1cb143
Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents:
276
diff
changeset
|
55 |
uint8_t *ec_slave_mbox_prepare_send(const ec_slave_t *slave, /**< slave */ |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
279
diff
changeset
|
56 |
ec_datagram_t *datagram, /**< datagram */ |
195
674071846ee3
Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents:
154
diff
changeset
|
57 |
uint8_t type, /**< mailbox protocol */ |
674071846ee3
Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents:
154
diff
changeset
|
58 |
size_t size /**< size of the data */ |
145
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
59 |
) |
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
60 |
{ |
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
61 |
size_t total_size; |
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
62 |
|
834
0791aac03180
Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
63 |
if (unlikely(!slave->sii.mailbox_protocols)) { |
986
a486591ba86b
Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
64 |
EC_ERR("Slave %u does not support mailbox communication!\n", |
145
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
65 |
slave->ring_position); |
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
66 |
return NULL; |
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
67 |
} |
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
68 |
|
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
69 |
total_size = size + 6; |
834
0791aac03180
Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
70 |
if (unlikely(total_size > slave->sii.rx_mailbox_size)) { |
145
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
71 |
EC_ERR("Data size does not fit in mailbox!\n"); |
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
72 |
return NULL; |
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
73 |
} |
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
74 |
|
815
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
786
diff
changeset
|
75 |
if (ec_datagram_fpwr(datagram, slave->station_address, |
834
0791aac03180
Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
76 |
slave->sii.rx_mailbox_offset, |
0791aac03180
Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
77 |
slave->sii.rx_mailbox_size)) |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
279
diff
changeset
|
78 |
return NULL; |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
279
diff
changeset
|
79 |
|
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
279
diff
changeset
|
80 |
EC_WRITE_U16(datagram->data, size); // mailbox service data length |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
279
diff
changeset
|
81 |
EC_WRITE_U16(datagram->data + 2, slave->station_address); // station addr. |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
279
diff
changeset
|
82 |
EC_WRITE_U8 (datagram->data + 4, 0x00); // channel & priority |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
279
diff
changeset
|
83 |
EC_WRITE_U8 (datagram->data + 5, type); // underlying protocol type |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
279
diff
changeset
|
84 |
|
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
279
diff
changeset
|
85 |
return datagram->data + 6; |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
279
diff
changeset
|
86 |
} |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
279
diff
changeset
|
87 |
|
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
279
diff
changeset
|
88 |
/*****************************************************************************/ |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
279
diff
changeset
|
89 |
|
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
279
diff
changeset
|
90 |
/** |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
279
diff
changeset
|
91 |
Prepares a datagram for checking the mailbox state. |
786 | 92 |
\todo Determine sync manager used for receive mailbox |
195
674071846ee3
Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents:
154
diff
changeset
|
93 |
\return 0 in case of success, else < 0 |
674071846ee3
Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents:
154
diff
changeset
|
94 |
*/ |
674071846ee3
Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents:
154
diff
changeset
|
95 |
|
279
12f48c1cb143
Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents:
276
diff
changeset
|
96 |
int ec_slave_mbox_prepare_check(const ec_slave_t *slave, /**< slave */ |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
279
diff
changeset
|
97 |
ec_datagram_t *datagram /**< datagram */ |
279
12f48c1cb143
Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents:
276
diff
changeset
|
98 |
) |
12f48c1cb143
Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents:
276
diff
changeset
|
99 |
{ |
815
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
786
diff
changeset
|
100 |
if (ec_datagram_fprd(datagram, slave->station_address, 0x808, 8)) |
145
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
101 |
return -1; |
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
102 |
|
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
103 |
return 0; |
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
104 |
} |
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
105 |
|
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
106 |
/*****************************************************************************/ |
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
107 |
|
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
108 |
/** |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
279
diff
changeset
|
109 |
Processes a mailbox state checking datagram. |
195
674071846ee3
Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents:
154
diff
changeset
|
110 |
\return 0 in case of success, else < 0 |
674071846ee3
Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents:
154
diff
changeset
|
111 |
*/ |
674071846ee3
Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents:
154
diff
changeset
|
112 |
|
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
279
diff
changeset
|
113 |
int ec_slave_mbox_check(const ec_datagram_t *datagram /**< datagram */) |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
279
diff
changeset
|
114 |
{ |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
279
diff
changeset
|
115 |
return EC_READ_U8(datagram->data + 5) & 8 ? 1 : 0; |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
279
diff
changeset
|
116 |
} |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
279
diff
changeset
|
117 |
|
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
279
diff
changeset
|
118 |
/*****************************************************************************/ |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
279
diff
changeset
|
119 |
|
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
279
diff
changeset
|
120 |
/** |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
279
diff
changeset
|
121 |
Prepares a datagram to fetch mailbox data. |
195
674071846ee3
Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents:
154
diff
changeset
|
122 |
\return 0 in case of success, else < 0 |
674071846ee3
Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents:
154
diff
changeset
|
123 |
*/ |
674071846ee3
Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents:
154
diff
changeset
|
124 |
|
279
12f48c1cb143
Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents:
276
diff
changeset
|
125 |
int ec_slave_mbox_prepare_fetch(const ec_slave_t *slave, /**< slave */ |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
279
diff
changeset
|
126 |
ec_datagram_t *datagram /**< datagram */ |
279
12f48c1cb143
Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents:
276
diff
changeset
|
127 |
) |
12f48c1cb143
Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents:
276
diff
changeset
|
128 |
{ |
815
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
786
diff
changeset
|
129 |
if (ec_datagram_fprd(datagram, slave->station_address, |
834
0791aac03180
Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
130 |
slave->sii.tx_mailbox_offset, |
0791aac03180
Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
131 |
slave->sii.tx_mailbox_size)) return -1; |
145
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
132 |
return 0; |
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
133 |
} |
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
134 |
|
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
135 |
/*****************************************************************************/ |
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
136 |
|
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
137 |
/** |
390
685c267d80d8
Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
138 |
Mailbox error codes. |
685c267d80d8
Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
139 |
*/ |
685c267d80d8
Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
140 |
|
685c267d80d8
Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
141 |
const ec_code_msg_t mbox_error_messages[] = { |
685c267d80d8
Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
142 |
{0x00000001, "MBXERR_SYNTAX"}, |
685c267d80d8
Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
143 |
{0x00000002, "MBXERR_UNSUPPORTEDPROTOCOL"}, |
685c267d80d8
Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
144 |
{0x00000003, "MBXERR_INVAILDCHANNEL"}, |
685c267d80d8
Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
145 |
{0x00000004, "MBXERR_SERVICENOTSUPPORTED"}, |
685c267d80d8
Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
146 |
{0x00000005, "MBXERR_INVALIDHEADER"}, |
685c267d80d8
Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
147 |
{0x00000006, "MBXERR_SIZETOOSHORT"}, |
685c267d80d8
Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
148 |
{0x00000007, "MBXERR_NOMOREMEMORY"}, |
685c267d80d8
Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
149 |
{0x00000008, "MBXERR_INVALIDSIZE"}, |
685c267d80d8
Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
150 |
{} |
685c267d80d8
Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
151 |
}; |
685c267d80d8
Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
152 |
|
685c267d80d8
Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
153 |
/*****************************************************************************/ |
685c267d80d8
Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
154 |
|
685c267d80d8
Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
155 |
/** |
195
674071846ee3
Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents:
154
diff
changeset
|
156 |
Processes received mailbox data. |
674071846ee3
Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents:
154
diff
changeset
|
157 |
\return pointer to the received data |
674071846ee3
Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents:
154
diff
changeset
|
158 |
*/ |
674071846ee3
Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents:
154
diff
changeset
|
159 |
|
279
12f48c1cb143
Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents:
276
diff
changeset
|
160 |
uint8_t *ec_slave_mbox_fetch(const ec_slave_t *slave, /**< slave */ |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
279
diff
changeset
|
161 |
ec_datagram_t *datagram, /**< datagram */ |
390
685c267d80d8
Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
162 |
uint8_t *type, /**< expected mailbox protocol */ |
195
674071846ee3
Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents:
154
diff
changeset
|
163 |
size_t *size /**< size of the received data */ |
145
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
164 |
) |
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
165 |
{ |
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
166 |
size_t data_size; |
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
167 |
|
431
47e7f99005c0
Improved output at mailbox error.
Florian Pose <fp@igh-essen.com>
parents:
424
diff
changeset
|
168 |
data_size = EC_READ_U16(datagram->data); |
47e7f99005c0
Improved output at mailbox error.
Florian Pose <fp@igh-essen.com>
parents:
424
diff
changeset
|
169 |
|
834
0791aac03180
Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
170 |
if (data_size > slave->sii.tx_mailbox_size - 6) { |
986
a486591ba86b
Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
171 |
EC_ERR("Corrupt mailbox response received from slave %u!\n", |
504
63d11bdfe3df
Improved error messages in mailbox.c
Florian Pose <fp@igh-essen.com>
parents:
431
diff
changeset
|
172 |
slave->ring_position); |
834
0791aac03180
Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
173 |
ec_print_data(datagram->data, slave->sii.tx_mailbox_size); |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
279
diff
changeset
|
174 |
return NULL; |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
279
diff
changeset
|
175 |
} |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
279
diff
changeset
|
176 |
|
390
685c267d80d8
Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
177 |
*type = EC_READ_U8(datagram->data + 5) & 0x0F; |
685c267d80d8
Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
178 |
*size = data_size; |
685c267d80d8
Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
179 |
|
685c267d80d8
Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
180 |
if (*type == 0x00) { |
685c267d80d8
Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
181 |
const ec_code_msg_t *mbox_msg; |
685c267d80d8
Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
182 |
uint16_t code = EC_READ_U16(datagram->data + 8); |
685c267d80d8
Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
183 |
|
986
a486591ba86b
Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
184 |
EC_ERR("Mailbox error response received from slave %u - ", |
504
63d11bdfe3df
Improved error messages in mailbox.c
Florian Pose <fp@igh-essen.com>
parents:
431
diff
changeset
|
185 |
slave->ring_position); |
424
b792665b2dba
Display debug data on mailbox error.
Florian Pose <fp@igh-essen.com>
parents:
390
diff
changeset
|
186 |
|
390
685c267d80d8
Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
187 |
for (mbox_msg = mbox_error_messages; mbox_msg->code; mbox_msg++) { |
685c267d80d8
Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
188 |
if (mbox_msg->code != code) continue; |
431
47e7f99005c0
Improved output at mailbox error.
Florian Pose <fp@igh-essen.com>
parents:
424
diff
changeset
|
189 |
printk("Code 0x%04X: \"%s\".\n", |
390
685c267d80d8
Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
190 |
mbox_msg->code, mbox_msg->message); |
685c267d80d8
Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
191 |
break; |
685c267d80d8
Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
192 |
} |
685c267d80d8
Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
193 |
|
685c267d80d8
Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
194 |
if (!mbox_msg->code) |
431
47e7f99005c0
Improved output at mailbox error.
Florian Pose <fp@igh-essen.com>
parents:
424
diff
changeset
|
195 |
printk("Unknown error reply code 0x%04X.\n", code); |
47e7f99005c0
Improved output at mailbox error.
Florian Pose <fp@igh-essen.com>
parents:
424
diff
changeset
|
196 |
|
47e7f99005c0
Improved output at mailbox error.
Florian Pose <fp@igh-essen.com>
parents:
424
diff
changeset
|
197 |
if (slave->master->debug_level) |
47e7f99005c0
Improved output at mailbox error.
Florian Pose <fp@igh-essen.com>
parents:
424
diff
changeset
|
198 |
ec_print_data(datagram->data + 6, data_size); |
390
685c267d80d8
Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
199 |
|
145
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
200 |
return NULL; |
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
201 |
} |
11a82e4fd31b
Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
202 |
|
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
279
diff
changeset
|
203 |
return datagram->data + 6; |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
279
diff
changeset
|
204 |
} |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
279
diff
changeset
|
205 |
|
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
279
diff
changeset
|
206 |
/*****************************************************************************/ |