From: yu.dongliang <18588496441@163.com> Date: Mon, 23 Oct 2023 03:41:34 +0000 (+0800) Subject: ses_step_va_bridge.c X-Git-Url: http://baseworks.info/?a=commitdiff_plain;h=3246c244e64ae889616bce86608a2c591142c45f;p=ses.git ses_step_va_bridge.c --- diff --git a/Makefile b/Makefile index 7314e59..bc29d85 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,7 @@ CFILES += ses_step_jr.c CFILES += ses_step_va_diode.c CFILES += ses_step_va_transistor.c CFILES += ses_step_va.c +CFILES += ses_step_va_bridge.c CFILES += ses_step_va_balance.c CFILES += ses_step_output.c diff --git a/ses_core.h b/ses_core.h index 8ab3834..e482331 100644 --- a/ses_core.h +++ b/ses_core.h @@ -119,6 +119,7 @@ void __ses_path_pr (ScfEfunction* f, ses_path_t* path, int i, int j, ScfEpin void __ses_path_sr (ScfEfunction* f, ses_path_t* path, int i, int j, ScfEpin* cp1, double* r, double* jr); int __ses_path_pos (ScfEfunction* f, ScfEline* el); int __ses_path_neg (ScfEfunction* f, ScfEline* el); +int __ses_path_va (ScfEfunction* f, ses_path_t* path); static inline void vertical(int* px, int* py, int dx, int dy, int d) { diff --git a/ses_step_va.c b/ses_step_va.c index 917f099..70e6c19 100644 --- a/ses_step_va.c +++ b/ses_step_va.c @@ -2,8 +2,6 @@ int _ses_path_cmp(const void* v0, const void* v1); -static int __ses_path_va(ScfEfunction* f, ses_path_t* path); - static int __ses_path_split_a(ScfEfunction* f, ses_path_t* path, int i, double* a, double *ja) { ses_path_t* child; @@ -98,6 +96,9 @@ static int __ses_path_split_v(ScfEfunction* f, ses_path_t* path, ScfEpin* p0, in r = p->sr - (p->r + p->dr ) - p0->sr; jr = p->jsr - (p->jr + p->jdr) - p0->jsr; + scf_logi("c%ldp%ld-c%ldp%ld, p->sr: %lg, p->r: %lg, p->dr: %lg, p0->sr: %lg\n", + p0->cid, p0->id, p->cid, p->id, p->sr, p->r, p->dr, p0->sr); + } else if (i >= 1) { p2 = path->pins->data[i - 1]; @@ -121,11 +122,11 @@ static int __ses_path_split_v(ScfEfunction* f, ses_path_t* path, ScfEpin* p0, in p->v = p0->v - v; p->jv = p0->jv - jv; - scf_logd("c%ldp%ld, c%ldp%ld, a: %lg, r: %lg, v: %lg\n", p0->cid, p0->id, p->cid, p->id, a, r, v); + scf_logi("c%ldp%ld, c%ldp%ld, a: %lg, r: %lg, v: %lg\n", p0->cid, p0->id, p->cid, p->id, a, r, v); return 0; } -static int __ses_path_va(ScfEfunction* f, ses_path_t* path) +int __ses_path_va(ScfEfunction* f, ses_path_t* path) { if (!path) return -EINVAL; @@ -270,7 +271,7 @@ static int _va_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ct for (i = 0; i < ctx->paths->size; i++) { path = ctx->paths->data[i]; - scf_logi("i: %d, path->type: %d\n", i, path->type); + scf_logi("i: %d, path->index: %d\n", i, path->index); if (path->pins->size < 2) { scf_loge("\n"); diff --git a/ses_step_va_bridge.c b/ses_step_va_bridge.c new file mode 100644 index 0000000..ab89ae3 --- /dev/null +++ b/ses_step_va_bridge.c @@ -0,0 +1,94 @@ +#include"ses_core.h" + +static int __ses_path_va_bridge(ScfEfunction* f, ses_path_t* path, int* changed) +{ + if (!path) + return -EINVAL; + + if (path->pins->size < 2) { + scf_loge("\n"); + return -EINVAL; + } + + ses_path_t* child; + ScfEcomponent* c; + ScfEline* el; + ScfEpin* p0; + ScfEpin* p1; + + p0 = path->pins->data[0]; + p1 = path->pins->data[path->pins->size - 1]; + + el = f->elines[p0->lid]; + p0->v = el->v; + p0->jv = el->jv; + + el = f->elines[p1->lid]; + p1->v = el->v; + p1->jv = el->jv; + + double v = p0->v - p1->v; + double jv = p0->jv - p1->jv; + + scf_logw("path: %d, c%ldp%ld--c%ldp%ld, v: %lg, p0->v: %lg, p1->v: %lg, n_diodes: %d\n", + path->index, p0->cid, p0->id, p1->cid, p1->id, v, p0->v, p1->v, path->n_diodes); + + int ret = __ses_path_va(f, path); + if (ret < 0) + return ret; + + return 0; +} + +static int ses_path_va_bridge(ScfEfunction* f, ses_path_t* path, int* changed) +{ + ses_path_t* child; + + size_t j; + + if (!path) + return -EINVAL; + + if (path->bridges) { + for (j = 0; j < path->bridges->size; j++) { + child = path->bridges->data[j]; + + int ret = __ses_path_va_bridge(f, child, changed); + if (ret < 0) + return ret; + + ret = ses_path_va_bridge(f, child, changed); + if (ret < 0) + return ret; + } + } + + return 0; +} + +static int _va_bridge_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx) +{ + ses_path_t* path; + + int changed = 0; + int i; + + for (i = 0; i < ctx->paths->size; i++) { + path = ctx->paths->data[i]; + + int ret = ses_path_va_bridge(f, path, &changed); + if (ret < 0) + return ret; + + printf("\n"); + } + + return changed > 0 ? -EAGAIN : 0; +} + +ses_step_t ses_step_va_bridge = +{ + .name = "va_bridge", + + .handler = _va_bridge_handler, +}; diff --git a/ses_steps.c b/ses_steps.c index 38aef66..1894f40 100644 --- a/ses_steps.c +++ b/ses_steps.c @@ -18,6 +18,7 @@ extern ses_step_t ses_step_jr; extern ses_step_t ses_step_va_diode; extern ses_step_t ses_step_va_transistor; extern ses_step_t ses_step_va; +extern ses_step_t ses_step_va_bridge; extern ses_step_t ses_step_va_balance; extern ses_step_t ses_step_output; @@ -44,6 +45,7 @@ static ses_step_t* ses_steps_1[] = #if 1 &ses_step_jr, &ses_step_va, + &ses_step_va_bridge, &ses_step_va_balance, #endif };