10 |
10 |
11 #include <linux/module.h> |
11 #include <linux/module.h> |
12 #include <linux/delay.h> |
12 #include <linux/delay.h> |
13 #include <linux/timer.h> |
13 #include <linux/timer.h> |
14 |
14 |
15 #include "../include/EtherCAT_rt.h" // Echtzeitschnittstelle |
15 #include "../include/ecrt.h" // Echtzeitschnittstelle |
16 #include "../include/EtherCAT_si.h" // Slave-Interface-Makros |
16 |
|
17 //#define ASYNC |
17 |
18 |
18 /*****************************************************************************/ |
19 /*****************************************************************************/ |
19 |
20 |
20 #define ABTASTFREQUENZ 100 |
21 #define ABTASTFREQUENZ 100 |
21 |
22 |
27 ec_master_t *master = NULL; |
28 ec_master_t *master = NULL; |
28 ec_domain_t *domain1 = NULL; |
29 ec_domain_t *domain1 = NULL; |
29 |
30 |
30 // Datenfelder |
31 // Datenfelder |
31 void *r_ssi; |
32 void *r_ssi; |
32 void *r_inc; |
|
33 |
33 |
34 // Kanäle |
34 // Kanäle |
35 uint32_t k_angle, k_pos; |
35 uint32_t k_pos; |
36 |
36 |
37 ec_field_init_t domain1_fields[] = { |
37 ec_field_init_t domain1_fields[] = { |
38 {&r_ssi, "1", "Beckhoff", "EL5001", ec_ipvalue, 0, 1}, |
38 {&r_ssi, "1", "Beckhoff", "EL5001", "InputValue", 0, 1}, |
39 {&r_inc, "0:3", "Beckhoff", "EL5101", ec_ipvalue, 0, 1}, |
|
40 {} |
39 {} |
41 }; |
40 }; |
42 |
41 |
43 /*****************************************************************************/ |
42 /*****************************************************************************/ |
44 |
43 |
45 void run(unsigned long data) |
44 void run(unsigned long data) |
46 { |
45 { |
47 static unsigned int counter = 0; |
46 static unsigned int counter = 0; |
48 |
47 |
49 // Prozessdaten lesen und schreiben |
48 #ifdef ASYNC |
50 EtherCAT_rt_domain_queue(domain1); |
49 // Prozessdaten emfpangen |
51 EtherCAT_rt_master_xio(master); |
50 ecrt_master_async_receive(master); |
52 EtherCAT_rt_domain_process(domain1); |
51 ecrt_domain_process(domain1); |
53 |
52 |
54 k_angle = EC_READ_U16(r_inc); |
53 // Prozessdaten verarbeiten |
55 k_pos = EC_READ_U32(r_ssi); |
54 k_pos = EC_READ_U32(r_ssi); |
|
55 |
|
56 // Prozessdaten senden |
|
57 ecrt_domain_queue(domain1); |
|
58 ecrt_master_async_send(master); |
|
59 #else |
|
60 // Prozessdaten senden und emfpangen |
|
61 ecrt_domain_queue(domain1); |
|
62 ecrt_master_sync_io(master); |
|
63 ecrt_domain_process(domain1); |
|
64 |
|
65 // Prozessdaten verarbeiten |
|
66 k_pos = EC_READ_U32(r_ssi); |
|
67 #endif |
56 |
68 |
57 if (counter) { |
69 if (counter) { |
58 counter--; |
70 counter--; |
59 } |
71 } |
60 else { |
72 else { |
61 counter = ABTASTFREQUENZ; |
73 counter = ABTASTFREQUENZ; |
62 printk(KERN_INFO "k_angle = %i\n", k_angle); |
|
63 printk(KERN_INFO "k_pos = %i\n", k_pos); |
74 printk(KERN_INFO "k_pos = %i\n", k_pos); |
64 } |
75 } |
65 |
76 |
66 // Timer neu starten |
77 // Timer neu starten |
67 timer.expires += HZ / ABTASTFREQUENZ; |
78 timer.expires += HZ / ABTASTFREQUENZ; |
70 |
81 |
71 /*****************************************************************************/ |
82 /*****************************************************************************/ |
72 |
83 |
73 int __init init_mini_module(void) |
84 int __init init_mini_module(void) |
74 { |
85 { |
75 const ec_field_init_t *field; |
|
76 |
|
77 printk(KERN_INFO "=== Starting Minimal EtherCAT environment... ===\n"); |
86 printk(KERN_INFO "=== Starting Minimal EtherCAT environment... ===\n"); |
78 |
87 |
79 if ((master = EtherCAT_rt_request_master(0)) == NULL) { |
88 if ((master = ecrt_request_master(0)) == NULL) { |
80 printk(KERN_ERR "Error requesting master 0!\n"); |
89 printk(KERN_ERR "Error requesting master 0!\n"); |
81 goto out_return; |
90 goto out_return; |
82 } |
91 } |
83 |
92 |
84 EtherCAT_rt_master_print(master); |
93 //ecrt_master_print(master); |
85 |
94 |
86 printk(KERN_INFO "Registering domain...\n"); |
95 printk(KERN_INFO "Registering domain...\n"); |
87 |
96 |
88 if (!(domain1 = EtherCAT_rt_master_register_domain(master, ec_sync, 100))) |
97 if (!(domain1 = ecrt_master_create_domain(master))) |
89 { |
98 { |
90 printk(KERN_ERR "EtherCAT: Could not register domain!\n"); |
99 printk(KERN_ERR "EtherCAT: Could not register domain!\n"); |
91 goto out_release_master; |
100 goto out_release_master; |
92 } |
101 } |
93 |
102 |
94 printk(KERN_INFO "Registering domain fields...\n"); |
103 printk(KERN_INFO "Registering domain fields...\n"); |
95 |
104 |
96 for (field = domain1_fields; field->data; field++) |
105 if (ecrt_domain_register_field_list(domain1, domain1_fields)) { |
97 { |
106 printk(KERN_ERR "EtherCAT: Could not register field!\n"); |
98 if (!EtherCAT_rt_register_slave_field(domain1, |
107 goto out_release_master; |
99 field->address, |
|
100 field->vendor, |
|
101 field->product, |
|
102 field->data, |
|
103 field->field_type, |
|
104 field->field_index, |
|
105 field->field_count)) { |
|
106 printk(KERN_ERR "EtherCAT: Could not register field!\n"); |
|
107 goto out_release_master; |
|
108 } |
|
109 } |
108 } |
110 |
109 |
111 printk(KERN_INFO "Activating master...\n"); |
110 printk(KERN_INFO "Activating master...\n"); |
112 |
111 |
113 if (EtherCAT_rt_master_activate(master)) { |
112 if (ecrt_master_activate(master)) { |
114 printk(KERN_ERR "EtherCAT: Could not activate master!\n"); |
113 printk(KERN_ERR "EtherCAT: Could not activate master!\n"); |
115 goto out_release_master; |
114 goto out_release_master; |
116 } |
115 } |
|
116 |
|
117 #ifdef ASYNC |
|
118 ecrt_domain_queue(domain1); |
|
119 ecrt_master_async_send(master); |
|
120 udelay(100); |
|
121 #endif |
117 |
122 |
118 printk("Starting cyclic sample thread.\n"); |
123 printk("Starting cyclic sample thread.\n"); |
119 |
124 |
120 init_timer(&timer); |
125 init_timer(&timer); |
121 timer.function = run; |
126 timer.function = run; |