Bugfix im Master, ec_master_reset() und laufendes Beispiel in rt.
This commit is contained in:
parent
5fb6877412
commit
5ceefe4379
|
|
@ -30,14 +30,16 @@ ec_slave_t *EtherCAT_rt_register_slave(ec_master_t *master,
|
|||
unsigned int slave_index,
|
||||
const char *vendor_name,
|
||||
const char *product_name,
|
||||
unsigned int domain);
|
||||
int domain);
|
||||
|
||||
int EtherCAT_rt_activate_slaves(ec_master_t *master);
|
||||
|
||||
int EtherCAT_rt_deactivate_slaves(ec_master_t *master);
|
||||
|
||||
int EtherCAT_rt_exchange_io(ec_master_t *master, unsigned int domain,
|
||||
unsigned int timeout_us);
|
||||
int EtherCAT_rt_domain_xio(ec_master_t *master, unsigned int domain,
|
||||
unsigned int timeout_us);
|
||||
|
||||
void EtherCAT_rt_debug_level(ec_master_t *master, int level);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
|
|
|||
|
|
@ -23,10 +23,10 @@
|
|||
|
||||
void ec_domain_init(ec_domain_t *dom)
|
||||
{
|
||||
dom->number = 0;
|
||||
dom->number = -1;
|
||||
dom->data_size = 0;
|
||||
dom->logical_offset = 0;
|
||||
dom->response_count = 0;
|
||||
dom->response_count = 0xFFFFFFFF;
|
||||
|
||||
memset(dom->data, 0x00, EC_FRAME_SIZE);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
typedef struct ec_domain
|
||||
{
|
||||
unsigned int number; /*<< Domänen-Identifikation */
|
||||
int number; /*<< Domänen-Identifikation */
|
||||
ec_command_t command; /**< Kommando zum Senden und Empfangen der
|
||||
Prozessdaten */
|
||||
unsigned char data[EC_FRAME_SIZE]; /**< Prozessdaten-Array */
|
||||
|
|
|
|||
|
|
@ -80,6 +80,35 @@ void ec_master_clear(ec_master_t *master)
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
/**
|
||||
Setzt den Master in den Ausgangszustand.
|
||||
|
||||
Bei einem "release" sollte immer diese Funktion aufgerufen werden,
|
||||
da sonst Slave-Liste, Domains, etc. weiter existieren.
|
||||
|
||||
@param master Zeiger auf den zurückzusetzenden Master
|
||||
*/
|
||||
|
||||
void ec_master_reset(ec_master_t *master)
|
||||
{
|
||||
if (master->bus_slaves) {
|
||||
kfree(master->bus_slaves);
|
||||
master->bus_slaves = NULL;
|
||||
}
|
||||
|
||||
master->bus_slaves_count = 0;
|
||||
master->command_index = 0;
|
||||
master->tx_data_length = 0;
|
||||
master->rx_data_length = 0;
|
||||
master->domain_count = 0;
|
||||
master->debug_level = 0;
|
||||
master->bus_time = 0;
|
||||
master->frames_lost = 0;
|
||||
master->t_lost_output = 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/**
|
||||
Öffnet das EtherCAT-Geraet des Masters.
|
||||
|
||||
|
|
@ -710,13 +739,18 @@ ec_slave_t *EtherCAT_rt_register_slave(ec_master_t *master,
|
|||
unsigned int bus_index,
|
||||
const char *vendor_name,
|
||||
const char *product_name,
|
||||
unsigned int domain)
|
||||
int domain)
|
||||
{
|
||||
ec_slave_t *slave;
|
||||
const ec_slave_type_t *type;
|
||||
ec_domain_t *dom;
|
||||
unsigned int j;
|
||||
|
||||
if (domain < 0) {
|
||||
printk(KERN_ERR "EtherCAT: Invalid domain: %i\n", domain);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (bus_index >= master->bus_slaves_count) {
|
||||
printk(KERN_ERR "EtherCAT: Illegal bus index! (%i / %i)\n", bus_index,
|
||||
master->bus_slaves_count);
|
||||
|
|
@ -734,7 +768,7 @@ ec_slave_t *EtherCAT_rt_register_slave(ec_master_t *master,
|
|||
|
||||
if (strcmp(vendor_name, type->vendor_name) ||
|
||||
strcmp(product_name, type->product_name)) {
|
||||
printk(KERN_ERR "Invalid Slave Type! Requested: \"%s %s\", present: \"%s"
|
||||
printk(KERN_ERR "Invalid Slave Type! Requested: \"%s %s\", found: \"%s"
|
||||
" %s\".\n", vendor_name, product_name, type->vendor_name,
|
||||
type->product_name);
|
||||
return NULL;
|
||||
|
|
@ -745,6 +779,7 @@ ec_slave_t *EtherCAT_rt_register_slave(ec_master_t *master,
|
|||
for (j = 0; j < master->domain_count; j++) {
|
||||
if (domain == master->domains[j].number) {
|
||||
dom = master->domains + j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -770,9 +805,11 @@ ec_slave_t *EtherCAT_rt_register_slave(ec_master_t *master,
|
|||
}
|
||||
|
||||
slave->process_data = dom->data + dom->data_size;
|
||||
dom->data_size += type->process_data_size;
|
||||
slave->logical_address = dom->data_size;
|
||||
slave->registered = 1;
|
||||
|
||||
dom->data_size += type->process_data_size;
|
||||
|
||||
return slave;
|
||||
}
|
||||
|
||||
|
|
@ -1029,8 +1066,8 @@ int EtherCAT_rt_deactivate_slaves(ec_master_t *master)
|
|||
@return 0 bei Erfolg, sonst < 0
|
||||
*/
|
||||
|
||||
int EtherCAT_rt_exchange_io(ec_master_t *master, unsigned int domain,
|
||||
unsigned int timeout_us)
|
||||
int EtherCAT_rt_domain_xio(ec_master_t *master, unsigned int domain,
|
||||
unsigned int timeout_us)
|
||||
{
|
||||
unsigned int i;
|
||||
ec_domain_t *dom;
|
||||
|
|
@ -1105,10 +1142,22 @@ int EtherCAT_rt_exchange_io(ec_master_t *master, unsigned int domain,
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
/**
|
||||
Setzt die Debug-Ebene des Masters.
|
||||
*/
|
||||
|
||||
void EtherCAT_rt_debug_level(ec_master_t *master, int level)
|
||||
{
|
||||
master->debug_level = level;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
EXPORT_SYMBOL(EtherCAT_rt_register_slave);
|
||||
EXPORT_SYMBOL(EtherCAT_rt_activate_slaves);
|
||||
EXPORT_SYMBOL(EtherCAT_rt_deactivate_slaves);
|
||||
EXPORT_SYMBOL(EtherCAT_rt_exchange_io);
|
||||
EXPORT_SYMBOL(EtherCAT_rt_domain_xio);
|
||||
EXPORT_SYMBOL(EtherCAT_rt_debug_level);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ struct ec_master
|
|||
// Master creation and deletion
|
||||
void ec_master_init(ec_master_t *);
|
||||
void ec_master_clear(ec_master_t *);
|
||||
void ec_master_reset(ec_master_t *);
|
||||
|
||||
// Registration of devices
|
||||
int ec_master_open(ec_master_t *);
|
||||
|
|
|
|||
|
|
@ -324,6 +324,8 @@ void EtherCAT_rt_release_master(ec_master_t *master)
|
|||
}
|
||||
|
||||
ec_master_close(master);
|
||||
ec_master_reset(master);
|
||||
|
||||
module_put(master->device.module);
|
||||
ec_masters_reserved[i] = 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ ifneq ($(KERNELRELEASE),)
|
|||
#------------------------------------------------------------------------------
|
||||
# Kbuild-Abschnitt
|
||||
|
||||
obj-m := msr_modul.o
|
||||
obj-m := msr_modul.o
|
||||
|
||||
msr_modul-objs := msr_module.o \
|
||||
msr_jitter.o \
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@
|
|||
|
||||
// EtherCAT
|
||||
#include "../include/EtherCAT_rt.h"
|
||||
#include "../eclib/eclib.h"
|
||||
|
||||
// Defines/Makros
|
||||
#define TSC2US(T1, T2) ((T2 - T1) * 1000UL / cpu_khz)
|
||||
|
|
@ -55,8 +56,7 @@ ec_master_t *master = NULL;
|
|||
static unsigned int ecat_bus_time = 0;
|
||||
static unsigned int ecat_timeouts = 0;
|
||||
|
||||
ec_slave_t *s_controller;
|
||||
ec_slave_t *s_analog_in;
|
||||
ec_slave_t *s_in1, *s_out1, *s_out2, *s_out3;
|
||||
|
||||
double value;
|
||||
int dig1;
|
||||
|
|
@ -65,12 +65,12 @@ int dig1;
|
|||
|
||||
static int register_slaves(void)
|
||||
{
|
||||
s_controller = EtherCAT_rt_register_slave(master, 0,
|
||||
"Beckhoff", "EK1100", 0);
|
||||
s_analog_in = EtherCAT_rt_register_slave(master, 1,
|
||||
"Beckhoff", "EL3102", 0);
|
||||
s_in1 = EtherCAT_rt_register_slave(master, 1, "Beckhoff", "EL3102", 0);
|
||||
s_out1 = EtherCAT_rt_register_slave(master, 8, "Beckhoff", "EL2004", 0);
|
||||
s_out2 = EtherCAT_rt_register_slave(master, 9, "Beckhoff", "EL2004", 0);
|
||||
s_out3 = EtherCAT_rt_register_slave(master, 10, "Beckhoff", "EL2004", 0);
|
||||
|
||||
return !s_controller || !s_analog_in;
|
||||
return !s_in1 || !s_out1 || !s_out2 || !s_out3;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
|
|
@ -81,30 +81,30 @@ static int register_slaves(void)
|
|||
|
||||
static void msr_controller_run(void)
|
||||
{
|
||||
static unsigned int debug_counter = 0;
|
||||
static unsigned int counter = 0;
|
||||
|
||||
// Prozessdaten lesen
|
||||
msr_jitter_run(MSR_ABTASTFREQUENZ);
|
||||
|
||||
#if 0
|
||||
if (debug_counter == 0) {
|
||||
master->debug_level = 2;
|
||||
if (counter) {
|
||||
counter--;
|
||||
}
|
||||
#endif
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
// Prozessdaten lesen und schreiben
|
||||
EtherCAT_rt_exchange_io(master, 0, 40);
|
||||
|
||||
#if 0
|
||||
if (debug_counter == 0) {
|
||||
master->debug_level = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
// value = EtherCAT_read_value(&ecat_slaves[1], 0);
|
||||
|
||||
debug_counter++;
|
||||
if (debug_counter >= MSR_ABTASTFREQUENZ * 5) debug_counter = 0;
|
||||
EtherCAT_rt_domain_xio(master, 0, 40);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
|
|
@ -126,8 +126,6 @@ void msr_run(unsigned irq)
|
|||
{
|
||||
static int counter = 0;
|
||||
|
||||
// Schreibe Kanal1 von Klemme X auf 1
|
||||
|
||||
timeval_add(&process_time, &process_time, &msr_time_increment);
|
||||
MSR_ADEOS_INTERRUPT_CODE(msr_controller_run(); msr_write_kanal_list(););
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue