CFILES += pack/scf_pack.c
CFILES += ses_layout.c
-CFILES += ses_layout_topo.c
CFILES += ses_graph.c
CFILES += ses_utils.c
CFILES += ses_path.c
-CFILES += ses_flow.c
CFILES += ses_node_analysis.c
CFILES += ses_steps.c
printf("f: %s\n", f->name);
- ses_steps_analyse(f, 100, 5);
+ ses_steps_analyse(f, 100, 3);
}
#endif
#define SCF_EDA_PIN_NEG 8
#define SCF_EDA_PIN_CF 16
#define SCF_EDA_PIN_BORDER 32
+#define SCF_EDA_PIN_CONST 64
+#define SCF_EDA_PIN_IN0 128
#define SCF_EDA_V_INIT -10001001.0
#define SCF_EDA_V_MIN -10000000.0
void ses_nodes_free (scf_vector_t* nodes);
void ses_nodes_print(scf_vector_t* nodes);
-
-ses_flow_t* ses_flow_alloc();
-void ses_flow_free (ses_flow_t* flow);
-void ses_flow_print(ses_flow_t* flow);
-
-void ses_flow_v_pos(ses_flow_t* flow, double a, double ja);
-void ses_flow_v_neg(ses_flow_t* flow, double a, double ja);
-void ses_flow_jr (ses_flow_t* flow, ScfEfunction* f);
+void ses_paths_print(scf_vector_t* paths);
ses_ctx_t* ses_ctx_alloc();
void ses_ctx_free (ses_ctx_t* ctx);
+++ /dev/null
-#include"ses_core.h"
-
-ses_flow_t* ses_flow_alloc()
-{
- ses_flow_t* flow = calloc(1, sizeof(ses_flow_t));
- if (!flow)
- return NULL;
-
- flow->paths = scf_vector_alloc();
- if (!flow->paths) {
- ses_flow_free(flow);
- return NULL;
- }
-
- return flow;
-}
-
-void ses_flow_free(ses_flow_t* flow)
-{
- if (flow) {
- if (flow->paths)
- scf_vector_free(flow->paths);
-
- free(flow);
- }
-}
-
-int ses_paths_find_flow(ses_flow_t* flow, scf_vector_t* paths, ScfEpin* vip, ses_path_t* bridge)
-{
- ses_path_t* path;
- ScfEpin* p;
-
- int i;
- int j;
-
- for (i = 0; i < paths->size; i++) {
- path = paths->data[i];
-
- if (path == bridge)
- continue;
-
- for (j = 0; j < path->pins->size; j++) {
- p = path->pins->data[j];
-
- if (vip->lid == p->lid) {
-
- if (j + 1 >= path->pins->size)
- break;
-
- if (scf_vector_add(flow->paths, path) < 0)
- return -1;
-
- flow->vip = p;
- flow->vip_i = j;
- flow->vip_m = 0;
- flow->vip_n = path->pins->size - 1;
- return 1;
- }
- }
-
- if (path->childs) {
- int ret = ses_paths_find_flow(flow, path->childs, vip, bridge);
- if (ret < 0)
- return ret;
-
- if (1 == ret) {
- if (scf_vector_add(flow->paths, path) < 0)
- return -ENOMEM;
- return 1;
- }
- }
-
- if (path->bridges) {
- int ret = ses_paths_find_flow(flow, path->bridges, vip, bridge);
- if (ret < 0)
- return ret;
-
- if (1 == ret) {
- if (scf_vector_add(flow->paths, path) < 0)
- return -ENOMEM;
- return 1;
- }
- }
- }
-
- return 0;
-}
-
-int ses_flow_find_neg(ses_flow_t* flow, scf_vector_t* paths, ScfEfunction* f)
-{
- if (flow->paths->size <= 0)
- return 0;
-
- ses_path_t* path = flow->paths->data[flow->paths->size - 1];
- ScfEpin* vp = flow->vip;
- ScfEpin* p = path->pins->data[path->pins->size - 1];
-
- ScfEcomponent* B = f->components[0];
- ScfEpin* Bn = B->pins[SCF_EDA_Battery_NEG];
-
- while (p->lid != Bn->lid) {
- int ret = ses_paths_find_flow(flow, paths, p, path);
- if (ret < 0)
- return ret;
-
- path = flow->paths->data[flow->paths->size - 1];
- p = path->pins ->data[path->pins->size - 1];
- }
-
- flow->vip = vp;
- return 0;
-}
-
-int ses_flow_find_pos(ses_flow_t* flow, scf_vector_t* paths, ScfEfunction* f)
-{
- if (flow->paths->size <= 0)
- return 0;
-
- ses_path_t* path = flow->paths->data[flow->paths->size - 1];
- ScfEpin* vp = flow->vip;
- ScfEpin* p = path->pins->data[0];
-
- ScfEcomponent* B = f->components[0];
- ScfEpin* Bp = B->pins[SCF_EDA_Battery_POS];
-
- while (p->lid != Bp->lid) {
- int ret = ses_paths_find_flow(flow, paths, p, path);
- if (ret < 0)
- return ret;
-
- path = flow->paths->data[flow->paths->size - 1];
- p = path->pins ->data[0];
- }
-
- flow->vip = vp;
- return 0;
-}
-
-void ses_flow_jr(ses_flow_t* flow, ScfEfunction* f)
-{
- if (!flow)
- return;
-
- flow->pos_pins = 0;
- flow->neg_pins = 0;
-
- flow->pos_r = 0;
- flow->neg_r = 0;
-
- flow->pos_cv = 0;
- flow->neg_cv = 0;
-
- if (!flow->paths || !flow->vip)
- return;
-
- ses_path_t* path;
- ses_path_t* child;
- ScfEcomponent* c;
- ScfEpin* p;
- ScfEpin* p0;
- ScfEpin* vip = flow->vip;
-
- int i;
- int j;
- int m;
- int n;
-
- for (i = 0; i < flow->paths->size; i++) {
- path = flow->paths->data[i];
-
- if (0 == i) {
- m = flow->vip_m;
- n = flow->vip_n;
- } else {
- m = 0;
- n = path->pins->size - 1;
- }
-
- for (j = m; j <= n; j++) {
- p = path->pins->data[j];
-
- ++flow->pos_pins;
-
- c = f->components[p->cid];
-
- if (SCF_EDA_NPN == c->type && SCF_EDA_NPN_B == p->id)
- flow->pos_NPNs++;
- else if (SCF_EDA_Diode == c->type && SCF_EDA_Diode_POS == p->id)
- flow->pos_diodes++;
-
- else if (SCF_EDA_Capacitor == c->type && (j & 0x1)) {
- int sign = !p->id - p->id;
-
- flow->pos_cv += c->v * sign;
- }
-
- if (p->lid == vip->lid) {
- vip = path->pins->data[0];
-
- child = ses_path_find_child(path, 0, j);
- if (!child)
- child = ses_path_find_bridge(path, 0, j);
-
- if (child) {
- flow->pos_r += child->parent_pr;
-
- } else if (SCF_EDA_NPN == c->type && SCF_EDA_NPN_E == p->id) {
- p = path->pins->data[j - 1];
-
- flow->pos_r += p->pr + p->r + p->dr;
- } else
- flow->pos_r += p->pr;
-
- scf_logd("flow->pos_r: %lg, c%ldp%ld->pr: %lg, vip c%ldp%ld->pr: %lg\n",
- flow->pos_r, p->cid, p->id, p->pr, vip->cid, vip->id, vip->pr);
- break;
- }
- }
- }
-
- vip = flow->vip;
-
- for (i = 0; i < flow->paths->size; i++) {
- path = flow->paths->data[i];
-
- if (0 == i) {
- m = flow->vip_m;
- n = flow->vip_n;
- } else {
- m = 0;
- n = path->pins->size - 1;
- }
-
- int parallel = 0;
- int j0;
-
- p0 = NULL;
- for (j = m; j <= n; j++) {
- p = path->pins->data[j];
-
- if (!p0) {
- if (!(j & 0x1) && p->lid == vip->lid) {
- p0 = p;
- j0 = j;
-
- child = ses_path_find_child(path, j0, n);
- if (child)
- parallel = 1;
- } else
- continue;
- }
-
- ++flow->neg_pins;
-
- c = f->components[p->cid];
-
- if (SCF_EDA_NPN == c->type && SCF_EDA_NPN_B == p->id)
- flow->neg_NPNs++;
- else if (SCF_EDA_Diode == c->type && SCF_EDA_Diode_POS == p->id)
- flow->neg_diodes++;
-
- else if (SCF_EDA_Capacitor == c->type && (j & 0x1)) {
- int sign = !p->id - p->id;
-
- flow->neg_cv += c->v * sign;
- }
-
- if (parallel)
- continue;
-
- if (SCF_EDA_NPN == c->type && SCF_EDA_NPN_E == p->id) {
- p = path->pins->data[j - 1];
-
- if (p->lid == p0->lid)
- flow->neg_r += p->r + p->dr;
- else
- flow->neg_r += p->pr - p0->pr;
-
- scf_logd("flow->neg_r: %lg, c%ldp%ld->sr: %lg, p0 c%ldp%ld->pr: %lg\n",
- flow->neg_r, p->cid, p->id, p->sr, p0->cid, p0->id, p0->pr);
-
- if (j + 1 <= n) {
- p0 = path->pins->data[j + 1];
- j0 = j + 1;
- } else {
- p0 = path->pins->data[j];
- j0 = j;
- }
-
- } else if (p->sr != p->pr) {
-
- child = ses_path_find_child(path, j0, j);
- if (!child)
- child = ses_path_find_bridge(path, j0, j);
-
- if (child)
- flow->neg_r += child->parent_pr - p0->pr;
- else
- flow->neg_r += p->sr - p0->pr;
-
- scf_logd("flow->neg_r: %lg, c%ldp%ld->sr: %lg, p->pr: %lg, p0 c%ldp%ld->pr: %lg\n",
- flow->neg_r, p->cid, p->id, p->sr, p->pr, p0->cid, p0->id, p0->pr);
-
- p0 = p;
- j0 = j;
- }
- }
-
- if (p0) {
- vip = path->pins->data[j - 1];
- c = f->components[vip->cid];
-
- if (vip != p0) {
- child = ses_path_find_child(path, j0, j - 1);
- if (child)
- flow->neg_r += child->parent_pr - p0->pr;
- else
- flow->neg_r += vip->sr - p0->pr;
- }
-
- scf_logd("flow->neg_r: %lg, vip c%ldp%ld->sr: %lg, p0 c%ldp%ld->pr: %lg\n",
- flow->neg_r, vip->cid, vip->id, vip->sr, p0->cid, p0->id, p0->pr);
-
- if (SCF_EDA_NPN == c->type && SCF_EDA_NPN_E == vip->id)
- vip->pr = path->parent_pr;
- }
-
- scf_logd("flow->neg_r: %lg, vip c%ldp%ld->sr: %lg\n", flow->neg_r, vip->cid, vip->id, vip->sr);
- }
-
- scf_loge("flow pos_r: %lg, neg_r: %lg, pos_cv: %lg, neg_cv: %lg, vip: c%ldp%ld, pos_diodes: %d, pos_NPNs: %d, neg_diodes: %d, neg_NPNs: %d\n",
- flow->pos_r, flow->neg_r, flow->pos_cv, flow->neg_cv, flow->vip->cid, flow->vip->id, flow->pos_diodes, flow->pos_NPNs, flow->neg_diodes, flow->neg_NPNs);
-}
-
-void ses_flow_print(ses_flow_t* flow)
-{
- if (!flow || !flow->paths || !flow->vip)
- return;
-
- ses_path_t* path;
- ScfEpin* p;
- ScfEpin* vip = flow->vip;
-
- int i;
- int j;
- int m;
- int n;
-
- for (i = flow->paths->size - 1; i >= 0; i--) {
-
- if (i > 0) {
- path = flow->paths->data[i - 1];
-
- vip = path->pins->data[0];
- m = 0;
- n = path->pins->size - 1;
- } else {
- vip = flow->vip;
- m = flow->vip_m;
- n = flow->vip_n;
- }
-
- path = flow->paths->data[i];
-
- for (j = m; j <= n; j++) {
- p = path->pins->data[j];
-
- printf("c%ldp%ld ", p->cid, p->id);
-
- if (p->lid == vip->lid)
- break;
- }
-
- if (i > 0)
- printf(", ");
- }
-
- printf(";\n");
-
- vip = flow->vip;
-
- for (i = 0; i < flow->paths->size; i++) {
- path = flow->paths->data[i];
-
- if (i > 0) {
- m = 0;
- n = path->pins->size - 1;
- } else {
- m = flow->vip_m;
- n = flow->vip_n;
- }
-
- int flag = 0;
-
- for (j = m; j <= n; j++) {
- p = path->pins->data[j];
-
- if (!flag) {
- if (p->lid == vip->lid)
- flag = 1;
- continue;
- }
-
- printf("c%ldp%ld ", p->cid, p->id);
- }
-
- if (flag)
- printf(", ");
-
- vip = path->pins->data[j - 1];
- }
-
- printf(".\n");
-}
return 0;
}
-int epin_cmp_npn_c(const void* v0, const void* v1, void* arg)
-{
- const uint64_t* t0 = v0;
- const uint64_t* t1 = v1;
-
- ScfEfunction* f = arg;
- ScfEcomponent* c0 = f->components[t0[0]];
- ScfEcomponent* c1 = f->components[t1[0]];
- ScfEpin* p0 = c0->pins[t0[1]];
- ScfEpin* p1 = c1->pins[t1[1]];
-
- if (SCF_EDA_NPN != c0->type)
- return 1;
- if (SCF_EDA_NPN != c1->type)
- return -1;
-
- if (SCF_EDA_NPN_E != p0->id)
- return 1;
- if (SCF_EDA_NPN_E != p1->id)
- return -1;
-
- ScfEpin* pb0 = c0->pins[SCF_EDA_NPN_B];
- ScfEpin* pb1 = c1->pins[SCF_EDA_NPN_B];
-
- if (pb0->y < pb1->y)
- return -1;
- if (pb0->y > pb1->y)
- return 1;
-
- return 0;
-}
-
int epin_cmp_color(const void* v0, const void* v1, void* arg)
{
const uint64_t* t0 = v0;
f->elines[n]->vflag = 1;
eline_mov_before(f, __n, n);
-#if 1
- c = f->components[p->cid];
-
- if (SCF_EDA_NPN == c->type && SCF_EDA_NPN_C == p->id) {
- pe = c->pins[SCF_EDA_NPN_E];
- pb = c->pins[SCF_EDA_NPN_B];
-
- intptr_t ie = __ses_find_eline_index(f, pe->lid);
- intptr_t ib = __ses_find_eline_index(f, pb->lid);
-
- if (!f->elines[ib]->vflag) {
- f->elines[ib]->vflag = 1;
-
- eline_mov_after(f, __n, ib);
-
- ie = __ses_find_eline_index(f, pe->lid);
- ib = __ses_find_eline_index(f, pb->lid);
- n = __ses_find_eline_index(f, p->lid);
-
- scf_logw("**************** c%ldp%ld, ic: %ld, ib: %ld, ie: %ld\n", p->cid, p->id, n, ib, ie);
- }
- }
-#endif
}
}
-// printf("\n");
}
static void __ses_layout_path(ScfEfunction* f, ses_path_t* path, ses_path_t* base)
scf_vector_qsort(paths, epath_cmp_pins);
- _topo_print(paths);
+ ses_paths_print(paths);
B = f->components[0];
Bp = B->pins[SCF_EDA_Battery_POS];
return ret;
}
-static void __ses_layout_npn(ScfEfunction* f)
-{
- ScfEline* el0;
- ScfEline* el1;
-
- size_t i;
- size_t j;
-
- for (i = 0; i < f->n_elines; i++) {
- el0 = f->elines[i];
-
- if (el0->n_pins != 4)
- continue;
-
- intptr_t cflag = 0;
- intptr_t ib = INT_MAX;
-
- for (j = 0; j + 1 < el0->n_pins; j += 2) {
-
- ScfEcomponent* c = f->components[el0->pins[j]];
- ScfEpin* p = c->pins [el0->pins[j + 1]];
-
- if (c->color > 2)
- continue;
-
- if (SCF_EDA_NPN != c->type)
- continue;
-
- if (SCF_EDA_NPN_C == p->id)
- cflag = 1;
-
- intptr_t m = __ses_find_eline_index(f, c->pins[SCF_EDA_NPN_B]->lid);
-
- if (ib > m)
- ib = m;
- }
-
- if (cflag && ib < f->n_elines) {
- el1 = f->elines[ib];
-
- eline_mov_after(f, ib, i);
-
- scf_logi("mov el%ld [%ld] <--> [%ld] el%ld\n", el0->id, i, ib, el1->id);
- }
- }
-}
-
static int __ses_layout_lines2(ScfEfunction* f)
{
ScfEline* tmp;
__ses_layout_lines4(f);
- __ses_layout_npn(f);
-
#if 1
for (i = 0; i < f->n_elines; i++) {
el0 = f->elines[i];
else if (SCF_EDA_PIN_NEG & el->flags)
cairo_set_source_rgb(cr, 0, 0, 1);
+ else if (SCF_EDA_PIN_IN0 & el->flags)
+ cairo_set_source_rgb(cr, 0.8, 0, 0);
+
else if (SCF_EDA_PIN_IN & el->flags)
- cairo_set_source_rgb(cr, 0, 1, 0);
+ cairo_set_source_rgb(cr, 0, 0, 0.8);
+
+ else if (SCF_EDA_PIN_CONST & el->flags)
+ cairo_set_source_rgb(cr, 0, 0.6, 0);
else if (SCF_EDA_PIN_OUT & el->flags)
cairo_set_source_rgb(cr, 1, 0, 1);
else if (SCF_EDA_PIN_CF & el->flags)
- cairo_set_source_rgb(cr, 0.8, 0, 1.0);
+ cairo_set_source_rgb(cr, 0.8, 0, 0.8);
else
cairo_set_source_rgb(cr, 1, 0.5, 0.1);
uint8_t text[64];
- cairo_select_font_face(cr, "Georgia", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
+ cairo_select_font_face(cr, "Calibri", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
cairo_set_font_size (cr, 28);
ScfLine* prev = NULL;
+++ /dev/null
-#include"ses_core.h"
-
-static int __ses_dfs_add_path(scf_vector_t* paths, ses_path_t* path)
-{
- ScfEpin* p;
- int j;
-
- if (scf_vector_add(paths, path) < 0)
- return -ENOMEM;
-
- for (j = 0; j < path->pins->size; j++) {
- p = path->pins->data[j];
- p->pflag = 1;
- p->path = (uintptr_t)path;
- }
-
- return 0;
-}
-
-static int __layout_dfs_path(ScfEfunction* f, ScfEcomponent* rc, ScfEpin* rp, scf_vector_t* __paths, ses_path_t** ppath)
-{
- ScfEcomponent* c;
- ScfEline* el;
- ScfEpin* np;
- ScfEpin* p;
-
- int64_t i;
- int64_t j;
-
- if (SCF_EDA_Status_OFF == rc->status)
- return SCF_EDA_Status_OFF;
-
- if (SCF_EDA_Diode == rc->type && SCF_EDA_Diode_NEG == rp->id)
- return SCF_EDA_Path_OFF;
-
- if (SCF_EDA_NPN == rc->type && SCF_EDA_NPN_E == rp->id)
- return SCF_EDA_Path_OFF;
-
- if (SCF_EDA_PNP == rc->type && SCF_EDA_PNP_E != rp->id)
- return SCF_EDA_Path_OFF;
-
- if (!*ppath) {
- *ppath = ses_path_alloc();
- if (!*ppath)
- return -ENOMEM;
- }
-
- if (scf_vector_add((*ppath)->pins, rp) < 0)
- return -ENOMEM;
-
- if (!((SCF_EDA_NPN == rc->type && SCF_EDA_NPN_E == rp->id)
- || (SCF_EDA_PNP == rc->type && SCF_EDA_PNP_E == rp->id)))
- rp->vflag = 1;
-
- scf_logd("c%ldp%ld, l%ld, vflag: %d, pflag: %d\n", rp->cid, rp->id, rp->lid, rp->vflag, rp->pflag);
-
- int ret = 0;
-
- for (i = 0; i < rc->n_pins; i++) {
- np = rc->pins[i];
-
- if (np->vflag)
- continue;
-
- if (SCF_EDA_NPN == rc->type && SCF_EDA_NPN_E != np->id)
- continue;
- if (SCF_EDA_PNP == rc->type && SCF_EDA_PNP_E == np->id)
- continue;
-
- scf_logd("c%ldp%ld, l%ld, vflag: %d, pflag: %d\n", np->cid, np->id, np->lid, np->vflag, np->pflag);
-
- el = f->elines[np->lid];
-
- if (SCF_EDA_PIN_POS & el->flags) {
- scf_logd("pos l%ld\n\n", el->id);
-
- ret = SCF_EDA_Path_OFF;
- continue;
- }
-
- if (!*ppath) {
- *ppath = ses_path_alloc();
- if (!*ppath)
- return -ENOMEM;
- }
-
- if (SCF_EDA_PNP == rc->type && 0 == (*ppath)->pins->size) {
-
- if (scf_vector_add((*ppath)->pins, rp) < 0)
- return -ENOMEM;
- }
-
- if (scf_vector_add((*ppath)->pins, np) < 0)
- return -ENOMEM;
-
- if (!((SCF_EDA_NPN == rc->type && SCF_EDA_NPN_E == np->id)
- || (SCF_EDA_PNP == rc->type && SCF_EDA_PNP_E == np->id)))
- np->vflag = 1;
-
- if (SCF_EDA_PIN_NEG & el->flags) {
- scf_logd("neg l%ld\n\n", el->id);
-
- ret = __ses_dfs_add_path(__paths, *ppath);
- if (ret < 0)
- return ret;
-
- *ppath = NULL;
- return 0;
- }
-
- ret = 0;
-
- for (j = 0; j + 1 < el->n_pins; j += 2) {
-
- c = f->components[el->pins[j]];
- p = c->pins [el->pins[j + 1]];
-
- if (p->pflag) {
- if (p != np && *ppath) {
- scf_logd("branch: c%ld_p%ld, l%ld\n\n", c->id, p->id, el->id);
-
- if ((*ppath)->pins->size > 0) {
-
- ret = __ses_dfs_add_path(__paths, *ppath);
- if (ret < 0)
- return ret;
- } else
- ses_path_free(*ppath);
-
- *ppath = NULL;
- }
- continue;
- }
-
- if (p->vflag)
- continue;
-
- if (!((SCF_EDA_NPN == c->type && SCF_EDA_NPN_E == p->id)
- || (SCF_EDA_PNP == c->type && SCF_EDA_PNP_E == p->id)))
- p->vflag = 1;
-
- ret = __layout_dfs_path(f, c, p, __paths, ppath);
- if (ret < 0)
- return ret;
-
- if (SCF_EDA_Path_OFF == ret)
- p->vflag = 0;
- }
-
- if (*ppath) {
- scf_vector_del((*ppath)->pins, np);
-
- if (SCF_EDA_Status_OFF != ret)
- ret = SCF_EDA_Path_OFF;
- }
-
- if (SCF_EDA_Path_OFF == ret)
- np->vflag = 0;
- }
-
- if (SCF_EDA_Status_OFF == ret || SCF_EDA_Path_OFF == ret) {
- if (*ppath)
- scf_vector_del((*ppath)->pins, rp);
-
- if (SCF_EDA_Path_OFF == ret) {
- rp->vflag = 0;
-
- scf_logd("off: c%ld_p%ld, l%ld\n\n", rp->cid, rp->id, rp->lid);
-
- } else if (SCF_EDA_Status_OFF == ret)
- scf_logd("off: c%ld_p%ld, l%ld\n\n", rp->cid, rp->id, rp->lid);
- }
-
- return ret;
-}
-
-static int __layout_add_path(ses_path_t* parent, ses_path_t* child)
-{
- ses_path_t* path;
- ScfEpin* cp0 = child->pins->data[0];
- ScfEpin* cp1 = child->pins->data[child->pins->size - 1];
- ScfEpin* p0;
- ScfEpin* p1;
-
- int i;
- int j;
-
- if (!parent->childs) {
- parent->childs = scf_vector_alloc();
- if (!parent->childs)
- return -ENOMEM;
- }
-
- for (i = 0; i < parent->childs->size; i++) {
- path = parent->childs->data[i];
-
- p0 = path->pins->data[0];
- p1 = path->pins->data[path->pins->size - 1];
-
- if (p0->lid == cp0->lid && p1->lid == cp1->lid)
- return __layout_add_path(path, child);
- }
-
- child->parent_p0 = -1;
- child->parent_p1 = -1;
-
- for (j = 0; j < parent->pins->size; j++) {
- p0 = parent->pins->data[j];
-
- if (p0->lid == cp0->lid)
- child->parent_p0 = (j + 1) & ~0x1;
-
- else if (p0->lid == cp1->lid)
- child->parent_p1 = j;
-
- if (child->parent_p0 >= 0 && child->parent_p1 >= 0)
- break;
- }
-
- child->parent = parent;
- return scf_vector_add(parent->childs, child);
-}
-
-static int _layout_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* p2;
- ScfEpin* p3;
- 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];
-
- for (i = paths->size - 1; i >= 0; i--) {
- child = paths->data[i];
-
- assert(child->pins->size >= 2);
-
- p0 = child->pins->data[0];
- p1 = child->pins->data[child->pins->size - 1];
-
- if (p0->lid == Bp->lid && p1->lid == Bn->lid)
- continue;
-
- for (j = paths->size - 1; j >= 0; j--) {
- parent = paths->data[j];
-
- if (parent == child)
- continue;
-
- int n = 0;
-
- for (k = 0; k < parent->pins->size; k++) {
- p = parent->pins->data[k];
-
- if (p->lid == p0->lid)
- n |= 0x1;
-
- if (p->lid == p1->lid)
- n |= 0x2;
-
- if (0x3 == n)
- goto branch;
- }
- }
-
- continue;
-
-branch:
- if (scf_vector_del(paths, child) < 0)
- return -1;
-
- if (__layout_add_path(parent, child) < 0) {
- ses_path_free(child);
- return -ENOMEM;
- }
- }
-
- return 0;
-}
-
-static int ses_layout_layers(ScfEfunction* f, scf_vector_t* paths)
-{
- ses_path_t* path;
-
- int size;
-
- do {
- size = paths->size;
-
- int ret = _layout_layers(f, paths);
- if (ret < 0)
- return ret;
-
- } while (size > paths->size);
-
- return 0;
-}
-
-static int _layout_paths(ScfEfunction* f, ScfEline* el, scf_vector_t* paths)
-{
- if (!f || !el || !paths)
- return -EINVAL;
-
- ses_path_t* path;
- ScfEcomponent* c;
- ScfEcomponent* B;
- ScfEpin* p;
-
- size_t i;
-
- B = f->components[0];
- path = NULL;
-
- for (i = 0; i + 1 < el->n_pins; i += 2) {
-
- c = f->components[el->pins[i]];
- p = c->pins [el->pins[i + 1]];
-
- if (c == B)
- continue;
-
- int ret = __layout_dfs_path(f, c, p, paths, &path);
- if (ret < 0)
- return ret;
-
- if (!path)
- continue;
-
- if (SCF_EDA_Status_OFF == ret || SCF_EDA_Path_OFF == ret) {
- ses_path_free(path);
- path = NULL;
- continue;
- }
-
- if (scf_vector_add(paths, path) < 0) {
- ses_path_free(path);
- return -ENOMEM;
- }
-
- path = NULL;
- }
-
- if (path) {
- ses_path_free(path);
- path = NULL;
- }
-
- for (i = 0; i < paths->size; i++) {
- path = paths->data[i];
-
- path->index = i;
- }
-
- return 0;
-}
-
-int ses_layout_paths(ScfEfunction* f, scf_vector_t* paths)
-{
- if (!f || !paths)
- return -EINVAL;
-
- ses_path_t* path;
- ScfEcomponent* B;
- ScfEline* el;
-
- scf_vector_clear(paths, ( void (*)(void*) )ses_path_free);
-
- B = f->components[0];
- el = f->elines[B->pins[SCF_EDA_Battery_POS]->lid];
-
- int ret = _layout_paths(f, el, paths);
- if (ret < 0)
- return ret;
-
- int i;
- for (i = 0; i < f->n_elines; i++) {
- el = f->elines[i];
-
- if (el->flags & SCF_EDA_PIN_IN) {
-
- ret = _layout_paths(f, el, paths);
- if (ret < 0)
- return ret;
- }
- }
-
- return ses_layout_layers(f, paths);
-}
c->lock = 1;
(*n_offs)++;
- scf_loge("\033[34mc%ld, status: %d, dV: %lg, Ib: %lg, Rb: %lg, edge->index: %d\033[0m\n", c->id, c->status, dV, Ib, Rb, edge->index);
+ scf_logd("\033[34mc%ld, status: %d, dV: %lg, Ib: %lg, Rb: %lg, edge->index: %d\033[0m\n", c->id, c->status, dV, Ib, Rb, edge->index);
}
} else if (edge->edge_b) {
}
}
+void ses_paths_print(scf_vector_t* paths)
+{
+ ses_path_t* path;
+
+ int i;
+ for (i = 0; i < paths->size; i++) {
+ path = paths->data[i];
+
+ ses_path_print(path);
+ printf("\n");
+ }
+}
+
int ses_path_is_child(ses_path_t* parent, ses_path_t* child)
{
ScfEpin* cp0 = child->pins->data[0];
else if (SCF_EDA_PIN_OUT & el->flags)
cairo_set_source_rgb(cr, 1, 0, 1);
- else if (el->v == B->pins[SCF_EDA_Battery_POS]->v)
+ else if (SCF_EDA_PIN_IN0 & el->flags)
cairo_set_source_rgb(cr, 0.8, 0, 0);
- else if (el->v == B->pins[SCF_EDA_Battery_NEG]->v)
+ else if (SCF_EDA_PIN_IN & el->flags)
cairo_set_source_rgb(cr, 0, 0, 0.8);
- else if (SCF_EDA_PIN_IN & el->flags)
- cairo_set_source_rgb(cr, 0, 1, 0);
+ else if (SCF_EDA_PIN_CONST & el->flags)
+ cairo_set_source_rgb(cr, 0, 0.6, 0);
else if (SCF_EDA_PIN_CF & el->flags)
- cairo_set_source_rgb(cr, 0.8, 0, 1.0);
+ cairo_set_source_rgb(cr, 0.8, 0, 0.8);
else
cairo_set_source_rgb(cr, 1, 0.5, 0.1);
n = snprintf(text, sizeof(text) - 1, "%lgmV", (int64_t)(el->v * 1000.0 * SHOW_BITS) / SHOW_BITS);
else
n = snprintf(text, sizeof(text) - 1, "%lguV", (int64_t)(el->v * 1000000.0 * SHOW_BITS) / SHOW_BITS);
-#if 0
- // A of line
- if (el->aout > 1e-1 || el->aout < -1e-1)
- n += snprintf(text + n, sizeof(text) - 1 - n, ", %lgA", (int64_t)(el->aout * SHOW_BITS) / SHOW_BITS);
- else if (el->aout > 1e-5 || el->aout < -1e-5)
- n += snprintf(text + n, sizeof(text) - 1 - n, ", %lgmA", (int64_t)(el->aout * 1000.0 * SHOW_BITS) / SHOW_BITS);
- else
- n += snprintf(text + n, sizeof(text) - 1 - n, ", %lguA", (int64_t)(el->aout * 1000000.0 * SHOW_BITS) / SHOW_BITS);
+ cairo_set_font_size(cr, 20);
- if (el->ain > 1e-1 || el->ain < -1e-1)
- n += snprintf(text + n, sizeof(text) - 1 - n, ", in %lgA", (int64_t)(el->ain * SHOW_BITS) / SHOW_BITS);
+ if (el->v == B->pins[SCF_EDA_Battery_POS]->v)
+ cairo_set_source_rgb(cr, 1, 0, 0);
- else if (el->ain > 1e-5 || el->ain < -1e-5)
- n += snprintf(text + n, sizeof(text) - 1 - n, ", in %lgmA", (int64_t)(el->ain * 1000.0 * SHOW_BITS) / SHOW_BITS);
- else
- n += snprintf(text + n, sizeof(text) - 1 - n, ", in %lguA", (int64_t)(el->ain * 1000000.0 * SHOW_BITS) / SHOW_BITS);
-#endif
- cairo_set_font_size(cr, 20);
+ else if (el->v == B->pins[SCF_EDA_Battery_NEG]->v)
+ cairo_set_source_rgb(cr, 0, 0, 1);
cairo_move_to (cr, l->x0 + 10, l->y0 - 8);
cairo_show_text(cr, text);
if (prev) {
if (!(el->flags & SCF_EDA_PIN_BORDER))
- cairo_set_line_width(cr, 1);
+ cairo_set_line_width(cr, 1.5);
cairo_move_to(cr, prev->x0, prev->y0);
cairo_line_to(cr, l->x0, l->y0);
}
}
-int _topo_print(scf_vector_t* paths)
-{
- ses_path_t* path;
-
- int i;
- for (i = 0; i < paths->size; i++) {
- path = paths->data[i];
-
- ses_path_print(path);
-
- printf("\n");
- }
-}
-
static void _topo_clear(ScfEfunction* f)
{
if (!f)
return 0;
}
-static int __ses_topo_layers(ScfEfunction* f, scf_vector_t* paths)
+int __ses_topo_layers(ScfEfunction* f, scf_vector_t* paths)
{
ses_path_t* path;
return _topo_bridge_piers(f, paths);
}
+int ses_layout_paths(ScfEfunction* f, scf_vector_t* paths)
+{
+ if (!f || !paths)
+ return -EINVAL;
+
+ ses_path_t* path;
+ ScfEcomponent* B;
+ ScfEline* el;
+
+ scf_vector_clear(paths, ( void (*)(void*) )ses_path_free);
+
+ B = f->components[0];
+ el = f->elines[B->pins[SCF_EDA_Battery_POS]->lid];
+
+ int ret = _topo_paths(f, el, paths);
+ if (ret < 0)
+ return ret;
+
+ int i;
+ for (i = 0; i < f->n_elines; i++) {
+ el = f->elines[i];
+
+ if (el->flags & SCF_EDA_PIN_IN) {
+
+ ret = _topo_paths(f, el, paths);
+ if (ret < 0)
+ return ret;
+ }
+ }
+
+ ses_paths_print(paths);
+
+ return __ses_topo_layers(f, paths);
+}
+
static int _topo_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx)
{
ses_path_t* path;
return ret;
}
- _topo_print(ctx->paths);
+ ses_paths_print(ctx->paths);
return 0;
}