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

Subversion Repositories copyblaze

[/] [copyblaze/] [trunk/] [copyblaze/] [rtl/] [vhdl/] [ip/] [wb_scope/] [wb_scope.vhd] - Blame information for rev 59

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 16 ameziti
-----------------------------------------------------------------------------
2
-- On-chip logic analyzer with wishbone bus for control and data export.
3
-- Waveforms are stored in local BlockRAM which size (depth) can be
4
-- configured via a generic.
5
--
6
-- (c) 2006 by Joerg Bornschein  (jb@capsec.org)
7
-- All files under GPLv2   
8
-----------------------------------------------------------------------------
9
library ieee;
10
use ieee.std_logic_1164.ALL;
11
use ieee.numeric_std.ALL;
12
 
13
-----------------------------------------------------------------------------
14
-- Wishbone LogicAnalyzer ---------------------------------------------------
15
entity wb_scope is
16
        generic (
17
                depth      : natural := 4096 );
18
        port (
19
                clk        : in  std_logic;
20
                reset      : in  std_logic;
21
                -- 32 Bit Wishbone Slave
22
                wb_adr_i   : in  std_logic_vector(31 downto 0);
23
                wb_dat_i   : in  std_logic_vector(31 downto 0);
24
                wb_dat_o   : out std_logic_vector(31 downto 0);
25
                wb_sel_i   : in  std_logic_vector( 3 downto 0);
26
                wb_cyc_i   : in  std_logic;
27
                wb_stb_i   : in  std_logic;
28
                wb_ack_o   : out std_logic;
29
                wb_we_i    : in  std_logic;
30
                wb_irq_o   : out std_logic;
31
                -- I/O ports
32
                probe      : in  std_logic_vector(31 downto 0) );
33
end wb_scope;
34
 
35
-----------------------------------------------------------------------------
36
-- 0x00000 Status Register:
37
--      +-----------------+-------+-------+-------+
38
--      |    ... 0 ...    | SDONE | IRQEN | SPLEN |
39
--      +-----------------+-------+-------+-------+
40
--
41
-- 0x00004 Sample Pointer -- (0x0000 : 0xFFFF)
42
-- 0x00008 Sample Counter -- (Stop when 0)
43
-- 0x00010 Channel 0
44
-- 0x00011 Channel 1
45
-- 0x00012 Channel 2
46
-- 0x00013 Channel 3
47
-- 0x1???? Data 
48
-----------------------------------------------------------------------------
49
 
50
-----------------------------------------------------------------------------
51
-- Implementation -----------------------------------------------------------
52
architecture rtl of wb_scope is
53
 
54
-----------------------------------------------------------------------------
55
-- Components ---------------------------------------------------------------
56
component bram_dp is
57
        generic (
58
                depth     : natural );
59
        port (
60
                clk       : in  std_logic;
61
                reset     : in  std_logic;
62
                -- Port 1
63
                we1       : in  std_logic;
64
                addr1     : in  std_logic_vector(11 downto 0);
65
                wdata1    : in  std_logic_vector(31 downto 0);
66
                -- Port 2
67
                oe2       : in  std_logic;
68
                addr2     : in  std_logic_vector(11 downto 0);
69
                rdata2    : out std_logic_vector(31 downto 0) );
70
end component;
71
 
72
component mux32 is
73
        port (
74
                input     : in  std_logic_vector(31 downto 0);
75
                output    : out std_logic;
76
                sel       : in  std_logic_vector(4 downto 0) );
77
end component;
78
 
79
-----------------------------------------------------------------------------
80
-- Local Signals ------------------------------------------------------------
81
constant ZEROS  : std_logic_vector(31 downto 0) := (others => '0');
82
 
83
signal wbactive : std_logic;
84
 
85
signal status_reg : std_logic_vector(31 downto 0);
86
 
87
signal sp      : std_logic_vector(15 downto 0); -- SamplePointer
88
signal sc      : std_logic_vector(15 downto 0); -- SampleCounter
89
signal spen    : std_logic;                     -- Sample Enable
90
signal irqen   : std_logic;                     -- IRQ Enable
91
signal sdone   : std_logic;                     -- Sampling Done
92
 
93
signal sreg    : std_logic_vector(27 downto 0); -- sample register
94
signal chan    : std_logic_vector( 3 downto 0); -- actual data to be sampled
95
signal probe_b : std_logic_vector(31 downto 0); -- buffered probes
96
 
97
signal csel0 : std_logic_vector(4 downto 0);
98
signal csel1 : std_logic_vector(4 downto 0);
99
signal csel2 : std_logic_vector(4 downto 0);
100
signal csel3 : std_logic_vector(4 downto 0);
101
 
102
signal we1   : std_logic;
103
signal addr1 : std_logic_vector(11 downto 0);
104
signal wdata1: std_logic_vector(31 downto 0);
105
 
106
signal oe2   : std_logic;
107
signal addr2 : std_logic_vector(11 downto 0);
108
signal rdata2: std_logic_vector(31 downto 0);
109
 
110
signal ram_ack : std_logic;
111
 
112
 
113
begin
114
 
115
-- Sample RAM ---------------------------------------------------------------
116
ram0: bram_dp
117
        generic map (
118
                depth  => depth )
119
        port map (
120
                clk    => clk,
121
                reset  => reset,
122
                -- Port 1  (probe & sample engine (write only))
123
                we1    => we1,
124
                addr1  => addr1,
125
                wdata1 => wdata1,
126
                -- Port 2  (Wishbone Access (read only))
127
                oe2    => oe2,
128
                addr2  => addr2,
129
                rdata2 => rdata2 );
130
 
131
wbactive <= wb_stb_i and wb_cyc_i;
132
 
133
addr2 <= wb_adr_i(13 downto 2);
134
oe2   <= '1' when wbactive='1' and wb_adr_i(19 downto 16)=x"1" else
135
         '0';
136
 
137
wb_dat_o <= status_reg               when wbactive='1' and wb_adr_i(19 downto 16)=x"0" and wb_adr_i( 7 downto 0)=x"00" else
138
            ZEROS(31 downto 16) & sp when wbactive='1' and wb_adr_i(19 downto 16)=x"0" and wb_adr_i( 7 downto 0)=x"04" else
139
            ZEROS(31 downto 16) & sc when wbactive='1' and wb_adr_i(19 downto 16)=x"0" and wb_adr_i( 7 downto 0)=x"08" else
140
            ZEROS(2 downto 0)&csel3 &
141
            ZEROS(2 downto 0)&csel2 &
142
            ZEROS(2 downto 0)&csel1 &
143
            ZEROS(2 downto 0)&csel0  when wbactive='1' and wb_adr_i(19 downto 16)=x"0" and wb_adr_i( 7 downto 0)=x"10" else
144
            rdata2                   when wbactive='1' and wb_adr_i(19 downto 16)=x"1" else
145
            (others => '-');
146
 
147
wb_ack_o <= wbactive and ram_ack when wb_adr_i(19 downto 16)=x"1" else
148
                        wbactive;
149
 
150
wb_irq_o <= sdone and irqen;
151
 
152
status_reg <= ZEROS(31 downto 3) & sdone & irqen & spen;
153
 
154
wbproc: process(reset, clk) is
155
variable scv : unsigned(15 downto 0);
156
variable spv : unsigned(15 downto 0);
157
begin
158
        if reset='1' then
159
                spen  <= '0';
160
                irqen <= '0';
161
                sdone <= '0';
162
                sp    <= (others => '0');
163
                sc    <= (others => '0');
164
 
165
                csel0 <= (others => '0');
166
                csel1 <= (others => '0');
167
                csel2 <= (others => '0');
168
                csel3 <= (others => '0');
169
 
170
                sreg  <= (others => '0');
171
                we1   <= '0';
172
                ram_ack <= '0';
173
        elsif clk'event and clk='1' then
174
                -- Sample Data
175
                if spen='1' then
176
                        -- sampling done?
177
                        if sc=ZEROS(15 downto 0) then
178
                                spen  <= '0';
179
                                sdone <= '1';
180
                        end if;
181
 
182
                        -- sample into sreg 
183
                        if sp(2 downto 0)="111" then
184
                                addr1  <= sp(14 downto 3);
185
                                wdata1 <= sreg & chan;
186
                                we1    <= '1';
187
                        else
188
                                sreg   <= sreg(23 downto 0) & chan;
189
                                we1    <= '0';
190
                        end if;
191
 
192
                        -- increase pointer; decrease counter
193
                        scv := unsigned(sc);
194
                        scv := scv - 1;
195
                        sc <= std_logic_vector(scv);
196
 
197
                        spv := unsigned(sp);
198
                        spv := spv + 1;
199
                        sp <= std_logic_vector(spv);
200
                end if;
201
 
202
                -- WB register write request
203
                if wbactive='1' and wb_we_i='1' and wb_adr_i(19 downto 16)=x"0" then
204
                        if wb_adr_i(7 downto 0)=x"00" then -- StatusRegister
205
                                spen  <= wb_dat_i(0);
206
                                irqen <= wb_dat_i(1);
207
                                sdone <= '0';
208
                        end if;
209
 
210
                        if wb_adr_i(7 downto 0)=x"04" then -- SamplePointer
211
                                sp <= wb_dat_i(15 downto 0);
212
                        end if;
213
 
214
                        if wb_adr_i(7 downto 0)=x"08" then -- SampleCounter
215
                                sc <= wb_dat_i(15 downto 0);
216
                        end if;
217
 
218
                        if wb_adr_i(7 downto 0)=x"10" then -- Channel Sel
219
                                if wb_sel_i(0)='1' then
220
                                        csel3 <= wb_dat_i( 4 downto  0);
221
                                end if;
222
 
223
                                if wb_sel_i(1)='1' then
224
                                        csel2 <= wb_dat_i(12 downto  8);
225
                                end if;
226
 
227
                                if wb_sel_i(2)='1' then
228
                                        csel1 <= wb_dat_i(20 downto 16);
229
                                end if;
230
 
231
                                if wb_sel_i(3)='1' then
232
                                        csel0 <= wb_dat_i(28 downto 24);
233
                                end if;
234
                        end if;
235
                end if;
236
 
237
                -- Buffer read request
238
                if wbactive='1' and wb_adr_i(19 downto 16)=x"1" then
239
                        ram_ack <= '1' and not ram_ack;
240
                else
241
                        ram_ack <= '0';
242
                end if;
243
        end if;
244
end process;
245
 
246
-- Probe buffering and muxing -----------------------------------------------
247
bufproc: process(clk, reset) is -- buffer probes BEFORE mux (timing)
248
begin
249
        if reset='1' then
250
                probe_b <= (others => '0');
251
        elsif clk'event and clk='1' then
252
                probe_b <= probe;
253
        end if;
254
end process;
255
 
256
 
257
mux0: mux32           -- Channel 0
258
        port map (
259
                input    => probe_b,
260
                output   => chan(0),
261
                sel      => csel0 );
262
 
263
mux1: mux32           -- Channel 1
264
        port map (
265
                input    => probe_b,
266
                output   => chan(1),
267
                sel      => csel1 );
268
 
269
mux2: mux32           -- Channel 2
270
        port map (
271
                input    => probe_b,
272
                output   => chan(2),
273
                sel      => csel2 );
274
 
275
mux3: mux32           -- Channel 3
276
        port map (
277
                input    => probe_b,
278
                output   => chan(3),
279
                sel      => csel3 );
280
 
281
end rtl;
282
 

powered by: WebSVN 2.1.0

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