#include"ses_core.h"
+int __dfs_path_pos(ScfEfunction* f, ScfEline* el)
+{
+ ScfEcomponent* c;
+ ScfEcomponent* c2;
+ ScfEline* el2;
+ ScfEpin* p;
+ ScfEpin* p2;
+
+ size_t i;
+ size_t j;
+
+ if (SCF_EDA_PIN_POS & el->flags)
+ return 1;
+ if (SCF_EDA_PIN_NEG & el->flags)
+ return 0;
+
+ for (i = 0; i + 1 < el->n_pins; i += 2) {
+
+ c = f->components[el->pins[i]];
+ p = c->pins [el->pins[i + 1]];
+
+ if (p->vflag)
+ continue;
+ p->vflag = 1;
+
+ if (SCF_EDA_Diode == c->type) {
+
+ if (SCF_EDA_Diode_POS == p->id || SCF_EDA_Status_OFF == c->status)
+ continue;
+
+ p2 = c->pins[SCF_EDA_Diode_POS];
+
+ } else if (SCF_EDA_NPN == c->type) {
+
+ if (SCF_EDA_NPN_E != p->id || SCF_EDA_Status_OFF == c->status)
+ continue;
+
+ p2 = c->pins[SCF_EDA_NPN_B];
+ p2->vflag = 1;
+
+ if (__dfs_path_pos(f, f->elines[p2->lid]))
+ return 1;
+
+ p2 = c->pins[SCF_EDA_NPN_C];
+ p2->vflag = 1;
+
+ if (__dfs_path_pos(f, f->elines[p2->lid]))
+ return 1;
+
+ continue;
+ } else
+ p2 = c->pins[!p->id];
+
+ if (p2->vflag)
+ continue;
+ p2->vflag = 1;
+
+ if (__dfs_path_pos(f, f->elines[p2->lid]))
+ return 1;
+ }
+
+ return 0;
+}
+
+int __dfs_path_neg(ScfEfunction* f, ScfEline* el)
+{
+ ScfEcomponent* c;
+ ScfEpin* p;
+ ScfEpin* p2;
+
+ size_t i;
+ size_t j;
+
+ if (SCF_EDA_PIN_NEG & el->flags)
+ return 1;
+ if (SCF_EDA_PIN_POS & el->flags)
+ return 0;
+
+ for (i = 0; i + 1 < el->n_pins; i += 2) {
+
+ c = f->components[el->pins[i]];
+ p = c->pins [el->pins[i + 1]];
+
+ if (p->vflag)
+ continue;
+ p->vflag = 1;
+
+ if (SCF_EDA_Diode == c->type) {
+
+ if (SCF_EDA_Diode_NEG == p->id || SCF_EDA_Status_OFF == c->status)
+ continue;
+ p2 = c->pins[SCF_EDA_Diode_NEG];
+
+ } else if (SCF_EDA_NPN == c->type) {
+
+ if (SCF_EDA_NPN_E == p->id || SCF_EDA_Status_OFF == c->status)
+ continue;
+ p2 = c->pins[SCF_EDA_NPN_E];
+ } else
+ p2 = c->pins[!p->id];
+
+ if (p2->vflag)
+ continue;
+ p2->vflag = 1;
+
+ if (__dfs_path_neg(f, f->elines[p2->lid]))
+ return 1;
+ }
+
+ return 0;
+}
+
+int dfs_path_pos(ScfEfunction* f, ScfEline* el)
+{
+ ScfEcomponent* c;
+ ScfEpin* p;
+
+ size_t i;
+ size_t j;
+
+ for (i = 0; i < f->n_components; i++) {
+ c = f->components[i];
+
+ for (j = 0; j < c->n_pins; j++) {
+ p = c->pins[j];
+ p->vflag = 0;
+ }
+ }
+
+ return __dfs_path_pos(f, el);
+}
+
+int dfs_path_neg(ScfEfunction* f, ScfEline* el)
+{
+ ScfEcomponent* c;
+ ScfEpin* p;
+
+ size_t i;
+ size_t j;
+
+ for (i = 0; i < f->n_components; i++) {
+ c = f->components[i];
+
+ for (j = 0; j < c->n_pins; j++) {
+ p = c->pins[j];
+ p->vflag = 0;
+ }
+ }
+
+ return __dfs_path_neg(f, el);
+}
+
static int _output_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx)
{
- ScfEline* el;
+ ScfEcomponent* B = f->components[0];
+ ScfEpin* Bp = B->pins[SCF_EDA_Battery_POS];
+ ScfEpin* Bn = B->pins[SCF_EDA_Battery_NEG];
+ ScfEline* el;
size_t i;
for (i = 0; i < f->n_elines; i++) {
el = f->elines[i];
- if (SCF_EDA_PIN_OUT & el->flags)
+ if (SCF_EDA_PIN_OUT & el->flags) {
+
+ if (dfs_path_pos(f, el)) {
+
+ if (!dfs_path_neg(f, el))
+ el->v = Bp->v;
+
+ } else if (dfs_path_neg(f, el))
+ el->v = Bn->v;
+ else
+ return -EINVAL;
+
scf_logw("IN el: %ld, V: %lg\n", el->id, el->v);
+ }
}
return 0;