ses_step_topo.c
authoryu.dongliang <18588496441@163.com>
Tue, 7 Nov 2023 13:04:26 +0000 (21:04 +0800)
committeryu.dongliang <18588496441@163.com>
Tue, 7 Nov 2023 13:04:26 +0000 (21:04 +0800)
ses_core.h
ses_step_topo.c

index 0a5bef33bae62b686009b140bfe13a9a00d7508d..431968d93a6af0180778c59ddb4b7b1b1132df5b 100644 (file)
@@ -124,6 +124,7 @@ int  __ses_path_pos    (ScfEfunction* f, ScfEline*   el);
 int  __ses_path_neg    (ScfEfunction* f, ScfEline*   el);
 
 int  __ses_status_check(ScfEfunction* f, ScfEcomponent* c, ScfEpin* pb, ScfEpin* pe);
+int  __ses_topo_paths  (ScfEfunction* f, scf_vector_t*  paths);
 
 static inline void vertical(int* px, int* py, int dx, int dy, int d)
 {
index 57190389b7bd9e78a02b291a038f610ccf552a33..06838cd6802b869c6ac403fc62b4e6c3318a32c8 100644 (file)
@@ -480,11 +480,12 @@ static int _topo_print(scf_vector_t* paths)
        }
 }
 
-static int _topo_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx)
+static void _topo_clear(ScfEfunction* f)
 {
-       ses_path_t*      path;
+       if (!f)
+               return;
+
        ScfEcomponent*   c;
-       ScfEcomponent*   B;
        ScfEline*        el;
        ScfEpin*         p;
 
@@ -509,11 +510,21 @@ static int _topo_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t*
                        p->dr     = 0;
                }
        }
+}
 
-       scf_vector_clear(ctx->paths, ( void (*)(void*) )ses_path_free);
+static int _topo_paths(ScfEfunction* f, ScfEline* el, scf_vector_t* paths)
+{
+       if (!f || !el || !paths)
+               return -EINVAL;
+
+       ses_path_t*      path;
+       ScfEcomponent*   c;
+       ScfEcomponent*   B;
+       ScfEpin*         p;
+
+       size_t i;
 
        B    = f->components[0];
-       el   = f->elines[B->pins[SCF_EDA_Battery_POS]->lid];
        path = NULL;
 
        for (i = 0; i + 1 < el->n_pins; i += 2) {
@@ -524,9 +535,7 @@ static int _topo_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t*
                if (c == B)
                        continue;
 
-               scf_logd("i: %ld\n", i);
-
-               int ret = __dfs_path(f, c, p, ctx->paths, &path);
+               int ret = __dfs_path(f, c, p, paths, &path);
                if (ret < 0)
                        return ret;
 
@@ -539,7 +548,7 @@ static int _topo_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t*
                        continue;
                }
 
-               if (scf_vector_add(ctx->paths, path) < 0) {
+               if (scf_vector_add(paths, path) < 0) {
                        ses_path_free(path);
                        return -ENOMEM;
                }
@@ -552,17 +561,84 @@ static int _topo_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t*
                path = NULL;
        }
 
+       return 0;
+}
+
+int __ses_topo_paths(ScfEfunction* f, scf_vector_t*  paths)
+{
+       if (!f || !paths)
+               return -EINVAL;
+
+       ses_path_t*      path;
+       ScfEline*        el;
+       ScfEpin*         p;
+
+       size_t i;
+       size_t j;
+
+       _topo_clear(f);
+
+       scf_vector_clear(paths, ( void (*)(void*) )ses_path_free);
+
+       for (i = 0; i < f->n_elines; i++) {
+               el =        f->elines[i];
+
+               if (!(el->flags & (SCF_EDA_PIN_POS | SCF_EDA_PIN_IN)))
+                       continue;
+
+               int ret = _topo_paths(f, el, paths);
+               if (ret < 0)
+                       return ret;
+       }
+
+       for (i = 0; i < paths->size; i++) {
+               path      = paths->data[i];
+
+               scf_vector_clear(path->diodes, ( void (*)(void*) )free);
+
+               int ret = _topo_diodes(f, path);
+               if (ret < 0)
+                       return ret;
+       }
+
+       int ret = _topo_layers(f, paths);
+       if (ret < 0)
+               return ret;
+
+       _topo_print(paths);
+       return 0;
+}
+
+static int _topo_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx)
+{
+       ses_path_t*      path;
+       ScfEcomponent*   B;
+       ScfEline*        el;
+
+       size_t i;
+
+       _topo_clear(f);
+
+       scf_vector_clear(ctx->paths, ( void (*)(void*) )ses_path_free);
+
+       B  = f->components[0];
+       el = f->elines[B->pins[SCF_EDA_Battery_POS]->lid];
+
+       int ret = _topo_paths(f, el, ctx->paths);
+       if (ret < 0)
+               return ret;
+
        for (i = 0; i < ctx->paths->size; i++) {
                path      = ctx->paths->data[i];
 
                scf_vector_clear(path->diodes, ( void (*)(void*) )free);
 
-               int ret = _topo_diodes(f, path);
+               ret = _topo_diodes(f, path);
                if (ret < 0)
                        return ret;
        }
 
-       int ret = _topo_layers(f, ctx->paths);
+       ret = _topo_layers(f, ctx->paths);
        if (ret < 0)
                return ret;