_topo_diodes()
authoryu.dongliang <18588496441@163.com>
Fri, 27 Oct 2023 07:27:56 +0000 (15:27 +0800)
committeryu.dongliang <18588496441@163.com>
Fri, 27 Oct 2023 07:27:56 +0000 (15:27 +0800)
ses_core.h
ses_step_topo.c
ses_utils.c

index d640ac2a0f58843f64fc30d9e585b4d2a60bde82..5327c49f1cd8481ba5a499d4a7c9fa0d2a63cc6c 100644 (file)
@@ -16,7 +16,7 @@ struct ses_info_s
        int i;
        int j;
        int n_diodes;
-       int n_PNPs;
+       int n_NPNs;
 };
 
 struct ses_edge_s
index 3365ac68ce9659cd42f853b018053b6252bbb3b5..57190389b7bd9e78a02b291a038f610ccf552a33 100644 (file)
@@ -392,6 +392,80 @@ static int topo_epin_cmp(const void* v0, const void* v1, void* arg)
        return 0;
 }
 
+static int _topo_diodes(ScfEfunction* f, ses_path_t* path)
+{
+       ses_info_t*    info = NULL;
+       ScfEcomponent* c;
+       ScfEpin*       p;
+
+       int i;
+
+       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++;
+                               path->n_diodes++;
+                       }
+                       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++;
+                               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;
+}
+
 static int _topo_print(scf_vector_t* paths)
 {
        ses_path_t* path;
@@ -481,19 +555,11 @@ static int _topo_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t*
        for (i = 0; i < ctx->paths->size; i++) {
                path      = ctx->paths->data[i];
 
-               path->n_diodes = 0;
-
-               for (j = 0; j < path->pins->size; j++) {
-                       p  =        path->pins->data[j];
+               scf_vector_clear(path->diodes, ( void (*)(void*) )free);
 
-                       c  = f->components[p->cid];
-
-                       if ((SCF_EDA_Diode == c->type && SCF_EDA_Diode_NEG == p->id)
-                        || (SCF_EDA_NPN   == c->type && SCF_EDA_NPN_B     == p->id))
-                               path->n_diodes++;
-
-                       p->n_diodes = path->n_diodes;
-               }
+               int ret = _topo_diodes(f, path);
+               if (ret < 0)
+                       return ret;
        }
 
        int ret = _topo_layers(f, ctx->paths);
index eb444d25b164edcab277ba4163b2ec0aabf938f5..b098854f8f198c003c73a5b3ec8cea93b83c5da4 100644 (file)
@@ -351,7 +351,7 @@ void ses_path_print(ses_path_t* path)
        int i;
 
        if (!path->parent)
-               printf("\033[31mpath: %d, n_diodes: %d, \033[0m", path->index, path->n_diodes);
+               printf("\033[31mpath  : %d, n_diodes: %d, diodes->size: %d, \033[0m", path->index, path->n_diodes, path->diodes->size);
 
        for (i = 0; i < path->pins->size; i++) {
                p  =        path->pins->data[i];
@@ -364,7 +364,7 @@ void ses_path_print(ses_path_t* path)
                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);
+                       printf("\033[32mchild : %d, n_diodes: %d, diodes->size: %d, parent: %d, \033[0m", path2->index, path2->n_diodes, path2->diodes->size, path->index);
 
                        ses_path_print(path2);
                }
@@ -374,7 +374,7 @@ void ses_path_print(ses_path_t* path)
                for (i = 0; i < path->bridges->size; i++) {
                        path2     = path->bridges->data[i];
 
-                       printf("\033[33mbridge: %d, n_diodes: %d, parent: %d, \033[0m", path2->index, path2->n_diodes, path->index);
+                       printf("\033[33mbridge: %d, n_diodes: %d, diodes->size: %d, parent: %d, \033[0m", path2->index, path2->n_diodes, path2->diodes->size, path->index);
 
                        ses_path_print(path2);
                }