1, fix: find 'topo path' error when include capacitor in circuit,
authoryu.dongliang <18588496441@163.com>
Mon, 22 Apr 2024 07:46:19 +0000 (15:46 +0800)
committeryu.dongliang <18588496441@163.com>
Mon, 22 Apr 2024 07:46:23 +0000 (15:46 +0800)
2, make the layout show more clearly.

ses_core.h
ses_layout.c
ses_step_simplify.c
ses_step_topo.c
ses_step_va_capacitor.c
ses_utils.c
test/main.c

index e490b4b8e3f5019bc54e487ea64325817c13faf5..b19f64b90d8ee7c2d838c65994fc60340133359d 100644 (file)
@@ -101,7 +101,8 @@ struct ses_step_s
 ses_path_t* ses_path_alloc();
 void        ses_path_free (ses_path_t* path);
 void        ses_path_print(ses_path_t* path);
-int         ses_path_add  (ses_path_t* path, ses_path_t* child);
+int         ses_path_add  (ses_path_t* path, ses_path_t* child, ScfEfunction* f);
+int         ses_path_xchg (ses_path_t* path0, int k0, ses_path_t* path1, int k1);
 
 ses_path_t* ses_path_save (ses_path_t* src);
 int         ses_path_load (ses_path_t* dst, ses_path_t* src);
index e3437d17cffe8f79e240c8120c9270bfed15c561..e1d3504c2c7c57d2e4210a473d3a93f49f24690c 100644 (file)
@@ -1657,7 +1657,7 @@ int ses_layout_function(ScfEfunction* f, int d)
 //             printf("\n");
        }
 
-       f->w  = tx1 + d;
+       f->w  = tx1 + d * 3;
        f->h += d;
 
        scf_loge("f->x: %d, y: %d, w: %d, h: %d, tx0: %d, tx1: %d\n", f->x, f->y, f->w, f->h, tx0, tx1);
@@ -1793,7 +1793,7 @@ int ses_layout_board(ScfEboard* b)
 
                ses_lines_same_components(f);
 
-               int ret = ses_layout_function(f, 50);
+               int ret = ses_layout_function(f, 60);
                if (ret < 0) {
                        scf_loge("\n");
                        return ret;
index 92448bf0366cdc1380c11d20fbf4365639a4476f..b4df409b11763a358f3002e742513d81a3a4ca7b 100644 (file)
@@ -18,35 +18,15 @@ void __ses_function_draw(ScfEfunction* f, cairo_t* cr)
                cairo_set_line_width(cr, 2.5);
 
                uint8_t text[64];
-               snprintf(text, sizeof(text) - 1, "%ld", c->id);
+               int n = snprintf(text, sizeof(text) - 1, "%ld", c->id);
 
                cairo_set_source_rgb  (cr, 0, 0, 0);
-               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, 20);
-               cairo_move_to         (cr, c->x + 10, c->y - 5);
+               cairo_move_to         (cr, c->x - 10 - n * 10, c->y - 5);
                cairo_show_text       (cr, text);
                cairo_stroke(cr);
 
-               if (SCF_EDA_Capacitor == c->type) {
-
-                       if (c->v > 0)
-                               cairo_set_source_rgb(cr, 0.7, 0.0, 0.0);
-                       else
-                               cairo_set_source_rgb(cr, 0.0, 0.0, 0.7);
-
-                       if (c->v > 1e-3 || c->v < -1e-3)
-                               snprintf(text, sizeof(text) - 1, "%lgv", (int)(c->v * 1000) / 1000.0);
-
-                       else if (c->v > 1e-6 || c->v < -1e-6)
-                               snprintf(text, sizeof(text) - 1, "%lgmV", (int)(c->v * 1000000) / 1000.0);
-                       else
-                               snprintf(text, sizeof(text) - 1, "%lguV", (int)(c->v * 1000000) / 1000000.0);
-
-                       cairo_move_to  (cr, c->x + 10, c->y + 10);
-                       cairo_show_text(cr, text);
-                       cairo_stroke(cr);
-               }
-
                if ((SCF_EDA_Diode == c->type || SCF_EDA_NPN == c->type) && SCF_EDA_Status_OFF == c->status)
                        cairo_set_source_rgb(cr, 0.0, 0.6, 0.6);
                else
@@ -151,6 +131,33 @@ void __ses_function_draw(ScfEfunction* f, cairo_t* cr)
                                }
                                cairo_line_to(cr, p->x, p->y);
                                cairo_stroke(cr);
+
+                               if (c->v > 0)
+                                       cairo_set_source_rgb(cr, 0.7, 0.0, 0.0);
+                               else
+                                       cairo_set_source_rgb(cr, 0.0, 0.0, 0.7);
+                               cairo_select_font_face(cr, "Georgia", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
+
+                               if (c->v > 1e-3 || c->v < -1e-3) {
+                                       snprintf(text, sizeof(text) - 1, "%lgv", (int)(c->v * 1000) / 1000.0);
+
+                                       cairo_move_to  (cr, c->x + 10, c->y + 10);
+                                       cairo_show_text(cr, text);
+
+                               } else if (c->v > 1e-6 || c->v < -1e-6) {
+                                       snprintf(text, sizeof(text) - 1, "%lgmV", (int)(c->v * 1000000) / 1000.0);
+
+                                       cairo_move_to  (cr, c->x + 10, c->y + 10);
+                                       cairo_show_text(cr, text);
+                               }
+
+                               cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
+
+                               snprintf(text, sizeof(text) - 1, "%lguf", c->uf);
+
+                               cairo_move_to  (cr, c->x + 4, c->y - 5);
+                               cairo_show_text(cr, text);
+                               cairo_stroke(cr);
                                break;
 
                        case SCF_EDA_Resistor:
@@ -171,7 +178,18 @@ void __ses_function_draw(ScfEfunction* f, cairo_t* cr)
                                p = c->pins[1];
                                cairo_move_to    (cr,  p->x,       p->y);
                                cairo_line_to    (cr,  c->x + dx1, c->y + dy1);
+                               cairo_stroke(cr);
+
+                               if (c->r > 1e6)
+                                       snprintf(text, sizeof(text) - 1, "%dM", (int)(c->r / 1000000.0));
+                               else
+                                       snprintf(text, sizeof(text) - 1, "%dk", (int)(c->r / 1000.0));
+
+                               cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
+                               cairo_select_font_face(cr, "Georgia", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
 
+                               cairo_move_to  (cr, c->x + 4, c->y - 5);
+                               cairo_show_text(cr, text);
                                cairo_stroke(cr);
                                break;
 
@@ -312,11 +330,9 @@ static int _simplify_draw(ScfEfunction* f, uint32_t bx, uint32_t by, uint32_t bw
                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_set_font_size   (cr, 28);
 
+               uint8_t  text[64];
                ScfLine* prev = NULL;
 
                for (k = 0; k < el->n_lines; k++) {
@@ -326,16 +342,17 @@ static int _simplify_draw(ScfEfunction* f, uint32_t bx, uint32_t by, uint32_t bw
                                continue;
 
                        if (!prev) {
-                               snprintf(text, sizeof(text) - 1, "%ld", el->id);
+                               cairo_set_font_size(cr, 28);
+                               int n = snprintf(text, sizeof(text) - 1, "%ld", el->id);
 
-                               cairo_move_to  (cr, l->x0 - 30, l->y0 + 5);
+                               cairo_move_to  (cr, l->x0 - 10 - n * 12, l->y0 + 10);
                                cairo_show_text(cr, text);
                                cairo_stroke(cr);
 
                                if (el->v < SCF_EDA_V_MIN)
-                                       snprintf(text, sizeof(text) - 1, "%lg", B->pins[SCF_EDA_Battery_NEG]->v);
+                                       snprintf(text, sizeof(text) - 1, "%lgv", B->pins[SCF_EDA_Battery_NEG]->v);
                                else if (el->v > SCF_EDA_V_MAX)
-                                       snprintf(text, sizeof(text) - 1, "%lg", B->pins[SCF_EDA_Battery_POS]->v);
+                                       snprintf(text, sizeof(text) - 1, "%lgv", B->pins[SCF_EDA_Battery_POS]->v);
 
                                else if (el->v > 1e-3 || el->v < -1e-3)
                                        snprintf(text, sizeof(text) - 1, "%lgv", (int)(el->v * 1000) / 1000.0);
@@ -345,8 +362,6 @@ static int _simplify_draw(ScfEfunction* f, uint32_t bx, uint32_t by, uint32_t bw
                                else
                                        snprintf(text, sizeof(text) - 1, "%lguV", (int)(el->v * 1000000) / 1000000.0);
 
-                               cairo_set_font_size(cr, 20);
-
                                int cx = INT_MAX;
                                int cy = l->y0;
 
@@ -359,13 +374,17 @@ static int _simplify_draw(ScfEfunction* f, uint32_t bx, uint32_t by, uint32_t bw
                                        }
                                }
 
-                               if (cy > l->y0)
-                                       cairo_move_to(cr, l->x0 + 12, l->y0 - 8);
-                               else
-                                       cairo_move_to(cr, l->x0 + 12, l->y0 + 24);
+                               cairo_set_font_size(cr, 20);
 
-                               cairo_show_text(cr, text);
-                               cairo_stroke(cr);
+                               if (cy > l->y0) {
+                                       cairo_move_to  (cr, cx - 20, l->y0 - 8);
+                                       cairo_show_text(cr, text);
+                                       cairo_stroke(cr);
+                               } else {
+                                       cairo_move_to  (cr, cx - 20, l->y0 + 24);
+                                       cairo_show_text(cr, text);
+                                       cairo_stroke(cr);
+                               }
                        }
 
                        cairo_set_line_width(cr, 4);
index 18dd489f4a6a58acdcc5250d59904c33f1c5241d..77ae8b428f2018586d7dc1b0d2b46b5f2bcc74ed 100644 (file)
@@ -80,7 +80,9 @@ int __dfs_path(ScfEfunction* f, ScfEcomponent* rc, ScfEpin* rp, scf_vector_t* __
                        }
 
                        *ppath = NULL;
-                       return 0;
+
+                       if (SCF_EDA_PIN_NEG & el->flags)
+                               return 0;
                }
 
                ret = 0;
@@ -91,7 +93,6 @@ int __dfs_path(ScfEfunction* f, ScfEcomponent* rc, ScfEpin* rp, scf_vector_t* __
                        p  = c->pins      [el->pins[j + 1]];
 
                        if (p->pflag) {
-
                                if (p != np && *ppath) {
                                        scf_logd("branch: c%ld_p%ld, l%ld\n", c->id, p->id, el->id);
 
@@ -297,47 +298,6 @@ static int _topo_path_bridges(ScfEfunction* f, ses_path_t* path)
        return __topo_path_bridges(f, path);
 }
 
-static int __topo_path_xchg(ses_path_t* path0, int k0, ses_path_t* path1, int k1)
-{
-       ScfEpin* p;
-
-       int i;
-
-       scf_logd("path0: %d, k0: %d ... path1: %d, k1: %d\n", path0->pins->size, k0, path1->pins->size, k1);
-
-       for (i = 0; i + k0 < path0->pins->size && i + k1 < path1->pins->size; i++)
-               SCF_XCHG(path0->pins->data[i + k0], path1->pins->data[i + k1]);
-
-       scf_logd("path0: %d, k0: %d ... path1: %d, k1: %d, i: %d\n", path0->pins->size, k0, path1->pins->size, k1, i);
-
-       if (i + k0 < path0->pins->size) {
-
-               while (i + k0 < path0->pins->size) {
-                       p         = path0->pins->data[i + k0];
-
-                       if (scf_vector_del(path0->pins, p) < 0)
-                               return -1;
-
-                       if (scf_vector_add(path1->pins, p) < 0)
-                               return -ENOMEM;
-               }
-
-       } else if (i + k1 < path1->pins->size) {
-
-               while (i + k1 < path1->pins->size) {
-                       p         = path1->pins->data[i + k1];
-
-                       if (scf_vector_del(path1->pins, p) < 0)
-                               return -1;
-
-                       if (scf_vector_add(path0->pins, p) < 0)
-                               return -ENOMEM;
-               }
-       }
-
-       return 0;
-}
-
 static int _topo_path_connect(ScfEfunction* f, scf_vector_t* paths)
 {
        if (!f || !paths)
@@ -491,7 +451,7 @@ static int _topo_path_completes(ScfEfunction* f, scf_vector_t* paths)
                                                p2->cid, p2->id, p->cid,  p->id,  path1->pins->size,
                                                p0->cid, p0->id, p1->cid, p1->id, path0->pins->size);
 
-                               int ret = __topo_path_xchg(path0, 0, path1, k + 1);
+                               int ret = ses_path_xchg(path0, 0, path1, k + 1);
                                if (ret < 0)
                                        return ret;
 
@@ -517,7 +477,7 @@ static int _topo_path_completes(ScfEfunction* f, scf_vector_t* paths)
                                                p2->cid, p2->id, p3->cid, p3->id, path1->pins->size,
                                                p ->cid, p ->id, p1->cid, p1->id, path0->pins->size);
 
-                               int ret = __topo_path_xchg(path0, k, path1, path1->pins->size);
+                               int ret = ses_path_xchg(path0, k, path1, path1->pins->size);
                                if (ret < 0)
                                        return ret;
 
@@ -749,7 +709,7 @@ branch:
                if (scf_vector_del(paths, child) < 0)
                        return -1;
 
-               if (ses_path_add(parent, child) < 0) {
+               if (ses_path_add(parent, child, f) < 0) {
                        ses_path_free(child);
                        return -ENOMEM;
                }
@@ -936,95 +896,97 @@ static int _topo_paths(ScfEfunction* f, ScfEline* el, scf_vector_t* paths)
        return 0;
 }
 
-int __ses_topo_paths(ScfEfunction* f, scf_vector_t*  paths)
+static int __ses_topo_layers(ScfEfunction* f, scf_vector_t* paths)
 {
-       if (!f || !paths)
-               return -EINVAL;
+       ses_path_t* path;
 
-       ses_path_t*      path;
-       ScfEline*        el;
-       ScfEpin*         p;
+       int size;
+       int i;
 
-       size_t i;
+       do {
+               do {
+                       size = paths->size;
 
-       _topo_clear(f);
+                       for (i = 0; i < paths->size; i++) {
+                               path      = paths->data[i];
 
-       scf_vector_clear(paths, ( void (*)(void*) )ses_path_free);
+                               _topo_key_components(f, path);
+                       }
 
-       for (i = 0; i < f->n_elines; i++) {
-               el =        f->elines[i];
+                       int ret = _topo_layers(f, paths);
+                       if (ret < 0)
+                               return ret;
 
-               if (!(el->flags & (SCF_EDA_PIN_POS | SCF_EDA_PIN_IN)))
-                       continue;
+                       ret = _topo_path_completes(f, paths);
+                       if (ret < 0)
+                               return ret;
+               } while (size > paths->size);
 
-               int ret = _topo_paths(f, el, paths);
+               int ret = _topo_path_connect(f, paths);
                if (ret < 0)
                        return ret;
-       }
+       } while (size > paths->size);
 
-       for (i = 0; i < paths->size; i++) {
-               path      = paths->data[i];
-
-               scf_vector_clear(path->infos, ( void (*)(void*) )free);
-
-               _topo_key_components(f, path);
-       }
-
-       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)
+int __ses_topo_paths(ScfEfunction* f, scf_vector_t*  paths)
 {
+       if (!f || !paths)
+               return -EINVAL;
+
        ses_path_t*      path;
        ScfEcomponent*   B;
        ScfEline*        el;
 
        _topo_clear(f);
 
-       scf_vector_clear(ctx->paths, ( void (*)(void*) )ses_path_free);
+       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, ctx->paths);
+       int ret = _topo_paths(f, el, paths);
        if (ret < 0)
                return ret;
 
-       int size;
        int i;
+       for (i = 0; i < f->n_elines; i++) {
+               el =        f->elines[i];
 
-       do {
-               do {
-                       size = ctx->paths->size;
+               if (el->flags & SCF_EDA_PIN_IN) {
+
+                       ret = _topo_paths(f, el, paths);
+                       if (ret < 0)
+                               return ret;
+               }
+       }
 
-                       for (i = 0; i < ctx->paths->size; i++) {
-                               path      = ctx->paths->data[i];
+       return __ses_topo_layers(f, paths);
+}
 
-                               _topo_key_components(f, path);
-                       }
+static int _topo_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx)
+{
+       ses_path_t*      path;
+       ScfEcomponent*   B;
+       ScfEline*        el;
 
-                       scf_logd("size: %d, paths->size: %d\n", size, ctx->paths->size);
+       _topo_clear(f);
 
-                       ret = _topo_layers(f, ctx->paths);
-                       if (ret < 0)
-                               return ret;
+       scf_vector_clear(ctx->paths, ( void (*)(void*) )ses_path_free);
 
-                       ret = _topo_path_completes(f, ctx->paths);
-                       if (ret < 0)
-                               return ret;
-               } while (size > ctx->paths->size);
+       B  = f->components[0];
+       el = f->elines[B->pins[SCF_EDA_Battery_POS]->lid];
 
-               ret = _topo_path_connect(f, ctx->paths);
-               if (ret < 0)
-                       return ret;
-       } while (size > ctx->paths->size);
+       int ret = _topo_paths(f, el, ctx->paths);
+       if (ret < 0)
+               return ret;
 
+       ret = __ses_topo_layers(f, ctx->paths);
+       if (ret < 0)
+               return ret;
 
+       int i;
        for (i = 0; i < ctx->paths->size; i++) {
                path      = ctx->paths->data[i];
 
index 48e8fb8bbdbb0c0d9dc3c03d44e265fb083c82ea..6998d6742027df9232e107b0a899ecc6ac3c1631 100644 (file)
@@ -55,11 +55,10 @@ static int __ses_path_va_capacitor(ScfEfunction* f, scf_vector_t* paths, ses_pat
        p0 = bridge->pins->data[0];
        p1 = bridge->pins->data[bridge->pins->size - 1];
 
-       el    = f->elines[p0->lid];
-       p0->v = el->v;
+       if (p0->lid == Bp->lid && p1->lid == Bn->lid)
+               return 0;
 
-       el    = f->elines[p1->lid];
-       p1->v = el->v;
+       __ses_path_jr(f, bridge);
 
        flow0 = ses_flow_alloc();
        if (!flow0)
@@ -97,6 +96,12 @@ static int __ses_path_va_capacitor(ScfEfunction* f, scf_vector_t* paths, ses_pat
        double cv;
        double ja;
 
+       el    = f->elines[p0->lid];
+       p0->v = el->v;
+
+       el    = f->elines[p1->lid];
+       p1->v = el->v;
+
        cv = __ses_path_v_capacitor(f, bridge);
 
        scf_logw("c%ldp%ld-c%ldp%ld, cv: %lg, p0->v: %lg, p1->v: %lg\n", p0->cid, p0->id, p1->cid, p1->id, cv, p0->v, p1->v);
@@ -154,8 +159,6 @@ static int ses_path_va_capacitor(ScfEfunction* f, scf_vector_t* paths, ses_path_
 
        if (bridge->n_capacitors > 0) {
 
-               __ses_path_jr(f, bridge);
-
                ret = __ses_path_va_capacitor(f, paths, bridge, changed, ns, count);
                if (ret < 0)
                        return ret;
index 18df7e463425fd79293aee83ca0ba73d93405325..c993ab6b0c63c58083889a3a07b792f9aa135f67 100644 (file)
@@ -451,7 +451,44 @@ void ses_path_print(ses_path_t* path)
        }
 }
 
-int ses_path_add(ses_path_t* parent, ses_path_t* child)
+int ses_path_xchg(ses_path_t* path0, int k0, ses_path_t* path1, int k1)
+{
+       ScfEpin* p;
+
+       int i;
+
+       for (i = 0; i + k0 < path0->pins->size && i + k1 < path1->pins->size; i++)
+               SCF_XCHG(path0->pins->data[i + k0], path1->pins->data[i + k1]);
+
+       scf_logd("path0: %d, k0: %d ... path1: %d, k1: %d, i: %d\n", path0->pins->size, k0, path1->pins->size, k1, i);
+
+       if (i + k0 < path0->pins->size) {
+
+               while (i + k0 < path0->pins->size) {
+                       p         = path0->pins->data[i + k0];
+
+                       assert(0 == scf_vector_del(path0->pins, p));
+
+                       if (scf_vector_add(path1->pins, p) < 0)
+                               return -ENOMEM;
+               }
+
+       } else if (i + k1 < path1->pins->size) {
+
+               while (i + k1 < path1->pins->size) {
+                       p         = path1->pins->data[i + k1];
+
+                       assert(0 == scf_vector_del(path1->pins, p));
+
+                       if (scf_vector_add(path0->pins, p) < 0)
+                               return -ENOMEM;
+               }
+       }
+
+       return 0;
+}
+
+int ses_path_add(ses_path_t* parent, ses_path_t* child, ScfEfunction* f)
 {
        if (!parent || !child)
                return -EINVAL;
@@ -487,9 +524,9 @@ int ses_path_add(ses_path_t* parent, ses_path_t* child)
                                child->parent_p1        = path->parent_p1;
                                child->type             = SES_PATH_BRANCH;
 
-                               return ses_path_add(child, path);
+                               return ses_path_add(child, path, f);
                        } else
-                               return ses_path_add(path, child);
+                               return ses_path_add(path, child, f);
                }
        }
 
@@ -499,15 +536,54 @@ int ses_path_add(ses_path_t* parent, ses_path_t* child)
        for (j = 0; j < parent->pins->size; j++) {
                p0 =        parent->pins->data[j];
 
-               if (p0->lid == cp0->lid)
-                       child->parent_p0 = j;
+               if (p0->lid == cp0->lid) {
+                       child->parent_p0 = (j + 1) & ~0x1;
+                       break;
+               }
+       }
+       assert(j < parent->pins->size);
+
+       int n_capacitors = 0;
+
+       for ( ; j < parent->pins->size; j++) {
+               p0    = parent->pins->data[j];
+
+               if (!(j & 0x1)) {
+                       ScfEcomponent* c = f->components[p0->cid];
+
+                       if (SCF_EDA_Capacitor == c->type)
+                               n_capacitors++;
+               }
 
                if (p0->lid == cp1->lid) {
                        child->parent_p1 = j;
                        break;
                }
        }
-       assert(child->parent_p0 >= 0 && child->parent_p1 >= 0);
+       assert(j < parent->pins->size);
+
+       if (n_capacitors > 0 && 0 == child->n_capacitors) {
+
+               int ret = ses_path_xchg(parent, child->parent_p0, child, 0);
+               if (ret < 0)
+                       return ret;
+
+               j                = child->parent_p1 - child->parent_p0 + 1;
+               child->parent_p1 = parent->pins->size - 1;
+
+               while (j < child->pins->size) {
+                       p0   = child->pins->data[j];
+
+                       assert(0 == scf_vector_del(child->pins, p0));
+
+                       ret = scf_vector_add(parent->pins, p0);
+                       if (ret < 0)
+                               return ret;
+               }
+
+               child ->n_capacitors  = n_capacitors;
+               parent->n_capacitors -= n_capacitors;
+       }
 
        child->parent = parent;
        child->type   = SES_PATH_BRANCH;
@@ -595,4 +671,3 @@ void ses_ctx_free(ses_ctx_t* ctx)
                free(ctx);
        }
 }
-
index 2b2cff3bd163dbd9a2db22a712dd86191a3a89f1..5361aeffdd915195e73158e068af85dfae2aee6a 100644 (file)
@@ -6,19 +6,26 @@
 int main(int argc, char* argv[])
 {
        ScfEcomponent* B;
+
        ScfEcomponent* R0;
+       ScfEcomponent* C0;
+       ScfEcomponent* T0;
+
        ScfEcomponent* R1;
        ScfEcomponent* R2;
        ScfEcomponent* R3;
-       ScfEcomponent* T0;
-       ScfEcomponent* T1;
-       ScfEcomponent* C0;
        ScfEcomponent* C1;
+       ScfEcomponent* C2;
+       ScfEcomponent* C3;
+
+       ScfEcomponent* R4;
+       ScfEcomponent* R5;
+
        ScfEfunction*  f;
        ScfEboard*     b;
 
        b = scf_eboard__alloc();
-       f = scf_efunction__alloc("oscillator");
+       f = scf_efunction__alloc("sin_oscillator");
 
        EDA_INST_ADD_COMPONENT(f, B,  SCF_EDA_Battery);
 
@@ -26,39 +33,54 @@ int main(int argc, char* argv[])
        B->pins[SCF_EDA_Battery_POS]->flags = SCF_EDA_PIN_POS;
 
        EDA_INST_ADD_COMPONENT(f, R0, SCF_EDA_Resistor);
+       EDA_INST_ADD_COMPONENT(f, C0, SCF_EDA_Capacitor);
+       EDA_INST_ADD_COMPONENT(f, T0, SCF_EDA_NPN);
+
        EDA_INST_ADD_COMPONENT(f, R1, SCF_EDA_Resistor);
        EDA_INST_ADD_COMPONENT(f, R2, SCF_EDA_Resistor);
        EDA_INST_ADD_COMPONENT(f, R3, SCF_EDA_Resistor);
-       EDA_INST_ADD_COMPONENT(f, T0, SCF_EDA_NPN);
-       EDA_INST_ADD_COMPONENT(f, T1, SCF_EDA_NPN);
-       EDA_INST_ADD_COMPONENT(f, C0, SCF_EDA_Capacitor);
        EDA_INST_ADD_COMPONENT(f, C1, SCF_EDA_Capacitor);
+       EDA_INST_ADD_COMPONENT(f, C2, SCF_EDA_Capacitor);
+       EDA_INST_ADD_COMPONENT(f, C3, SCF_EDA_Capacitor);
+
+       EDA_INST_ADD_COMPONENT(f, R4, SCF_EDA_Resistor);
+       EDA_INST_ADD_COMPONENT(f, R5, SCF_EDA_Resistor);
+
+       EDA_PIN_ADD_PIN(B,  SCF_EDA_Battery_POS,  R4, 1);
+       EDA_PIN_ADD_PIN(B,  SCF_EDA_Battery_POS,  R5, 1);
 
-       EDA_PIN_ADD_PIN(B,  SCF_EDA_Battery_POS,  R0, 1);
-       EDA_PIN_ADD_PIN(B,  SCF_EDA_Battery_POS,  R1, 1);
-       EDA_PIN_ADD_PIN(B,  SCF_EDA_Battery_POS,  R2, 1);
-       EDA_PIN_ADD_PIN(B,  SCF_EDA_Battery_POS,  R3, 1);
+       EDA_PIN_ADD_PIN(R5, 0,                    T0, SCF_EDA_NPN_C);
+       EDA_PIN_ADD_PIN(T0, SCF_EDA_NPN_E,        R0, 1);
+       EDA_PIN_ADD_PIN(R0, 1,                    C0, 1);
+       EDA_PIN_ADD_PIN(R0, 0,                    C0, 0);
+       EDA_PIN_ADD_PIN(R0, 0,                    B,  SCF_EDA_Battery_NEG);
 
-       EDA_PIN_ADD_PIN(R0, 0,                    T0, SCF_EDA_NPN_C);
-       EDA_PIN_ADD_PIN(T0, SCF_EDA_NPN_E,        B,  SCF_EDA_Battery_NEG);
-       EDA_PIN_ADD_PIN(R0, 0,                    C0, 1);
-       EDA_PIN_ADD_PIN(R1, 0,                    C0, 0);
+       EDA_PIN_ADD_PIN(R4, 0,                    R3, 1);
+       EDA_PIN_ADD_PIN(R3, 1,                    T0, SCF_EDA_NPN_B);
+       EDA_PIN_ADD_PIN(R3, 0,                    B,  SCF_EDA_Battery_NEG);
 
-       EDA_PIN_ADD_PIN(R3, 0,                    T1, SCF_EDA_NPN_C);
-       EDA_PIN_ADD_PIN(T1, SCF_EDA_NPN_E,        B,  SCF_EDA_Battery_NEG);
-       EDA_PIN_ADD_PIN(R3, 0,                    C1, 1);
-       EDA_PIN_ADD_PIN(R2, 0,                    C1, 0);
+       EDA_PIN_ADD_PIN(C1, 1,                    T0, SCF_EDA_NPN_C);
+       EDA_PIN_ADD_PIN(C1, 0,                    C2, 1);
+       EDA_PIN_ADD_PIN(C2, 0,                    C3, 1);
+       EDA_PIN_ADD_PIN(C3, 0,                    T0, SCF_EDA_NPN_B);
 
-       EDA_PIN_ADD_PIN(C0, 0,                    T1, SCF_EDA_NPN_B);
-       EDA_PIN_ADD_PIN(C1, 0,                    T0, SCF_EDA_NPN_B);
+       EDA_PIN_ADD_PIN(C1, 0,                    R1, 1);
+       EDA_PIN_ADD_PIN(C2, 0,                    R2, 1);
+       EDA_PIN_ADD_PIN(R1, 0,                    B,  SCF_EDA_Battery_NEG);
+       EDA_PIN_ADD_PIN(R2, 0,                    B,  SCF_EDA_Battery_NEG);
 
        T0->pins[SCF_EDA_NPN_C]->flags |= SCF_EDA_PIN_OUT;
-       T1->pins[SCF_EDA_NPN_C]->flags |= SCF_EDA_PIN_OUT;
 
+       R4->r  = 1000 * 47;
+       R5->r  = 1000 * 27;
+       R3->r  = 1000 * 10;
+       R2->r  = 1000 * 10;
+       R1->r  = 1000 * 10;
        R0->r  = 1000;
-       R3->r  = 1000;
-       C0->uf = 0.001;
-       C1->uf = 0.001;
+       C0->uf = 10;
+       C1->uf = 0.01;
+       C2->uf = 0.01;
+       C3->uf = 0.01;
 
        scf_eboard__add_function(b, f);
 
@@ -69,7 +91,7 @@ int main(int argc, char* argv[])
        ScfEboard_free(b);
        b = NULL;
 
-       FILE* fp = fopen("./oscillator.pack", "wb");
+       FILE* fp = fopen("./sin_oscillator.pack", "wb");
        if (!fp)
                return -EINVAL;