From: yu.dongliang <18588496441@163.com> Date: Wed, 6 Sep 2023 02:52:20 +0000 (+0800) Subject: ses_step_va_diode.c, ses_step_va_transistor.c X-Git-Url: http://baseworks.info/?a=commitdiff_plain;h=71b71bf6b508d6caa73f0a5ff29f338c66cd50f9;p=ses.git ses_step_va_diode.c, ses_step_va_transistor.c --- diff --git a/Makefile b/Makefile index 32bd7d7..25ecfb7 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,8 @@ CFILES += ses_step_simplify.c CFILES += ses_step_topo.c 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_balance.c CFILES += ses_step_output.c diff --git a/ses_step_va_diode.c b/ses_step_va_diode.c new file mode 100644 index 0000000..4c163eb --- /dev/null +++ b/ses_step_va_diode.c @@ -0,0 +1,121 @@ +#include"ses_core.h" + +static int __ses_path_va_diode(ScfEfunction* f, ses_path_t* path) +{ + if (!path) + return -EINVAL; + + if (path->pins->size < 2) { + scf_loge("\n"); + return -EINVAL; + } + + ses_path_t* child; + ScfEcomponent* c; + ScfEline* el; + ScfEpin* p; + ScfEpin* p0; + ScfEpin* p1; + ScfEpin* p2; + ScfEpin* cp0; + ScfEpin* cp1; + + int i; + int j; + int k; + + 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; + double a = 0; + double ja = 0; + + ses_ur_i(&a, &ja, v, jv, path->r, path->jr); + + scf_loge("path: %d, v: %lg + j%lg, r: %lg + j%lg, a: %lg + j%lg\n", path->index, v, jv, path->r, path->jr, a, ja); + + double r = 0; + double jr = 0; + double dv = 0; + double jdv = 0; + + for (i = 0; i < path->pins->size; i++) { + p = path->pins->data[i]; + + if (path->childs) { + for (j = 0; j < path->childs->size; j++) { + child = path->childs->data[j]; + + cp0 = child->pins->data[0]; + cp1 = child->pins->data[child->pins->size - 1]; + + int ret = __ses_path_va_diode(f, child); + if (ret < 0) + return ret; + } + } + } + printf("\n"); + + return 0; +} + +static int _va_diode_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx) +{ + ses_path_t* path; + ScfEcomponent* B; + ScfEpin* p0; + ScfEpin* p1; + ScfEpin* Bp; + ScfEpin* Bn; + + size_t i; + size_t j; + size_t k; + + B = f->components[0]; + Bp = B->pins[SCF_EDA_Battery_POS]; + Bn = B->pins[SCF_EDA_Battery_NEG]; + + for (i = 0; i < ctx->paths->size; i++) { + path = ctx->paths->data[i]; + + scf_logi("i: %ld, path->type: %d\n", i, path->type); + + if (path->pins->size < 2) { + scf_loge("\n"); + return -EINVAL; + } + + p0 = path->pins->data[0]; + p1 = path->pins->data[path->pins->size - 1]; + + if (p0->lid != Bp->lid || p1->lid != Bn->lid) + continue; + + int ret = __ses_path_va_diode(f, path); + if (ret < 0) + return ret; + + printf("\n"); + } + + return 0; +} + +ses_step_t ses_step_va_diode = +{ + .name = "va_diode", + + .handler = _va_diode_handler, +}; diff --git a/ses_step_va_transistor.c b/ses_step_va_transistor.c new file mode 100644 index 0000000..f773d58 --- /dev/null +++ b/ses_step_va_transistor.c @@ -0,0 +1,121 @@ +#include"ses_core.h" + +static int __ses_path_va_transistor(ScfEfunction* f, ses_path_t* path) +{ + if (!path) + return -EINVAL; + + if (path->pins->size < 2) { + scf_loge("\n"); + return -EINVAL; + } + + ses_path_t* child; + ScfEcomponent* c; + ScfEline* el; + ScfEpin* p; + ScfEpin* p0; + ScfEpin* p1; + ScfEpin* p2; + ScfEpin* cp0; + ScfEpin* cp1; + + int i; + int j; + int k; + + 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; + double a = 0; + double ja = 0; + + ses_ur_i(&a, &ja, v, jv, path->r, path->jr); + + scf_loge("path: %d, v: %lg + j%lg, r: %lg + j%lg, a: %lg + j%lg\n", path->index, v, jv, path->r, path->jr, a, ja); + + double r = 0; + double jr = 0; + double dv = 0; + double jdv = 0; + + for (i = 0; i < path->pins->size; i++) { + p = path->pins->data[i]; + + if (path->childs) { + for (j = 0; j < path->childs->size; j++) { + child = path->childs->data[j]; + + cp0 = child->pins->data[0]; + cp1 = child->pins->data[child->pins->size - 1]; + + int ret = __ses_path_va_transistor(f, child); + if (ret < 0) + return ret; + } + } + } + printf("\n"); + + return 0; +} + +static int _va_transistor_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx) +{ + ses_path_t* path; + ScfEcomponent* B; + ScfEpin* p0; + ScfEpin* p1; + ScfEpin* Bp; + ScfEpin* Bn; + + size_t i; + size_t j; + size_t k; + + B = f->components[0]; + Bp = B->pins[SCF_EDA_Battery_POS]; + Bn = B->pins[SCF_EDA_Battery_NEG]; + + for (i = 0; i < ctx->paths->size; i++) { + path = ctx->paths->data[i]; + + scf_logi("i: %ld, path->type: %d\n", i, path->type); + + if (path->pins->size < 2) { + scf_loge("\n"); + return -EINVAL; + } + + p0 = path->pins->data[0]; + p1 = path->pins->data[path->pins->size - 1]; + + if (p0->lid != Bp->lid || p1->lid != Bn->lid) + continue; + + int ret = __ses_path_va_transistor(f, path); + if (ret < 0) + return ret; + + printf("\n"); + } + + return 0; +} + +ses_step_t ses_step_va_transistor = +{ + .name = "va_transistor", + + .handler = _va_transistor_handler, +}; diff --git a/ses_steps.c b/ses_steps.c index c16d71b..8468655 100644 --- a/ses_steps.c +++ b/ses_steps.c @@ -13,7 +13,10 @@ extern ses_step_t ses_step_dc_transistor; extern ses_step_t ses_step_simplify; extern ses_step_t ses_step_topo; + 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_balance; @@ -32,6 +35,8 @@ static ses_step_t* ses_steps[] = &ses_step_topo, &ses_step_jr, + &ses_step_va_diode, + &ses_step_va_transistor, &ses_step_va, &ses_step_va_balance,