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

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