OpenCores
URL https://opencores.org/ocsvn/t51/t51/trunk

Subversion Repositories t51

[/] [t51/] [trunk/] [sw/] [xrom.cpp] - Blame information for rev 25

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 13 jesus
//
2
// Xilinx VHDL ROM generator
3
//
4 24 jesus
// Version : 0241
5 13 jesus
//
6
// Copyright (c) 2001-2002 Daniel Wallner (jesus@opencores.org)
7
//
8
// All rights reserved
9
//
10
// Redistribution and use in source and binary forms, with or without
11
// modification, are permitted provided that the following conditions are met:
12
//
13
// Redistributions of source code must retain the above copyright notice,
14
// this list of conditions and the following disclaimer.
15
//
16
// Redistributions in binary form must reproduce the above copyright
17
// notice, this list of conditions and the following disclaimer in the
18
// documentation and/or other materials provided with the distribution.
19
//
20
// Neither the name of the author nor the names of other contributors may
21
// be used to endorse or promote products derived from this software without
22
// specific prior written permission.
23
//
24
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
26
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
28
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34
// POSSIBILITY OF SUCH DAMAGE.
35
//
36
// Please report bugs to the author, but before you do so, please
37
// make sure that this is not a derivative work and that
38
// you have the latest version of this file.
39
//
40
// The latest version of this file can be found at:
41
//      http://www.opencores.org/cvsweb.shtml/t51/
42
//
43
// Limitations :
44
//      Not all address/data widths produce working code
45
//      Requires stl to compile
46
//
47
// File history :
48
//
49
// 0220 : Initial release
50
//
51 14 jesus
// 0221 : Fixed block ROMs with partial bytes
52 24 jesus
//
53
// 0241 : Updated for WebPack 5.1
54 13 jesus
 
55
#include <stdio.h>
56
#include <string>
57
#include <vector>
58
#include <iostream>
59
 
60
using namespace std;
61
 
62
#if !(defined(max)) && _MSC_VER
63
        // VC fix
64
        #define max __max
65
#endif
66
 
67
int main (int argc, char *argv[])
68
{
69 24 jesus
        cerr << "Xilinx VHDL ROM generator by Daniel Wallner. Version 0241\n";
70 13 jesus
 
71
        try
72
        {
73
                unsigned long aWidth;
74
                unsigned long dWidth;
75
                unsigned long select = 0;
76
                char z = 0;
77
 
78
                if (argc < 4)
79
                {
80
                        cerr << "\nUsage: xrom <entity name> <address bits> <data bits> <options>\n";
81
                        cerr << "\nThe options can be:\n";
82 25 jesus
                        cerr << "  -[decimal number] = SelectRAM usage in 1/16 parts\n";
83 13 jesus
                        cerr << "  -z = use tri-state buses\n";
84
                        cerr << "\nExample:\n";
85
                        cerr << "  xrom Test_ROM 13 8 -6\n\n";
86
                        return -1;
87
                }
88
 
89
                int result;
90
 
91
                result = sscanf(argv[2], "%lu", &aWidth);
92
                if (result < 1)
93
                {
94
                        throw "Error in address bits argument!\n";
95
                }
96
 
97
                result = sscanf(argv[3], "%lu", &dWidth);
98
                if (result < 1)
99
                {
100
                        throw "Error in data bits argument!\n";
101
                }
102
 
103
                if (argc > 4)
104
                {
105
                        result = sscanf(argv[4], "%c%lu", &z, &select);
106
                        if (result < 1 || z != '-')
107
                        {
108
                                throw "Error in options!\n";
109
                        }
110
                        if (result < 2)
111
                        {
112
                                sscanf(argv[4], "%c%c", &z, &z);
113
                                if (z != 'z')
114
                                {
115
                                        throw "Error in options!\n";
116
                                }
117
                        }
118
                }
119
 
120
                if (argc > 5)
121
                {
122
                        result = sscanf(argv[5], "%c%lu", &z, &select);
123
                        if (result < 1 || z != '-')
124
                        {
125
                                throw "Error in options!\n";
126
                        }
127
                        if (result < 2)
128
                        {
129
                                sscanf(argv[5], "%c%c", &z, &z);
130
                                if (z != 'z')
131
                                {
132
                                        throw "Error in options!\n";
133
                                }
134
                        }
135
                }
136
 
137
                unsigned long selectIter = 0;
138
                unsigned long blockIter = 0;
139
                unsigned long bytes = (dWidth + 7) / 8;
140
 
141
                if (!select)
142
                {
143
                        blockIter = ((1UL << aWidth) + 511) / 512;
144
                }
145
                else if (select == 16)
146
                {
147
                        selectIter = ((1UL << aWidth) + 15) / 16;
148
                }
149
                else
150
                {
151
                        blockIter = ((1UL << aWidth) * (16 - select) / 16 + 511) / 512;
152
                        selectIter = ((1UL << aWidth) - blockIter * 512 + 15) / 16;
153
                }
154
 
155
                unsigned long blockTotal = ((1UL << aWidth) + 511) / 512;
156
 
157
                printf("-- This file was generated with xrom written by Daniel Wallner\n");
158
                printf("\nlibrary IEEE;");
159
                printf("\nuse IEEE.std_logic_1164.all;");
160
                printf("\nuse IEEE.numeric_std.all;");
161
                printf("\nlibrary UNISIM;");
162
                printf("\nuse UNISIM.vcomponents.all;");
163
                printf("\n\nentity %s is", argv[1]);
164
                printf("\n\tport(");
165
                printf("\n\t\tClk\t: in std_logic;");
166
                printf("\n\t\tA\t: in std_logic_vector(%d downto 0);", aWidth - 1);
167
                printf("\n\t\tD\t: out std_logic_vector(%d downto 0)", dWidth - 1);
168
                printf("\n\t);");
169
                printf("\nend %s;", argv[1]);
170
                printf("\n\narchitecture rtl of %s is", argv[1]);
171
 
172
                if (selectIter > 0)
173
                {
174
                        printf("\n\tsignal A_r: unsigned(A'range);");
175
                }
176
                if (selectIter > 1)
177
                {
178
                        printf("\n\ttype sRAMOut_a is array(0 to %d) of std_logic_vector(D'range);", selectIter - 1);
179
                        printf("\n\tsignal sRAMOut : sRAMOut_a;");
180
                        printf("\n\tsignal siA_r : integer;");
181
                }
182
                if (selectIter && blockIter)
183
                {
184
                        printf("\n\tsignal sD : std_logic_vector(D'range);");
185
                }
186 14 jesus
                if (blockIter == 1)
187
                {
188
                        printf("\n\tsignal bRAMOut : std_logic_vector(%d downto 0);", bytes * 8 - 1);
189
                }
190 13 jesus
                if (blockIter > 1)
191
                {
192 14 jesus
                        printf("\n\ttype bRAMOut_a is array(%d to %d) of std_logic_vector(%d downto 0);", blockTotal - blockIter, blockTotal - 1, bytes * 8 - 1);
193 13 jesus
                        printf("\n\tsignal bRAMOut : bRAMOut_a;");
194
                        printf("\n\tsignal biA_r : integer;");
195
                        if (!selectIter)
196
                        {
197
                                printf("\n\tsignal A_r : unsigned(A'left downto 9);");
198
                        }
199
                }
200
                if (selectIter && blockIter)
201
                {
202
                        printf("\n\tsignal bD : std_logic_vector(D'range);");
203
                }
204
 
205
                printf("\nbegin");
206
 
207
                if (selectIter > 0 || blockIter > 1)
208
                {
209
                        printf("\n\tprocess (Clk)");
210
                        printf("\n\tbegin");
211
                        printf("\n\t\tif Clk'event and Clk = '1' then");
212
                        if (!selectIter)
213
                        {
214
                                printf("\n\t\t\tA_r <= unsigned(A(A'left downto 9));");
215
                        }
216
                        else
217
                        {
218
                                printf("\n\t\t\tA_r <= unsigned(A);");
219
                        }
220
                        printf("\n\t\tend if;");
221
                        printf("\n\tend process;");
222
                }
223
 
224
                if (selectIter == 1)
225
                {
226
                        printf("\n\n\tsG1: for I in 0 to %d generate", dWidth - 1);
227
                        printf("\n\t\tS%s : LUT4\n\t\t\tport map (", argv[1]);
228
                        if (blockIter)
229
                        {
230
                                printf("s");
231
                        }
232 24 jesus
                        printf("WE => '0', WCLK => '0', D => '0', O => D(I), A0 => A_r(0), A1 => A_r(1), A2 => A_r(2), A3 => A_r(3));");
233 13 jesus
                        printf("\n\tend generate;");
234
                }
235
                if (selectIter > 1)
236
                {
237
                        printf("\n\n\tsiA_r <= to_integer(A_r(A'left downto 4));");
238
                        printf("\n\n\tsG1: for I in 0 to %d generate", selectIter - 1);
239
                        printf("\n\t\tsG2: for J in 0 to %d generate", dWidth - 1);
240 24 jesus
                        printf("\n\t\t\tS%s : RAM16X1S\n\t\t\t\tport map (WE => '0', WCLK => '0', D => '0', O => sRAMOut(I)(J), A0 => A_r(0), A1 => A_r(1), A2 => A_r(2), A3 => A_r(3));", argv[1]);
241 13 jesus
                        printf("\n\t\tend generate;");
242
                        if (z == 'z')
243
                        {
244
                                printf("\n\t\t");
245
                                if (blockIter)
246
                                {
247
                                        printf("s");
248
                                }
249
                                printf("D <= sRAMOut(I) when siA_r = I else (others => 'Z');");
250
                        }
251
                        printf("\n\tend generate;");
252
                        if (z != 'z')
253
                        {
254
                                printf("\n\n\tprocess (siA_r, sRAMOut)\n\tbegin\n\t\t");
255
                                if (blockIter)
256
                                {
257
                                        printf("s");
258
                                }
259
                                printf("D <= sRAMOut(0);");
260
                                printf("\n\t\tfor I in 1 to %d loop", selectIter - 1);
261
                                printf("\n\t\t\tif siA_r = I then\n\t\t\t\t");
262
                                if (blockIter)
263
                                {
264
                                        printf("s");
265
                                }
266
                                printf("D <= sRAMOut(I);\n\t\t\tend if;");
267
                                printf("\n\t\tend loop;\n\tend process;");
268
                        }
269
                }
270
 
271
                if (blockIter == 1)
272
                {
273
                        printf("\n\n\tbG1: for J in 0 to %d generate", bytes - 1);
274 14 jesus
                        printf("\n\t\tB%s : RAMB4_S8", argv[1]);
275 24 jesus
                        printf("\n\t\t\tport map (DI => \"00000000\", EN => '1', RST => '0', WE => '0', CLK => Clk, ADDR => A(8 downto 0), DO => bRAMOut(7 + 8 * J downto 8 * J));", argv[1]);
276 14 jesus
                        printf("\n\tend generate;");
277
                        printf("\n\n\t");
278 13 jesus
                        if (selectIter)
279
                        {
280
                                printf("b");
281
                        }
282 14 jesus
                        printf("D <= bRAMOut(D'range);");
283 13 jesus
                }
284
                if (blockIter > 1)
285
                {
286
                        printf("\n\n\tbiA_r <= to_integer(A_r(A'left downto 9));");
287
                        printf("\n\n\tbG1: for I in %d to %d generate", blockTotal - blockIter, blockTotal - 1);
288
                        printf("\n\t\tbG2: for J in 0 to %d generate", bytes - 1);
289 24 jesus
                        printf("\n\t\t\tB%s : RAMB4_S8\n\t\t\t\tport map (DI => \"00000000\", EN => '1', RST => '0', WE => '0', CLK => Clk, ADDR => A(8 downto 0), DO => bRAMOut(I)(7 + 8 * J downto 8 * J));", argv[1]);
290 13 jesus
                        printf("\n\t\tend generate;");
291
                        if (z == 'z')
292
                        {
293
                                printf("\n\t\t");
294
                                if (selectIter)
295
                                {
296
                                        printf("b");
297
                                }
298
                                printf("D <= bRAMOut(I) when biA_r = I else (others => 'Z');");
299
                        }
300
                        printf("\n\tend generate;");
301
                        if (z != 'z')
302
                        {
303
                                printf("\n\n\tprocess (biA_r, bRAMOut)\n\tbegin\n\t\t");
304
                                if (selectIter)
305
                                {
306
                                        printf("b");
307
                                }
308 14 jesus
                                printf("D <= bRAMOut(%d)(D'range);", blockTotal - blockIter);
309 13 jesus
                                printf("\n\t\tfor I in %d to %d loop", blockTotal - blockIter + 1, blockTotal - 1);
310
                                printf("\n\t\t\tif biA_r = I then\n\t\t\t\t");
311
                                if (selectIter)
312
                                {
313
                                        printf("b");
314
                                }
315 14 jesus
                                printf("D <= bRAMOut(I)(D'range);\n\t\t\tend if;");
316 13 jesus
                                printf("\n\t\tend loop;\n\tend process;");
317
                        }
318
                }
319
 
320
                if (selectIter && blockIter)
321
                {
322
                        printf("\n\n\tD <= bD when A_r(A'left downto 9) >= %d else sD;", blockTotal - blockIter);
323
                }
324
 
325
                printf("\nend;\n");
326
 
327
                return 0;
328
        }
329
        catch (string error)
330
        {
331
                cerr << "Fatal: " << error;
332
        }
333
        catch (const char *error)
334
        {
335
                cerr << "Fatal: " << error;
336
        }
337
        return -1;
338
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.