16 #include "master.h" |
16 #include "master.h" |
17 |
17 |
18 /*****************************************************************************/ |
18 /*****************************************************************************/ |
19 |
19 |
20 /** |
20 /** |
21 Bereitet ein Mailbox-Send-Kommando vor. |
21 Prepares a mailbox-send command. |
22 */ |
22 \return pointer to mailbox command data |
23 |
23 */ |
24 uint8_t *ec_slave_mbox_prepare_send(ec_slave_t *slave, /**< Slave */ |
24 |
25 uint8_t type, /**< Mailbox-Protokoll */ |
25 uint8_t *ec_slave_mbox_prepare_send(ec_slave_t *slave, /**< slave */ |
26 size_t size /**< Datengröße */ |
26 uint8_t type, /**< mailbox protocol */ |
|
27 size_t size /**< size of the data */ |
27 ) |
28 ) |
28 { |
29 { |
29 ec_command_t *command = &slave->mbox_command; |
30 ec_command_t *command = &slave->mbox_command; |
30 size_t total_size; |
31 size_t total_size; |
31 |
32 |
44 if (ec_command_npwr(command, slave->station_address, |
45 if (ec_command_npwr(command, slave->station_address, |
45 slave->sii_rx_mailbox_offset, |
46 slave->sii_rx_mailbox_offset, |
46 slave->sii_rx_mailbox_size)) |
47 slave->sii_rx_mailbox_size)) |
47 return NULL; |
48 return NULL; |
48 |
49 |
49 EC_WRITE_U16(command->data, size); // Mailbox service data length |
50 EC_WRITE_U16(command->data, size); // mailbox service data length |
50 EC_WRITE_U16(command->data + 2, slave->station_address); // Station address |
51 EC_WRITE_U16(command->data + 2, slave->station_address); // station address |
51 EC_WRITE_U8 (command->data + 4, 0x00); // Channel & priority |
52 EC_WRITE_U8 (command->data + 4, 0x00); // hhannel & priority |
52 EC_WRITE_U8 (command->data + 5, type); // Underlying protocol type |
53 EC_WRITE_U8 (command->data + 5, type); // underlying protocol type |
53 |
54 |
54 return command->data + 6; |
55 return command->data + 6; |
55 } |
56 } |
56 |
57 |
57 /*****************************************************************************/ |
58 /*****************************************************************************/ |
58 |
59 |
59 /** |
60 /** |
60 Bereitet ein Kommando zum Abfragen des Mailbox-Zustandes vor. |
61 Prepares a command for checking the mailbox state. |
61 */ |
62 \return 0 in case of success, else < 0 |
62 |
63 */ |
63 int ec_slave_mbox_prepare_check(ec_slave_t *slave /**< Slave */) |
64 |
64 { |
65 int ec_slave_mbox_prepare_check(ec_slave_t *slave /**< slave */) |
65 ec_command_t *command = &slave->mbox_command; |
66 { |
66 |
67 ec_command_t *command = &slave->mbox_command; |
67 // FIXME: Zweiter Sync-Manager nicht immer TX-Mailbox? |
68 |
|
69 // FIXME: second sync manager? |
68 if (ec_command_nprd(command, slave->station_address, 0x808, 8)) |
70 if (ec_command_nprd(command, slave->station_address, 0x808, 8)) |
69 return -1; |
71 return -1; |
70 |
72 |
71 return 0; |
73 return 0; |
72 } |
74 } |
73 |
75 |
74 /*****************************************************************************/ |
76 /*****************************************************************************/ |
75 |
77 |
76 /** |
78 /** |
77 Liest den Mailbox-Zustand aus einem empfangenen Kommando. |
79 Processes a mailbox state checking command. |
78 */ |
80 \return 0 in case of success, else < 0 |
79 |
81 */ |
80 int ec_slave_mbox_check(const ec_slave_t *slave /**< Slave */) |
82 |
|
83 int ec_slave_mbox_check(const ec_slave_t *slave /**< slave */) |
81 { |
84 { |
82 return EC_READ_U8(slave->mbox_command.data + 5) & 8 ? 1 : 0; |
85 return EC_READ_U8(slave->mbox_command.data + 5) & 8 ? 1 : 0; |
83 } |
86 } |
84 |
87 |
85 /*****************************************************************************/ |
88 /*****************************************************************************/ |
86 |
89 |
87 /** |
90 /** |
88 Bereitet ein Kommando zum Laden von Daten von der Mailbox vor. |
91 Prepares a command to fetch mailbox data. |
89 */ |
92 \return 0 in case of success, else < 0 |
90 |
93 */ |
91 int ec_slave_mbox_prepare_fetch(ec_slave_t *slave /**< Slave */) |
94 |
|
95 int ec_slave_mbox_prepare_fetch(ec_slave_t *slave /**< slave */) |
92 { |
96 { |
93 ec_command_t *command = &slave->mbox_command; |
97 ec_command_t *command = &slave->mbox_command; |
94 |
98 |
95 if (ec_command_nprd(command, slave->station_address, |
99 if (ec_command_nprd(command, slave->station_address, |
96 slave->sii_tx_mailbox_offset, |
100 slave->sii_tx_mailbox_offset, |
99 } |
103 } |
100 |
104 |
101 /*****************************************************************************/ |
105 /*****************************************************************************/ |
102 |
106 |
103 /** |
107 /** |
104 Verarbeitet empfangene Mailbox-Daten. |
108 Processes received mailbox data. |
105 */ |
109 \return pointer to the received data |
106 |
110 */ |
107 uint8_t *ec_slave_mbox_fetch(ec_slave_t *slave, /**< Slave */ |
111 |
108 uint8_t type, /**< Protokoll */ |
112 uint8_t *ec_slave_mbox_fetch(ec_slave_t *slave, /**< slave */ |
109 size_t *size /**< Größe der empfangenen Daten */ |
113 uint8_t type, /**< expected mailbox protocol */ |
|
114 size_t *size /**< size of the received data */ |
110 ) |
115 ) |
111 { |
116 { |
112 ec_command_t *command = &slave->mbox_command; |
117 ec_command_t *command = &slave->mbox_command; |
113 size_t data_size; |
118 size_t data_size; |
114 |
119 |
156 } |
161 } |
157 |
162 |
158 /*****************************************************************************/ |
163 /*****************************************************************************/ |
159 |
164 |
160 /** |
165 /** |
161 Wartet auf den Empfang eines Mailbox-Kommandos. |
166 Waits for the reception of a mailbox command. |
162 */ |
167 \return pointer to the received data |
163 |
168 */ |
164 uint8_t *ec_slave_mbox_simple_receive(ec_slave_t *slave, /**< Slave */ |
169 |
165 uint8_t type, /**< Protokoll */ |
170 uint8_t *ec_slave_mbox_simple_receive(ec_slave_t *slave, /**< slave */ |
166 size_t *size /**< Größe der gelesenen |
171 uint8_t type, /**< expected protocol */ |
167 Daten */ |
172 size_t *size /**< received data size */ |
168 ) |
173 ) |
169 { |
174 { |
170 cycles_t start, end, timeout; |
175 cycles_t start, end, timeout; |
171 ec_command_t *command; |
176 ec_command_t *command; |
172 |
177 |