From 366c07f446b1b93ca5a22a03534badc07508e9b5 Mon Sep 17 00:00:00 2001 From: andreas karlsson Date: Tue, 14 Jun 2022 20:56:29 +0200 Subject: [PATCH] Add support for input- or output only slaves Seperate validation of SM configuration that depend on size of tx/rx pdo. Add disable of SM3 when input only slave reports error in OP. Don't enable SM3 on start input if no inputs Don't enable SM2 on start outputs if no outputs fix #112 fix #113 --- soes/ecat_slv.c | 3 ++- soes/esc.c | 56 ++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 51 insertions(+), 8 deletions(-) diff --git a/soes/ecat_slv.c b/soes/ecat_slv.c index c583b16..874b45a 100644 --- a/soes/ecat_slv.c +++ b/soes/ecat_slv.c @@ -202,7 +202,8 @@ void DIG_process (uint8_t flags) } if ((CC_ATOMIC_GET(watchdog) <= 0) && - ((CC_ATOMIC_GET(ESCvar.App.state) & APPSTATE_OUTPUT) > 0)) + ((CC_ATOMIC_GET(ESCvar.App.state) & APPSTATE_OUTPUT) > 0) && + (ESCvar.ESC_SM2_sml > 0)) { DPRINT("DIG_process watchdog expired\n"); ESC_ALstatusgotoerror((ESCsafeop | ESCerror), ALERR_WATCHDOG); diff --git a/soes/esc.c b/soes/esc.c index df77643..07c9a04 100644 --- a/soes/esc.c +++ b/soes/esc.c @@ -688,8 +688,19 @@ uint8_t ESC_checkSM23 (uint8_t state) _ESCsm2 *SM; ESC_read (ESCREG_SM2, (void *) &ESCvar.SM[2], sizeof (ESCvar.SM[2])); SM = (_ESCsm2 *) & ESCvar.SM[2]; - if ((etohs (SM->PSA) != ESC_SM2_sma) || (etohs (SM->Length) != ESCvar.ESC_SM2_sml) - || (SM->Command != ESC_SM2_smc) || !(SM->ActESC & ESC_SM2_act)) + + /* Check SM settings */ + if ((etohs (SM->PSA) != ESC_SM2_sma) || + (SM->Command != ESC_SM2_smc)) + { + ESCvar.SMtestresult = SMRESULT_ERRSM2; + /* fail state change */ + return (ESCpreop | ESCerror); + } + /* If length > 0 check run-time settings */ + else if ((ESCvar.ESC_SM2_sml > 0) && + ((etohs (SM->Length) != ESCvar.ESC_SM2_sml) || + !(SM->ActESC & ESC_SM2_act))) { ESCvar.SMtestresult = SMRESULT_ERRSM2; /* fail state change */ @@ -701,10 +712,21 @@ uint8_t ESC_checkSM23 (uint8_t state) /* SM2 overlaps SM3, fail state change */ return (ESCpreop | ESCerror); } + ESC_read (ESCREG_SM3, (void *) &ESCvar.SM[3], sizeof (ESCvar.SM[3])); SM = (_ESCsm2 *) & ESCvar.SM[3]; - if ((etohs (SM->PSA) != ESC_SM3_sma) || (etohs (SM->Length) != ESCvar.ESC_SM3_sml) - || (SM->Command != ESC_SM3_smc) || !(SM->ActESC & ESC_SM3_act)) + /* Check SM settings */ + if ((etohs (SM->PSA) != ESC_SM3_sma) || + (SM->Command != ESC_SM3_smc)) + { + ESCvar.SMtestresult = SMRESULT_ERRSM3; + /* fail state change */ + return (ESCpreop | ESCerror); + } + /* If length > 0 check run-time settings */ + else if ((ESCvar.ESC_SM3_sml > 0) && + ((etohs (SM->Length) != ESCvar.ESC_SM3_sml) || + !(SM->ActESC & ESC_SM3_act))) { ESCvar.SMtestresult = SMRESULT_ERRSM3; /* fail state change */ @@ -727,7 +749,12 @@ uint8_t ESC_startinput (uint8_t state) if (state != (ESCpreop | ESCerror)) { - ESC_SMenable (3); + /* If inputs > 0 , enable SM3 */ + if (ESCvar.ESC_SM3_sml > 0) + { + ESC_SMenable (3); + } + /* Go to state input regardless of any inputs present */ CC_ATOMIC_SET(ESCvar.App.state, APPSTATE_INPUT); } else @@ -812,8 +839,13 @@ void ESC_stopinput (void) */ uint8_t ESC_startoutput (uint8_t state) { - - ESC_SMenable (2); + + /* If outputs > 0 , enable SM2 */ + if (ESCvar.ESC_SM2_sml > 0) + { + ESC_SMenable (2); + } + /* Go to state output regardless of any outputs present */ CC_ATOMIC_OR(ESCvar.App.state, APPSTATE_OUTPUT); return state; @@ -1167,6 +1199,11 @@ void ESC_state (void) an = ESCsafeop | ESCerror; ESC_ALerror (ALERR_INVALIDSTATECHANGE); ESC_stopoutput (); + /* If no outputs present, we need to flag error using SM3 */ + if (ESCvar.ESC_SM2_sml == 0 && ESCvar.ESC_SM3_sml > 0) + { + ESC_SMdisable (3); + } break; } case OP_TO_SAFEOP: @@ -1180,6 +1217,11 @@ void ESC_state (void) if (an == ESCop) { ESC_stopoutput (); + /* If no outputs present, we need to flag error using SM3 */ + if (ESCvar.ESC_SM2_sml == 0 && ESCvar.ESC_SM3_sml > 0) + { + ESC_SMdisable (3); + } an = ESCsafeop; } if (as == ESCsafeop)