From 80272aa382b49a134c749cc8d583bf7ca1ce133d Mon Sep 17 00:00:00 2001 From: "yu.dongliang" <18588496441@163.com> Date: Sun, 9 Jul 2023 23:11:16 +0800 Subject: [PATCH] ses layout --- main.c | 4 +-- ses_layout.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 84 insertions(+), 5 deletions(-) diff --git a/main.c b/main.c index 6baa21c..d255c46 100644 --- a/main.c +++ b/main.c @@ -46,7 +46,7 @@ int main(int argc, char* argv[]) ScfEboard* b = scf_eboard__unpack(NULL, len, pb); - ses_layout_board(b, 0, 0, 100, 100); + ses_layout_board(b, 0, 0, 30, 160); #if 0 size_t i; size_t j; @@ -73,6 +73,6 @@ int main(int argc, char* argv[]) } #endif - scf_eboard__free_unpacked(b, NULL); +// scf_eboard__free_unpacked(b, NULL); return 0; } diff --git a/ses_layout.c b/ses_layout.c index 0cbdc45..1573ede 100644 --- a/ses_layout.c +++ b/ses_layout.c @@ -20,6 +20,20 @@ int epin_cmp(const void* v0, const void* v1) return 0; } +int econn_cmp(const void* v0, const void* v1) +{ + const ScfEconn* ec0 = *(const ScfEconn**)v0; + const ScfEconn* ec1 = *(const ScfEconn**)v1; + + if (ec0->n_cids < ec1->n_cids) + return 1; + + if (ec0->n_cids > ec1->n_cids) + return -1; + + return 0; +} + int eline_cmp(const void* v0, const void* v1) { const ScfEline* el0 = *(const ScfEline**)v0; @@ -188,6 +202,8 @@ int ses_lines_same_components(ScfEfunction* f) ec = NULL; } + + qsort(el0->conns, el0->n_conns, sizeof(ScfEconn*), econn_cmp); } if (ec) { @@ -219,14 +235,75 @@ int ses_lines_same_components(ScfEfunction* f) int ses_layout_function(ScfEfunction* f, uint32_t d, uint32_t bx, uint32_t by, uint32_t bw, uint32_t bh) { ScfEline* el; + ScfEline* el2; ScfEconn* ec; + ScfLine* l; - size_t i; - size_t j; + uint32_t w; + uint32_t h; + size_t i; + size_t j; + size_t k; + size_t m; + size_t n; + + f->x = bx; + f->y = by; + n = 0; + + for (i = 0; i < f->n_elines; i++) { + el = f->elines[i]; + + w = el->n_pins * d; + + if (w <= bw) + n++; + else + n += (w + bw - 1) / bw; + } + + f->h = n * d; + + if (f->h > bh) { + scf_loge("board's height too small, f->n_elines: %ld, n: %ld, f->h: %d, bh: %d\n", f->n_elines, n, f->h, bh); + return -EINVAL; + } + + n = (n + 1) >> 1; + m = 0; for (i = 0; i < f->n_elines; i++) { el = f->elines[i]; + w = el->n_pins * d; + k = (w + bw - 1) / bw; + m += k; + + if (m < n) + h = (n - m % n) * d; + else + h = (n + m % n) * d; + + for (j = 0; j < k; j++) { + + l = malloc(sizeof(ScfLine)); + if (!l) + return -ENOMEM; + + l->x0 = bx; + l->y0 = by + h - j * d; + l->x1 = l->x0 + w; + l->y1 = l->y0; + + scf_logi("el i: %ld, j: %ld, h: %d y0: %d, w: %d, bw: %d\n", i, j, h, l->y0, w, bw); + + if (scf_eline__add_line(el, l) < 0) { + free(l); + return -ENOMEM; + } + } + + printf("\n"); } return 0; @@ -276,9 +353,11 @@ int ses_layout_board(ScfEboard* b, uint32_t x, uint32_t y, uint32_t w, uint32_t ses_pins_same_line(f); ses_lines_same_components(f); + + ses_layout_function(f, 5, x + 20, y + 20, w - 20, h - 20); } - ses_layout_draw(); +// ses_layout_draw(); return 0; } -- 2.25.1