}
}
-static int _topo_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx)
+static void _topo_clear(ScfEfunction* f)
{
- ses_path_t* path;
+ if (!f)
+ return;
+
ScfEcomponent* c;
- ScfEcomponent* B;
ScfEline* el;
ScfEpin* p;
p->dr = 0;
}
}
+}
- scf_vector_clear(ctx->paths, ( void (*)(void*) )ses_path_free);
+static int _topo_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];
- el = f->elines[B->pins[SCF_EDA_Battery_POS]->lid];
path = NULL;
for (i = 0; i + 1 < el->n_pins; i += 2) {
if (c == B)
continue;
- scf_logd("i: %ld\n", i);
-
- int ret = __dfs_path(f, c, p, ctx->paths, &path);
+ int ret = __dfs_path(f, c, p, paths, &path);
if (ret < 0)
return ret;
continue;
}
- if (scf_vector_add(ctx->paths, path) < 0) {
+ if (scf_vector_add(paths, path) < 0) {
ses_path_free(path);
return -ENOMEM;
}
path = NULL;
}
+ return 0;
+}
+
+int __ses_topo_paths(ScfEfunction* f, scf_vector_t* paths)
+{
+ if (!f || !paths)
+ return -EINVAL;
+
+ ses_path_t* path;
+ ScfEline* el;
+ ScfEpin* p;
+
+ size_t i;
+ size_t j;
+
+ _topo_clear(f);
+
+ scf_vector_clear(paths, ( void (*)(void*) )ses_path_free);
+
+ for (i = 0; i < f->n_elines; i++) {
+ el = f->elines[i];
+
+ if (!(el->flags & (SCF_EDA_PIN_POS | SCF_EDA_PIN_IN)))
+ continue;
+
+ int ret = _topo_paths(f, el, paths);
+ if (ret < 0)
+ return ret;
+ }
+
+ for (i = 0; i < paths->size; i++) {
+ path = paths->data[i];
+
+ scf_vector_clear(path->diodes, ( void (*)(void*) )free);
+
+ int ret = _topo_diodes(f, path);
+ if (ret < 0)
+ return ret;
+ }
+
+ int ret = _topo_layers(f, paths);
+ if (ret < 0)
+ return ret;
+
+ _topo_print(paths);
+ return 0;
+}
+
+static int _topo_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx)
+{
+ ses_path_t* path;
+ ScfEcomponent* B;
+ ScfEline* el;
+
+ size_t i;
+
+ _topo_clear(f);
+
+ scf_vector_clear(ctx->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, ctx->paths);
+ if (ret < 0)
+ return ret;
+
for (i = 0; i < ctx->paths->size; i++) {
path = ctx->paths->data[i];
scf_vector_clear(path->diodes, ( void (*)(void*) )free);
- int ret = _topo_diodes(f, path);
+ ret = _topo_diodes(f, path);
if (ret < 0)
return ret;
}
- int ret = _topo_layers(f, ctx->paths);
+ ret = _topo_layers(f, ctx->paths);
if (ret < 0)
return ret;