EtherCAT-Slave-Interface als Makros implementiert.
authorFlorian Pose <fp@igh-essen.com>
Thu, 26 Jan 2006 10:48:26 +0000
changeset 59 c8bd4fe3b38c
parent 58 21b7342e2a90
child 60 2d2b120ba734
EtherCAT-Slave-Interface als Makros implementiert.
Makefile
include/EtherCAT_si.h
libec/Makefile
libec/libec.c
libec/libec.h
rt/Makefile
rt/libec.o_shipped
rt/msr_module.c
--- a/Makefile	Thu Jan 26 09:12:09 2006 +0000
+++ b/Makefile	Thu Jan 26 10:48:26 2006 +0000
@@ -13,7 +13,7 @@
 #------------------------------------------------------------------------------
 # Kbuild-Abschnitt
 
-obj-m := master/ devices/ libec/ rt/ mini/
+obj-m := master/ devices/ rt/ mini/
 
 #------------------------------------------------------------------------------
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/EtherCAT_si.h	Thu Jan 26 10:48:26 2006 +0000
@@ -0,0 +1,46 @@
+/******************************************************************************
+ *
+ *  E t h e r C A T _ s i . h
+ *
+ *  EtherCAT Slave-Interface.
+ *
+ *  $Id$
+ *
+ *****************************************************************************/
+
+#define EC_PROC_DATA(SLAVE) ((unsigned char *) ((SLAVE)->process_data))
+
+/*****************************************************************************/
+
+#define EC_READ_EL10XX(SLAVE, CHANNEL) \
+    ((EC_PROC_DATA(SLAVE)[0] >> (CHANNEL)) & 0x01)
+
+/*****************************************************************************/
+
+#define EC_READ_EL31XX(SLAVE, CHANNEL) \
+    ((short int) ((EC_PROC_DATA(SLAVE)[(CHANNEL) * 3 + 2] << 8) | \
+                   EC_PROC_DATA(SLAVE)[(CHANNEL) * 3 + 1]))
+
+/*****************************************************************************/
+
+#define EC_WRITE_EL20XX(SLAVE, CHANNEL, VALUE) \
+    do { \
+        if (VALUE) EC_PROC_DATA(SLAVE)[0] |=  (1 << (CHANNEL)); \
+        else       EC_PROC_DATA(SLAVE)[0] &= ~(1 << (CHANNEL)); \
+    } while (0)
+
+/*****************************************************************************/
+
+#define EC_WRITE_EL41XX(SLAVE, CHANNEL, VALUE) \
+    do { \
+        EC_PROC_DATA(SLAVE)[(CHANNEL) * 3 + 1] = ((VALUE) & 0xFF00) >> 8; \
+        EC_PROC_DATA(SLAVE)[(CHANNEL) * 3 + 2] =  (VALUE) & 0xFF; \
+    } while (0)
+
+/*****************************************************************************/
+
+/* Emacs-Konfiguration
+;;; Local Variables: ***
+;;; c-basic-offset:4 ***
+;;; End: ***
+*/
--- a/libec/Makefile	Thu Jan 26 09:12:09 2006 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,41 +0,0 @@
-#------------------------------------------------------------------------------
-#
-#  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
-
-
--- a/libec/libec.c	Thu Jan 26 09:12:09 2006 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,57 +0,0 @@
-/******************************************************************************
- *
- *  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: ***
-*/
--- a/libec/libec.h	Thu Jan 26 09:12:09 2006 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,34 +0,0 @@
-/******************************************************************************
- *
- *  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/rt/Makefile	Thu Jan 26 09:12:09 2006 +0000
+++ b/rt/Makefile	Thu Jan 26 10:48:26 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 libec.o
+		libm.o
 
 EXTRA_CFLAGS := -I $(src)/rt_lib/msr-include -D_SIMULATION \
 		-I/usr/include -mhard-float
--- a/rt/libec.o_shipped	Thu Jan 26 09:12:09 2006 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-../libec/lib.a
\ No newline at end of file
--- a/rt/msr_module.c	Thu Jan 26 09:12:09 2006 +0000
+++ b/rt/msr_module.c	Thu Jan 26 10:48:26 2006 +0000
@@ -33,7 +33,7 @@
 
 // EtherCAT
 #include "../include/EtherCAT_rt.h"
-#include "../libec/libec.h"
+#include "../include/EtherCAT_si.h"
 
 // Defines/Makros
 #define TSC2US(T1, T2) ((T2 - T1) * 1000UL / cpu_khz)
@@ -86,22 +86,22 @@
     }
     else {
         // "Star Trek"-Effekte
-        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);
+        EC_WRITE_EL20XX(s_out1, 0, jiffies & 1);
+        EC_WRITE_EL20XX(s_out1, 1, (jiffies >> 1) & 1);
+        EC_WRITE_EL20XX(s_out1, 2, (jiffies >> 2) & 1);
+        EC_WRITE_EL20XX(s_out1, 3, (jiffies >> 3) & 1);
+        EC_WRITE_EL20XX(s_out2, 0, (jiffies >> 4) & 1);
+        EC_WRITE_EL20XX(s_out2, 1, (jiffies >> 3) & 1);
+        EC_WRITE_EL20XX(s_out2, 2, (jiffies >> 2) & 1);
+        EC_WRITE_EL20XX(s_out2, 3, (jiffies >> 6) & 1);
+        EC_WRITE_EL20XX(s_out3, 0, (jiffies >> 7) & 1);
+        EC_WRITE_EL20XX(s_out3, 1, (jiffies >> 2) & 1);
+        EC_WRITE_EL20XX(s_out3, 2, (jiffies >> 8) & 1);
 
         counter = MSR_ABTASTFREQUENZ / 4;
     }
 
-    LEC_write_EL20XX(s_out3, 3, LEC_read_EL31XX(s_in1, 0) < 0);
+    EC_WRITE_EL20XX(s_out3, 3, EC_READ_EL31XX(s_in1, 0) < 0);
 
     // Prozessdaten lesen und schreiben
     EtherCAT_rt_domain_xio(master, 0, 40);