#include"ses_core.h"
-void ses_route_print(scf_vector_t* route)
+int ses_paths_find_flow(ses_flow_t* flow, scf_vector_t* paths, ScfEpin* vip, ses_path_t* bridge)
{
- if (!route || route->size <= 0)
- return;
-
ses_path_t* path;
- ScfEpin* p2;
ScfEpin* p;
int i;
int j;
- p2 = route->data[0];
-
- printf("route->size: %d, c%ldp%ld, ", route->size, p2->cid, p2->id);
-
- for (i = 0; i < route->size - 1; i++) {
- path = route->data[i];
-
- for (j = 0; j < path->pins->size; j++) {
- p = path->pins->data[j];
-
- printf("c%ldp%ld ", p->cid, p->id);
-
- if (p->lid == p2->lid) {
- p2 = path->pins->data[0];
- break;
- }
- }
- printf(", ");
- }
-
- printf("\n");
-}
-
-int ses_paths_find_route(scf_vector_t* __route, scf_vector_t* paths, ScfEpin* p, ses_path_t* bridge)
-{
- ses_path_t* path;
- ScfEpin* p2;
-
- int i;
- int j;
-
for (i = 0; i < paths->size; i++) {
path = paths->data[i];
continue;
for (j = 0; j < path->pins->size; j++) {
- p2 = path->pins->data[j];
+ p = path->pins->data[j];
- if (p2->lid == p->lid) {
-
- if (scf_vector_add(__route, p2) < 0)
- return -1;
+ if (vip ->lid == p->lid) {
+ flow->vip = p;
- if (scf_vector_add(__route, path) < 0)
+ if (scf_vector_add(flow->paths, path) < 0)
return -1;
return 1;
}
if (!path->childs)
continue;
- int ret = ses_paths_find_route(__route, path->childs, p, bridge);
+ int ret = ses_paths_find_flow(flow, path->childs, p, bridge);
if (ret < 0)
return ret;
if (1 == ret) {
- if (scf_vector_add(__route, path) < 0)
+ if (scf_vector_add(flow->paths, path) < 0)
return -1;
return 1;
}
return 0;
}
-static int __ses_path_va_balance(ScfEfunction* f, ses_path_t* bridge, scf_vector_t* route0, scf_vector_t* route1)
+static int __ses_path_va_balance(ScfEfunction* f, ses_path_t* bridge, ses_flow_t* flow0, ses_flow_t* flow1)
{
- if (!bridge)
+ if (!bridge || !flow0 || !flow1)
return -EINVAL;
if (bridge->pins->size < 2) {
return -EINVAL;
}
- ses_path_t* child;
ScfEcomponent* c;
ScfEline* el;
ScfEpin* p;
- ScfEpin* p0;
- ScfEpin* p1;
- ScfEpin* p2;
- ScfEpin* rp0;
- ScfEpin* rp1;
+ ScfEpin* p0 = bridge->pins->data[0];
+ ScfEpin* p1 = bridge->pins->data[bridge->pins->size - 1];
+
+ ses_path_t* path0 = flow0->paths->data[flow0->paths->size - 1];
+ ses_path_t* path1 = flow1->paths->data[flow1->paths->size - 1];
+
+ ScfEpin* r0p0 = path0->pins->data[0];
+ ScfEpin* r0p1 = flow0->vip;
+
+ ScfEpin* r1p0 = path1->pins->data[0];
+ ScfEpin* r1p1 = flow1->vip;
int i;
int j;
int k;
- p0 = bridge->pins->data[0];
- p1 = bridge->pins->data[bridge->pins->size - 1];
-
el = f->elines[p0->lid];
p0->v = el->v;
p0->jv = el->jv;
scf_loge("p0: %lg + j%lg, p1: %lg + j%lg, bridge->r: %lg + j%lg\n", p0->v, p0->jv, p1->v, p1->jv, bridge->r, bridge->jr);
- rp0 = route0->data[0];
- rp1 = route1->data[0];
+ if (p0->v > p1->v) {
- scf_loge("rp0->pr: %lg + j%lg, rp1->pr: %lg + j%lg\n", rp0->pr, rp0->jpr, rp1->pr, rp1->jpr);
+ double v = r0p0->v - p1->v;
+ double jv = r0p0->jv - p1->jv;
- if (p0->v > p1->v) {
+ double r0 = r0p1->pr - r0p0->pr;
+ double jr0 = r0p1->jpr - r0p0->jpr;
- for (i = 0; i < bridge->pins->size; i++) {
- p = bridge->pins->data[i];
+ double r = r0 + bridge->r;
+ double jr = jr0 + bridge->jr;
- c = f->components[p->cid];
+ double a;
+ double ja;
- if (SCF_EDA_Diode == c->type) {
+ ses_ur_i(&a, &ja, v, jv, r, jr);
- if (SCF_EDA_Diode_NEG == p->id || p0->v - p1->v < SCF_EDA_V_Diode_OFF)
- c->status = SCF_EDA_Status_OFF;
- else
- c->status = SCF_EDA_Status_ON;
- }
- }
+ scf_loge("r->pr: %lg + j%lg, v: %lg + j%lg, a: %lg + j%lg\n", r, jr, v, jv, a, ja);
} else {
static int _va_balance_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx)
{
- scf_vector_t* route0;
- scf_vector_t* route1;
-
+ ses_flow_t* flow0;
+ ses_flow_t* flow1;
ses_path_t* bridge;
+
ScfEcomponent* B;
ScfEpin* p0;
ScfEpin* p1;
printf("\n*******************\n");
- route0 = scf_vector_alloc();
- if (!route0)
+ flow0 = ses_flow_alloc();
+ if (!flow0)
return -ENOMEM;
- route1 = scf_vector_alloc();
- if (!route1) {
- scf_vector_free(route0);
+ flow1 = ses_flow_alloc();
+ if (!flow1) {
+ ses_flow_free(flow0);
return -ENOMEM;
}
ses_path_print(bridge);
- route0->size = 0;
- route1->size = 0;
+ flow0->paths->size = 0;
+ flow1->paths->size = 0;
- int ret = ses_paths_find_route(route0, ctx->paths, p0, bridge);
+ int ret = ses_paths_find_flow(flow0, ctx->paths, p0, bridge);
if (ret < 0)
return ret;
- ret = ses_paths_find_route(route1, ctx->paths, p1, bridge);
+ ret = ses_paths_find_flow(flow1, ctx->paths, p1, bridge);
if (ret < 0)
return ret;
- ses_route_print(route0);
+ ses_flow_print(flow0);
printf("\n");
- ses_route_print(route1);
+ ses_flow_print(flow1);
printf("\n");
- ret = __ses_path_va_balance(f, bridge, route0, route1);
+ ret = __ses_path_va_balance(f, bridge, flow0, flow1);
if (ret < 0)
return ret;
printf("\n");
}
- scf_vector_free(route0);
- scf_vector_free(route1);
+ ses_flow_free(flow0);
+ ses_flow_free(flow1);
return 0;
}
&ses_step_output,
};
+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)
+ goto _paths_error;
+
+ flow->ppins = scf_vector_alloc();
+ if (!flow->ppins)
+ goto _ppins_error;
+
+ flow->npins = scf_vector_alloc();
+ if (!flow->npins)
+ goto _npins_error;
+
+ return flow;
+
+_npins_error:
+ scf_vector_free(flow->ppins);
+_ppins_error:
+ scf_vector_free(flow->paths);
+_paths_error:
+ free(flow);
+ return NULL;
+}
+
+void ses_flow_free(ses_flow_t* flow)
+{
+ if (flow) {
+ if (flow->paths)
+ scf_vector_free(flow->paths);
+
+ if (flow->ppins)
+ scf_vector_free(flow->ppins);
+
+ if (flow->npins)
+ scf_vector_free(flow->npins);
+
+ free(flow);
+ }
+}
+
+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;
+
+ for (i = 0; i < flow->paths->size; i++) {
+ path = flow->paths->data[i];
+
+ for (j = 0; j < path->pins->size; j++) {
+ p = path->pins->data[j];
+
+ printf("c%ldp%ld ", p->cid, p->id);
+
+ if (p->lid == vip->lid) {
+ vip = path->pins->data[0];
+ break;
+ }
+ }
+ printf(", ");
+ }
+
+ printf(";\n");
+
+ vip = flow->vip;
+
+ for (i = 0; i < flow->paths->size; i++) {
+ path = flow->paths->data[i];
+
+ int flag = 0;
+
+ for (j = 0; j < path->pins->size; j++) {
+ p = path->pins->data[j];
+
+ if (!flag && p->lid == vip->lid) {
+ flag = 1;
+ continue;
+ }
+
+ printf("c%ldp%ld ", p->cid, p->id);
+ }
+
+ printf(", ");
+
+ vip = path->pins->data[j - 1];
+ }
+
+ printf(".\n");
+}
+
ses_path_t* ses_path_alloc()
{
ses_path_t* path = calloc(1, sizeof(ses_path_t));