|
1 /****************************************************************************** |
|
2 * |
|
3 * Oeffentliche EtherCAT-Schnittstellen fuer Echtzeitprozesse. |
|
4 * |
|
5 * $Id$ |
|
6 * |
|
7 *****************************************************************************/ |
|
8 |
|
9 #ifndef _ETHERCAT_RT_H_ |
|
10 #define _ETHERCAT_RT_H_ |
|
11 |
|
12 #include <asm/byteorder.h> |
|
13 |
|
14 /*****************************************************************************/ |
|
15 |
|
16 struct ec_master; |
|
17 typedef struct ec_master ec_master_t; |
|
18 |
|
19 struct ec_domain; |
|
20 typedef struct ec_domain ec_domain_t; |
|
21 |
|
22 struct ec_slave; |
|
23 typedef struct ec_slave ec_slave_t; |
|
24 |
|
25 typedef struct |
|
26 { |
|
27 void **data_ptr; |
|
28 const char *slave_address; |
|
29 const char *vendor_name; |
|
30 const char *product_name; |
|
31 const char *field_name; |
|
32 unsigned int field_index; |
|
33 unsigned int field_count; |
|
34 } |
|
35 ec_field_init_t; |
|
36 |
|
37 /*****************************************************************************/ |
|
38 // Master request functions |
|
39 |
|
40 ec_master_t *ecrt_request_master(unsigned int master_index); |
|
41 void ecrt_release_master(ec_master_t *master); |
|
42 |
|
43 /*****************************************************************************/ |
|
44 // Master methods |
|
45 |
|
46 ec_domain_t *ecrt_master_create_domain(ec_master_t *master); |
|
47 int ecrt_master_activate(ec_master_t *master); |
|
48 void ecrt_master_deactivate(ec_master_t *master); |
|
49 void ecrt_master_sync_io(ec_master_t *master); |
|
50 void ecrt_master_async_send(ec_master_t *master); |
|
51 void ecrt_master_async_receive(ec_master_t *master); |
|
52 void ecrt_master_debug(ec_master_t *master, int level); |
|
53 void ecrt_master_print(const ec_master_t *master); |
|
54 int ecrt_master_sdo_write(ec_master_t *master, |
|
55 const char *slave_addr, |
|
56 uint16_t sdo_index, |
|
57 uint8_t sdo_subindex, |
|
58 uint32_t value, |
|
59 size_t size); |
|
60 int ecrt_master_sdo_read(ec_master_t *master, |
|
61 const char *slave_addr, |
|
62 uint16_t sdo_index, |
|
63 uint8_t sdo_subindex, |
|
64 uint32_t *value); |
|
65 |
|
66 /*****************************************************************************/ |
|
67 // Domain Methods |
|
68 |
|
69 ec_slave_t *ecrt_domain_register_field(ec_domain_t *domain, |
|
70 const char *address, |
|
71 const char *vendor_name, |
|
72 const char *product_name, |
|
73 void **data_ptr, |
|
74 const char *field_name, |
|
75 unsigned int field_index, |
|
76 unsigned int field_count); |
|
77 int ecrt_domain_register_field_list(ec_domain_t *domain, |
|
78 ec_field_init_t *fields); |
|
79 void ecrt_domain_queue(ec_domain_t *domain); |
|
80 void ecrt_domain_process(ec_domain_t *domain); |
|
81 |
|
82 /*****************************************************************************/ |
|
83 // Slave Methods |
|
84 |
|
85 int ecrt_slave_sdo_write(ec_slave_t *slave, |
|
86 uint16_t sdo_index, |
|
87 uint8_t sdo_subindex, |
|
88 uint32_t value, |
|
89 size_t size); |
|
90 int ecrt_slave_sdo_read(ec_slave_t *slave, |
|
91 uint16_t sdo_index, |
|
92 uint8_t sdo_subindex, |
|
93 uint32_t *value); |
|
94 |
|
95 /*****************************************************************************/ |
|
96 // Bitwise read/write macros |
|
97 |
|
98 #define EC_READ_BIT(PD, CH) (*((uint8_t *) (PD)) >> (CH)) & 0x01) |
|
99 |
|
100 #define EC_WRITE_BIT(PD, CH, VAL) \ |
|
101 do { \ |
|
102 if (VAL) *((uint8_t *) (PD)) |= (1 << (CH)); \ |
|
103 else *((uint8_t *) (PD)) &= ~(1 << (CH)); \ |
|
104 } while (0) |
|
105 |
|
106 /*****************************************************************************/ |
|
107 // Read macros |
|
108 |
|
109 #define EC_READ_U8(PD) ((uint8_t) *((uint8_t *) (PD))) |
|
110 #define EC_READ_S8(PD) ((int8_t) *((uint8_t *) (PD))) |
|
111 |
|
112 #define EC_READ_U16(PD) ((uint16_t) le16_to_cpup((void *) (PD))) |
|
113 #define EC_READ_S16(PD) ((int16_t) le16_to_cpup((void *) (PD))) |
|
114 |
|
115 #define EC_READ_U32(PD) ((uint32_t) le32_to_cpup((void *) (PD))) |
|
116 #define EC_READ_S32(PD) ((int32_t) le32_to_cpup((void *) (PD))) |
|
117 |
|
118 /*****************************************************************************/ |
|
119 // Write macros |
|
120 |
|
121 #define EC_WRITE_U8(PD, VAL) \ |
|
122 do { \ |
|
123 *((uint8_t *)(PD)) = ((uint8_t) (VAL)); \ |
|
124 } while (0) |
|
125 |
|
126 #define EC_WRITE_S8(PD, VAL) EC_WRITE_U8(PD, VAL) |
|
127 |
|
128 #define EC_WRITE_U16(PD, VAL) \ |
|
129 do { \ |
|
130 *((uint16_t *) (PD)) = (uint16_t) (VAL); \ |
|
131 cpu_to_le16s(PD); \ |
|
132 } while (0) |
|
133 |
|
134 #define EC_WRITE_S16(PD, VAL) EC_WRITE_U16(PD, VAL) |
|
135 |
|
136 #define EC_WRITE_U32(PD, VAL) \ |
|
137 do { \ |
|
138 *((uint32_t *) (PD)) = (uint32_t) (VAL); \ |
|
139 cpu_to_le16s(PD); \ |
|
140 } while (0) |
|
141 |
|
142 #define EC_WRITE_S32(PD, VAL) EC_WRITE_U32(PD, VAL) |
|
143 |
|
144 /*****************************************************************************/ |
|
145 |
|
146 #endif |