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

Last change on this file since 144 was 143, checked in by rolagamo, 10 years ago
File size: 15.4 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 
179 FUNCTION all_ones(s1:std_logic_vector) return std_logic;
180  --This function returns if the input vector has all ones and no zeros
181 FUNCTION all_zeros(s1:std_logic_vector) return std_logic;
182  --This function returns if the input vector has all zeros and no ones
183 FUNCTION incr_vec(s1:std_logic_vector;en:std_logic) return std_logic_vector;
184  --This function increments an std_logic_vector type by '1', without
185  --using any arithmatic
186
187  FUNCTION dcr_vec(s1:std_logic_vector;en:std_logic) return std_logic_vector;
188  --This function decrements an std_logic_vector type by '1', without
189  --using any arithmatic
190  FUNCTION Rol_Vec(s1:std_logic_vector) return std_logic_vector;
191  --renvoie un std_logic_vector de taille ADRLEN
192  Function Stdlv (s1 : natural) return std_logic_vector;
193  --renvoie un std_logic_vector de taille width
194  Function Stdlv (s1 : natural;width:positive ) return std_logic_vector;
195  function image(L: bit_vector) return String;
196  function image(L: bit) return String;
197   function image(L: std_logic_vector) return String;
198  function image(L: std_logic) return String;
199  function Hex_to_Ascii(l : std_logic_vector(3 downto 0))return std_logic_vector;
200--  function HexImage(L: unsigned) return String;
201--  function HexImage(L: signed) return String;
202--  function HexImage(L: std_ulogic_vector) return String;
203--  function HexImage(L: std_logic_vector) return String;
204--  function HexImage(L: bit_vector) return String;
205end CoreTypes;
206
207
208Package body CoreTypes is
209
210
211FUNCTION incr_vec(s1:std_logic_vector;en:std_logic) return std_logic_vector is
212                  --this function increments a std_logic_vector type by '1'
213        VARIABLE V : std_logic_vector(s1'high downto s1'low) ;
214        VARIABLE tb : std_logic_vector(s1'high downto s1'low);
215        BEGIN
216        tb(s1'low) := en;
217        V := s1;
218        for i in (V'low + 1) to V'high loop
219            tb(i) := V(i - 1) and tb(i -1);
220        end loop;
221        for i in V'low to V'high loop
222            if(tb(i) = '1') then
223                V(i) := not(V(i));
224            end if;
225        end loop;
226        return V;
227        end incr_vec; -- end function
228
229FUNCTION  dcr_vec(s1:std_logic_vector;en:std_logic) return std_logic_vector is
230                  --this function decrements a std_logic_vector type by '1'
231        VARIABLE V : std_logic_vector(s1'high downto s1'low) ;
232        VARIABLE tb : std_logic_vector(s1'high downto s1'low);
233        BEGIN
234        tb(s1'low) := not(en);
235        V := s1;
236        for i in (V'low + 1) to V'high loop
237            tb(i) := V(i - 1) or tb(i -1);
238        end loop;
239        for i in V'low to V'high loop
240            if(tb(i) = '0') then
241                V(i) := not(V(i));
242            end if;
243        end loop;
244        return V;
245        end dcr_vec; -- end function
246FUNCTION all_ones(s1:std_logic_vector) return std_logic is
247                  --this function tells if all bits of a vector are '1'
248                  --return value Z is '1', then vector has all 1 bits
249        --VARIABLE V : std_logic_vector(s1'high downto s1'low) ;
250        VARIABLE Z : std_logic;
251        BEGIN
252        Z := s1(s1'low);
253        FOR i IN (s1'low+1) to s1'high LOOP
254            Z := Z AND s1(i);
255        END LOOP;
256        RETURN Z;
257        END all_ones; -- end function
258FUNCTION all_zeros(s1:std_logic_vector) return std_logic is
259                  --this function tells if all bits of a vector are '0'
260                  --return value Z if '1', then vector has all 0 bits
261        --VARIABLE V : std_logic_vector(s1'high downto s1'low) ;
262        VARIABLE Z : std_logic;
263        BEGIN
264        Z := '0';
265        FOR i IN (s1'low) to s1'high LOOP
266            Z := Z OR s1(i);
267        END LOOP;
268        RETURN not(Z);
269        END all_zeros; -- end function
270                 
271FUNCTION Rol_Vec(s1:std_logic_vector) return std_logic_vector is
272--cette fonction fait roter un STD_logic d'un pas vers la gauche
273VARIABLE V : std_logic_vector(s1'high downto s1'low) ;
274        VARIABLE lb : std_logic :=s1(s1'left);
275        BEGIN
276     
277        for i in V'left  downto (V'right+1) loop
278            V(i) := s1(i - 1) ;
279        end loop;
280        V(V'right):=lb;
281        return V;
282        end Rol_vec;
283 Function Stdlv (s1 : natural ) return std_logic_vector is
284VARIABLE V : std_logic_vector(ADRLEN-1 downto 0);
285 begin
286        V:=std_logic_vector(to_unsigned(s1,ADRLEN));
287        return V;
288 end stdlv;
289 Function Stdlv (s1 : natural;width:positive ) return std_logic_vector is
290VARIABLE V : std_logic_vector(width-1 downto 0);
291 begin
292        V:=std_logic_vector(to_unsigned(s1,width));
293        return V;
294 end stdlv;
295 
296 -- Start of heximage functions
297--function HexImage(L: bit_vector) return String is
298--begin
299--return(HexImage(imge(L)));
300--end function HexImage;
301--
302--function HexImage(L: std_ulogic_vector) return String is
303--begin
304--return(HexImage(image(to_x01(L))));
305--end function HexImage;
306
307--function HexImage(L: std_logic_vector) return String is
308--begin
309--return(HexImage(imge(to_x01(L))));
310--end function HexImage;
311--
312--function HexImage(L: signed) return String is
313--begin
314--return(HexImage(imge(L)));
315--end function HexImage;
316--
317--function HexImage(L: unsigned) return String is
318--begin
319--return(HexImage(image(L)));
320--end function HexImage;
321-- End of heximage functions
322-- Start of an example image function
323function Hex_to_Ascii(l : std_logic_vector(3 downto 0)) return std_logic_vector is
324variable he:std_logic_vector(7 downto 0);
325variable val : unsigned(7 downto 0);
326begin
327val:= unsigned(X"0" & unsigned(l));
328
329if val<10 then
330he:=std_logic_vector(val+48);
331else
332he:=std_logic_vector(val+55);
333end if;
334return he;
335end function;
336function image(L: bit) return String is
337variable bit_image: String(1 to 1) := bit'image(L);
338begin
339return(bit_image(1 to 1));
340end function image;
341
342
343function image(L: std_logic) return String is
344variable bit_image: String(1 to 3) := std_logic'image(L);
345begin
346return(bit_image(1 to 1));
347end function image;
348
349function image(L: bit_vector) return String is
350variable Lx: bit_vector(1 to L'length);
351variable RetVal: String(1 to L'length);
352begin
353Lx := L;
354for i in Lx'range loop
355RetVal(i to i) := image(Lx(i));
356end loop;
357return(RetVal);
358end function image;
359
360
361function image(L: std_logic_vector) return String is
362variable Lx: std_logic_vector(1 to L'length);
363variable RetVal: String(1 to L'length);
364begin
365Lx := L;
366for i in Lx'range loop
367RetVal(i to i) := image(Lx(i));
368end loop;
369return(RetVal);
370end function image;
371--***************************************************
372--functions d'initialisation
373 function init_memory(size : natural;val :std_logic_vector(Word-1 downto 0):=(others=>'0')) return memory is
374variable dt: memory(0 to size-1);
375 begin
376 for i in 0 to size-1 loop
377 dt(i):=val;
378 end loop;
379 return dt;
380 end function;
381function init_DpRam return typ_dpram is
382variable sram : typ_dpRam;
383
384begin
385                sram.I.data_out :=(others=>'0');
386          sram.o.clk_wr :='0';
387          sram.o.clk_rd :='0';
388                sram.o.we     :='0';
389                sram.o.ena    :='0';
390                sram.o.enb    :='0';
391                sram.o.addr_wr:=(others=>'0');
392                sram.o.addr_rd:=(others=>'0');
393                sram.o.data_in:=(others=>'0');
394
395return sram;
396end function;
397
398function init_core_i return Core_i is
399variable coreI : Core_i;
400begin
401 
402                corei.Instr_ack :='0'; -- signal la prise en compte de l'instruction
403                corei.Ready   :='0';-- indique que la dernière fonction est terminée
404                corei.InitOk :='0'; -- l'initialisation est terminée
405                corei.Hold_Req :='0';--Demande DMA
406                corei.RamSel :='0';-- indique le statut de la RAM (0 ->dispo 1->occupé par Core_MPI)
407                corei.IsMain :='0'; -- indique si la librairie est principal
408                corei.Rank :=0; --donne le rang du processus courant
409                corei.Spawned:='0'; --indique que ce module a été activé par la bibliothèque
410  return (corei);
411end function;
412function init_core_o return Core_o is
413variable coreO : Core_o;
414begin
415                 coreo.Instr_en :='0';  -- active une instruction MPI
416                coreo.Hold_Ack :='0';-- Autorisation DMA
417                coreo.MemBusy :='0';-- active le refus de DMA (1 -> ignoré la requête DMA de MPI HCL)
418                coreo.Instruction :=(others=>'0'); -- fonction Mpi à exécuter   
419return coreo;
420end function;
421function init_core_s return Core_s is
422
423variable coreS : Core_s;
424begin
425 cores.Rank :=0; --donne le rang du processus courant
426                 cores.IntState1 :=0; --permet de stocker l'état des MAE interne dans les procédures
427                 cores.IntState2 :=0;
428                 cores.WinId :=0; --stocke le dernier Id utilisé par WinCreate
429                 cores.GPost :=(others=>'0'); --etat de la fenêtre active
430                 cores.GStart :=(others=>'0');
431                 cores.tmem  :=init_memory(4); --petite mémoire tampon pour stocker les variables statiques des MVPs
432  return Cores ;
433end function;
434function init_core_io return Core_io is
435variable coreIO : Core_io;
436begin
437  CoreIO.O:=init_core_o;
438  CoreIO.I:=Init_Core_I;
439  CoreIO.S:=Init_Core_S;
440  return CoreIO;
441end function;
442
443end CoreTypes;
Note: See TracBrowser for help on using the repository browser.