LibEC
authorFlorian Pose <fp@igh-essen.com>
Fri, 20 Jan 2006 17:50:35 +0000
changeset 57 bae4965439b8
parent 56 36d1fa37f5e1
child 58 21b7342e2a90
LibEC
Makefile
libec/Makefile
libec/libec.c
libec/libec.h
mini/mini.c
rt/Makefile
rt/libec.o_shipped
rt/msr_module.c
--- a/Makefile	Fri Jan 20 16:04:10 2006 +0000
+++ b/Makefile	Fri Jan 20 17:50:35 2006 +0000
@@ -13,7 +13,7 @@
 #------------------------------------------------------------------------------
 # Kbuild-Abschnitt
 
-obj-m := master/ devices/ rt/ mini/
+obj-m := master/ devices/ libec/ rt/ mini/
 
 #------------------------------------------------------------------------------
 
@@ -25,7 +25,7 @@
 include ethercat.conf
 
 modules:
-	$(MAKE) -C $(KERNELDIR) M=`pwd` modules
+	$(MAKE) -C $(KERNELDIR) M=`pwd`
 
 clean:
 	$(MAKE) -C $(KERNELDIR) M=`pwd` clean
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libec/Makefile	Fri Jan 20 17:50:35 2006 +0000
@@ -0,0 +1,41 @@
+#------------------------------------------------------------------------------
+#
+#  Makefile
+#
+#  EtherCAT-Library
+#
+#  $Id$
+#
+#------------------------------------------------------------------------------
+
+ifneq ($(KERNELRELEASE),)
+
+#------------------------------------------------------------------------------
+# Kbuild-Abschnitt
+
+lib-m := libec.o
+
+#------------------------------------------------------------------------------
+
+else
+
+#------------------------------------------------------------------------------
+# Default-Abschnitt
+
+ifneq ($(wildcard ethercat.conf),)
+include ethercat.conf
+else
+KERNELDIR = /lib/modules/`uname -r`/build
+endif
+
+modules:
+	$(MAKE) -C $(KERNELDIR) M=`pwd`
+
+clean:
+	$(MAKE) -C $(KERNELDIR) M=`pwd` clean
+
+#------------------------------------------------------------------------------
+
+endif
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libec/libec.c	Fri Jan 20 17:50:35 2006 +0000
@@ -0,0 +1,57 @@
+/******************************************************************************
+ *
+ *  l i b e c . c
+ *
+ *  EtherCAT-Library fuer Echtzeitmodule
+ *
+ *  $Id$
+ *
+ *****************************************************************************/
+
+#include "libec.h"
+
+/*****************************************************************************/
+
+int LEC_read_EL10XX(ec_slave_t *slave, unsigned int channel)
+{
+    unsigned char *data = slave->process_data;
+
+    return (data[0] >> channel) & 0x01;
+}
+
+/*****************************************************************************/
+
+int LEC_read_EL31XX(ec_slave_t *slave, unsigned int channel)
+{
+    unsigned char *data = slave->process_data;
+
+    return (short int) ((data[channel * 3 + 2] << 8) | data[channel * 3 + 1]);
+}
+
+/*****************************************************************************/
+
+void LEC_write_EL20XX(ec_slave_t *slave, unsigned int channel, int value)
+{
+    unsigned char *data = slave->process_data;
+
+    if (value) data[0] |= (1 << channel);
+    else data[0] &= ~(1 << channel);
+}
+
+/*****************************************************************************/
+
+void LEC_write_EL41XX(ec_slave_t *slave, unsigned int channel, int value)
+{
+    unsigned char *data = slave->process_data;
+
+    data[channel * 3 + 1] = (value & 0xFF00) >> 8;
+    data[channel * 3 + 2] = value & 0xFF;
+}
+
+/*****************************************************************************/
+
+/* Emacs-Konfiguration
+;;; Local Variables: ***
+;;; c-basic-offset:4 ***
+;;; End: ***
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libec/libec.h	Fri Jan 20 17:50:35 2006 +0000
@@ -0,0 +1,34 @@
+/******************************************************************************
+ *
+ *  l i b e c . h
+ *
+ *  EtherCAT-Library fuer Echtzeitmodule
+ *
+ *  $Id$
+ *
+ *****************************************************************************/
+
+#ifndef _LIBEC_H_
+#define _LIBEC_H_
+
+#ifndef _ETHERCAT_RT_H_
+#include "../include/EtherCAT_rt.h"
+#endif
+
+/*****************************************************************************/
+
+int LEC_read_EL10XX(ec_slave_t *slave, unsigned int channel);
+int LEC_read_EL31XX(ec_slave_t *slave, unsigned int channel);
+
+void LEC_write_EL20XX(ec_slave_t *slave, unsigned int channel, int value);
+void LEC_write_EL41XX(ec_slave_t *slave, unsigned int channel, int value);
+
+/*****************************************************************************/
+
+#endif
+
+/* Emacs-Konfiguration
+;;; Local Variables: ***
+;;; c-basic-offset:4 ***
+;;; End: ***
+*/
--- a/mini/mini.c	Fri Jan 20 16:04:10 2006 +0000
+++ b/mini/mini.c	Fri Jan 20 17:50:35 2006 +0000
@@ -59,7 +59,7 @@
 
     // Prozessdaten lesen und schreiben
     rdtscl(k);
-    EtherCAT_rt_exchange_io(master, 1, 100);
+    EtherCAT_rt_domain_xio(master, 1, 100);
     firstrun = 0;
 
     timer.expires += HZ / 1000;
--- a/rt/Makefile	Fri Jan 20 16:04:10 2006 +0000
+++ b/rt/Makefile	Fri Jan 20 17:50:35 2006 +0000
@@ -25,7 +25,7 @@
 		rt_lib/msr-core/msr_error_reg.o \
 		rt_lib/msr-utils/msr_utils.o \
 		rt_lib/msr-math/msr_base64.o \
-		libm.o
+		libm.o libec.o
 
 EXTRA_CFLAGS := -I $(src)/rt_lib/msr-include -D_SIMULATION \
 		-I/usr/include -mhard-float
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rt/libec.o_shipped	Fri Jan 20 17:50:35 2006 +0000
@@ -0,0 +1,1 @@
+../libec/lib.a
\ No newline at end of file
--- a/rt/msr_module.c	Fri Jan 20 16:04:10 2006 +0000
+++ b/rt/msr_module.c	Fri Jan 20 17:50:35 2006 +0000
@@ -33,7 +33,7 @@
 
 // EtherCAT
 #include "../include/EtherCAT_rt.h"
-#include "../eclib/eclib.h"
+#include "../libec/libec.h"
 
 // Defines/Makros
 #define TSC2US(T1, T2) ((T2 - T1) * 1000UL / cpu_khz)
@@ -51,11 +51,7 @@
 static struct ipipe_sysinfo sys_info;
 
 // EtherCAT
-
 ec_master_t *master = NULL;
-static unsigned int ecat_bus_time = 0;
-static unsigned int ecat_timeouts = 0;
-
 ec_slave_t *s_in1, *s_out1, *s_out2, *s_out3;
 
 double value;
@@ -90,18 +86,22 @@
     }
     else {
         // "Star Trek"-Effekte
-        *((unsigned char *) s_out1->process_data) = jiffies;
-        *((unsigned char *) s_out2->process_data) = jiffies >> 4;
-        *((unsigned char *) s_out3->process_data) = jiffies >> 8;
+        LEC_write_EL20XX(s_out1, 0, jiffies & 1);
+        LEC_write_EL20XX(s_out1, 1, (jiffies >> 1) & 1);
+        LEC_write_EL20XX(s_out1, 2, (jiffies >> 2) & 1);
+        LEC_write_EL20XX(s_out1, 3, (jiffies >> 3) & 1);
+        LEC_write_EL20XX(s_out2, 0, (jiffies >> 4) & 1);
+        LEC_write_EL20XX(s_out2, 1, (jiffies >> 3) & 1);
+        LEC_write_EL20XX(s_out2, 2, (jiffies >> 2) & 1);
+        LEC_write_EL20XX(s_out2, 3, (jiffies >> 6) & 1);
+        LEC_write_EL20XX(s_out3, 0, (jiffies >> 7) & 1);
+        LEC_write_EL20XX(s_out3, 1, (jiffies >> 2) & 1);
+        LEC_write_EL20XX(s_out3, 2, (jiffies >> 8) & 1);
 
         counter = MSR_ABTASTFREQUENZ / 4;
     }
 
-    if (((char *) s_in1->process_data)[2] < 0)
-        ((unsigned char *) s_out3->process_data)[0] |= 8;
-    else
-        ((unsigned char *) s_out3->process_data)[0] &= ~8;
-
+    LEC_write_EL20XX(s_out3, 3, LEC_read_EL31XX(s_in1, 0) < 0);
 
     // Prozessdaten lesen und schreiben
     EtherCAT_rt_domain_xio(master, 0, 40);
@@ -168,9 +168,6 @@
     msr_reg_kanal("/value", "V", &value, TDBL);
     msr_reg_kanal("/dig1", "", &dig1, TINT);
 
-    msr_reg_kanal("/Taskinfo/EtherCAT/BusTime", "us", &ecat_bus_time, TUINT);
-    msr_reg_kanal("/Taskinfo/EtherCAT/Timeouts", "", &ecat_timeouts, TUINT);
-
     return 0;
 }