|
1 /**************************************************************** |
|
2 * |
|
3 * e c _ m a s t e r . h |
|
4 * |
|
5 * Struktur für einen EtherCAT-Master. |
|
6 * |
|
7 * $Date$ |
|
8 * $Author$ |
|
9 * |
|
10 ***************************************************************/ |
|
11 |
|
12 #ifndef _EC_MASTER_H_ |
|
13 #define _EC_MASTER_H_ |
|
14 |
|
15 #include "ec_device.h" |
|
16 #include "ec_slave.h" |
|
17 #include "ec_command.h" |
|
18 |
|
19 /***************************************************************/ |
|
20 |
|
21 /** |
|
22 EtherCAT-Master |
|
23 |
|
24 Verwaltet die EtherCAT-Slaves und kommuniziert mit |
|
25 dem zugewiesenen EtherCAT-Gerät. |
|
26 */ |
|
27 |
|
28 typedef struct |
|
29 { |
|
30 EtherCAT_slave_t *slaves; /**< Zeiger auf statischen Speicher |
|
31 mit Slave-Informationen */ |
|
32 unsigned int slave_count; /**< Anzahl der Slaves in slaves */ |
|
33 |
|
34 EtherCAT_command_t *first_command; /**< Zeiger auf das erste |
|
35 Kommando in der Liste */ |
|
36 EtherCAT_command_t *process_data_command; /**< Zeiger Auf das Kommando |
|
37 zum Senden und Empfangen |
|
38 der Prozessdaten */ |
|
39 |
|
40 EtherCAT_device_t *dev; /**< Zeiger auf das zugewiesene EtherCAT-Gerät */ |
|
41 |
|
42 unsigned char command_index; /**< Aktueller Kommando-Index */ |
|
43 |
|
44 unsigned char tx_data[ECAT_FRAME_BUFFER_SIZE]; /**< Statischer Speicher |
|
45 für zu sendende Daten */ |
|
46 unsigned int tx_data_length; /**< Länge der Daten im Sendespeicher */ |
|
47 unsigned char rx_data[ECAT_FRAME_BUFFER_SIZE]; /**< Statische Speicher für |
|
48 eine Kopie des Rx-Buffers |
|
49 im EtherCAT-Gerät */ |
|
50 |
|
51 unsigned char *process_data; /**< Zeiger auf Speicher mit Prozessdaten */ |
|
52 unsigned int process_data_length; /**< Länge der Prozessdaten */ |
|
53 |
|
54 EtherCAT_command_t cmd_ring[ECAT_COMMAND_RING_SIZE]; /** Statischer Kommandoring */ |
|
55 unsigned int cmd_ring_index; /**< Index des nächsten Kommandos im Ring */ |
|
56 } |
|
57 EtherCAT_master_t; |
|
58 |
|
59 /***************************************************************/ |
|
60 |
|
61 // Master creation and deletion |
|
62 int EtherCAT_master_init(EtherCAT_master_t *, EtherCAT_device_t *); |
|
63 void EtherCAT_master_clear(EtherCAT_master_t *); |
|
64 |
|
65 // Slave management |
|
66 int EtherCAT_check_slaves(EtherCAT_master_t *, EtherCAT_slave_t *, unsigned int); |
|
67 void EtherCAT_clear_slaves(EtherCAT_master_t *); |
|
68 int EtherCAT_activate_slave(EtherCAT_master_t *, EtherCAT_slave_t *); |
|
69 int EtherCAT_deactivate_slave(EtherCAT_master_t *, EtherCAT_slave_t *); |
|
70 int EtherCAT_activate_all_slaves(EtherCAT_master_t *); |
|
71 int EtherCAT_deactivate_all_slaves(EtherCAT_master_t *); |
|
72 |
|
73 // Sending and receiving |
|
74 int EtherCAT_async_send_receive(EtherCAT_master_t *); |
|
75 int EtherCAT_send(EtherCAT_master_t *); |
|
76 int EtherCAT_receive(EtherCAT_master_t *); |
|
77 int EtherCAT_write_process_data(EtherCAT_master_t *); |
|
78 int EtherCAT_read_process_data(EtherCAT_master_t *); |
|
79 |
|
80 /***************************************************************/ |
|
81 |
|
82 // Slave information interface |
|
83 int EtherCAT_read_slave_information(EtherCAT_master_t *, |
|
84 unsigned short int, |
|
85 unsigned short int, |
|
86 unsigned int *); |
|
87 |
|
88 // EtherCAT commands |
|
89 EtherCAT_command_t *EtherCAT_read(EtherCAT_master_t *, |
|
90 unsigned short, |
|
91 unsigned short, |
|
92 unsigned int); |
|
93 EtherCAT_command_t *EtherCAT_write(EtherCAT_master_t *, |
|
94 unsigned short, |
|
95 unsigned short, |
|
96 unsigned int, |
|
97 const unsigned char *); |
|
98 EtherCAT_command_t *EtherCAT_position_read(EtherCAT_master_t *, |
|
99 short, |
|
100 unsigned short, |
|
101 unsigned int); |
|
102 EtherCAT_command_t *EtherCAT_position_write(EtherCAT_master_t *, |
|
103 short, |
|
104 unsigned short, |
|
105 unsigned int, |
|
106 const unsigned char *); |
|
107 EtherCAT_command_t *EtherCAT_broadcast_read(EtherCAT_master_t *, |
|
108 unsigned short, |
|
109 unsigned int); |
|
110 EtherCAT_command_t *EtherCAT_broadcast_write(EtherCAT_master_t *, |
|
111 unsigned short, |
|
112 unsigned int, |
|
113 const unsigned char *); |
|
114 EtherCAT_command_t *EtherCAT_logical_read_write(EtherCAT_master_t *, |
|
115 unsigned int, |
|
116 unsigned int, |
|
117 unsigned char *); |
|
118 |
|
119 void EtherCAT_remove_command(EtherCAT_master_t *, EtherCAT_command_t *); |
|
120 |
|
121 // Slave states |
|
122 int EtherCAT_state_change(EtherCAT_master_t *, EtherCAT_slave_t *, unsigned char); |
|
123 |
|
124 /***************************************************************/ |
|
125 |
|
126 // Private functions |
|
127 EtherCAT_command_t *alloc_cmd(EtherCAT_master_t *); |
|
128 void add_command(EtherCAT_master_t *, EtherCAT_command_t *); |
|
129 void set_byte(unsigned char *, unsigned int, unsigned char); |
|
130 void set_word(unsigned char *, unsigned int, unsigned int); |
|
131 |
|
132 /***************************************************************/ |
|
133 |
|
134 #endif |