From: yu.dongliang <18588496441@163.com> Date: Sat, 21 Oct 2023 06:32:13 +0000 (+0800) Subject: bridge X-Git-Url: http://baseworks.info/?a=commitdiff_plain;h=b9516c01abc1483bc7243e762d21c005832d6ac0;p=ses.git bridge --- diff --git a/ses_core.h b/ses_core.h index ed0a941..8ab3834 100644 --- a/ses_core.h +++ b/ses_core.h @@ -49,6 +49,8 @@ struct ses_path_s scf_vector_t* childs; + scf_vector_t* bridges; + ses_path_t* parent; int parent_p0; int parent_p1; diff --git a/ses_step_topo.c b/ses_step_topo.c index 66e9c57..cd9b175 100644 --- a/ses_step_topo.c +++ b/ses_step_topo.c @@ -168,6 +168,7 @@ static void _topo_path_sort(ses_path_t* path) return; ses_path_t* child; + int i; for (i = 0; i < path->childs->size; i++) { @@ -179,20 +180,128 @@ static void _topo_path_sort(ses_path_t* path) scf_vector_qsort(path->childs, _ses_child_cmp); } -static int _topo_layers(scf_vector_t* paths, ScfEcomponent* B) +static int __topo_path_bridges(ScfEfunction* f, ses_path_t* path) { - ses_path_t* child; - ses_path_t* parent; - ScfEpin* Bp; - ScfEpin* Bn; - ScfEpin* p0; - ScfEpin* p1; - ScfEpin* p; + ScfEcomponent* c0; + ScfEcomponent* c1; + ses_path_t* sp0; + ses_path_t* sp1; + ScfEpin* p0; + ScfEpin* p1; + + int i; + int j; + + path->bridges = scf_vector_alloc(); + if (!path->bridges) + return -ENOMEM; + + for (i = 0; i < path->childs->size - 1; ) { + sp0 = path->childs->data[i]; + + for (j = i + 1; j < path->childs->size; ) { + sp1 = path->childs->data[i]; + + if (sp0->parent_p0 <= sp1->parent_p0 && sp0->parent_p1 >= sp1->parent_p1) { + j++; + continue; + } + + if (sp0->parent_p0 >= sp1->parent_p0 && sp0->parent_p1 <= sp1->parent_p1) { + j++; + continue; + } + + p0 = sp0->pins->data[0]; + p1 = sp1->pins->data[0]; + + if (SCF_EDA_PIN_IN & p0->flags) + goto bridge_sp1; + + if (SCF_EDA_PIN_IN & p1->flags) + goto bridge_sp0; + + c0 = f->components[p0->cid]; + c1 = f->components[p1->cid]; + + if (SCF_EDA_NPN == c0->type && SCF_EDA_NPN_C == p0->id) + goto bridge_sp1; + + if (SCF_EDA_NPN == c1->type && SCF_EDA_NPN_C == p1->id) + goto bridge_sp0; + + if ((SCF_EDA_Diode == c0->type && SCF_EDA_Diode_POS == p0->id) + || (SCF_EDA_NPN == c0->type && SCF_EDA_NPN_B == p0->id)) + goto bridge_sp1; + + if ((SCF_EDA_Diode == c1->type && SCF_EDA_Diode_POS == p1->id) + || (SCF_EDA_NPN == c1->type && SCF_EDA_NPN_B == p1->id)) + goto bridge_sp0; + +bridge_sp1: + scf_vector_del(path->childs, sp1); + if (scf_vector_add(path->bridges, sp1) < 0) + return -ENOMEM; + } + + i++; + continue; +bridge_sp0: + scf_vector_del(path->childs, sp0); + if (scf_vector_add(path->bridges, sp0) < 0) + return -ENOMEM; + } + + for (i = 0; i < path->bridges->size; i++) { + sp0 = path->bridges->data[i]; + + scf_logw("path: %d, i: %d, bridge: %d\n", path->index, i, sp0->index); + } + + if (path->bridges->size <= 0) { + scf_vector_free(path->bridges); + path->bridges = NULL; + } + + return 0; +} + +static int _topo_path_bridges(ScfEfunction* f, ses_path_t* path) +{ + if (!path || !path->childs || path->childs->size <= 0) + return 0; + + ses_path_t* child; + + int i; + + for (i = 0; i < path->childs->size; i++) { + child = path->childs->data[i]; + + int ret = _topo_path_bridges(f, child); + if (ret < 0) + return ret; + } + + return __topo_path_bridges(f, path); +} + +static int _topo_layers(ScfEfunction* f, scf_vector_t* paths) +{ + ScfEcomponent* B; + ses_path_t* child; + ses_path_t* parent; + ScfEpin* Bp; + ScfEpin* Bn; + ScfEpin* p0; + ScfEpin* p1; + ScfEpin* p; int i; int j; int k; + B = f->components[0]; Bp = B->pins[SCF_EDA_Battery_POS]; Bn = B->pins[SCF_EDA_Battery_NEG]; @@ -250,6 +359,8 @@ branch: child = paths->data[i]; _topo_path_sort(child); + + _topo_path_bridges(f, child); } return 0; @@ -387,9 +498,7 @@ static int _topo_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* } } -// _topo_print(ctx->paths); - - int ret = _topo_layers(ctx->paths, B); + int ret = _topo_layers(f, ctx->paths); if (ret < 0) return ret; diff --git a/ses_steps.c b/ses_steps.c index c1d1409..fc2bcec 100644 --- a/ses_steps.c +++ b/ses_steps.c @@ -41,7 +41,7 @@ static ses_step_t* ses_steps_1[] = &ses_step_va_diode, &ses_step_va_transistor, -#if 1 +#if 0 &ses_step_jr, &ses_step_va, &ses_step_va_balance, @@ -138,7 +138,7 @@ int ses_steps_analyse(ScfEfunction* f, int64_t ns, int64_t count) return ret; int j; - for (j = 0; j < 2; j++) { + for (j = 0; ; j++) { ret = __ses_steps_analyse(f, ns, i, ctx); if (-EAGAIN == ret) diff --git a/ses_utils.c b/ses_utils.c index 5fa1b51..0e58df1 100644 --- a/ses_utils.c +++ b/ses_utils.c @@ -317,6 +317,11 @@ void ses_path_free(ses_path_t* path) scf_vector_free (path->childs); } + if (path->bridges) { + scf_vector_clear(path->bridges, ( void (*)(void*) )ses_path_free); + scf_vector_free (path->bridges); + } + free(path); } } @@ -341,15 +346,24 @@ void ses_path_print(ses_path_t* path) } printf("\n"); - if (!path->childs) - return; + if (path->childs) { + 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); - for (i = 0; i < path->childs->size; i++) { - path2 = path->childs->data[i]; + ses_path_print(path2); + } + } - printf("\033[32mchild: %d, n_diodes: %d, parent: %d, \033[0m", path2->index, path2->n_diodes, path->index); + if (path->bridges) { + for (i = 0; i < path->bridges->size; i++) { + path2 = path->bridges->data[i]; - ses_path_print(path2); + printf("\033[32mbridge: %d, n_diodes: %d, parent: %d, \033[0m", path2->index, path2->n_diodes, path->index); + + ses_path_print(path2); + } } }