From 817435066f53006f42899bf602e3b7e4182aa57a Mon Sep 17 00:00:00 2001 From: Andreas Karlsson Date: Mon, 10 Jun 2019 11:48:41 +0200 Subject: [PATCH] Add support to choose if manual or automatic state change is done by config functions, fixes #189 --- soem/ethercatconfig.c | 36 ++++++++++++++++++++++++++++++------ soem/ethercatmain.c | 3 ++- soem/ethercatmain.h | 2 ++ 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/soem/ethercatconfig.c b/soem/ethercatconfig.c index 6fb8ad6..af667a6 100644 --- a/soem/ethercatconfig.c +++ b/soem/ethercatconfig.c @@ -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; @@ -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++; @@ -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++; diff --git a/soem/ethercatmain.c b/soem/ethercatmain.c index 795a21c..30065b6 100644 --- a/soem/ethercatmain.c +++ b/soem/ethercatmain.c @@ -119,7 +119,8 @@ ecx_contextt ecx_context = { &ec_SM, // .eepSM = &ec_FMMU, // .eepFMMU = NULL, // .FOEhook() - NULL // .EOEhook() + NULL, // .EOEhook() + 0 // .manualstatechange }; #endif diff --git a/soem/ethercatmain.h b/soem/ethercatmain.h index 42ad54b..7001572 100644 --- a/soem/ethercatmain.h +++ b/soem/ethercatmain.h @@ -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