From 2b80d283f4d22cbd77f9f231a2003722116a36a5 Mon Sep 17 00:00:00 2001 From: Wolfgang Spraul Date: Fri, 24 Aug 2012 08:12:13 +0200 Subject: [PATCH] enabling a few switches --- autotest.c | 29 ++++++++++++++++++++------ control.c | 60 +++++++++++++++++++++++++++++------------------------ control.h | 21 ++++++++++--------- floorplan.c | 9 +++++--- 4 files changed, 73 insertions(+), 46 deletions(-) diff --git a/autotest.c b/autotest.c index b8d5b23..6d2d429 100644 --- a/autotest.c +++ b/autotest.c @@ -167,7 +167,7 @@ int main(int argc, char** argv) rc = diff_printf(&tstate); if (rc) FAIL(rc); - printf("P46 I pinw %s\n", strarray_lookup(&model.str, P46_dev->iob.pinw_out_I)); +printf("P46 I pinw %s\n", strarray_lookup(&model.str, P46_dev->iob.pinw_out_I)); switch_to.yx_req = YX_DEV_ILOGIC; switch_to.flags = SWTO_YX_DEF; @@ -177,7 +177,10 @@ int main(int argc, char** argv) switch_to.start_switch = P46_dev->iob.pinw_out_I; rc = fpga_switch_to_yx(&switch_to); if (rc) FAIL(rc); - printf(" %s\n", fmt_swchain(&model, switch_to.y, switch_to.x, switch_to.chain, switch_to.chain_size, SW_FROM)); + rc = fpga_switch_set_enable(&model, switch_to.y, switch_to.x, &switch_to.set); + if (rc) FAIL(rc); + +printf(" %s\n", fmt_swset(&model, switch_to.y, switch_to.x, &switch_to.set, SW_FROM)); switch_to.yx_req = YX_ROUTING_TILE; switch_to.flags = SWTO_YX_DEF; @@ -186,7 +189,10 @@ int main(int argc, char** argv) switch_to.start_switch = switch_to.dest_connpt; rc = fpga_switch_to_yx(&switch_to); if (rc) FAIL(rc); - printf(" %s\n", fmt_swchain(&model, switch_to.y, switch_to.x, switch_to.chain, switch_to.chain_size, SW_FROM)); + rc = fpga_switch_set_enable(&model, switch_to.y, switch_to.x, &switch_to.set); + if (rc) FAIL(rc); + +printf(" %s\n", fmt_swset(&model, switch_to.y, switch_to.x, &switch_to.set, SW_FROM)); switch_to.yx_req = YX_ROUTING_TO_FABLOGIC; switch_to.flags = SWTO_YX_CLOSEST; @@ -195,7 +201,10 @@ int main(int argc, char** argv) switch_to.start_switch = switch_to.dest_connpt; rc = fpga_switch_to_yx(&switch_to); if (rc) FAIL(rc); - printf(" %s\n", fmt_swchain(&model, switch_to.y, switch_to.x, switch_to.chain, switch_to.chain_size, SW_FROM)); + rc = fpga_switch_set_enable(&model, switch_to.y, switch_to.x, &switch_to.set); + if (rc) FAIL(rc); + +printf(" %s\n", fmt_swset(&model, switch_to.y, switch_to.x, &switch_to.set, SW_FROM)); switch_to.yx_req = YX_DEV_LOGIC; switch_to.flags = SWTO_YX_TARGET_CONNPT|SWTO_YX_MAX_SWITCH_DEPTH; @@ -217,7 +226,10 @@ int main(int argc, char** argv) } rc = fpga_switch_to_yx(&switch_to); if (rc) FAIL(rc); - printf(" %s\n", fmt_swchain(&model, switch_to.y, switch_to.x, switch_to.chain, switch_to.chain_size, SW_FROM)); + rc = fpga_switch_set_enable(&model, switch_to.y, switch_to.x, &switch_to.set); + if (rc) FAIL(rc); + +printf(" %s\n", fmt_swset(&model, switch_to.y, switch_to.x, &switch_to.set, SW_FROM)); { struct sw_chain c = { @@ -227,9 +239,14 @@ int main(int argc, char** argv) .from_to = SW_FROM, .max_chain_size = MAX_SW_DEPTH }; if (fpga_switch_chain(&c) == NO_CONN) FAIL(EINVAL); if (c.set.len == 0) { HERE(); FAIL(EINVAL); } - printf(" %s\n", fmt_swchain(&model, c.y, c.x, c.set.sw, c.set.len, SW_FROM)); + rc = fpga_switch_set_enable(&model, c.y, c.x, &c.set); + if (rc) FAIL(rc); +printf(" %s\n", fmt_swset(&model, c.y, c.x, &c.set, SW_FROM)); } + rc = diff_printf(&tstate); + if (rc) FAIL(rc); + printf("\n"); printf("P48 O pinw %s\n", strarray_lookup(&model.str, P48_dev->iob.pinw_in_O)); diff --git a/control.c b/control.c index 0488433..9d392ad 100644 --- a/control.c +++ b/control.c @@ -410,6 +410,15 @@ void fpga_switch_enable(struct fpga_model* model, int y, int x, YX_TILE(model, y, x)->switches[swidx] |= SWITCH_ON; } +int fpga_switch_set_enable(struct fpga_model* model, int y, int x, + struct sw_set* set) +{ + int i; + for (i = 0; i < set->len; i++) + fpga_switch_enable(model, y, x, set->sw[i]); + return 0; +} + void fpga_switch_disable(struct fpga_model* model, int y, int x, swidx_t swidx) { @@ -448,35 +457,35 @@ const char* fmt_sw(struct fpga_model* model, int y, int x, swidx_t sw, int from_ return sw_buf[last_buf]; } -#define FMT_SWCHAIN_BUF_SIZE 2048 -#define FMT_SWCHAIN_NUM_BUFS 8 +#define FMT_SWSET_BUF_SIZE 2048 +#define FMT_SWSET_NUM_BUFS 8 -const char* fmt_swchain(struct fpga_model* model, int y, int x, - swidx_t* sw, int sw_size, int from_to) +const char* fmt_swset(struct fpga_model* model, int y, int x, + struct sw_set* set, int from_to) { - static char buf[FMT_SWCHAIN_NUM_BUFS][FMT_SWCHAIN_BUF_SIZE]; + static char buf[FMT_SWSET_NUM_BUFS][FMT_SWSET_BUF_SIZE]; static int last_buf = 0; int i, o; - last_buf = (last_buf+1)%FMT_SWCHAIN_NUM_BUFS; + last_buf = (last_buf+1)%FMT_SWSET_NUM_BUFS; o = 0; - if (sw_size) { + if (set->len) { if (from_to == SW_FROM) { - strcpy(&buf[last_buf][o], fpga_switch_str(model, y, x, sw[0], SW_FROM)); + strcpy(&buf[last_buf][o], fpga_switch_str(model, y, x, set->sw[0], SW_FROM)); o += strlen(&buf[last_buf][o]); - for (i = 0; i < sw_size; i++) { + for (i = 0; i < set->len; i++) { buf[last_buf][o++] = ' '; - strcpy(&buf[last_buf][o], fmt_sw(model, y, x, sw[i], SW_FROM)); + strcpy(&buf[last_buf][o], fmt_sw(model, y, x, set->sw[i], SW_FROM)); o += strlen(&buf[last_buf][o]); } } else { // SW_TO - for (i = sw_size-1; i >= 0; i--) { - if (i < sw_size-1) buf[last_buf][o++] = ' '; - strcpy(&buf[last_buf][o], fmt_sw(model, y, x, sw[i], SW_TO)); + for (i = set->len-1; i >= 0; i--) { + if (i < set->len-1) buf[last_buf][o++] = ' '; + strcpy(&buf[last_buf][o], fmt_sw(model, y, x, set->sw[i], SW_TO)); o += strlen(&buf[last_buf][o]); } buf[last_buf][o++] = ' '; - strcpy(&buf[last_buf][o], fpga_switch_str(model, y, x, sw[0], SW_TO)); + strcpy(&buf[last_buf][o], fpga_switch_str(model, y, x, set->sw[0], SW_TO)); o += strlen(&buf[last_buf][o]); } } @@ -645,8 +654,8 @@ void printf_swchain(struct fpga_model* model, int y, int x, { .model = model, .y = y, .x = x, .start_switch = sw, .from_to = from_to, .max_chain_size = max_depth}; while (fpga_switch_chain(&chain) != NO_CONN) { - printf("sw %s\n", fmt_swchain(model, y, x, - chain.set.sw, chain.set.len, from_to)); + printf("sw %s\n", fmt_swset(model, y, x, + &chain.set, from_to)); } } @@ -657,8 +666,8 @@ void printf_swconns(struct fpga_model* model, int y, int x, { .model = model, .y = y, .x = x, .start_switch = sw, .max_switch_depth = max_depth }; while (fpga_switch_conns(&conns) != NO_CONN) { - printf("sw %s conn y%02i x%02i %s\n", fmt_swchain(model, y, x, - conns.chain.set.sw, conns.chain.set.len, SW_FROM), + printf("sw %s conn y%02i x%02i %s\n", fmt_swset(model, y, x, + &conns.chain.set, SW_FROM), conns.dest_y, conns.dest_x, strarray_lookup(&model->str, conns.dest_str_i)); } @@ -673,10 +682,10 @@ int fpga_switch_to_yx(struct switch_to_yx* p) (p->flags & SWTO_YX_MAX_SWITCH_DEPTH) ? p->max_switch_depth : MAX_SW_DEPTH }; - int best_y, best_x, best_chain_size, best_distance, distance; + struct sw_set best_set; + int best_y, best_x, best_distance, distance; int best_num_dests; str16_t best_connpt; - swidx_t best_chain[MAX_SW_DEPTH]; best_y = -1; while (fpga_switch_conns(&conns) != NO_CONN) { @@ -691,12 +700,10 @@ int fpga_switch_to_yx(struct switch_to_yx* p) continue; else if (conns.num_dests > best_num_dests) continue; - else if (conns.chain.set.len > best_chain_size) + else if (conns.chain.set.len > best_set.len) continue; } - memcpy(best_chain, conns.chain.set.sw, - conns.chain.set.len*sizeof(*best_chain)); - best_chain_size = conns.chain.set.len; + best_set = conns.chain.set; best_y = conns.dest_y; best_x = conns.dest_x; best_num_dests = conns.num_dests; @@ -708,10 +715,9 @@ int fpga_switch_to_yx(struct switch_to_yx* p) } } if (best_y == -1) - p->chain_size = 0; + p->set.len = 0; else { - memcpy(p->chain, best_chain, best_chain_size*sizeof(*p->chain)); - p->chain_size = best_chain_size; + p->set = best_set; p->dest_y = best_y; p->dest_x = best_x; p->dest_connpt = best_connpt; diff --git a/control.h b/control.h index 9094d17..1fe6bba 100644 --- a/control.h +++ b/control.h @@ -43,6 +43,12 @@ void fpga_conn_dest(struct fpga_model* model, int y, int x, typedef int swidx_t; // swidx_t is an index into the uint32_t switches array #define MAX_SW_DEPTH 64 // largest seen so far was 20 +struct sw_set +{ + swidx_t sw[MAX_SW_DEPTH]; + int len; +}; + // returns a switch index, or -1 (NO_SWITCH) if no switch was found swidx_t fpga_switch_first(struct fpga_model* model, int y, int x, str16_t name_i, int from_to); @@ -61,19 +67,15 @@ int fpga_switch_is_enabled(struct fpga_model* model, int y, int x, swidx_t swidx); void fpga_switch_enable(struct fpga_model* model, int y, int x, swidx_t swidx); +int fpga_switch_set_enable(struct fpga_model* model, int y, int x, + struct sw_set* set); void fpga_switch_disable(struct fpga_model* model, int y, int x, swidx_t swidx); const char* fmt_sw(struct fpga_model* model, int y, int x, swidx_t sw, int from_to); -const char* fmt_swchain(struct fpga_model* model, int y, int x, - swidx_t* sw, int sw_size, int from_to); - -struct sw_set -{ - swidx_t sw[MAX_SW_DEPTH]; - int len; -}; +const char* fmt_swset(struct fpga_model* model, int y, int x, + struct sw_set* set, int from_to); struct sw_chain { @@ -149,8 +151,7 @@ struct switch_to_yx str16_t target_connpt; // only if SWTO_YX_TARGET_CONNPT is set // output: - swidx_t chain[MAX_SW_DEPTH]; - int chain_size; + struct sw_set set; int dest_y; int dest_x; str16_t dest_connpt; diff --git a/floorplan.c b/floorplan.c index ae59c0c..6a2ee95 100644 --- a/floorplan.c +++ b/floorplan.c @@ -631,7 +631,9 @@ int printf_switches(FILE* f, struct fpga_model* model, int enabled_only) for (y = 0; y < model->y_height; y++) { tile = YX_TILE(model, y, x); - first_switch_printed = 0; + // no newlines between tiles in enabled_only mode + first_switch_printed = enabled_only; + for (i = 0; i < tile->num_switches; i++) { from_connpt_o = (tile->switches[i] & 0x3FFF8000) >> 15; to_connpt_o = tile->switches[i] & 0x00007FFF; @@ -654,9 +656,10 @@ int printf_switches(FILE* f, struct fpga_model* model, int enabled_only) first_switch_printed = 1; fprintf(f, "\n"); } - fprintf(f, "sw y%02i x%02i %s %s %s\n", + fprintf(f, "sw y%02i x%02i %s %s %s%s\n", y, x, from_str, is_bidirectional - ? "<->" : "->", to_str); + ? "<->" : "->", to_str, + is_on ? " on" : ""); } } }