ses_step_va_transistor.c
authoryu.dongliang <18588496441@163.com>
Thu, 19 Oct 2023 15:24:30 +0000 (23:24 +0800)
committeryu.dongliang <18588496441@163.com>
Thu, 19 Oct 2023 15:24:30 +0000 (23:24 +0800)
ses_layout.c
ses_step_va_transistor.c
ses_steps.c

index 8171d5e918e6cfaa83260d92e66378247968a641..2dedeb1bf5c6fd602cb3aa36ac170b5b365996b8 100644 (file)
@@ -230,7 +230,7 @@ next:
                el->c_pins = el->n_pins;
                el->id     = i;
 
-               scf_logw("line i: %ld, %p, el->flags: %#lx\n", i, el, el->flags);
+               scf_logd("line i: %ld, %p, el->flags: %#lx\n", i, el, el->flags);
 
                for (j = 0; j + 1 < el->n_pins; j += 2) {
 
@@ -240,9 +240,9 @@ next:
                        p->lid   = i;
                        p->c_lid = i;
 
-                       scf_logi("pin j: %ld, c%ldp%ld\n", j, el->pins[j], el->pins[j + 1]);
+                       scf_logd("pin j: %ld, c%ldp%ld\n", j, el->pins[j], el->pins[j + 1]);
                }
-               printf("\n");
+//             printf("\n");
 
                i++;
        }
index 26cde5b71ac2c883821ab18f1821e8937b54bf90..66c38ff1cb726285b6d814a37c3fff98e8604882 100644 (file)
@@ -18,10 +18,83 @@ void __ses_path_dr_transistor(ScfEfunction* f, ses_path_t* path, int i, int j)
        p->dr  -= r;
        p->jdr -= jr;
 
-       scf_logi("c%ldp%ld, v: %lg, r: %lg, p->sr: %lg, p->a: %lg, p->dr: %lg\n",
+       scf_logd("c%ldp%ld, v: %lg, r: %lg, p->sr: %lg, p->a: %lg, p->dr: %lg\n",
                        p->cid, p->id, v, r, p->sr, p->a, p->dr);
 }
 
+static int __ses_status_check(ScfEcomponent* c, ScfEpin* pb, ScfEpin* pe, ScfEpin* Bn)
+{
+       if (pe->v < SCF_EDA_V_MIN) {
+               pe->v = pb->v - SCF_EDA_V_Diode_ON;
+
+               if (pe->v < Bn->v) {
+                       pe->v = Bn->v;
+                       c->status = SCF_EDA_Status_OFF;
+               } else
+                       c->status = SCF_EDA_Status_ON;
+
+               scf_loge("c%ld, status: %d\n", c->id, c->status);
+               return 1;
+
+       } else if (pb->v - pe->v < SCF_EDA_V_Diode_ON) {
+
+               if (c->status != SCF_EDA_Status_OFF) {
+                       c->status  = SCF_EDA_Status_OFF;
+                       scf_loge("c%ld, status: %d\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);
+               return 1;
+       }
+
+       return 0;
+}
+
+static int __ses_status_change(ScfEfunction* f, ScfEline* el)
+{
+       ScfEcomponent* c;
+       ScfEcomponent* B;
+       ScfEpin*       Bp;
+       ScfEpin*       Bn;
+       ScfEpin*       p;
+       ScfEpin*       pe;
+
+       size_t j;
+       int    changed = 0;
+
+       B  = f->components[0];
+       Bp = B->pins[SCF_EDA_Battery_POS];
+       Bn = B->pins[SCF_EDA_Battery_NEG];
+
+       for (j = 0; j + 1 < el->n_pins; j += 2) {
+
+               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);
+                       }
+
+               } else if (SCF_EDA_Diode  == c->type) {
+
+                       if (SCF_EDA_Diode_POS == p->id) {
+
+                               pe       = c->pins[SCF_EDA_Diode_NEG];
+                               changed += __ses_status_check(c, p, pe, Bn);
+                       }
+               }
+       }
+
+       return changed;
+}
+
 static int __ses_path_va_transistor(ScfEfunction* f, ses_path_t* path, int* changed)
 {
        ses_path_t*    parent = path->parent;
@@ -36,13 +109,7 @@ static int __ses_path_va_transistor(ScfEfunction* f, ses_path_t* path, int* chan
        ScfEpin*       Bn;
 
        ScfEpin*       p;
-       ScfEpin*       pb;
        ScfEpin*       pc;
-       ScfEpin*       pe;
-
-       int i;
-       int j;
-       int k;
 
        B  = f->components[0];
        Bp = B->pins[SCF_EDA_Battery_POS];
@@ -64,10 +131,11 @@ static int __ses_path_va_transistor(ScfEfunction* f, ses_path_t* path, int* chan
        p1->v  = el->v;
        p1->jv = el->jv;
 
+       int i;
+
        for (i = 0; i < path->pins->size - 1; i++) {
                pc =        path->pins->data[i];
 
-               el = f->elines    [pc->lid];
                c  = f->components[pc->cid];
 
                if (SCF_EDA_NPN != c->type)
@@ -116,6 +184,7 @@ static int __ses_path_va_transistor(ScfEfunction* f, ses_path_t* path, int* chan
                        pc->jv = Bp->jv - jv;
                }
 
+               el     = f->elines[pc->lid];
                el->v  = pc->v;
                el->jv = pc->jv;
                el->a  = pc->a;
@@ -135,6 +204,8 @@ static int __ses_path_va_transistor(ScfEfunction* f, ses_path_t* path, int* chan
 
                scf_loge("i: %d, c%ldp%ld--c%ldp%ld, v: %lg, pc->v: %lg, pc->a: %lg, pr: %lg, pc->dr: %lg\n\n",
                                i, p0->cid, p0->id, pc->cid, pc->id, v, pc->v, pc->a, pr, pc->dr);
+
+               *changed += __ses_status_change(f, el);
        }
 
        return 0;
index 203a4799d976f294db712966cb2882146f90ea2b..92534ba383dc7e6b565a92fcfdb98c20a2ea5041 100644 (file)
@@ -137,7 +137,8 @@ int ses_steps_analyse(ScfEfunction* f, int64_t ns, int64_t count)
                if (ret < 0)
                        return ret;
 
-               while (1) {
+               int j;
+               for (j = 0; j < 2; j++) {
                        ret = __ses_steps_analyse(f, ns, i, ctx);
 
                        if (-EAGAIN == ret)