249 lines
6.4 KiB
C
249 lines
6.4 KiB
C
//
|
|
// Author: Wolfgang Spraul
|
|
//
|
|
// This is free and unencumbered software released into the public domain.
|
|
// For details see the UNLICENSE file at the root of the source tree.
|
|
//
|
|
|
|
#include "model.h"
|
|
#include "control.h"
|
|
|
|
struct iob_site
|
|
{
|
|
int xy;
|
|
const char* name[4]; // left and right only use 2, top and bottom 4
|
|
};
|
|
|
|
static const struct iob_site xc6slx9_iob_top[] =
|
|
{
|
|
{ 5, {"P144", "P143", "P142", "P141"}},
|
|
{ 7, {"P140", "P139", "P138", "P137"}},
|
|
{12, {"UNB9", "UNB10", "UNB11", "UNB12"}},
|
|
{14, {"UNB13", "UNB14", "UNB15", "UNB16"}},
|
|
{19, {"UNB17", "UNB18", "UNB19", "UNB20"}},
|
|
{21, {"P134", "P133", "P132", "P131"}},
|
|
{25, {"P127", "P126", "P124", "P123"}},
|
|
{29, {"UNB29", "UNB30", "UNB31", "UNB32"}},
|
|
{31, {"UNB33", "UNB34", "P121", "P120"}},
|
|
{36, {"P119", "P118", "P117", "P116"}},
|
|
{38, {"P115", "P114", "P112", "P111"}},
|
|
};
|
|
|
|
static const struct iob_site xc6slx9_iob_bottom[] =
|
|
{
|
|
{ 5, {"P38", "P39", "P40", "P41"}},
|
|
{ 7, {"UNB140", "UNB139", "P43", "P44"}},
|
|
{12, {"P45", "P46", "P47", "P48"}},
|
|
{14, {"UNB132", "UNB131", "UNB130", "UNB129"}},
|
|
{19, {"UNB128", "UNB127", "UNB126", "UNB125"}},
|
|
{21, {"UNB124", "UNB123", "P50", "P51"}},
|
|
{25, {"P55", "P56", "UNB118", "UNB117"}},
|
|
{29, {"UNB116", "UNB115", "UNB114", "UNB113"}},
|
|
{31, {"P57", "P58", "P59", "P60"}},
|
|
{36, {"P61", "P62", "P64", "P65"}},
|
|
{38, {"P66", "P67", "P69", "P70"}},
|
|
};
|
|
|
|
static const struct iob_site xc6slx9_iob_left[] =
|
|
{
|
|
{ 3, {"P1", "P2"}},
|
|
{ 5, {"UNB198", "UNB197"}},
|
|
{ 7, {"UNB196", "UNB195"}},
|
|
{ 9, {"UNB194", "UNB193"}},
|
|
{ 11, {"P5", "P6"}},
|
|
{ 12, {"P7", "P8"}},
|
|
{ 13, {"P9", "P10"}},
|
|
{ 14, {"P11", "P12"}},
|
|
{ 28, {"UNB184", "UNB183"}},
|
|
{ 29, {"UNB182", "UNB181"}},
|
|
{ 30, {"UNB180", "UNB179"}},
|
|
{ 31, {"UNB178", "UNB177"}},
|
|
{ 32, {"P14", "P15"}},
|
|
{ 33, {"P16", "P17"}},
|
|
{ 37, {"P21", "P22"}},
|
|
{ 38, {"P23", "P24"}},
|
|
{ 39, {"UNB168", "UNB167"}},
|
|
{ 42, {"UNB166", "UNB165"}},
|
|
{ 46, {"UNB164", "UNB163"}},
|
|
{ 49, {"P26", "P27"}},
|
|
{ 52, {"P29", "P30"}},
|
|
{ 55, {"UNB158", "UNB157"}},
|
|
{ 58, {"UNB156", "UNB155"}},
|
|
{ 61, {"UNB154", "UNB153"}},
|
|
{ 65, {"UNB152", "UNB151"}},
|
|
{ 66, {"UNB150", "UNB149"}},
|
|
{ 67, {"P32", "P33"}},
|
|
{ 68, {"P34", "P35"}},
|
|
};
|
|
|
|
static const struct iob_site xc6slx9_iob_right[] =
|
|
{
|
|
{ 4, {"P105", "P104"}},
|
|
{ 5, {"UNB47", "UNB48"}},
|
|
{ 7, {"UNB49", "UNB50"}},
|
|
{ 9, {"UNB51", "UNB52"}},
|
|
{ 11, {"P102", "P101"}},
|
|
{ 12, {"P100", "P99"}},
|
|
{ 13, {"P98", "P97"}},
|
|
{ 14, {"UNB59", "UNB60"}},
|
|
{ 28, {"UNB61", "UNB62"}},
|
|
{ 29, {"UNB63", "UNB64"}},
|
|
{ 30, {"UNB65", "UNB66"}},
|
|
{ 31, {"UNB67", "UNB68"}},
|
|
{ 32, {"P95", "P94"}},
|
|
{ 33, {"P93", "P92"}},
|
|
{ 37, {"P88", "P87"}},
|
|
{ 38, {"P85", "P84"}},
|
|
{ 39, {"UNB77", "UNB78"}},
|
|
{ 42, {"P83", "P82"}},
|
|
{ 46, {"P81", "P80"}},
|
|
{ 49, {"P79", "P78"}},
|
|
{ 52, {"UNB85", "UNB86"}},
|
|
{ 55, {"UNB87", "UNB88"}},
|
|
{ 58, {"UNB89", "UNB90"}},
|
|
{ 61, {"UNB91", "UNB92"}},
|
|
{ 65, {"UNB93", "UNB94"}},
|
|
{ 66, {"UNB95", "UNB96"}},
|
|
{ 67, {"UNB97", "UNB98"}},
|
|
{ 68, {"P75", "P74"}},
|
|
};
|
|
|
|
int fpga_find_iob(struct fpga_model* model, const char* sitename,
|
|
int* y, int* x, int* idx)
|
|
{
|
|
int i, j;
|
|
|
|
for (i = 0; i < sizeof(xc6slx9_iob_top)/sizeof(xc6slx9_iob_top[0]); i++) {
|
|
for (j = 0; j < 4; j++) {
|
|
if (!strcmp(xc6slx9_iob_top[i].name[j], sitename)) {
|
|
*y = TOP_OUTER_ROW;
|
|
*x = xc6slx9_iob_top[i].xy;
|
|
*idx = j;
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
for (i = 0; i < sizeof(xc6slx9_iob_bottom)/sizeof(xc6slx9_iob_bottom[0]); i++) {
|
|
for (j = 0; j < 4; j++) {
|
|
if (!strcmp(xc6slx9_iob_bottom[i].name[j], sitename)) {
|
|
*y = model->y_height-BOT_OUTER_ROW;
|
|
*x = xc6slx9_iob_bottom[i].xy;
|
|
*idx = j;
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
for (i = 0; i < sizeof(xc6slx9_iob_left)/sizeof(xc6slx9_iob_left[0]); i++) {
|
|
for (j = 0; j < 2; j++) {
|
|
if (!strcmp(xc6slx9_iob_left[i].name[j], sitename)) {
|
|
*y = xc6slx9_iob_left[i].xy;
|
|
*x = LEFT_OUTER_COL;
|
|
*idx = j;
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
for (i = 0; i < sizeof(xc6slx9_iob_right)/sizeof(xc6slx9_iob_right[0]); i++) {
|
|
for (j = 0; j < 2; j++) {
|
|
if (!strcmp(xc6slx9_iob_right[i].name[j], sitename)) {
|
|
*y = xc6slx9_iob_right[i].xy;
|
|
*x = model->x_width-RIGHT_OUTER_O;
|
|
*idx = j;
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
const char* fpga_iob_sitename(struct fpga_model* model, int y, int x,
|
|
int idx)
|
|
{
|
|
int i;
|
|
|
|
if (y == TOP_OUTER_ROW) {
|
|
for (i = 0; i < sizeof(xc6slx9_iob_top)/sizeof(xc6slx9_iob_top[0]); i++) {
|
|
if (xc6slx9_iob_right[i].xy == x) {
|
|
if (idx < 0 || idx > 3) return 0;
|
|
return xc6slx9_iob_top[i].name[idx];
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
if (y == model->y_height-BOT_OUTER_ROW) {
|
|
for (i = 0; i < sizeof(xc6slx9_iob_bottom)/sizeof(xc6slx9_iob_bottom[0]); i++) {
|
|
if (xc6slx9_iob_bottom[i].xy == x) {
|
|
if (idx < 0 || idx > 3) return 0;
|
|
return xc6slx9_iob_bottom[i].name[idx];
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
if (x == LEFT_OUTER_COL) {
|
|
for (i = 0; i < sizeof(xc6slx9_iob_left)/sizeof(xc6slx9_iob_left[0]); i++) {
|
|
if (xc6slx9_iob_left[i].xy == y) {
|
|
if (idx < 0 || idx > 1) return 0;
|
|
return xc6slx9_iob_left[i].name[idx];
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
if (x == model->x_width-RIGHT_OUTER_O) {
|
|
for (i = 0; i < sizeof(xc6slx9_iob_right)/sizeof(xc6slx9_iob_right[0]); i++) {
|
|
if (xc6slx9_iob_right[i].xy == y) {
|
|
if (idx < 0 || idx > 1) return 0;
|
|
return xc6slx9_iob_right[i].name[idx];
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
struct fpga_device* fpga_dev(struct fpga_model* model,
|
|
int y, int x, enum fpgadev_type type, int idx)
|
|
{
|
|
struct fpga_tile* tile;
|
|
int type_count, i;
|
|
|
|
tile = YX_TILE(model, y, x);
|
|
type_count = 0;
|
|
for (i = 0; i < tile->num_devs; i++) {
|
|
if (tile->devs[i].type == type) {
|
|
if (type_count == idx)
|
|
return &tile->devs[i];
|
|
type_count++;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
#define MAX_LUT_LEN 512
|
|
|
|
int fpga_set_lut(struct fpga_model* model, struct fpga_device* dev,
|
|
int which_lut, const char* lut_str, int lut_len)
|
|
{
|
|
char** ptr;
|
|
|
|
if (dev->type != DEV_LOGIC)
|
|
return -1;
|
|
switch (which_lut) {
|
|
case A6_LUT: ptr = &dev->logic.A6_lut; break;
|
|
case B6_LUT: ptr = &dev->logic.B6_lut; break;
|
|
case C6_LUT: ptr = &dev->logic.C6_lut; break;
|
|
case D6_LUT: ptr = &dev->logic.D6_lut; break;
|
|
default: return -1;
|
|
}
|
|
if (!(*ptr)) {
|
|
*ptr = malloc(MAX_LUT_LEN);
|
|
if (!(*ptr)) {
|
|
OUT_OF_MEM();
|
|
return -1;
|
|
}
|
|
}
|
|
if (lut_len == ZTERM) lut_len = strlen(lut_str);
|
|
memcpy(*ptr, lut_str, lut_len);
|
|
(*ptr)[lut_len] = 0;
|
|
return 0;
|
|
}
|