Skip to content
Snippets Groups Projects
Commit 16ad5bfe authored by Florian Pose's avatar Florian Pose
Browse files

LibEC

parent 01ebcd55
No related branches found
No related tags found
No related merge requests found
......@@ -13,7 +13,7 @@ ifneq ($(KERNELRELEASE),)
#------------------------------------------------------------------------------
# Kbuild-Abschnitt
obj-m := master/ devices/ rt/ mini/
obj-m := master/ devices/ libec/ rt/ mini/
#------------------------------------------------------------------------------
......@@ -25,7 +25,7 @@ else
include ethercat.conf
modules:
$(MAKE) -C $(KERNELDIR) M=`pwd` modules
$(MAKE) -C $(KERNELDIR) M=`pwd`
clean:
$(MAKE) -C $(KERNELDIR) M=`pwd` clean
......
#------------------------------------------------------------------------------
#
# 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
/******************************************************************************
*
* 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: ***
*/
/******************************************************************************
*
* 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: ***
*/
......@@ -59,7 +59,7 @@ static void run(unsigned long data)
// 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;
......
......@@ -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
libm.o libec.o
EXTRA_CFLAGS := -I $(src)/rt_lib/msr-include -D_SIMULATION \
-I/usr/include -mhard-float
......
../libec/lib.a
\ No newline at end of file
......@@ -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_domain this_domain;
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 @@ static void msr_controller_run(void)
}
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 @@ int msr_globals_register(void)
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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment