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

Subversion Repositories mips_enhanced

[/] [mips_enhanced/] [trunk/] [grlib-gpl-1.0.19-b3188/] [lib/] [tech/] [ec/] [orca/] [mem3.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dimamali
--
2
----- package mem3 -----
3
--
4
LIBRARY ieee;
5
USE ieee.std_logic_1164.all;
6
use ieee.std_logic_arith.all;
7
 
8
PACKAGE mem3 IS
9
   TYPE mem_type_5 IS array (Integer range <>) OF std_logic_vector(17 downto 0);
10
   TYPE mem_type_6 IS array (Integer range <>) OF std_logic_vector(15 downto 0);
11
   FUNCTION hex2bin (hex: character) RETURN std_logic_vector;
12
   FUNCTION str3_slv12 (hex: string) RETURN std_logic_vector;
13
   FUNCTION data2data (data_w: integer) RETURN integer;
14
   FUNCTION data2addr_w (data_w: integer) RETURN integer;
15
   FUNCTION data2data_w (data_w: integer) RETURN integer;
16
   FUNCTION init_ram (hex: string; DATA_WIDTH_A : integer; DATA_WIDTH_B : integer) RETURN std_logic_vector;
17
   FUNCTION init_ram1 (hex: string) RETURN mem_type_6;
18
   FUNCTION str2slv (str: in string) RETURN std_logic_vector;
19
   FUNCTION Valid_Address (IN_ADDR : in std_logic_vector) return boolean;
20
END mem3;
21
PACKAGE BODY mem3 IS
22
 
23
   FUNCTION hex2bin (hex: character) RETURN std_logic_vector IS
24
        VARIABLE result : std_logic_vector (3 downto 0);
25
   BEGIN
26
        CASE hex IS
27
          WHEN '0' =>
28
             result := "0000";
29
          WHEN '1' =>
30
             result := "0001";
31
          WHEN '2' =>
32
             result := "0010";
33
          WHEN '3' =>
34
             result := "0011";
35
          WHEN '4' =>
36
             result := "0100";
37
          WHEN '5' =>
38
             result := "0101";
39
          WHEN '6' =>
40
             result := "0110";
41
          WHEN '7' =>
42
             result := "0111";
43
          WHEN '8' =>
44
             result := "1000";
45
          WHEN '9' =>
46
             result := "1001";
47
          WHEN 'A'|'a' =>
48
             result := "1010";
49
          WHEN 'B'|'b' =>
50
             result := "1011";
51
          WHEN 'C'|'c' =>
52
             result := "1100";
53
          WHEN 'D'|'d' =>
54
             result := "1101";
55
          WHEN 'E'|'e' =>
56
             result := "1110";
57
          WHEN 'F'|'f' =>
58
             result := "1111";
59
          WHEN 'X'|'x' =>
60
             result := "XXXX";
61
          WHEN others =>
62
             NULL;
63
        END CASE;
64
        RETURN result;
65
   END;
66
 
67
   FUNCTION str5_slv18 (s : string(5 downto 1)) return std_logic_vector is
68
        VARIABLE result : std_logic_vector(17 downto 0);
69
   BEGIN
70
       FOR i in 0 to 3 LOOP
71
          result(((i+1)*4)-1 downto (i*4)) := hex2bin(s(i+1));
72
       END LOOP;
73
          result(17 downto 16) := hex2bin(s(5))(1 downto 0);
74
       RETURN result;
75
   END;
76
 
77
   FUNCTION str4_slv16 (s : string(4 downto 1)) return std_logic_vector is
78
        VARIABLE result : std_logic_vector(15 downto 0);
79
   BEGIN
80
       FOR i in 0 to 3 LOOP
81
          result(((i+1)*4)-1 downto (i*4)) := hex2bin(s(i+1));
82
       END LOOP;
83
       RETURN result;
84
   END;
85
 
86
   FUNCTION str3_slv12 (hex: string) return std_logic_vector is
87
        VARIABLE result : std_logic_vector(11 downto 0);
88
   BEGIN
89
       FOR i in 0 to 2 LOOP
90
          result(((i+1)*4)-1 downto (i*4)) := hex2bin(hex(i+1));
91
       END LOOP;
92
       RETURN result;
93
   END;
94
 
95
   FUNCTION data2addr_w (data_w : integer) return integer is
96
        VARIABLE result : integer;
97
   BEGIN
98
        CASE data_w IS
99
          WHEN 1 =>
100
             result := 13;
101
          WHEN 2 =>
102
             result := 12;
103
          WHEN 4 =>
104
             result := 11;
105
          WHEN 9 =>
106
             result := 10;
107
          WHEN 18 =>
108
             result := 9;
109
          WHEN 36 =>
110
             result := 8;
111
          WHEN others =>
112
             NULL;
113
        END CASE;
114
       RETURN result;
115
   END;
116
 
117
   FUNCTION data2data_w (data_w : integer) return integer is
118
        VARIABLE result : integer;
119
   BEGIN
120
        CASE data_w IS
121
          WHEN 1 =>
122
             result := 1;
123
          WHEN 2 =>
124
             result := 2;
125
          WHEN 4 =>
126
             result := 4;
127
          WHEN 9 =>
128
             result := 9;
129
          WHEN 18 =>
130
             result := 18;
131
          WHEN 36 =>
132
             result := 18;
133
          WHEN others =>
134
             NULL;
135
        END CASE;
136
       RETURN result;
137
   END;
138
 
139
   FUNCTION data2data (data_w : integer) return integer is
140
        VARIABLE result : integer;
141
   BEGIN
142
        CASE data_w IS
143
          WHEN 1 =>
144
             result := 8;
145
          WHEN 2 =>
146
             result := 4;
147
          WHEN 4 =>
148
             result := 2;
149
          WHEN 9 =>
150
             result := 36864;
151
          WHEN 18 =>
152
             result := 36864;
153
          WHEN 36 =>
154
             result := 36864;
155
          WHEN others =>
156
             NULL;
157
        END CASE;
158
       RETURN result;
159
   END;
160
 
161
   FUNCTION init_ram (hex: string; DATA_WIDTH_A : integer; DATA_WIDTH_B : integer) RETURN std_logic_vector IS
162
        CONSTANT length : integer := hex'length;
163
        VARIABLE result1 : mem_type_5 (0 to ((length/5)-1));
164
        VARIABLE result : std_logic_vector(((length*18)/5)-1 downto 0);
165
   BEGIN
166
       FOR i in 0 to ((length/5)-1) LOOP
167
         result1(i) := str5_slv18(hex((i+1)*5 downto (i*5)+1));
168
       END LOOP;
169
       IF (DATA_WIDTH_A >= 9 and DATA_WIDTH_B >= 9) THEN
170
          FOR j in 0 to 511 LOOP
171
            result(((j*18) + 17) downto (j*18)) := result1(j)(17 downto 0);
172
          END LOOP;
173
       ELSE
174
          FOR j in 0 to 511 LOOP
175
            result(((j*18) + 7) downto (j*18)) := result1(j)(7 downto 0);
176
            result((j*18) + 8) := '0';
177
            result(((j*18) + 16) downto ((j*18) + 9)) := result1(j)(15 downto 8);
178
            result((j*18) + 17) := '0';
179
          END LOOP;
180
       END IF;
181
       RETURN result;
182
   END;
183
 
184
   FUNCTION init_ram1 (hex: string) RETURN mem_type_6 IS
185
        CONSTANT length : integer := hex'length;
186
        VARIABLE result : mem_type_6 (0 to ((length/4)-1));
187
   BEGIN
188
       FOR i in 0 to ((length/4)-1) LOOP
189
         result(i) := str4_slv16(hex((i+1)*4 downto (i*4)+1));
190
       END LOOP;
191
       RETURN result;
192
   END;
193
 
194
-- String to std_logic_vector
195
 
196
  FUNCTION str2slv (
197
      str : in string
198
  ) return std_logic_vector is
199
 
200
  variable j : integer := str'length;
201
  variable slv : std_logic_vector (str'length downto 1);
202
 
203
  begin
204
      for i in str'low to str'high loop
205
          case str(i) is
206
              when '0' => slv(j) := '0';
207
              when '1' => slv(j) := '1';
208
              when 'X' => slv(j) := 'X';
209
              when 'U' => slv(j) := 'U';
210
              when others => slv(j) := 'X';
211
          end case;
212
          j := j - 1;
213
      end loop;
214
      return slv;
215
  end str2slv;
216
 
217
function Valid_Address (
218
    IN_ADDR : in std_logic_vector
219
 ) return boolean is
220
 
221
    variable v_Valid_Flag : boolean := TRUE;
222
 
223
begin
224
 
225
    for i in IN_ADDR'high downto IN_ADDR'low loop
226
        if (IN_ADDR(i) /= '0' and IN_ADDR(i) /= '1') then
227
            v_Valid_Flag := FALSE;
228
        end if;
229
    end loop;
230
 
231
    return v_Valid_Flag;
232
end Valid_Address;
233
 
234
END mem3 ;

powered by: WebSVN 2.1.0

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