From a86e57ab119c2b8f6b490d15fdd465aace4ce8ce Mon Sep 17 00:00:00 2001 From: "yu.dongliang" <18588496441@163.com> Date: Tue, 24 Oct 2023 15:07:49 +0800 Subject: [PATCH] ses_step_dc_diode.c ses_step_dc_transistor.c --- scf_eda_pb.h | 2 +- ses_step_dc_diode.c | 94 +++++++++++++++++++++++++++------------- ses_step_dc_transistor.c | 4 +- ses_steps.c | 2 +- 4 files changed, 67 insertions(+), 35 deletions(-) diff --git a/scf_eda_pb.h b/scf_eda_pb.h index 951d1a7..eda39ff 100644 --- a/scf_eda_pb.h +++ b/scf_eda_pb.h @@ -33,7 +33,7 @@ enum { #define SCF_EDA_V_Diode_OFF 0.70 #define SCF_EDA_V_NPN_ON SCF_EDA_V_Diode_OFF -#define SCF_EDA_V_NPN_OFF 0.65 +#define SCF_EDA_V_NPN_OFF 0.60 enum { SCF_EDA_Battery_NEG, diff --git a/ses_step_dc_diode.c b/ses_step_dc_diode.c index 8afef4e..49aeba0 100644 --- a/ses_step_dc_diode.c +++ b/ses_step_dc_diode.c @@ -4,55 +4,89 @@ static int _dc_diode_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx { ScfEcomponent* c; ScfEcomponent* B; - ScfEline* el; - ScfEline* el1; - ScfEpin* p0; - ScfEpin* p1; + ScfEline* lb; + ScfEline* le; + ScfEpin* pb; + ScfEpin* pe; + ScfEpin* Bp; + ScfEpin* Bn; size_t i; size_t j; size_t k; - B = f->components[0]; + B = f->components[0]; + Bp = B->pins[SCF_EDA_Battery_POS]; + Bn = B->pins[SCF_EDA_Battery_NEG]; - for (i = 0; i < f->n_elines; i++) { - el = f->elines[i]; + for (i = 0; i < f->n_components; i++) { + c = f->components[i]; - if (!el->vconst) + if (SCF_EDA_Diode != c->type) continue; - for (j = 0; j + 1 < el->n_pins; j += 2) { + pb = c->pins[SCF_EDA_Diode_POS]; + pe = c->pins[SCF_EDA_Diode_NEG]; - c = f->components[el->pins[j]]; + lb = f->elines[pb->lid]; + le = f->elines[pe->lid]; - if (SCF_EDA_Diode != c->type) + if (__ses_path_neg(f, lb) && !__ses_path_pos(f, lb)) { + c->status = SCF_EDA_Status_OFF; + + scf_loge("Diode c%ld, status: %d\n", c->id, c->status); + continue; + } + + if (lb->v < SCF_EDA_V_MIN) { + + if (le->v < SCF_EDA_V_MIN) continue; - p0 = c->pins[ el->pins[j + 1]]; - p1 = c->pins[!p0->id]; - p0->v = el->v; + pe->v = le->v; + pb->v = le->v + SCF_EDA_V_Diode_ON; + lb->v = pb->v; - if (SCF_EDA_Diode_NEG == p0->id) - p1->v = p0->v + SCF_EDA_V_Diode_ON; - else - p1->v = p0->v - SCF_EDA_V_Diode_ON; + if (le->v == Bn->v) + lb->vconst = 1; - if (p1->v > B->v || p1->v < 0) - c->status = SCF_EDA_Status_OFF; + c->status = SCF_EDA_Status_ON; - else { - el1 = f->elines[p1->lid]; + } else if (le->v < SCF_EDA_V_MIN) { - if (el1->v < SCF_EDA_V_MIN || el1->v >= p1->v) { - el1->v = p1->v; - el1->vconst = 1; - c->status = SCF_EDA_Status_ON; - } else - c->status = SCF_EDA_Status_OFF; - } + pb->v = lb->v; + pe->v = lb->v - SCF_EDA_V_Diode_ON; + le->v = pe->v; - scf_loge("Diode c%ld, status: %d\n", c->id, c->status); + if (lb->v == Bp->v) + le->vconst = 1; + + c->status = SCF_EDA_Status_ON; + + } else if (lb->v >= le->v + SCF_EDA_V_Diode_OFF) { + + if (le->v == Bn->v) { + if (lb->v == Bp->v) { + scf_loge("Diode c%ld, short connected\n", c->id); + return -EINVAL; + } + + lb->vconst = 1; + + } else if (lb->v == Bp->v) + le->vconst = 1; + + lb->v = le->v + SCF_EDA_V_Diode_ON; + pb->v = lb->v; + pe->v = le->v; + + c->status = SCF_EDA_Status_ON; + } else { + c->status = SCF_EDA_Status_OFF; + + scf_logi("Diode c%ld, status: %d, lb->v: %lg, le->v: %lg\n", c->id, c->status, lb->v, le->v); } + scf_loge("\033[34mDiode c%ld, status: %d\033[0m\n", c->id, c->status); } return 0; diff --git a/ses_step_dc_transistor.c b/ses_step_dc_transistor.c index f9a2b3c..156f582 100644 --- a/ses_step_dc_transistor.c +++ b/ses_step_dc_transistor.c @@ -83,11 +83,9 @@ static int _dc_transistor_handler(ScfEfunction* f, int64_t ns, int64_t count, se pe->v = le->v; c->status = SCF_EDA_Status_ON; - } else { + } else c->status = SCF_EDA_Status_OFF; - scf_logi("NPN c%ld, status: %d, lb->v: %lg, le->v: %lg\n", c->id, c->status, lb->v, le->v); - } scf_loge("\033[34mNPN c%ld, status: %d\033[0m\n", c->id, c->status); } diff --git a/ses_steps.c b/ses_steps.c index 31bd711..023125b 100644 --- a/ses_steps.c +++ b/ses_steps.c @@ -29,11 +29,11 @@ static ses_step_t* ses_steps_0[] = &ses_step_battery, &ses_step_dc_input, - &ses_step_dc_diode, }; static ses_step_t* ses_steps_1[] = { + &ses_step_dc_diode, &ses_step_dc_transistor, &ses_step_simplify, -- 2.25.1