static int __ses_path_va_diode(ScfEfunction* f, ses_path_t* path)
{
ses_path_t* child;
+ ses_info_t* info;
+
ScfEcomponent* c;
ScfEline* el;
ScfEpin* p;
int i;
int j;
- int k;
p0 = path->pins->data[0];
p1 = path->pins->data[path->pins->size - 1];
p1->v = el->v;
p1->jv = el->jv;
- int i_diodes = 0;
- int j_diodes = 0;
- int i_NPNs = 0;
- int j_NPNs = 0;
-
- for (i = 0; i < path->pins->size; i++) {
- pi = path->pins->data[i];
-
- el = f->elines [pi->lid];
- c = f->components[pi->cid];
-
- if (SCF_EDA_Diode == c->type) {
- i_diodes++;
- continue;
- }
-
- if (SCF_EDA_NPN != c->type)
- break;
+ double v = p0->v - p1->v;
+ double jv = p0->jv - p1->jv;
- if (SCF_EDA_NPN_C == pi->id)
- return 0;
+ double r = 0;
+ double jr = 0;
- i_NPNs++;
- }
-
- for (j = path->pins->size - 1; j >= i; j--) {
- pj = path->pins->data[j];
+ double a;
+ double ja;
- el = f->elines [pj->lid];
- c = f->components[pj->cid];
+ i = 0;
- if (SCF_EDA_Diode == c->type) {
- j_diodes++;
- continue;
- }
+ for (j = 0; j < path->diodes->size; j++) {
+ info = path->diodes->data[j];
+ pi = path->pins->data[i];
+ pj = path->pins->data[info->i];
- if (SCF_EDA_NPN != c->type)
- break;
+ v -= info->n_diodes * SCF_EDA_V_Diode_ON;
+ v -= info->n_NPNs * SCF_EDA_V_NPN_ON;
- if (SCF_EDA_NPN_C == pj->id)
- return 0;
+ r += pj->pr - pj->r - pi->pr;
+ jr += pj->jpr - pj->jr - pi->jpr;
- j_NPNs++;
- }
+ scf_logi("i: %d, info->i: %d, c%ldp%ld--c%ldp%ld, r: %lg, v: %lg\n", i, info->i, pi->cid, pi->id, pj->cid, pj->id, r, v);
- if (j <= i) {
- scf_loge("all components are Diode\n");
- return -1;
+ i = info->j;
}
- i_diodes >>= 1;
- j_diodes >>= 1;
-
- i_NPNs >>= 1;
- j_NPNs >>= 1;
-
- double __vi = p0->v - SCF_EDA_V_Diode_ON * i_diodes - SCF_EDA_V_NPN_ON * i_NPNs;
- double __vj = p1->v + SCF_EDA_V_Diode_ON * j_diodes + SCF_EDA_V_NPN_ON * j_NPNs;
-
- scf_logd("i: %d, c%ldp%ld, __vi: %lg, i_diodes: %d, i_NPNs: %d\n", i, pi->cid, pi->id, __vi, i_diodes, i_NPNs);
- scf_logd("j: %d, c%ldp%ld, __vj: %lg, j_diodes: %d, j_NPNs: %d\n", j, pj->cid, pj->id, __vj, j_diodes, j_NPNs);
-
- pi->v = __vi;
- pj->v = __vj;
+ if (i < path->pins->size - 1) {
+ pi = path->pins->data[i];
- if (j < path->pins->size - 1)
- pj = path->pins->data[++j];
- pj->v = __vj;
+ r += p1->sr - p1->r - pi->pr;
+ jr += p1->jsr - p1->jr - pi->jpr;
- double v = pi->v - pj->v;
- double jv = pi->jv - pj->jv;
-
- double pr = pj->pr - pj->r - pi->pr;
- double jpr = pj->jpr - pj->jr - pi->jpr;
-
- double sr = pj->sr - pj->r - pi->sr;
- double jsr = pj->jsr - pj->jr - pi->jsr;
-
- double a;
- double ja;
-
- if (j == path->pins->size - 1
- && p1->sr == p1->pr
- && p1->jsr == p1->jpr)
- ses_ur_i(&a, &ja, v, jv, pr, jpr);
- else
- ses_ur_i(&a, &ja, v, jv, sr, jsr);
+ scf_logi("i: %d, info->i: %d, c%ldp%ld--c%ldp%ld, r: %lg, v: %lg\n", i, path->pins->size - 1, pi->cid, pi->id, p1->cid, p1->id, r, v);
+ }
- c = f->components[pj->cid];
+ ses_ur_i(&a, &ja, v, jv, r, jr);
path->a = a;
path->ja = ja;
- scf_logd("i: %d, j: %d, c%ldp%ld--c%ldp%ld, a: %lg\n", i, j, pi->cid, pi->id, pj->cid, pj->id, a);
+ i = 0;
- if (SCF_EDA_Diode == c->type && SCF_EDA_Diode_POS == pj->id) {
+ for (j = 0; j < path->diodes->size; j++) {
+ info = path->diodes->data[j];
+ pi = path->pins->data[info->i];
+ pj = path->pins->data[info->j];
- el = f->elines[pj->lid];
- el->a = a;
- el->ja = ja;
- el->aconst = 1;
-
- pj->a = a;
- pj->ja = ja;
-
- if (path->childs)
- __ses_path_split_i(f, path, j, path->pins->size - 1, a, ja, &pj->a, &pj->ja);
-
- scf_loge("j: %d, c%ldp%ld--c%ldp%ld, v: %lg, pj->v: %lg, pj->a: %lg, pr: %lg, sr: %lg\n\n",
- j, pj->cid, pj->id, p1->cid, p1->id, v, pj->v, pj->a, pr, sr);
-
- __ses_path_dr_forward(f, path, j, path->pins->size - 1, pj->a, pj->ja);
-
- } else if (SCF_EDA_NPN == c->type && SCF_EDA_NPN_B == pj->id) {
-
- el = f->elines[pj->lid];
- el->a = a;
- el->ja = ja;
- el->aconst = 1;
-
- pj->a = a;
- pj->ja = ja;
+ c = f->components[pi->cid];
- if (path->childs)
- __ses_path_split_i(f, path, j, path->pins->size - 1, a, ja, &pj->a, &pj->ja);
+ assert((SCF_EDA_Diode == c->type && SCF_EDA_Diode_POS == pi->id)
+ || (SCF_EDA_NPN == c->type && SCF_EDA_NPN_B == pi->id));
- scf_loge("j: %d, c%ldp%ld--c%ldp%ld, v: %lg, pj->v: %lg, pj->a: %lg, pr: %lg, sr: %lg\n\n",
- j, pj->cid, pj->id, p1->cid, p1->id, v, pj->v, pj->a, pr, sr);
+ pi->a = a;
+ pi->ja = ja;
- __ses_path_dr_forward(f, path, j, path->pins->size - 1, pj->a, pj->ja);
- }
+ __ses_path_pr(f, path, i, info->i, NULL, &r, &jr);
- if (i > 0)
- pi = path->pins->data[--i];
- pi->v = __vi;
+ ses_ir_u(&v, &jv, a, ja, r, jr);
- c = f->components[pi->cid];
+ pi->v = p0->v - v;
+ pi->jv = p0->jv - jv;
- if (SCF_EDA_Diode == c->type && SCF_EDA_Diode_NEG == pi->id) {
+ pj->v = pi->v - info->n_diodes * SCF_EDA_V_Diode_ON - info->n_NPNs * SCF_EDA_V_NPN_ON;
+ pj->jv = pi->jv;
el = f->elines[pi->lid];
el->a = a;
el->ja = ja;
+ el->v = pi->v;
+ el->jv = pi->jv;
el->aconst = 1;
- pi->a = a;
- pi->ja = ja;
-
- if (path->childs)
- __ses_path_split_i(f, path, 0, i, a, ja, &pi->a, &pi->ja);
-
- __ses_path_dr_reverse(f, path, 0, i, pi->a, pi->ja);
-
- scf_loge("i: %d, c%ldp%ld--c%ldp%ld, v: %lg, pi->v: %lg, pi->a: %lg, pr: %lg, sr: %lg\n\n",
- i, p0->cid, p0->id, pi->cid, pi->id, v, pi->v, pi->a, pr, sr);
-
- } else if (SCF_EDA_NPN == c->type && SCF_EDA_NPN_E == pj->id) {
-
- el = f->elines[pi->lid];
+ el = f->elines[pj->lid];
el->a = a;
el->ja = ja;
+ el->v = pj->v;
+ el->jv = pj->jv;
el->aconst = 1;
- pi->a = a;
- pi->ja = ja;
-
if (path->childs)
- __ses_path_split_i(f, path, 0, i, a, ja, &pi->a, &pi->ja);
-
- p = c->pins[SCF_EDA_NPN_B];
+ __ses_path_split_i(f, path, info->i, info->j, a, ja, &pi->a, &pi->ja);
- __ses_path_dr_reverse(f, path, 0, i, pi->a, pi->ja);
+ scf_loge("info->i: %d, info->j: %d, c%ldp%ld--c%ldp%ld, pi->v: %lg, pj->v: %lg, pi->a: %lg\n\n",
+ info->i, info->j, pi->cid, pi->id, pj->cid, pj->id, pi->v, pj->v, pi->a);
- scf_loge("i: %d, c%ldp%ld--c%ldp%ld, v: %lg, pi->v: %lg, pi->a: %lg, pr: %lg, sr: %lg\n\n",
- i, p0->cid, p0->id, pi->cid, pi->id, v, pi->v, pi->a, pr, sr);
+ __ses_path_dr_forward(f, path, info->i, info->j, pi->a, pi->ja);
}
return 0;