OpenCores
URL https://opencores.org/ocsvn/pulse_processing_algorithm/pulse_processing_algorithm/trunk

Subversion Repositories pulse_processing_algorithm

[/] [pulse_processing_algorithm/] [progdelay_pipeline.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 panda_emc
-----------------------------------------------------------------------------------------------
2
--
3
--    Copyright (C) 2011 Peter Lemmens, PANDA collaboration
4
--              p.j.j.lemmens@rug.nl
5
--    http://www-panda.gsi.de
6
--
7
--    As a reference, please use:
8
--    E. Guliyev, M. Kavatsyuk, P.J.J. Lemmens, G. Tambave, H. Loehner,
9
--    "VHDL Implementation of Feature-Extraction Algorithm for the PANDA Electromagnetic Calorimeter"
10
--    Nuclear Inst. and Methods in Physics Research, A ....
11
--
12
--
13
--    This program is free software; you can redistribute it and/or modify
14
--    it under the terms of the GNU Lesser General Public License as published by
15
--    the Free Software Foundation; either version 3 of the License, or
16
--    (at your option) any later version.
17
--
18
--    This program is distributed in the hope that it will be useful,
19
--    but WITHOUT ANY WARRANTY; without even the implied warranty of
20
--    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
--    GNU Lesser General Public License for more details.
22
--
23
--    You should have received a copy of the GNU General Public License
24
--    along with this program; if not, write to the Free Software
25
--    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
26
--
27
-----------------------------------------------------------------------------------------------
28
-----------------------------------------------------------------------------------------------
29
-- Company              :       KVI (Kernfysisch Versneller Instituut  -- Groningen, The Netherlands    
30
-- Author               :       P.J.J. Lemmens
31
-- Design Name  :       Feature Extraction
32
-- Module Name  :       progdelay_pipeline.vhd
33
-- Description  :       programmable delayline / datapipe with a (generic-fixed) maximum size
34
--                                              
35
-----------------------------------------------------------------------------------------------
36
 
37
library IEEE;
38
use IEEE.STD_LOGIC_1164.ALL;
39
use IEEE.STD_LOGIC_ARITH.ALL;
40
use IEEE.STD_LOGIC_UNSIGNED.ALL;
41
 
42
entity progdelay_pipeline is
43
        generic (RAM_SIZE_PWR   : natural       := 1;
44
                                FLEX_RAM_STYLE  : string                := "distributed");
45
        Port (clk                       : in  STD_LOGIC;
46
                        rst                     : in  STD_LOGIC;
47
                        enable          : in  STD_LOGIC;
48
                        program         : in  STD_LOGIC;
49
                        delay_in                : in    STD_LOGIC_VECTOR;
50
                        data_in         : in    STD_LOGIC_VECTOR;
51
                        data_out                : out   STD_LOGIC_VECTOR;
52
                        data_valid      : out   std_logic
53
                );
54
end progdelay_pipeline;
55
 
56
architecture Behavioral of progdelay_pipeline is
57
 
58
--      type prog_state_type is (prog_rst, prog_exec, prog_done);
59
 
60
        constant        WIDTH                                   : natural := data_in'length;
61
        constant        DELAY_WIDTH                     : natural := delay_in'length;
62
        constant        DEFAULT_DELAY           : natural := 8 - 1;
63
        constant        MAX_RAM_ADDRESS : natural := 2**RAM_SIZE_PWR - 1;
64
 
65
        component flex_ram
66
        generic (RAM_SIZE_PWR   : natural       := 1;
67
                                FLEX_RAM_STYLE  : string                := "distributed");
68
                Port (clk                       : in  STD_LOGIC := '0';
69
                                enable          : in  STD_LOGIC := '0';
70
                                write_ptr       : in  STD_LOGIC_VECTOR;
71
                                read_ptr                : in  STD_LOGIC_VECTOR;
72
                                data_in         : in    STD_LOGIC_VECTOR;
73
                                data_out                : out   STD_LOGIC_VECTOR
74
                                );
75
        end component;
76
 
77
--      signal prog_state_S     : prog_state_type := prog_rst;
78
 
79
        signal clk_S                    : STD_LOGIC := '0';
80
        signal rst_S                    : STD_LOGIC := '1';
81
        signal program_S                : STD_LOGIC := '0';
82
        signal enable_S         : STD_LOGIC := '0';
83
        signal data_valid_S     : STD_LOGIC := '0';
84
        signal delay_S                  : STD_LOGIC_VECTOR(delay_in'high downto 0)       := conv_std_logic_vector(DEFAULT_DELAY + 1, DELAY_WIDTH);
85
        signal data_in_S                : STD_LOGIC_VECTOR(WIDTH - 1 downto 0)                   := (others      => '0');
86
        signal del_data_S               : STD_LOGIC_VECTOR(WIDTH - 1 downto 0)                   := (others      => '0');
87
        signal data_out_S               : STD_LOGIC_VECTOR(WIDTH - 1 downto 0)                   := (others      => '0');
88
 
89
        signal write_ptr_S      : STD_LOGIC_VECTOR(RAM_SIZE_PWR - 1 downto 0) := conv_std_logic_vector(DEFAULT_DELAY, RAM_SIZE_PWR);
90
        signal read_ptr_S               : STD_LOGIC_VECTOR(RAM_SIZE_PWR - 1 downto 0) := (others => '0');
91
 
92
        signal rst_count_S      : STD_LOGIC_VECTOR(RAM_SIZE_PWR downto 0) := conv_std_logic_vector(DEFAULT_DELAY + 1, RAM_SIZE_PWR + 1);
93
 
94
begin
95
        pipe_ram : flex_ram
96
                generic map(RAM_SIZE_PWR        => RAM_SIZE_PWR,
97
                                                FLEX_RAM_STYLE  => FLEX_RAM_STYLE)
98
                Port map(clk                    =>      clk_S,
99
                                        enable          => enable_S,
100
                                        write_ptr       => write_ptr_S,
101
                                        read_ptr                => read_ptr_S,
102
                                        data_in         => data_in_S,
103
                                        data_out                => del_data_S
104
                                );
105
 
106
 
107
        clk_S                   <= clk;
108
        rst_S                   <=      rst;
109
        enable_S                <=      enable;
110
        program_S       <= program;
111
        delay_S         <= delay_in;
112
        data_in_S       <= data_in;
113
        data_out                <= data_out_S;
114
        data_valid      <=      data_valid_S;
115
 
116
------------------------------------------------------
117
----------------------------------------------------
118
        rst_fake : process (clk_S)
119
                begin
120
                if rising_edge(clk_S) then
121
                        if (rst_S = '1') or (program_S = '1') then
122
                                if (delay_S >= 4) then
123
                                        rst_count_S <= conv_std_logic_vector(conv_integer(delay_S - 1), RAM_SIZE_PWR + 1);
124
                                else
125
                                        rst_count_S <= conv_std_logic_vector((4), RAM_SIZE_PWR + 1);
126
                                end if;
127
                        else
128
                                if (enable_S = '1' and rst_count_S > 0) then
129
                                        rst_count_S             <= rst_count_S - 1;
130
                                end if;
131
                        end if;
132
                end if;
133
        end process;
134
----------------------------------------------------
135
        ram_reg : process (clk_S)
136
        begin
137
                if rising_edge(clk_S) then
138
                        if (rst_S = '1') or (program_S = '1') then
139
                                data_out_S              <= (others => '0');
140
                                data_valid_S    <=      '0';
141
                        else
142
                                if (enable_S = '1') then
143
                                        if (rst_count_S > 0) then
144
                                                data_out_S              <= (others => '0');
145
                                                data_valid_S    <=      '0';
146
                                        else
147
                                                data_out_S              <= del_data_S;
148
                                                data_valid_S    <=      '1';
149
                                        end if;
150
                                end if;
151
                        end if;
152
                end if;
153
        end process;
154
 
155
-----------------------------------------------------
156
        write_ptr : process(clk_S)
157
        begin
158
                if rising_edge(clk_S) then
159
                        if (rst_S = '1') or (program_S = '1') then
160
                                if (delay_S >= 4) then  -- to avoid rst_count laggin on delay_S
161
                                        write_ptr_S <= conv_std_logic_vector(conv_integer(delay_S) - 2, RAM_SIZE_PWR); -- hier stond delay_S -2 ?!?!
162
                                else
163
                                        write_ptr_S <= conv_std_logic_vector((4 - 2), RAM_SIZE_PWR); -- hier stond 4 -2 ?!?!
164
                                end if;
165
                        else
166
                                if (enable_S ='1') then
167
                                        if (write_ptr_S < MAX_RAM_ADDRESS) then
168
                                                write_ptr_S <= write_ptr_S + 1;
169
                                        else
170
                                                write_ptr_S <= (others => '0');
171
                                        end if;
172
                                end if;
173
                        end if;
174
                end if;
175
        end process;
176
 
177
------------------------------------------------------
178
        read_ptr : process(clk_S)--, init_S, enable_S)
179
        begin
180
                if rising_edge(clk_S) then
181
                        if (rst_S = '1') or (program_S = '1') then
182
                                read_ptr_S <= (others => '0');
183
                        else
184
                                if (enable_S ='1') then
185
                                        if (read_ptr_S < MAX_RAM_ADDRESS) then
186
                                                read_ptr_S <= read_ptr_S + 1;
187
                                        else
188
                                                read_ptr_S <= (others => '0');
189
                                        end if;
190
                                end if;
191
                        end if;
192
                end if;
193
        end process;
194
 
195
end Behavioral;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.