steps
authoryu.dongliang <18588496441@163.com>
Thu, 20 Jul 2023 06:50:29 +0000 (14:50 +0800)
committeryu.dongliang <18588496441@163.com>
Thu, 20 Jul 2023 06:50:36 +0000 (14:50 +0800)
scf_eda_pb.h
ses_step_battery.c
ses_step_dc_diode.c
ses_step_dc_transistor.c

index 0a30f52d7aaf89069af30530b7567de3ffe96e1c..55f6029930219d4ec2cd58fe55846001bbe9af9b 100644 (file)
@@ -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,
index 2357bc66a09d23705456debbe6263d4d6346a560..11d5144bf564fb6a23a1c659ce267fe8b1798bf1 100644 (file)
@@ -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;
 
index 245af844fa24b2844d048404c884a2b13988427f..4d4e2338f48aa970fdd23ee6381dd1151e137188 100644 (file)
@@ -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);
                }
        }
index 647f86a8795caf5a5057d35d889c8d0ddc5f613c..8c88ec7481d3cfe72f1f44eec04ba8b00c041485 100644 (file)
@@ -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,
 };