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

Subversion Repositories wbscope

[/] [wbscope/] [trunk/] [rtl/] [axi4lscope.v] - Blame information for rev 13

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 12 dgisselq
`timescale 1 ns / 1 ps
2
////////////////////////////////////////////////////////////////////////////////
3
//
4
// Filename:    axi4lscope.v
5
//
6 13 dgisselq
// Project:     WBScope, a wishbone hosted scope
7 12 dgisselq
//
8
// Purpose:     This is a generic/library routine for providing a bus accessed
9
//      'scope' or (perhaps more appropriately) a bus accessed logic analyzer.
10
//      The general operation is such that this 'scope' can record and report
11
//      on any 32 bit value transiting through the FPGA.  Once started and
12
//      reset, the scope records a copy of the input data every time the clock
13
//      ticks with the circuit enabled.  That is, it records these values up
14
//      until the trigger.  Once the trigger goes high, the scope will record
15 13 dgisselq
//      for br_holdoff more counts before stopping.  Values may then be read
16 12 dgisselq
//      from the buffer, oldest to most recent.  After reading, the scope may
17
//      then be reset for another run.
18
//
19
//      In general, therefore, operation happens in this fashion:
20
//              1. A reset is issued.
21
//              2. Recording starts, in a circular buffer, and continues until
22
//              3. The trigger line is asserted.
23
//                      The scope registers the asserted trigger by setting
24
//                      the 'o_triggered' output flag.
25
//              4. A counter then ticks until the last value is written
26
//                      The scope registers that it has stopped recording by
27
//                      setting the 'o_stopped' output flag.
28
//              5. The scope recording is then paused until the next reset.
29
//              6. While stopped, the CPU can read the data from the scope
30
//              7. -- oldest to most recent
31 13 dgisselq
//              8. -- one value per i_rd&i_data_clk
32 12 dgisselq
//              9. Writes to the data register reset the address to the
33
//                      beginning of the buffer
34
//
35
//      Although the data width DW is parameterized, it is not very changable,
36
//      since the width is tied to the width of the data bus, as is the 
37
//      control word.  Therefore changing the data width would require changing
38
//      the interface.  It's doable, but it would be a change to the interface.
39
//
40
//      The SYNCHRONOUS parameter turns on and off meta-stability
41
//      synchronization.  Ideally a wishbone scope able to handle one or two
42
//      clocks would have a changing number of ports as this SYNCHRONOUS
43
//      parameter changed.  Other than running another script to modify
44
//      this, I don't know how to do that so ... we'll just leave it running
45
//      off of two clocks or not.
46
//
47
//
48
//      Internal to this routine, registers and wires are named with one of the
49
//      following prefixes:
50
//
51
//      i_      An input port to the routine
52
//      o_      An output port of the routine
53
//      br_     A register, controlled by the bus clock
54
//      dr_     A register, controlled by the data clock
55
//      bw_     A wire/net, controlled by the bus clock
56
//      dw_     A wire/net, controlled by the data clock
57
//
58
//      And, of course, since AXI wants to be particular about their port
59
//      naming conventions, anything beginning with
60
//
61
//      S_AXI_
62
//
63
//      is a signal associated with this function as an AXI slave.
64
//      
65
//
66
// Creator:     Dan Gisselquist, Ph.D.
67
//              Gisselquist Technology, LLC
68
//
69
////////////////////////////////////////////////////////////////////////////////
70
//
71 13 dgisselq
// Copyright (C) 2015-2017, Gisselquist Technology, LLC
72 12 dgisselq
//
73
// This program is free software (firmware): you can redistribute it and/or
74
// modify it under the terms of  the GNU General Public License as published
75
// by the Free Software Foundation, either version 3 of the License, or (at
76
// your option) any later version.
77
//
78
// This program is distributed in the hope that it will be useful, but WITHOUT
79
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
80
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
81
// for more details.
82
//
83
// You should have received a copy of the GNU General Public License along
84 13 dgisselq
// with this program.  (It's in the $(ROOT)/doc directory.  Run make with no
85 12 dgisselq
// target there if the PDF file isn't present.)  If not, see
86
// <http://www.gnu.org/licenses/> for a copy.
87
//
88
// License:     GPL, v3, as defined and found on www.gnu.org,
89
//              http://www.gnu.org/licenses/gpl.html
90
//
91
//
92
////////////////////////////////////////////////////////////////////////////////
93
//
94
//
95 13 dgisselq
`default_nettype        none
96
//
97 12 dgisselq
module axi4lscope
98
        #(
99
                // Users to add parameters here
100 13 dgisselq
                parameter [4:0]  LGMEM = 5'd10,
101 12 dgisselq
                parameter       BUSW = 32,
102
                parameter       SYNCHRONOUS=1,
103 13 dgisselq
                parameter       HOLDOFFBITS = 20,
104
                parameter [(HOLDOFFBITS-1):0]    DEFAULT_HOLDOFF
105
                                                = ((1<<(LGMEM-1))-4),
106 12 dgisselq
                // User parameters ends
107
                // DO NOT EDIT BELOW THIS LINE ---------------------
108
                // Do not modify the parameters beyond this line
109
                // Width of S_AXI data bus
110
                parameter integer C_S_AXI_DATA_WIDTH    = 32,
111
                // Width of S_AXI address bus
112
                parameter integer C_S_AXI_ADDR_WIDTH    = 4
113
        )
114
        (
115
                // Users to add ports here
116 13 dgisselq
                input wire      i_data_clk, // The data clock, can be set to ACLK
117 12 dgisselq
                input wire      i_ce,   // = '1' when recordable data is present
118
                input wire      i_trigger,// = '1' when interesting event hapns
119
                input wire      [31:0]   i_data,
120
                output  wire    o_interrupt,    // ='1' when scope has stopped
121
                // User ports ends
122
                // DO NOT EDIT BELOW THIS LINE ---------------------
123
                // Do not modify the ports beyond this line
124
                // Global Clock Signal
125
                input wire  S_AXI_ACLK,
126
                // Global Reset Signal. This Signal is Active LOW
127
                input wire  S_AXI_ARESETN,
128
                // Write address (issued by master, acceped by Slave)
129
                input wire [C_S_AXI_ADDR_WIDTH-1 : 0] S_AXI_AWADDR,
130
                // Write channel Protection type. This signal indicates the
131
                // privilege and security level of the transaction, and whether
132
                // the transaction is a data access or an instruction access.
133
                input wire [2 : 0] S_AXI_AWPROT,
134
                // Write address valid. This signal indicates that the master
135
                // signaling valid write address and control information.
136
                input wire  S_AXI_AWVALID,
137
                // Write address ready. This signal indicates that the slave
138
                // is ready to accept an address and associated control signals.
139
                output wire  S_AXI_AWREADY,
140
                // Write data (issued by master, acceped by Slave) 
141
                input wire [C_S_AXI_DATA_WIDTH-1 : 0] S_AXI_WDATA,
142
                // Write strobes. This signal indicates which byte lanes hold
143
                // valid data. There is one write strobe bit for each eight
144
                // bits of the write data bus.    
145
                input wire [(C_S_AXI_DATA_WIDTH/8)-1 : 0] S_AXI_WSTRB,
146
                // Write valid. This signal indicates that valid write
147
                // data and strobes are available.
148
                input wire  S_AXI_WVALID,
149
                // Write ready. This signal indicates that the slave
150
                // can accept the write data.
151
                output wire  S_AXI_WREADY,
152
                // Write response. This signal indicates the status
153
                // of the write transaction.
154
                output wire [1 : 0] S_AXI_BRESP,
155
                // Write response valid. This signal indicates that the channel
156
                // is signaling a valid write response.
157
                output wire  S_AXI_BVALID,
158
                // Response ready. This signal indicates that the master
159
                // can accept a write response.
160
                input wire  S_AXI_BREADY,
161
                // Read address (issued by master, acceped by Slave)
162
                input wire [C_S_AXI_ADDR_WIDTH-1 : 0] S_AXI_ARADDR,
163
                // Protection type. This signal indicates the privilege
164
                // and security level of the transaction, and whether the
165
                // transaction is a data access or an instruction access.
166
                input wire [2 : 0] S_AXI_ARPROT,
167
                // Read address valid. This signal indicates that the channel
168
                // is signaling valid read address and control information.
169
                input wire  S_AXI_ARVALID,
170
                // Read address ready. This signal indicates that the slave is
171
                // ready to accept an address and associated control signals.
172
                output wire  S_AXI_ARREADY,
173
                // Read data (issued by slave)
174
                output wire [C_S_AXI_DATA_WIDTH-1 : 0] S_AXI_RDATA,
175
                // Read response. This signal indicates the status of the
176
                // read transfer.
177
                output wire [1 : 0] S_AXI_RRESP,
178
                // Read valid. This signal indicates that the channel is
179
                // signaling the required read data.
180
                output wire  S_AXI_RVALID,
181
                // Read ready. This signal indicates that the master can
182
                // accept the read data and response information.
183
                input wire  S_AXI_RREADY
184
                // DO NOT EDIT ABOVE THIS LINE ---------------------
185
        );
186
 
187
        // AXI4LITE signals
188
        reg [C_S_AXI_ADDR_WIDTH-1 : 0]   axi_awaddr;
189
        reg                             axi_awready;
190
        reg                             axi_wready;
191
        // reg          [1 : 0]         axi_bresp;
192
        reg                             axi_bvalid;
193
        reg [C_S_AXI_ADDR_WIDTH-1 : 0]   axi_araddr;
194
        reg                             axi_arready;
195
        // reg           [1 : 0]        axi_rresp;
196
        reg                             axi_rvalid;
197
 
198
 
199 13 dgisselq
        wire    write_stb;
200
 
201 12 dgisselq
        ///////////////////////////////////////////////////
202
        //
203
        // Decode and handle the AXI/Bus signaling
204
        //
205
        ///////////////////////////////////////////////////
206
        //
207
        // Sadly, the AXI bus is *way* more complicated to
208
        // deal with than it needs to be.  Still, we offer
209
        // the following as a simple means of dealing with
210
        // it.  The majority of the code in this section 
211
        // comes directly from a Xilinx/Vivado generated
212
        // file.
213
        //
214
        // Gisselquist Technology, LLC, claims no copyright
215
        // or ownership of this section of the code.
216
        //
217
        wire    i_reset;
218
        assign  i_reset = !S_AXI_ARESETN;
219
 
220
        always @(posedge S_AXI_ACLK)
221
                if (i_reset)
222
                        axi_awready <= 1'b0;
223
                else if ((!axi_awready)&&(S_AXI_AWVALID)&&(S_AXI_WVALID))
224
                        axi_awready <= 1'b1;
225
                else
226
                        axi_awready <= 1'b0;
227
        assign  S_AXI_AWREADY = axi_awready;
228
 
229
        always @(posedge S_AXI_ACLK)
230
                if ((!axi_awready)&&(S_AXI_AWVALID)&&(S_AXI_WVALID))
231
                        axi_awaddr <= S_AXI_AWADDR;
232
 
233
        always @(posedge S_AXI_ACLK)
234
                if (i_reset)
235
                        axi_wready <= 1'b0;
236
                else if ((!axi_wready)&&(S_AXI_WVALID)&&(S_AXI_AWVALID))
237
                        axi_wready <= 1'b1;
238
                else
239
                        axi_wready <= 1'b0;
240
        assign  S_AXI_WREADY = axi_wready;
241
 
242
        always @(posedge S_AXI_ACLK)
243
                if (i_reset)
244
                begin
245
                        axi_bvalid <= 0;
246
                        // axi_bresp <= 2'b00;
247
                end else if ((~axi_bvalid)&&(write_stb))
248
                begin
249
                        axi_bvalid <= 1'b1;
250
                        // axi_bresp <= 2'b00; // 'Okay' response
251
                end else if ((S_AXI_BREADY)&&(axi_bvalid))
252
                        axi_bvalid <= 1'b0;
253
        assign  S_AXI_BRESP = 2'b00;    // An 'OKAY' response
254
        assign  S_AXI_BVALID= axi_bvalid;
255
 
256
 
257
 
258
        always @(posedge S_AXI_ACLK)
259
                if (i_reset)
260
                begin
261
                        axi_arready <= 1'b0;
262
                        axi_araddr <= 0;
263
                end else if ((!axi_arready)&&(S_AXI_ARVALID))
264
                begin
265
                        axi_arready <= 1'b1;
266
                        axi_araddr <= S_AXI_ARADDR;
267
                end else
268
                        axi_arready <= 1'b0;
269
        assign  S_AXI_ARREADY = axi_arready;
270
 
271
        always @(posedge S_AXI_ACLK)
272
                if (i_reset)
273
                begin
274
                        axi_rvalid <= 0;
275
                        // axi_rresp  <= 0;
276
                end else if ((axi_arready)&&(S_AXI_ARVALID)&&(!axi_rvalid))
277
                begin
278
                        axi_rvalid <= 1'b0;
279
                        // axi_rresp <= 2'b00;
280
                end else if ((axi_rvalid)&&(S_AXI_RREADY))
281
                        axi_rvalid <= 1'b0;
282
        assign  S_AXI_RVALID = axi_rvalid;
283
        assign  S_AXI_RRESP  = 2'b00;
284
 
285
 
286
 
287
 
288
        ///////////////////////////////////////////////////
289
        //
290
        // Final simplification of the AXI code
291
        //
292
        ///////////////////////////////////////////////////
293
        //
294
        // Now that we've provided all of the bus signaling
295
        // above, can we make any sense of it?
296
        //
297
        // The following wires are here to provide some
298
        // simplification of the complex bus protocol.  In
299
        // particular, are we reading or writing during this
300
        // clock?  The two *should* be mutually exclusive
301
        // (i.e., you *shouldn't* be able to both read and
302
        // write on the same clock) ... but Xilinx's default
303
        // implementation does nothing to ensure that this
304
        // would be the case.
305
        //
306
        // From here on down, Gisselquist Technology, LLC,
307
        // claims a copyright on the code.
308
        //
309 13 dgisselq
        wire    bus_clock;
310
        assign  bus_clock = S_AXI_ACLK;
311
 
312 12 dgisselq
        wire    read_from_data;
313
        assign  read_from_data = (S_AXI_ARVALID)&&(S_AXI_ARREADY)
314
                                        &&(axi_araddr[0]);
315
 
316
        assign  write_stb = ((axi_awready)&&(S_AXI_AWVALID)
317
                                &&(axi_wready)&&(S_AXI_WVALID));
318
        wire    write_to_control;
319
        assign  write_to_control = (write_stb)&&(!axi_awaddr[0]);
320
 
321 13 dgisselq
        reg     read_address;
322
        always @(posedge bus_clock)
323
                read_address <= axi_araddr[0];
324 12 dgisselq
 
325
        wire    [31:0]   i_wb_data;
326
        assign  i_wb_data = S_AXI_WDATA;
327
 
328
 
329
        ///////////////////////////////////////////////////
330
        //
331
        // The actual SCOPE
332
        //
333
        ///////////////////////////////////////////////////
334
        //
335
        // Now that we've finished reading/writing from the
336
        // bus, ... or at least acknowledging reads and 
337
        // writes from and to the bus--even if they haven't
338
        // happened yet, now we implement our actual scope.
339
        // This includes implementing the actual reads/writes
340
        // from/to the bus.
341
        //
342
        // From here on down, is the heart of the scope itself.
343
        //
344
        reg     [(LGMEM-1):0]    raddr;
345
        reg     [(BUSW-1):0]     mem[0:((1<<LGMEM)-1)];
346
 
347
        // Our status/config register
348
        wire            bw_reset_request, bw_manual_trigger,
349
                        bw_disable_trigger, bw_reset_complete;
350 13 dgisselq
        reg     [2:0]    br_config;
351
        reg     [(HOLDOFFBITS-1):0]      br_holdoff;
352
        initial br_config = 3'b0;
353
        initial br_holdoff = DEFAULT_HOLDOFF;
354
        always @(posedge bus_clock)
355 12 dgisselq
                if (write_to_control)
356
                begin
357
                        br_config <= { i_wb_data[31],
358 13 dgisselq
                                i_wb_data[27],
359
                                i_wb_data[26] };
360
                        br_holdoff <= i_wb_data[(HOLDOFFBITS-1):0];
361 12 dgisselq
                end else if (bw_reset_complete)
362 13 dgisselq
                        br_config[2] <= 1'b1;
363
        assign  bw_reset_request   = (!br_config[2]);
364
        assign  bw_manual_trigger  = (br_config[1]);
365
        assign  bw_disable_trigger = (br_config[0]);
366 12 dgisselq
 
367
        wire    dw_reset, dw_manual_trigger, dw_disable_trigger;
368
        generate
369
        if (SYNCHRONOUS > 0)
370
        begin
371
                assign  dw_reset = bw_reset_request;
372
                assign  dw_manual_trigger = bw_manual_trigger;
373
                assign  dw_disable_trigger = bw_disable_trigger;
374
                assign  bw_reset_complete = bw_reset_request;
375
        end else begin
376
                reg             r_reset_complete;
377
                (* ASYNC_REG = "TRUE" *) reg    [2:0]    q_iflags;
378
                reg     [2:0]    r_iflags;
379
 
380
                // Resets are synchronous to the bus clock, not the data clock
381
                // so do a clock transfer here
382
                initial q_iflags = 3'b000;
383
                initial r_reset_complete = 1'b0;
384 13 dgisselq
                always @(posedge i_data_clk)
385 12 dgisselq
                begin
386
                        q_iflags <= { bw_reset_request, bw_manual_trigger, bw_disable_trigger };
387
                        r_iflags <= q_iflags;
388
                        r_reset_complete <= (dw_reset);
389
                end
390
 
391
                assign  dw_reset = r_iflags[2];
392
                assign  dw_manual_trigger = r_iflags[1];
393
                assign  dw_disable_trigger = r_iflags[0];
394
 
395
                (* ASYNC_REG = "TRUE" *) reg    q_reset_complete;
396
                reg     qq_reset_complete;
397
                // Pass an acknowledgement back from the data clock to the bus
398
                // clock that the reset has been accomplished
399
                initial q_reset_complete = 1'b0;
400
                initial qq_reset_complete = 1'b0;
401 13 dgisselq
                always @(posedge bus_clock)
402 12 dgisselq
                begin
403
                        q_reset_complete  <= r_reset_complete;
404
                        qq_reset_complete <= q_reset_complete;
405
                end
406
 
407
                assign bw_reset_complete = qq_reset_complete;
408
        end endgenerate
409
 
410
        //
411
        // Set up the trigger
412
        //
413
        //
414
        // Write with the i-clk, or input clock.  All outputs read with the
415 13 dgisselq
        // bus clock, or bus_clock  as we've called it here.
416 12 dgisselq
        reg     dr_triggered, dr_primed;
417
        wire    dw_trigger;
418
        assign  dw_trigger = (dr_primed)&&(
419 13 dgisselq
                                ((i_trigger)&&(!dw_disable_trigger))
420 12 dgisselq
                                ||(dw_manual_trigger));
421
        initial dr_triggered = 1'b0;
422 13 dgisselq
        always @(posedge i_data_clk)
423 12 dgisselq
                if (dw_reset)
424
                        dr_triggered <= 1'b0;
425
                else if ((i_ce)&&(dw_trigger))
426
                        dr_triggered <= 1'b1;
427
 
428
        //
429
        // Determine when memory is full and capture is complete
430
        //
431
        // Writes take place on the data clock
432 13 dgisselq
        // The counter is unsigned
433
        (* ASYNC_REG="TRUE" *) reg      [(HOLDOFFBITS-1):0]      counter;
434
 
435 12 dgisselq
        reg             dr_stopped;
436
        initial dr_stopped = 1'b0;
437 13 dgisselq
        initial counter = 0;
438
        always @(posedge i_data_clk)
439 12 dgisselq
                if (dw_reset)
440 13 dgisselq
                        counter <= 0;
441
                else if ((i_ce)&&(dr_triggered)&&(!dr_stopped))
442 12 dgisselq
                begin
443 13 dgisselq
                        counter <= counter + 1'b1;
444
                end
445
        always @(posedge i_data_clk)
446
                if ((!dr_triggered)||(dw_reset))
447 12 dgisselq
                        dr_stopped <= 1'b0;
448 13 dgisselq
                else if (HOLDOFFBITS > 1) // if (i_ce)
449
                        dr_stopped <= (counter >= br_holdoff);
450
                else if (HOLDOFFBITS <= 1)
451
                        dr_stopped <= ((i_ce)&&(dw_trigger));
452 12 dgisselq
 
453
        //
454
        //      Actually do our writes to memory.  Record, via 'primed' when
455
        //      the memory is full.
456
        //
457
        //      The 'waddr' address that we are using really crosses two clock
458
        //      domains.  While writing and changing, it's in the data clock
459
        //      domain.  Once stopped, it becomes part of the bus clock domain.
460
        //      The clock transfer on the stopped line handles the clock
461
        //      transfer for these signals.
462
        //
463
        reg     [(LGMEM-1):0]    waddr;
464
        initial waddr = {(LGMEM){1'b0}};
465
        initial dr_primed = 1'b0;
466 13 dgisselq
        always @(posedge i_data_clk)
467 12 dgisselq
                if (dw_reset) // For simulation purposes, supply a valid value
468
                begin
469
                        waddr <= 0; // upon reset.
470
                        dr_primed <= 1'b0;
471 13 dgisselq
                end else if ((i_ce)&&(!dr_stopped))
472 12 dgisselq
                begin
473
                        // mem[waddr] <= i_data;
474
                        waddr <= waddr + {{(LGMEM-1){1'b0}},1'b1};
475 13 dgisselq
                        if (!dr_primed)
476
                        begin
477
                                //if (br_holdoff[(HOLDOFFBITS-1):LGMEM]==0)
478
                                //      dr_primed <= (waddr >= br_holdoff[(LGMEM-1):0]);
479
                                // else
480
 
481
                                        dr_primed <= (&waddr);
482
                        end
483 12 dgisselq
                end
484
 
485 13 dgisselq
        // Delay the incoming data so that we can get our trigger
486
        // logic to line up with the data.  The goal is to have a
487
        // hold off of zero place the trigger in the last memory
488
        // address.
489
        localparam      STOPDELAY = 1;
490
        wire    [(BUSW-1):0]             wr_piped_data;
491
        generate
492
        if (STOPDELAY == 0)
493
                // No delay ... just assign the wires to our input lines
494
                assign  wr_piped_data = i_data;
495
        else if (STOPDELAY == 1)
496
        begin
497
                //
498
                // Delay by one means just register this once
499
                reg     [(BUSW-1):0]     data_pipe;
500
                always @(posedge i_data_clk)
501
                        if (i_ce)
502
                                data_pipe <= i_data;
503
                assign  wr_piped_data = data_pipe;
504
        end else begin
505
                // Arbitrary delay ... use a longer pipe
506
                reg     [(STOPDELAY*BUSW-1):0]   data_pipe;
507
 
508
                always @(posedge i_data_clk)
509
                        if (i_ce)
510
                                data_pipe <= { data_pipe[((STOPDELAY-1)*BUSW-1):0], i_data };
511
                assign  wr_piped_data = { data_pipe[(STOPDELAY*BUSW-1):((STOPDELAY-1)*BUSW)] };
512
        end endgenerate
513
 
514
        always @(posedge i_data_clk)
515
                if ((i_ce)&&(!dr_stopped))
516
                        mem[waddr] <= wr_piped_data;
517
 
518 12 dgisselq
        //
519
        // Clock transfer of the status signals
520
        //
521
        wire    bw_stopped, bw_triggered, bw_primed;
522
        generate
523
        if (SYNCHRONOUS > 0)
524
        begin
525
                assign  bw_stopped   = dr_stopped;
526
                assign  bw_triggered = dr_triggered;
527
                assign  bw_primed    = dr_primed;
528
        end else begin
529
                // These aren't a problem, since none of these are strobe
530
                // signals.  They goes from low to high, and then stays high
531
                // for many clocks.  Swapping is thus easy--two flip flops to
532
                // protect against meta-stability and we're done.
533
                //
534
                (* ASYNC_REG = "TRUE" *) reg    [2:0]    q_oflags;
535
                reg     [2:0]    r_oflags;
536
                initial q_oflags = 3'h0;
537
                initial r_oflags = 3'h0;
538 13 dgisselq
                always @(posedge bus_clock)
539 12 dgisselq
                        if (bw_reset_request)
540
                        begin
541
                                q_oflags <= 3'h0;
542
                                r_oflags <= 3'h0;
543
                        end else begin
544
                                q_oflags <= { dr_stopped, dr_triggered, dr_primed };
545
                                r_oflags <= q_oflags;
546
                        end
547
 
548
                assign  bw_stopped   = r_oflags[2];
549
                assign  bw_triggered = r_oflags[1];
550
                assign  bw_primed    = r_oflags[0];
551
        end endgenerate
552
 
553
        // Reads use the bus clock
554 13 dgisselq
        always @(posedge bus_clock)
555 12 dgisselq
        begin
556 13 dgisselq
                if ((bw_reset_request)||(write_to_control))
557 12 dgisselq
                        raddr <= 0;
558
                else if ((read_from_data)&&(bw_stopped))
559 13 dgisselq
                        raddr <= raddr + 1'b1; // Data read, when stopped
560 12 dgisselq
        end
561
 
562 13 dgisselq
        reg     [(LGMEM-1):0]    this_addr;
563
        always @(posedge bus_clock)
564
                if (read_from_data)
565
                        this_addr <= raddr + waddr + 1'b1;
566
                else
567
                        this_addr <= raddr + waddr;
568 12 dgisselq
 
569
        reg     [31:0]   nxt_mem;
570 13 dgisselq
        always @(posedge bus_clock)
571
                nxt_mem <= mem[this_addr];
572 12 dgisselq
 
573 13 dgisselq
        wire    [19:0]   full_holdoff;
574
        assign full_holdoff[(HOLDOFFBITS-1):0] = br_holdoff;
575
        generate if (HOLDOFFBITS < 20)
576
                assign full_holdoff[19:(HOLDOFFBITS)] = 0;
577
        endgenerate
578 12 dgisselq
 
579 13 dgisselq
        reg     [31:0]   o_bus_data;
580 12 dgisselq
        wire    [4:0]    bw_lgmem;
581
        assign          bw_lgmem = LGMEM;
582 13 dgisselq
        always @(posedge bus_clock)
583
                if (!read_address) // Control register read
584
                        o_bus_data <= { bw_reset_request,
585 12 dgisselq
                                        bw_stopped,
586
                                        bw_triggered,
587
                                        bw_primed,
588
                                        bw_manual_trigger,
589
                                        bw_disable_trigger,
590
                                        (raddr == {(LGMEM){1'b0}}),
591
                                        bw_lgmem,
592 13 dgisselq
                                        full_holdoff  };
593
                else if (!bw_stopped) // read, prior to stopping
594
                        o_bus_data <= i_data;
595 12 dgisselq
                else // if (i_wb_addr) // Read from FIFO memory
596 13 dgisselq
                        o_bus_data <= nxt_mem; // mem[raddr+waddr];
597 12 dgisselq
 
598 13 dgisselq
        assign  S_AXI_RDATA = o_bus_data;
599 12 dgisselq
 
600
        reg     br_level_interrupt;
601
        initial br_level_interrupt = 1'b0;
602 13 dgisselq
        assign  o_interrupt = (bw_stopped)&&(!bw_disable_trigger)
603
                                        &&(!br_level_interrupt);
604
        always @(posedge bus_clock)
605 12 dgisselq
                if ((bw_reset_complete)||(bw_reset_request))
606
                        br_level_interrupt<= 1'b0;
607
                else
608 13 dgisselq
                        br_level_interrupt<= (bw_stopped)&&(!bw_disable_trigger);
609 12 dgisselq
 
610 13 dgisselq
        // verilator lint_off UNUSED
611
        // Make verilator happy
612
        wire    [44:0]   unused;
613
        assign unused = { S_AXI_WSTRB, S_AXI_ARPROT, S_AXI_AWPROT,
614
                axi_awaddr[3:1], axi_araddr[3:1],
615
                i_wb_data[30:28], i_wb_data[25:0] };
616
        // verilator lint_on UNUSED
617 12 dgisselq
endmodule

powered by: WebSVN 2.1.0

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