|
1 /****************************************************************************** |
|
2 * |
|
3 * m i n i . c |
|
4 * |
|
5 * Minimalmodul für EtherCAT |
|
6 * |
|
7 * $Id$ |
|
8 * |
|
9 *****************************************************************************/ |
|
10 |
|
11 #include <linux/module.h> |
|
12 #include <linux/delay.h> |
|
13 #include <linux/timer.h> |
|
14 |
|
15 #include "../include/EtherCAT_rt.h" |
|
16 |
|
17 /*****************************************************************************/ |
|
18 |
|
19 // Auskommentieren, wenn keine zyklischen Daten erwuenscht |
|
20 #define ECAT_CYCLIC_DATA |
|
21 |
|
22 /*****************************************************************************/ |
|
23 |
|
24 ec_master_t *master = NULL; |
|
25 |
|
26 #ifdef ECAT_CYCLIC_DATA |
|
27 |
|
28 int value; |
|
29 int dig1; |
|
30 |
|
31 struct timer_list timer; |
|
32 unsigned long last_start_jiffies; |
|
33 |
|
34 #endif // ECAT_CYCLIC_DATA |
|
35 |
|
36 /****************************************************************************** |
|
37 * |
|
38 * Function: run |
|
39 * |
|
40 * Beschreibung: Zyklischer Prozess |
|
41 * |
|
42 *****************************************************************************/ |
|
43 |
|
44 #ifdef ECAT_CYCLIC_DATA |
|
45 |
|
46 static void run(unsigned long data) |
|
47 { |
|
48 static int ms = 0; |
|
49 static unsigned long int k = 0; |
|
50 static int firstrun = 1; |
|
51 |
|
52 ms++; |
|
53 ms %= 1000; |
|
54 |
|
55 #if 0 |
|
56 if (klemme >= 0) |
|
57 EtherCAT_write_value(&ecat_slaves[klemme], kanal, up_down); |
|
58 #endif |
|
59 |
|
60 // Prozessdaten lesen und schreiben |
|
61 rdtscl(k); |
|
62 EtherCAT_rt_domain_cycle(master, 1, 100); |
|
63 firstrun = 0; |
|
64 |
|
65 timer.expires += HZ / 1000; |
|
66 add_timer(&timer); |
|
67 } |
|
68 |
|
69 #endif // ECAT_CYCLIC_DATA |
|
70 |
|
71 /****************************************************************************** |
|
72 * |
|
73 * Function: init |
|
74 * |
|
75 *****************************************************************************/ |
|
76 |
|
77 int __init init_mini_module(void) |
|
78 { |
|
79 printk(KERN_INFO "=== Starting Minimal EtherCAT environment... ===\n"); |
|
80 |
|
81 if ((master = EtherCAT_rt_request_master(0)) == NULL) { |
|
82 printk(KERN_ERR "EtherCAT master 0 not available!\n"); |
|
83 goto out_return; |
|
84 } |
|
85 |
|
86 //check_slaves(); |
|
87 |
|
88 printk("Activating all EtherCAT slaves.\n"); |
|
89 |
|
90 if (EtherCAT_rt_activate_slaves(master) != 0) { |
|
91 printk(KERN_ERR "EtherCAT: Could not activate slaves!\n"); |
|
92 goto out_release_master; |
|
93 } |
|
94 |
|
95 #ifdef ECAT_CYCLIC_DATA |
|
96 printk("Starting cyclic sample thread.\n"); |
|
97 |
|
98 init_timer(&timer); |
|
99 |
|
100 timer.function = run; |
|
101 timer.data = 0; |
|
102 timer.expires = jiffies+10; // Das erste Mal sofort feuern |
|
103 last_start_jiffies = timer.expires; |
|
104 add_timer(&timer); |
|
105 |
|
106 printk("Initialised sample thread.\n"); |
|
107 #endif |
|
108 |
|
109 printk(KERN_INFO "=== Minimal EtherCAT environment started. ===\n"); |
|
110 |
|
111 return 0; |
|
112 |
|
113 out_release_master: |
|
114 EtherCAT_rt_release_master(master); |
|
115 |
|
116 out_return: |
|
117 return -1; |
|
118 } |
|
119 |
|
120 /****************************************************************************** |
|
121 * |
|
122 * Function: cleanup |
|
123 * |
|
124 *****************************************************************************/ |
|
125 |
|
126 void __exit cleanup_mini_module(void) |
|
127 { |
|
128 printk(KERN_INFO "=== Stopping Minimal EtherCAT environment... ===\n"); |
|
129 |
|
130 if (master) |
|
131 { |
|
132 #ifdef ECAT_CYCLIC_DATA |
|
133 del_timer_sync(&timer); |
|
134 #endif // ECAT_CYCLIC_DATA |
|
135 |
|
136 printk(KERN_INFO "Deactivating slaves.\n"); |
|
137 |
|
138 EtherCAT_rt_deactivate_slaves(master); |
|
139 EtherCAT_rt_release_master(master); |
|
140 } |
|
141 |
|
142 printk(KERN_INFO "=== Minimal EtherCAT environment stopped. ===\n"); |
|
143 } |
|
144 |
|
145 /*****************************************************************************/ |
|
146 |
|
147 MODULE_LICENSE("GPL"); |
|
148 MODULE_AUTHOR ("Florian Pose <fp@igh-essen.com>"); |
|
149 MODULE_DESCRIPTION ("Minimal EtherCAT environment"); |
|
150 |
|
151 module_init(init_mini_module); |
|
152 module_exit(cleanup_mini_module); |
|
153 |
|
154 /*****************************************************************************/ |
|
155 |
|
156 /* Emacs-Konfiguration |
|
157 ;;; Local Variables: *** |
|
158 ;;; c-basic-offset:4 *** |
|
159 ;;; End: *** |
|
160 */ |