Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 336 | f9daq | 1 | ---------------------------------------------------------------------------------- |
| 2 | -- Company: |
||
| 3 | -- Engineer: |
||
| 4 | -- |
||
| 5 | -- Create Date: 14.10.2018 11:13:46 |
||
| 6 | -- Design Name: |
||
| 7 | -- Module Name: PE_unit - Behavioral |
||
| 8 | -- Project Name: |
||
| 9 | -- Target Devices: |
||
| 10 | -- Tool Versions: |
||
| 11 | -- Description: |
||
| 12 | -- |
||
| 13 | -- Dependencies: |
||
| 14 | -- |
||
| 15 | -- Revision: |
||
| 16 | -- Revision 0.01 - File Created |
||
| 17 | -- Additional Comments: |
||
| 18 | -- |
||
| 19 | ---------------------------------------------------------------------------------- |
||
| 20 | |||
| 21 | |||
| 22 | library IEEE; |
||
| 23 | use IEEE.STD_LOGIC_1164.ALL; |
||
| 24 | |||
| 25 | -- Uncomment the following library declaration if using |
||
| 26 | -- arithmetic functions with Signed or Unsigned values |
||
| 27 | use IEEE.NUMERIC_STD.ALL; |
||
| 28 | |||
| 29 | -- Uncomment the following library declaration if instantiating |
||
| 30 | -- any Xilinx leaf cells in this code. |
||
| 31 | --library UNISIM; |
||
| 32 | --use UNISIM.VComponents.all; |
||
| 33 | |||
| 34 | entity PE_unit is |
||
| 35 | |||
| 36 | generic ( |
||
| 37 | bit_num : natural := 10; --number of data bits |
||
| 38 | bin_num : natural := 1024; --number of histogram bins |
||
| 39 | buffer_size : natural := 5; -- buffer size in bits, 5 bit gets 32 different values |
||
| 40 | byte: natural := 8; |
||
| 41 | mode: string := "MODE_3" -- modes of operation: MODE_1 = navaden algoritm, MODE_2 = odklop bufferja in 1 enota, MODE_3 = novo od 30.11.2018 naprej |
||
| 42 | ); |
||
| 43 | |||
| 44 | port ( |
||
| 45 | clk: in std_logic; |
||
| 46 | UC_wr_en: in std_logic; --microprocessor tells PE_unit that it read current data and is ready for the next one -- ustavljanje, pošiljaj histogram takrat, ko je procesor ready, ne vsak clk cikel |
||
| 47 | PE_START: in std_logic; --flag that tells PE_unit that BRAM_buffer is full |
||
| 48 | data_in : in unsigned ( (bit_num - 1) downto 0 ); --data for PE unit from BRAM_buffer |
||
| 49 | BUFF_addr: out unsigned ( (buffer_size - 1) downto 0 ); -- address for BRAM_buffer, goes to PE_addr |
||
| 50 | PE_wr_rd_en: out std_logic; -- signal to tell BRAM_buffer to start sending when '1' and to tell PE_unit to start sending when '0' |
||
| 51 | data_out: out unsigned ( buffer_size downto 0 ); -- output data |
||
| 52 | UC_rd_en_final: out std_logic; --tells microprocessor that whole histogram data is ready to be sent from PE_unit to microprocessor |
||
| 53 | UC_rd_en_current: out std_logic; -- signal, ki procesorju omogoci sprotno branje iz brama2 |
||
| 54 | ---MODE_3 additional ports--- |
||
| 55 | write_A_M3: in std_logic; --gre na write_A, ko smo v postopku branja, |
||
| 56 | ADC_unit_RESET: out std_logic; |
||
| 57 | PE_RESET: in std_logic |
||
| 58 | ); |
||
| 59 | end PE_unit; |
||
| 60 | |||
| 61 | architecture Behavioral of PE_unit is |
||
| 62 | |||
| 63 | ---------------------COMPONENTS----------------------- |
||
| 64 | component dual_port_bram is |
||
| 65 | |||
| 66 | generic ( |
||
| 67 | bit_num : natural := 10; |
||
| 68 | bin_num : natural := 1024; --number of histogram bins |
||
| 69 | buffer_size : natural := 5 -- buffer size in bits, 5 bit gets 32 different values |
||
| 70 | |||
| 71 | ); |
||
| 72 | |||
| 73 | port ( |
||
| 74 | -- A side -- |
||
| 75 | clk_A: in std_logic; |
||
| 76 | bram_en_A: in std_logic; |
||
| 77 | wr_en_A: in std_logic; |
||
| 78 | addr_A: in unsigned ( (bit_num - 1) downto 0 ); |
||
| 79 | data_in_A: in unsigned ( buffer_size downto 0 ); |
||
| 80 | data_out_A: out unsigned ( buffer_size downto 0 ); |
||
| 81 | |||
| 82 | -- B side -- |
||
| 83 | clk_B: in std_logic; |
||
| 84 | bram_en_B: in std_logic; |
||
| 85 | wr_en_B: in std_logic; |
||
| 86 | addr_B: in unsigned ( (bit_num - 1) downto 0 ); |
||
| 87 | data_in_B: in unsigned ( buffer_size downto 0 ); |
||
| 88 | data_out_B: out unsigned ( buffer_size downto 0 ) |
||
| 89 | ); |
||
| 90 | |||
| 91 | end component; |
||
| 92 | |||
| 93 | |||
| 94 | |||
| 95 | ------------------SIGNALS----------------------------- |
||
| 96 | |||
| 97 | signal zeros : unsigned( buffer_size downto 0 ) := (others => '0'); --zero signal |
||
| 98 | signal zeros10: unsigned( (bit_num - 1) downto 0 ) := (others => '0'); |
||
| 99 | |||
| 100 | signal old_value : unsigned ( (bit_num - 1) downto 0 ); |
||
| 101 | signal new_value : unsigned ( (bit_num - 1) downto 0 ); |
||
| 102 | |||
| 103 | signal BUFF_addr_sig : unsigned ( (buffer_size - 1) downto 0 ) := zeros(buffer_size - 1 downto 0); -- address for BRAM_buffer, goes to PE_addr |
||
| 104 | |||
| 105 | type state_type is (IDLE, WRITE, READ, RESET); --definicija avtomata s stirimi stanji |
||
| 106 | signal state: state_type := IDLE; |
||
| 107 | |||
| 108 | --values to be writen/read to/from bram1-- |
||
| 109 | signal counter_new : unsigned ( (buffer_size ) downto 0 ) := (others => '0'); |
||
| 110 | signal counter_in : unsigned ( (buffer_size ) downto 0 ) := (others => '0'); |
||
| 111 | signal count_update : std_logic := '0'; |
||
| 112 | signal start_counting : std_logic := '0'; |
||
| 113 | signal bin_idx : unsigned ( (bit_num - 1) downto 0 ) := (others => '0'); |
||
| 114 | --signal bin_idx_reset : unsigned ( (bit_num - 1) downto 0 ) := (others => '0'); --this signal is address to write 0 into bram (to reset bram) |
||
| 115 | |||
| 116 | --bram1 control signals-- |
||
| 117 | signal addr_A_sig : unsigned ( (bit_num - 1) downto 0 ) := (others => '0'); |
||
| 118 | signal addr_B_sig : unsigned ( (bit_num - 1) downto 0 ) := (others => '0'); |
||
| 119 | signal data_in_A_sig : unsigned ( buffer_size downto 0 ) := (others => '0'); |
||
| 120 | signal data_out_B_sig : unsigned ( buffer_size downto 0 ) := (others => '0'); |
||
| 121 | |||
| 122 | |||
| 123 | signal write_A: std_logic := '0'; |
||
| 124 | signal read_B: std_logic := '0'; |
||
| 125 | |||
| 126 | |||
| 127 | --other control signals -- |
||
| 128 | signal PE_wr_rd_en_sig: std_logic := '0'; |
||
| 129 | signal UC_rd_en_final_sig : std_logic := '0'; |
||
| 130 | signal UC_rd_en_current_sig : std_logic := '0'; |
||
| 131 | signal UC_wr_en_sig : std_logic := '0'; |
||
| 132 | signal UC_wr_en_prev_sig: std_logic := '0'; |
||
| 133 | |||
| 134 | signal delay_flag : boolean := FALSE; --used only to delay certain signals or states for 1 clock cycle |
||
| 135 | |||
| 136 | --MODE_3 signals-- |
||
| 137 | signal RESET_sig: std_logic := '0'; --gledam rising edge reset signala, zato tudi reset_sig_prev signal |
||
| 138 | signal RESET_sig_prev: std_logic := '0'; |
||
| 139 | signal ADC_unit_RESET_sig: std_logic := '0'; |
||
| 140 | signal counter : unsigned ( (buffer_size ) downto 0 ) := (others =>'0'); --steje stevilo prejetih podatkov, ko pride do konca je buffer full |
||
| 141 | --bram2 signals |
||
| 142 | signal write_A_all_modes: std_logic := '0'; --izhod iz multiplekserja; ko sta MODE 1 in 2, je to stari write_A, drugace pa pulzni signal iz ADC_enote v MODE_3 |
||
| 143 | signal write_A_prev_M3: std_logic := '0'; -- signal, s katerim gledam rising edge write_A_all_modes signala v MODE_3 |
||
| 144 | signal data_out_bram1_sig : unsigned ( (buffer_size ) downto 0 ) := (others => '0'); |
||
| 145 | signal data_out_bram2_sig : unsigned ( (buffer_size ) downto 0 ) := (others => '0'); |
||
| 146 | signal read_B2: std_logic := '0'; |
||
| 147 | signal addr_B2_sig : unsigned ( (bit_num - 1) downto 0 ) := (others => '0'); |
||
| 148 | |||
| 149 | |||
| 150 | signal data_out_sig : unsigned ( (buffer_size ) downto 0 ) := (others => '0'); |
||
| 151 | |||
| 152 | |||
| 153 | ------------------FUNCTIONS----------------------- |
||
| 154 | function check_signal_edge( sig_in: std_logic; |
||
| 155 | sig_in_prev: std_logic; |
||
| 156 | type_of_edge: string) return boolean is --falling or rising |
||
| 157 | |||
| 158 | begin |
||
| 159 | |||
| 160 | if (type_of_edge = "rising") then |
||
| 161 | |||
| 162 | if (sig_in = '1' and sig_in_prev = '0') then |
||
| 163 | return TRUE; |
||
| 164 | else |
||
| 165 | return FALSE; |
||
| 166 | end if; |
||
| 167 | |||
| 168 | elsif (type_of_edge = "falling") then |
||
| 169 | |||
| 170 | if (sig_in = '0' and sig_in_prev = '1') then |
||
| 171 | return TRUE; |
||
| 172 | else |
||
| 173 | return FALSE; |
||
| 174 | end if; |
||
| 175 | |||
| 176 | end if; |
||
| 177 | |||
| 178 | end function; |
||
| 179 | |||
| 180 | |||
| 181 | ---------------------------------------------------------------------------- |
||
| 182 | |||
| 183 | |||
| 184 | |||
| 185 | |||
| 186 | |||
| 187 | |||
| 188 | |||
| 189 | begin |
||
| 190 | |||
| 191 | BRAM_connect: dual_port_bram generic map (bit_num => bit_num, |
||
| 192 | bin_num => bin_num, |
||
| 193 | buffer_size => buffer_size) |
||
| 194 | |||
| 195 | port map (clk_A => clk, |
||
| 196 | bram_en_A => write_A_all_modes, --spremenjeno 2.12.2018 |
||
| 197 | wr_en_A => write_A_all_modes, -- -||- |
||
| 198 | addr_A => addr_A_sig, |
||
| 199 | data_in_A => data_in_A_sig, |
||
| 200 | data_out_A => open, |
||
| 201 | |||
| 202 | clk_B => clk, |
||
| 203 | bram_en_B => read_B, |
||
| 204 | wr_en_B => '0', --ni pisanja v B port, to more biti vedno onemogočeno |
||
| 205 | addr_B => addr_B_sig, |
||
| 206 | data_in_B => zeros, --open ne pusti, zato sem dal zeros |
||
| 207 | data_out_B => data_out_B_sig ); |
||
| 208 | |||
| 209 | |||
| 210 | -------------------------------------NALOGA BRAM_1----------------------------------------------------- |
||
| 211 | |||
| 212 | --stran A: a1) vpisovanje vrednosti iz BRAM_bufferja (preko algoritma za histogram) (state = WRITE) |
||
| 213 | -- a2) vpisovanje nicel (reset pomnilnika) (state = READ) |
||
| 214 | |||
| 215 | --stran B: b1) branje novega counterja (counter_new) za histogram algoritem (state = WRITE) |
||
| 216 | -- b2) branje izhodnih podatkov data_out (state = READ) |
||
| 217 | |||
| 218 | --HKRATI: a1) in b1) |
||
| 219 | -- a2) in b2) |
||
| 220 | |||
| 221 | |||
| 222 | |||
| 223 | ------------------------------ COMB. DEL, KI VELJA ZA VSE MODE-e ------------------------------------------------------------ |
||
| 224 | |||
| 225 | BUFF_addr <= BUFF_addr_sig; |
||
| 226 | PE_wr_rd_en <= PE_wr_rd_en_sig; |
||
| 227 | ADC_unit_RESET <= ADC_unit_RESET_sig; |
||
| 228 | |||
| 229 | new_value <= data_in when state = WRITE else |
||
| 230 | (others => '0');-- when state = READ or state = IDLE or state = RESET; |
||
| 231 | |||
| 232 | data_out <= data_out_sig; |
||
| 233 | |||
| 234 | --signals from/to microprocessor |
||
| 235 | UC_rd_en_final <= UC_rd_en_final_sig; |
||
| 236 | UC_rd_en_current <= UC_rd_en_current_sig; |
||
| 237 | UC_wr_en_sig <= UC_wr_en; |
||
| 238 | RESET_sig <= PE_RESET; |
||
| 239 | |||
| 240 | |||
| 241 | |||
| 242 | -------------------------------------------------------------------------------------------------------------------------------- |
||
| 243 | |||
| 244 | |||
| 245 | |||
| 246 | |||
| 247 | --------------------------------MODE_1 AND MODE_2 ------------------------------------------------------------------------------ |
||
| 248 | ---------------------------------------------------------------------------------------------------------------------------------- |
||
| 249 | ---------------------------------------------------------------------------------------------------------------------------------- |
||
| 250 | |||
| 251 | MODE_1_MODE_2: if (mode = "MODE_1" or mode = "MODE_2") generate |
||
| 252 | |||
| 253 | |||
| 254 | ----------------------- COMBINATIONAL PART ----------------- |
||
| 255 | |||
| 256 | |||
| 257 | |||
| 258 | ---- Counter Adder---- |
||
| 259 | |||
| 260 | counter_in <= (0 => '1', others => '0') when count_update = '0' else --mux - : tale enka tukaj zato, da ni 'X' na zacetku pr signalih, glej sliko v mapi slike, grafi itd. |
||
| 261 | (counter_new + 1) when count_update = '1'; --important part: this is where counter_new is increased every iteration |
||
| 262 | |||
| 263 | |||
| 264 | counter_new <= data_out_B_sig when state = WRITE else --demux |
||
| 265 | zeros; |
||
| 266 | |||
| 267 | |||
| 268 | ----Data IN/OUT---- |
||
| 269 | |||
| 270 | data_in_A_sig <= counter_in when state = WRITE else --mux |
||
| 271 | zeros when state = READ; |
||
| 272 | --TODO: dodaj se za RESET stanje (nicle) |
||
| 273 | |||
| 274 | |||
| 275 | data_out_sig <= data_out_B_sig when state = READ else -- demux |
||
| 276 | zeros; |
||
| 277 | |||
| 278 | |||
| 279 | |||
| 280 | ---- Enable signals ---- |
||
| 281 | |||
| 282 | write_A_all_modes <= write_A; |
||
| 283 | |||
| 284 | read_B <= PE_wr_rd_en_sig when state = WRITE else |
||
| 285 | not PE_wr_rd_en_sig when state = READ else |
||
| 286 | '0' when state = IDLE; |
||
| 287 | |||
| 288 | |||
| 289 | |||
| 290 | |||
| 291 | ---- Address signals ---- |
||
| 292 | addr_A_sig <= old_value when state = WRITE else |
||
| 293 | bin_idx - 1 when state = READ and bin_idx > 0 else |
||
| 294 | to_unsigned(bin_num - 1,10) when state = READ and delay_flag = TRUE else -- tukaj naj bo address 1023, da se vpise 0 na to mesto (reset) |
||
| 295 | zeros10 when state = IDLE; |
||
| 296 | |||
| 297 | |||
| 298 | addr_B_sig <= new_value when state = WRITE else |
||
| 299 | bin_idx when state = READ else |
||
| 300 | zeros10 when state = IDLE; |
||
| 301 | |||
| 302 | |||
| 303 | |||
| 304 | |||
| 305 | |||
| 306 | |||
| 307 | ----------------------------------SEQUENTIAL PART ------------------------------------------- |
||
| 308 | |||
| 309 | |||
| 310 | ALGORITHM: process(clk) |
||
| 311 | |||
| 312 | variable first_data: std_logic := '0'; |
||
| 313 | |||
| 314 | |||
| 315 | |||
| 316 | begin |
||
| 317 | |||
| 318 | if rising_edge(clk) then |
||
| 319 | |||
| 320 | case state is |
||
| 321 | |||
| 322 | when IDLE => |
||
| 323 | |||
| 324 | write_A <= '0'; -- this one is here, because we have to set it to '0' after program returns from READ state |
||
| 325 | --UC_rd_en_sig <= '0'; --ta tukej zato, da se v hist_system_top vpisejo vse vrednosti na data_out, pol pa sele tale dol pade |
||
| 326 | |||
| 327 | --writing condition-- |
||
| 328 | if (PE_START = '1' and UC_rd_en_final_sig = '0' ) then -- and "konec posiljanja flag je ON" ) then -- sem pripravljen na sprejemanje |
||
| 329 | |||
| 330 | if(delay_flag = FALSE) then |
||
| 331 | delay_flag <= TRUE; |
||
| 332 | PE_wr_rd_en_sig <= '1'; --zacni sprejemanje |
||
| 333 | old_value <= zeros10; |
||
| 334 | BUFF_addr_sig <= zeros(buffer_size - 1 downto 0); |
||
| 335 | |||
| 336 | else |
||
| 337 | state <= WRITE; |
||
| 338 | delay_flag <= FALSE; -- ponastavitev delay flaga, da se lahko uporabi se drugje |
||
| 339 | old_value <= new_value; |
||
| 340 | BUFF_addr_sig <= BUFF_addr_sig + 1; |
||
| 341 | --first_data := '0'; --ponastavi, drugace se branje OK izvede samo prvic. |
||
| 342 | end if; |
||
| 343 | |||
| 344 | --reading condition, part 1 --- |
||
| 345 | elsif (PE_START = '0' and PE_wr_rd_en_sig = '1') then --sem pripravljen na pošiljanje -- tole se lahko zgodi sele, ko gre najprej WRITE faza skozi, |
||
| 346 | PE_wr_rd_en_sig <= '0'; -- to pa zato, da od zacetka ne posilja nicel, ampak se vrti v IDLE stanju. |
||
| 347 | |||
| 348 | state <= READ; |
||
| 349 | |||
| 350 | |||
| 351 | --idle condition----- |
||
| 352 | else |
||
| 353 | state <= IDLE; |
||
| 354 | end if; |
||
| 355 | |||
| 356 | |||
| 357 | |||
| 358 | |||
| 359 | when WRITE => |
||
| 360 | |||
| 361 | if (first_data = '0') then |
||
| 362 | first_data := '1'; |
||
| 363 | old_value <= new_value; |
||
| 364 | BUFF_addr_sig <= BUFF_addr_sig + 1; |
||
| 365 | |||
| 366 | write_A <= '1'; |
||
| 367 | start_counting <= '1'; |
||
| 368 | |||
| 369 | else |
||
| 370 | |||
| 371 | if (write_A = '1') then |
||
| 372 | count_update <= '1'; |
||
| 373 | else |
||
| 374 | count_update <= '0'; |
||
| 375 | end if; |
||
| 376 | |||
| 377 | |||
| 378 | if (PE_START = '1') then |
||
| 379 | BUFF_addr_sig <= BUFF_addr_sig + 1; |
||
| 380 | |||
| 381 | elsif (PE_START = '0') then |
||
| 382 | BUFF_addr_sig <= (others =>'0'); --zeros(buffer_size - 1 downto 0); |
||
| 383 | delay_flag <= TRUE; -- s tem za en urin cikel zamaknem prehod v IDLE state in ponastavitev vsega, zato da se vsi podatki poracunajo |
||
| 384 | end if; |
||
| 385 | |||
| 386 | |||
| 387 | old_value <= new_value; |
||
| 388 | |||
| 389 | |||
| 390 | |||
| 391 | if (delay_flag = TRUE) then |
||
| 392 | delay_flag <= FALSE; |
||
| 393 | write_A <= '0'; |
||
| 394 | count_update <= '0'; |
||
| 395 | start_counting <= '0'; |
||
| 396 | state <= IDLE; |
||
| 397 | first_data := '0'; --ponastavi, drugace se branje OK izvede samo prvic. |
||
| 398 | |||
| 399 | end if; |
||
| 400 | |||
| 401 | |||
| 402 | end if; |
||
| 403 | |||
| 404 | |||
| 405 | |||
| 406 | |||
| 407 | when READ => --za dodajanje procesorskega signala: signal vpliva samo na povečevanje indeksov, ne na write in read in brama. samo ob pravem času more index povečat |
||
| 408 | if (bin_idx = to_unsigned(2,bit_num) ) then --tole zato, da mi prvega podatka takoj ne pobriše, oz. da na 0, ampak ga šele potem, ko pride drugi podatek na izhodno vodilo : TODO: A NE BI MOGL BIT 1?? SPODEJ MAM 1 IN PROV DELA |
||
| 409 | write_A <= '1'; |
||
| 410 | end if; |
||
| 411 | |||
| 412 | |||
| 413 | UC_rd_en_final_sig <= '1'; |
||
| 414 | |||
| 415 | UC_wr_en_prev_sig <= UC_wr_en_sig; --ta signal zato, da lahko gledam falling edge od UC_wr_en, ker na falling edge menjam podatke: novo 15.11.2018 |
||
| 416 | ------------------------------------------------------------- |
||
| 417 | if (UC_wr_en_sig = '0' and UC_wr_en_prev_sig = '1') then -- ta pogoj je enak, kot da bi rekel if falling_edge (UC_wr_en) |
||
| 418 | bin_idx <= bin_idx + 1; |
||
| 419 | else |
||
| 420 | bin_idx <= bin_idx; |
||
| 421 | end if; |
||
| 422 | |||
| 423 | ------------------------------------------------------------ |
||
| 424 | if (bin_idx = bin_num - 1) then |
||
| 425 | --write_A <= '0'; |
||
| 426 | bin_idx <= (others =>'0'); --zeros & "0000"; |
||
| 427 | delay_flag <= TRUE; |
||
| 428 | |||
| 429 | end if; |
||
| 430 | |||
| 431 | if (delay_flag = TRUE) then |
||
| 432 | delay_flag <= FALSE; |
||
| 433 | state <= IDLE; --menjava stanj mora biti zakasnjena za 1 clk, da se se 1023 podatek vpise na data_out |
||
| 434 | UC_rd_en_final_sig <= '0'; |
||
| 435 | end if; |
||
| 436 | |||
| 437 | |||
| 438 | end case; |
||
| 439 | |||
| 440 | end if; |
||
| 441 | |||
| 442 | end process; |
||
| 443 | |||
| 444 | end generate; |
||
| 445 | -------------------------------------------------------------------------------------------------------------------- |
||
| 446 | ------------------------------------------------------------------------------------------------------------------- |
||
| 447 | ------------------------------------------------------------------------------------------------------------------------ |
||
| 448 | |||
| 449 | |||
| 450 | |||
| 451 | |||
| 452 | |||
| 453 | |||
| 454 | |||
| 455 | -----------------------------MODE_3--------------------------------------------------------------------------------------------- |
||
| 456 | --------------------------------------------------------------------------------------------------------------------------------- |
||
| 457 | --------------------------------------------------------------------------------------------------------------------------------- |
||
| 458 | MODE_3: if (mode = "MODE_3") generate |
||
| 459 | |||
| 460 | |||
| 461 | --priklucitev dodatnega bufferja |
||
| 462 | |||
| 463 | BRAM_2_connect: dual_port_bram generic map (bit_num => bit_num, |
||
| 464 | bin_num => bin_num, |
||
| 465 | buffer_size => buffer_size) |
||
| 466 | |||
| 467 | port map (clk_A => clk, |
||
| 468 | bram_en_A => write_A_all_modes, --spremenjeno 2.12.2018 |
||
| 469 | wr_en_A => write_A_all_modes, -- -||- |
||
| 470 | addr_A => addr_A_sig, |
||
| 471 | data_in_A => data_in_A_sig, |
||
| 472 | data_out_A => open, |
||
| 473 | |||
| 474 | clk_B => clk, |
||
| 475 | bram_en_B => read_B2, |
||
| 476 | wr_en_B => '0', --ni pisanja v B port, to more biti vedno onemogočeno |
||
| 477 | addr_B => addr_B2_sig, |
||
| 478 | data_in_B => zeros, |
||
| 479 | data_out_B => data_out_bram2_sig ); |
||
| 480 | |||
| 481 | --------COMBINATIONAL PART------------------ |
||
| 482 | |||
| 483 | ---- Counter Adder, BRAM_1---- |
||
| 484 | |||
| 485 | counter_in <= (0 => '1', others => '0') when count_update = '0' else --mux - : tale enka tukaj zato, da ni 'X' na zacetku pr signalih, ker counter_new rab, da ga bram inicializira glej sliko v mapi slike, grafi itd. |
||
| 486 | (counter_new + 1) when count_update = '1'; --important part: this is where counter_new is increased every iteration |
||
| 487 | |||
| 488 | |||
| 489 | |||
| 490 | ----Data IN/OUT, BRAM_1---- |
||
| 491 | |||
| 492 | data_in_A_sig <= counter_in when state = WRITE else --mux |
||
| 493 | zeros;-- za vsa ostala stanja |
||
| 494 | |||
| 495 | |||
| 496 | |||
| 497 | data_out_bram1_sig <= data_out_B_sig when state = READ else -- demux |
||
| 498 | zeros; |
||
| 499 | |||
| 500 | counter_new <= data_out_B_sig when state = WRITE else --demux |
||
| 501 | zeros; |
||
| 502 | |||
| 503 | |||
| 504 | |||
| 505 | |||
| 506 | ---- Enable signals, BRAM_1 ---- |
||
| 507 | |||
| 508 | write_A_all_modes <= write_A_M3 when state = WRITE else |
||
| 509 | write_A when state = READ else --tukaj se vpisuejo nicle |
||
| 510 | '0' when state = IDLE else--v idle zdej pomoje lahko zbrises write_A = '0', preveri |
||
| 511 | '1' when state = RESET; --nicle vpisujes cel cajt, zato '1' |
||
| 512 | |||
| 513 | read_B <= PE_wr_rd_en_sig when state = WRITE else --TODO 31.3.2019: ali ni kar vseeno, da je addr_B_sig = '1', ko WR in RD in '0' else. <- ne, ker se pri WR stanju ta signal postavi z 1 clk zamude |
||
| 514 | not PE_wr_rd_en_sig when state = READ else |
||
| 515 | '0'; -- V stanjih IDLE in RESET |
||
| 516 | |||
| 517 | --TODO: 7.4.2019 PE_wr_rd_en_sig bom preimenoval v read_B_en (zaenkrat samo za na shematiko)!!!!!!! |
||
| 518 | |||
| 519 | |||
| 520 | |||
| 521 | |||
| 522 | ---- Address signals, BRAM_1 ---- |
||
| 523 | |||
| 524 | addr_A_sig <= old_value when state = WRITE else -- P2 |
||
| 525 | bin_idx - 1 when state = READ and bin_idx > 0 else --P3 |
||
| 526 | to_unsigned(bin_num - 1,10) when state = READ and delay_flag = TRUE else -- tukaj naj bo address 1023, da se vpise 0 na to mesto (reset) P4 |
||
| 527 | (others =>'0') when state = IDLE else -- P1 |
||
| 528 | bin_idx when state = RESET; --P5 |
||
| 529 | |||
| 530 | |||
| 531 | addr_B_sig <= new_value when state = WRITE else |
||
| 532 | bin_idx when state = READ else |
||
| 533 | (others => '0'); --za ostali stanji IDLE in RESET |
||
| 534 | |||
| 535 | |||
| 536 | |||
| 537 | |||
| 538 | ---- Data IN/OUT, BRAM_2 ---- |
||
| 539 | |||
| 540 | --input v bram2 je kar data_in_A_sig prikljucen na input komponente bram2 |
||
| 541 | --output bram2 je dat_out_bram2_sig , prikljuceno direktno na outB komponente bram2 |
||
| 542 | |||
| 543 | |||
| 544 | ---- Enable signals, BRAM_2 ---- |
||
| 545 | |||
| 546 | --write_A_all_modes je tudi write enable signal bram2 |
||
| 547 | read_B2 <= PE_wr_rd_en_sig when state = WRITE else |
||
| 548 | '1' when state = IDLE else --zato, da 1023. podatek pobrise iz data_out_bram2_sig |
||
| 549 | '0'; -- v stanjih READ IN RESET |
||
| 550 | --TODO: 7.4.2019 PE_wr_rd_en_sig bom preimenoval v read_B_en (zaenkrat samo za na shematiko)!!!!!!! |
||
| 551 | |||
| 552 | |||
| 553 | ---- Address signals, BRAM_2 ---- |
||
| 554 | |||
| 555 | --addr_A_sig : za vpisovanje je enak naslov kot pri bram1 |
||
| 556 | |||
| 557 | addr_B2_sig <= bin_idx when state = WRITE else |
||
| 558 | (others => '0'); -- v stanjih READ, IDLE IN RESET |
||
| 559 | |||
| 560 | |||
| 561 | |||
| 562 | |||
| 563 | |||
| 564 | --------skupna logika obeh bram-ov--------------------- |
||
| 565 | data_out_sig <= data_out_bram2_sig when state = WRITE else |
||
| 566 | data_out_bram1_sig when state = READ else |
||
| 567 | (others => '0'); --pri IDLE in RESET stanju |
||
| 568 | |||
| 569 | |||
| 570 | --------SEQUENTIAL PART--------------------- |
||
| 571 | |||
| 572 | ALGORITHM_bram_1: process(clk) |
||
| 573 | |||
| 574 | variable first_data: std_logic := '0'; |
||
| 575 | variable buffer_full: std_logic := '0'; -- 0 - ni se poln, 1 - bram je poln |
||
| 576 | |||
| 577 | begin |
||
| 578 | |||
| 579 | if rising_edge(clk) then |
||
| 580 | |||
| 581 | case state is |
||
| 582 | |||
| 583 | when IDLE => |
||
| 584 | |||
| 585 | if (PE_START = '1') then --START SIGNAL |
||
| 586 | |||
| 587 | write_A <= '0'; -- this one is here, because we have to set it to '0' after program returns from READ state |
||
| 588 | |||
| 589 | if (buffer_full = '0' and RESET_sig = '0') then -- ni se cas za posiljanje, se pravi lahko sprejemam --PISANJE V PE ENOTO |
||
| 590 | |||
| 591 | |||
| 592 | PE_wr_rd_en_sig <= '1'; --tole vezano na read_B, zato ga se vedno obdrzim |
||
| 593 | old_value <= (others => '0'); |
||
| 594 | state <= WRITE; |
||
| 595 | --old_value <= new_value; |
||
| 596 | |||
| 597 | |||
| 598 | elsif (buffer_full = '1' and RESET_sig = '0') then --BRANJE NA KONCU IZ PE ENOTE |
||
| 599 | --pisi na vodilo na koncu in resetiraj prvi bram, tako kot do sedaj, skratka pojdi v READ stanje |
||
| 600 | bin_idx <= (others => '0'); --ga resetiram, da je 0, ker ga tudi bram 2 uproablja |
||
| 601 | UC_wr_en_prev_sig <= '0'; -- da ga ponastavim, ker drugace mi 0. podatek takoj preklopi v 1., ne caka na falling edge od UC_wr_en_sig |
||
| 602 | state <= READ; |
||
| 603 | |||
| 604 | |||
| 605 | elsif (check_signal_edge(RESET_sig,RESET_sig_prev,"rising")) then |
||
| 606 | state <= RESET; |
||
| 607 | ADC_unit_RESET_sig <= '1'; |
||
| 608 | |||
| 609 | end if; |
||
| 610 | |||
| 611 | |||
| 612 | |||
| 613 | elsif (PE_START = '0') then --CE JE START NA '0' |
||
| 614 | |||
| 615 | if (check_signal_edge(RESET_sig,RESET_sig_prev,"rising")) then |
||
| 616 | state <= RESET; |
||
| 617 | bin_idx <= (others => '0'); |
||
| 618 | ADC_unit_RESET_sig <= '1'; |
||
| 619 | |||
| 620 | else |
||
| 621 | state <= IDLE; |
||
| 622 | end if; |
||
| 623 | |||
| 624 | end if; |
||
| 625 | |||
| 626 | --stimanje reset signala |
||
| 627 | RESET_sig_prev <= RESET_sig; |
||
| 628 | ---------------------------- |
||
| 629 | |||
| 630 | |||
| 631 | |||
| 632 | |||
| 633 | when WRITE => |
||
| 634 | |||
| 635 | -------------------bram_1 handling--------------------- |
||
| 636 | old_value <= new_value; |
||
| 637 | count_update <= '1'; --ta tukaj samo zato, da nimam 'X' v simulaciji, glej sliko v mapi slike_grafi itd. |
||
| 638 | |||
| 639 | write_A_prev_M3 <= write_A_all_modes; |
||
| 640 | if (write_A_all_modes = '1' and write_A_prev_M3 = '0') then --rising edge write signala |
||
| 641 | counter <= counter + 1; |
||
| 642 | end if; |
||
| 643 | |||
| 644 | |||
| 645 | if (counter = 2**buffer_size) then --ko sem prejel maksimalno št. podatkov, ki jih lahko buffer shrani TODO: 18.5.2019: PREVERI TUKEJ, CE JE counter_in = 2*buffer_size -1 |
||
| 646 | --kok delaya? -- nc ni treba |
||
| 647 | state <= IDLE; |
||
| 648 | buffer_full := '1'; |
||
| 649 | PE_wr_rd_en_sig <= '0'; |
||
| 650 | count_update <= '0'; |
||
| 651 | counter <= (others => '0'); |
||
| 652 | end if; |
||
| 653 | |||
| 654 | |||
| 655 | |||
| 656 | -----------------bram_2 handling ---------------------- |
||
| 657 | if (counter > 0 and counter < 2**buffer_size) then --ce si ze vpisal vsaj en podatek in se nisi prisel do konca vpisovanja |
||
| 658 | UC_rd_en_current_sig <= '1'; --povej procesorju, da lahko zacne sprotno branje |
||
| 659 | |||
| 660 | elsif (counter = 2**buffer_size) then |
||
| 661 | UC_rd_en_current_sig <= '0'; -- procesor naj konca sprotno branje |
||
| 662 | end if; |
||
| 663 | |||
| 664 | |||
| 665 | UC_wr_en_prev_sig <= UC_wr_en_sig; --ta signal zato, da lahko gledam falling edge od UC_wr_en, ker na falling edge menjam podatke: |
||
| 666 | |||
| 667 | if (UC_rd_en_current_sig = '1') then --ce je omogoceno sprotno branje, lahko podajas podatke na izhod |
||
| 668 | if (check_signal_edge(UC_wr_en_sig, UC_wr_en_prev_sig, "falling")) then -- ta pogoj je enak, kot da bi rekel if falling_edge (UC_wr_en) |
||
| 669 | bin_idx <= bin_idx + 1; |
||
| 670 | else |
||
| 671 | bin_idx <= bin_idx; |
||
| 672 | end if; |
||
| 673 | end if; |
||
| 674 | |||
| 675 | |||
| 676 | -- if (bin_idx = bin_num - 1) then |
||
| 677 | -- --bin_idx <= (others =>'0'); --zeros & "0000"; |
||
| 678 | -- delay_flag <= TRUE; |
||
| 679 | -- end if; |
||
| 680 | |||
| 681 | -- if (delay_flag = TRUE) then |
||
| 682 | -- delay_flag <= FALSE; |
||
| 683 | -- --UC_wr_en_prev_sig <= '0'; |
||
| 684 | -- --bin_idx <= (others => '0'); |
||
| 685 | -- end if; |
||
| 686 | |||
| 687 | |||
| 688 | --------------------RESET handling-------------------------- |
||
| 689 | RESET_sig_prev <= RESET_sig; |
||
| 690 | if (check_signal_edge(RESET_sig,RESET_sig_prev,"rising")) then |
||
| 691 | state <= RESET; |
||
| 692 | bin_idx <= (others =>'0'); |
||
| 693 | UC_rd_en_current_sig <= '0'; |
||
| 694 | ADC_unit_RESET_sig <= '1'; |
||
| 695 | end if; |
||
| 696 | |||
| 697 | -----------------STOP SYSTEM handling ------------------------ |
||
| 698 | if (PE_START = '0') then |
||
| 699 | state <= IDLE; |
||
| 700 | UC_rd_en_current_sig <= '0'; |
||
| 701 | end if; |
||
| 702 | |||
| 703 | |||
| 704 | |||
| 705 | when READ => --za dodajanje procesorskega signala: signal vpliva samo na povečevanje indeksov, ne na write in read in brama. samo ob pravem času more index povečat |
||
| 706 | |||
| 707 | UC_rd_en_final_sig <= '1'; |
||
| 708 | ------------------------------------------------------------- |
||
| 709 | UC_wr_en_prev_sig <= UC_wr_en_sig; --ta signal zato, da lahko gledam falling edge od UC_wr_en, ker na falling edge menjam podatke: novo 15.11.2018 |
||
| 710 | |||
| 711 | if (UC_rd_en_final_sig = '1') then --to zato, da, ce se ponesreci vrine kaksen UC_wr_en preden skoci UC_rd_en_final na '1', da se nic ne zgodi |
||
| 712 | if ( check_signal_edge(UC_wr_en_sig, UC_wr_en_prev_sig, "falling") ) then -- ta pogoj je enak, kot da bi rekel if falling_edge (UC_wr_en) |
||
| 713 | bin_idx <= bin_idx + 1; |
||
| 714 | else |
||
| 715 | bin_idx <= bin_idx; |
||
| 716 | end if; |
||
| 717 | end if; |
||
| 718 | |||
| 719 | ------------------------------------------------------------ |
||
| 720 | if (bin_idx = to_unsigned(1,bit_num) ) then --tole zato, da mi prvega podatka takoj ne pobriše, oz. da na 0, ampak ga šele potem, ko pride drugi podatek na izhodno vodilo |
||
| 721 | write_A <= '1'; |
||
| 722 | end if; |
||
| 723 | |||
| 724 | |||
| 725 | if (bin_idx = bin_num - 1) then |
||
| 726 | bin_idx <= (others =>'0'); |
||
| 727 | delay_flag <= TRUE; |
||
| 728 | |||
| 729 | end if; |
||
| 730 | |||
| 731 | if (delay_flag = TRUE) then |
||
| 732 | delay_flag <= FALSE; |
||
| 733 | state <= IDLE; --menjava stanj mora biti zakasnjena za 1 clk, da se se 1023 podatek vpise na data_out |
||
| 734 | UC_rd_en_final_sig <= '0'; |
||
| 735 | bin_idx <= (others => '0'); --se enkrat na 0, drugace se zaradi delaya spet postavi na 1 |
||
| 736 | buffer_full := '0'; |
||
| 737 | end if; |
||
| 738 | |||
| 739 | |||
| 740 | --------------------RESET handling-------------------------- |
||
| 741 | RESET_sig_prev <= RESET_sig; |
||
| 742 | if (check_signal_edge(RESET_sig,RESET_sig_prev,"rising")) then |
||
| 743 | state <= RESET; |
||
| 744 | bin_idx <= (others => '0'); |
||
| 745 | UC_rd_en_final_sig <= '0'; |
||
| 746 | ADC_unit_RESET_sig <= '1'; |
||
| 747 | end if; |
||
| 748 | |||
| 749 | -----------------STOP SYSTEM handling ------------------------ |
||
| 750 | if (PE_START = '0') then |
||
| 751 | state <= IDLE; |
||
| 752 | UC_rd_en_final_sig <= '0'; --ce gres tkole: READ -> IDLE -> RESET, potem je treba tega tuki ugasnt |
||
| 753 | end if; |
||
| 754 | |||
| 755 | |||
| 756 | |||
| 757 | |||
| 758 | when RESET => |
||
| 759 | |||
| 760 | bin_idx <= bin_idx + 1; --to je naslov, v katerega se v oba bram-a vpisujejo nicle |
||
| 761 | |||
| 762 | if (bin_idx = bin_num - 1) then |
||
| 763 | bin_idx <= (others => '0'); |
||
| 764 | state <= IDLE; |
||
| 765 | ADC_unit_RESET_sig <= '0'; |
||
| 766 | end if; |
||
| 767 | |||
| 768 | PE_wr_rd_en_sig <= '0'; |
||
| 769 | count_update <= '0'; |
||
| 770 | counter <= (others => '0'); |
||
| 771 | buffer_full := '0'; |
||
| 772 | |||
| 773 | |||
| 774 | |||
| 775 | end case; |
||
| 776 | |||
| 777 | end if; |
||
| 778 | |||
| 779 | end process; |
||
| 780 | |||
| 781 | |||
| 782 | end generate; |
||
| 783 | |||
| 784 | |||
| 785 | end Behavioral; |