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

Implemented ecrt_slave_config_state(); minor changes in

ec_master_state_t and ec_slave_config_state_t; adapted example.
parent 99717b00
No related branches found
No related tags found
No related merge requests found
......@@ -8,8 +8,6 @@ $Id$
Version 1.4.0:
* Supply new ec_master_state_t.
* Implement ecrt_slave_config_state().
* Remove get_cycles() calls and references to cpu_khz to increase
portability.
* Make ecrt_master_slave_config() return no error when slave is not present
......
......@@ -60,6 +60,9 @@ spinlock_t master_lock = SPIN_LOCK_UNLOCKED;
static ec_domain_t *domain1 = NULL;
static ec_domain_state_t domain1_state = {};
static ec_slave_config_t *sc_ana_in = NULL;
static ec_slave_config_state_t sc_ana_in_state = {};
static struct timer_list timer;
static unsigned int counter = 0;
......@@ -128,14 +131,14 @@ void check_domain1_state(void)
{
ec_domain_state_t ds;
spin_lock(&master_lock);
ecrt_domain_state(domain1, &ds);
if (ds.working_counter != domain1_state.working_counter)
printk(KERN_INFO PFX "domain1 working_counter changed to %u.\n",
ds.working_counter);
spin_unlock(&master_lock);
if (ds.working_counter != domain1_state.working_counter)
printk(KERN_INFO PFX "Domain1: WC %u.\n", ds.working_counter);
if (ds.wc_state != domain1_state.wc_state)
printk(KERN_INFO PFX "domain1 wc_state changed to %u.\n",
ds.wc_state);
printk(KERN_INFO PFX "Domain1: State %u.\n", ds.wc_state);
domain1_state = ds;
}
......@@ -150,16 +153,39 @@ void check_master_state(void)
ecrt_master_state(master, &ms);
spin_unlock(&master_lock);
if (ms.slaves_responding != master_state.slaves_responding) {
printk(KERN_INFO PFX "slaves_responding changed to %u.\n",
ms.slaves_responding);
}
if (ms.slaves_responding != master_state.slaves_responding)
printk(KERN_INFO PFX "%u slave(s).\n", ms.slaves_responding);
if (ms.al_states != master_state.al_states)
printk(KERN_INFO PFX "AL states: 0x%02X.\n", ms.al_states);
if (ms.link_up != master_state.link_up)
printk(KERN_INFO PFX "Link is %s.\n", ms.link_up ? "up" : "down");
master_state = ms;
}
/*****************************************************************************/
void check_slave_config_states(void)
{
ec_slave_config_state_t s;
spin_lock(&master_lock);
ecrt_slave_config_state(sc_ana_in, &s);
spin_unlock(&master_lock);
if (s.al_state != sc_ana_in_state.al_state)
printk(KERN_INFO PFX "AnaIn: State 0x%02X.\n", s.al_state);
if (s.online != sc_ana_in_state.online)
printk(KERN_INFO PFX "AnaIn: %s.\n", s.online ? "online" : "offline");
if (s.operational != sc_ana_in_state.operational)
printk(KERN_INFO PFX "AnaIn: %soperational.\n",
s.operational ? "" : "Not ");
sc_ana_in_state = s;
}
/*****************************************************************************/
#ifdef SDO_ACCESS
void read_sdo(void)
{
......@@ -207,6 +233,9 @@ void cyclic_task(unsigned long data)
// check for master state (optional)
check_master_state();
// check for islave configuration state(s) (optional)
check_slave_config_states();
#ifdef SDO_ACCESS
// read process data Sdo
......@@ -269,14 +298,15 @@ int __init init_mini_module(void)
goto out_release_master;
}
#ifdef CONFIGURE_PDOS
printk(KERN_INFO PFX "Configuring Pdos...\n");
if (!(sc = ecrt_master_slave_config(master, 0, 1, Beckhoff_EL3162))) {
if (!(sc_ana_in = ecrt_master_slave_config(
master, 0, 1, Beckhoff_EL3162))) {
printk(KERN_ERR PFX "Failed to get slave configuration.\n");
goto out_release_master;
}
if (ecrt_slave_config_pdos(sc, EC_END, el3162_pdos)) {
#ifdef CONFIGURE_PDOS
printk(KERN_INFO PFX "Configuring Pdos...\n");
if (ecrt_slave_config_pdos(sc_ana_in, EC_END, el3162_pdos)) {
printk(KERN_ERR PFX "Failed to configure Pdos.\n");
goto out_release_master;
}
......
......@@ -157,15 +157,16 @@ typedef struct ec_sdo_request ec_sdo_request_t; /**< \see ec_sdo_request. */
*/
typedef struct {
unsigned int slaves_responding; /**< Number of slaves in the bus. */
uint8_t slave_states; /**< Application-layer states of all slaves.
The states are coded in the lower 4 bits. If a bit
is set, it means that at least one slave in the
bus is in the corresponding state:
- Bit 0: \a INIT
- Bit 1: \a PREOP
- Bit 2: \a SAFEOP
- Bit 3: \a OP */
uint8_t link_up; /**< \a true, if the network link is up. */
unsigned int al_states : 4; /**< Application-layer states of all slaves.
The states are coded in the lower 4 bits.
If a bit is set, it means that at least one
slave in the bus is in the corresponding
state:
- Bit 0: \a INIT
- Bit 1: \a PREOP
- Bit 2: \a SAFEOP
- Bit 3: \a OP */
unsigned int link_up : 1; /**< \a true, if the network link is up. */
} ec_master_state_t;
/*****************************************************************************/
......@@ -177,17 +178,17 @@ typedef struct {
* \see ecrt_slave_config_state().
*/
typedef struct {
uint8_t slave_state; /**< The application-layer state of the slave.
- 1: \a INIT
- 2: \a PREOP
- 4: \a SAFEOP
- 8: \a OP
Note that each state is coded in a different
bit! */
unsigned int online : 1; /**< The slave is online. */
unsigned int operational : 1; /**< The slave was brought into \a OP state
using the specified configuration. */
unsigned int al_state : 4; /**< The application-layer state of the slave.
- 1: \a INIT
- 2: \a PREOP
- 4: \a SAFEOP
- 8: \a OP
Note that each state is coded in a different
bit! */
} ec_slave_config_state_t;
/*****************************************************************************/
......
......@@ -1372,7 +1372,7 @@ void ecrt_master_callbacks(ec_master_t *master, int (*request_cb)(void *),
void ecrt_master_state(const ec_master_t *master, ec_master_state_t *state)
{
state->slaves_responding = master->fsm.slaves_responding;
state->slave_states = master->fsm.slave_states;
state->al_states = master->fsm.slave_states;
state->link_up = master->main_device.link_state;
}
......
......@@ -618,6 +618,22 @@ ec_sdo_request_t *ecrt_slave_config_create_sdo_request(ec_slave_config_t *sc,
/*****************************************************************************/
void ecrt_slave_config_state(const ec_slave_config_t *sc,
ec_slave_config_state_t *state)
{
state->online = sc->slave ? 1 : 0;
if (state->online) {
state->operational =
sc->slave->current_state == EC_SLAVE_STATE_OP;
state->al_state = sc->slave->current_state;
} else {
state->operational = 0;
state->al_state = EC_SLAVE_STATE_UNKNOWN;
}
}
/*****************************************************************************/
/** \cond */
EXPORT_SYMBOL(ecrt_slave_config_pdo_assign_add);
......@@ -631,6 +647,7 @@ EXPORT_SYMBOL(ecrt_slave_config_sdo8);
EXPORT_SYMBOL(ecrt_slave_config_sdo16);
EXPORT_SYMBOL(ecrt_slave_config_sdo32);
EXPORT_SYMBOL(ecrt_slave_config_create_sdo_request);
EXPORT_SYMBOL(ecrt_slave_config_state);
/** \endcond */
......
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