For me python sucks. I tried to write some code to convert the data I found into something I can use in my project, but failed on a stupid data copying bit I don't grasp and the IDE does not tell me what is wrong so I ended up just writing it in C. As ii was for just a single job one time conversion not the most elegant code but it did the trick.
The python code kept failing on the assignment "sectionnames = items[0]". I tried to just load it with a static but every time it just bailed out without any info. Was not in the mood to research it further. My python knowledge is very little and not high upon my list to learn more about it, but if it is obvious to someone why it fails, please enlighten me.
items = []
sectionnames = []
sectionids = []
def main():
global items
global sectionnames
global sectionids
inputfile = open("al3_10_connection_setup", "rt")
outputfile = open("al3_10_signal_mapping.h", "wt")
strinp = inputfile.readline()
nofsections = int(strinp)
for i in range(nofsections):
strinp = inputfile.readline()
items = strinp.split()
sectionnames[i] = items[0]
sectionids[i] = items[1]
strinp = inputfile.readline()
if __name__ == "__main__":
main()
In my C code I added a couple of if statements for breakpoints to detect if parts of the data did something unexpected and at some point it did. A counter was 2 instead of 1 so had to deal with that. Also the length of the names were bigger then expected.
#include <stdio.h> // standard input / output functions
#include <stdlib.h>
#include <string.h>
void listdatasection(FILE *fin, FILE *fout, char *sectionname, int count)
{
int datatid;
int datacount;
char hdl_name[32];
char signal_name[32];
int cnt0;
int cnt1;
int signalid;
int xoff;
int yoff;
int len;
char line[128];
char *sptr;
char *dptr;
while(count--)
{
fgets(line, 128, fin);
sptr = line;
datatid = atoi(sptr);
while(*sptr++ != ' ');
datacount = atoi(sptr);
fprintf(fout, "//----------------------------------------------------------------------------------------------------------------------------------\n\n");
fprintf(fout, "SIGNAL_NAME_MAP %s_%d[] =\n{\n", sectionname, datatid);
while(datacount--)
{
fgets(line, 128, fin);
dptr = hdl_name;
sptr = line;
while(*sptr != ' ')
{
*dptr++ = *sptr++;
}
*dptr = 0;
sptr++;
cnt0 = atoi(sptr);
while(*sptr++ != ' ');
cnt1 = atoi(sptr);
if((cnt0 != 0) || ((cnt1 != 1) && (cnt1 != 2)))
{
dptr = 0;
}
//This next bit needs to be done cnt1 times????
//Not entirely. The multiple data is on the same line and is repeated as such indicating a signal can have entries in to tiles
fgets(line, 128, fin);
sptr = line;
signalid = atoi(sptr);
if(signalid != 0)
{
dptr = 0;
}
while(*sptr++ != ' ');
dptr = signal_name;
while(*sptr != ' ')
{
*dptr++ = *sptr++;
}
*dptr = 0;
sptr++;
xoff = atoi(sptr);
while(*sptr++ != ' ');
yoff = atoi(sptr);
fprintf(fout, " { \"%s\",", hdl_name);
len = 21 - strlen(hdl_name);
if(len < 0)
{
dptr = 0;
}
while(len--)
{
fwrite(" ", 1, 1, fout);
}
fprintf(fout, "\"%s\",", signal_name);
len = 13 - strlen(signal_name);
if(len < 0)
{
dptr = 0;
}
while(len--)
{
fwrite(" ", 1, 1, fout);
}
if(xoff >= 0)
{
fwrite(" ", 1, 1, fout);
}
fprintf(fout, "%d, ", xoff);
if(yoff >= 0)
{
fwrite(" ", 1, 1, fout);
}
fprintf(fout, "%d },\n", yoff);
if(cnt1 == 2)
{
while(*sptr++ != ' ');
signalid = atoi(sptr);
if(signalid != 0)
{
dptr = 0;
}
while(*sptr++ != ' ');
dptr = signal_name;
while(*sptr != ' ')
{
*dptr++ = *sptr++;
}
*dptr = 0;
sptr++;
xoff = atoi(sptr);
while(*sptr++ != ' ');
yoff = atoi(sptr);
fprintf(fout, " { \"%s\",", hdl_name);
len = 21 - strlen(hdl_name);
if(len < 0)
{
dptr = 0;
}
while(len--)
{
fwrite(" ", 1, 1, fout);
}
fprintf(fout, "\"%s\",", signal_name);
len = 13 - strlen(signal_name);
if(len < 0)
{
dptr = 0;
}
while(len--)
{
fwrite(" ", 1, 1, fout);
}
if(xoff >= 0)
{
fwrite(" ", 1, 1, fout);
}
fprintf(fout, "%d, ", xoff);
if(yoff >= 0)
{
fwrite(" ", 1, 1, fout);
}
fprintf(fout, "%d },\n", yoff);
}
}
fprintf(fout, "};\n\n" );
}
}
int main(int argc, char** argv)
{
FILE *fin = fopen("al3_10_connection_setup", "r");
FILE *fout = fopen("al3_10_connection_setup.h", "w");
char line[128];
int nofsections;
int i,j;
char *sptr;
char *dptr;
char sectionnames[20][32];
char sectionids[20];
int id;
int count;
if(fin && fout)
{
fgets(line, 128, fin);
nofsections = atoi(line);
for(i=0;i<nofsections;i++)
{
fgets(line, 128, fin);
dptr = sectionnames[i];
sptr = line;
while(*sptr != ' ')
{
*dptr++ = *sptr++;
}
*dptr = 0;
sptr++;
sectionids[i] = atoi(sptr);
}
while(fgets(line, 128, fin))
{
//Next bit has an id number and a count
sptr = line;
id = atoi(sptr);
while(*sptr++ != ' ');
count = atoi(sptr);
//Match the id to one of the section ids and use the belonging name to make an entry in the h file
for(i=0;i<nofsections;i++)
{
if(id == sectionids[i])
{
id = i;
break;
}
}
//Make a function to read the lines from the file and write them to the h file
listdatasection(fin, fout, sectionnames[id], count);
}
fprintf(fout, "//----------------------------------------------------------------------------------------------------------------------------------\n\n");
fclose(fin);
fclose(fout);
}
}
It yielded information like below
//----------------------------------------------------------------------------------------------------------------------------------
SIGNAL_NAME_MAP iol_tb_0[] =
{
{ "ce", "ce0", 0, 0 },
{ "clk", "clk_s0", 0, 0 },
{ "di", "q0", 0, 0 },
{ "eninr_dyn", "d3", 0, 0 },
{ "icomp", "f1", 0, 0 },
{ "itrue", "f0", 0, 0 },
{ "ocomp", "b3", 0, 0 },
{ "otrue", "a3", 0, 0 },
{ "rst", "sr0", 0, 0 },
{ "ts", "c3", 0, 0 },
};
//----------------------------------------------------------------------------------------------------------------------------------
SIGNAL_NAME_MAP iol_tb_1[] =
{
{ "ce", "ce1", 0, 0 },
{ "clk", "clk_s1", 0, 0 },
{ "di", "q1", 0, 0 },
{ "eninr_dyn", "d4", 0, 0 },
{ "icomp", "f2", 0, 0 },
{ "itrue", "f3", 0, 0 },
{ "ocomp", "b4", 0, 0 },
{ "otrue", "a4", 0, 0 },
{ "rst", "sr1", 0, 0 },
{ "ts", "c4", 0, 0 },
};
//----------------------------------------------------------------------------------------------------------------------------------
SIGNAL_NAME_MAP iol_tb_2[] =
{
{ "ce", "ce1", 1, 0 },
{ "clk", "clk_s1", 1, 0 },
{ "di", "q1", 1, 0 },
{ "eninr_dyn", "d4", 1, 0 },
{ "icomp", "f2", 1, 0 },
{ "itrue", "f3", 1, 0 },
{ "ocomp", "b4", 1, 0 },
{ "otrue", "a4", 1, 0 },
{ "rst", "sr1", 1, 0 },
{ "ts", "c4", 1, 0 },
};
//----------------------------------------------------------------------------------------------------------------------------------
SIGNAL_NAME_MAP iol_tb_3[] =
{
{ "ce", "ce0", 1, 0 },
{ "clk", "clk_s0", 1, 0 },
{ "di", "q0", 1, 0 },
{ "eninr_dyn", "d3", 1, 0 },
{ "icomp", "f1", 1, 0 },
{ "itrue", "f0", 1, 0 },
{ "ocomp", "b3", 1, 0 },
{ "otrue", "a3", 1, 0 },
{ "rst", "sr0", 1, 0 },
{ "ts", "c3", 1, 0 },
};
//----------------------------------------------------------------------------------------------------------------------------------
Now that I have this data I have to make an array with information per tile on which of the tables need to be searched to translate the tile signal name to the hdl signal name.