From 565c60caa74afe604dd3cd6d1a64d524b41b4d4e Mon Sep 17 00:00:00 2001 From: "yu.dongliang" <18588496441@163.com> Date: Tue, 7 Nov 2023 21:04:26 +0800 Subject: [PATCH] ses_step_topo.c --- ses_core.h | 1 + ses_step_topo.c | 98 +++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 88 insertions(+), 11 deletions(-) diff --git a/ses_core.h b/ses_core.h index 0a5bef3..431968d 100644 --- a/ses_core.h +++ b/ses_core.h @@ -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) { diff --git a/ses_step_topo.c b/ses_step_topo.c index 5719038..06838cd 100644 --- a/ses_step_topo.c +++ b/ses_step_topo.c @@ -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; -- 2.25.1