|
1 /****************************************************************************** |
|
2 * |
|
3 * e t h e r n e t . c |
|
4 * |
|
5 * Ethernet-over-EtherCAT (EoE) |
|
6 * |
|
7 * $Id$ |
|
8 * |
|
9 *****************************************************************************/ |
|
10 |
|
11 #include "../include/ecrt.h" |
|
12 #include "globals.h" |
|
13 #include "master.h" |
|
14 #include "slave.h" |
|
15 #include "mailbox.h" |
|
16 #include "ethernet.h" |
|
17 |
|
18 /*****************************************************************************/ |
|
19 |
|
20 void ec_eoe_init(ec_eoe_t *eoe, ec_slave_t *slave) |
|
21 { |
|
22 eoe->slave = slave; |
|
23 eoe->rx_state = EC_EOE_IDLE; |
|
24 } |
|
25 |
|
26 /*****************************************************************************/ |
|
27 |
|
28 void ec_eoe_clear(ec_eoe_t *eoe) |
|
29 { |
|
30 } |
|
31 |
|
32 /*****************************************************************************/ |
|
33 |
|
34 void ec_eoe_run(ec_eoe_t *eoe) |
|
35 { |
|
36 uint8_t *data; |
|
37 ec_master_t *master; |
|
38 size_t rec_size; |
|
39 |
|
40 master = eoe->slave->master; |
|
41 |
|
42 if (eoe->rx_state == EC_EOE_IDLE) { |
|
43 ec_slave_mbox_prepare_check(eoe->slave); |
|
44 ec_master_queue_command(master, &eoe->slave->mbox_command); |
|
45 eoe->rx_state = EC_EOE_CHECKING; |
|
46 return; |
|
47 } |
|
48 |
|
49 if (eoe->rx_state == EC_EOE_CHECKING) { |
|
50 if (eoe->slave->mbox_command.state != EC_CMD_RECEIVED) { |
|
51 master->stats.eoe_errors++; |
|
52 eoe->rx_state = EC_EOE_IDLE; |
|
53 return; |
|
54 } |
|
55 if (!ec_slave_mbox_check(eoe->slave)) { |
|
56 eoe->rx_state = EC_EOE_IDLE; |
|
57 return; |
|
58 } |
|
59 ec_slave_mbox_prepare_fetch(eoe->slave); |
|
60 ec_master_queue_command(master, &eoe->slave->mbox_command); |
|
61 eoe->rx_state = EC_EOE_FETCHING; |
|
62 return; |
|
63 } |
|
64 |
|
65 if (eoe->rx_state == EC_EOE_FETCHING) { |
|
66 EC_DBG("EOE fetching\n"); |
|
67 if (eoe->slave->mbox_command.state != EC_CMD_RECEIVED) { |
|
68 master->stats.eoe_errors++; |
|
69 eoe->rx_state = EC_EOE_IDLE; |
|
70 return; |
|
71 } |
|
72 if (!(data = ec_slave_mbox_fetch(eoe->slave, 0x02, &rec_size))) { |
|
73 master->stats.eoe_errors++; |
|
74 eoe->rx_state = EC_EOE_IDLE; |
|
75 return; |
|
76 } |
|
77 EC_DBG("EOE received: %i\n", rec_size); |
|
78 eoe->rx_state = EC_EOE_IDLE; |
|
79 return; |
|
80 } |
|
81 } |
|
82 |
|
83 /*****************************************************************************/ |
|
84 |
|
85 void ec_eoe_print(const ec_eoe_t *eoe) |
|
86 { |
|
87 EC_INFO(" EoE slave %i\n", eoe->slave->ring_position); |
|
88 EC_INFO(" RX State %i\n", eoe->rx_state); |
|
89 } |
|
90 |
|
91 /*****************************************************************************/ |
|
92 |
|
93 /* Emacs-Konfiguration |
|
94 ;;; Local Variables: *** |
|
95 ;;; c-basic-offset:4 *** |
|
96 ;;; End: *** |
|
97 */ |