Alle Änderungen aus den Branches no_rtai und no_int nach Trunk portiert.

This commit is contained in:
Florian Pose 2005-11-04 16:47:23 +00:00
parent d52281b1ba
commit f06757ec0d
12 changed files with 242 additions and 324 deletions

View File

@ -9,40 +9,22 @@
#
#################################################################
#KERNELDIR=/usr/src/linux
#KERNELDIR=/home/rich/linux-2.4.20.CX1100-rthal5
#KERNELDIR=./linux-2.4.20.CX1100-rthal5
MSR_DIR = /vol/projekte/msr_messen_steuern_regeln
EC_DIR = $(MSR_DIR)/ethercat
#IgH
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
#euler-nottuln
#KERNELDIR = $(EC_DIR)/linux-2.4.20.CX1100-rthal5-kdb
KERNELDIR = $(EC_DIR)/linux-2.4.20-kdb
#KERNELDIR = /usr/src/linux
#RTAIDIR = /usr/src/rtai
#patra
#KERNELDIR = /usr/src/linux-2.4.20.CX1100-rthal5
#RTAIDIR = /usr/src/rtai-24.1.13
#include $(KERNELDIR)/.config
ECAT_8139_OBJ = drv_8139too.o ec_device.o ec_master.o \
ec_slave.o ec_command.o ec_types.o
CFLAGS = -O2 -Wall -Wuninitialized -D__KERNEL__ -DMODULE \
-I$(KERNELDIR)/include -D_RTAI -I$(RTAIDIR)/include \
-I$(RTLIBDIR)/msr-include
ifdef CONFIG_SMP
CFLAGS += -D__SMP__ -DSMP
endif
CFLAGS = -O2 -Wall -Wuninitialized -D__KERNEL__ \
-DMODULE -I$(KERNELDIR)/include
#################################################################
all: .depend ecat_8139too.o
all: .depend Makefile ecat_8139too.o
ecat_8139too.o: $(ECAT_8139_OBJ)
$(LD) -r $(ECAT_8139_OBJ) -o $@
@ -55,7 +37,7 @@ doc docs:
#################################################################
.depend:
.depend depend dep:
$(CC) $(CFLAGS) -M *.c > .depend
ifeq (.depend,$(wildcard .depend))

View File

@ -3,7 +3,7 @@
* drv_8139too.c
*
* EtherCAT-Treiber für RTL8139-kompatible Netzwerkkarten.
*
*
* Autoren: Wilhelm Hagemeister, Florian Pose
*
* $Date$
@ -136,8 +136,6 @@
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
#include "ec_device.h"
#include <rtai.h>
#include <linux/delay.h>
#include "ec_dbg.h"
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
@ -193,6 +191,17 @@ static int multicast_filter_limit = 32;
/* bitmapped message enable number */
static int debug = -1;
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
// Device index for EtherCAT device selection
static int ec_device_index = -1;
//#define ECAT_DEBUG
EtherCAT_device_t rtl_ecat_dev;
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
/* Size of the in-memory receive ring. */
#define RX_BUF_LEN_IDX 2 /* 0==8K, 1==16K, 2==32K, 3==64K */
#define RX_BUF_LEN (8192 << RX_BUF_LEN_IDX)
@ -635,6 +644,13 @@ MODULE_PARM_DESC (max_interrupt_work, "8139too maximum events handled per interr
MODULE_PARM_DESC (media, "8139too: Bits 4+9: force full duplex, bit 5: 100Mbps");
MODULE_PARM_DESC (full_duplex, "8139too: Force full duplex for board(s) (1)");
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
MODULE_PARM(ec_device_index, "i");
MODULE_PARM_DESC(ec_device_index, "Index of the device reserved for EtherCAT.");
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
static int read_eeprom (void *ioaddr, int location, int addr_len);
static int rtl8139_open (struct net_device *dev);
static int mdio_read (struct net_device *dev, int phy_id, int location);
@ -647,7 +663,6 @@ static int rtl8139_start_xmit (struct sk_buff *skb,
struct net_device *dev);
static void rtl8139_interrupt (int irq, void *dev_instance,
struct pt_regs *regs);
static void rt_rtl8139_interrupt(void);
static int rtl8139_close (struct net_device *dev);
static int netdev_ioctl (struct net_device *dev, struct ifreq *rq, int cmd);
static struct net_device_stats *rtl8139_get_stats (struct net_device *dev);
@ -712,16 +727,6 @@ static void rtl8139_hw_start (struct net_device *dev);
#endif /* USE_IO_OPS */
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
#define ECATcard 1 // Diese Ethernetkarte wird für Ethercat verwendet
//#define ECAT_DEBUG
EtherCAT_device_t rtl_ecat_dev;
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
static const u16 rtl8139_intr_mask =
PCIErr | PCSTimeout | RxUnderrun | RxOverflow | RxFIFOOver |
TxErr | TxOK | RxErr | RxOK;
@ -999,7 +1004,7 @@ static int __devinit rtl8139_init_one (struct pci_dev *pdev,
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
if (board_idx == ECATcard)
if (board_idx == ec_device_index)
{
EC_DBG("EtherCAT registering board %d.\n", board_idx);
@ -1046,7 +1051,7 @@ static int __devinit rtl8139_init_one (struct pci_dev *pdev,
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
if (board_idx == ECATcard)
if (board_idx == ec_device_index)
{
rtl_ecat_dev.lock = &tp->lock;
}
@ -1378,19 +1383,12 @@ static int rtl8139_open (struct net_device *dev)
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
if (dev != rtl_ecat_dev.dev)
if (dev != rtl_ecat_dev.dev)
{
retval = request_irq(dev->irq, rtl8139_interrupt, SA_SHIRQ, dev->name, dev);
if (retval)
return retval;
}
else
{
//rt_disable_irq(dev->irq);
retval = rt_request_global_irq(dev->irq,rt_rtl8139_interrupt);
//rt_enable_irq(dev->irq);
}
if (retval)
return retval;
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
@ -1406,11 +1404,7 @@ static int rtl8139_open (struct net_device *dev)
{
free_irq(dev->irq, dev);
}
else
{
rt_free_global_irq (dev->irq);
}
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
if (tp->tx_bufs)
@ -1419,7 +1413,7 @@ static int rtl8139_open (struct net_device *dev)
if (tp->rx_ring)
pci_free_consistent(tp->pci_dev, RX_BUF_TOT_LEN,
tp->rx_ring, tp->rx_ring_dma);
return -ENOMEM;
}
@ -1449,12 +1443,6 @@ static int rtl8139_open (struct net_device *dev)
EC_DBG (KERN_WARNING "%s: unable to start kernel thread\n",
dev->name);
}
#if 0
else
{
rt_enable_irq(dev->irq);
}
#endif
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
@ -1470,6 +1458,7 @@ static void rtl_check_media (struct net_device *dev)
if (tp->phys[0] >= 0) {
u16 mii_lpa = mdio_read(dev, tp->phys[0], MII_LPA);
if (mii_lpa == 0xffff)
; /* Not there */
else if ((mii_lpa & LPA_100FULL) == LPA_100FULL
@ -1551,14 +1540,20 @@ static void rtl8139_hw_start (struct net_device *dev)
if ((!(tmp & CmdRxEnb)) || (!(tmp & CmdTxEnb)))
RTL_W8 (ChipCmd, CmdRxEnb | CmdTxEnb);
/* Enable all known interrupts by setting the interrupt mask. */
RTL_W16 (IntrMask, rtl8139_intr_mask);
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
if (dev != rtl_ecat_dev.dev) netif_start_queue (dev);
if (dev != rtl_ecat_dev.dev)
{
/* Enable all known interrupts by setting the interrupt mask. */
RTL_W16 (IntrMask, rtl8139_intr_mask);
netif_start_queue (dev);
}
else
{
RTL_W16 (IntrMask, 0x0000);
}
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
EC_DBG(KERN_DEBUG "%s: rtl8139_hw_start finished.\n", dev->name);
}
@ -1829,23 +1824,11 @@ static void rtl8139_tx_timeout (struct net_device *dev)
i == (int) (tp->dirty_tx % NUM_TX_DESC) ?
" (queue head)" : "");
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
/* Stop a shared interrupt from scavenging while we are. */
if (dev == rtl_ecat_dev.dev)
{
flags = rt_spin_lock_irqsave (&tp->lock);
rtl8139_tx_clear (tp);
rt_spin_unlock_irqrestore (&tp->lock,flags);
}
else {
spin_lock_irqsave (&tp->lock, flags);
rtl8139_tx_clear (tp);
spin_unlock_irqrestore (&tp->lock, flags);
}
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
spin_lock_irqsave (&tp->lock, flags);
rtl8139_tx_clear (tp);
spin_unlock_irqrestore (&tp->lock, flags);
/* ...and finally, reset everything */
rtl8139_hw_start (dev);
@ -1876,7 +1859,7 @@ static int rtl8139_start_xmit (struct sk_buff *skb, struct net_device *dev)
skb_copy_and_csum_dev(skb, tp->tx_buf[entry]);
// Socket buffer nicht löschen, wenn vom EtherCAT-device
if (dev != rtl_ecat_dev.dev) dev_kfree_skb(skb);
if (dev != rtl_ecat_dev.dev) dev_kfree_skb(skb);
}
else
{
@ -1885,17 +1868,10 @@ static int rtl8139_start_xmit (struct sk_buff *skb, struct net_device *dev)
return 0;
}
/* Note: the chip doesn't have auto-pad! */
if (dev == rtl_ecat_dev.dev)
{
rt_spin_lock_irq(&tp->lock);
}
else
{
spin_lock_irq(&tp->lock);
}
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
/* Note: the chip doesn't have auto-pad! */
spin_lock_irq(&tp->lock);
RTL_W32_F (TxStatus0 + (entry * sizeof (u32)),
tp->tx_flag | max(len, (unsigned int)ETH_ZLEN));
@ -1913,17 +1889,10 @@ static int rtl8139_start_xmit (struct sk_buff *skb, struct net_device *dev)
netif_stop_queue (dev);
}
if (dev == rtl_ecat_dev.dev)
{
rt_spin_unlock_irq(&tp->lock);
}
else
{
spin_unlock_irq(&tp->lock);
}
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
spin_unlock_irq(&tp->lock);
DPRINTK ("%s: Queued Tx packet size %u to slot %d.\n",
dev->name, len, entry);
@ -1981,12 +1950,12 @@ static void rtl8139_tx_interrupt (struct net_device *dev,
tp->stats.tx_window_errors++;
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
if (dev == rtl_ecat_dev.dev)
{
rtl_ecat_dev.state = ECAT_DS_ERROR;
}
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
} else {
@ -2059,12 +2028,12 @@ static void rtl8139_rx_err (u32 rx_status, struct net_device *dev,
}
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
if (dev == rtl_ecat_dev.dev)
{
rtl_ecat_dev.state = ECAT_DS_ERROR;
}
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
#ifndef CONFIG_8139_OLD_RX_RESET
@ -2170,7 +2139,7 @@ static void rtl8139_rx_interrupt (struct net_device *dev,
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
#if RTL8139_DEBUG > 2
#if RTL8139_DEBUG > 2
if (dev == rtl_ecat_dev.dev)
{
int i;
@ -2259,7 +2228,7 @@ static void rtl8139_rx_interrupt (struct net_device *dev,
tp->stats.rx_packets++;
}
}
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
cur_rx = (cur_rx + rx_size + 4 + 3) & ~3;
@ -2330,8 +2299,6 @@ static void rtl8139_weird_interrupt (struct net_device *dev,
}
}
/* The interrupt handler does all of the Rx thread work and cleans up
after the Tx thread. */
static void rtl8139_interrupt (int irq, void *dev_instance,
@ -2344,16 +2311,15 @@ static void rtl8139_interrupt (int irq, void *dev_instance,
int ackstat, status;
int link_changed = 0; /* avoid bogus "uninit" warning */
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
if (dev == rtl_ecat_dev.dev)
{
rt_spin_lock(&tp->lock);
rtl_ecat_dev.intr_cnt++;
}
else
{
spin_lock (&tp->lock);
spin_lock(&tp->lock);
}
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
@ -2424,13 +2390,9 @@ static void rtl8139_interrupt (int irq, void *dev_instance,
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
if (dev == rtl_ecat_dev.dev)
if (dev != rtl_ecat_dev.dev)
{
rt_spin_unlock(&tp->lock);
}
else
{
spin_unlock(&tp->lock);
spin_unlock (&tp->lock);
}
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
@ -2439,15 +2401,6 @@ static void rtl8139_interrupt (int irq, void *dev_instance,
dev->name, RTL_R16 (IntrStatus));
}
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
static void rt_rtl8139_interrupt(void)
{
rtl8139_interrupt(rtl_ecat_dev.dev->irq, rtl_ecat_dev.dev, NULL);
}
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
static int rtl8139_close (struct net_device *dev)
{
struct rtl8139_private *tp = dev->priv;
@ -2472,26 +2425,13 @@ static int rtl8139_close (struct net_device *dev)
wait_for_completion (&tp->thr_exited);
}
}
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
DPRINTK ("%s: Shutting down ethercard, status was 0x%4.4x.\n",
dev->name, RTL_R16 (IntrStatus));
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
//mdelay(1);
if (dev == rtl_ecat_dev.dev)
{
flags = rt_spin_lock_irqsave(&tp->lock);
}
else
{
spin_lock_irqsave(&tp->lock, flags);
}
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
spin_lock_irqsave(&tp->lock, flags);
/* Stop the chip's Tx and Rx DMA processes. */
RTL_W8 (ChipCmd, 0);
@ -2503,33 +2443,15 @@ static int rtl8139_close (struct net_device *dev)
tp->stats.rx_missed_errors += RTL_R32 (RxMissed);
RTL_W32 (RxMissed, 0);
spin_unlock_irqrestore (&tp->lock, flags);
synchronize_irq ();
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
if (dev == rtl_ecat_dev.dev)
{
rt_spin_unlock_irqrestore (&tp->lock, flags);
synchronize_irq ();
}
else
{
spin_unlock_irqrestore (&tp->lock, flags);
synchronize_irq ();
}
EC_DBG ("rtl8139: freeing irq");
//mdelay(1);
if (dev != rtl_ecat_dev.dev)
{
free_irq (dev->irq, dev);
}
else
{
rt_disable_irq(dev->irq);
rt_free_global_irq (dev->irq);
rt_enable_irq(dev->irq);
}
free_irq(dev->irq, dev);
}
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
@ -2744,7 +2666,7 @@ static int netdev_ethtool_ioctl (struct net_device *dev, void *useraddr)
rc = -EFAULT;
goto err_out_gregs;
}
if (regs.len > regs_len)
regs.len = regs_len;
if (regs.len < regs_len) {
@ -2868,22 +2790,12 @@ static struct net_device_stats *rtl8139_get_stats (struct net_device *dev)
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
if (dev == rtl_ecat_dev.dev)
if (dev == rtl_ecat_dev.dev || netif_running(dev))
{
flags = rt_spin_lock_irqsave (&tp->lock);
spin_lock_irqsave (&tp->lock, flags);
tp->stats.rx_missed_errors += RTL_R32 (RxMissed);
RTL_W32 (RxMissed, 0);
rt_spin_unlock_irqrestore (&tp->lock, flags);
}
else
{
if (netif_running(dev))
{
spin_lock_irqsave (&tp->lock, flags);
tp->stats.rx_missed_errors += RTL_R32 (RxMissed);
RTL_W32 (RxMissed, 0);
spin_unlock_irqrestore (&tp->lock, flags);
}
spin_unlock_irqrestore (&tp->lock, flags);
}
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
@ -2947,22 +2859,9 @@ static void rtl8139_set_rx_mode (struct net_device *dev)
unsigned long flags;
struct rtl8139_private *tp = dev->priv;
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
if (dev == rtl_ecat_dev.dev)
{
flags = rt_spin_lock_irqsave (&tp->lock);
__set_rx_mode(dev);
rt_spin_unlock_irqrestore (&tp->lock, flags);
}
else
{
spin_lock_irqsave (&tp->lock, flags);
__set_rx_mode(dev);
spin_unlock_irqrestore (&tp->lock, flags);
}
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
spin_lock_irqsave (&tp->lock, flags);
__set_rx_mode(dev);
spin_unlock_irqrestore (&tp->lock, flags);
}
#ifdef CONFIG_PM

View File

@ -6,16 +6,15 @@
#define ECMASTER_DEBUG
#include "../rs232dbg/rs232dbg.h"
//#include "../rs232dbg/rs232dbg.h"
#ifdef ECMASTER_DEBUG
/* note: prints function name for you */
//# define EC_DBG(fmt, args...) SDBG_print(fmt, ## args)
#define EC_DBG(fmt, args...) SDBG_print("%s: " fmt, __FUNCTION__ , ## args)
//#define EC_DBG(fmt, args...) printk(KERN_INFO fmt, ## args)
//#define EC_DBG(fmt, args...) SDBG_print("%s: " fmt, __FUNCTION__ , ## args)
#define EC_DBG(fmt, args...) printk(fmt, ## args)
#else
#define EC_DBG(fmt, args...)
#endif

View File

@ -12,7 +12,6 @@
#include <linux/skbuff.h>
#include <linux/if_ether.h>
#include <linux/netdevice.h>
#include <rtai.h>
#include <linux/delay.h>
#include "ec_device.h"
@ -22,7 +21,7 @@
/**
EtherCAT-Geräte-Konstuktor.
Initialisiert ein EtherCAT-Gerät, indem es die Variablen
in der Struktur auf die Default-Werte setzt.
@ -48,7 +47,7 @@ void EtherCAT_device_init(EtherCAT_device_t *ecd)
/**
EtherCAT-Geräte-Destuktor.
Gibt den dynamisch allozierten Speicher des
EtherCAT-Gerätes (die beiden Socket-Buffer) wieder frei.
@ -76,7 +75,7 @@ void EtherCAT_device_clear(EtherCAT_device_t *ecd)
/**
Weist einem EtherCAT-Gerät das entsprechende net_device zu.
Prüft das net_device, allokiert Socket-Buffer in Sende- und
Empfangsrichtung und weist dem EtherCAT-Gerät und den
Socket-Buffern das net_device zu.
@ -279,6 +278,26 @@ int EtherCAT_device_receive(EtherCAT_device_t *ecd,
/***************************************************************/
/**
Ruft manuell die Interrupt-Routine der Netzwerkkarte auf.
@param ecd EtherCAT-Gerät
@return Anzahl der kopierten Bytes bei Erfolg, sonst < 0
*/
void EtherCAT_device_call_isr(EtherCAT_device_t *ecd)
{
EC_DBG(KERN_DEBUG "EtherCAT: Calling ISR...\n");
// Manuell die ISR aufrufen
rtl8139_interrupt(0, ecd->dev, NULL);
EC_DBG(KERN_DEBUG "EtherCAT: ISR finished.\n");
}
/***************************************************************/
/**
Gibt alle Informationen über das Device-Objekt aus.

View File

@ -78,6 +78,7 @@ int EtherCAT_device_close(EtherCAT_device_t *);
int EtherCAT_device_send(EtherCAT_device_t *, unsigned char *, unsigned int);
int EtherCAT_device_receive(EtherCAT_device_t *, unsigned char *, unsigned int);
void EtherCAT_device_call_isr(EtherCAT_device_t *);
void EtherCAT_device_debug(EtherCAT_device_t *);

View File

@ -18,9 +18,6 @@
#include "ec_master.h"
#include "ec_dbg.h"
// FIXME: Klappt nur solange, wie es nur einen Master gibt! fp
static int ASYNC = 0;
/***************************************************************/
/**
@ -159,13 +156,12 @@ int EtherCAT_check_slaves(EtherCAT_master_t *master,
}
else
{
EC_DBG("EtherCAT: Slave count on bus: %i. Found: %i.\n",
cmd->working_counter, slave_count);
EC_DBG("EtherCAT: Found all %i slaves.\n", slave_count);
}
EtherCAT_remove_command(master, cmd);
// For every slave in the list
// For every slave in the list
for (i = 0; i < slave_count; i++)
{
cur = &slaves[i];
@ -239,21 +235,28 @@ int EtherCAT_check_slaves(EtherCAT_master_t *master,
if (EtherCAT_read_slave_information(master, cur->station_address,
0x0008, &cur->vendor_id) != 0)
{
EC_DBG(KERN_ERR "EtherCAT: Could not read SII!\n");
EC_DBG(KERN_ERR "EtherCAT: Could not read SII vendor id!\n");
return -1;
}
if (EtherCAT_read_slave_information(master, cur->station_address,
0x000A, &cur->product_code) != 0)
{
EC_DBG(KERN_ERR "EtherCAT: Could not read SII!\n");
EC_DBG(KERN_ERR "EtherCAT: Could not read SII product code!\n");
return -1;
}
if (EtherCAT_read_slave_information(master, cur->station_address,
0x000E, &cur->revision_number) != 0)
{
EC_DBG(KERN_ERR "EtherCAT: Could not read SII!\n");
EC_DBG(KERN_ERR "EtherCAT: Could not read SII revision number!\n");
return -1;
}
if (EtherCAT_read_slave_information(master, cur->station_address,
0x0012, &cur->serial_number) != 0)
{
EC_DBG(KERN_ERR "EtherCAT: Could not read SII serial number!\n");
return -1;
}
@ -284,7 +287,8 @@ int EtherCAT_check_slaves(EtherCAT_master_t *master,
if (!found)
{
EC_DBG(KERN_ERR "EtherCAT: Unknown slave device (vendor %X, code %X) at position %i.\n",
EC_DBG(KERN_ERR "EtherCAT: Unknown slave device"
" (vendor %X, code %X) at position %i.\n",
i, cur->vendor_id, cur->product_code);
return -1;
}
@ -312,8 +316,9 @@ int EtherCAT_check_slaves(EtherCAT_master_t *master,
slaves[i].process_data = master->process_data + pos;
slaves[i].logical_address0 = pos;
EC_DBG(KERN_DEBUG "EtherCAT: Slave %i - \"%s %s\" - Logical Address 0x%08X\n",
i, slaves[i].desc->vendor_name, slaves[i].desc->product_name, pos);
EC_DBG(KERN_DEBUG "EtherCAT: Slave %i - Address 0x%X, \"%s %s\", s/n %u\n",
i, pos, slaves[i].desc->vendor_name, slaves[i].desc->product_name,
slaves[i].serial_number);
pos += slaves[i].desc->data_length;
}
@ -451,7 +456,7 @@ int EtherCAT_read_slave_information(EtherCAT_master_t *master,
entsprechenden Antworten.
@param master EtherCAT-Master
@return 0 bei Erfolg, sonst < 0
*/
@ -459,28 +464,30 @@ int EtherCAT_async_send_receive(EtherCAT_master_t *master)
{
unsigned int wait_cycles;
int i;
// Send all commands
for (i = 0; i < ECAT_NUM_RETRIES; i++)
{
ASYNC = 1;
if (EtherCAT_send(master) < 0)
{
return -1;
}
ASYNC = 0;
// Wait until something is received or an error has occurred
wait_cycles = 10;
EtherCAT_device_call_isr(master->dev);
while (master->dev->state == ECAT_DS_SENT && wait_cycles)
{
udelay(1000);
wait_cycles--;
EtherCAT_device_call_isr(master->dev);
}
//EC_DBG("Master async send: tries %d",tries_left);
if (!wait_cycles)
{
EC_DBG(KERN_ERR "EtherCAT: Asynchronous receive timeout.\n");
@ -492,7 +499,7 @@ int EtherCAT_async_send_receive(EtherCAT_master_t *master)
EC_DBG(KERN_ERR "EtherCAT: Asyncronous send error. State %i\n", master->dev->state);
continue;
}
// Receive all commands
if (EtherCAT_receive(master) < 0)
{
@ -518,7 +525,7 @@ int EtherCAT_async_send_receive(EtherCAT_master_t *master)
Danach wird die Sendefunktion des EtherCAT-Gerätes aufgerufen.
@param master EtherCAT-Master
@return 0 bei Erfolg, sonst < 0
*/
@ -614,7 +621,7 @@ int EtherCAT_send(EtherCAT_master_t *master)
// Pad with zeros
while (pos < 46) master->tx_data[pos++] = 0x00;
master->tx_data_length = framelength;
#ifdef DEBUG_SEND_RECEIVE
@ -635,7 +642,7 @@ int EtherCAT_send(EtherCAT_master_t *master)
{
EC_DBG(KERN_DEBUG "device send...\n");
}
// Send frame
if (EtherCAT_device_send(master->dev, master->tx_data, framelength) != 0)
{
@ -644,7 +651,7 @@ int EtherCAT_send(EtherCAT_master_t *master)
EC_DBG(KERN_DEBUG);
for (i = 0; i < framelength; i++)
{
EC_DBG("%02X ", master->tx_data[i]);
EC_DBG("%02X ", master->tx_data[i]);
if ((i + 1) % 16 == 0) EC_DBG("\n" KERN_DEBUG);
}
EC_DBG("\n");
@ -669,7 +676,7 @@ int EtherCAT_send(EtherCAT_master_t *master)
allen gesendeten Kommandos ihre Antworten zu.
@param master EtherCAT-Master
@return 0 bei Erfolg, sonst < 0
*/

View File

@ -37,9 +37,10 @@ void EtherCAT_slave_init(EtherCAT_slave_t *slave)
slave->vendor_id = 0;
slave->product_code = 0;
slave->revision_number = 0;
slave->serial_number = 0;
slave->desc = 0;
slave->logical_address0 = 0;
slave->current_state = ECAT_STATE_UNKNOWN;

View File

@ -18,6 +18,9 @@
/**
EtherCAT-Slave
Achtung: Bei Änderungen dieser Struktur immer das Define
ECAT_INIT_SLAVE anpassen!
*/
typedef struct
@ -35,6 +38,7 @@ typedef struct
unsigned int vendor_id; /**< Identifikationsnummer des Herstellers */
unsigned int product_code; /**< Herstellerspezifischer Produktcode */
unsigned int revision_number; /**< Revisionsnummer */
unsigned int serial_number; /**< Seriennummer der Klemme */
const EtherCAT_slave_desc_t *desc; /**< Zeiger auf die Beschreibung
des Slave-Typs */
@ -49,7 +53,7 @@ typedef struct
}
EtherCAT_slave_t;
#define ECAT_INIT_SLAVE(TYPE) {0, 0, 0, 0, 0, 0, 0, 0, \
#define ECAT_INIT_SLAVE(TYPE) {0, 0, 0, 0, 0, 0, 0, 0, 0, \
TYPE, 0, ECAT_STATE_UNKNOWN, \
ECAT_STATE_UNKNOWN, NULL}

View File

@ -8,13 +8,18 @@
#
#----------------------------------------------------------------
MSRDIR = /vol/projekte/msr_messen_steuern_regeln
KERNELDIR = $(MSRDIR)/linux/kernel/2.4.20/include/linux-2.4.20.CX1100-rthal5
CFLAGS = -O2 -Wall -Wuninitialized -D__KERNEL__ -DMODULE -I$(KERNELDIR)/include
EC_DIR = /vol/projekte/msr_messen_steuern_regeln/ethercat
#KERNELDIR = $(EC_DIR)/linux-2.4.20.CX1100-rthal5-kdb
KERNELDIR = $(EC_DIR)/linux-2.4.20-kdb
#KERNELDIR = /usr/src/linux
CFLAGS = -O2 -Wall -Wuninitialized -D__KERNEL__ \
-DMODULE -I$(KERNELDIR)/include
MODULE = ec_mini_mod.o
SRC = ec_mini.c
SRC = ec_mini.c
OBJ = $(SRC:.c=.o)
#----------------------------------------------------------------

View File

@ -12,19 +12,32 @@
#include <linux/tqueue.h>
#include <linux/slab.h>
#include <linux/delay.h>
#include <linux/completion.h>
#include "../drivers/ec_master.h"
#include "../drivers/ec_device.h"
#include "../drivers/ec_types.h"
#include "../drivers/ec_dbg.h"
/******************************************************************************/
#define ECAT_OPEN
#define ECAT_MASTER
#define ECAT_SLAVES
#define ECAT_CYCLIC_DATA
/******************************************************************************/
extern EtherCAT_device_t rtl_ecat_dev;
//static EtherCAT_master_t *ecat_master = NULL;
#ifdef ECAT_MASTER
static EtherCAT_master_t *ecat_master = NULL;
#endif
#if 0
#ifdef ECAT_SLAVES
static EtherCAT_slave_t ecat_slaves[] =
{
#if 0
// Block 1
ECAT_INIT_SLAVE(Beckhoff_EK1100),
ECAT_INIT_SLAVE(Beckhoff_EL4102),
@ -44,6 +57,7 @@ static EtherCAT_slave_t ecat_slaves[] =
ECAT_INIT_SLAVE(Beckhoff_EL2004),
ECAT_INIT_SLAVE(Beckhoff_EL2004),
ECAT_INIT_SLAVE(Beckhoff_EL2004),
#endif
// Block 2
ECAT_INIT_SLAVE(Beckhoff_EK1100),
@ -72,8 +86,13 @@ static EtherCAT_slave_t ecat_slaves[] =
#define ECAT_SLAVES_COUNT (sizeof(ecat_slaves) / sizeof(EtherCAT_slave_t))
#endif
#ifdef ECAT_CYCLIC_DATA
double value;
int dig1;
struct tq_struct cyclic_task;
struct clientdata {task_queue *queue;} cyclic_data;
static DECLARE_COMPLETION(on_exit);
#endif
/******************************************************************************
*
@ -81,7 +100,7 @@ int dig1;
*
*****************************************************************************/
#if 0
#ifdef ECAT_CYCLIC_DATA
static int next2004(int *wrap)
{
static int i = 0;
@ -109,20 +128,23 @@ static int next2004(int *wrap)
/******************************************************************************
*
* Function: msr_controller
* Function: run
*
* Beschreibung: Zyklischer Prozess
*
*****************************************************************************/
#if 0
void msr_controller()
#ifdef ECAT_CYCLIC_DATA
void run(void *ptr)
{
struct clientdata *data = (struct clientdata *) ptr;
#if 1
static int ms = 0;
static int cnt = 0;
static unsigned long int k = 0;
static int firstrun = 1;
static int klemme = 12;
static int kanal = 0;
static int up_down = 0;
@ -133,10 +155,10 @@ void msr_controller()
#if 0
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))
/ (current_cpu_data.loops_per_jiffy / 10);
/ (current_cpu_data.loops_per_jiffy / 10);
rx_intr = ecat_master->dev->rx_intr_cnt;
tx_intr = ecat_master->dev->tx_intr_cnt;
total_intr = ecat_master->dev->intr_cnt;
@ -145,6 +167,8 @@ void msr_controller()
// Prozessdaten lesen
if (!firstrun)
{
klemme = next2004(&wrap);
EtherCAT_read_process_data(ecat_master);
// Daten lesen und skalieren
@ -152,11 +176,13 @@ void msr_controller()
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)
{
@ -168,7 +194,7 @@ void msr_controller()
klemme = next2004(&wrap);
if (wrap == 1)
{
{
if (up_down == 1) up_down = 0;
else up_down = 1;
}
@ -177,15 +203,29 @@ void msr_controller()
if (klemme >= 0)
EtherCAT_write_value(&ecat_master->slaves[klemme], kanal,up_down);
//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);
#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
// Prozessdaten schreiben
rdtscl(k);
EtherCAT_write_process_data(ecat_master);
firstrun = 0;
#endif
if (data->queue)
{
// Neu in die Taskqueue eintragen
queue_task(&cyclic_task, data->queue);
}
else
{
//last_queue_finished = 0;
complete(&on_exit);
}
}
#endif
@ -195,10 +235,8 @@ void msr_controller()
*
******************************************************************************/
//#define ECAT_OPEN
int init()
{
{
#ifdef ECAT_OPEN
int rv = -1;
#endif
@ -219,14 +257,13 @@ int init()
}
if (!rtl_ecat_dev.dev) // Es gibt kein EtherCAT-Device
{
{
EC_DBG(KERN_ERR "msr_modul: No EtherCAT device!\n");
goto out_close;
}
#endif
#if 0
// EtherCAT-Master und Slaves initialisieren
#ifdef ECAT_MASTER
EC_DBG("Initialising EtherCAT master\n");
if ((ecat_master = (EtherCAT_master_t *) kmalloc(sizeof(EtherCAT_master_t), GFP_KERNEL)) == 0)
@ -240,9 +277,11 @@ int init()
EC_DBG(KERN_ERR "EtherCAT could not init master!\n");
goto out_master;
}
ecat_master->debug_level = 1;
#endif
#if 0
#ifdef ECAT_SLAVES
EC_DBG("Checking EtherCAT slaves.\n");
if (EtherCAT_check_slaves(ecat_master, ecat_slaves, ECAT_SLAVES_COUNT) != 0)
@ -258,12 +297,15 @@ int init()
EC_DBG(KERN_ERR "EtherCAT: Could not activate slaves!\n");
goto out_masterclear;
}
#endif
// Zyklischen Aufruf starten
#ifdef ECAT_CYCLIC_DATA
EC_DBG("Starting cyclic sample thread.\n");
EtherCAT_write_process_data(ecat_master);
cyclic_task.routine = run;
cyclic_task.data = (void *) &cyclic_data;
cyclic_data.queue = &tq_timer;
queue_task(&cyclic_task, &tq_timer);
EC_DBG("Initialised sample thread.\n");
#endif
@ -272,13 +314,13 @@ int init()
return 0;
#if 0
#ifdef ECAT_SLAVES
out_masterclear:
EC_DBG(KERN_INFO "Clearing EtherCAT master.\n");
EtherCAT_master_clear(ecat_master);
#endif
#if 0
#ifdef ECAT_MASTER
out_master:
EC_DBG(KERN_INFO "Freeing EtherCAT master.\n");
kfree(ecat_master);
@ -304,14 +346,18 @@ void cleanup()
{
EC_DBG(KERN_INFO "=== Stopping Minimal EtherCAT environment... ===\n");
// Noch einmal lesen
//EC_DBG(KERN_INFO "Reading process data.\n");
//EtherCAT_read_process_data(ecat_master);
#if 0
#ifdef ECAT_MASTER
if (ecat_master)
{
#if 0
//ecat_master->debug_level = 1;
#ifdef ECAT_CYCLIC_DATA
cyclic_data.queue = NULL;
wait_for_completion(&on_exit);
EtherCAT_clear_process_data(ecat_master);
#endif
#ifdef ECAT_SLAVES
EC_DBG(KERN_INFO "Deactivating slaves.\n");
EtherCAT_deactivate_all_slaves(ecat_master);
#endif

View File

@ -1,47 +1,22 @@
#IgH
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
#euler-nottuln
#KERNELDIR = /usr/src/linux
#RTAIDIR = /usr/src/rtai
MSRDIR = /vol/projekte/msr_messen_steuern_regeln
ECATDIR = $(MSRDIR)/ethercat
#patra
#KERNELDIR = /usr/src/linux-2.4.20.CX1100-rthal5
#RTAIDIR = /usr/src/rtai-24.1.13
KERNELDIR = $(ECATDIR)/linux-2.4.20.CX1100-rthal5-kdb
RTAIDIR = $(MSRDIR)/linux/kernel/2.4.20/include/rtai-24.1.13
RTLIBDIR=rt_lib
#include $(KERNELDIR)/.config
#CFLAGS = -DRTAI -D__KERNEL__ -DMODULE -I$(KERNELDIR)/include -I$(RTAIDIR)/include -I$(RTLIBDIR)/msr-include \
# -Wall -Wstrict-prototypes -Wno-trigraphs -O2 -fno-strict-aliasing -fno-common -fomit-frame-pointer \
# -pipe -mpreferred-stack-boundary=2 -march=i686 -nostdinc -iwithprefix include
CFLAGS = -O2 -Wall -Wuninitialized -D__KERNEL__ -DMODULE -I$(KERNELDIR)/include -D_RTAI -I$(RTAIDIR)/include -I$(RTLIBDIR)/msr-include
#CFLAGS += -DSIMULATION
#LDFLAGS =
#VPATH = $(RTLIBDIR)/
CFLAGS = -O2 -Wall -Wuninitialized -D__KERNEL__ -DMODULE \
-I$(KERNELDIR)/include -D_RTAI -I$(RTAIDIR)/include -I$(RTLIBDIR)/msr-include
TARGET = sdbg
MODULE = $(TARGET).o
SRC = rs232dbg.c aip_com.c
#Suchpfad für die Dateien aus dem RT-Lib-Verzeichnis
VPATH = $(RTLIBDIR)/msr-core:$(RTLIBDIR)/msr-control:$(RTLIBDIR)/msr-math:$(RTLIBDIR)/msr-misc:$(RTLIBDIR)/msr-utils
#Datei aus dem RT-Libverzeichnis für dies Projekt
RTSRC =
ALLSRC = $(SRC) $(RTSRC)
ALLSRC = $(SRC)
OBJS = $(ALLSRC:.c=.o)
all: .depend $(TARGET).o Makefile
$(TARGET).o: $(SRC:.c=.o) $(RTSRC:.c=.o)
@ -57,26 +32,6 @@ clean:
depend .depend dep:
$(CC) $(CFLAGS) -M *.c > $@
ifeq (.depend,$(wildcard .depend))
include .depend
endif
#all: msr_module.o
#
#msr_io.o: msr_io.c msr_io.h
# $(CC) $(CFLAGS) -c -o $@ $<
#
#msr_module.o: msr_io.o
# $(LD) -r -o $@ $^
#
# $(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
#clean:
# rm -f *.o *~ core

View File

@ -810,7 +810,7 @@ int init_aip_com(void)
//void cleanup_module(void) Hm, IgH
void cleanup_aip_com(void)
{
int i;
unsigned int i;
for (i = 0; i < RT_COM_CNT; i++) {
struct rt_com_struct *p = &(rt_com_table[i]);
if (0 < p->used) {