__topo_path_diodes()
authoryu.dongliang <18588496441@163.com>
Mon, 13 Nov 2023 03:21:41 +0000 (11:21 +0800)
committeryu.dongliang <18588496441@163.com>
Mon, 13 Nov 2023 03:21:41 +0000 (11:21 +0800)
ses_step_dc_input.c
ses_step_topo.c
ses_steps.c

index 736da1ee1de8fe327ad017564194d6f0ccd292f1..835f3e30ef098085e8146cd65ec9fdca8be1c147 100644 (file)
@@ -22,7 +22,7 @@ static int _dc_input_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx
                if (!(SCF_EDA_PIN_IN & el->flags))
                        continue;
 
-               k   = 1 % 2;
+               k   = 0 % 2;
                el2 = f->elines[B->pins[k]->lid];
 
                el->v      = k * B->v;
index 6555c9963864add05b5c29820aaab88b2b06d392..fc959c17ae12492cee31493cf0462f80c8997979 100644 (file)
@@ -446,6 +446,149 @@ static int _topo_path_completes(ScfEfunction* f, scf_vector_t* paths)
        return 0;
 }
 
+static int __ses_branch_exist(ses_path_t* path, int i)
+{
+       if (!path->childs)
+               return 0;
+
+       ses_path_t* child;
+       ScfEpin*    cp;
+       ScfEpin*    p = path->pins->data[i];
+
+       int j;
+       int k;
+
+       for (j = 0; j < path->childs->size; j++) {
+               child     = path->childs->data[j];
+
+               for (k = 0; k < child->pins->size; k++) {
+                       cp =        child->pins->data[k];
+
+                       if (cp->lid == p->lid)
+                               return 1;
+               }
+       }
+
+       return 0;
+}
+
+static int __topo_path_diodes(ScfEfunction* f, ses_path_t* path)
+{
+       ses_info_t*    info = NULL;
+       ScfEcomponent* c;
+       ScfEpin*       p;
+
+       int i;
+       int j;
+
+       for (i = 0; i < path->pins->size; i++) {
+               p  =        path->pins->data[i];
+
+               c  = f->components[p->cid];
+
+               if (SCF_EDA_Diode == c->type) {
+
+                       if (!info) {
+                               info = calloc(1, sizeof(ses_info_t));
+                               if (!info)
+                                       return -ENOMEM;
+
+                               info->i = i;
+                       }
+
+                       if (SCF_EDA_Diode_NEG == p->id) {
+                               info->n_diodes++;
+
+                               if (__ses_branch_exist(path, i))
+                                       goto _add;
+                       }
+                       continue;
+               }
+
+               if (SCF_EDA_NPN == c->type) {
+
+                       if (SCF_EDA_NPN_B == p->id) {
+                               if (!info) {
+                                       info = calloc(1, sizeof(ses_info_t));
+                                       if (!info)
+                                               return -ENOMEM;
+
+                                       info->i = i;
+                               }
+
+                               info->n_NPNs++;
+                               continue;
+
+                       } else if (SCF_EDA_NPN_E == p->id) {
+
+                               if (__ses_branch_exist(path, i))
+                                       goto _add;
+
+                               continue;
+                       }
+               }
+
+_add:
+               if (info) {
+                       info->j = i - 1;
+
+                       if (scf_vector_add(path->diodes, info) < 0) {
+                               free(info);
+                               return -ENOMEM;
+                       }
+
+                       info = NULL;
+               }
+       }
+
+       if (info) {
+               info->j = i - 1;
+
+               if (scf_vector_add(path->diodes, info) < 0) {
+                       free(info);
+                       return -ENOMEM;
+               }
+
+               info = NULL;
+       }
+
+       return 0;
+}
+
+static int _topo_path_diodes(ScfEfunction* f, ses_path_t* path)
+{
+       ses_path_t* child;
+
+       int ret;
+       int i;
+
+       ret = __topo_path_diodes(f, path);
+       if (ret < 0)
+               return ret;
+
+       if (path->childs) {
+               for (i = 0; i < path->childs->size; i++) {
+                       child     = path->childs->data[i];
+
+                       ret = _topo_path_diodes(f, child);
+                       if (ret < 0)
+                               return ret;
+               }
+       }
+
+       if (path->bridges) {
+               for (i = 0; i < path->bridges->size; i++) {
+                       child     = path->bridges->data[i];
+
+                       ret = _topo_path_diodes(f, child);
+                       if (ret < 0)
+                               return ret;
+               }
+       }
+
+       return 0;
+}
+
 static int _topo_layers(ScfEfunction* f, scf_vector_t* paths)
 {
        ScfEcomponent* B;
@@ -520,7 +663,13 @@ branch:
 
                _topo_path_sort(child);
 
-               _topo_path_bridges(f, child);
+               int ret = _topo_path_bridges(f, child);
+               if (ret < 0)
+                       return ret;
+
+               ret = _topo_path_diodes(f, child);
+               if (ret < 0)
+                       return ret;
        }
 
        return 0;
@@ -552,7 +701,6 @@ static int topo_epin_cmp(const void* v0, const void* v1, void* arg)
 
 static int _topo_diodes(ScfEfunction* f, ses_path_t* path)
 {
-       ses_info_t*    info = NULL;
        ScfEcomponent* c;
        ScfEpin*       p;
 
@@ -565,62 +713,16 @@ static int _topo_diodes(ScfEfunction* f, ses_path_t* path)
 
                if (SCF_EDA_Diode == c->type) {
 
-                       if (!info) {
-                               info = calloc(1, sizeof(ses_info_t));
-                               if (!info)
-                                       return -ENOMEM;
-
-                               info->i = i;
-                       }
-
-                       if (SCF_EDA_Diode_NEG == p->id) {
-                               info->n_diodes++;
+                       if (SCF_EDA_Diode_NEG == p->id)
                                path->n_diodes++;
-                       }
-                       continue;
-               }
 
-               if (SCF_EDA_NPN == c->type) {
+               } else if (SCF_EDA_NPN == c->type) {
 
-                       if (SCF_EDA_NPN_B == p->id) {
-                               if (!info) {
-                                       info = calloc(1, sizeof(ses_info_t));
-                                       if (!info)
-                                               return -ENOMEM;
-
-                                       info->i = i;
-                               }
-
-                               info->n_NPNs++;
+                       if (SCF_EDA_NPN_B == p->id)
                                path->n_diodes++;
-                               continue;
-                       } else if (SCF_EDA_NPN_E == p->id)
-                               continue;
-               }
-
-               if (info) {
-                       info->j = i - 1;
-
-                       if (scf_vector_add(path->diodes, info) < 0) {
-                               free(info);
-                               return -ENOMEM;
-                       }
-
-                       info = NULL;
                }
        }
 
-       if (info) {
-               info->j = i - 1;
-
-               if (scf_vector_add(path->diodes, info) < 0) {
-                       free(info);
-                       return -ENOMEM;
-               }
-
-               info = NULL;
-       }
-
        return 0;
 }
 
index c6fc664140627af32c85c90cc73bf1a336d57c5d..204bbab7b4fa979f9735dc2d6e97ebde6dd05495 100644 (file)
@@ -38,12 +38,12 @@ static ses_step_t*  ses_steps_1[] =
 
 //     &ses_step_simplify,
        &ses_step_topo,
-#if 1
+
        &ses_step_jr,
 
        &ses_step_va_diode,
        &ses_step_va_transistor,
-
+#if 1
        &ses_step_jr,
        &ses_step_va,
        &ses_step_va_bridge,
@@ -144,7 +144,7 @@ int ses_steps_analyse(ScfEfunction* f, int64_t ns, int64_t count)
                        return ret;
 
                int j;
-               for (j = 0; j < 3; j++) {
+               for (j = 0; j < 1; j++) {
                        printf("\n\033[33m%s(), %d(), j: %d\033[0m\n", __func__, __LINE__, j);
 
                        ret = __ses_steps_analyse(f, ns, i, ctx);