From: yu.dongliang <18588496441@163.com> Date: Mon, 13 Nov 2023 03:21:41 +0000 (+0800) Subject: __topo_path_diodes() X-Git-Url: http://baseworks.info/?a=commitdiff_plain;h=10a2a93e73084e539797faae6dd1029273933f13;p=ses.git __topo_path_diodes() --- diff --git a/ses_step_dc_input.c b/ses_step_dc_input.c index 736da1e..835f3e3 100644 --- a/ses_step_dc_input.c +++ b/ses_step_dc_input.c @@ -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; diff --git a/ses_step_topo.c b/ses_step_topo.c index 6555c99..fc959c1 100644 --- a/ses_step_topo.c +++ b/ses_step_topo.c @@ -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; } diff --git a/ses_steps.c b/ses_steps.c index c6fc664..204bbab 100644 --- a/ses_steps.c +++ b/ses_steps.c @@ -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);