bridge
authoryu.dongliang <18588496441@163.com>
Sat, 21 Oct 2023 06:32:13 +0000 (14:32 +0800)
committeryu.dongliang <18588496441@163.com>
Sat, 21 Oct 2023 06:32:13 +0000 (14:32 +0800)
ses_core.h
ses_step_topo.c
ses_steps.c
ses_utils.c

index ed0a941582949edacfa24106be035d4094cc5534..8ab38346f8de418fffc3f36d46a931300e39cb79 100644 (file)
@@ -49,6 +49,8 @@ struct ses_path_s
 
        scf_vector_t*  childs;
 
+       scf_vector_t*  bridges;
+
        ses_path_t*    parent;
        int            parent_p0;
        int            parent_p1;
index 66e9c57669940d7614488c17455a2234f23ad1de..cd9b17540a7b879fea0e7bd2b540f7bee75515fb 100644 (file)
@@ -168,6 +168,7 @@ static void _topo_path_sort(ses_path_t* path)
                return;
 
        ses_path_t* child;
+
        int i;
 
        for (i = 0; i < path->childs->size; i++) {
@@ -179,20 +180,128 @@ static void _topo_path_sort(ses_path_t* path)
        scf_vector_qsort(path->childs, _ses_child_cmp);
 }
 
-static int _topo_layers(scf_vector_t* paths, ScfEcomponent* B)
+static int __topo_path_bridges(ScfEfunction* f, ses_path_t* path)
 {
-       ses_path_t*      child;
-       ses_path_t*      parent;
-       ScfEpin*         Bp;
-       ScfEpin*         Bn;
-       ScfEpin*         p0;
-       ScfEpin*         p1;
-       ScfEpin*         p;
+       ScfEcomponent* c0;
+       ScfEcomponent* c1;
+       ses_path_t*    sp0;
+       ses_path_t*    sp1;
+       ScfEpin*       p0;
+       ScfEpin*       p1;
+
+       int i;
+       int j;
+
+       path->bridges = scf_vector_alloc();
+       if (!path->bridges)
+               return -ENOMEM;
+
+       for (i = 0; i < path->childs->size - 1; ) {
+               sp0       = path->childs->data[i];
+
+               for (j = i + 1; j < path->childs->size; ) {
+                       sp1           = path->childs->data[i];
+
+                       if (sp0->parent_p0 <= sp1->parent_p0 && sp0->parent_p1 >= sp1->parent_p1) {
+                               j++;
+                               continue;
+                       }
+
+                       if (sp0->parent_p0 >= sp1->parent_p0 && sp0->parent_p1 <= sp1->parent_p1) {
+                               j++;
+                               continue;
+                       }
+
+                       p0 = sp0->pins->data[0];
+                       p1 = sp1->pins->data[0];
+
+                       if (SCF_EDA_PIN_IN & p0->flags)
+                               goto bridge_sp1;
+
+                       if (SCF_EDA_PIN_IN & p1->flags)
+                               goto bridge_sp0;
+
+                       c0 = f->components[p0->cid];
+                       c1 = f->components[p1->cid];
+
+                       if (SCF_EDA_NPN == c0->type && SCF_EDA_NPN_C == p0->id)
+                               goto bridge_sp1;
+
+                       if (SCF_EDA_NPN == c1->type && SCF_EDA_NPN_C == p1->id)
+                               goto bridge_sp0;
+
+                       if ((SCF_EDA_Diode == c0->type && SCF_EDA_Diode_POS == p0->id)
+                        || (SCF_EDA_NPN   == c0->type && SCF_EDA_NPN_B     == p0->id))
+                               goto bridge_sp1;
+
+                       if ((SCF_EDA_Diode == c1->type && SCF_EDA_Diode_POS == p1->id)
+                        || (SCF_EDA_NPN   == c1->type && SCF_EDA_NPN_B     == p1->id))
+                               goto bridge_sp0;
+
+bridge_sp1:
+                       scf_vector_del(path->childs, sp1);
+                       if (scf_vector_add(path->bridges, sp1) < 0)
+                               return -ENOMEM;
+               }
+
+               i++;
+               continue;
+bridge_sp0:
+               scf_vector_del(path->childs, sp0);
+               if (scf_vector_add(path->bridges, sp0) < 0)
+                       return -ENOMEM;
+       }
+
+       for (i = 0; i < path->bridges->size; i++) {
+               sp0       = path->bridges->data[i];
+
+               scf_logw("path: %d, i: %d, bridge: %d\n", path->index, i, sp0->index);
+       }
+
+       if (path->bridges->size <= 0) {
+               scf_vector_free(path->bridges);
+               path->bridges = NULL;
+       }
+
+       return 0;
+}
+
+static int _topo_path_bridges(ScfEfunction* f, ses_path_t* path)
+{
+       if (!path || !path->childs || path->childs->size <= 0)
+               return 0;
+
+       ses_path_t* child;
+
+       int i;
+
+       for (i = 0; i < path->childs->size; i++) {
+               child     = path->childs->data[i];
+
+               int ret = _topo_path_bridges(f, child);
+               if (ret < 0)
+                       return ret;
+       }
+
+       return __topo_path_bridges(f, path);
+}
+
+static int _topo_layers(ScfEfunction* f, scf_vector_t* paths)
+{
+       ScfEcomponent* B;
+       ses_path_t*    child;
+       ses_path_t*    parent;
+       ScfEpin*       Bp;
+       ScfEpin*       Bn;
+       ScfEpin*       p0;
+       ScfEpin*       p1;
+       ScfEpin*       p;
 
        int i;
        int j;
        int k;
 
+       B  = f->components[0];
        Bp = B->pins[SCF_EDA_Battery_POS];
        Bn = B->pins[SCF_EDA_Battery_NEG];
 
@@ -250,6 +359,8 @@ branch:
                child     = paths->data[i];
 
                _topo_path_sort(child);
+
+               _topo_path_bridges(f, child);
        }
 
        return 0;
@@ -387,9 +498,7 @@ static int _topo_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t*
                }
        }
 
-//     _topo_print(ctx->paths);
-
-       int ret = _topo_layers(ctx->paths, B);
+       int ret = _topo_layers(f, ctx->paths);
        if (ret < 0)
                return ret;
 
index c1d14095367b46b1ed325116644726583c5df061..fc2bcec625f41a7cf7a59795257952a9cbec533e 100644 (file)
@@ -41,7 +41,7 @@ static ses_step_t*  ses_steps_1[] =
 
        &ses_step_va_diode,
        &ses_step_va_transistor,
-#if 1
+#if 0
        &ses_step_jr,
        &ses_step_va,
        &ses_step_va_balance,
@@ -138,7 +138,7 @@ int ses_steps_analyse(ScfEfunction* f, int64_t ns, int64_t count)
                        return ret;
 
                int j;
-               for (j = 0; j < 2; j++) {
+               for (j = 0; ; j++) {
                        ret = __ses_steps_analyse(f, ns, i, ctx);
 
                        if (-EAGAIN == ret)
index 5fa1b51ccc48e7d2eab76689e4fa802f17c0d206..0e58df158a76003477f59f83262b974fcce0c563 100644 (file)
@@ -317,6 +317,11 @@ void ses_path_free(ses_path_t* path)
                        scf_vector_free (path->childs);
                }
 
+               if (path->bridges) {
+                       scf_vector_clear(path->bridges, ( void (*)(void*) )ses_path_free);
+                       scf_vector_free (path->bridges);
+               }
+
                free(path);
        }
 }
@@ -341,15 +346,24 @@ void ses_path_print(ses_path_t* path)
        }
        printf("\n");
 
-       if (!path->childs)
-               return;
+       if (path->childs) {
+               for (i = 0; i < path->childs->size; i++) {
+                       path2     = path->childs->data[i];
+
+                       printf("\033[32mchild: %d, n_diodes: %d, parent: %d, \033[0m", path2->index, path2->n_diodes, path->index);
 
-       for (i = 0; i < path->childs->size; i++) {
-               path2     = path->childs->data[i];
+                       ses_path_print(path2);
+               }
+       }
 
-               printf("\033[32mchild: %d, n_diodes: %d, parent: %d, \033[0m", path2->index, path2->n_diodes, path->index);
+       if (path->bridges) {
+               for (i = 0; i < path->bridges->size; i++) {
+                       path2     = path->bridges->data[i];
 
-               ses_path_print(path2);
+                       printf("\033[32mbridge: %d, n_diodes: %d, parent: %d, \033[0m", path2->index, path2->n_diodes, path->index);
+
+                       ses_path_print(path2);
+               }
        }
 }