Skip to content

Commit

Permalink
Added config_map_aligned to use byte aligned outputs and inputs (#645)
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Laza authored Oct 19, 2022
1 parent 26fc5dd commit 6a5babf
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 11 deletions.
85 changes: 75 additions & 10 deletions soem/ethercatconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -1175,16 +1175,7 @@ static void ecx_config_create_output_mappings(ecx_contextt *context, void *pIOma
context->grouplist[group].outputsWKC++;
}

/** Map all PDOs in one group of slaves to IOmap with Outputs/Inputs
* in sequential order (legacy SOEM way).
*
*
* @param[in] context = context struct
* @param[out] pIOmap = pointer to IOmap
* @param[in] group = group to map, 0 = all groups
* @return IOmap size
*/
int ecx_config_map_group(ecx_contextt *context, void *pIOmap, uint8 group)
static int ecx_main_config_map_group(ecx_contextt *context, void *pIOmap, uint8 group, boolean forceByteAlignment)
{
uint16 slave, configadr;
uint8 BitPos;
Expand Down Expand Up @@ -1218,6 +1209,17 @@ int ecx_config_map_group(ecx_contextt *context, void *pIOmap, uint8 group)
if (context->slavelist[slave].Obits)
{
ecx_config_create_output_mappings (context, pIOmap, group, slave, &LogAddr, &BitPos);

if (forceByteAlignment)
{
/* Force byte alignment if the output is < 8 bits */
if (BitPos)
{
LogAddr++;
BitPos = 0;
}
}

diff = LogAddr - oLogAddr;
oLogAddr = LogAddr;
if ((segmentsize + diff) > (EC_MAXLRWDATA - EC_FIRSTDCDATAGRAM))
Expand Down Expand Up @@ -1278,6 +1280,17 @@ int ecx_config_map_group(ecx_contextt *context, void *pIOmap, uint8 group)
{

ecx_config_create_input_mappings(context, pIOmap, group, slave, &LogAddr, &BitPos);

if (forceByteAlignment)
{
/* Force byte alignment if the input is < 8 bits */
if (BitPos)
{
LogAddr++;
BitPos = 0;
}
}

diff = LogAddr - oLogAddr;
oLogAddr = LogAddr;
if ((segmentsize + diff) > (EC_MAXLRWDATA - EC_FIRSTDCDATAGRAM))
Expand Down Expand Up @@ -1354,6 +1367,34 @@ int ecx_config_map_group(ecx_contextt *context, void *pIOmap, uint8 group)
return 0;
}

/** Map all PDOs in one group of slaves to IOmap with Outputs/Inputs
* in sequential order (legacy SOEM way).
*
*
* @param[in] context = context struct
* @param[out] pIOmap = pointer to IOmap
* @param[in] group = group to map, 0 = all groups
* @return IOmap size
*/
int ecx_config_map_group(ecx_contextt *context, void *pIOmap, uint8 group)
{
return ecx_main_config_map_group(context, pIOmap, group, FALSE);
}

/** Map all PDOs in one group of slaves to IOmap with Outputs/Inputs
* in sequential order (legacy SOEM way) and force byte alignement.
*
*
* @param[in] context = context struct
* @param[out] pIOmap = pointer to IOmap
* @param[in] group = group to map, 0 = all groups
* @return IOmap size
*/
int ecx_config_map_group_aligned(ecx_contextt *context, void *pIOmap, uint8 group)
{
return ecx_main_config_map_group(context, pIOmap, group, TRUE);
}

/** Map all PDOs in one group of slaves to IOmap with Outputs/Inputs
* overlapping. NOTE: Must use this for TI ESC when using LRW.
*
Expand Down Expand Up @@ -1659,6 +1700,19 @@ int ec_config_overlap_map_group(void *pIOmap, uint8 group)
return ecx_config_overlap_map_group(&ecx_context, pIOmap, group);
}

/** Map all PDOs in one group of slaves to IOmap with Outputs/Inputs
* in sequential order (legacy SOEM way) and force byte alignment.
*
* @param[out] pIOmap = pointer to IOmap
* @param[in] group = group to map, 0 = all groups
* @return IOmap size
* @see ecx_config_map_group
*/
int ec_config_map_group_aligned(void *pIOmap, uint8 group)
{
return ecx_config_map_group_aligned(&ecx_context, pIOmap, group);
}

/** Map all PDOs from slaves to IOmap with Outputs/Inputs
* in sequential order (legacy SOEM way).
*
Expand All @@ -1681,6 +1735,17 @@ int ec_config_overlap_map(void *pIOmap)
return ec_config_overlap_map_group(pIOmap, 0);
}

/** Map all PDOs from slaves to IOmap with Outputs/Inputs
* in sequential order (legacy SOEM way) and force byte alignment.
*
* @param[out] pIOmap = pointer to IOmap
* @return IOmap size
*/
int ec_config_map_aligned(void *pIOmap)
{
return ec_config_map_group_aligned(pIOmap, 0);
}

/** Enumerate / map and init all slaves.
*
* @param[in] usetable = TRUE when using configtable to init slaves, FALSE otherwise
Expand Down
3 changes: 3 additions & 0 deletions soem/ethercatconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ extern "C"
int ec_config_init(uint8 usetable);
int ec_config_map(void *pIOmap);
int ec_config_overlap_map(void *pIOmap);
int ec_config_map_aligned(void *pIOmap);
int ec_config_map_group(void *pIOmap, uint8 group);
int ec_config_overlap_map_group(void *pIOmap, uint8 group);
int ec_config_map_group_aligned(void *pIOmap, uint8 group);
int ec_config(uint8 usetable, void *pIOmap);
int ec_config_overlap(uint8 usetable, void *pIOmap);
int ec_recover_slave(uint16 slave, int timeout);
Expand All @@ -34,6 +36,7 @@ int ec_reconfig_slave(uint16 slave, int timeout);
int ecx_config_init(ecx_contextt *context, uint8 usetable);
int ecx_config_map_group(ecx_contextt *context, void *pIOmap, uint8 group);
int ecx_config_overlap_map_group(ecx_contextt *context, void *pIOmap, uint8 group);
int ecx_config_map_group_aligned(ecx_contextt *context, void *pIOmap, uint8 group);
int ecx_recover_slave(ecx_contextt *context, uint16 slave, int timeout);
int ecx_reconfig_slave(ecx_contextt *context, uint16 slave, int timeout);

Expand Down
10 changes: 9 additions & 1 deletion test/linux/simple_test/simple_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ boolean needlf;
volatile int wkc;
boolean inOP;
uint8 currentgroup = 0;
boolean forceByteAlignment = FALSE;

void simpletest(char *ifname)
{
Expand All @@ -44,7 +45,14 @@ void simpletest(char *ifname)
{
printf("%d slaves found and configured.\n",ec_slavecount);

ec_config_map(&IOmap);
if (forceByteAlignment)
{
ec_config_map_aligned(&IOmap);
}
else
{
ec_config_map(&IOmap);
}

ec_configdc();

Expand Down

0 comments on commit 6a5babf

Please sign in to comment.