ses_step_va_bridge.c
authoryu.dongliang <18588496441@163.com>
Mon, 23 Oct 2023 03:41:34 +0000 (11:41 +0800)
committeryu.dongliang <18588496441@163.com>
Mon, 23 Oct 2023 03:41:34 +0000 (11:41 +0800)
Makefile
ses_core.h
ses_step_va.c
ses_step_va_bridge.c [new file with mode: 0644]
ses_steps.c

index 7314e59fce11455e8bf0967bf0d7d91fa77351f6..bc29d8590c75d711e6656f7e95d918e80ae5937a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -17,6 +17,7 @@ CFILES += ses_step_jr.c
 CFILES += ses_step_va_diode.c
 CFILES += ses_step_va_transistor.c
 CFILES += ses_step_va.c 
+CFILES += ses_step_va_bridge.c
 CFILES += ses_step_va_balance.c
 CFILES += ses_step_output.c
 
index 8ab38346f8de418fffc3f36d46a931300e39cb79..e482331050c217d4eb242fa9f27cab105298585b 100644 (file)
@@ -119,6 +119,7 @@ void __ses_path_pr     (ScfEfunction* f, ses_path_t* path, int i, int j, ScfEpin
 void __ses_path_sr     (ScfEfunction* f, ses_path_t* path, int i, int j, ScfEpin* cp1, double* r, double* jr);
 int  __ses_path_pos    (ScfEfunction* f, ScfEline* el);
 int  __ses_path_neg    (ScfEfunction* f, ScfEline* el);
+int  __ses_path_va     (ScfEfunction* f, ses_path_t* path);
 
 static inline void vertical(int* px, int* py, int dx, int dy, int d)
 {
index 917f09945347f2d6e7c65a813c9f998ae2932d87..70e6c195d50ba05fa1e276bca90a800568be2688 100644 (file)
@@ -2,8 +2,6 @@
 
 int _ses_path_cmp(const void* v0, const void* v1);
 
-static int __ses_path_va(ScfEfunction* f, ses_path_t* path);
-
 static int __ses_path_split_a(ScfEfunction* f, ses_path_t* path, int i, double* a, double *ja)
 {
        ses_path_t*    child;
@@ -98,6 +96,9 @@ static int __ses_path_split_v(ScfEfunction* f, ses_path_t* path, ScfEpin* p0, in
                        r  = p->sr  - (p->r  + p->dr ) - p0->sr;
                        jr = p->jsr - (p->jr + p->jdr) - p0->jsr;
 
+                       scf_logi("c%ldp%ld-c%ldp%ld, p->sr: %lg, p->r: %lg, p->dr: %lg, p0->sr: %lg\n",
+                                       p0->cid, p0->id, p->cid, p->id, p->sr, p->r, p->dr, p0->sr);
+
                } else if (i >= 1) {
                        p2 = path->pins->data[i - 1];
 
@@ -121,11 +122,11 @@ static int __ses_path_split_v(ScfEfunction* f, ses_path_t* path, ScfEpin* p0, in
        p->v  = p0->v  - v;
        p->jv = p0->jv - jv;
 
-       scf_logd("c%ldp%ld, c%ldp%ld, a: %lg, r: %lg, v: %lg\n", p0->cid, p0->id, p->cid, p->id, a, r, v);
+       scf_logi("c%ldp%ld, c%ldp%ld, a: %lg, r: %lg, v: %lg\n", p0->cid, p0->id, p->cid, p->id, a, r, v);
        return 0;
 }
 
-static int __ses_path_va(ScfEfunction* f, ses_path_t* path)
+int __ses_path_va(ScfEfunction* f, ses_path_t* path)
 {
        if (!path)
                return -EINVAL;
@@ -270,7 +271,7 @@ static int _va_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ct
        for (i = 0; i < ctx->paths->size; i++) {
                path      = ctx->paths->data[i];
 
-               scf_logi("i: %d, path->type: %d\n", i, path->type);
+               scf_logi("i: %d, path->index: %d\n", i, path->index);
 
                if (path->pins->size < 2) {
                        scf_loge("\n");
diff --git a/ses_step_va_bridge.c b/ses_step_va_bridge.c
new file mode 100644 (file)
index 0000000..ab89ae3
--- /dev/null
@@ -0,0 +1,94 @@
+#include"ses_core.h"
+
+static int __ses_path_va_bridge(ScfEfunction* f, ses_path_t* path, int* changed)
+{
+       if (!path)
+               return -EINVAL;
+
+       if (path->pins->size < 2) {
+               scf_loge("\n");
+               return -EINVAL;
+       }
+
+       ses_path_t*    child;
+       ScfEcomponent* c;
+       ScfEline*      el;
+       ScfEpin*       p0;
+       ScfEpin*       p1;
+
+       p0 = path->pins->data[0];
+       p1 = path->pins->data[path->pins->size - 1];
+
+       el     = f->elines[p0->lid];
+       p0->v  = el->v;
+       p0->jv = el->jv;
+
+       el     = f->elines[p1->lid];
+       p1->v  = el->v;
+       p1->jv = el->jv;
+
+       double v  = p0->v  - p1->v;
+       double jv = p0->jv - p1->jv;
+
+       scf_logw("path: %d, c%ldp%ld--c%ldp%ld, v: %lg, p0->v: %lg, p1->v: %lg, n_diodes: %d\n",
+                       path->index, p0->cid, p0->id, p1->cid, p1->id, v, p0->v, p1->v, path->n_diodes);
+
+       int ret = __ses_path_va(f, path);
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+
+static int ses_path_va_bridge(ScfEfunction* f, ses_path_t* path, int* changed)
+{
+       ses_path_t* child;
+
+       size_t j;
+
+       if (!path)
+               return -EINVAL;
+
+       if (path->bridges) {
+               for (j = 0; j < path->bridges->size; j++) {
+                       child     = path->bridges->data[j];
+
+                       int ret = __ses_path_va_bridge(f, child, changed);
+                       if (ret < 0)
+                               return ret;
+
+                       ret = ses_path_va_bridge(f, child, changed);
+                       if (ret < 0)
+                               return ret;
+               }
+       }
+
+       return 0;
+}
+
+static int _va_bridge_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx)
+{
+       ses_path_t* path;
+
+       int changed = 0;
+       int i;
+
+       for (i = 0; i < ctx->paths->size; i++) {
+               path      = ctx->paths->data[i];
+
+               int ret = ses_path_va_bridge(f, path, &changed);
+               if (ret < 0)
+                       return ret;
+
+               printf("\n");
+       }
+
+       return changed > 0 ? -EAGAIN : 0;
+}
+
+ses_step_t  ses_step_va_bridge =
+{
+       .name    = "va_bridge",
+
+       .handler = _va_bridge_handler,
+};
index 38aef663f13041014be4a58ae4cfc511eabf3066..1894f40aab5e3741a07c1a8e95c6df8768991536 100644 (file)
@@ -18,6 +18,7 @@ extern ses_step_t   ses_step_jr;
 extern ses_step_t   ses_step_va_diode;
 extern ses_step_t   ses_step_va_transistor;
 extern ses_step_t   ses_step_va;
+extern ses_step_t   ses_step_va_bridge;
 extern ses_step_t   ses_step_va_balance;
 
 extern ses_step_t   ses_step_output;
@@ -44,6 +45,7 @@ static ses_step_t*  ses_steps_1[] =
 #if 1
        &ses_step_jr,
        &ses_step_va,
+       &ses_step_va_bridge,
        &ses_step_va_balance,
 #endif
 };