Skip to content

Commit

Permalink
Add support to choose if manual or automatic state change is done by …
Browse files Browse the repository at this point in the history
…config functions, fixes #189
  • Loading branch information
Andreas Karlsson committed Jun 10, 2019
1 parent cc417d4 commit 8174350
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
36 changes: 30 additions & 6 deletions soem/ethercatconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,16 @@ int ecx_config_init(ecx_contextt *context, uint8 usetable)
}
/* some slaves need eeprom available to PDI in init->preop transition */
ecx_eeprom2pdi(context, slave);
/* request pre_op for slave */
ecx_FPWRw(context->port, configadr, ECT_REG_ALCTL, htoes(EC_STATE_PRE_OP | EC_STATE_ACK) , EC_TIMEOUTRET3); /* set preop status */
/* User may override automatic state change */
if (context->manualstatechange == 0)
{
/* request pre_op for slave */
ecx_FPWRw(context->port,
configadr,
ECT_REG_ALCTL,
htoes(EC_STATE_PRE_OP | EC_STATE_ACK),
EC_TIMEOUTRET3); /* set preop status */
}
}
}
return wkc;
Expand Down Expand Up @@ -1273,8 +1281,16 @@ int ecx_config_map_group(ecx_contextt *context, void *pIOmap, uint8 group)
}

ecx_eeprom2pdi(context, slave); /* set Eeprom control to PDI */
ecx_FPWRw(context->port, configadr, ECT_REG_ALCTL, htoes(EC_STATE_SAFE_OP) , EC_TIMEOUTRET3); /* set safeop status */

/* User may override automatic state change */
if (context->manualstatechange == 0)
{
/* request safe_op for slave */
ecx_FPWRw(context->port,
configadr,
ECT_REG_ALCTL,
htoes(EC_STATE_SAFE_OP),
EC_TIMEOUTRET3); /* set safeop status */
}
if (context->slavelist[slave].blockLRW)
{
context->grouplist[group].blockLRW++;
Expand Down Expand Up @@ -1409,8 +1425,16 @@ int ecx_config_overlap_map_group(ecx_contextt *context, void *pIOmap, uint8 grou
}

ecx_eeprom2pdi(context, slave); /* set Eeprom control to PDI */
ecx_FPWRw(context->port, configadr, ECT_REG_ALCTL, htoes(EC_STATE_SAFE_OP), EC_TIMEOUTRET3); /* set safeop status */

/* User may override automatic state change */
if (context->manualstatechange == 0)
{
/* request safe_op for slave */
ecx_FPWRw(context->port,
configadr,
ECT_REG_ALCTL,
htoes(EC_STATE_SAFE_OP),
EC_TIMEOUTRET3);
}
if (context->slavelist[slave].blockLRW)
{
context->grouplist[group].blockLRW++;
Expand Down
3 changes: 2 additions & 1 deletion soem/ethercatmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ ecx_contextt ecx_context = {
&ec_SM, // .eepSM =
&ec_FMMU, // .eepFMMU =
NULL, // .FOEhook()
NULL // .EOEhook()
NULL, // .EOEhook()
0 // .manualstatechange
};
#endif

Expand Down
2 changes: 2 additions & 0 deletions soem/ethercatmain.h
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,8 @@ struct ecx_context
int (*FOEhook)(uint16 slave, int packetnumber, int datasize);
/** registered EoE hook */
int (*EOEhook)(ecx_contextt * context, uint16 slave, void * eoembx);
/** flag to control legacy automatic state change or manual state change */
int manualstatechange;
};

#ifdef EC_VER1
Expand Down

1 comment on commit 8174350

@tecodrive
Copy link

@tecodrive tecodrive commented on 8174350 Jun 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, this solve the Problem with EL5101, because DCSYNC0 cannot set in SAFE_OP, only in PRE_OP.

ecx_context.manualstatechange = -1; /* did not switch to SAFE_OP = -1 , default = 0 */
if ( ec_config_overlap_map( &EcatSystem.data.bus.IOmap ) <= 0 ) { ... }
ecx_context.manualstatechange = 0; /* did not switch to SAFE_OP = -1 , default = 0 */

Please sign in to comment.