1 |
6 |
olupas |
--===================================================================--
|
2 |
|
|
--
|
3 |
|
|
-- www.OpenCores.Org - June 2000
|
4 |
|
|
-- This model adheres to the GNU public license
|
5 |
|
|
--
|
6 |
|
|
-- Design units : Functions and procedures used in models
|
7 |
|
|
--
|
8 |
|
|
-- File name : PCI_LIB.vhd
|
9 |
|
|
--
|
10 |
|
|
-- Purpose : type conversion functions, read commands file
|
11 |
|
|
-- procedures
|
12 |
|
|
--
|
13 |
|
|
-- Limitations : None known
|
14 |
|
|
--
|
15 |
|
|
-- Errors : None known
|
16 |
|
|
--
|
17 |
|
|
-- Library : PCI_Lib.vhd
|
18 |
|
|
--
|
19 |
|
|
-- Dependencies : IEEE.Std_Logic_1164
|
20 |
|
|
--
|
21 |
|
|
-- Author : Ovidiu Lupas
|
22 |
|
|
-- olupas@opencores.org
|
23 |
|
|
--
|
24 |
|
|
-- Simulator : ModelSim EE version 5.2 on a Windows95 PC
|
25 |
|
|
-- ActiveVHDL 3.1 on a Windows95 PC
|
26 |
|
|
--===================================================================--
|
27 |
|
|
-----------------------------------------------------------------------
|
28 |
|
|
-- Revision list
|
29 |
|
|
-- Version Author Date Changes
|
30 |
|
|
--
|
31 |
|
|
-- 0.1 Ovidiu Lupas June 09, 2000 New model
|
32 |
|
|
-----------------------------------------------------------------------
|
33 |
|
|
library IEEE;
|
34 |
|
|
use IEEE.Std_Logic_1164.all;
|
35 |
|
|
--
|
36 |
|
|
package Simulation is
|
37 |
|
|
-- Definition of the CommandType record array which is used to record
|
38 |
|
|
-- the commands from the .cmd file
|
39 |
|
|
type Data_buffer is array(1 to 256) of Std_Logic_Vector(31 downto 0);
|
40 |
|
|
type Data_Enable is array(1 to 256) of Std_Logic_Vector(3 downto 0);
|
41 |
|
|
|
42 |
|
|
type CommandType is
|
43 |
|
|
record
|
44 |
|
|
command : string(1 to 4);
|
45 |
|
|
addr : Std_Logic_Vector(31 downto 0);
|
46 |
|
|
data : Data_buffer;
|
47 |
|
|
data_nr : Integer;
|
48 |
|
|
enable : Data_Enable;
|
49 |
|
|
end record;
|
50 |
|
|
-- Definition of the CommandArray type type which can be used for
|
51 |
|
|
-- the commands present in .cmd file
|
52 |
|
|
type CommandArray is array(positive range <>) of CommandType;
|
53 |
|
|
end Simulation; --========== End of package Simulation =============--
|
54 |
|
|
--
|
55 |
|
|
library IEEE,STD,work;
|
56 |
|
|
library work;
|
57 |
|
|
use work.Simulation.all;
|
58 |
|
|
use IEEE.Std_Logic_1164.all;
|
59 |
|
|
use STD.textio.all;
|
60 |
|
|
--
|
61 |
|
|
package PCI_Def is
|
62 |
|
|
--------------------------------------------------------------------
|
63 |
|
|
-- convert a character to a value from 0 to 15
|
64 |
|
|
--------------------------------------------------------------------
|
65 |
|
|
function digit_value(
|
66 |
|
|
C : Character)
|
67 |
|
|
return integer;
|
68 |
|
|
--------------------------------------------------------------------
|
69 |
|
|
-- Converts unsigned Std_LOGIC_Vector to Integer, leftmost bit is MSB
|
70 |
|
|
-- Error message for unknowns (U, X, W, Z, -), converted to 0
|
71 |
|
|
-- Verifies whether vector is too long (> 16 bits)
|
72 |
|
|
--------------------------------------------------------------------
|
73 |
|
|
function Vec2Int (
|
74 |
|
|
Invector : in Std_Logic_Vector(15 downto 0))
|
75 |
|
|
return Integer;
|
76 |
|
|
--------------------------------------------------------------------
|
77 |
|
|
-- Converts unsigned Std_Logic_Vector to Integer, leftmost bit is MSB
|
78 |
|
|
-- Error message for unknowns (U, X, W, Z, -), converted to 0
|
79 |
|
|
-- Verifies whether vector is too long (> 16 bits)
|
80 |
|
|
--------------------------------------------------------------------
|
81 |
|
|
function Byte2Int (
|
82 |
|
|
Invector : in Std_Logic_Vector(7 downto 0))
|
83 |
|
|
return Integer;
|
84 |
|
|
--------------------------------------------------------------------
|
85 |
|
|
-- Converts unsigned Std_Logic_Vector to Integer, leftmost bit is MSB
|
86 |
|
|
-- Error message for unknowns (U, X, W, Z, -), converted to 0
|
87 |
|
|
-- Verifies whether vector is too long (> 16 bits)
|
88 |
|
|
--------------------------------------------------------------------
|
89 |
|
|
procedure Hex2Bit (
|
90 |
|
|
C : in Character;
|
91 |
|
|
Vector : out Std_Logic_Vector(3 downto 0);
|
92 |
|
|
Good : out Boolean);
|
93 |
|
|
--------------------------------------------------------------------
|
94 |
|
|
-- Converts Hex characters to binary representation
|
95 |
|
|
-- Asserts that no unknown value exists at the time of conversion.
|
96 |
|
|
--------------------------------------------------------------------
|
97 |
|
|
procedure Bit2Hex (
|
98 |
|
|
Vector : in Std_Logic_Vector(3 downto 0);
|
99 |
|
|
C : out Character;
|
100 |
|
|
Good : out Boolean);
|
101 |
|
|
--------------------------------------------------------------------
|
102 |
|
|
-- Converts bit_vector into a hex string
|
103 |
|
|
-- Asserts that no unknown value exists at the time of conversion.
|
104 |
|
|
--------------------------------------------------------------------
|
105 |
|
|
procedure Vec2Hex (
|
106 |
|
|
Value : in Std_Logic_Vector(31 downto 0);
|
107 |
|
|
result : out String(1 to 8);
|
108 |
|
|
Good : out Boolean);
|
109 |
|
|
--------------------------------------------------------------------
|
110 |
|
|
-- read a number from the line
|
111 |
|
|
-- use this if you have hex numbers that are not in VHDL pound-sign format
|
112 |
|
|
--------------------------------------------------------------------
|
113 |
|
|
procedure Read (
|
114 |
|
|
L : inout Line;
|
115 |
|
|
value : out Integer;
|
116 |
|
|
radix : in Positive);
|
117 |
|
|
--------------------------------------------------------------------
|
118 |
|
|
-- reads a hex value and returns a bit_vector value
|
119 |
|
|
--------------------------------------------------------------------
|
120 |
|
|
procedure ReadHex (
|
121 |
|
|
L : inout Line;
|
122 |
|
|
Value : out Std_Logic_Vector;
|
123 |
|
|
Good : out Boolean;
|
124 |
|
|
Enable: out Std_Logic_Vector);
|
125 |
|
|
--------------------------------------------------------------------
|
126 |
|
|
-- Implements the parsing of the cmd file, which specifies the tasks
|
127 |
|
|
-- that are applied to the processor.
|
128 |
|
|
--------------------------------------------------------------------
|
129 |
|
|
procedure FileParser (
|
130 |
|
|
constant file_name : in String;
|
131 |
|
|
variable Commands : inout CommandArray;
|
132 |
|
|
variable NumCommands : out Natural;
|
133 |
|
|
variable ErrFlag : inout Boolean);
|
134 |
|
|
end PCI_Def; --============== End of package header =================--
|
135 |
|
|
--
|
136 |
|
|
library IEEE;
|
137 |
|
|
use IEEE.Std_Logic_1164.all;
|
138 |
|
|
library std;
|
139 |
|
|
use std.textio.all;
|
140 |
|
|
--
|
141 |
|
|
package body PCI_Def is
|
142 |
|
|
--------------------------------------------------------------------
|
143 |
|
|
-- convert a character to a value from 0 to 15
|
144 |
|
|
--------------------------------------------------------------------
|
145 |
|
|
function digit_value (
|
146 |
|
|
C : Character)
|
147 |
|
|
return integer is
|
148 |
|
|
constant not_digit : integer := -999;
|
149 |
|
|
begin
|
150 |
|
|
if (C ='X') and (C ='x') then
|
151 |
|
|
return 15;
|
152 |
|
|
end if;
|
153 |
|
|
if (C >= '0') and (C <= '9') then
|
154 |
|
|
return (Character'pos(C) - Character'pos('0'));
|
155 |
|
|
elsif (C >= 'a') and (C <= 'f') then
|
156 |
|
|
return (character'pos(c) - character'pos('a') + 10);
|
157 |
|
|
elsif (C >= 'A') and (C <= 'F') then
|
158 |
|
|
return (character'pos(c) - character'pos('A') + 10);
|
159 |
|
|
else
|
160 |
|
|
return not_digit;
|
161 |
|
|
end if;
|
162 |
|
|
end digit_value;
|
163 |
|
|
--------------------------------------------------------------------
|
164 |
|
|
--------------------------------------------------------------------
|
165 |
|
|
function Vec2Int (
|
166 |
|
|
InVector : in Std_Logic_Vector(15 downto 0))
|
167 |
|
|
return Integer is
|
168 |
|
|
constant HeaderMsg : String := "To_Integer:";
|
169 |
|
|
constant MsgSeverity : Severity_Level := Warning;
|
170 |
|
|
variable Value : Integer := 0;
|
171 |
|
|
begin
|
172 |
|
|
if InVector = "UUUUUUUUUUUUUUUU" then
|
173 |
|
|
report HeaderMsg&"The input vector is of type 'U'. Converted to 0"
|
174 |
|
|
severity MsgSeverity;
|
175 |
|
|
elsif InVector = "XXXXXXXXXXXXXXXX" then
|
176 |
|
|
report HeaderMsg&"The input vector is of type 'X'. Converted to 0"
|
177 |
|
|
severity MsgSeverity;
|
178 |
|
|
elsif InVector = "WWWWWWWWWWWWWWWW" then
|
179 |
|
|
report HeaderMsg&"The input vector is of type 'W'. Converted to 0"
|
180 |
|
|
severity MsgSeverity;
|
181 |
|
|
elsif InVector = "ZZZZZZZZZZZZZZZZ" then
|
182 |
|
|
report HeaderMsg&"The input vector is of type 'Z'. Converted to 0"
|
183 |
|
|
severity MsgSeverity;
|
184 |
|
|
else
|
185 |
|
|
for i in 0 to 15 loop
|
186 |
|
|
if (InVector(i) = '1') then
|
187 |
|
|
Value := Value + (2**I);
|
188 |
|
|
end if;
|
189 |
|
|
end loop;
|
190 |
|
|
end if;
|
191 |
|
|
return Value;
|
192 |
|
|
end Vec2Int;
|
193 |
|
|
--------------------------------------------------------------------
|
194 |
|
|
--------------------------------------------------------------------
|
195 |
|
|
function Byte2Int (
|
196 |
|
|
InVector : in Std_Logic_Vector(7 downto 0))
|
197 |
|
|
return Integer is
|
198 |
|
|
constant HeaderMsg : String := "To_Integer:";
|
199 |
|
|
constant MsgSeverity : Severity_Level := Warning;
|
200 |
|
|
variable Value : Integer := 0;
|
201 |
|
|
begin
|
202 |
|
|
for i in 0 to 7 loop
|
203 |
|
|
if (InVector(i) = '1') then
|
204 |
|
|
Value := Value + (2**I);
|
205 |
|
|
end if;
|
206 |
|
|
end loop;
|
207 |
|
|
return Value;
|
208 |
|
|
end Byte2Int;
|
209 |
|
|
--------------------------------------------------------------------
|
210 |
|
|
--------------------------------------------------------------------
|
211 |
|
|
procedure Hex2Bit (
|
212 |
|
|
C : in Character;
|
213 |
|
|
Vector : out Std_Logic_Vector(3 downto 0);
|
214 |
|
|
Good : out Boolean) is
|
215 |
|
|
variable Good1 : Boolean := false;
|
216 |
|
|
constant HeaderMsg : String := "Hex2Bit:";
|
217 |
|
|
constant MsgSeverity : Severity_Level := Error;
|
218 |
|
|
begin
|
219 |
|
|
Good := false;
|
220 |
|
|
case C is
|
221 |
|
|
when '0' => Vector := "0000"; Good1 := true;
|
222 |
|
|
when '1' => Vector := "0001"; Good1 := true;
|
223 |
|
|
when '2' => Vector := "0010"; Good1 := true;
|
224 |
|
|
when '3' => Vector := "0011"; Good1 := true;
|
225 |
|
|
when '4' => Vector := "0100"; Good1 := true;
|
226 |
|
|
when '5' => Vector := "0101"; Good1 := true;
|
227 |
|
|
when '6' => Vector := "0110"; Good1 := true;
|
228 |
|
|
when '7' => Vector := "0111"; Good1 := true;
|
229 |
|
|
when '8' => Vector := "1000"; Good1 := true;
|
230 |
|
|
when '9' => Vector := "1001"; Good1 := true;
|
231 |
|
|
when 'A'|'a' => Vector := "1010"; Good1 := true;
|
232 |
|
|
when 'B'|'b' => Vector := "1011"; Good1 := true;
|
233 |
|
|
when 'C'|'c' => Vector := "1100"; Good1 := true;
|
234 |
|
|
when 'D'|'d' => Vector := "1101"; Good1 := true;
|
235 |
|
|
when 'E'|'e' => Vector := "1110"; Good1 := true;
|
236 |
|
|
when 'F'|'f' => Vector := "1111"; Good1 := true;
|
237 |
|
|
-- extended for std_LOGIC --
|
238 |
|
|
when 'U'|'u' => Vector := "UUUU"; Good1 := true;
|
239 |
|
|
when 'X'|'x' => Vector := "1111"; Good1 := true;
|
240 |
|
|
when 'Z'|'z' => Vector := "ZZZZ"; Good1 := true;
|
241 |
|
|
when 'W'|'w' => Vector := "WWWW"; Good1 := true;
|
242 |
|
|
when 'L'|'l' => Vector := "LLLL"; Good1 := true;
|
243 |
|
|
when 'H'|'h' => Vector := "HHHH"; Good1 := true;
|
244 |
|
|
when '-' => Vector := "----"; Good1 := true;
|
245 |
|
|
when others => Good1 := false;
|
246 |
|
|
end case;
|
247 |
|
|
if not Good1 then
|
248 |
|
|
Vector := "0000";
|
249 |
|
|
report HeaderMsg&"Expected a Hex character (0-F)"
|
250 |
|
|
severity MsgSeverity;
|
251 |
|
|
end if;
|
252 |
|
|
Good := Good1;
|
253 |
|
|
end Hex2Bit;
|
254 |
|
|
--------------------------------------------------------------------
|
255 |
|
|
--------------------------------------------------------------------
|
256 |
|
|
procedure Bit2Hex (
|
257 |
|
|
Vector : Std_Logic_Vector(3 downto 0);
|
258 |
|
|
C : out Character;
|
259 |
|
|
Good : out Boolean) is
|
260 |
|
|
variable Good1 : Boolean := false;
|
261 |
|
|
constant HeaderMsg : String := "Bit2Hex: ";
|
262 |
|
|
constant MsgSeverity : Severity_Level := Error;
|
263 |
|
|
begin
|
264 |
|
|
Good := false;
|
265 |
|
|
case Vector is
|
266 |
|
|
when x"0" => C := '0'; Good1 := true;
|
267 |
|
|
when x"1" => C := '1'; Good1 := true;
|
268 |
|
|
when x"2" => C := '2'; Good1 := true;
|
269 |
|
|
when x"3" => C := '3'; Good1 := true;
|
270 |
|
|
when x"4" => C := '4'; Good1 := true;
|
271 |
|
|
when x"5" => C := '5'; Good1 := true;
|
272 |
|
|
when x"6" => C := '6'; Good1 := true;
|
273 |
|
|
when x"7" => C := '7'; Good1 := true;
|
274 |
|
|
when x"8" => C := '8'; Good1 := true;
|
275 |
|
|
when x"9" => C := '9'; Good1 := true;
|
276 |
|
|
when x"A" => C := 'A'; Good1 := true;
|
277 |
|
|
when x"B" => C := 'B'; Good1 := true;
|
278 |
|
|
when x"C" => C := 'C'; Good1 := true;
|
279 |
|
|
when x"D" => C := 'D'; Good1 := true;
|
280 |
|
|
when x"E" => C := 'E'; Good1 := true;
|
281 |
|
|
when x"F" => C := 'F'; Good1 := true;
|
282 |
|
|
when "ZZZZ" => C := 'Z'; Good1 := true;
|
283 |
|
|
when others => Good1 := false;
|
284 |
|
|
end case;
|
285 |
|
|
if not Good1 then
|
286 |
|
|
C := '0';
|
287 |
|
|
report HeaderMsg&"Expected a Hex character (0-F)"
|
288 |
|
|
severity MsgSeverity;
|
289 |
|
|
end if;
|
290 |
|
|
Good := Good1;
|
291 |
|
|
end Bit2Hex;
|
292 |
|
|
--------------------------------------------------------------------
|
293 |
|
|
--------------------------------------------------------------------
|
294 |
|
|
procedure Vec2Hex (
|
295 |
|
|
Value : in Std_Logic_Vector(31 downto 0);
|
296 |
|
|
Result : out String(1 to 8);
|
297 |
|
|
GOOD : out BOOLEAN) is
|
298 |
|
|
variable OK : Boolean;
|
299 |
|
|
variable C : Character;
|
300 |
|
|
constant NE : Integer := value'length/4; -- number of Hex chars
|
301 |
|
|
variable BV : Std_Logic_Vector(value'length-1 downto 0) := Value;
|
302 |
|
|
variable Res : String(1 to 8);
|
303 |
|
|
constant HeaderMsg : String := "Vec2Hex: ";
|
304 |
|
|
constant MsgSeverity : Severity_Level := Error;
|
305 |
|
|
begin
|
306 |
|
|
if Value'length mod 4 /= 0 then -- Testing if Vector is mod 4
|
307 |
|
|
Good := false;
|
308 |
|
|
report HeaderMsg&"The length of input vector is not modulo 4!"
|
309 |
|
|
severity MsgSeverity;
|
310 |
|
|
return;
|
311 |
|
|
end if;
|
312 |
|
|
Bit2Hex(BV(3 downto 0), C, OK); -- Conversion of the 4 LSB bits
|
313 |
|
|
if not OK then
|
314 |
|
|
Good := false;
|
315 |
|
|
return;
|
316 |
|
|
end if;
|
317 |
|
|
Res := C & Res(2 to NE); -- Places first Char in Result
|
318 |
|
|
for i in 1 to NE-1 loop
|
319 |
|
|
Bit2Hex(BV(4*i+3 downto 4*i), C, OK); -- Converts next Char
|
320 |
|
|
if not OK then
|
321 |
|
|
Good := false;
|
322 |
|
|
return;
|
323 |
|
|
end if;
|
324 |
|
|
Res := Res(1 to i) & C & Res(i+2 to NE);
|
325 |
|
|
end loop;
|
326 |
|
|
for i in 0 to NE-1 loop
|
327 |
|
|
Result (1+i) := Res (NE-i);
|
328 |
|
|
end loop;
|
329 |
|
|
Good := true;
|
330 |
|
|
end Vec2Hex;
|
331 |
|
|
--------------------------------------------------------------------
|
332 |
|
|
--------------------------------------------------------------------
|
333 |
|
|
procedure Read (
|
334 |
|
|
L : inout line;
|
335 |
|
|
Value : out integer;
|
336 |
|
|
Radix : in positive) is
|
337 |
|
|
constant not_digit : integer := -999;
|
338 |
|
|
variable Digit : integer;
|
339 |
|
|
variable Result : integer := 0;
|
340 |
|
|
variable Pos : integer;
|
341 |
|
|
begin
|
342 |
|
|
-- calculate the value
|
343 |
|
|
if (L'length <=0 ) then
|
344 |
|
|
for i in Pos to L'right loop
|
345 |
|
|
digit := digit_value(L(i));
|
346 |
|
|
exit when (Digit = not_digit) or (digit >= radix);
|
347 |
|
|
Result := Result * Radix + digit;
|
348 |
|
|
Pos := Pos + 1;
|
349 |
|
|
end loop;
|
350 |
|
|
Value := Result;
|
351 |
|
|
end if;
|
352 |
|
|
end Read;
|
353 |
|
|
--------------------------------------------------------------------
|
354 |
|
|
--------------------------------------------------------------------
|
355 |
|
|
procedure ReadHex (
|
356 |
|
|
L : inout Line;
|
357 |
|
|
Value : out Std_Logic_Vector;
|
358 |
|
|
Good : out Boolean;
|
359 |
|
|
Enable : out Std_Logic_Vector) is
|
360 |
|
|
variable OK : Boolean;
|
361 |
|
|
variable C : Character;
|
362 |
|
|
constant NE : Integer := value'length/4;
|
363 |
|
|
variable BV : Std_Logic_Vector(value'length-1 downto 0);
|
364 |
|
|
variable TEMP : Std_Logic_Vector(value'length-1 downto 0);
|
365 |
|
|
variable S : String(1 to NE-1);
|
366 |
|
|
constant HeaderMsg : String := "Vec2Hex";
|
367 |
|
|
constant MsgSeverity : Severity_Level := Warning;
|
368 |
|
|
begin
|
369 |
|
|
Enable(3 downto 0) :="0000";
|
370 |
|
|
if Value'length mod 4 /= 0 then -- Testing if Vector is mod 4
|
371 |
|
|
Good := false;
|
372 |
|
|
report HeaderMsg&"The length of input vector is not modulo 4!"
|
373 |
|
|
severity MsgSeverity;
|
374 |
|
|
return;
|
375 |
|
|
end if;
|
376 |
|
|
loop
|
377 |
|
|
read(L, C, OK); -- Finds the first Hex Char
|
378 |
|
|
exit when (((C /= ' ') and (C /= CR) and (C /= HT)) or
|
379 |
|
|
(L'length = 0));
|
380 |
|
|
end loop;
|
381 |
|
|
Hex2Bit(C, BV( 3 downto 0), OK); -- Converts first Hex Char to 4 Bits
|
382 |
|
|
if C ='X' or C ='x' then
|
383 |
|
|
Enable(3) :='1';
|
384 |
|
|
end if;
|
385 |
|
|
|
386 |
|
|
if not OK then
|
387 |
|
|
Good := false;
|
388 |
|
|
return;
|
389 |
|
|
end if;
|
390 |
|
|
read(L, S, OK); -- Reads the next three Hex Chars
|
391 |
|
|
if not OK then
|
392 |
|
|
Good := false;
|
393 |
|
|
return;
|
394 |
|
|
end if;
|
395 |
|
|
for i in 1 to NE-1 loop
|
396 |
|
|
if s(i) ='X' or s(i) ='x' then
|
397 |
|
|
if i=1 then
|
398 |
|
|
Enable(3):='1';
|
399 |
|
|
end if;
|
400 |
|
|
if i=2 or i=3 then
|
401 |
|
|
Enable(2):='1';
|
402 |
|
|
end if;
|
403 |
|
|
if i=4 or i=5 then
|
404 |
|
|
Enable(1):='1';
|
405 |
|
|
end if;
|
406 |
|
|
if i=6 or i=7 then
|
407 |
|
|
Enable(0):='1';
|
408 |
|
|
end if;
|
409 |
|
|
end if;
|
410 |
|
|
Hex2Bit(s(i), BV(4*i+3 downto 4*i), OK); -- Converts to BitVector
|
411 |
|
|
if not OK then
|
412 |
|
|
Good := false;
|
413 |
|
|
return;
|
414 |
|
|
end if;
|
415 |
|
|
end loop;
|
416 |
|
|
Good := true;
|
417 |
|
|
|
418 |
|
|
-- for byte
|
419 |
|
|
if (value'length = 8 ) then
|
420 |
|
|
for i in 0 to 3 loop
|
421 |
|
|
TEMP(i) := BV(value'length-4+i);
|
422 |
|
|
end loop;
|
423 |
|
|
for i in 0 to 3 loop
|
424 |
|
|
TEMP(i+4) := BV(value'length-8+i);
|
425 |
|
|
end loop;
|
426 |
|
|
end if;
|
427 |
|
|
|
428 |
|
|
-- for word
|
429 |
|
|
if (value'length = 16 ) then
|
430 |
|
|
for i in 0 to 3 loop
|
431 |
|
|
TEMP(i) := BV(value'length-4+i);
|
432 |
|
|
end loop;
|
433 |
|
|
for i in 0 to 3 loop
|
434 |
|
|
TEMP(i+4) := BV(value'length-8+i);
|
435 |
|
|
end loop;
|
436 |
|
|
for i in 0 to 3 loop
|
437 |
|
|
TEMP(i+8) := BV(value'length-12+i);
|
438 |
|
|
end loop;
|
439 |
|
|
for i in 0 to 3 loop
|
440 |
|
|
TEMP(i+12) := BV(value'length-16+i);
|
441 |
|
|
end loop;
|
442 |
|
|
end if;
|
443 |
|
|
|
444 |
|
|
-- for DWORD
|
445 |
|
|
if (value'length =32 ) then
|
446 |
|
|
for i in 0 to 3 loop
|
447 |
|
|
TEMP(i) := BV(value'length-4+i);
|
448 |
|
|
end loop;
|
449 |
|
|
for i in 0 to 3 loop
|
450 |
|
|
TEMP(i+4) := BV(value'length-8+i);
|
451 |
|
|
end loop;
|
452 |
|
|
for i in 0 to 3 loop
|
453 |
|
|
TEMP(i+8) := BV(value'length-12+i);
|
454 |
|
|
end loop;
|
455 |
|
|
for i in 0 to 3 loop
|
456 |
|
|
TEMP(i+12) := BV(value'length-16+i);
|
457 |
|
|
end loop;
|
458 |
|
|
for i in 0 to 3 loop
|
459 |
|
|
TEMP(i+16) := BV(value'length-20+i);
|
460 |
|
|
end loop;
|
461 |
|
|
for i in 0 to 3 loop
|
462 |
|
|
TEMP(i+20) := BV(value'length-24+i);
|
463 |
|
|
end loop;
|
464 |
|
|
for i in 0 to 3 loop
|
465 |
|
|
TEMP(i+24) := BV(value'length-28+i);
|
466 |
|
|
end loop;
|
467 |
|
|
for i in 0 to 3 loop
|
468 |
|
|
TEMP(i+28) := BV(value'length-32+i);
|
469 |
|
|
end loop;
|
470 |
|
|
end if;
|
471 |
|
|
|
472 |
|
|
Value := TEMP;
|
473 |
|
|
end ReadHex;
|
474 |
|
|
--------------------------------------------------------------------
|
475 |
|
|
--------------------------------------------------------------------
|
476 |
|
|
procedure FileParser (
|
477 |
|
|
constant file_name : in String ;
|
478 |
|
|
variable Commands : inout CommandArray;
|
479 |
|
|
variable NumCommands : out Natural;
|
480 |
|
|
variable ErrFlag : inout Boolean) is
|
481 |
|
|
File CmdFile : text;
|
482 |
|
|
constant HeaderMsg : String := "FileParser:";
|
483 |
|
|
constant MsgSeverity : Severity_Level := Error;
|
484 |
|
|
variable L : Line := NULL;
|
485 |
|
|
variable Linenum : Natural := 0;
|
486 |
|
|
variable LblNum : Natural := 0;
|
487 |
|
|
variable CmdNum : Natural := 0;
|
488 |
|
|
variable EndOfFile : Boolean := false;
|
489 |
|
|
variable Good : Boolean := false;
|
490 |
|
|
variable Int : Integer;
|
491 |
|
|
variable Tm : Time;
|
492 |
|
|
variable C : Character;
|
493 |
|
|
variable Addr : Std_Logic_Vector(31 downto 0);
|
494 |
|
|
variable Data : Std_Logic_Vector(31 downto 0);
|
495 |
|
|
variable Enable : Std_Logic_Vector(3 downto 0);
|
496 |
|
|
variable Vect_count : Std_Logic_Vector(7 downto 0);
|
497 |
|
|
variable Data_word : Std_Logic_Vector(15 downto 0);
|
498 |
|
|
variable Data_byte : Std_Logic_Vector(7 downto 0);
|
499 |
|
|
variable str4 : string(1 to 4);
|
500 |
|
|
variable count_nr : Integer;
|
501 |
|
|
variable count : Integer;
|
502 |
|
|
begin
|
503 |
|
|
ErrFlag := false;
|
504 |
|
|
FILE_OPEN(CmdFile,file_name,READ_MODE);
|
505 |
|
|
loop
|
506 |
|
|
readline(CmdFile,L);
|
507 |
|
|
EndOfFile := endfile(CmdFile);
|
508 |
|
|
CmdNum := CmdNum + 1;
|
509 |
|
|
LineNum := LineNum + 1;
|
510 |
|
|
read(L, str4, Good);
|
511 |
|
|
if not Good then
|
512 |
|
|
CmdNum := CmdNum-1;
|
513 |
|
|
else
|
514 |
|
|
case str4 is
|
515 |
|
|
when "WRSW" => -- write single word command
|
516 |
|
|
readhex(L,Addr,Good,Enable);
|
517 |
|
|
if not Good then
|
518 |
|
|
report HeaderMsg&"Invalid WRSW command in :"&file_name&", line #"& integer'image(LineNum) &", "&"Address parameter should be 8 hex characters"
|
519 |
|
|
severity MsgSeverity;
|
520 |
|
|
ErrFlag := true;
|
521 |
|
|
else
|
522 |
|
|
Good := true;
|
523 |
|
|
readhex(L,Data_byte,Good,Enable);
|
524 |
|
|
count_nr := Byte2Int(Data_Byte);
|
525 |
|
|
count := 0;
|
526 |
|
|
for I in 0 to count_nr-1 loop
|
527 |
|
|
readhex(L,Data,Good,Enable);
|
528 |
|
|
if (Good =true) then
|
529 |
|
|
count := count + 1;
|
530 |
|
|
commands(CmdNum).command := "WRSW";
|
531 |
|
|
commands(CmdNum).addr := Addr;
|
532 |
|
|
commands(CmdNum).data(count) := Data;
|
533 |
|
|
commands(CmdNum).data_nr := count_nr;
|
534 |
|
|
commands(CmdNum).enable(count) := Enable;
|
535 |
|
|
else
|
536 |
|
|
report HeaderMsg&"Invalid DATA in WRSW command ";
|
537 |
|
|
end if;
|
538 |
|
|
end loop;
|
539 |
|
|
end if;
|
540 |
|
|
|
541 |
|
|
when "RDSW" => -- read single word command
|
542 |
|
|
readhex(L,Addr,Good,Enable);
|
543 |
|
|
if not Good then
|
544 |
|
|
report HeaderMsg&"Invalid RDSW command in :"&file_name&", line #"& integer'image(LineNum) &", "&"Address parameter should be 8 hex characters"
|
545 |
|
|
severity MsgSeverity;
|
546 |
|
|
ErrFlag := true;
|
547 |
|
|
else
|
548 |
|
|
Good := true;
|
549 |
|
|
readhex(L,Data_byte,Good,Enable);
|
550 |
|
|
count_nr :=Byte2Int(Data_Byte);
|
551 |
|
|
count := 0;
|
552 |
|
|
for I in 0 to count_nr-1 loop
|
553 |
|
|
readhex(L,Data,Good,Enable);
|
554 |
|
|
if (Good =true) then
|
555 |
|
|
count := count + 1;
|
556 |
|
|
commands(CmdNum).command := "RDSW";
|
557 |
|
|
commands(CmdNum).addr := Addr;
|
558 |
|
|
commands(CmdNum).data(count) := Data;
|
559 |
|
|
commands(CmdNum).data_nr := count_nr;
|
560 |
|
|
commands(CmdNum).enable(count) := Enable;
|
561 |
|
|
else
|
562 |
|
|
report HeaderMsg&"Invalid DATA in RDSW command ";
|
563 |
|
|
end if;
|
564 |
|
|
end loop;
|
565 |
|
|
end if;
|
566 |
|
|
|
567 |
|
|
when "WRMW" => -- write multiple words command
|
568 |
|
|
readhex(L,Addr,Good,Enable);
|
569 |
|
|
if not Good then
|
570 |
|
|
report HeaderMsg&"Invalid WRMW command in :"&file_name&", line #"& integer'image(LineNum) &", "&"Address parameter should be 8 hex characters"
|
571 |
|
|
severity MsgSeverity;
|
572 |
|
|
ErrFlag := true;
|
573 |
|
|
else
|
574 |
|
|
Good := true;
|
575 |
|
|
readhex(L,Data_byte,Good,Enable);
|
576 |
|
|
count_nr :=Byte2Int(Data_Byte);
|
577 |
|
|
count := 0;
|
578 |
|
|
for I in 0 to count_nr-1 loop
|
579 |
|
|
readhex(L,Data,Good,Enable);
|
580 |
|
|
if (Good =true) then
|
581 |
|
|
count := count + 1;
|
582 |
|
|
commands(CmdNum).command := "WRMW";
|
583 |
|
|
commands(CmdNum).addr := Addr;
|
584 |
|
|
commands(CmdNum).data(count) := Data;
|
585 |
|
|
commands(CmdNum).data_nr := count_nr;
|
586 |
|
|
commands(CmdNum).enable(count) := Enable;
|
587 |
|
|
else
|
588 |
|
|
report HeaderMsg&"Invalid DATA in WRMW command ";
|
589 |
|
|
end if;
|
590 |
|
|
end loop;
|
591 |
|
|
end if;
|
592 |
|
|
|
593 |
|
|
when "RDMW" => -- read multiple words command
|
594 |
|
|
readhex(L,Addr,Good,Enable);
|
595 |
|
|
if not Good then
|
596 |
|
|
report HeaderMsg&"Invalid RDMW command in :"&file_name&", line #"& integer'image(LineNum) &", "&"Address parameter should be 8 hex characters"
|
597 |
|
|
severity MsgSeverity;
|
598 |
|
|
ErrFlag := true;
|
599 |
|
|
else
|
600 |
|
|
Good := true;
|
601 |
|
|
readhex(L,Data_Byte,Good,Enable);
|
602 |
|
|
count_nr :=Byte2Int(Data_Byte);
|
603 |
|
|
count := 0;
|
604 |
|
|
for I in 0 to count_nr-1 loop
|
605 |
|
|
readhex(L,Data,Good,Enable);
|
606 |
|
|
if (Good =true) then
|
607 |
|
|
count := count + 1;
|
608 |
|
|
commands(CmdNum).command := "RDMW";
|
609 |
|
|
commands(CmdNum).addr := Addr;
|
610 |
|
|
commands(CmdNum).data(count) := Data;
|
611 |
|
|
commands(CmdNum).data_nr := count_nr;
|
612 |
|
|
commands(CmdNum).enable(count) := Enable;
|
613 |
|
|
else
|
614 |
|
|
report HeaderMsg&"Invalid DATA in RDMW command ";
|
615 |
|
|
end if;
|
616 |
|
|
end loop;
|
617 |
|
|
end if;
|
618 |
|
|
|
619 |
|
|
when "RDML" => -- read multiple words command
|
620 |
|
|
readhex(L,Addr,Good,Enable);
|
621 |
|
|
if not Good then
|
622 |
|
|
report HeaderMsg&"Invalid RDML command in :"&file_name&", line #"& integer'image(LineNum) &", "&"Address parameter should be 8 hex characters"
|
623 |
|
|
severity MsgSeverity;
|
624 |
|
|
ErrFlag := true;
|
625 |
|
|
else
|
626 |
|
|
Good := true;
|
627 |
|
|
readhex(L,Data_Byte,Good,Enable);
|
628 |
|
|
count_nr :=Byte2Int(Data_Byte);
|
629 |
|
|
count := 0;
|
630 |
|
|
for I in 0 to count_nr-1 loop
|
631 |
|
|
readhex(L,Data,Good,Enable);
|
632 |
|
|
if (Good =true) then
|
633 |
|
|
count := count + 1;
|
634 |
|
|
commands(CmdNum).command := "RDML";
|
635 |
|
|
commands(CmdNum).addr := Addr;
|
636 |
|
|
commands(CmdNum).data(count) := Data;
|
637 |
|
|
commands(CmdNum).data_nr := count_nr;
|
638 |
|
|
commands(CmdNum).enable(count) := Enable;
|
639 |
|
|
else
|
640 |
|
|
report HeaderMsg&"Invalid DATA in RDML command ";
|
641 |
|
|
end if;
|
642 |
|
|
end loop;
|
643 |
|
|
end if;
|
644 |
|
|
|
645 |
|
|
when "WCFG" => -- write to configuration space command
|
646 |
|
|
readhex(L,Addr,Good,Enable);
|
647 |
|
|
if not Good then
|
648 |
|
|
report HeaderMsg&"Invalid WCFG command in :"&file_name&", line #"& integer'image(LineNum) &", "&"Address parameter should be 8 hex characters"
|
649 |
|
|
severity MsgSeverity;
|
650 |
|
|
ErrFlag := true;
|
651 |
|
|
else
|
652 |
|
|
Good := true;
|
653 |
|
|
readhex(L,Data_byte,Good,Enable);
|
654 |
|
|
count_nr :=Byte2Int(Data_Byte);
|
655 |
|
|
count := 0;
|
656 |
|
|
for I in 0 to count_nr-1 loop
|
657 |
|
|
readhex(L,Data,Good,Enable);
|
658 |
|
|
if (Good =true) then
|
659 |
|
|
count := count + 1;
|
660 |
|
|
commands(CmdNum).command := "WCFG";
|
661 |
|
|
commands(CmdNum).addr := Addr;
|
662 |
|
|
commands(CmdNum).data(count) := Data;
|
663 |
|
|
commands(CmdNum).data_nr := count_nr;
|
664 |
|
|
commands(CmdNum).enable(count) := Enable;
|
665 |
|
|
else
|
666 |
|
|
report HeaderMsg&"Invalid DATA in WCFG command ";
|
667 |
|
|
end if;
|
668 |
|
|
end loop;
|
669 |
|
|
end if;
|
670 |
|
|
|
671 |
|
|
when "RCFG" => -- read from configuration space command
|
672 |
|
|
readhex(L,Addr,Good,Enable);
|
673 |
|
|
if not Good then
|
674 |
|
|
report HeaderMsg&"Invalid RCFG command in :"&file_name&", line #"& integer'image(LineNum) &", "&"Address parameter should be 8 hex characters"
|
675 |
|
|
severity MsgSeverity;
|
676 |
|
|
ErrFlag := true;
|
677 |
|
|
else
|
678 |
|
|
Good := true;
|
679 |
|
|
readhex(L,Data_Byte,Good,Enable);
|
680 |
|
|
count_nr :=Byte2Int(Data_Byte);
|
681 |
|
|
count := 0;
|
682 |
|
|
for I in 0 to count_nr-1 loop
|
683 |
|
|
readhex(L,Data,Good,Enable);
|
684 |
|
|
if (Good =true) then
|
685 |
|
|
count := count + 1;
|
686 |
|
|
commands(CmdNum).command := "RCFG";
|
687 |
|
|
commands(CmdNum).addr := Addr;
|
688 |
|
|
commands(CmdNum).data(count) := Data;
|
689 |
|
|
commands(CmdNum).data_nr := count_nr;
|
690 |
|
|
commands(CmdNum).enable(count) := Enable;
|
691 |
|
|
else
|
692 |
|
|
report HeaderMsg&"Invalid DATA in RCFG command ";
|
693 |
|
|
end if;
|
694 |
|
|
end loop;
|
695 |
|
|
end if;
|
696 |
|
|
|
697 |
|
|
when "WRIO" => -- write to I/O space command
|
698 |
|
|
readhex(L,Addr,Good,Enable);
|
699 |
|
|
if not Good then
|
700 |
|
|
report HeaderMsg&"Invalid WRIO command in :"&file_name&", line #"& integer'image(LineNum) &", "&"Address parameter should be 8 hex characters"
|
701 |
|
|
severity MsgSeverity;
|
702 |
|
|
ErrFlag := true;
|
703 |
|
|
else
|
704 |
|
|
Good := true;
|
705 |
|
|
readhex(L,Data_byte,Good,Enable);
|
706 |
|
|
count_nr :=Byte2Int(Data_Byte);
|
707 |
|
|
count := 0;
|
708 |
|
|
for I in 0 to count_nr-1 loop
|
709 |
|
|
readhex(L,Data,Good,Enable);
|
710 |
|
|
if (Good = true) then
|
711 |
|
|
count := count + 1;
|
712 |
|
|
commands(CmdNum).command := "WRIO";
|
713 |
|
|
commands(CmdNum).addr := Addr;
|
714 |
|
|
commands(CmdNum).data(count) := Data;
|
715 |
|
|
commands(CmdNum).data_nr := count_nr;
|
716 |
|
|
commands(CmdNum).enable(count) := Enable;
|
717 |
|
|
else
|
718 |
|
|
report HeaderMsg&"Invalid DATA in WRIO command ";
|
719 |
|
|
end if;
|
720 |
|
|
end loop;
|
721 |
|
|
end if;
|
722 |
|
|
|
723 |
|
|
when "RDIO" => -- read from I/O space command
|
724 |
|
|
readhex(L,Addr,Good,Enable);
|
725 |
|
|
if not Good then
|
726 |
|
|
report HeaderMsg&"Invalid RDIO command in :"&file_name&", line #"& integer'image(LineNum) &", "&"Address parameter should be 8 hex characters"
|
727 |
|
|
severity MsgSeverity;
|
728 |
|
|
ErrFlag := true;
|
729 |
|
|
else
|
730 |
|
|
Good := true;
|
731 |
|
|
readhex(L,Data_Byte,Good,Enable);
|
732 |
|
|
count_nr :=Byte2Int(Data_Byte);
|
733 |
|
|
count := 0;
|
734 |
|
|
for I in 0 to count_nr-1 loop
|
735 |
|
|
readhex(L,Data,Good,Enable);
|
736 |
|
|
if (Good = true) then
|
737 |
|
|
count := count + 1;
|
738 |
|
|
commands(CmdNum).command := "RDIO";
|
739 |
|
|
commands(CmdNum).addr := Addr;
|
740 |
|
|
commands(CmdNum).data(count) := Data;
|
741 |
|
|
commands(CmdNum).data_nr := count_nr;
|
742 |
|
|
commands(CmdNum).enable(count) := Enable;
|
743 |
|
|
else
|
744 |
|
|
report HeaderMsg&"Invalid DATA in RDIO command ";
|
745 |
|
|
end if;
|
746 |
|
|
end loop;
|
747 |
|
|
end if;
|
748 |
|
|
|
749 |
|
|
when "CWAT" =>
|
750 |
|
|
readhex(L,Addr,Good,Enable);
|
751 |
|
|
if not Good then
|
752 |
|
|
report HeaderMsg&"Invalid CWAT command in :"&file_name&", line #"& integer'image(LineNum) &", "&"Address parameter should be 8 hex characters"
|
753 |
|
|
severity MsgSeverity;
|
754 |
|
|
ErrFlag := true;
|
755 |
|
|
else
|
756 |
|
|
count_nr :=0;
|
757 |
|
|
readhex(L,Data,Good,Enable);
|
758 |
|
|
if (Good = true) then
|
759 |
|
|
count :=count +1;
|
760 |
|
|
commands(CmdNum).command := "WAIT";
|
761 |
|
|
commands(CmdNum).addr := Addr;
|
762 |
|
|
commands(CmdNum).data(1) := Data;
|
763 |
|
|
commands(CmdNum).data_nr := 1;
|
764 |
|
|
commands(CmdNum).enable(1) := Enable;
|
765 |
|
|
else
|
766 |
|
|
report HeaderMsg&"Invalid DATA in CWAT command ";
|
767 |
|
|
end if;
|
768 |
|
|
end if;
|
769 |
|
|
|
770 |
|
|
when "ABRT" =>
|
771 |
|
|
count :=count + 1;
|
772 |
|
|
commands(CmdNum).command := "ABRT";
|
773 |
|
|
commands(CmdNum).addr := "00000000000000000000000000000000";
|
774 |
|
|
commands(CmdNum).data(1) := "00000000000000000000000000000000";
|
775 |
|
|
commands(CmdNum).data_nr := 1;
|
776 |
|
|
commands(CmdNum).enable(1) := Enable;
|
777 |
|
|
|
778 |
|
|
when others =>
|
779 |
|
|
CmdNum := CmdNum -1;
|
780 |
|
|
if str4(1 to 2)/= "##" then
|
781 |
|
|
report HeaderMsg & "Invalid command in file: "&file_name&", line #"& integer'image(LineNum) &", "& "Unknown command : "& str4 & l(l'left to l'right)
|
782 |
|
|
severity error;
|
783 |
|
|
ErrFlag := true;
|
784 |
|
|
end if;
|
785 |
|
|
end case;
|
786 |
|
|
end if;
|
787 |
|
|
NumCommands := CmdNum;
|
788 |
|
|
Exit when EndOfFile;
|
789 |
|
|
end loop;
|
790 |
|
|
end FileParser;
|
791 |
|
|
--------------------------------------------------------------------
|
792 |
|
|
--------------------------------------------------------------------
|
793 |
|
|
end PCI_Def; --================ End of package body ================--
|