1 | -- Package File Template |
---|
2 | -- |
---|
3 | -- Purpose: This package defines supplemental types, subtypes, |
---|
4 | -- constants, and components |
---|
5 | |
---|
6 | |
---|
7 | library IEEE; |
---|
8 | use IEEE.STD_LOGIC_1164.all; |
---|
9 | use IEEE.numeric_std.all; |
---|
10 | package CoreTypes is |
---|
11 | CONSTANT Word :POSITIVE:= 8; |
---|
12 | CONSTANT ADRLEN:POSITIVE:=16; |
---|
13 | CONSTANT LZFILL :std_logic_vector(2*Word-ADRLEN to 0):=(others=>'0');--indique le nombre de zero à utiliser pour completer le bus de données lorsque la longueur restante du bus d'adresse est inférueure à la largeur du bus de données |
---|
14 | CONSTANT IADR0 : NATURAL :=2; --Adresse basse de l'instruction |
---|
15 | CONSTANT IADR1 : natural :=3; |
---|
16 | CONSTANT CORE_BASE_ADR :natural range 0 to 65535:=4096; |
---|
17 | CONSTANT CORE_UPPER_ADR : natural range 0 to 255:=16; |
---|
18 | CONSTANT CORE_GET_ADR:natural:=CORE_BASE_ADR+526; |
---|
19 | CONSTANT CORE_PUT_ADR :natural:=CORE_BASE_ADR+516; |
---|
20 | CONSTANT core_INIT_ADR : natural:=CORE_BASE_ADR+512; |
---|
21 | CONSTANT CORE_WCREATE_ADR : natural := CORE_BASE_ADR+536; |
---|
22 | CONSTANT CORE_WCOMPL_ADR : natural := CORE_BASE_ADR+546; |
---|
23 | CONSTANT CORE_WPOST_ADR : natural := CORE_BASE_ADR+556; |
---|
24 | CONSTANT CORE_WWAIT_ADR : natural := CORE_BASE_ADR+566; |
---|
25 | CONSTANT CORE_SPAWN_ADR : natural := CORE_BASE_ADR+576; |
---|
26 | CONSTANT CORE_Rank2port_BASE :NATURAL:=52; |
---|
27 | CONSTANT CORE_RANK_ADR : NATURAL:=CORE_BASE_ADR+CORE_Rank2Port_Base; |
---|
28 | CONSTANT WIN0_ADR :natural :=4; |
---|
29 | CONSTANT WIN1_ADR :natural :=14; |
---|
30 | CONSTANT WIN2_ADR :natural :=24; |
---|
31 | CONSTANT WIN3_ADR :natural :=34; |
---|
32 | CONSTANT GETPORTID : std_logic_vector(3 downto 0):="0001"; |
---|
33 | |
---|
34 | type Typ_PortIO is |
---|
35 | array(natural range <>) of std_logic_vector( Word-1 downto 0); |
---|
36 | |
---|
37 | type memory is |
---|
38 | array (natural range <>) of std_logic_vector(word-1 downto 0); |
---|
39 | |
---|
40 | type Core_io is |
---|
41 | record |
---|
42 | Instr_en :std_logic; -- active une instruction MPI |
---|
43 | Instr_ack :std_logic;-- signal la prise en compte de l'instruction |
---|
44 | Ready :std_logic;-- indique que la dernière fonction est terminée |
---|
45 | InitOk :std_logic; -- l'initialisation est terminée |
---|
46 | Hold_Req :std_logic;--Demande DMA |
---|
47 | Hold_Ack :std_logic;-- Autorisation DMA |
---|
48 | MemBusy :std_logic;-- active le refus de DMA (1 -> ignoré la requête DMA) |
---|
49 | RamSel :std_logic;-- indique le statut de la RAM (0 ->dispo 1->occupé par Core_MPI) |
---|
50 | IntState1 : natural range 0 to 255; --permet de stocker l'état des MAE interne dans les procédures |
---|
51 | IntState2 : natural range 0 to 255; |
---|
52 | Instruction :std_logic_vector (word-1 downto 0); |
---|
53 | WinId :natural range 0 to 255; --stocke le dernier Id utilisé par WinCreate |
---|
54 | IsMain : std_logic; -- indique si la librairie est principal |
---|
55 | Rank : natural range 0 to 16; --donne le rang du processus courant |
---|
56 | Spawned: std_logic; --indique que ce module a été activé par la bibliothèque |
---|
57 | end record; |
---|
58 | |
---|
59 | type typ_dpram is |
---|
60 | record |
---|
61 | |
---|
62 | |
---|
63 | clk_wr : STD_LOGIC; |
---|
64 | clk_rd : STD_LOGIC; |
---|
65 | we : STD_LOGIC; |
---|
66 | ena : STD_LOGIC; |
---|
67 | enb : STD_LOGIC; |
---|
68 | addr_wr: STD_LOGIC_VECTOR (ADRLEN-1 downto 0); |
---|
69 | addr_rd : STD_LOGIC_VECTOR (ADRLEN-1 downto 0); |
---|
70 | data_in : STD_LOGIC_VECTOR (Word-1 downto 0); |
---|
71 | data_out : STD_LOGIC_VECTOR (Word-1 downto 0); |
---|
72 | |
---|
73 | |
---|
74 | end record; |
---|
75 | type Typ_MPIPort_in is |
---|
76 | record |
---|
77 | instruction : STD_LOGIC_VECTOR (Word -1 downto 0); |
---|
78 | instruction_en : STD_LOGIC; |
---|
79 | |
---|
80 | |
---|
81 | packet_ack : std_logic; |
---|
82 | ram_data_out : STD_LOGIC_VECTOR (Word-1 downto 0); |
---|
83 | |
---|
84 | hold_ack : STD_Logic; --autorisation par l'application |
---|
85 | clk : STD_LOGIC; |
---|
86 | reset : STD_LOGIC; |
---|
87 | |
---|
88 | end record; |
---|
89 | type Typ_MPIPort_out is |
---|
90 | record |
---|
91 | |
---|
92 | |
---|
93 | ram_we : STD_LOGIC; |
---|
94 | ram_en : STD_LOGIC; |
---|
95 | ram_data_in : STD_LOGIC_VECTOR (WORD-1 downto 0); |
---|
96 | ram_address_rd : STD_LOGIC_VECTOR (ADRLEN-1 downto 0); |
---|
97 | ram_address_wr : STD_LOGIC_VECTOR (ADRLEN-1 downto 0); |
---|
98 | packet_received : STD_LOGIC; |
---|
99 | barrier_completed : STD_LOGIC; |
---|
100 | instruction_fifo_full : STD_LOGIC; |
---|
101 | PushOut : STD_LOGIC_VECTOR (WORD-1 downto 0); |
---|
102 | |
---|
103 | hold_req : STD_Logic; --requete vers application |
---|
104 | end record; |
---|
105 | |
---|
106 | Type Ar_MPIPort_In is array (positive range <>) of Typ_MPIPort_in; |
---|
107 | Type Ar_MPIPort_out is array (positive range <>) of Typ_MPIPort_out; |
---|
108 | |
---|
109 | -- Declare constants |
---|
110 | |
---|
111 | -- constant <constant_name> : time := <time_unit> ns; |
---|
112 | -- constant <constant_name> : integer := <value>; |
---|
113 | -- |
---|
114 | -- Declare functions and procedure |
---|
115 | Component SWITCH_GEN is |
---|
116 | generic(number_of_ports : positive := 8); |
---|
117 | port( |
---|
118 | -- ports d'entree |
---|
119 | Port_in : in typ_portIO(1 to number_of_ports) ; |
---|
120 | -- |
---|
121 | |
---|
122 | -- port de sortie |
---|
123 | Port_out : out typ_portIO(1 to number_of_ports); |
---|
124 | -- |
---|
125 | -- signaux de controle |
---|
126 | cmd_in_en : in std_logic_vector(number_of_ports downto 1); |
---|
127 | data_in_en : in std_logic_vector(number_of_ports downto 1); |
---|
128 | data_out_en : in std_logic_vector(number_of_ports downto 1); |
---|
129 | fifo_in_full : out std_logic_vector(number_of_ports downto 1); |
---|
130 | fifo_in_empty : out std_logic_vector(number_of_ports downto 1); |
---|
131 | data_available : out std_logic_vector(number_of_ports downto 1); |
---|
132 | clk : in STD_LOGIC; |
---|
133 | reset : in STD_LOGIC); |
---|
134 | end component SWITCH_GEN; |
---|
135 | -- déclaration des fonctions utilisées |
---|
136 | |
---|
137 | FUNCTION all_ones(s1:std_logic_vector) return std_logic; |
---|
138 | --This function returns if the input vector has all ones and no zeros |
---|
139 | FUNCTION all_zeros(s1:std_logic_vector) return std_logic; |
---|
140 | --This function returns if the input vector has all zeros and no ones |
---|
141 | FUNCTION incr_vec(s1:std_logic_vector;en:std_logic) return std_logic_vector; |
---|
142 | --This function increments an std_logic_vector type by '1', without |
---|
143 | --using any arithmatic |
---|
144 | |
---|
145 | FUNCTION dcr_vec(s1:std_logic_vector;en:std_logic) return std_logic_vector; |
---|
146 | --This function decrements an std_logic_vector type by '1', without |
---|
147 | --using any arithmatic |
---|
148 | FUNCTION Rol_Vec(s1:std_logic_vector) return std_logic_vector; |
---|
149 | --renvoie un std_logic_vector de taille ADRLEN |
---|
150 | Function Stdlv (s1 : natural) return std_logic_vector; |
---|
151 | --renvoie un std_logic_vector de taille width |
---|
152 | Function Stdlv (s1 : natural;width:positive ) return std_logic_vector; |
---|
153 | function image(L: bit_vector) return String; |
---|
154 | function image(L: bit) return String; |
---|
155 | function image(L: std_logic_vector) return String; |
---|
156 | function image(L: std_logic) return String; |
---|
157 | -- function HexImage(L: unsigned) return String; |
---|
158 | -- function HexImage(L: signed) return String; |
---|
159 | -- function HexImage(L: std_ulogic_vector) return String; |
---|
160 | -- function HexImage(L: std_logic_vector) return String; |
---|
161 | -- function HexImage(L: bit_vector) return String; |
---|
162 | end CoreTypes; |
---|
163 | |
---|
164 | |
---|
165 | Package body CoreTypes is |
---|
166 | |
---|
167 | |
---|
168 | FUNCTION incr_vec(s1:std_logic_vector;en:std_logic) return std_logic_vector is |
---|
169 | --this function increments a std_logic_vector type by '1' |
---|
170 | VARIABLE V : std_logic_vector(s1'high downto s1'low) ; |
---|
171 | VARIABLE tb : std_logic_vector(s1'high downto s1'low); |
---|
172 | BEGIN |
---|
173 | tb(s1'low) := en; |
---|
174 | V := s1; |
---|
175 | for i in (V'low + 1) to V'high loop |
---|
176 | tb(i) := V(i - 1) and tb(i -1); |
---|
177 | end loop; |
---|
178 | for i in V'low to V'high loop |
---|
179 | if(tb(i) = '1') then |
---|
180 | V(i) := not(V(i)); |
---|
181 | end if; |
---|
182 | end loop; |
---|
183 | return V; |
---|
184 | end incr_vec; -- end function |
---|
185 | |
---|
186 | FUNCTION dcr_vec(s1:std_logic_vector;en:std_logic) return std_logic_vector is |
---|
187 | --this function decrements a std_logic_vector type by '1' |
---|
188 | VARIABLE V : std_logic_vector(s1'high downto s1'low) ; |
---|
189 | VARIABLE tb : std_logic_vector(s1'high downto s1'low); |
---|
190 | BEGIN |
---|
191 | tb(s1'low) := not(en); |
---|
192 | V := s1; |
---|
193 | for i in (V'low + 1) to V'high loop |
---|
194 | tb(i) := V(i - 1) or tb(i -1); |
---|
195 | end loop; |
---|
196 | for i in V'low to V'high loop |
---|
197 | if(tb(i) = '0') then |
---|
198 | V(i) := not(V(i)); |
---|
199 | end if; |
---|
200 | end loop; |
---|
201 | return V; |
---|
202 | end dcr_vec; -- end function |
---|
203 | FUNCTION all_ones(s1:std_logic_vector) return std_logic is |
---|
204 | --this function tells if all bits of a vector are '1' |
---|
205 | --return value Z is '1', then vector has all 1 bits |
---|
206 | --VARIABLE V : std_logic_vector(s1'high downto s1'low) ; |
---|
207 | VARIABLE Z : std_logic; |
---|
208 | BEGIN |
---|
209 | Z := s1(s1'low); |
---|
210 | FOR i IN (s1'low+1) to s1'high LOOP |
---|
211 | Z := Z AND s1(i); |
---|
212 | END LOOP; |
---|
213 | RETURN Z; |
---|
214 | END all_ones; -- end function |
---|
215 | FUNCTION all_zeros(s1:std_logic_vector) return std_logic is |
---|
216 | --this function tells if all bits of a vector are '0' |
---|
217 | --return value Z if '1', then vector has all 0 bits |
---|
218 | --VARIABLE V : std_logic_vector(s1'high downto s1'low) ; |
---|
219 | VARIABLE Z : std_logic; |
---|
220 | BEGIN |
---|
221 | Z := '0'; |
---|
222 | FOR i IN (s1'low) to s1'high LOOP |
---|
223 | Z := Z OR s1(i); |
---|
224 | END LOOP; |
---|
225 | RETURN not(Z); |
---|
226 | END all_zeros; -- end function |
---|
227 | |
---|
228 | FUNCTION Rol_Vec(s1:std_logic_vector) return std_logic_vector is |
---|
229 | --cette fonction fait roter un STD_logic d'un pas vers la gauche |
---|
230 | VARIABLE V : std_logic_vector(s1'high downto s1'low) ; |
---|
231 | VARIABLE lb : std_logic :=s1(s1'left); |
---|
232 | BEGIN |
---|
233 | |
---|
234 | for i in V'left downto (V'right+1) loop |
---|
235 | V(i) := s1(i - 1) ; |
---|
236 | end loop; |
---|
237 | V(V'right):=lb; |
---|
238 | return V; |
---|
239 | end Rol_vec; |
---|
240 | Function Stdlv (s1 : natural ) return std_logic_vector is |
---|
241 | VARIABLE V : std_logic_vector(ADRLEN-1 downto 0); |
---|
242 | begin |
---|
243 | V:=std_logic_vector(to_unsigned(s1,ADRLEN)); |
---|
244 | return V; |
---|
245 | end stdlv; |
---|
246 | Function Stdlv (s1 : natural;width:positive ) return std_logic_vector is |
---|
247 | VARIABLE V : std_logic_vector(width-1 downto 0); |
---|
248 | begin |
---|
249 | V:=std_logic_vector(to_unsigned(s1,width)); |
---|
250 | return V; |
---|
251 | end stdlv; |
---|
252 | |
---|
253 | -- Start of heximage functions |
---|
254 | --function HexImage(L: bit_vector) return String is |
---|
255 | --begin |
---|
256 | --return(HexImage(imge(L))); |
---|
257 | --end function HexImage; |
---|
258 | -- |
---|
259 | --function HexImage(L: std_ulogic_vector) return String is |
---|
260 | --begin |
---|
261 | --return(HexImage(image(to_x01(L)))); |
---|
262 | --end function HexImage; |
---|
263 | |
---|
264 | --function HexImage(L: std_logic_vector) return String is |
---|
265 | --begin |
---|
266 | --return(HexImage(imge(to_x01(L)))); |
---|
267 | --end function HexImage; |
---|
268 | -- |
---|
269 | --function HexImage(L: signed) return String is |
---|
270 | --begin |
---|
271 | --return(HexImage(imge(L))); |
---|
272 | --end function HexImage; |
---|
273 | -- |
---|
274 | --function HexImage(L: unsigned) return String is |
---|
275 | --begin |
---|
276 | --return(HexImage(image(L))); |
---|
277 | --end function HexImage; |
---|
278 | -- End of heximage functions |
---|
279 | -- Start of an example image function |
---|
280 | function image(L: bit) return String is |
---|
281 | variable bit_image: String(1 to 1) := bit'image(L); |
---|
282 | begin |
---|
283 | return(bit_image(1 to 1)); |
---|
284 | end function image; |
---|
285 | |
---|
286 | |
---|
287 | function image(L: std_logic) return String is |
---|
288 | variable bit_image: String(1 to 3) := std_logic'image(L); |
---|
289 | begin |
---|
290 | return(bit_image(1 to 1)); |
---|
291 | end function image; |
---|
292 | |
---|
293 | function image(L: bit_vector) return String is |
---|
294 | variable Lx: bit_vector(1 to L'length); |
---|
295 | variable RetVal: String(1 to L'length); |
---|
296 | begin |
---|
297 | Lx := L; |
---|
298 | for i in Lx'range loop |
---|
299 | RetVal(i to i) := image(Lx(i)); |
---|
300 | end loop; |
---|
301 | return(RetVal); |
---|
302 | end function image; |
---|
303 | |
---|
304 | |
---|
305 | function image(L: std_logic_vector) return String is |
---|
306 | variable Lx: std_logic_vector(1 to L'length); |
---|
307 | variable RetVal: String(1 to L'length); |
---|
308 | begin |
---|
309 | Lx := L; |
---|
310 | for i in Lx'range loop |
---|
311 | RetVal(i to i) := image(Lx(i)); |
---|
312 | end loop; |
---|
313 | return(RetVal); |
---|
314 | end function image; |
---|
315 | end CoreTypes; |
---|