source: PROJECT_CORE_MPI/MPI_HCL/BRANCHES/v2.1/NOC/CoreTypes.vhd @ 143

Last change on this file since 143 was 143, checked in by rolagamo, 10 years ago
File size: 15.7 KB
Line 
1  --    Package File Template
2--
3--      Purpose: This package defines supplemental types, subtypes,
4--               constants, and components
5
6
7library IEEE;
8use IEEE.STD_LOGIC_1164.all;
9use IEEE.numeric_std.all;
10package CoreTypes is
11CONSTANT Word :POSITIVE:= 8;
12CONSTANT ADRLEN:POSITIVE:=16;
13CONSTANT 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
14CONSTANT IADR0 : NATURAL :=2; --Adresse basse de l'instruction
15CONSTANT IADR1 : natural :=3;
16CONSTANT CORE_BASE_ADR :natural range 0 to 65535:=4096;
17CONSTANT WIN_BASE_ADR :natural range 0 to 65535:=CORE_BASE_ADR+4;
18CONSTANT CORE_UPPER_ADR : natural range 0 to 255:=16;
19CONSTANT CORE_GET_ADR:natural:=CORE_BASE_ADR+526;
20CONSTANT CORE_PUT_ADR :natural:=CORE_BASE_ADR+516;
21CONSTANT core_INIT_ADR : natural:=CORE_BASE_ADR+512;
22CONSTANT CORE_WCREATE_ADR : natural := CORE_BASE_ADR+536;
23CONSTANT CORE_WCOMPL_ADR : natural := CORE_BASE_ADR+546;
24CONSTANT CORE_WPOST_ADR : natural := CORE_BASE_ADR+556;
25CONSTANT CORE_WWAIT_ADR : natural := CORE_BASE_ADR+566;
26CONSTANT CORE_WSYNC_ADR : natural := CORE_BASE_ADR+576;
27CONSTANT CORE_SPAWN_ADR : natural := CORE_BASE_ADR+586;
28CONSTANT CORE_Rank2port_BASE :NATURAL:=52;
29CONSTANT CORE_RANK_ADR : NATURAL:=CORE_BASE_ADR+CORE_Rank2Port_Base;
30CONSTANT WIN0_ADR :natural :=CORE_BASE_ADR+4;
31CONSTANT WIN1_ADR :natural :=CORE_BASE_ADR+20;
32CONSTANT WIN2_ADR :natural :=CORE_BASE_ADR+36;
33CONSTANT WIN3_ADR :natural :=CORE_BASE_ADR+52;
34CONSTANT GETPORTID : std_logic_vector(3 downto 0):="0001";
35 
36  type Typ_PortIO is
37   array(natural range <>) of std_logic_vector( Word-1 downto 0);
38       
39        type memory is 
40        array (natural range <>) of std_logic_vector(word-1 downto 0);
41
42type Core_i is
43        record
44                Instr_ack :std_logic;-- signal la prise en compte de l'instruction
45                Ready   :std_logic;-- indique que la dernière fonction est terminée
46                InitOk :std_logic; -- l'initialisation est terminée
47                Hold_Req :std_logic;--Demande DMA
48                RamSel :std_logic;-- indique le statut de la RAM (0 ->dispo 1->occupé par Core_MPI)
49                IsMain : std_logic; -- indique si la librairie est principal
50                Rank : natural range 0 to 15; --donne le rang du processus courant
51                Spawned: std_logic; --indique que ce module a été activé par la bibliothèque
52end record;     
53type Core_o is
54        record
55                Instr_en :std_logic;  -- active une instruction MPI
56                Hold_Ack :std_logic;-- Autorisation DMA
57                MemBusy :std_logic;-- active le refus de DMA (1 -> ignoré la requête DMA de MPI HCL)
58                Instruction :std_logic_vector (word-1 downto 0); -- fonction Mpi à exécuter     
59end record;
60type core_s is
61record
62    Rank : natural range 0 to 15; --donne le rang du processus courant
63                IntState1 : natural range 0 to 255; --permet de stocker l'état des MAE interne dans les procédures
64                IntState2 : natural range 0 to 255;
65                WinId :natural range  0 to 255; --stocke le dernier Id utilisé par WinCreate
66                GPost : std_logic_vector(15 downto 0); --etat de la fenêtre active
67                GStart : std_logic_vector(15 downto 0);
68                tmem : memory(0 to 3); --petite mémoire tampon pour stocker les variables statiques des MVPs
69end record;
70type core_io is
71record
72                I:core_i; --les entrées
73                O:core_o; --les sorties
74                S:core_s; --les signaux temporaires
75end record;
76
77type Core_io_old is
78        record
79                Instr_en :std_logic;  -- active une instruction MPI
80                Instr_ack :std_logic;-- signal la prise en compte de l'instruction
81                Ready   :std_logic;-- indique que la dernière fonction est terminée
82                InitOk :std_logic; -- l'initialisation est terminée
83                Hold_Req :std_logic;--Demande DMA
84                Hold_Ack :std_logic;-- Autorisation DMA
85                MemBusy :std_logic;-- active le refus de DMA (1 -> ignoré la requête DMA)
86                RamSel :std_logic;-- indique le statut de la RAM (0 ->dispo 1->occupé par Core_MPI)
87                IntState1 : natural range 0 to 255; --permet de stocker l'état des MAE interne dans les procédures
88                IntState2 : natural range 0 to 255;
89                Instruction :std_logic_vector (word-1 downto 0);
90                WinId :natural range  0 to 255; --stocke le dernier Id utilisé par WinCreate
91                IsMain : std_logic; -- indique si la librairie est principal
92                Rank : natural range 0 to 15; --donne le rang du processus courant
93                Spawned: std_logic; --indique que ce module a été activé par la bibliothèque
94end record;
95
96type typ_dpram_i is
97record
98                data_out :  STD_LOGIC_VECTOR (Word-1 downto 0); 
99                                                 
100end record;       
101type typ_dpram_o is
102record
103           clk_wr :  STD_LOGIC;
104           clk_rd :  STD_LOGIC;
105                we     :  STD_LOGIC;
106                ena    :  STD_LOGIC;
107                enb    :  STD_LOGIC;
108                addr_wr:  STD_LOGIC_VECTOR (ADRLEN-1 downto 0);
109                addr_rd :  STD_LOGIC_VECTOR (ADRLEN-1 downto 0);
110                data_in  :  STD_LOGIC_VECTOR (Word-1 downto 0); 
111end record;     
112type typ_dpram is
113record
114O : typ_dpram_o;
115I : typ_dpram_I;
116end record;   
117type Typ_MPIPort_in is
118record
119                          instruction :   STD_LOGIC_VECTOR (Word -1 downto 0);
120           instruction_en :  STD_LOGIC;
121                         
122
123                          packet_ack : std_logic;
124           ram_data_out :  STD_LOGIC_VECTOR (Word-1 downto 0);
125                         
126                          hold_ack       :  STD_Logic;  --autorisation par l'application
127                          clk :  STD_LOGIC;
128           reset :  STD_LOGIC;
129                         
130end record;
131type Typ_MPIPort_out is
132record           
133         
134                         
135           ram_we :  STD_LOGIC;
136                          ram_en :  STD_LOGIC;
137                          ram_data_in : STD_LOGIC_VECTOR (WORD-1 downto 0);
138           ram_address_rd :  STD_LOGIC_VECTOR (ADRLEN-1 downto 0);
139                          ram_address_wr :  STD_LOGIC_VECTOR (ADRLEN-1 downto 0);
140                          packet_received : STD_LOGIC;
141                          barrier_completed : STD_LOGIC;
142           instruction_fifo_full : STD_LOGIC;
143                          PushOut :  STD_LOGIC_VECTOR (WORD-1 downto 0);
144                           
145           hold_req       : STD_Logic;  --requete vers application
146end record;
147
148Type Ar_MPIPort_In is array (positive range <>) of Typ_MPIPort_in;
149Type Ar_MPIPort_out is array (positive range <>) of Typ_MPIPort_out;
150type ar_DpRam is array (natural range <>) of typ_dpRam;
151-- Declare constants
152
153--  constant <constant_name>            : time := <time_unit> ns;
154--  constant <constant_name>            : integer := <value>;
155--
156-- Declare functions and procedure
157Component  SWITCH_GEN is     
158 generic(number_of_ports : positive := 8);
159     port(
160                -- ports d'entree
161           Port_in : in typ_portIO(1 to number_of_ports) ;
162--                       
163                         
164                          -- port de sortie
165                          Port_out : out  typ_portIO(1 to number_of_ports);
166--                       
167                          -- signaux de controle
168                          cmd_in_en : in std_logic_vector(number_of_ports downto 1);
169                          data_in_en : in std_logic_vector(number_of_ports downto 1);
170                          data_out_en : in std_logic_vector(number_of_ports downto 1);
171                          fifo_in_full : out std_logic_vector(number_of_ports downto 1);
172                          fifo_in_empty : out std_logic_vector(number_of_ports downto 1);
173                          data_available : out std_logic_vector(number_of_ports downto 1);
174                          clk       : in   STD_LOGIC;
175                          reset     : in   STD_LOGIC);
176end component SWITCH_GEN;
177-- déclaration des fonctions utilisées
178--functions d'initialisation
179--
180function init_core_i return Core_i;
181function init_core_o return Core_o;
182function init_core_s return Core_s;
183function init_core_io return Core_io;
184function init_dpRam return Typ_dpRam;
185--*****************************************************
186 FUNCTION all_ones(s1:std_logic_vector) return std_logic; 
187  --This function returns if the input vector has all ones and no zeros
188 FUNCTION all_zeros(s1:std_logic_vector) return std_logic; 
189  --This function returns if the input vector has all zeros and no ones
190 FUNCTION incr_vec(s1:std_logic_vector;en:std_logic) return std_logic_vector; 
191  --This function increments an std_logic_vector type by '1', without
192  --using any arithmatic
193
194  FUNCTION dcr_vec(s1:std_logic_vector;en:std_logic) return std_logic_vector; 
195  --This function decrements an std_logic_vector type by '1', without
196  --using any arithmatic
197  FUNCTION Rol_Vec(s1:std_logic_vector) return std_logic_vector;
198  --renvoie un std_logic_vector de taille ADRLEN
199  Function Stdlv (s1 : natural) return std_logic_vector;
200  --renvoie un std_logic_vector de taille width
201  Function Stdlv (s1 : natural;width:positive ) return std_logic_vector;
202  function image(L: bit_vector) return String;
203  function image(L: bit) return String;
204   function image(L: std_logic_vector) return String;
205  function image(L: std_logic) return String;
206  function Hex_to_Ascii(l : std_logic_vector(3 downto 0))return std_logic_vector;
207--  function HexImage(L: unsigned) return String;
208--  function HexImage(L: signed) return String;
209--  function HexImage(L: std_ulogic_vector) return String;
210--  function HexImage(L: std_logic_vector) return String;
211--  function HexImage(L: bit_vector) return String;
212end CoreTypes;
213
214
215Package body CoreTypes is
216
217
218FUNCTION incr_vec(s1:std_logic_vector;en:std_logic) return std_logic_vector is 
219                  --this function increments a std_logic_vector type by '1'
220        VARIABLE V : std_logic_vector(s1'high downto s1'low) ; 
221        VARIABLE tb : std_logic_vector(s1'high downto s1'low); 
222        BEGIN 
223        tb(s1'low) := en; 
224        V := s1; 
225        for i in (V'low + 1) to V'high loop 
226            tb(i) := V(i - 1) and tb(i -1); 
227        end loop; 
228        for i in V'low to V'high loop 
229            if(tb(i) = '1') then 
230                V(i) := not(V(i)); 
231            end if; 
232        end loop; 
233        return V; 
234        end incr_vec; -- end function
235
236FUNCTION  dcr_vec(s1:std_logic_vector;en:std_logic) return std_logic_vector is 
237                  --this function decrements a std_logic_vector type by '1'
238        VARIABLE V : std_logic_vector(s1'high downto s1'low) ; 
239        VARIABLE tb : std_logic_vector(s1'high downto s1'low); 
240        BEGIN 
241        tb(s1'low) := not(en); 
242        V := s1; 
243        for i in (V'low + 1) to V'high loop 
244            tb(i) := V(i - 1) or tb(i -1); 
245        end loop; 
246        for i in V'low to V'high loop 
247            if(tb(i) = '0') then 
248                V(i) := not(V(i)); 
249            end if; 
250        end loop; 
251        return V; 
252        end dcr_vec; -- end function
253FUNCTION all_ones(s1:std_logic_vector) return std_logic is 
254                  --this function tells if all bits of a vector are '1'
255                  --return value Z is '1', then vector has all 1 bits
256        --VARIABLE V : std_logic_vector(s1'high downto s1'low) ;
257        VARIABLE Z : std_logic; 
258        BEGIN 
259        Z := s1(s1'low); 
260        FOR i IN (s1'low+1) to s1'high LOOP 
261            Z := Z AND s1(i); 
262        END LOOP; 
263        RETURN Z; 
264        END all_ones; -- end function
265FUNCTION all_zeros(s1:std_logic_vector) return std_logic is 
266                  --this function tells if all bits of a vector are '0'
267                  --return value Z if '1', then vector has all 0 bits
268        --VARIABLE V : std_logic_vector(s1'high downto s1'low) ;
269        VARIABLE Z : std_logic; 
270        BEGIN 
271        Z := '0'; 
272        FOR i IN (s1'low) to s1'high LOOP 
273            Z := Z OR s1(i); 
274        END LOOP; 
275        RETURN not(Z); 
276        END all_zeros; -- end function
277                 
278FUNCTION Rol_Vec(s1:std_logic_vector) return std_logic_vector is
279--cette fonction fait roter un STD_logic d'un pas vers la gauche
280VARIABLE V : std_logic_vector(s1'high downto s1'low) ; 
281        VARIABLE lb : std_logic :=s1(s1'left);
282        BEGIN 
283     
284        for i in V'left  downto (V'right+1) loop 
285            V(i) := s1(i - 1) ; 
286        end loop; 
287        V(V'right):=lb;
288        return V; 
289        end Rol_vec;
290 Function Stdlv (s1 : natural ) return std_logic_vector is
291VARIABLE V : std_logic_vector(ADRLEN-1 downto 0);
292 begin
293        V:=std_logic_vector(to_unsigned(s1,ADRLEN));
294        return V;
295 end stdlv;
296 Function Stdlv (s1 : natural;width:positive ) return std_logic_vector is
297VARIABLE V : std_logic_vector(width-1 downto 0);
298 begin
299        V:=std_logic_vector(to_unsigned(s1,width));
300        return V;
301 end stdlv;
302 
303 -- Start of heximage functions
304--function HexImage(L: bit_vector) return String is
305--begin
306--return(HexImage(imge(L)));
307--end function HexImage;
308--
309--function HexImage(L: std_ulogic_vector) return String is
310--begin
311--return(HexImage(image(to_x01(L))));
312--end function HexImage;
313
314--function HexImage(L: std_logic_vector) return String is
315--begin
316--return(HexImage(imge(to_x01(L))));
317--end function HexImage;
318--
319--function HexImage(L: signed) return String is
320--begin
321--return(HexImage(imge(L)));
322--end function HexImage;
323--
324--function HexImage(L: unsigned) return String is
325--begin
326--return(HexImage(image(L)));
327--end function HexImage;
328-- End of heximage functions
329-- Start of an example image function
330function Hex_to_Ascii(l : std_logic_vector(3 downto 0)) return std_logic_vector is
331variable he:std_logic_vector(7 downto 0);
332variable val : unsigned(7 downto 0);
333begin
334val:= unsigned(X"0" & unsigned(l));
335
336if val<10 then
337he:=std_logic_vector(val+48);
338else
339he:=std_logic_vector(val+55);
340end if;
341return he;
342end function;
343function image(L: bit) return String is
344variable bit_image: String(1 to 1) := bit'image(L);
345begin
346return(bit_image(1 to 1));
347end function image;
348
349
350function image(L: std_logic) return String is
351variable bit_image: String(1 to 3) := std_logic'image(L);
352begin
353return(bit_image(1 to 1));
354end function image;
355
356function image(L: bit_vector) return String is
357variable Lx: bit_vector(1 to L'length);
358variable RetVal: String(1 to L'length);
359begin
360Lx := L;
361for i in Lx'range loop
362RetVal(i to i) := image(Lx(i));
363end loop;
364return(RetVal);
365end function image;
366
367
368function image(L: std_logic_vector) return String is
369variable Lx: std_logic_vector(1 to L'length);
370variable RetVal: String(1 to L'length);
371begin
372Lx := L;
373for i in Lx'range loop
374RetVal(i to i) := image(Lx(i));
375end loop;
376return(RetVal);
377end function image;
378--***************************************************
379--functions d'initialisation
380 function init_memory(size : natural;val :std_logic_vector(Word-1 downto 0):=(others=>'0')) return memory is
381variable dt: memory(0 to size-1);
382 begin
383 for i in 0 to size-1 loop
384 dt(i):=val;
385 end loop;
386 return dt;
387 end function;
388function init_DpRam return typ_dpram is
389variable sram : typ_dpRam;
390
391begin
392                sram.I.data_out :=(others=>'0'); 
393          sram.o.clk_wr :='0';
394          sram.o.clk_rd :='0';
395                sram.o.we     :='0';
396                sram.o.ena    :='0';
397                sram.o.enb    :='0';
398                sram.o.addr_wr:=(others=>'0');
399                sram.o.addr_rd:=(others=>'0');
400                sram.o.data_in:=(others=>'0'); 
401
402return sram;
403end function;
404
405function init_core_i return Core_i is
406variable coreI : Core_i;
407begin
408 
409                corei.Instr_ack :='0'; -- signal la prise en compte de l'instruction
410                corei.Ready   :='0';-- indique que la dernière fonction est terminée
411                corei.InitOk :='0'; -- l'initialisation est terminée
412                corei.Hold_Req :='0';--Demande DMA
413                corei.RamSel :='0';-- indique le statut de la RAM (0 ->dispo 1->occupé par Core_MPI)
414                corei.IsMain :='0'; -- indique si la librairie est principal
415                corei.Rank :=0; --donne le rang du processus courant
416                corei.Spawned:='0'; --indique que ce module a été activé par la bibliothèque
417  return (corei);
418end function;
419function init_core_o return Core_o is
420variable coreO : Core_o;
421begin
422                 coreo.Instr_en :='0';  -- active une instruction MPI
423                coreo.Hold_Ack :='0';-- Autorisation DMA
424                coreo.MemBusy :='0';-- active le refus de DMA (1 -> ignoré la requête DMA de MPI HCL)
425                coreo.Instruction :=(others=>'0'); -- fonction Mpi à exécuter   
426return coreo;
427end function;
428function init_core_s return Core_s is
429
430variable coreS : Core_s;
431begin
432 cores.Rank :=0; --donne le rang du processus courant
433                 cores.IntState1 :=0; --permet de stocker l'état des MAE interne dans les procédures
434                 cores.IntState2 :=0;
435                 cores.WinId :=0; --stocke le dernier Id utilisé par WinCreate
436                 cores.GPost :=(others=>'0'); --etat de la fenêtre active
437                 cores.GStart :=(others=>'0');
438                 cores.tmem  :=init_memory(4); --petite mémoire tampon pour stocker les variables statiques des MVPs
439  return Cores ;
440end function;
441function init_core_io return Core_io is
442variable coreIO : Core_io;
443begin
444  CoreIO.O:=init_core_o;
445  CoreIO.I:=Init_Core_I;
446  CoreIO.S:=Init_Core_S;
447  return CoreIO;
448end function;
449
450end CoreTypes;
Note: See TracBrowser for help on using the repository browser.