Subversion Repositories f9daq

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
336 f9daq 1
----------------------------------------------------------------------------------
2
-- Company: 
3
-- Engineer: 
4
-- 
5
-- Create Date: 13.10.2018 11:54:07
6
-- Design Name: 
7
-- Module Name: BRAM_buffer - 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 BRAM_buffer is
35
    generic (
36
              bit_num : natural := 10; --number of data bits
37
              buffer_size : natural := 26); -- buffer size in bits, 5 bit gets 32 different values 
38
 
39
    port (
40
           clk: in std_logic;
41
 
42
           AD_wr_en: in std_logic; --from AD unit, enable writing into bram
43
           AD_addr: in unsigned ( (buffer_size - 1) downto 0); --from AD unit, address for writing
44
           PE_addr: in unsigned ( (buffer_size - 1) downto 0 ); -- from PE_unit, address for reading
45
           PE_wr_en: in std_logic; -- from PE_unit, enable writing into PE unit 
46
           data_in : in unsigned ( (bit_num - 1) downto 0 ); --data from ADC
47
           data_out : out unsigned ( (bit_num - 1) downto 0 ); -- data for PE_unit
48
           BUFF_data_ready: out std_logic --signal, ki PE_enoti pove, da so podatki pripravljeni (prvič)--preveri ali je to potrebno, ker bodo itak samo ničle letele iz PE enote predn se kaj vpiše, ničle lahko na računalniku preč vržem
49
          );
50
 
51
end BRAM_buffer;
52
 
53
architecture Behavioral of BRAM_buffer is
54
 
55
---- COMPONENTS ----
56
 
57
    component single_port_bram is
58
 
59
        generic (
60
                  bit_num : natural := 10; --number of data bits
61
                  buffer_size : natural := 5); -- buffer size in bits, 5 bit gets 32 different values 
62
 
63
        port (
64
               clk: in std_logic;
65
               bram_en: in std_logic;
66
               wr_en: in std_logic;
67
               addr: in unsigned ( (buffer_size - 1) downto 0 );
68
               data_in : in unsigned ( (bit_num - 1) downto 0 ); --data from ADC
69
               data_out : out unsigned ( (bit_num - 1) downto 0 ) -- data for PE_unit
70
              );
71
 
72
    end component;
73
 
74
 
75
---- SIGNALS ----
76
 
77
    signal addr_sig: unsigned ( (buffer_size - 1) downto 0);
78
    signal bram_en_sig: std_logic;
79
 
80
    signal zeros: unsigned ( (buffer_size - 1) downto 0 ) := (others => '0');
81
 
82
    type state_type is (WRITE, READ, IDLE); -- definicija stanj
83
    signal state: state_type;
84
 
85
 
86
begin
87
 
88
--------------------COMBINATIONAL PART-------------------------------------
89
    state <= WRITE when AD_wr_en = '1' else --stanja 
90
             READ  when PE_wr_en = '1' else
91
             IDLE  when (AD_wr_en = '0' and PE_wr_en = '0');
92
 
93
 
94
    addr_sig <= AD_addr when state = WRITE else
95
                PE_addr when state = READ  else--mux to choose addresses for writing or reading
96
                zeros when state = IDLE;
97
 
98
 
99
    bram_en_sig <= AD_wr_en or PE_wr_en; -- bram enable signal
100
 
101
 
102
 --------------------------------CONNECT UNITS --------------------------------   
103
    BRAM_connect: single_port_bram generic map (bit_num     => bit_num,
104
                                                buffer_size => buffer_size)  
105
 
106
                                   port map (clk => clk,
107
                                             bram_en => bram_en_sig,
108
                                             wr_en => AD_wr_en,
109
                                             addr => addr_sig,
110
                                             data_in => data_in,
111
                                             data_out => data_out);
112
 
113
-------------------SEQUENTIAL PART----------------------------------------------
114
 
115
--- tole je za nastavljanje BUFF_data_ready signala 
116
    BUFF_data_ready_proc: process (clk)
117
        variable BUFF_ON_flag : std_logic := '0';
118
 
119
    begin
120
        if ( rising_edge(clk) ) then
121
 
122
            if (AD_addr = 2**buffer_size - 1 and AD_wr_en = '1') then -- pogoj AD_wr_en = '1' zato, da se flag postavi šele ko je izbrana
123
                BUFF_ON_flag := '1';                                  -- konkretno ta enota, drugace se flag postavi takoj, ko addr pride do 2**buffer_size - 1
124
            elsif (PE_addr = 2**buffer_size - 1) then                 -- kar pa je ze, ko se polni prva enota. 
125
                BUFF_ON_flag := '0';
126
            end if;
127
 
128
 
129
            if (BUFF_ON_flag = '1' ) then
130
                BUFF_data_ready <= '1';
131
 
132
            else
133
                BUFF_data_ready <= '0';
134
            end if;
135
 
136
        end if;
137
    end process;
138
end Behavioral;