[101] | 1 | -- Package File Template |
---|
| 2 | -- |
---|
| 3 | -- Purpose: This package defines supplemental types, subtypes, |
---|
| 4 | -- constants, and components |
---|
| 5 | |
---|
| 6 | |
---|
| 7 | library IEEE; |
---|
| 8 | use IEEE.STD_LOGIC_1164.all; |
---|
| 9 | use IEEE.numeric_std.all; |
---|
| 10 | package CoreTypes is |
---|
| 11 | CONSTANT Word :POSITIVE:= 8; |
---|
| 12 | CONSTANT ADRLEN:POSITIVE:=16; |
---|
| 13 | CONSTANT 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 |
---|
| 14 | CONSTANT IADR0 : NATURAL :=2; --Adresse basse de l'instruction |
---|
| 15 | CONSTANT IADR1 : natural :=3; |
---|
| 16 | CONSTANT CORE_BASE_ADR :natural range 0 to 65535:=4096; |
---|
| 17 | CONSTANT WIN_BASE_ADR :natural range 0 to 65535:=CORE_BASE_ADR+4; |
---|
| 18 | CONSTANT CORE_UPPER_ADR : natural range 0 to 255:=16; |
---|
| 19 | CONSTANT CORE_GET_ADR:natural:=CORE_BASE_ADR+526; |
---|
| 20 | CONSTANT CORE_PUT_ADR :natural:=CORE_BASE_ADR+516; |
---|
| 21 | CONSTANT core_INIT_ADR : natural:=CORE_BASE_ADR+512; |
---|
| 22 | CONSTANT CORE_WCREATE_ADR : natural := CORE_BASE_ADR+536; |
---|
| 23 | CONSTANT CORE_WCOMPL_ADR : natural := CORE_BASE_ADR+546; |
---|
| 24 | CONSTANT CORE_WPOST_ADR : natural := CORE_BASE_ADR+556; |
---|
| 25 | CONSTANT CORE_WWAIT_ADR : natural := CORE_BASE_ADR+566; |
---|
| 26 | CONSTANT CORE_WSYNC_ADR : natural := CORE_BASE_ADR+576; |
---|
| 27 | CONSTANT CORE_SPAWN_ADR : natural := CORE_BASE_ADR+586; |
---|
| 28 | CONSTANT CORE_Rank2port_BASE :NATURAL:=52; |
---|
| 29 | CONSTANT CORE_RANK_ADR : NATURAL:=CORE_BASE_ADR+CORE_Rank2Port_Base; |
---|
| 30 | CONSTANT WIN0_ADR :natural :=CORE_BASE_ADR+4; |
---|
| 31 | CONSTANT WIN1_ADR :natural :=CORE_BASE_ADR+20; |
---|
| 32 | CONSTANT WIN2_ADR :natural :=CORE_BASE_ADR+36; |
---|
| 33 | CONSTANT WIN3_ADR :natural :=CORE_BASE_ADR+52; |
---|
| 34 | CONSTANT 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 | |
---|
| 42 | type 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 |
---|
| 52 | end record; |
---|
| 53 | type 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 |
---|
| 59 | end record; |
---|
| 60 | type core_s is |
---|
| 61 | record |
---|
| 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 |
---|
| 69 | end record; |
---|
| 70 | type core_io is |
---|
| 71 | record |
---|
| 72 | I:core_i; --les entrées |
---|
| 73 | O:core_o; --les sorties |
---|
| 74 | S:core_s; --les signaux temporaires |
---|
| 75 | end record; |
---|
| 76 | |
---|
| 77 | type 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 |
---|
| 94 | end record; |
---|
| 95 | |
---|
| 96 | type typ_dpram_i is |
---|
| 97 | record |
---|
| 98 | data_out : STD_LOGIC_VECTOR (Word-1 downto 0); |
---|
| 99 | |
---|
| 100 | end record; |
---|
| 101 | type typ_dpram_o is |
---|
| 102 | record |
---|
| 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); |
---|
| 111 | end record; |
---|
| 112 | type typ_dpram is |
---|
| 113 | record |
---|
| 114 | O : typ_dpram_o; |
---|
| 115 | I : typ_dpram_I; |
---|
| 116 | end record; |
---|
| 117 | type Typ_MPIPort_in is |
---|
| 118 | record |
---|
| 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 | |
---|
| 130 | end record; |
---|
| 131 | type Typ_MPIPort_out is |
---|
| 132 | record |
---|
| 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 |
---|
| 146 | end record; |
---|
| 147 | |
---|
| 148 | Type Ar_MPIPort_In is array (positive range <>) of Typ_MPIPort_in; |
---|
| 149 | Type Ar_MPIPort_out is array (positive range <>) of Typ_MPIPort_out; |
---|
| 150 | |
---|
| 151 | -- Declare constants |
---|
| 152 | |
---|
| 153 | -- constant <constant_name> : time := <time_unit> ns; |
---|
| 154 | -- constant <constant_name> : integer := <value>; |
---|
| 155 | -- |
---|
| 156 | -- Declare functions and procedure |
---|
| 157 | Component 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); |
---|
| 176 | end 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 HexImage(L: unsigned) return String; |
---|
| 200 | -- function HexImage(L: signed) return String; |
---|
| 201 | -- function HexImage(L: std_ulogic_vector) return String; |
---|
| 202 | -- function HexImage(L: std_logic_vector) return String; |
---|
| 203 | -- function HexImage(L: bit_vector) return String; |
---|
| 204 | end CoreTypes; |
---|
| 205 | |
---|
| 206 | |
---|
| 207 | Package body CoreTypes is |
---|
| 208 | |
---|
| 209 | |
---|
| 210 | FUNCTION incr_vec(s1:std_logic_vector;en:std_logic) return std_logic_vector is |
---|
| 211 | --this function increments a std_logic_vector type by '1' |
---|
| 212 | VARIABLE V : std_logic_vector(s1'high downto s1'low) ; |
---|
| 213 | VARIABLE tb : std_logic_vector(s1'high downto s1'low); |
---|
| 214 | BEGIN |
---|
| 215 | tb(s1'low) := en; |
---|
| 216 | V := s1; |
---|
| 217 | for i in (V'low + 1) to V'high loop |
---|
| 218 | tb(i) := V(i - 1) and tb(i -1); |
---|
| 219 | end loop; |
---|
| 220 | for i in V'low to V'high loop |
---|
| 221 | if(tb(i) = '1') then |
---|
| 222 | V(i) := not(V(i)); |
---|
| 223 | end if; |
---|
| 224 | end loop; |
---|
| 225 | return V; |
---|
| 226 | end incr_vec; -- end function |
---|
| 227 | |
---|
| 228 | FUNCTION dcr_vec(s1:std_logic_vector;en:std_logic) return std_logic_vector is |
---|
| 229 | --this function decrements a std_logic_vector type by '1' |
---|
| 230 | VARIABLE V : std_logic_vector(s1'high downto s1'low) ; |
---|
| 231 | VARIABLE tb : std_logic_vector(s1'high downto s1'low); |
---|
| 232 | BEGIN |
---|
| 233 | tb(s1'low) := not(en); |
---|
| 234 | V := s1; |
---|
| 235 | for i in (V'low + 1) to V'high loop |
---|
| 236 | tb(i) := V(i - 1) or tb(i -1); |
---|
| 237 | end loop; |
---|
| 238 | for i in V'low to V'high loop |
---|
| 239 | if(tb(i) = '0') then |
---|
| 240 | V(i) := not(V(i)); |
---|
| 241 | end if; |
---|
| 242 | end loop; |
---|
| 243 | return V; |
---|
| 244 | end dcr_vec; -- end function |
---|
| 245 | FUNCTION all_ones(s1:std_logic_vector) return std_logic is |
---|
| 246 | --this function tells if all bits of a vector are '1' |
---|
| 247 | --return value Z is '1', then vector has all 1 bits |
---|
| 248 | --VARIABLE V : std_logic_vector(s1'high downto s1'low) ; |
---|
| 249 | VARIABLE Z : std_logic; |
---|
| 250 | BEGIN |
---|
| 251 | Z := s1(s1'low); |
---|
| 252 | FOR i IN (s1'low+1) to s1'high LOOP |
---|
| 253 | Z := Z AND s1(i); |
---|
| 254 | END LOOP; |
---|
| 255 | RETURN Z; |
---|
| 256 | END all_ones; -- end function |
---|
| 257 | FUNCTION all_zeros(s1:std_logic_vector) return std_logic is |
---|
| 258 | --this function tells if all bits of a vector are '0' |
---|
| 259 | --return value Z if '1', then vector has all 0 bits |
---|
| 260 | --VARIABLE V : std_logic_vector(s1'high downto s1'low) ; |
---|
| 261 | VARIABLE Z : std_logic; |
---|
| 262 | BEGIN |
---|
| 263 | Z := '0'; |
---|
| 264 | FOR i IN (s1'low) to s1'high LOOP |
---|
| 265 | Z := Z OR s1(i); |
---|
| 266 | END LOOP; |
---|
| 267 | RETURN not(Z); |
---|
| 268 | END all_zeros; -- end function |
---|
| 269 | |
---|
| 270 | FUNCTION Rol_Vec(s1:std_logic_vector) return std_logic_vector is |
---|
| 271 | --cette fonction fait roter un STD_logic d'un pas vers la gauche |
---|
| 272 | VARIABLE V : std_logic_vector(s1'high downto s1'low) ; |
---|
| 273 | VARIABLE lb : std_logic :=s1(s1'left); |
---|
| 274 | BEGIN |
---|
| 275 | |
---|
| 276 | for i in V'left downto (V'right+1) loop |
---|
| 277 | V(i) := s1(i - 1) ; |
---|
| 278 | end loop; |
---|
| 279 | V(V'right):=lb; |
---|
| 280 | return V; |
---|
| 281 | end Rol_vec; |
---|
| 282 | Function Stdlv (s1 : natural ) return std_logic_vector is |
---|
| 283 | VARIABLE V : std_logic_vector(ADRLEN-1 downto 0); |
---|
| 284 | begin |
---|
| 285 | V:=std_logic_vector(to_unsigned(s1,ADRLEN)); |
---|
| 286 | return V; |
---|
| 287 | end stdlv; |
---|
| 288 | Function Stdlv (s1 : natural;width:positive ) return std_logic_vector is |
---|
| 289 | VARIABLE V : std_logic_vector(width-1 downto 0); |
---|
| 290 | begin |
---|
| 291 | V:=std_logic_vector(to_unsigned(s1,width)); |
---|
| 292 | return V; |
---|
| 293 | end stdlv; |
---|
| 294 | |
---|
| 295 | -- Start of heximage functions |
---|
| 296 | --function HexImage(L: bit_vector) return String is |
---|
| 297 | --begin |
---|
| 298 | --return(HexImage(imge(L))); |
---|
| 299 | --end function HexImage; |
---|
| 300 | -- |
---|
| 301 | --function HexImage(L: std_ulogic_vector) return String is |
---|
| 302 | --begin |
---|
| 303 | --return(HexImage(image(to_x01(L)))); |
---|
| 304 | --end function HexImage; |
---|
| 305 | |
---|
| 306 | --function HexImage(L: std_logic_vector) return String is |
---|
| 307 | --begin |
---|
| 308 | --return(HexImage(imge(to_x01(L)))); |
---|
| 309 | --end function HexImage; |
---|
| 310 | -- |
---|
| 311 | --function HexImage(L: signed) return String is |
---|
| 312 | --begin |
---|
| 313 | --return(HexImage(imge(L))); |
---|
| 314 | --end function HexImage; |
---|
| 315 | -- |
---|
| 316 | --function HexImage(L: unsigned) return String is |
---|
| 317 | --begin |
---|
| 318 | --return(HexImage(image(L))); |
---|
| 319 | --end function HexImage; |
---|
| 320 | -- End of heximage functions |
---|
| 321 | -- Start of an example image function |
---|
| 322 | function image(L: bit) return String is |
---|
| 323 | variable bit_image: String(1 to 1) := bit'image(L); |
---|
| 324 | begin |
---|
| 325 | return(bit_image(1 to 1)); |
---|
| 326 | end function image; |
---|
| 327 | |
---|
| 328 | |
---|
| 329 | function image(L: std_logic) return String is |
---|
| 330 | variable bit_image: String(1 to 3) := std_logic'image(L); |
---|
| 331 | begin |
---|
| 332 | return(bit_image(1 to 1)); |
---|
| 333 | end function image; |
---|
| 334 | |
---|
| 335 | function image(L: bit_vector) return String is |
---|
| 336 | variable Lx: bit_vector(1 to L'length); |
---|
| 337 | variable RetVal: String(1 to L'length); |
---|
| 338 | begin |
---|
| 339 | Lx := L; |
---|
| 340 | for i in Lx'range loop |
---|
| 341 | RetVal(i to i) := image(Lx(i)); |
---|
| 342 | end loop; |
---|
| 343 | return(RetVal); |
---|
| 344 | end function image; |
---|
| 345 | |
---|
| 346 | |
---|
| 347 | function image(L: std_logic_vector) return String is |
---|
| 348 | variable Lx: std_logic_vector(1 to L'length); |
---|
| 349 | variable RetVal: String(1 to L'length); |
---|
| 350 | begin |
---|
| 351 | Lx := L; |
---|
| 352 | for i in Lx'range loop |
---|
| 353 | RetVal(i to i) := image(Lx(i)); |
---|
| 354 | end loop; |
---|
| 355 | return(RetVal); |
---|
| 356 | end function image; |
---|
| 357 | end CoreTypes; |
---|