From: yu.dongliang <18588496441@163.com> Date: Thu, 20 Jul 2023 06:50:29 +0000 (+0800) Subject: steps X-Git-Url: http://baseworks.info/?a=commitdiff_plain;h=08fbb6bcacedd7ca1fb2b635399dcf6fbacabe59;p=ses.git steps --- diff --git a/scf_eda_pb.h b/scf_eda_pb.h index 0a30f52..55f6029 100644 --- a/scf_eda_pb.h +++ b/scf_eda_pb.h @@ -23,6 +23,10 @@ enum { #define SCF_EDA_PIN_POS 4 #define SCF_EDA_PIN_NEG 8 +#define SCF_EDA_V_INIT -10001001.0 +#define SCF_EDA_V_MIN -10000000.0 +#define SCF_EDA_V_MAX 10000000.0 + enum { SCF_EDA_Battery_NEG, SCF_EDA_Battery_POS, diff --git a/ses_step_battery.c b/ses_step_battery.c index 2357bc6..11d5144 100644 --- a/ses_step_battery.c +++ b/ses_step_battery.c @@ -7,17 +7,22 @@ static int _battery_handler(ScfEfunction* f, int64_t ns, int64_t count) ScfEpin* p; size_t i; - size_t j; - size_t k; + + for (i = 0; i < f->n_elines; i++) { + el = f->elines[i]; + el->v = SCF_EDA_V_INIT; + } c = f->components[0]; c->v = 6; p = c->pins[SCF_EDA_Battery_POS]; + p->v = 6; el = f->elines[p->lid]; el->v = 6; p = c->pins[SCF_EDA_Battery_NEG]; + p ->v = 0; el = f->elines[p->lid]; el->v = 0; diff --git a/ses_step_dc_diode.c b/ses_step_dc_diode.c index 245af84..4d4e233 100644 --- a/ses_step_dc_diode.c +++ b/ses_step_dc_diode.c @@ -5,6 +5,7 @@ static int _dc_diode_handler(ScfEfunction* f, int64_t ns, int64_t count) ScfEcomponent* c; ScfEcomponent* B; ScfEline* el; + ScfEline* el1; ScfEpin* p0; ScfEpin* p1; @@ -13,7 +14,6 @@ static int _dc_diode_handler(ScfEfunction* f, int64_t ns, int64_t count) size_t k; B = f->components[0]; - k = 0; for (i = 0; i < f->n_elines; i++) { el = f->elines[i]; @@ -40,6 +40,16 @@ static int _dc_diode_handler(ScfEfunction* f, int64_t ns, int64_t count) if (p1->v > B->v || p1->v < 0) c->status = SCF_EDA_Status_OFF; + else { + el1 = f->elines[p1->lid]; + + if (el1->v < SCF_EDA_V_MIN || el1->v > p1->v) { + el1->v = p1->v; + c->status = SCF_EDA_Status_ON; + } else + c->status = SCF_EDA_Status_OFF; + } + scf_loge("Diode c%ld, status: %d\n", c->id, c->status); } } diff --git a/ses_step_dc_transistor.c b/ses_step_dc_transistor.c index 647f86a..8c88ec7 100644 --- a/ses_step_dc_transistor.c +++ b/ses_step_dc_transistor.c @@ -1,8 +1,57 @@ #include"ses_core.h" +static int _dc_transistor_handler(ScfEfunction* f, int64_t ns, int64_t count) +{ + ScfEcomponent* c; + ScfEcomponent* B; + ScfEline* el; + ScfEpin* pb; + ScfEpin* pc; + ScfEpin* pe; + + size_t i; + size_t j; + size_t k; + + B = f->components[0]; + + for (i = 0; i < f->n_components; i++) { + c = f->components[i]; + + if (SCF_EDA_Transistor != c->type) + continue; + + pb = c->pins[SCF_EDA_Transistor_B]; + pc = c->pins[SCF_EDA_Transistor_C]; + pe = c->pins[SCF_EDA_Transistor_E]; + + el = f->elines[pe->lid]; + if (el->v < SCF_EDA_V_MIN) + continue; + pe->v = el->v; + + el = f->elines[pb->lid]; + if (el->v < SCF_EDA_V_MIN) + continue; + pb->v = el->v; + + if (pb->v > pe->v + 0.7) { + pb->v = pe->v + 0.7; + el->v = pb->v; + + c->status = SCF_EDA_Status_ON; + } else + c->status = SCF_EDA_Status_OFF; + + scf_loge("Transistor c%ld, status: %d\n", c->id, c->status); + } + + return 0; +} -ses_step_t ses_step_dc_transistor = +ses_step_t ses_step_dc_transistor = { - .name = "dc_transistor", + .name = "dc_transistor", + .handler = _dc_transistor_handler, };