44 #include "../../include/ecrt.h" // EtherCAT realtime interface |
40 #include "../../include/ecrt.h" // EtherCAT realtime interface |
45 #include "../../include/ecdb.h" // EtherCAT slave database |
41 #include "../../include/ecdb.h" // EtherCAT slave database |
46 |
42 |
47 #define FREQUENCY 100 |
43 #define FREQUENCY 100 |
48 |
44 |
|
45 #define KBUS |
|
46 |
49 /*****************************************************************************/ |
47 /*****************************************************************************/ |
50 |
48 |
51 struct timer_list timer; |
49 struct timer_list timer; |
52 |
50 |
53 // EtherCAT |
51 // EtherCAT |
54 ec_master_t *master = NULL; |
52 ec_master_t *master = NULL; |
55 ec_domain_t *domain1 = NULL; |
53 ec_domain_t *domain1 = NULL; |
56 spinlock_t master_lock = SPIN_LOCK_UNLOCKED; |
54 spinlock_t master_lock = SPIN_LOCK_UNLOCKED; |
57 |
55 |
58 // data fields |
56 // data fields |
59 void *r_ana_out; |
57 #ifdef KBUS |
60 |
58 void *r_inputs; |
61 // channels |
59 void *r_outputs; |
62 uint32_t k_pos; |
60 #endif |
63 uint8_t k_stat; |
61 |
64 |
62 void *r_ana_in; |
|
63 |
|
64 #if 1 |
65 ec_pdo_reg_t domain1_pdos[] = { |
65 ec_pdo_reg_t domain1_pdos[] = { |
66 {"2", Beckhoff_EL4132_Output1, &r_ana_out}, |
66 {"2", Beckhoff_EL3102_Input1, &r_ana_in}, |
67 {"3", Beckhoff_EL5001_Value, NULL}, |
|
68 {} |
67 {} |
69 }; |
68 }; |
|
69 #endif |
70 |
70 |
71 /*****************************************************************************/ |
71 /*****************************************************************************/ |
72 |
72 |
73 void run(unsigned long data) |
73 void run(unsigned long data) |
74 { |
74 { |
75 static unsigned int counter = 0; |
75 static unsigned int counter = 0; |
|
76 static unsigned int einaus = 0; |
76 |
77 |
77 spin_lock(&master_lock); |
78 spin_lock(&master_lock); |
78 |
79 |
79 // receive |
80 // receive |
80 ecrt_master_receive(master); |
81 ecrt_master_receive(master); |
81 ecrt_domain_process(domain1); |
82 ecrt_domain_process(domain1); |
82 |
83 |
83 // process data |
84 // process data |
84 //k_pos = EC_READ_U32(r_ssi); |
85 //k_pos = EC_READ_U32(r_ssi); |
|
86 #ifdef KBUS |
|
87 EC_WRITE_U8(r_outputs + 2, einaus ? 0xFF : 0x00); |
|
88 #endif |
85 |
89 |
86 // send |
90 // send |
87 ecrt_master_run(master); |
91 ecrt_master_run(master); |
88 ecrt_master_send(master); |
92 ecrt_master_send(master); |
89 |
93 |
122 |
123 |
123 /*****************************************************************************/ |
124 /*****************************************************************************/ |
124 |
125 |
125 int __init init_mini_module(void) |
126 int __init init_mini_module(void) |
126 { |
127 { |
|
128 #if 1 |
127 ec_slave_t *slave; |
129 ec_slave_t *slave; |
|
130 #endif |
128 |
131 |
129 printk(KERN_INFO "=== Starting Minimal EtherCAT environment... ===\n"); |
132 printk(KERN_INFO "=== Starting Minimal EtherCAT environment... ===\n"); |
130 |
133 |
131 if ((master = ecrt_request_master(0)) == NULL) { |
134 if ((master = ecrt_request_master(0)) == NULL) { |
132 printk(KERN_ERR "Requesting master 0 failed!\n"); |
135 printk(KERN_ERR "Requesting master 0 failed!\n"); |
141 printk(KERN_ERR "Domain creation failed!\n"); |
144 printk(KERN_ERR "Domain creation failed!\n"); |
142 goto out_release_master; |
145 goto out_release_master; |
143 } |
146 } |
144 |
147 |
145 printk(KERN_INFO "Registering PDOs...\n"); |
148 printk(KERN_INFO "Registering PDOs...\n"); |
|
149 #if 1 |
146 if (ecrt_domain_register_pdo_list(domain1, domain1_pdos)) { |
150 if (ecrt_domain_register_pdo_list(domain1, domain1_pdos)) { |
147 printk(KERN_ERR "PDO registration failed!\n"); |
151 printk(KERN_ERR "PDO registration failed!\n"); |
148 goto out_release_master; |
152 goto out_release_master; |
149 } |
153 } |
150 |
154 #endif |
151 if (!(slave = ecrt_master_get_slave(master, "3"))) |
155 |
|
156 #ifdef KBUS |
|
157 if (!ecrt_domain_register_pdo_range(domain1, "0", Beckhoff_BK1120, |
|
158 EC_DIR_OUTPUT, 0, 4, &r_outputs)) { |
|
159 printk(KERN_ERR "PDO registration failed!\n"); |
|
160 goto out_release_master; |
|
161 } |
|
162 if (!ecrt_domain_register_pdo_range(domain1, "0", Beckhoff_BK1120, |
|
163 EC_DIR_INPUT, 0, 4, &r_inputs)) { |
|
164 printk(KERN_ERR "PDO registration failed!\n"); |
|
165 goto out_release_master; |
|
166 } |
|
167 #endif |
|
168 |
|
169 #if 1 |
|
170 if (!(slave = ecrt_master_get_slave(master, "2"))) |
152 goto out_release_master; |
171 goto out_release_master; |
153 |
172 |
154 if (ecrt_slave_conf_sdo8(slave, 0x4061, 1, 0)) |
173 if (ecrt_slave_conf_sdo8(slave, 0x4061, 1, 0)) |
155 goto out_release_master; |
174 goto out_release_master; |
|
175 #endif |
156 |
176 |
157 printk(KERN_INFO "Activating master...\n"); |
177 printk(KERN_INFO "Activating master...\n"); |
158 if (ecrt_master_activate(master)) { |
178 if (ecrt_master_activate(master)) { |
159 printk(KERN_ERR "Failed to activate master!\n"); |
179 printk(KERN_ERR "Failed to activate master!\n"); |
160 goto out_release_master; |
180 goto out_release_master; |
181 |
201 |
182 void __exit cleanup_mini_module(void) |
202 void __exit cleanup_mini_module(void) |
183 { |
203 { |
184 printk(KERN_INFO "=== Stopping Minimal EtherCAT environment... ===\n"); |
204 printk(KERN_INFO "=== Stopping Minimal EtherCAT environment... ===\n"); |
185 |
205 |
186 if (master) { |
206 del_timer_sync(&timer); |
187 del_timer_sync(&timer); |
207 printk(KERN_INFO "Releasing master...\n"); |
188 printk(KERN_INFO "Deactivating master...\n"); |
208 ecrt_release_master(master); |
189 ecrt_master_deactivate(master); |
|
190 ecrt_release_master(master); |
|
191 } |
|
192 |
209 |
193 printk(KERN_INFO "=== Minimal EtherCAT environment stopped. ===\n"); |
210 printk(KERN_INFO "=== Minimal EtherCAT environment stopped. ===\n"); |
194 } |
211 } |
195 |
212 |
196 /*****************************************************************************/ |
213 /*****************************************************************************/ |