From 3670be0292747e5e99de43edf3086eb948989443 Mon Sep 17 00:00:00 2001 From: "yu.dongliang" <18588496441@163.com> Date: Mon, 23 Oct 2023 22:15:57 +0800 Subject: [PATCH] __ses_status_check() --- scf_eda_pb.h | 3 +++ ses_core.h | 6 ++--- ses_step_dc_transistor.c | 8 +++---- ses_step_va_balance.c | 51 +++++++--------------------------------- ses_step_va_bridge.c | 4 ++-- ses_step_va_transistor.c | 29 +++++++++++++++-------- 6 files changed, 40 insertions(+), 61 deletions(-) diff --git a/scf_eda_pb.h b/scf_eda_pb.h index 5fdb4ba..379270b 100644 --- a/scf_eda_pb.h +++ b/scf_eda_pb.h @@ -32,6 +32,9 @@ enum { #define SCF_EDA_V_Diode_ON 0.69 #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 + enum { SCF_EDA_Battery_NEG, SCF_EDA_Battery_POS, diff --git a/ses_core.h b/ses_core.h index 89ae3c5..9985095 100644 --- a/ses_core.h +++ b/ses_core.h @@ -117,11 +117,11 @@ int ses_steps_analyse(ScfEfunction* f, int64_t ns, int64_t count); void __ses_path_split_i(ScfEfunction* f, ses_path_t* path, int i, int j, double la, double jla, double* a, double* ja); void __ses_path_pr (ScfEfunction* f, ses_path_t* path, int i, int j, ScfEpin* cp1, double* r, double* jr); void __ses_path_sr (ScfEfunction* f, ses_path_t* path, int i, int j, ScfEpin* cp1, double* r, double* jr); -int __ses_path_pos (ScfEfunction* f, ScfEline* el); -int __ses_path_neg (ScfEfunction* f, ScfEline* el); int __ses_path_va (ScfEfunction* f, ses_path_t* path); +int __ses_path_pos (ScfEfunction* f, ScfEline* el); +int __ses_path_neg (ScfEfunction* f, ScfEline* el); -int __ses_status_check(ScfEcomponent* c, ScfEpin* pb, ScfEpin* pe, ScfEpin* Bn); +int __ses_status_check(ScfEfunction* f, ScfEcomponent* c, ScfEpin* pb, ScfEpin* pe); static inline void vertical(int* px, int* py, int dx, int dy, int d) { diff --git a/ses_step_dc_transistor.c b/ses_step_dc_transistor.c index ccf5863..6bcba87 100644 --- a/ses_step_dc_transistor.c +++ b/ses_step_dc_transistor.c @@ -46,7 +46,7 @@ static int _dc_transistor_handler(ScfEfunction* f, int64_t ns, int64_t count, se continue; pe->v = le->v; - pb->v = le->v + SCF_EDA_V_Diode_ON; + pb->v = le->v + SCF_EDA_V_NPN_ON; lb->v = pb->v; if (le->v == Bn->v) @@ -57,7 +57,7 @@ static int _dc_transistor_handler(ScfEfunction* f, int64_t ns, int64_t count, se } else if (le->v < SCF_EDA_V_MIN) { pb->v = lb->v; - pe->v = lb->v - SCF_EDA_V_Diode_ON; + pe->v = lb->v - SCF_EDA_V_NPN_ON; le->v = pe->v; if (lb->v == Bp->v) @@ -65,7 +65,7 @@ static int _dc_transistor_handler(ScfEfunction* f, int64_t ns, int64_t count, se c->status = SCF_EDA_Status_ON; - } else if (lb->v >= le->v + SCF_EDA_V_Diode_OFF) { + } else if (lb->v >= le->v + SCF_EDA_V_NPN_OFF) { if (le->v == Bn->v) { if (lb->v == Bp->v) { @@ -78,7 +78,7 @@ static int _dc_transistor_handler(ScfEfunction* f, int64_t ns, int64_t count, se } else if (lb->v == Bp->v) le->vconst = 1; - lb->v = le->v + SCF_EDA_V_Diode_ON; + lb->v = le->v + SCF_EDA_V_NPN_ON; pb->v = lb->v; pe->v = le->v; diff --git a/ses_step_va_balance.c b/ses_step_va_balance.c index a85ea45..f298c0a 100644 --- a/ses_step_va_balance.c +++ b/ses_step_va_balance.c @@ -70,7 +70,6 @@ static void inline __ses_bridge_i(double* i0, double* i1, double* i2, double* i3 static size_t __ses_line_update(ScfEfunction* f, ScfEline* el) { ScfEcomponent* c; - ScfEline* el2; ScfEpin* p; ScfEpin* p2; @@ -87,57 +86,25 @@ static size_t __ses_line_update(ScfEfunction* f, ScfEline* el) if (SCF_EDA_Diode_POS == p->id) { - p2 = c->pins[SCF_EDA_Diode_NEG]; - el2 = f->elines[p2->lid]; - p2->v = el2->v; - - if (p->v - p2->v < SCF_EDA_V_Diode_ON) { - c->status = SCF_EDA_Status_OFF; - n++; - - scf_loge("c%ld off, p%ld->v: %lg, p%ld->v: %lg, diff: %lg\n", c->id, p->id, p->v, p2->id, p2->v, p->v - p2->v); - } + p2 = c->pins[SCF_EDA_Diode_NEG]; + n += __ses_status_check(f, c, p, p2); } else { - p2 = c->pins[SCF_EDA_Diode_POS]; - el2 = f->elines[p2->lid]; - p2->v = el2->v; - - if (p2->v - p->v < SCF_EDA_V_Diode_ON) { - c->status = SCF_EDA_Status_OFF; - n++; - - scf_loge("c%ld off, p%ld->v: %lg, p%ld->v: %lg, diff: %lg\n", c->id, p->id, p->v, p2->id, p2->v, p2->v - p->v); - } + p2 = c->pins[SCF_EDA_Diode_POS]; + n += __ses_status_check(f, c, p2, p); } } else if (SCF_EDA_NPN == c->type) { if (SCF_EDA_NPN_B == p->id) { - p2 = c->pins[SCF_EDA_NPN_E]; - el2 = f->elines[p2->lid]; - p2->v = el2->v; - - if (p->v - p2->v < SCF_EDA_V_Diode_ON) { - c->status = SCF_EDA_Status_OFF; - n++; - - scf_loge("c%ld off, p%ld->v: %lg, p%ld->v: %lg, diff: %lg\n", c->id, p->id, p->v, p2->id, p2->v, p->v - p2->v); - } + p2 = c->pins[SCF_EDA_NPN_E]; + n += __ses_status_check(f, c, p, p2); } else if (SCF_EDA_NPN_E == p->id) { - p2 = c->pins[SCF_EDA_NPN_B]; - el2 = f->elines[p2->lid]; - p2->v = el2->v; - - if (p2->v - p->v < SCF_EDA_V_Diode_ON) { - c->status = SCF_EDA_Status_OFF; - n++; - - scf_loge("c%ld off, p%ld->v: %lg, p%ld->v: %lg, diff: %lg\n", c->id, p->id, p->v, p2->id, p2->v, p2->v - p->v); - } + p2 = c->pins[SCF_EDA_NPN_B]; + n += __ses_status_check(f, c, p2, p); } } } @@ -182,7 +149,7 @@ static int __ses_path_va_balance(ScfEfunction* f, ses_path_t* bridge, ses_flow_t p1->v = el->v; p1->jv = el->jv; - scf_loge("p0: %lg, p1: %lg, bridge->r: %lg\n", p0->v, p1->v, bridge->r); + scf_loge("p0: %lg, p1: %lg, diff: %lg, bridge->r: %lg\n", p0->v, p1->v, p0->v - p1->v, bridge->r); if (p0->v > p1->v) { diff --git a/ses_step_va_bridge.c b/ses_step_va_bridge.c index 00254cc..2354fa4 100644 --- a/ses_step_va_bridge.c +++ b/ses_step_va_bridge.c @@ -53,7 +53,7 @@ static int __ses_path_va_bridge(ScfEfunction* f, ses_path_t* path, int* changed) if (SCF_EDA_NPN_B == p0->id) { p1 = c->pins[SCF_EDA_NPN_E]; - *changed += __ses_status_check(c, p0, p1, Bn); + *changed += __ses_status_check(f, c, p0, p1); } } else if (SCF_EDA_Diode == c->type) { @@ -61,7 +61,7 @@ static int __ses_path_va_bridge(ScfEfunction* f, ses_path_t* path, int* changed) if (SCF_EDA_Diode_POS == p0->id) { p1 = c->pins[SCF_EDA_Diode_NEG]; - *changed += __ses_status_check(c, p0, p1, Bn); + *changed += __ses_status_check(f, c, p0, p1); } } } diff --git a/ses_step_va_transistor.c b/ses_step_va_transistor.c index 26d4503..ec93c57 100644 --- a/ses_step_va_transistor.c +++ b/ses_step_va_transistor.c @@ -22,10 +22,21 @@ void __ses_path_dr_transistor(ScfEfunction* f, ses_path_t* path, int i, int j) p->cid, p->id, v, r, p->sr, p->a, p->dr); } -int __ses_status_check(ScfEcomponent* c, ScfEpin* pb, ScfEpin* pe, ScfEpin* Bn) +int __ses_status_check(ScfEfunction* f, ScfEcomponent* c, ScfEpin* pb, ScfEpin* pe) { + ScfEcomponent* B = f->components[0]; + ScfEpin* Bn = B->pins[SCF_EDA_Battery_NEG]; + + double DV = SCF_EDA_V_NPN_OFF; + + if (SCF_EDA_Diode == c->type) + DV = SCF_EDA_V_Diode_ON; + + pb->v = f->elines[pb->lid]->v; + pe->v = f->elines[pe->lid]->v; + if (pe->v < SCF_EDA_V_MIN) { - pe->v = pb->v - SCF_EDA_V_Diode_ON; + pe->v = pb->v - DV; if (pe->v < Bn->v) { pe->v = Bn->v; @@ -33,19 +44,19 @@ int __ses_status_check(ScfEcomponent* c, ScfEpin* pb, ScfEpin* pe, ScfEpin* Bn) } else c->status = SCF_EDA_Status_ON; - scf_loge("c%ld, status: %d\n", c->id, c->status); + scf_loge("\033[34mc%ld, status: %d\033[0m\n", c->id, c->status); return 1; - } else if (pb->v - pe->v < SCF_EDA_V_Diode_ON) { + } else if (pb->v - pe->v < DV) { if (c->status != SCF_EDA_Status_OFF) { c->status = SCF_EDA_Status_OFF; - scf_loge("c%ld, status: %d\n", c->id, c->status); + scf_loge("\033[34mc%ld, status: %d\033[0m\n", c->id, c->status); return 1; } } else if (SCF_EDA_Status_ON != c->status) { c->status = SCF_EDA_Status_ON; - scf_loge("c%ld, status: %d\n", c->id, c->status); + scf_loge("\033[34mc%ld, status: %d\033[0m\n", c->id, c->status); return 1; } @@ -73,13 +84,11 @@ static int __ses_status_change(ScfEfunction* f, ScfEline* el) c = f->components[el->pins[j]]; p = c->pins [el->pins[j + 1]]; - p->v = el->v; - if (SCF_EDA_NPN == c->type) { if (SCF_EDA_NPN_B == p->id) { pe = c->pins[SCF_EDA_NPN_E]; - changed += __ses_status_check(c, p, pe, Bn); + changed += __ses_status_check(f, c, p, pe); } } else if (SCF_EDA_Diode == c->type) { @@ -87,7 +96,7 @@ static int __ses_status_change(ScfEfunction* f, ScfEline* el) if (SCF_EDA_Diode_POS == p->id) { pe = c->pins[SCF_EDA_Diode_NEG]; - changed += __ses_status_check(c, p, pe, Bn); + changed += __ses_status_check(f, c, p, pe); } } } -- 2.25.1