EtherCAT-Slave-Interface als Makros implementiert.

This commit is contained in:
Florian Pose 2006-01-26 10:48:26 +00:00
parent a8ef8e2cbf
commit 1a78254c0d
8 changed files with 61 additions and 148 deletions

View File

@ -13,7 +13,7 @@ ifneq ($(KERNELRELEASE),)
#------------------------------------------------------------------------------
# Kbuild-Abschnitt
obj-m := master/ devices/ libec/ rt/ mini/
obj-m := master/ devices/ rt/ mini/
#------------------------------------------------------------------------------

46
include/EtherCAT_si.h Normal file
View File

@ -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: ***
*/

View File

@ -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

View File

@ -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: ***
*/

View File

@ -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: ***
*/

View File

@ -25,7 +25,7 @@ msr_modul-objs := msr_module.o \
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

View File

@ -1 +0,0 @@
../libec/lib.a

View File

@ -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 @@ static void msr_controller_run(void)
}
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);