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