Skip to content

Commit

Permalink
improve groups, make memory usage more efficient, fix erroneous byte …
Browse files Browse the repository at this point in the history
…calculations and dc frame handling
  • Loading branch information
Andreas Karlsson committed Mar 11, 2019
1 parent 8832ef0 commit 930d6e0
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 15 deletions.
55 changes: 42 additions & 13 deletions soem/ethercatconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ void ecx_init_context(ecx_contextt *context)
ecx_siigetbyte(context, 0, EC_MAXEEPBUF);
for(lp = 0; lp < context->maxgroup; lp++)
{
context->grouplist[lp].logstartaddr = lp << 16; /* default start address per group entry */
/* default start address per group entry */
context->grouplist[lp].logstartaddr = lp << EC_LOGGROUPOFFSET;
}
}

Expand Down Expand Up @@ -992,8 +993,19 @@ static void ecx_config_create_input_mappings(ecx_contextt *context, void *pIOmap
}
if (!context->slavelist[slave].inputs)
{
context->slavelist[slave].inputs =
(uint8 *)(pIOmap)+etohl(context->slavelist[slave].FMMU[FMMUc].LogStart);
if (group)
{
context->slavelist[slave].inputs =
(uint8 *)(pIOmap) +
etohl(context->slavelist[slave].FMMU[FMMUc].LogStart) -
context->grouplist[group].logstartaddr;
}
else
{
context->slavelist[slave].inputs =
(uint8 *)(pIOmap) +
etohl(context->slavelist[slave].FMMU[FMMUc].LogStart);
}
context->slavelist[slave].Istartbit =
context->slavelist[slave].FMMU[FMMUc].LogStartbit;
EC_PRINT(" Inputs %p startbit %d\n",
Expand Down Expand Up @@ -1109,8 +1121,19 @@ static void ecx_config_create_output_mappings(ecx_contextt *context, void *pIOma
context->grouplist[group].outputsWKC++;
if (!context->slavelist[slave].outputs)
{
context->slavelist[slave].outputs =
(uint8 *)(pIOmap)+etohl(context->slavelist[slave].FMMU[FMMUc].LogStart);
if (group)
{
context->slavelist[slave].outputs =
(uint8 *)(pIOmap) +
etohl(context->slavelist[slave].FMMU[FMMUc].LogStart) -
context->grouplist[group].logstartaddr;
}
else
{
context->slavelist[slave].outputs =
(uint8 *)(pIOmap) +
etohl(context->slavelist[slave].FMMU[FMMUc].LogStart);
}
context->slavelist[slave].Ostartbit =
context->slavelist[slave].FMMU[FMMUc].LogStartbit;
EC_PRINT(" slave %d Outputs %p startbit %d\n",
Expand Down Expand Up @@ -1204,14 +1227,15 @@ int ecx_config_map_group(ecx_contextt *context, void *pIOmap, uint8 group)
}
}
context->grouplist[group].outputs = pIOmap;
context->grouplist[group].Obytes = LogAddr;
context->grouplist[group].Obytes = LogAddr - context->grouplist[group].logstartaddr;
context->grouplist[group].nsegments = currentsegment + 1;
context->grouplist[group].Isegment = currentsegment;
context->grouplist[group].Ioffset = segmentsize;
if (!group)
{
context->slavelist[0].outputs = pIOmap;
context->slavelist[0].Obytes = LogAddr; /* store output bytes in master record */
context->slavelist[0].Obytes = LogAddr -
context->grouplist[group].logstartaddr; /* store output bytes in master record */
}

/* do input mapping of slave and program FMMUs */
Expand Down Expand Up @@ -1274,11 +1298,15 @@ int ecx_config_map_group(ecx_contextt *context, void *pIOmap, uint8 group)
context->grouplist[group].IOsegment[currentsegment] = segmentsize;
context->grouplist[group].nsegments = currentsegment + 1;
context->grouplist[group].inputs = (uint8 *)(pIOmap) + context->grouplist[group].Obytes;
context->grouplist[group].Ibytes = LogAddr - context->grouplist[group].Obytes;
context->grouplist[group].Ibytes = LogAddr -
context->grouplist[group].logstartaddr -
context->grouplist[group].Obytes;
if (!group)
{
context->slavelist[0].inputs = (uint8 *)(pIOmap) + context->slavelist[0].Obytes;
context->slavelist[0].Ibytes = LogAddr - context->slavelist[0].Obytes; /* store input bytes in master record */
context->slavelist[0].Ibytes = LogAddr -
context->grouplist[group].logstartaddr -
context->slavelist[0].Obytes; /* store input bytes in master record */
}

EC_PRINT("IOmapSize %d\n", LogAddr - context->grouplist[group].logstartaddr);
Expand Down Expand Up @@ -1391,8 +1419,8 @@ int ecx_config_overlap_map_group(ecx_contextt *context, void *pIOmap, uint8 grou
context->grouplist[group].Isegment = 0;
context->grouplist[group].Ioffset = 0;

context->grouplist[group].Obytes = soLogAddr;
context->grouplist[group].Ibytes = siLogAddr;
context->grouplist[group].Obytes = soLogAddr - context->grouplist[group].logstartaddr;
context->grouplist[group].Ibytes = siLogAddr - context->grouplist[group].logstartaddr;
context->grouplist[group].outputs = pIOmap;
context->grouplist[group].inputs = (uint8 *)pIOmap + context->grouplist[group].Obytes;

Expand All @@ -1404,10 +1432,11 @@ int ecx_config_overlap_map_group(ecx_contextt *context, void *pIOmap, uint8 grou

if (!group)
{
/* store output bytes in master record */
context->slavelist[0].outputs = pIOmap;
context->slavelist[0].Obytes = soLogAddr; /* store output bytes in master record */
context->slavelist[0].Obytes = soLogAddr - context->grouplist[group].logstartaddr;
context->slavelist[0].inputs = (uint8 *)pIOmap + context->slavelist[0].Obytes;
context->slavelist[0].Ibytes = siLogAddr;
context->slavelist[0].Ibytes = siLogAddr - context->grouplist[group].logstartaddr;
}

EC_PRINT("IOmapSize %d\n", context->grouplist[group].Obytes + context->grouplist[group].Ibytes);
Expand Down
4 changes: 2 additions & 2 deletions soem/ethercatdc.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ boolean ecx_configdc(ecx_contextt *context)
context->slavelist[0].hasdc = TRUE;
context->slavelist[0].DCnext = i;
context->slavelist[i].DCprevious = 0;
context->grouplist[0].hasdc = TRUE;
context->grouplist[0].DCnext = i;
context->grouplist[context->slavelist[i].group].hasdc = TRUE;
context->grouplist[context->slavelist[i].group].DCnext = i;
}
else
{
Expand Down
1 change: 1 addition & 0 deletions soem/ethercatmain.h
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ int ecx_receive_processdata_group(ecx_contextt *context, uint8 group, int timeou
int ecx_send_processdata(ecx_contextt *context);
int ecx_send_overlap_processdata(ecx_contextt *context);
int ecx_receive_processdata(ecx_contextt *context, int timeout);
int ecx_send_processdata_group(ecx_contextt *context, uint8 group);

#ifdef __cplusplus
}
Expand Down
2 changes: 2 additions & 0 deletions soem/ethercattype.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ extern "C"
#define EC_MAXEEPBUF EC_MAXEEPBITMAP << 5
/** default number of retries if wkc <= 0 */
#define EC_DEFAULTRETRIES 3
/** default group size in 2^x */
#define EC_LOGGROUPOFFSET 16

/** definition for frame buffers */
typedef uint8 ec_bufT[EC_BUFSIZE];
Expand Down

0 comments on commit 930d6e0

Please sign in to comment.