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