mirror of
https://gitlab.com/etherlab.org/ethercat.git
synced 2026-09-22 01:53:54 +08:00
Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
This commit is contained in:
+3
-2
@@ -36,8 +36,9 @@ include $(src)/../config.kbuild
|
||||
obj-m := ec_master.o
|
||||
|
||||
ec_master-objs := module.o master.o device.o slave.o datagram.o \
|
||||
domain.o mailbox.o canopen.o ethernet.o \
|
||||
fsm_sii.o fsm_change.o fsm_coe.o fsm.o xmldev.o
|
||||
domain.o mailbox.o canopen.o ethernet.o \
|
||||
fsm_sii.o fsm_change.o fsm_coe.o fsm_slave.o fsm_master.o \
|
||||
xmldev.o
|
||||
|
||||
ifeq ($(EC_DBG_IF),1)
|
||||
ec_master-objs += debug.o
|
||||
|
||||
+2
-1
@@ -43,7 +43,8 @@ EXTRA_DIST = \
|
||||
fsm_sii.c fsm_sii.h \
|
||||
fsm_change.c fsm_change.h \
|
||||
fsm_coe.c fsm_coe.h \
|
||||
fsm.c fsm.h \
|
||||
fsm_slave.c fsm_slave.h \
|
||||
fsm_master.c fsm_master.h \
|
||||
globals.h \
|
||||
mailbox.c mailbox.h \
|
||||
master.c master.h \
|
||||
|
||||
-1831
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,91 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 2006 Florian Pose, Ingenieurgemeinschaft IgH
|
||||
*
|
||||
* This file is part of the IgH EtherCAT Master.
|
||||
*
|
||||
* The IgH EtherCAT Master is free software; you can redistribute it
|
||||
* and/or modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* The IgH EtherCAT Master is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with the IgH EtherCAT Master; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* The right to use EtherCAT Technology is granted and comes free of
|
||||
* charge under condition of compatibility of product made by
|
||||
* Licensee. People intending to distribute/sell products based on the
|
||||
* code, have to sign an agreement to guarantee that products using
|
||||
* software based on IgH EtherCAT master stay compatible with the actual
|
||||
* EtherCAT specification (which are released themselves as an open
|
||||
* standard) as the (only) precondition to have the right to use EtherCAT
|
||||
* Technology, IP and trade marks.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
\file
|
||||
EtherCAT finite state machines.
|
||||
*/
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#ifndef __EC_FSM_MASTER__
|
||||
#define __EC_FSM_MASTER__
|
||||
|
||||
#include "globals.h"
|
||||
#include "../include/ecrt.h"
|
||||
#include "datagram.h"
|
||||
#include "slave.h"
|
||||
#include "canopen.h"
|
||||
|
||||
#include "fsm_slave.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
typedef struct ec_fsm_master ec_fsm_master_t; /**< \see ec_fsm_master */
|
||||
|
||||
/**
|
||||
Finite state machine of an EtherCAT master.
|
||||
*/
|
||||
|
||||
struct ec_fsm_master
|
||||
{
|
||||
ec_master_t *master; /**< master the FSM runs on */
|
||||
ec_datagram_t *datagram; /**< datagram used in the state machine */
|
||||
unsigned int retries; /**< retries on datagram timeout. */
|
||||
|
||||
void (*state)(ec_fsm_master_t *); /**< master state function */
|
||||
unsigned int slaves_responding; /**< number of responding slaves */
|
||||
ec_slave_state_t slave_states; /**< states of responding slaves */
|
||||
unsigned int validate; /**< non-zero, if validation to do */
|
||||
ec_slave_t *slave; /**< current slave */
|
||||
ec_sdo_request_t *sdo_request; /**< SDO request to process */
|
||||
uint16_t sii_offset;
|
||||
|
||||
ec_fsm_slave_t fsm_slave; /**< slave state machine */
|
||||
ec_fsm_sii_t fsm_sii; /**< SII state machine */
|
||||
ec_fsm_change_t fsm_change; /**< State change state machine */
|
||||
ec_fsm_coe_t fsm_coe; /**< CoE state machine */
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
void ec_fsm_master_init(ec_fsm_master_t *, ec_master_t *, ec_datagram_t *);
|
||||
void ec_fsm_master_clear(ec_fsm_master_t *);
|
||||
|
||||
int ec_fsm_master_exec(ec_fsm_master_t *);
|
||||
int ec_fsm_master_running(ec_fsm_master_t *);
|
||||
int ec_fsm_master_success(ec_fsm_master_t *);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#endif
|
||||
+1101
File diff suppressed because it is too large
Load Diff
@@ -38,43 +38,34 @@
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#ifndef __EC_STATES__
|
||||
#define __EC_STATES__
|
||||
#ifndef __EC_FSM_SLAVE__
|
||||
#define __EC_FSM_SLAVE__
|
||||
|
||||
#include "globals.h"
|
||||
#include "../include/ecrt.h"
|
||||
#include "datagram.h"
|
||||
#include "slave.h"
|
||||
#include "canopen.h"
|
||||
|
||||
#include "fsm_sii.h"
|
||||
#include "fsm_change.h"
|
||||
#include "fsm_coe.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
typedef struct ec_fsm ec_fsm_t; /**< \see ec_fsm */
|
||||
typedef struct ec_fsm_slave ec_fsm_slave_t; /**< \see ec_fsm_slave */
|
||||
|
||||
/**
|
||||
Finite state machine of an EtherCAT master.
|
||||
Finite state machine of an EtherCAT slave.
|
||||
*/
|
||||
|
||||
struct ec_fsm
|
||||
struct ec_fsm_slave
|
||||
{
|
||||
ec_master_t *master; /**< master the FSM runs on */
|
||||
ec_slave_t *slave; /**< slave the FSM runs on */
|
||||
ec_datagram_t datagram; /**< datagram used in the state machine */
|
||||
ec_datagram_t *datagram; /**< datagram used in the state machine */
|
||||
unsigned int retries; /**< retries on datagram timeout. */
|
||||
|
||||
void (*master_state)(ec_fsm_t *); /**< master state function */
|
||||
unsigned int master_slaves_responding; /**< number of responding slaves */
|
||||
ec_slave_state_t master_slave_states; /**< states of responding slaves */
|
||||
unsigned int master_validation; /**< non-zero, if validation to do */
|
||||
uint16_t sii_offset; /**< current offset for SII access */
|
||||
ec_sdo_request_t *sdo_request;
|
||||
|
||||
void (*slave_state)(ec_fsm_t *); /**< slave state function */
|
||||
void (*state)(ec_fsm_slave_t *); /**< state function */
|
||||
ec_sdo_data_t *sdodata; /**< SDO configuration data */
|
||||
uint16_t sii_offset;
|
||||
|
||||
ec_fsm_sii_t fsm_sii; /**< SII state machine */
|
||||
ec_fsm_change_t fsm_change; /**< State change state machine */
|
||||
@@ -83,20 +74,14 @@ struct ec_fsm
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
int ec_fsm_init(ec_fsm_t *, ec_master_t *);
|
||||
void ec_fsm_clear(ec_fsm_t *);
|
||||
void ec_fsm_slave_init(ec_fsm_slave_t *, ec_datagram_t *);
|
||||
void ec_fsm_slave_clear(ec_fsm_slave_t *);
|
||||
|
||||
int ec_fsm_exec(ec_fsm_t *);
|
||||
int ec_fsm_running(ec_fsm_t *);
|
||||
int ec_fsm_success(ec_fsm_t *);
|
||||
void ec_fsm_slave_start_scan(ec_fsm_slave_t *, ec_slave_t *);
|
||||
void ec_fsm_slave_start_conf(ec_fsm_slave_t *, ec_slave_t *);
|
||||
|
||||
// TODO: layout slave state machines
|
||||
|
||||
/** \cond */
|
||||
void ec_fsm_slaveconf_state_start(ec_fsm_t *);
|
||||
void ec_fsm_slave_state_end(ec_fsm_t *);
|
||||
void ec_fsm_slave_state_error(ec_fsm_t *);
|
||||
/** \endcond */
|
||||
int ec_fsm_slave_exec(ec_fsm_slave_t *);
|
||||
int ec_fsm_slave_success(const ec_fsm_slave_t *);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
+38
-33
@@ -183,8 +183,15 @@ int ec_master_init(ec_master_t *master, /**< EtherCAT master */
|
||||
list_add_tail(&eoe->list, &master->eoe_handlers);
|
||||
}
|
||||
|
||||
// init state machine datagram
|
||||
ec_datagram_init(&master->fsm_datagram);
|
||||
if (ec_datagram_prealloc(&master->fsm_datagram, EC_MAX_DATA_SIZE)) {
|
||||
EC_ERR("Failed to allocate FSM datagram.\n");
|
||||
goto out_clear_eoe;
|
||||
}
|
||||
|
||||
// create state machine object
|
||||
if (ec_fsm_init(&master->fsm, master)) goto out_clear_eoe;
|
||||
ec_fsm_master_init(&master->fsm, master, &master->fsm_datagram);
|
||||
|
||||
// init kobject and add it to the hierarchy
|
||||
memset(&master->kobj, 0x00, sizeof(struct kobject));
|
||||
@@ -203,14 +210,14 @@ int ec_master_init(ec_master_t *master, /**< EtherCAT master */
|
||||
|
||||
return 0;
|
||||
|
||||
out_clear_eoe:
|
||||
out_clear_eoe:
|
||||
list_for_each_entry_safe(eoe, next_eoe, &master->eoe_handlers, list) {
|
||||
list_del(&eoe->list);
|
||||
ec_eoe_clear(eoe);
|
||||
kfree(eoe);
|
||||
}
|
||||
ec_xmldev_clear(&master->xmldev);
|
||||
out_return:
|
||||
out_return:
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -252,7 +259,8 @@ void ec_master_clear(struct kobject *kobj /**< kobject of the master */)
|
||||
list_del_init(&datagram->queue);
|
||||
}
|
||||
|
||||
ec_fsm_clear(&master->fsm);
|
||||
ec_fsm_master_clear(&master->fsm);
|
||||
ec_datagram_clear(&master->fsm_datagram);
|
||||
ec_xmldev_clear(&master->xmldev);
|
||||
|
||||
// clear EoE objects
|
||||
@@ -416,7 +424,6 @@ void ec_master_leave_idle_mode(ec_master_t *master /**< EtherCAT master */)
|
||||
int ec_master_enter_operation_mode(ec_master_t *master /**< EtherCAT master */)
|
||||
{
|
||||
ec_slave_t *slave;
|
||||
ec_datagram_t *datagram = &master->fsm.datagram;
|
||||
|
||||
ec_master_eoe_stop(master); // stop EoE timer
|
||||
master->eoe_checked = 1; // prevent from starting again by FSM
|
||||
@@ -425,15 +432,15 @@ int ec_master_enter_operation_mode(ec_master_t *master /**< EtherCAT master */)
|
||||
master->mode = EC_MASTER_MODE_OPERATION;
|
||||
|
||||
// wait for FSM datagram
|
||||
if (datagram->state == EC_DATAGRAM_SENT) {
|
||||
while (get_cycles() - datagram->cycles_sent
|
||||
if (master->fsm_datagram.state == EC_DATAGRAM_SENT) {
|
||||
while (get_cycles() - master->fsm_datagram.cycles_sent
|
||||
< (cycles_t) EC_IO_TIMEOUT /* us */ * (cpu_khz / 1000)) {}
|
||||
ecrt_master_receive(master);
|
||||
}
|
||||
|
||||
// finish running master FSM
|
||||
if (ec_fsm_running(&master->fsm)) {
|
||||
while (ec_fsm_exec(&master->fsm)) {
|
||||
if (ec_fsm_master_running(&master->fsm)) {
|
||||
while (ec_fsm_master_exec(&master->fsm)) {
|
||||
ec_master_sync_io(master);
|
||||
}
|
||||
}
|
||||
@@ -477,43 +484,42 @@ void ec_master_leave_operation_mode(ec_master_t *master
|
||||
/**< EtherCAT master */)
|
||||
{
|
||||
ec_slave_t *slave;
|
||||
ec_fsm_t *fsm = &master->fsm;
|
||||
ec_datagram_t *datagram = &master->fsm.datagram;
|
||||
ec_fsm_master_t *fsm = &master->fsm;
|
||||
ec_fsm_slave_t fsm_slave;
|
||||
|
||||
ec_master_eoe_stop(master); // stop EoE timer
|
||||
master->eoe_checked = 1; // prevent from starting again by FSM
|
||||
|
||||
// wait for FSM datagram
|
||||
if (datagram->state == EC_DATAGRAM_SENT) {
|
||||
if (master->fsm_datagram.state == EC_DATAGRAM_SENT) {
|
||||
// active waiting
|
||||
while (get_cycles() - datagram->cycles_sent
|
||||
while (get_cycles() - master->fsm_datagram.cycles_sent
|
||||
< (cycles_t) EC_IO_TIMEOUT /* us */ * (cpu_khz / 1000));
|
||||
ecrt_master_receive(master);
|
||||
}
|
||||
|
||||
// finish running master FSM
|
||||
if (ec_fsm_running(fsm)) {
|
||||
while (ec_fsm_exec(fsm)) {
|
||||
if (ec_fsm_master_running(fsm)) {
|
||||
while (ec_fsm_master_exec(fsm)) {
|
||||
ec_master_sync_io(master);
|
||||
}
|
||||
}
|
||||
|
||||
ec_fsm_slave_init(&fsm_slave, &master->fsm_datagram);
|
||||
|
||||
// set states for all slaves
|
||||
list_for_each_entry(slave, &master->slaves, list) {
|
||||
ec_slave_reset(slave);
|
||||
ec_slave_request_state(slave, EC_SLAVE_STATE_PREOP);
|
||||
|
||||
fsm->slave = slave;
|
||||
fsm->slave_state = ec_fsm_slaveconf_state_start;
|
||||
|
||||
do {
|
||||
fsm->slave_state(fsm);
|
||||
ec_fsm_slave_start_conf(&fsm_slave, slave);
|
||||
while (ec_fsm_slave_exec(&fsm_slave)) {
|
||||
ec_master_sync_io(master);
|
||||
}
|
||||
while (fsm->slave_state != ec_fsm_slave_state_end
|
||||
&& fsm->slave_state != ec_fsm_slave_state_error);
|
||||
}
|
||||
|
||||
ec_fsm_slave_clear(&fsm_slave);
|
||||
|
||||
ec_master_destroy_domains(master);
|
||||
|
||||
master->request_cb = ec_master_request_cb;
|
||||
@@ -816,7 +822,7 @@ static int ec_master_thread(void *data)
|
||||
spin_unlock_bh(&master->internal_lock);
|
||||
|
||||
// execute master state machine
|
||||
ec_fsm_exec(&master->fsm);
|
||||
ec_fsm_master_exec(&master->fsm);
|
||||
|
||||
// send
|
||||
spin_lock_bh(&master->internal_lock);
|
||||
@@ -1402,7 +1408,7 @@ int ecrt_master_activate(ec_master_t *master /**< EtherCAT master */)
|
||||
{
|
||||
uint32_t domain_offset;
|
||||
ec_domain_t *domain;
|
||||
ec_fsm_t *fsm = &master->fsm;
|
||||
ec_fsm_slave_t fsm_slave;
|
||||
ec_slave_t *slave;
|
||||
|
||||
// allocate all domains
|
||||
@@ -1415,24 +1421,23 @@ int ecrt_master_activate(ec_master_t *master /**< EtherCAT master */)
|
||||
domain_offset += domain->data_size;
|
||||
}
|
||||
|
||||
ec_fsm_slave_init(&fsm_slave, &master->fsm_datagram);
|
||||
|
||||
// configure all slaves
|
||||
list_for_each_entry(slave, &master->slaves, list) {
|
||||
fsm->slave = slave;
|
||||
fsm->slave_state = ec_fsm_slaveconf_state_start;
|
||||
|
||||
do {
|
||||
fsm->slave_state(fsm);
|
||||
ec_fsm_slave_start_conf(&fsm_slave, slave);
|
||||
while (ec_fsm_slave_exec(&fsm_slave)) {
|
||||
ec_master_sync_io(master);
|
||||
}
|
||||
while (fsm->slave_state != ec_fsm_slave_state_end
|
||||
&& fsm->slave_state != ec_fsm_slave_state_error);
|
||||
|
||||
if (fsm->slave_state == ec_fsm_slave_state_error) {
|
||||
if (!ec_fsm_slave_success(&fsm_slave)) {
|
||||
ec_fsm_slave_clear(&fsm_slave);
|
||||
EC_ERR("Failed to configure slave %i!\n", slave->ring_position);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
ec_fsm_slave_clear(&fsm_slave);
|
||||
ec_master_prepare(master); // prepare asynchronous IO
|
||||
|
||||
return 0;
|
||||
@@ -1537,7 +1542,7 @@ void ecrt_master_run(ec_master_t *master /**< EtherCAT master */)
|
||||
ec_master_output_stats(master);
|
||||
|
||||
// execute master state machine in a loop
|
||||
ec_fsm_exec(&master->fsm);
|
||||
ec_fsm_master_exec(&master->fsm);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
+3
-2
@@ -50,7 +50,7 @@
|
||||
#include "device.h"
|
||||
#include "domain.h"
|
||||
#include "xmldev.h"
|
||||
#include "fsm.h"
|
||||
#include "fsm_master.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
@@ -104,7 +104,8 @@ struct ec_master
|
||||
|
||||
ec_xmldev_t xmldev; /**< XML character device */
|
||||
|
||||
ec_fsm_t fsm; /**< master state machine */
|
||||
ec_fsm_master_t fsm; /**< master state machine */
|
||||
ec_datagram_t fsm_datagram; /**< datagram used for state machines */
|
||||
ec_master_mode_t mode; /**< master mode */
|
||||
|
||||
struct list_head slaves; /**< list of slaves on the bus */
|
||||
|
||||
Reference in New Issue
Block a user