Portierung der Module in drivers/ und mini/ nach Kernel 2.6.

This commit is contained in:
Florian Pose 2005-11-25 14:52:34 +00:00
parent c9bcae49fc
commit 6c19b64274
7 changed files with 3762 additions and 1115 deletions

View File

@ -43,14 +43,14 @@ endif
.mini: .mini:
$(MAKE) -C mini $(MAKE) -C mini
config $(CONFIG_FILE): config conf $(CONFIG_FILE):
@echo "# EtherCAT Konfigurationsdatei" > $(CONFIG_FILE) @echo "# EtherCAT Konfigurationsdatei Kernel 2.6" > $(CONFIG_FILE)
@echo >> $(CONFIG_FILE) @echo >> $(CONFIG_FILE)
@echo "KERNELDIR = /vol/projekte/msr_messen_steuern_regeln/linux/kernel/2.4.20/include/linux-2.4.20.CX1100-rthal5" >> $(CONFIG_FILE) @echo "KERNELDIR = /usr/src/linux" >> $(CONFIG_FILE)
@echo "RTAIDIR = /vol/projekte/msr_messen_steuern_regeln/linux/kernel/2.4.20/include/rtai-24.1.13" >> $(CONFIG_FILE) @echo "RTAIDIR =" >> $(CONFIG_FILE)
@echo "RTLIBDIR = rt_lib" >> $(CONFIG_FILE) @echo "RTLIBDIR =" >> $(CONFIG_FILE)
@echo >> $(CONFIG_FILE) @echo >> $(CONFIG_FILE)
@echo "GCC_SYSTEMDIR = /usr/lib/gcc-lib/i486-suse-linux/3.3/include" >> $(CONFIG_FILE) @echo "#GCC_SYSTEMDIR = /usr/lib/gcc-lib/i486-suse-linux/3.3/include" >> $(CONFIG_FILE)
@echo >> $(CONFIG_FILE) @echo >> $(CONFIG_FILE)
@echo "MAKE_RT = yes" >> $(CONFIG_FILE) @echo "MAKE_RT = yes" >> $(CONFIG_FILE)
@echo "MAKE_RS232 = yes" >> $(CONFIG_FILE) @echo "MAKE_RS232 = yes" >> $(CONFIG_FILE)

File diff suppressed because it is too large Load Diff

View File

@ -8,60 +8,34 @@
# #
#---------------------------------------------------------------- #----------------------------------------------------------------
CONFIG_FILE = ../ethercat.conf ifneq ($(KERNELRELEASE),)
ifeq ($(CONFIG_FILE),$(wildcard $(CONFIG_FILE))) #----------------------------------------------------------------
include $(CONFIG_FILE) # Kbuild-Abschnitt
else
KERNELDIR = /vol/projekte/msr_messen_steuern_regeln/linux/kernel/2.4.20/include/linux-2.4.20.CX1100-rthal5
RTAIDIR = /vol/projekte/msr_messen_steuern_regeln/linux/kernel/2.4.20/include/rtai-24.1.13
RTLIBDIR = rt_lib
GCC_SYSTEMDIR = /usr/lib/gcc-lib/i486-suse-linux/3.3/include
endif
CFLAGS = -O2 -Wall -Wuninitialized -D__KERNEL__ \ obj-m := 8139too-ecat.o
-DMODULE -I$(KERNELDIR)/include -nostdinc \
-isystem $(GCC_SYSTEMDIR)
ifdef CONFIG_SMP 8139too-ecat-objs := 8139too.o ec_device.o ec_master.o \
CFLAGS += -D__SMP__ -DSMP ec_slave.o ec_command.o ec_types.o
endif
MODULE = ecat_8139too.o
OBJ = drv_8139too.o ec_device.o ec_master.o \
ec_slave.o ec_command.o ec_types.o
SRC = $(OBJ:.o=.c)
#---------------------------------------------------------------- #----------------------------------------------------------------
all: .output_dirs depend $(MODULE) else
$(MODULE): $(OBJ) #----------------------------------------------------------------
$(LD) -r $(OBJ) -o $@ # Default-Abschnitt
.c.o: CONFIG_FILE = ../ethercat.conf
$(CC) $(CFLAGS) -c $< -o $@ PWD = $(shell pwd)
doc docs: include $(CONFIG_FILE) # Für KERNELDIR
$(MAKE) -C .. doc
.output_dirs: default:
@echo "x-- Directories -------------" $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
@echo "| Kernel $(KERNELDIR)"
@echo "| RTAI $(RTAIDIR)"
@echo "| RT_lib $(RTLIBDIR)"
@echo "x----------------------------"
.depend depend dep:
$(CC) $(CFLAGS) -M $(SRC) > .depend
clean: clean:
rm -f *.o *~ core .depend $(MAKE) -C $(KERNELDIR) M=$(PWD) clean
#---------------------------------------------------------------- #----------------------------------------------------------------
ifeq (.depend,$(wildcard .depend))
include .depend
endif endif
#----------------------------------------------------------------

View File

@ -17,7 +17,8 @@
#include "ec_device.h" #include "ec_device.h"
#include "ec_dbg.h" #include "ec_dbg.h"
extern void rtl8139_interrupt(int, void *, struct pt_regs *); extern irqreturn_t rtl8139_interrupt(int, void *, struct pt_regs *);
extern int rtl8139_poll(struct net_device *, int *);
/***************************************************************/ /***************************************************************/
@ -291,7 +292,18 @@ int EtherCAT_device_receive(EtherCAT_device_t *ecd,
void EtherCAT_device_call_isr(EtherCAT_device_t *ecd) void EtherCAT_device_call_isr(EtherCAT_device_t *ecd)
{ {
rtl8139_interrupt(0, ecd->dev, NULL); int budget;
budget = 1; /* Einen Frame empfangen */
rtl8139_interrupt(0, ecd->dev, NULL);
rtl8139_poll(ecd->dev, &budget);
if (budget != 0)
{
EC_DBG(KERN_ERR "EtherCAT: Warning - Budget is %d!\n",
budget);
}
} }
/***************************************************************/ /***************************************************************/

2646
drivers/original_8139too.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -8,47 +8,33 @@
# #
#---------------------------------------------------------------- #----------------------------------------------------------------
CONFIG_FILE = ../ethercat.conf ifneq ($(KERNELRELEASE),)
ifeq ($(CONFIG_FILE),$(wildcard $(CONFIG_FILE))) #----------------------------------------------------------------
include $(CONFIG_FILE) # Kbuild-Abschnitt
else
KERNELDIR = /vol/projekte/msr_messen_steuern_regeln/linux/kernel/2.4.20/include/linux-2.4.20.CX1100-rthal5
RTAIDIR = /vol/projekte/msr_messen_steuern_regeln/linux/kernel/2.4.20/include/rtai-24.1.13
RTLIBDIR = rt_lib
endif
CFLAGS = -O2 -Wall -Wuninitialized -D__KERNEL__ \ obj-m := ec_mini_mod.o
-DMODULE -I$(KERNELDIR)/include
MODULE = ec_mini_mod.o ec_mini_mod-objs := ec_mini.o
SRC = ec_mini.c
OBJ = $(SRC:.c=.o)
#---------------------------------------------------------------- #----------------------------------------------------------------
all: .output_dirs .depend Makefile $(MODULE) else
$(MODULE): $(OBJ) #----------------------------------------------------------------
$(LD) -r $(OBJ) -o $@ # Default-Abschnitt
.output_dirs: CONFIG_FILE = ../ethercat.conf
@echo "x-- Directories -------------" PWD = $(shell pwd)
@echo "| Kernel $(KERNELDIR)"
@echo "| RTAI $(RTAIDIR)"
@echo "| RT_lib $(RTLIBDIR)"
@echo "x----------------------------"
depend .depend dep: include $(CONFIG_FILE) # Für KERNELDIR
$(CC) $(CFLAGS) -M $(SRC) > .depend
default:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
clean: clean:
rm -f *.o *~ core .depend $(MAKE) -C $(KERNELDIR) M=$(PWD) clean
#---------------------------------------------------------------- #----------------------------------------------------------------
ifeq (.depend,$(wildcard .depend))
include .depend
endif endif
#----------------------------------------------------------------

View File

@ -9,10 +9,9 @@
******************************************************************************/ ******************************************************************************/
#include <linux/module.h> #include <linux/module.h>
#include <linux/tqueue.h> //#include <linux/slab.h>
#include <linux/slab.h> //#include <linux/delay.h>
#include <linux/delay.h> #include <linux/timer.h>
#include <linux/completion.h>
#include "../drivers/ec_master.h" #include "../drivers/ec_master.h"
#include "../drivers/ec_device.h" #include "../drivers/ec_device.h"
@ -21,6 +20,8 @@
/******************************************************************************/ /******************************************************************************/
#define ECAT
#define ECAT_OPEN #define ECAT_OPEN
#define ECAT_MASTER #define ECAT_MASTER
#define ECAT_SLAVES #define ECAT_SLAVES
@ -28,6 +29,8 @@
/******************************************************************************/ /******************************************************************************/
#ifdef ECAT
extern EtherCAT_device_t rtl_ecat_dev; extern EtherCAT_device_t rtl_ecat_dev;
#ifdef ECAT_MASTER #ifdef ECAT_MASTER
@ -38,61 +41,66 @@ static EtherCAT_master_t *ecat_master = NULL;
static EtherCAT_slave_t ecat_slaves[] = static EtherCAT_slave_t ecat_slaves[] =
{ {
#if 0 #if 0
// Block 1 // Block 1
ECAT_INIT_SLAVE(Beckhoff_EK1100), ECAT_INIT_SLAVE(Beckhoff_EK1100),
ECAT_INIT_SLAVE(Beckhoff_EL4102), ECAT_INIT_SLAVE(Beckhoff_EL4102),
ECAT_INIT_SLAVE(Beckhoff_EL3162), ECAT_INIT_SLAVE(Beckhoff_EL3162),
ECAT_INIT_SLAVE(Beckhoff_EL1014), ECAT_INIT_SLAVE(Beckhoff_EL1014),
ECAT_INIT_SLAVE(Beckhoff_EL2004), ECAT_INIT_SLAVE(Beckhoff_EL2004),
ECAT_INIT_SLAVE(Beckhoff_EL3102), ECAT_INIT_SLAVE(Beckhoff_EL3102),
ECAT_INIT_SLAVE(Beckhoff_EL4102), ECAT_INIT_SLAVE(Beckhoff_EL4102),
ECAT_INIT_SLAVE(Beckhoff_EL4102), ECAT_INIT_SLAVE(Beckhoff_EL4102),
ECAT_INIT_SLAVE(Beckhoff_EL4102), ECAT_INIT_SLAVE(Beckhoff_EL4102),
ECAT_INIT_SLAVE(Beckhoff_EL3162), ECAT_INIT_SLAVE(Beckhoff_EL3162),
ECAT_INIT_SLAVE(Beckhoff_EL3162), ECAT_INIT_SLAVE(Beckhoff_EL3162),
ECAT_INIT_SLAVE(Beckhoff_EL3162), ECAT_INIT_SLAVE(Beckhoff_EL3162),
ECAT_INIT_SLAVE(Beckhoff_EL3102), ECAT_INIT_SLAVE(Beckhoff_EL3102),
ECAT_INIT_SLAVE(Beckhoff_EL3102), ECAT_INIT_SLAVE(Beckhoff_EL3102),
ECAT_INIT_SLAVE(Beckhoff_EL2004), ECAT_INIT_SLAVE(Beckhoff_EL2004),
ECAT_INIT_SLAVE(Beckhoff_EL2004), ECAT_INIT_SLAVE(Beckhoff_EL2004),
ECAT_INIT_SLAVE(Beckhoff_EL2004), ECAT_INIT_SLAVE(Beckhoff_EL2004),
ECAT_INIT_SLAVE(Beckhoff_EL2004), ECAT_INIT_SLAVE(Beckhoff_EL2004),
#endif #endif
// Block 2 // Block 2
ECAT_INIT_SLAVE(Beckhoff_EK1100), ECAT_INIT_SLAVE(Beckhoff_EK1100),
ECAT_INIT_SLAVE(Beckhoff_EL4102), ECAT_INIT_SLAVE(Beckhoff_EL4102),
ECAT_INIT_SLAVE(Beckhoff_EL1014), ECAT_INIT_SLAVE(Beckhoff_EL1014),
ECAT_INIT_SLAVE(Beckhoff_EL3162), ECAT_INIT_SLAVE(Beckhoff_EL3162),
ECAT_INIT_SLAVE(Beckhoff_EL2004), ECAT_INIT_SLAVE(Beckhoff_EL2004),
ECAT_INIT_SLAVE(Beckhoff_EL3102), ECAT_INIT_SLAVE(Beckhoff_EL3102),
// Block 3 // Block 3
ECAT_INIT_SLAVE(Beckhoff_EK1100), ECAT_INIT_SLAVE(Beckhoff_EK1100),
ECAT_INIT_SLAVE(Beckhoff_EL1014), ECAT_INIT_SLAVE(Beckhoff_EL1014),
ECAT_INIT_SLAVE(Beckhoff_EL1014), ECAT_INIT_SLAVE(Beckhoff_EL1014),
ECAT_INIT_SLAVE(Beckhoff_EL1014), ECAT_INIT_SLAVE(Beckhoff_EL1014),
ECAT_INIT_SLAVE(Beckhoff_EL1014), ECAT_INIT_SLAVE(Beckhoff_EL1014),
ECAT_INIT_SLAVE(Beckhoff_EL1014), ECAT_INIT_SLAVE(Beckhoff_EL1014),
ECAT_INIT_SLAVE(Beckhoff_EL2004), ECAT_INIT_SLAVE(Beckhoff_EL2004),
ECAT_INIT_SLAVE(Beckhoff_EL2004), ECAT_INIT_SLAVE(Beckhoff_EL2004),
ECAT_INIT_SLAVE(Beckhoff_EL2004), ECAT_INIT_SLAVE(Beckhoff_EL2004),
ECAT_INIT_SLAVE(Beckhoff_EL2004), ECAT_INIT_SLAVE(Beckhoff_EL2004),
ECAT_INIT_SLAVE(Beckhoff_EL1014), ECAT_INIT_SLAVE(Beckhoff_EL1014),
ECAT_INIT_SLAVE(Beckhoff_EL1014), ECAT_INIT_SLAVE(Beckhoff_EL1014),
ECAT_INIT_SLAVE(Beckhoff_EL1014) ECAT_INIT_SLAVE(Beckhoff_EL1014)
}; };
#define ECAT_SLAVES_COUNT (sizeof(ecat_slaves) / sizeof(EtherCAT_slave_t)) #define ECAT_SLAVES_COUNT (sizeof(ecat_slaves) / sizeof(EtherCAT_slave_t))
#endif
#endif // ECAT_SLAVES
#endif // ECAT
#ifdef ECAT_CYCLIC_DATA #ifdef ECAT_CYCLIC_DATA
double value; double value;
int dig1; int dig1;
struct tq_struct cyclic_task;
struct clientdata {task_queue *queue;} cyclic_data; struct timer_list timer;
static DECLARE_COMPLETION(on_exit); unsigned long last_start_jiffies;
#endif
#endif // ECAT_CYCLIC_DATA
/****************************************************************************** /******************************************************************************
* *
@ -100,31 +108,34 @@ static DECLARE_COMPLETION(on_exit);
* *
*****************************************************************************/ *****************************************************************************/
#ifdef ECAT
#ifdef ECAT_CYCLIC_DATA #ifdef ECAT_CYCLIC_DATA
static int next2004(int *wrap) static int next2004(int *wrap)
{ {
static int i = 0; static int i = 0;
unsigned int j = 0; unsigned int j = 0;
*wrap = 0; *wrap = 0;
for (j = 0; j < ECAT_SLAVES_COUNT; j++) for (j = 0; j < ECAT_SLAVES_COUNT; j++)
{
i++;
i %= ECAT_SLAVES_COUNT;
if (i == 0) *wrap = 1;
if (ecat_slaves[i].desc == Beckhoff_EL2004)
{ {
return i; i++;
}
}
return -1; i %= ECAT_SLAVES_COUNT;
if (i == 0) *wrap = 1;
if (ecat_slaves[i].desc == Beckhoff_EL2004)
{
return i;
}
}
return -1;
} }
#endif #endif
#endif
/****************************************************************************** /******************************************************************************
* *
@ -135,248 +146,266 @@ static int next2004(int *wrap)
*****************************************************************************/ *****************************************************************************/
#ifdef ECAT_CYCLIC_DATA #ifdef ECAT_CYCLIC_DATA
void run(void *ptr)
static void run(unsigned long data)
{ {
struct clientdata *data = (struct clientdata *) ptr; #ifdef ECAT
static int ms = 0;
static int cnt = 0;
static unsigned long int k = 0;
static int firstrun = 1;
#if 1 static int klemme = 12;
static int ms = 0; static int kanal = 0;
static int cnt = 0; static int up_down = 0;
static unsigned long int k = 0; int wrap = 0;
static int firstrun = 1;
static int klemme = 12; ms++;
static int kanal = 0; ms %= 1000;
static int up_down = 0;
int wrap = 0;
ms++;
ms %= 1000;
#if 0 #if 0
ecat_tx_delay = ((unsigned int) (100000 / HZ) * (ecat_master->dev->tx_time-k)) ecat_tx_delay = ((unsigned int) (100000 / HZ) * (ecat_master->dev->tx_time-k))
/ (current_cpu_data.loops_per_jiffy / 10); / (current_cpu_data.loops_per_jiffy / 10);
ecat_rx_delay = ((unsigned int) (100000 / HZ) * (ecat_master->dev->rx_time-k)) ecat_rx_delay = ((unsigned int) (100000 / HZ) * (ecat_master->dev->rx_time-k))
/ (current_cpu_data.loops_per_jiffy / 10); / (current_cpu_data.loops_per_jiffy / 10);
rx_intr = ecat_master->dev->rx_intr_cnt; rx_intr = ecat_master->dev->rx_intr_cnt;
tx_intr = ecat_master->dev->tx_intr_cnt; tx_intr = ecat_master->dev->tx_intr_cnt;
total_intr = ecat_master->dev->intr_cnt; total_intr = ecat_master->dev->intr_cnt;
#endif #endif
// Prozessdaten lesen // Prozessdaten lesen
if (!firstrun) if (!firstrun)
{
klemme = next2004(&wrap);
EtherCAT_read_process_data(ecat_master);
// Daten lesen und skalieren
value = EtherCAT_read_value(&ecat_master->slaves[5], 0) / 3276.7;
dig1 = EtherCAT_read_value(&ecat_master->slaves[3], 0);
}
#if 0
// Daten schreiben
EtherCAT_write_value(&ecat_master->slaves[4], 0, ms > 500 ? 1 : 0);
EtherCAT_write_value(&ecat_master->slaves[4], 1, ms > 500 ? 0 : 1);
EtherCAT_write_value(&ecat_master->slaves[4], 2, ms > 500 ? 0 : 1);
EtherCAT_write_value(&ecat_master->slaves[4], 3, ms > 500 ? 1 : 0);
#endif
if (cnt++ > 20)
{
cnt = 0;
if (++kanal > 3)
{ {
kanal = 0; klemme = next2004(&wrap);
klemme = next2004(&wrap);
if (wrap == 1) EtherCAT_read_process_data(ecat_master);
{
if (up_down == 1) up_down = 0; // Daten lesen und skalieren
else up_down = 1; value = EtherCAT_read_value(&ecat_master->slaves[5], 0) / 3276.7;
} dig1 = EtherCAT_read_value(&ecat_master->slaves[3], 0);
} }
}
if (klemme >= 0)
EtherCAT_write_value(&ecat_master->slaves[klemme], kanal,up_down);
#if 0 #if 0
EtherCAT_write_value(&ecat_master->slaves[13], 1, ms > 500 ? 0 : 1); // Daten schreiben
EtherCAT_write_value(&ecat_master->slaves[14], 2, ms > 500 ? 0 : 1); EtherCAT_write_value(&ecat_master->slaves[4], 0, ms > 500 ? 1 : 0);
EtherCAT_write_value(&ecat_master->slaves[15], 3, ms > 500 ? 1 : 0); EtherCAT_write_value(&ecat_master->slaves[4], 1, ms > 500 ? 0 : 1);
EtherCAT_write_value(&ecat_master->slaves[4], 2, ms > 500 ? 0 : 1);
EtherCAT_write_value(&ecat_master->slaves[4], 3, ms > 500 ? 1 : 0);
#endif #endif
// Prozessdaten schreiben if (cnt++ > 20)
rdtscl(k); {
EtherCAT_write_process_data(ecat_master); cnt = 0;
firstrun = 0;
if (++kanal > 3)
{
kanal = 0;
klemme = next2004(&wrap);
if (wrap == 1)
{
if (up_down == 1) up_down = 0;
else up_down = 1;
}
}
}
if (klemme >= 0)
EtherCAT_write_value(&ecat_master->slaves[klemme], kanal,up_down);
#if 0
EtherCAT_write_value(&ecat_master->slaves[13], 1, ms > 500 ? 0 : 1);
EtherCAT_write_value(&ecat_master->slaves[14], 2, ms > 500 ? 0 : 1);
EtherCAT_write_value(&ecat_master->slaves[15], 3, ms > 500 ? 1 : 0);
#endif #endif
if (data->queue) // Prozessdaten schreiben
{ rdtscl(k);
// Neu in die Taskqueue eintragen EtherCAT_write_process_data(ecat_master);
queue_task(&cyclic_task, data->queue); firstrun = 0;
} #endif
else
{ timer.expires += HZ / 100;
//last_queue_finished = 0; add_timer(&timer);
complete(&on_exit);
}
} }
#endif
#endif // ECAT_CYCLIC_DATA
/****************************************************************************** /******************************************************************************
* *
* Function: init * Function: init
* *
******************************************************************************/ ******************************************************************************/
int init() int __init init_module()
{ {
#ifdef ECAT
#ifdef ECAT_OPEN #ifdef ECAT_OPEN
int rv = -1; int rv = -1;
#endif
#endif #endif
EC_DBG(KERN_INFO "=== Starting Minimal EtherCAT environment... ===\n"); EC_DBG(KERN_INFO "=== Starting Minimal EtherCAT environment... ===\n");
EtherCAT_device_debug(&rtl_ecat_dev); #ifdef ECAT
//mdelay(5000);
EtherCAT_device_debug(&rtl_ecat_dev);
#ifdef ECAT_OPEN #ifdef ECAT_OPEN
EC_DBG("Opening EtherCAT device.\n"); EC_DBG("Opening EtherCAT device.\n");
// HIER PASSIERT DER FEHLER: // HIER PASSIERT DER FEHLER:
if (EtherCAT_device_open(&rtl_ecat_dev) < 0) if (EtherCAT_device_open(&rtl_ecat_dev) < 0)
{ {
EC_DBG(KERN_ERR "msr_modul: Could not initialize EtherCAT NIC.\n"); EC_DBG(KERN_ERR "msr_modul: Could not initialize EtherCAT NIC.\n");
goto out_nothing; goto out_nothing;
} }
if (!rtl_ecat_dev.dev) // Es gibt kein EtherCAT-Device if (!rtl_ecat_dev.dev) // Es gibt kein EtherCAT-Device
{ {
EC_DBG(KERN_ERR "msr_modul: No EtherCAT device!\n"); EC_DBG(KERN_ERR "msr_modul: No EtherCAT device!\n");
goto out_close; goto out_close;
} }
#endif #endif // ECAT_OPEN
#ifdef ECAT_MASTER #ifdef ECAT_MASTER
EC_DBG("Initialising EtherCAT master\n"); EC_DBG("Initialising EtherCAT master\n");
if ((ecat_master = (EtherCAT_master_t *) kmalloc(sizeof(EtherCAT_master_t), GFP_KERNEL)) == 0) if ((ecat_master = (EtherCAT_master_t *) kmalloc(sizeof(EtherCAT_master_t), GFP_KERNEL)) == 0)
{ {
EC_DBG(KERN_ERR "msr_modul: Could not alloc memory for EtherCAT master!\n"); EC_DBG(KERN_ERR "msr_modul: Could not alloc memory for EtherCAT master!\n");
goto out_close; goto out_close;
} }
if (EtherCAT_master_init(ecat_master, &rtl_ecat_dev) < 0) if (EtherCAT_master_init(ecat_master, &rtl_ecat_dev) < 0)
{ {
EC_DBG(KERN_ERR "EtherCAT could not init master!\n"); EC_DBG(KERN_ERR "EtherCAT could not init master!\n");
goto out_master; goto out_master;
} }
//ecat_master->debug_level = 1; //ecat_master->debug_level = 1;
#endif
#endif // ECAT_MASTER
#ifdef ECAT_SLAVES #ifdef ECAT_SLAVES
EC_DBG("Checking EtherCAT slaves.\n"); EC_DBG("Checking EtherCAT slaves.\n");
if (EtherCAT_check_slaves(ecat_master, ecat_slaves, ECAT_SLAVES_COUNT) != 0) if (EtherCAT_check_slaves(ecat_master, ecat_slaves, ECAT_SLAVES_COUNT) != 0)
{ {
EC_DBG(KERN_ERR "EtherCAT: Could not init slaves!\n"); EC_DBG(KERN_ERR "EtherCAT: Could not init slaves!\n");
goto out_masterclear; goto out_masterclear;
} }
EC_DBG("Activating all EtherCAT slaves.\n"); EC_DBG("Activating all EtherCAT slaves.\n");
if (EtherCAT_activate_all_slaves(ecat_master) != 0) if (EtherCAT_activate_all_slaves(ecat_master) != 0)
{ {
EC_DBG(KERN_ERR "EtherCAT: Could not activate slaves!\n"); EC_DBG(KERN_ERR "EtherCAT: Could not activate slaves!\n");
goto out_masterclear; goto out_masterclear;
} }
#endif #endif
#endif // ECAT
#ifdef ECAT_CYCLIC_DATA #ifdef ECAT_CYCLIC_DATA
EC_DBG("Starting cyclic sample thread.\n"); EC_DBG("Starting cyclic sample thread.\n");
cyclic_task.routine = run; init_timer(&timer);
cyclic_task.data = (void *) &cyclic_data;
cyclic_data.queue = &tq_timer;
queue_task(&cyclic_task, &tq_timer);
EC_DBG("Initialised sample thread.\n"); timer.function = run;
timer.data = 0;
timer.expires = jiffies; // Das erste Mal sofort feuern
last_start_jiffies = timer.expires;
add_timer(&timer);
EC_DBG("Initialised sample thread.\n");
#endif #endif
EC_DBG(KERN_INFO "=== Minimal EtherCAT environment started. ===\n"); EC_DBG(KERN_INFO "=== Minimal EtherCAT environment started. ===\n");
return 0; return 0;
#ifdef ECAT
#ifdef ECAT_SLAVES #ifdef ECAT_SLAVES
out_masterclear: out_masterclear:
EC_DBG(KERN_INFO "Clearing EtherCAT master.\n"); EC_DBG(KERN_INFO "Clearing EtherCAT master.\n");
EtherCAT_master_clear(ecat_master); EtherCAT_master_clear(ecat_master);
#endif #endif
#ifdef ECAT_MASTER #ifdef ECAT_MASTER
out_master: out_master:
EC_DBG(KERN_INFO "Freeing EtherCAT master.\n"); EC_DBG(KERN_INFO "Freeing EtherCAT master.\n");
kfree(ecat_master); kfree(ecat_master);
#endif #endif
#ifdef ECAT_OPEN #ifdef ECAT_OPEN
out_close: out_close:
EC_DBG(KERN_INFO "Closing device.\n"); EC_DBG(KERN_INFO "Closing device.\n");
EtherCAT_device_close(&rtl_ecat_dev); EtherCAT_device_close(&rtl_ecat_dev);
out_nothing: out_nothing:
return rv; return rv;
#endif #endif
#endif // ECAT
} }
/****************************************************************************** /******************************************************************************
* *
* Function: cleanup * Function: cleanup
* *
******************************************************************************/ ******************************************************************************/
void cleanup() void __exit cleanup_module()
{ {
EC_DBG(KERN_INFO "=== Stopping Minimal EtherCAT environment... ===\n"); EC_DBG(KERN_INFO "=== Stopping Minimal EtherCAT environment... ===\n");
#ifdef ECAT_MASTER #ifdef ECAT_MASTER
if (ecat_master)
{ #ifdef ECAT
//ecat_master->debug_level = 1; if (ecat_master)
{
#endif
//ecat_master->debug_level = 1;
#ifdef ECAT_CYCLIC_DATA #ifdef ECAT_CYCLIC_DATA
cyclic_data.queue = NULL;
wait_for_completion(&on_exit); del_timer_sync(&timer);
EtherCAT_clear_process_data(ecat_master);
#ifdef ECAT
EtherCAT_clear_process_data(ecat_master);
#endif #endif
#endif // ECAT_CYCLIC_DATA
#ifdef ECAT
#ifdef ECAT_SLAVES #ifdef ECAT_SLAVES
EC_DBG(KERN_INFO "Deactivating slaves.\n"); EC_DBG(KERN_INFO "Deactivating slaves.\n");
EtherCAT_deactivate_all_slaves(ecat_master); EtherCAT_deactivate_all_slaves(ecat_master);
#endif #endif
EC_DBG(KERN_INFO "Clearing EtherCAT master.\n"); EC_DBG(KERN_INFO "Clearing EtherCAT master.\n");
EtherCAT_master_clear(ecat_master); EtherCAT_master_clear(ecat_master);
EC_DBG(KERN_INFO "Freeing EtherCAT master.\n"); EC_DBG(KERN_INFO "Freeing EtherCAT master.\n");
kfree(ecat_master); kfree(ecat_master);
ecat_master = NULL; ecat_master = NULL;
} }
#endif #endif // ECAT
#endif // ECAT_MASTER
#ifdef ECAT
#ifdef ECAT_OPEN #ifdef ECAT_OPEN
EC_DBG(KERN_INFO "Closing device.\n"); EC_DBG(KERN_INFO "Closing device.\n");
EtherCAT_device_close(&rtl_ecat_dev); EtherCAT_device_close(&rtl_ecat_dev);
#endif
#endif #endif
EC_DBG(KERN_INFO "=== Minimal EtherCAT environment stopped. ===\n"); EC_DBG(KERN_INFO "=== Minimal EtherCAT environment stopped. ===\n");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -385,7 +414,7 @@ MODULE_LICENSE("GPL");
MODULE_AUTHOR ("Florian Pose <fp@igh-essen.com>"); MODULE_AUTHOR ("Florian Pose <fp@igh-essen.com>");
MODULE_DESCRIPTION ("Minimal EtherCAT environment"); MODULE_DESCRIPTION ("Minimal EtherCAT environment");
module_init(init); module_init(init_module);
module_exit(cleanup); module_exit(cleanup_module);
/*****************************************************************************/ /*****************************************************************************/