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

Cleaned up Pdo mapping and configuration state machines.

parent 6f0241e5
No related branches found
No related tags found
No related merge requests found
...@@ -150,7 +150,7 @@ void ec_fsm_mapping_state_start( ...@@ -150,7 +150,7 @@ void ec_fsm_mapping_state_start(
return; return;
} }
fsm->dir = EC_DIR_OUTPUT; fsm->sync = NULL;
ec_fsm_mapping_next_sync(fsm); ec_fsm_mapping_next_sync(fsm);
} }
...@@ -162,31 +162,38 @@ void ec_fsm_mapping_next_sync( ...@@ -162,31 +162,38 @@ void ec_fsm_mapping_next_sync(
ec_fsm_mapping_t *fsm /**< mapping state machine */ ec_fsm_mapping_t *fsm /**< mapping state machine */
) )
{ {
while (1) { ec_direction_t dir;
if (fsm->dir > EC_DIR_INPUT) { const ec_sync_t *sync;
// no more directions to configure mappings for const ec_pdo_mapping_t *map;
fsm->state = ec_fsm_mapping_state_end;
return;
}
if (!(fsm->sync = ec_slave_get_pdo_sync(fsm->slave, fsm->dir))) { for (dir = EC_DIR_OUTPUT; dir <= EC_DIR_INPUT; dir++) {
EC_WARN("next_sync(): No sync manager!\n"); if (!(sync = ec_slave_get_pdo_sync(fsm->slave, dir))) {
fsm->dir++; EC_WARN("No sync manager for direction %u!\n", dir);
continue; continue;
} }
fsm->mapping = &fsm->slave->config->mapping[fsm->dir]; if (fsm->sync) { // there is a last SM
if (sync == fsm->sync) // this is the last SM
if (ec_pdo_mapping_equal(&fsm->sync->mapping, fsm->mapping)) { fsm->sync = NULL; // take the next one
// the mapping for this direction does not have to be altered
fsm->dir++;
continue;
} else { } else {
fsm->dir++; map = &fsm->slave->config->mapping[dir];
if (ec_pdo_mapping_equal(&sync->mapping, map))
continue;
fsm->sync = sync;
fsm->mapping = map;
break; break;
} }
} }
if (!sync) {
if (fsm->slave->master->debug_level)
EC_DBG("Pdo mapping finished for slave %u.\n",
fsm->slave->ring_position);
fsm->state = ec_fsm_mapping_state_end;
return;
}
if (fsm->slave->master->debug_level) { if (fsm->slave->master->debug_level) {
EC_DBG("Configuring PDO mapping for SM%u of slave %u.\n", EC_DBG("Configuring PDO mapping for SM%u of slave %u.\n",
fsm->sync->index, fsm->slave->ring_position); fsm->sync->index, fsm->slave->ring_position);
...@@ -222,6 +229,27 @@ ec_pdo_t *ec_fsm_mapping_next_pdo( ...@@ -222,6 +229,27 @@ ec_pdo_t *ec_fsm_mapping_next_pdo(
/*****************************************************************************/ /*****************************************************************************/
/** Add a Pdo to the mapping.
*/
void ec_fsm_mapping_add_pdo(
ec_fsm_mapping_t *fsm /**< mapping state machine */
)
{
fsm->sdodata.subindex = fsm->pdo_count;
EC_WRITE_U16(&fsm->sdo_value, fsm->pdo->index);
fsm->sdodata.size = 2;
if (fsm->slave->master->debug_level)
EC_DBG("Mapping PDO 0x%04X at position %u.\n",
fsm->pdo->index, fsm->sdodata.subindex);
fsm->state = ec_fsm_mapping_state_add_pdo;
ec_fsm_coe_download(fsm->fsm_coe, fsm->slave, &fsm->sdodata);
ec_fsm_coe_exec(fsm->fsm_coe); // execute immediately
}
/*****************************************************************************/
/** Set the number of mapped PDOs to zero. /** Set the number of mapped PDOs to zero.
*/ */
void ec_fsm_mapping_state_zero_count( void ec_fsm_mapping_state_zero_count(
...@@ -250,17 +278,7 @@ void ec_fsm_mapping_state_zero_count( ...@@ -250,17 +278,7 @@ void ec_fsm_mapping_state_zero_count(
// add first PDO to mapping // add first PDO to mapping
fsm->pdo_count = 1; fsm->pdo_count = 1;
fsm->sdodata.subindex = fsm->pdo_count; ec_fsm_mapping_add_pdo(fsm);
EC_WRITE_U16(&fsm->sdo_value, fsm->pdo->index);
fsm->sdodata.size = 2;
if (fsm->slave->master->debug_level)
EC_DBG("Mapping PDO 0x%04X at position %u.\n",
fsm->pdo->index, fsm->sdodata.subindex);
fsm->state = ec_fsm_mapping_state_add_pdo;
ec_fsm_coe_download(fsm->fsm_coe, fsm->slave, &fsm->sdodata);
ec_fsm_coe_exec(fsm->fsm_coe); // execute immediately
} }
/*****************************************************************************/ /*****************************************************************************/
...@@ -299,16 +317,7 @@ void ec_fsm_mapping_state_add_pdo( ...@@ -299,16 +317,7 @@ void ec_fsm_mapping_state_add_pdo(
// add next PDO to mapping // add next PDO to mapping
fsm->pdo_count++; fsm->pdo_count++;
fsm->sdodata.subindex = fsm->pdo_count; ec_fsm_mapping_add_pdo(fsm);
EC_WRITE_U16(&fsm->sdo_value, fsm->pdo->index);
fsm->sdodata.size = 2;
if (fsm->slave->master->debug_level)
EC_DBG("Mapping PDO 0x%04X at position %u.\n",
fsm->pdo->index, fsm->sdodata.subindex);
ec_fsm_coe_download(fsm->fsm_coe, fsm->slave, &fsm->sdodata);
ec_fsm_coe_exec(fsm->fsm_coe); // execute immediately
} }
/*****************************************************************************/ /*****************************************************************************/
......
...@@ -54,18 +54,17 @@ typedef struct ec_fsm_mapping ec_fsm_mapping_t; /**< \see ec_fsm_mapping */ ...@@ -54,18 +54,17 @@ typedef struct ec_fsm_mapping ec_fsm_mapping_t; /**< \see ec_fsm_mapping */
*/ */
struct ec_fsm_mapping struct ec_fsm_mapping
{ {
void (*state)(ec_fsm_mapping_t *); /**< state function */ void (*state)(ec_fsm_mapping_t *); /**< State function. */
ec_fsm_coe_t *fsm_coe; /**< CoE state machine to use */ ec_fsm_coe_t *fsm_coe; /**< CoE state machine to use. */
ec_slave_t *slave; /**< Slave the FSM runs on. */
ec_slave_t *slave; /**< slave the FSM runs on */ const ec_sync_t *sync; /**< Current sync manager. */
const ec_pdo_mapping_t *mapping; /**< Target Pdo mapping. */
const ec_pdo_t *pdo; /**< Current Pdo. */
ec_direction_t dir; /**< current PDO direction */ ec_sdo_data_t sdodata; /**< SDO configuration data. */
ec_sync_t *sync; /**< current sync manager */ uint16_t sdo_value; /**< SDO value. */
const ec_pdo_mapping_t *mapping; /**< Mapping to assign. */ unsigned int pdo_count; /**< Number of mapped Pdos. */
ec_pdo_t *pdo; /**< current PDO */
ec_sdo_data_t sdodata; /**< SDO configuration data */
uint16_t sdo_value; /**< SDO value */
unsigned int pdo_count; /**< number of mapped PDOs */
}; };
/*****************************************************************************/ /*****************************************************************************/
......
...@@ -167,27 +167,28 @@ void ec_fsm_pdo_config_next_pdo( ...@@ -167,27 +167,28 @@ void ec_fsm_pdo_config_next_pdo(
map = &fsm->slave->config->mapping[dir]; map = &fsm->slave->config->mapping[dir];
list_for_each_entry(pdo, &map->pdos, list) { list_for_each_entry(pdo, &map->pdos, list) {
if (fsm->pdo) { if (fsm->pdo) { // there was a Pdo configured in the last run
if (pdo == fsm->pdo) if (pdo == fsm->pdo) // this is the last Pdo
fsm->pdo = NULL; fsm->pdo = NULL; // take the next one
} else { } else {
if ((mapped_pdo = ec_slave_find_pdo(fsm->slave, pdo->index))) if ((mapped_pdo = ec_slave_find_pdo(fsm->slave, pdo->index)))
if (ec_pdo_equal_entries(pdo, mapped_pdo)) if (ec_pdo_equal_entries(pdo, mapped_pdo))
continue; // Pdo configured correctly continue; // Pdo configured correctly
fsm->pdo = pdo; fsm->pdo = pdo;
goto configure; break;
} }
} }
} }
if (fsm->slave->master->debug_level) if (!fsm->pdo) {
EC_DBG("Pdo configuration finished for slave %u.\n", if (fsm->slave->master->debug_level)
fsm->slave->ring_position); EC_DBG("Pdo configuration finished for slave %u.\n",
fsm->state = ec_fsm_pdo_config_state_end; fsm->slave->ring_position);
return; fsm->state = ec_fsm_pdo_config_state_end;
return;
}
configure:
if (fsm->slave->master->debug_level) { if (fsm->slave->master->debug_level) {
EC_DBG("Changing configuration of Pdo 0x%04X of slave %u.\n", EC_DBG("Changing configuration of Pdo 0x%04X of slave %u.\n",
fsm->pdo->index, fsm->slave->ring_position); fsm->pdo->index, fsm->slave->ring_position);
......
...@@ -31,10 +31,9 @@ ...@@ -31,10 +31,9 @@
* *
*****************************************************************************/ *****************************************************************************/
/** /** \file
\file * EtherCAT PDO configuration state machine structures.
EtherCAT PDO configuration state machine structures. */
*/
/*****************************************************************************/ /*****************************************************************************/
......
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