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

Last change on this file since 69 was 69, checked in by rolagamo, 11 years ago
File size: 10.9 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_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
57end record;
58
59type typ_dpram is
60record
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                         
74end record;       
75type Typ_MPIPort_in is
76record
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                         
88end record;
89type Typ_MPIPort_out is
90record           
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
104end record;
105
106Type Ar_MPIPort_In is array (positive range <>) of Typ_MPIPort_in;
107Type 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
115Component  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);
134end 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;
162end CoreTypes;
163
164
165Package body CoreTypes is
166
167
168FUNCTION 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
186FUNCTION  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
203FUNCTION 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
215FUNCTION 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                 
228FUNCTION 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
230VARIABLE 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
241VARIABLE 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
247VARIABLE 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
280function image(L: bit) return String is
281variable bit_image: String(1 to 1) := bit'image(L);
282begin
283return(bit_image(1 to 1));
284end function image;
285
286
287function image(L: std_logic) return String is
288variable bit_image: String(1 to 3) := std_logic'image(L);
289begin
290return(bit_image(1 to 1));
291end function image;
292
293function image(L: bit_vector) return String is
294variable Lx: bit_vector(1 to L'length);
295variable RetVal: String(1 to L'length);
296begin
297Lx := L;
298for i in Lx'range loop
299RetVal(i to i) := image(Lx(i));
300end loop;
301return(RetVal);
302end function image;
303
304
305function image(L: std_logic_vector) return String is
306variable Lx: std_logic_vector(1 to L'length);
307variable RetVal: String(1 to L'length);
308begin
309Lx := L;
310for i in Lx'range loop
311RetVal(i to i) := image(Lx(i));
312end loop;
313return(RetVal);
314end function image;
315end CoreTypes;
Note: See TracBrowser for help on using the repository browser.