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) {
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++;
}
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;
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];
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)
pc->jv = Bp->jv - jv;
}
+ el = f->elines[pc->lid];
el->v = pc->v;
el->jv = pc->jv;
el->a = pc->a;
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;