enabling a few switches

This commit is contained in:
Wolfgang Spraul 2012-08-24 08:12:13 +02:00
parent 183317620c
commit 2b80d283f4
4 changed files with 73 additions and 46 deletions

View File

@ -167,7 +167,7 @@ int main(int argc, char** argv)
rc = diff_printf(&tstate); rc = diff_printf(&tstate);
if (rc) FAIL(rc); 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.yx_req = YX_DEV_ILOGIC;
switch_to.flags = SWTO_YX_DEF; 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; switch_to.start_switch = P46_dev->iob.pinw_out_I;
rc = fpga_switch_to_yx(&switch_to); rc = fpga_switch_to_yx(&switch_to);
if (rc) FAIL(rc); 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.yx_req = YX_ROUTING_TILE;
switch_to.flags = SWTO_YX_DEF; switch_to.flags = SWTO_YX_DEF;
@ -186,7 +189,10 @@ int main(int argc, char** argv)
switch_to.start_switch = switch_to.dest_connpt; switch_to.start_switch = switch_to.dest_connpt;
rc = fpga_switch_to_yx(&switch_to); rc = fpga_switch_to_yx(&switch_to);
if (rc) FAIL(rc); 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.yx_req = YX_ROUTING_TO_FABLOGIC;
switch_to.flags = SWTO_YX_CLOSEST; switch_to.flags = SWTO_YX_CLOSEST;
@ -195,7 +201,10 @@ int main(int argc, char** argv)
switch_to.start_switch = switch_to.dest_connpt; switch_to.start_switch = switch_to.dest_connpt;
rc = fpga_switch_to_yx(&switch_to); rc = fpga_switch_to_yx(&switch_to);
if (rc) FAIL(rc); 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.yx_req = YX_DEV_LOGIC;
switch_to.flags = SWTO_YX_TARGET_CONNPT|SWTO_YX_MAX_SWITCH_DEPTH; 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); rc = fpga_switch_to_yx(&switch_to);
if (rc) FAIL(rc); 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 = { struct sw_chain c = {
@ -227,9 +239,14 @@ int main(int argc, char** argv)
.from_to = SW_FROM, .max_chain_size = MAX_SW_DEPTH }; .from_to = SW_FROM, .max_chain_size = MAX_SW_DEPTH };
if (fpga_switch_chain(&c) == NO_CONN) FAIL(EINVAL); if (fpga_switch_chain(&c) == NO_CONN) FAIL(EINVAL);
if (c.set.len == 0) { HERE(); 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("\n");
printf("P48 O pinw %s\n", strarray_lookup(&model.str, P48_dev->iob.pinw_in_O)); printf("P48 O pinw %s\n", strarray_lookup(&model.str, P48_dev->iob.pinw_in_O));

View File

@ -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; 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, void fpga_switch_disable(struct fpga_model* model, int y, int x,
swidx_t swidx) 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]; return sw_buf[last_buf];
} }
#define FMT_SWCHAIN_BUF_SIZE 2048 #define FMT_SWSET_BUF_SIZE 2048
#define FMT_SWCHAIN_NUM_BUFS 8 #define FMT_SWSET_NUM_BUFS 8
const char* fmt_swchain(struct fpga_model* model, int y, int x, const char* fmt_swset(struct fpga_model* model, int y, int x,
swidx_t* sw, int sw_size, int from_to) 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; static int last_buf = 0;
int i, o; int i, o;
last_buf = (last_buf+1)%FMT_SWCHAIN_NUM_BUFS; last_buf = (last_buf+1)%FMT_SWSET_NUM_BUFS;
o = 0; o = 0;
if (sw_size) { if (set->len) {
if (from_to == SW_FROM) { 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]); o += strlen(&buf[last_buf][o]);
for (i = 0; i < sw_size; i++) { for (i = 0; i < set->len; i++) {
buf[last_buf][o++] = ' '; 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]); o += strlen(&buf[last_buf][o]);
} }
} else { // SW_TO } else { // SW_TO
for (i = sw_size-1; i >= 0; i--) { for (i = set->len-1; i >= 0; i--) {
if (i < sw_size-1) buf[last_buf][o++] = ' '; if (i < set->len-1) buf[last_buf][o++] = ' ';
strcpy(&buf[last_buf][o], fmt_sw(model, y, x, sw[i], SW_TO)); strcpy(&buf[last_buf][o], fmt_sw(model, y, x, set->sw[i], SW_TO));
o += strlen(&buf[last_buf][o]); o += strlen(&buf[last_buf][o]);
} }
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]); 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, { .model = model, .y = y, .x = x, .start_switch = sw,
.from_to = from_to, .max_chain_size = max_depth}; .from_to = from_to, .max_chain_size = max_depth};
while (fpga_switch_chain(&chain) != NO_CONN) { while (fpga_switch_chain(&chain) != NO_CONN) {
printf("sw %s\n", fmt_swchain(model, y, x, printf("sw %s\n", fmt_swset(model, y, x,
chain.set.sw, chain.set.len, from_to)); &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, { .model = model, .y = y, .x = x, .start_switch = sw,
.max_switch_depth = max_depth }; .max_switch_depth = max_depth };
while (fpga_switch_conns(&conns) != NO_CONN) { while (fpga_switch_conns(&conns) != NO_CONN) {
printf("sw %s conn y%02i x%02i %s\n", fmt_swchain(model, y, x, printf("sw %s conn y%02i x%02i %s\n", fmt_swset(model, y, x,
conns.chain.set.sw, conns.chain.set.len, SW_FROM), &conns.chain.set, SW_FROM),
conns.dest_y, conns.dest_x, conns.dest_y, conns.dest_x,
strarray_lookup(&model->str, conns.dest_str_i)); 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->flags & SWTO_YX_MAX_SWITCH_DEPTH)
? p->max_switch_depth : MAX_SW_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; int best_num_dests;
str16_t best_connpt; str16_t best_connpt;
swidx_t best_chain[MAX_SW_DEPTH];
best_y = -1; best_y = -1;
while (fpga_switch_conns(&conns) != NO_CONN) { while (fpga_switch_conns(&conns) != NO_CONN) {
@ -691,12 +700,10 @@ int fpga_switch_to_yx(struct switch_to_yx* p)
continue; continue;
else if (conns.num_dests > best_num_dests) else if (conns.num_dests > best_num_dests)
continue; continue;
else if (conns.chain.set.len > best_chain_size) else if (conns.chain.set.len > best_set.len)
continue; continue;
} }
memcpy(best_chain, conns.chain.set.sw, best_set = conns.chain.set;
conns.chain.set.len*sizeof(*best_chain));
best_chain_size = conns.chain.set.len;
best_y = conns.dest_y; best_y = conns.dest_y;
best_x = conns.dest_x; best_x = conns.dest_x;
best_num_dests = conns.num_dests; best_num_dests = conns.num_dests;
@ -708,10 +715,9 @@ int fpga_switch_to_yx(struct switch_to_yx* p)
} }
} }
if (best_y == -1) if (best_y == -1)
p->chain_size = 0; p->set.len = 0;
else { else {
memcpy(p->chain, best_chain, best_chain_size*sizeof(*p->chain)); p->set = best_set;
p->chain_size = best_chain_size;
p->dest_y = best_y; p->dest_y = best_y;
p->dest_x = best_x; p->dest_x = best_x;
p->dest_connpt = best_connpt; p->dest_connpt = best_connpt;

View File

@ -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 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 #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 // 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, swidx_t fpga_switch_first(struct fpga_model* model, int y, int x,
str16_t name_i, int from_to); 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); swidx_t swidx);
void fpga_switch_enable(struct fpga_model* model, int y, int x, void fpga_switch_enable(struct fpga_model* model, int y, int x,
swidx_t swidx); 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, void fpga_switch_disable(struct fpga_model* model, int y, int x,
swidx_t swidx); swidx_t swidx);
const char* fmt_sw(struct fpga_model* model, int y, int x, const char* fmt_sw(struct fpga_model* model, int y, int x,
swidx_t sw, int from_to); swidx_t sw, int from_to);
const char* fmt_swchain(struct fpga_model* model, int y, int x, const char* fmt_swset(struct fpga_model* model, int y, int x,
swidx_t* sw, int sw_size, int from_to); struct sw_set* set, int from_to);
struct sw_set
{
swidx_t sw[MAX_SW_DEPTH];
int len;
};
struct sw_chain struct sw_chain
{ {
@ -149,8 +151,7 @@ struct switch_to_yx
str16_t target_connpt; // only if SWTO_YX_TARGET_CONNPT is set str16_t target_connpt; // only if SWTO_YX_TARGET_CONNPT is set
// output: // output:
swidx_t chain[MAX_SW_DEPTH]; struct sw_set set;
int chain_size;
int dest_y; int dest_y;
int dest_x; int dest_x;
str16_t dest_connpt; str16_t dest_connpt;

View File

@ -631,7 +631,9 @@ int printf_switches(FILE* f, struct fpga_model* model, int enabled_only)
for (y = 0; y < model->y_height; y++) { for (y = 0; y < model->y_height; y++) {
tile = YX_TILE(model, y, x); 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++) { for (i = 0; i < tile->num_switches; i++) {
from_connpt_o = (tile->switches[i] & 0x3FFF8000) >> 15; from_connpt_o = (tile->switches[i] & 0x3FFF8000) >> 15;
to_connpt_o = tile->switches[i] & 0x00007FFF; 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; first_switch_printed = 1;
fprintf(f, "\n"); 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 y, x, from_str, is_bidirectional
? "<->" : "->", to_str); ? "<->" : "->", to_str,
is_on ? " on" : "");
} }
} }
} }