#include"ses_core.h"
+void ses_route_print(scf_vector_t* route)
+{
+ 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];
+
+ if (path == bridge)
+ continue;
+
+ for (j = 0; j < path->pins->size; j++) {
+ p2 = path->pins->data[j];
+
+ if (p2->lid == p->lid) {
+
+ if (scf_vector_add(__route, p2) < 0)
+ return -1;
+
+ if (scf_vector_add(__route, path) < 0)
+ return -1;
+ return 1;
+ }
+ }
+
+ if (!path->childs)
+ continue;
+
+ int ret = ses_paths_find_route(__route, path->childs, p, bridge);
+ if (ret < 0)
+ return ret;
+
+ if (1 == ret) {
+ if (scf_vector_add(__route, path) < 0)
+ return -1;
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+static int __ses_path_va_balance(ScfEfunction* f, ses_path_t* path, scf_vector_t* route0, scf_vector_t* route1)
+{
+ 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;
+
+ scf_loge("p0: %lg + j%lg, p1: %lg + j%lg\n", p0->v, p0->jv, p1->v, p1->jv);
+
+ return 0;
+}
+
static int _va_balance_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx)
{
- ses_path_t* path;
+ scf_vector_t* route0;
+ scf_vector_t* route1;
+
+ ses_path_t* bridge;
ScfEcomponent* B;
ScfEpin* p0;
ScfEpin* p1;
printf("\n*******************\n");
+ route0 = scf_vector_alloc();
+ if (!route0)
+ return -ENOMEM;
+
+ route1 = scf_vector_alloc();
+ if (!route1) {
+ scf_vector_free(route0);
+ return -ENOMEM;
+ }
+
int i;
for (i = 0; i < ctx->paths->size; i++) {
- path = ctx->paths->data[i];
+ bridge = ctx->paths->data[i];
- if (path->pins->size < 2) {
+ if (bridge->pins->size < 2) {
scf_loge("\n");
return -EINVAL;
}
- p0 = path->pins->data[0];
- p1 = path->pins->data[path->pins->size - 1];
+ p0 = bridge->pins->data[0];
+ p1 = bridge->pins->data[bridge->pins->size - 1];
if (p0->lid == Bp->lid || p1->lid == Bn->lid)
continue;
- scf_logi("i: %d, path->type: %d\n", i, path->type);
+ scf_logi("i: %d, bridge->type: %d\n", i, bridge->type);
+
+ ses_path_print(bridge);
+
+ route0->size = 0;
+ route1->size = 0;
+
+ int ret = ses_paths_find_route(route0, ctx->paths, p0, bridge);
+ if (ret < 0)
+ return ret;
- ses_path_print(path);
-#if 0
- int ret = __ses_path_va(f, path);
+ ret = ses_paths_find_route(route1, ctx->paths, p1, bridge);
if (ret < 0)
return ret;
-#endif
+
+ ses_route_print(route0);
+ printf("\n");
+
+ ses_route_print(route1);
+ printf("\n");
+
+ ret = __ses_path_va_balance(f, bridge, route0, route1);
+ if (ret < 0)
+ return ret;
+
printf("\n");
}
+ scf_vector_free(route0);
+ scf_vector_free(route1);
return 0;
}