{
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;