1 |
2 |
jsauermann |
|
2 |
|
|
#include <stdio.h>
|
3 |
|
|
#include <assert.h>
|
4 |
|
|
|
5 |
|
|
char data[0x10000];
|
6 |
|
|
|
7 |
|
|
//-----------------------------------------------------------------------------
|
8 |
|
|
void write_mem_1(FILE * out, FILE * ucf, int bank, int bit, const char * data)
|
9 |
|
|
{
|
10 |
|
|
fprintf(out, "-- content of m_%d_%d\r\n", bank, bit);
|
11 |
|
|
for (int col = 0; col < 16; col++)
|
12 |
|
|
{
|
13 |
|
|
fprintf(out, "constant m_%d_%d_%X : BIT_VECTOR := X\"", bank, bit, col);
|
14 |
|
|
fprintf(ucf, "INST \"cp_eng_memo_m_%d_%d\" INIT_0%X = ",
|
15 |
|
|
bank, bit, col);
|
16 |
|
|
|
17 |
|
|
for (const char * end = data + 256*(col + 1); end > data + 256*col;)
|
18 |
|
|
{
|
19 |
|
|
int b3 = *--end; b3 >>= bit; b3 &= 1;
|
20 |
|
|
int b2 = *--end; b2 >>= bit; b2 &= 1;
|
21 |
|
|
int b1 = *--end; b1 >>= bit; b1 &= 1;
|
22 |
|
|
int b0 = *--end; b0 >>= bit; b0 &= 1;
|
23 |
|
|
fprintf(out, "%1.1X", (b3 << 3) | (b2 << 2) | (b1 << 1) | b0);
|
24 |
|
|
fprintf(ucf, "%1.1X", (b3 << 3) | (b2 << 2) | (b1 << 1) | b0);
|
25 |
|
|
}
|
26 |
|
|
|
27 |
|
|
fprintf(out, "\";\r\n");
|
28 |
|
|
fprintf(ucf, ";\r\n");
|
29 |
|
|
|
30 |
|
|
}
|
31 |
|
|
fprintf(out, "\r\n");
|
32 |
|
|
fprintf(ucf, "\r\n");
|
33 |
|
|
|
34 |
|
|
/**********
|
35 |
|
|
fprintf(out,
|
36 |
|
|
"\tm_%d_%d : RAMB4_S1_S1\r\n"
|
37 |
|
|
"\t-- synopsys translate_off\r\n"
|
38 |
|
|
"\tGENERIC MAP(\r\n", bank, bit);
|
39 |
|
|
|
40 |
|
|
for (int col = 0; col < 4; col++)
|
41 |
|
|
{
|
42 |
|
|
fprintf(out, "\t");
|
43 |
|
|
for (int row = 0; row < 4; row++)
|
44 |
|
|
{
|
45 |
|
|
const int pos = row + 4*col;
|
46 |
|
|
fprintf(out, "INIT_0%X => m_%d_%d_%X", pos, bank, bit, pos);
|
47 |
|
|
if (pos < 15) fprintf(out, ", ");
|
48 |
|
|
else fprintf(out, ")");
|
49 |
|
|
}
|
50 |
|
|
fprintf(out, "\r\n");
|
51 |
|
|
}
|
52 |
|
|
fprintf(out, "\t-- synopsys translate_on\r\n\r\n");
|
53 |
|
|
**********/
|
54 |
|
|
}
|
55 |
|
|
//-----------------------------------------------------------------------------
|
56 |
|
|
void write_bank_1(FILE * out, FILE * ucf, int bank, const char * data)
|
57 |
|
|
{
|
58 |
|
|
for (int i = 0; i < 8; i++) write_mem_1(out, ucf, bank, i, data);
|
59 |
|
|
}
|
60 |
|
|
//-----------------------------------------------------------------------------
|
61 |
|
|
void write_header(FILE * out, FILE * ucf)
|
62 |
|
|
{
|
63 |
|
|
fprintf(out,
|
64 |
|
|
"library IEEE;\r\n"
|
65 |
|
|
"use IEEE.STD_LOGIC_1164.all;\r\n"
|
66 |
|
|
"\r\n"
|
67 |
|
|
"package mem_content is\r\n"
|
68 |
|
|
"\r\n"
|
69 |
|
|
);
|
70 |
|
|
|
71 |
|
|
fprintf(ucf,
|
72 |
|
|
"NET \"clk40\" TNM_NET = \"clk40\";\r\n"
|
73 |
|
|
"TIMESPEC \"TS_clk40\" = PERIOD \"clk40\" 25 ns HIGH 50 %%;\r\n"
|
74 |
|
|
// "NET \"clk20\" TNM_NET = \"clk20\";\r\n"
|
75 |
|
|
// "TIMESPEC \"TS_clk20\" = PERIOD \"clk20\" \"TS_clk40\" * 2;\r\n"
|
76 |
|
|
"\r\n"
|
77 |
|
|
"NET \"clk40\" LOC = P92;\r\n"
|
78 |
|
|
"NET \"clk_out\" LOC = P84;\r\n"
|
79 |
|
|
|
80 |
|
|
"NET \"xm_adr<14>\" LOC = P66;\r\n"
|
81 |
|
|
"NET \"xm_adr<12>\" LOC = P64;\r\n"
|
82 |
|
|
"NET \"xm_we_n\" LOC = P63;\r\n"
|
83 |
|
|
"NET \"xm_adr<7>\" LOC = P99;\r\n"
|
84 |
|
|
"NET \"xm_adr<13>\" LOC = P97;\r\n"
|
85 |
|
|
"NET \"xm_adr<6>\" LOC = P96;\r\n"
|
86 |
|
|
"NET \"xm_adr<8>\" LOC = P95;\r\n"
|
87 |
|
|
"NET \"xm_adr<5>\" LOC = P94;\r\n"
|
88 |
|
|
"NET \"xm_adr<9>\" LOC = P118;\r\n"
|
89 |
|
|
"NET \"xm_adr<4>\" LOC = P117;\r\n"
|
90 |
|
|
"NET \"xm_adr<11>\" LOC = P115;\r\n"
|
91 |
|
|
"NET \"xm_adr<3>\" LOC = P114;\r\n"
|
92 |
|
|
"NET \"xm_oe_n\" LOC = P113;\r\n"
|
93 |
|
|
"NET \"xm_adr<2>\" LOC = P111;\r\n"
|
94 |
|
|
"NET \"xm_adr<10>\" LOC = P110;\r\n"
|
95 |
|
|
"NET \"xm_adr<1>\" LOC = P109;\r\n"
|
96 |
|
|
"NET \"xm_ce_n\" LOC = P108;\r\n"
|
97 |
|
|
"NET \"xm_adr<0>\" LOC = P149;\r\n"
|
98 |
|
|
"NET \"xm_dio<7>\" LOC = P147;\r\n"
|
99 |
|
|
"NET \"xm_dio<0>\" LOC = P144;\r\n"
|
100 |
|
|
"NET \"xm_dio<6>\" LOC = P142;\r\n"
|
101 |
|
|
"NET \"xm_dio<1>\" LOC = P141;\r\n"
|
102 |
|
|
"NET \"xm_dio<5>\" LOC = P140;\r\n"
|
103 |
|
|
"NET \"xm_dio<2>\" LOC = P139;\r\n"
|
104 |
|
|
"NET \"xm_dio<4>\" LOC = P133;\r\n"
|
105 |
|
|
"NET \"xm_dio<3>\" LOC = P131;\r\n"
|
106 |
|
|
|
107 |
|
|
"NET \"deactivate_n\" LOC = P220;\r\n"
|
108 |
|
|
"NET \"enable_n\" LOC = P218;\r\n"
|
109 |
|
|
"NET \"led<0>\" LOC = P27;\r\n"
|
110 |
|
|
"NET \"led<1>\" LOC = P28;\r\n"
|
111 |
|
|
"NET \"led<2>\" LOC = P3;\r\n"
|
112 |
|
|
"NET \"led<3>\" LOC = P4;\r\n"
|
113 |
|
|
"NET \"led<4>\" LOC = P5;\r\n"
|
114 |
|
|
"NET \"led<5>\" LOC = P6;\r\n"
|
115 |
|
|
"NET \"led<6>\" LOC = P7;\r\n"
|
116 |
|
|
"NET \"led<7>\" LOC = P9;\r\n"
|
117 |
|
|
"NET \"ser_in\" LOC = P216;\r\n"
|
118 |
|
|
"NET \"ser_out\" LOC = P217;\r\n"
|
119 |
|
|
"NET \"switch<0>\" LOC = P194;\r\n"
|
120 |
|
|
"NET \"switch<1>\" LOC = P195;\r\n"
|
121 |
|
|
"NET \"switch<2>\" LOC = P199;\r\n"
|
122 |
|
|
"NET \"switch<3>\" LOC = P200;\r\n"
|
123 |
|
|
"NET \"switch<4>\" LOC = P201;\r\n"
|
124 |
|
|
"NET \"switch<5>\" LOC = P202;\r\n"
|
125 |
|
|
"NET \"switch<6>\" LOC = P203;\r\n"
|
126 |
|
|
"NET \"switch<7>\" LOC = P205;\r\n"
|
127 |
|
|
"NET \"switch<8>\" LOC = P206;\r\n"
|
128 |
|
|
"NET \"switch<9>\" LOC = P208;\r\n"
|
129 |
|
|
"NET \"temp_ce\" LOC = P160;\r\n"
|
130 |
|
|
"NET \"temp_sclk\" LOC = P159;\r\n"
|
131 |
|
|
"NET \"temp_spi\" LOC = P161;\r\n"
|
132 |
|
|
"NET \"temp_spo\" LOC = P162;\r\n"
|
133 |
|
|
"NET \"seg1<0>\" LOC = P231; \r\n"
|
134 |
|
|
"NET \"seg1<1>\" LOC = P230; \r\n"
|
135 |
|
|
"NET \"seg1<2>\" LOC = P229; \r\n"
|
136 |
|
|
"NET \"seg1<3>\" LOC = P228; \r\n"
|
137 |
|
|
"NET \"seg1<4>\" LOC = P224; \r\n"
|
138 |
|
|
"NET \"seg1<5>\" LOC = P223; \r\n"
|
139 |
|
|
"NET \"seg1<6>\" LOC = P222; \r\n"
|
140 |
|
|
"NET \"seg1<7>\" LOC = P221; \r\n"
|
141 |
|
|
"NET \"seg2<0>\" LOC = P188; \r\n"
|
142 |
|
|
"NET \"seg2<1>\" LOC = P187; \r\n"
|
143 |
|
|
"NET \"seg2<2>\" LOC = P186; \r\n"
|
144 |
|
|
"NET \"seg2<3>\" LOC = P238; \r\n"
|
145 |
|
|
"NET \"seg2<4>\" LOC = P237; \r\n"
|
146 |
|
|
"NET \"seg2<5>\" LOC = P236; \r\n"
|
147 |
|
|
"NET \"seg2<6>\" LOC = P235; \r\n"
|
148 |
|
|
"NET \"seg2<7>\" LOC = P234;\r\n"
|
149 |
|
|
"\r\n"
|
150 |
|
|
);
|
151 |
|
|
}
|
152 |
|
|
//-----------------------------------------------------------------------------
|
153 |
|
|
void write_tail(FILE * out)
|
154 |
|
|
{
|
155 |
|
|
fprintf(out,
|
156 |
|
|
"\r\n"
|
157 |
|
|
"end mem_content;\r\n"
|
158 |
|
|
"\r\n"
|
159 |
|
|
"package body mem_content is\r\n"
|
160 |
|
|
"\r\n"
|
161 |
|
|
"end mem_content;\r\n"
|
162 |
|
|
"\r\n"
|
163 |
|
|
);
|
164 |
|
|
}
|
165 |
|
|
//-----------------------------------------------------------------------------
|
166 |
|
|
int main(int argc, char *argv[])
|
167 |
|
|
{
|
168 |
|
|
assert(argc == 2 && "No (binary) input file specified");
|
169 |
|
|
|
170 |
|
|
for (int i = 0; i < sizeof(data); i++) data[i] = 0;
|
171 |
|
|
|
172 |
|
|
FILE * in = fopen(argv[1], "rb");
|
173 |
|
|
if (in == 0)
|
174 |
|
|
{
|
175 |
|
|
fprintf(stderr, "Can't open input file %s\n", argv[1]);
|
176 |
|
|
return 1;
|
177 |
|
|
}
|
178 |
|
|
|
179 |
|
|
int bytes = fread(data, 1, sizeof(data), in);
|
180 |
|
|
fclose(in);
|
181 |
|
|
|
182 |
|
|
printf("Read %d bytes\n", bytes);
|
183 |
|
|
|
184 |
|
|
FILE * out = fopen("../vhdl/mem_content.vhd", "w");
|
185 |
|
|
assert(out);
|
186 |
|
|
|
187 |
|
|
FILE * ucf = fopen("../vhdl/board_cpu.ucf", "w");
|
188 |
|
|
assert(ucf);
|
189 |
|
|
|
190 |
|
|
write_header(out, ucf);
|
191 |
|
|
write_bank_1(out, ucf, 0, data);
|
192 |
|
|
write_bank_1(out, ucf, 1, data + 0x1000);
|
193 |
|
|
write_tail(out);
|
194 |
|
|
|
195 |
|
|
fclose(out);
|
196 |
|
|
fclose(ucf);
|
197 |
|
|
return 0;
|
198 |
|
|
}
|
199 |
|
|
//-----------------------------------------------------------------------------
|