equal
deleted
inserted
replaced
17 |
17 |
18 /*****************************************************************************/ |
18 /*****************************************************************************/ |
19 |
19 |
20 #define EC_FUNC_HEADER \ |
20 #define EC_FUNC_HEADER \ |
21 frame->master = master; \ |
21 frame->master = master; \ |
22 frame->state = ec_frame_ready; \ |
|
23 frame->index = 0; \ |
22 frame->index = 0; \ |
24 frame->working_counter = 0; |
23 frame->working_counter = 0; |
25 |
24 |
26 #define EC_FUNC_WRITE_FOOTER \ |
25 #define EC_FUNC_WRITE_FOOTER \ |
27 frame->data_length = length; \ |
26 frame->data_length = length; \ |
256 |
255 |
257 if (unlikely(frame->master->debug_level > 0)) { |
256 if (unlikely(frame->master->debug_level > 0)) { |
258 EC_DBG("ec_frame_send\n"); |
257 EC_DBG("ec_frame_send\n"); |
259 } |
258 } |
260 |
259 |
261 if (unlikely(frame->state != ec_frame_ready)) { |
|
262 EC_WARN("Frame not in \"ready\" state!\n"); |
|
263 } |
|
264 |
|
265 command_size = frame->data_length + EC_COMMAND_HEADER_SIZE |
260 command_size = frame->data_length + EC_COMMAND_HEADER_SIZE |
266 + EC_COMMAND_FOOTER_SIZE; |
261 + EC_COMMAND_FOOTER_SIZE; |
267 frame_size = command_size + EC_FRAME_HEADER_SIZE; |
262 frame_size = command_size + EC_FRAME_HEADER_SIZE; |
268 |
263 |
269 if (unlikely(frame_size > EC_MAX_FRAME_SIZE)) { |
264 if (unlikely(frame_size > EC_MAX_FRAME_SIZE)) { |
281 frame->master->command_index = (frame->master->command_index + 1) % 0x0100; |
276 frame->master->command_index = (frame->master->command_index + 1) % 0x0100; |
282 |
277 |
283 if (unlikely(frame->master->debug_level > 0)) { |
278 if (unlikely(frame->master->debug_level > 0)) { |
284 EC_DBG("Sending command index 0x%X\n", frame->index); |
279 EC_DBG("Sending command index 0x%X\n", frame->index); |
285 } |
280 } |
286 |
|
287 frame->state = ec_frame_sent; |
|
288 |
281 |
289 // Zeiger auf Socket-Buffer holen |
282 // Zeiger auf Socket-Buffer holen |
290 data = ec_device_prepare(&frame->master->device); |
283 data = ec_device_prepare(&frame->master->device); |
291 |
284 |
292 // EtherCAT frame header |
285 // EtherCAT frame header |
334 unsigned int received_length, frame_length, data_length; |
327 unsigned int received_length, frame_length, data_length; |
335 uint8_t *data; |
328 uint8_t *data; |
336 uint8_t command_type, command_index; |
329 uint8_t command_type, command_index; |
337 ec_device_t *device; |
330 ec_device_t *device; |
338 |
331 |
339 if (unlikely(frame->state != ec_frame_sent)) { |
|
340 EC_ERR("Frame was not sent!\n"); |
|
341 return -1; |
|
342 } |
|
343 |
|
344 device = &frame->master->device; |
332 device = &frame->master->device; |
345 |
333 |
346 if (!(received_length = ec_device_received(device))) return -1; |
334 if (!(received_length = ec_device_received(device))) return -1; |
347 |
335 |
348 device->state = EC_DEVICE_STATE_READY; |
336 device->state = EC_DEVICE_STATE_READY; |
385 EC_WARN("WARNING - Send/Receive anomaly!\n"); |
373 EC_WARN("WARNING - Send/Receive anomaly!\n"); |
386 ec_device_debug(device); |
374 ec_device_debug(device); |
387 ec_device_call_isr(device); // Empfangenes "vergessen" |
375 ec_device_call_isr(device); // Empfangenes "vergessen" |
388 return -1; |
376 return -1; |
389 } |
377 } |
390 |
|
391 frame->state = ec_frame_received; |
|
392 |
378 |
393 // Empfangene Daten in Kommandodatenspeicher kopieren |
379 // Empfangene Daten in Kommandodatenspeicher kopieren |
394 memcpy(frame->data, data, data_length); |
380 memcpy(frame->data, data, data_length); |
395 data += data_length; |
381 data += data_length; |
396 |
382 |