diff --git a/src/spicelib/devices/csw/cswload.c b/src/spicelib/devices/csw/cswload.c index 5de4e4250..cd6c0d021 100644 --- a/src/spicelib/devices/csw/cswload.c +++ b/src/spicelib/devices/csw/cswload.c @@ -12,6 +12,20 @@ Modified: 2001 Jon Engelbert #include "ngspice/sperror.h" #include "ngspice/suffix.h" +static void +verify(int state, char *msg) +{ + switch (state) { + case REALLY_ON: + case REALLY_OFF: + case HYST_ON: + case HYST_OFF: + break; + default: + internalerror(msg); + } +} + int CSWload(GENmodel *inModel, CKTcircuit *ckt) @@ -66,15 +80,15 @@ CSWload(GENmodel *inModel, CKTcircuit *ckt) /* in hysteresis... change value if going from low to hysteresis, * or from hi to hysteresis. */ + verify(previous_state, "bad value for previous_state in swload"); + /* if previous state was in hysteresis, then don't change the state.. */ - if (previous_state == HYST_OFF || previous_state == HYST_ON) - current_state = previous_state; + if (previous_state == REALLY_ON) + current_state = HYST_ON; else if (previous_state == REALLY_OFF) current_state = HYST_OFF; - else if (previous_state == REALLY_ON) - current_state = HYST_ON; else - internalerror("bad value for previous region in swload"); + current_state = previous_state; } if ((current_state == REALLY_ON || current_state == HYST_ON) != (old_current_state == REALLY_ON || old_current_state == HYST_ON)) { @@ -95,15 +109,15 @@ CSWload(GENmodel *inModel, CKTcircuit *ckt) /* in hysteresis... change value if going from low to hysteresis, * or from hi to hysteresis. */ + verify(previous_state, "bad value for previous_state in cswload"); + /* if previous state was in hysteresis, then don't change the state.. */ - if (previous_state == HYST_OFF || previous_state == HYST_ON) - current_state = previous_state; - else if (previous_state == REALLY_ON) + if (previous_state == REALLY_ON) current_state = HYST_ON; else if (previous_state == REALLY_OFF) current_state = HYST_OFF; else - internalerror("bad value for previous region in cswload"); + current_state = previous_state; } } diff --git a/src/spicelib/devices/sw/swload.c b/src/spicelib/devices/sw/swload.c index 35df5a13b..f1e267508 100644 --- a/src/spicelib/devices/sw/swload.c +++ b/src/spicelib/devices/sw/swload.c @@ -12,6 +12,20 @@ Modified: 2001 Jon Engelbert #include "ngspice/sperror.h" #include "ngspice/suffix.h" +static void +verify(int state, char *msg) +{ + switch (state) { + case REALLY_ON: + case REALLY_OFF: + case HYST_ON: + case HYST_OFF: + break; + default: + internalerror(msg); + } +} + int SWload(GENmodel *inModel, CKTcircuit *ckt) @@ -70,15 +84,16 @@ SWload(GENmodel *inModel, CKTcircuit *ckt) current_state = old_current_state; } else { // in hysteresis... change value if going from low to hysteresis, or from hi to hysteresis. + + verify(previous_state, "bad value for previous_state in swload"); + // if previous state was in hysteresis, then don't change the state.. - if (previous_state == HYST_OFF || previous_state == HYST_ON) - current_state = previous_state; - else if (previous_state == REALLY_ON) + if (previous_state == REALLY_ON) current_state = HYST_ON; else if (previous_state == REALLY_OFF) current_state = HYST_OFF; else - internalerror("bad value for previous state in swload"); + current_state = previous_state; } if ((current_state == REALLY_ON || current_state == HYST_ON) != (old_current_state == REALLY_ON || old_current_state == HYST_ON)) { @@ -96,12 +111,15 @@ SWload(GENmodel *inModel, CKTcircuit *ckt) if (model->SWvHysteresis > 0) { current_state = previous_state; } else { - if (previous_state == HYST_ON || previous_state == HYST_OFF) - current_state = previous_state; - else if (previous_state == REALLY_ON) + + verify(previous_state, "bad value for previous_state in swload"); + + if (previous_state == REALLY_ON) current_state = HYST_ON; else if (previous_state == REALLY_OFF) current_state = HYST_OFF; + else + current_state = previous_state; } }