source: PROJECT_CORE_MPI/SWITCH_GEN/BRANCHES/v0.03/CoreTypes.vhd @ 71

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