ses_ctx_t
authoryu.dongliang <18588496441@163.com>
Tue, 25 Jul 2023 11:59:53 +0000 (19:59 +0800)
committeryu.dongliang <18588496441@163.com>
Tue, 25 Jul 2023 11:59:53 +0000 (19:59 +0800)
ses_core.h
ses_step_battery.c
ses_step_dc_diode.c
ses_step_dc_input.c
ses_step_dc_transistor.c
ses_step_output.c
ses_step_simplify.c
ses_step_va.c
ses_step_va_balance.c
ses_steps.c

index 08364c4aa1558341fc86121edfba23681f424f79..7841e47c3e5da76d88d7b1f9f07071d629a6a2c3 100644 (file)
@@ -5,9 +5,8 @@
 #include"scf_vector.h"
 
 typedef struct ses_step_s    ses_step_t;
-typedef struct ses_loop_s    ses_loop_t;
 typedef struct ses_edge_s    ses_edge_t;
-typedef struct ses_pin_s     ses_pin_t;
+typedef struct ses_ctx_s     ses_ctx_t;
 
 struct ses_edge_s
 {
@@ -19,27 +18,25 @@ struct ses_edge_s
        ScfEpin*       p1;
 };
 
-struct ses_pin_s
+struct ses_ctx_s
 {
-       ScfEcomponent* c;
-       ScfEpin*       p;
-};
-
-struct ses_loop_s
-{
-       scf_vector_t*  pins;
+       scf_vector_t*  paths;
 };
 
 struct ses_step_s
 {
        const char*    name;
 
-       int          (*handler)(ScfEfunction* f, int64_t ns, int64_t count);
+       int          (*handler)(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx);
 
        void*          priv;
 };
 
 
+ses_ctx_t*  ses_ctx_alloc();
+void        ses_ctx_free (ses_ctx_t* ctx);
+
+
 int ses_layout_board (ScfEboard*    b);
 int ses_loop_function(ScfEfunction* f, scf_vector_t* loops);
 int ses_steps_analyse(ScfEfunction* f, int64_t ns, int64_t count);
index 11d5144bf564fb6a23a1c659ce267fe8b1798bf1..6f3c6178f2d59b132c834c91b26c68283d4a8ac1 100644 (file)
@@ -1,6 +1,6 @@
 #include"ses_core.h"
 
-static int _battery_handler(ScfEfunction* f, int64_t ns, int64_t count)
+static int _battery_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx)
 {
        ScfEcomponent*   c;
        ScfEline*        el;
index 4d4e2338f48aa970fdd23ee6381dd1151e137188..795826f90e154e31a9c64584cfd3bafe9a6036cb 100644 (file)
@@ -1,6 +1,6 @@
 #include"ses_core.h"
 
-static int _dc_diode_handler(ScfEfunction* f, int64_t ns, int64_t count)
+static int _dc_diode_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx)
 {
        ScfEcomponent*   c;
        ScfEcomponent*   B;
index 4e59bd1ac4dd9f3a4ccf480a9ed77cb0e36efc47..aad832ce02c141752bbf792e64de85e317362b93 100644 (file)
@@ -1,6 +1,6 @@
 #include"ses_core.h"
 
-static int _dc_input_handler(ScfEfunction* f, int64_t ns, int64_t count)
+static int _dc_input_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx)
 {
        ScfEcomponent*   B;
        ScfEline*        el;
index 8c88ec7481d3cfe72f1f44eec04ba8b00c041485..3dc6af26f7e2d25d62ebb9d67a15681be1106c8d 100644 (file)
@@ -1,6 +1,6 @@
 #include"ses_core.h"
 
-static int _dc_transistor_handler(ScfEfunction* f, int64_t ns, int64_t count)
+static int _dc_transistor_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx)
 {
        ScfEcomponent*   c;
        ScfEcomponent*   B;
index 9fea16727044668add1a07849027c798a99b23d3..4448353d28cda1f4d03b8b5b7ffc24df30fff0ef 100644 (file)
@@ -1,8 +1,13 @@
 #include"ses_core.h"
 
+static int _output_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx)
+{
+       return 0;
+}
 
 ses_step_t  ses_step_output =
 {
-       .name = "output",
+       .name    = "output",
 
+       .handler = _output_handler,
 };
index 598380d3828b1f342ae49f15af9ef5bebea0a163..9947b13109c852358e81185976cfc8a4660bbef9 100644 (file)
@@ -219,7 +219,7 @@ static int _simplify_draw(ScfEfunction* f, uint32_t bx, uint32_t by, uint32_t bw
        return 0;
 }
 
-static int _simplify_handler(ScfEfunction* f, int64_t ns, int64_t count)
+static int _simplify_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx)
 {
        ScfEcomponent*   c;
        ScfEcomponent*   B;
index cde11fde1d44c68abb92a79c8c380fc7e453404a..aa90f19c811628f53c4f841b45583f3e1972c297 100644 (file)
@@ -64,7 +64,7 @@ static int __dfs_route(ScfEfunction* f, ScfEcomponent* rc, ScfEpin* rp)
        return 0;
 }
 
-static int _va_handler(ScfEfunction* f, int64_t ns, int64_t count)
+static int _va_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx)
 {
        ScfEcomponent*   c;
        ScfEcomponent*   B;
index 47d64b9c538eeab617e906b9db9c4b60df5711ad..17b736e127799b3e6795933a2cdc85843e4e238e 100644 (file)
@@ -1,8 +1,13 @@
 #include"ses_core.h"
 
+static int _va_balance_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx)
+{
+       return 0;
+}
 
 ses_step_t  ses_step_va_balance =
 {
-       .name = "va_balance",
+       .name    = "va_balance",
 
+       .handler = _va_balance_handler,
 };
index 05ae5bcfb814cf6367876c39fe0e17ffeddea76a..7e19bb82c03a181bb758003ed46942bb2985f500 100644 (file)
@@ -33,6 +33,32 @@ static ses_step_t*  ses_steps[] =
        &ses_step_output,
 };
 
+ses_ctx_t* ses_ctx_alloc()
+{
+       ses_ctx_t* ctx = calloc(1, sizeof(ses_ctx_t));
+       if (!ctx)
+               return NULL;
+
+       ctx->paths = scf_vector_alloc();
+       if (!ctx->paths) {
+               free(ctx);
+               return NULL;
+       }
+
+       return ctx;
+}
+
+void ses_ctx_free(ses_ctx_t* ctx)
+{
+       if (ctx) {
+               if (ctx->paths) {
+                       scf_vector_clear(ctx->paths, ( void (*)(void*) )scf_vector_free);
+                       scf_vector_free (ctx->paths);
+               }
+
+               free(ctx);
+       }
+}
 
 int ses_steps_analyse(ScfEfunction* f, int64_t ns, int64_t count)
 {
@@ -40,6 +66,10 @@ int ses_steps_analyse(ScfEfunction* f, int64_t ns, int64_t count)
                return -EINVAL;
 
        ses_step_t* s;
+       ses_ctx_t*  ctx = ses_ctx_alloc();
+
+       if (!ctx)
+               return -ENOMEM;
 
        int64_t i;
        int64_t j;
@@ -52,13 +82,16 @@ int ses_steps_analyse(ScfEfunction* f, int64_t ns, int64_t count)
                        if (!s || !s->handler)
                                continue;
 
-                       int ret = s->handler(f, ns, i);
+                       int ret = s->handler(f, ns, i, ctx);
                        if (ret < 0) {
                                scf_loge("analysis step '%s' ret: %d\n", s->name, ret);
+
+                               ses_ctx_free(ctx);
                                return ret;
                        }
                }
        }
 
+       ses_ctx_free(ctx);
        return 0;
 }