Line 1... |
Line 1... |
///////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
//
|
//
|
// Filename: wbscope.v
|
// Filename: wbscope.v
|
//
|
//
|
// Project: FPGA Library of Routines
|
// Project: WBScope, a wishbone hosted scope
|
//
|
//
|
// Purpose: This is a generic/library routine for providing a bus accessed
|
// Purpose: This is a generic/library routine for providing a bus accessed
|
// 'scope' or (perhaps more appropriately) a bus accessed logic
|
// 'scope' or (perhaps more appropriately) a bus accessed logic analyzer.
|
// analyzer. The general operation is such that this 'scope' can
|
// The general operation is such that this 'scope' can record and report
|
// record and report on any 32 bit value transiting through the
|
// on any 32 bit value transiting through the FPGA. Once started and
|
// FPGA. Once started and reset, the scope records a copy of the
|
// reset, the scope records a copy of the input data every time the clock
|
// input data every time the clock ticks with the circuit enabled.
|
// ticks with the circuit enabled. That is, it records these values up
|
// That is, it records these values up until the trigger. Once
|
// until the trigger. Once the trigger goes high, the scope will record
|
// the trigger goes high, the scope will record for bw_holdoff
|
// for bw_holdoff more counts before stopping. Values may then be read
|
// more counts before stopping. Values may then be read from the
|
// from the buffer, oldest to most recent. After reading, the scope may
|
// buffer, oldest to most recent. After reading, the scope may
|
|
// then be reset for another run.
|
// then be reset for another run.
|
//
|
//
|
// In general, therefore, operation happens in this fashion:
|
// In general, therefore, operation happens in this fashion:
|
// 1. A reset is issued.
|
// 1. A reset is issued.
|
// 2. Recording starts, in a circular buffer, and continues until
|
// 2. Recording starts, in a circular buffer, and continues until
|
Line 56... |
Line 55... |
// dw_ A wire/net, controlled by the data clock
|
// dw_ A wire/net, controlled by the data clock
|
//
|
//
|
// Creator: Dan Gisselquist, Ph.D.
|
// Creator: Dan Gisselquist, Ph.D.
|
// Gisselquist Technology, LLC
|
// Gisselquist Technology, LLC
|
//
|
//
|
///////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
//
|
//
|
// Copyright (C) 2015, Gisselquist Technology, LLC
|
// Copyright (C) 2015-2017, Gisselquist Technology, LLC
|
//
|
//
|
// This program is free software (firmware): you can redistribute it and/or
|
// This program is free software (firmware): you can redistribute it and/or
|
// modify it under the terms of the GNU General Public License as published
|
// modify it under the terms of the GNU General Public License as published
|
// by the Free Software Foundation, either version 3 of the License, or (at
|
// by the Free Software Foundation, either version 3 of the License, or (at
|
// your option) any later version.
|
// your option) any later version.
|
Line 71... |
Line 70... |
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
// for more details.
|
// for more details.
|
//
|
//
|
// You should have received a copy of the GNU General Public License along
|
// You should have received a copy of the GNU General Public License along
|
// with this program. (It's in the $(ROOT)/doc directory, run make with no
|
// with this program. (It's in the $(ROOT)/doc directory. Run make with no
|
// target there if the PDF file isn't present.) If not, see
|
// target there if the PDF file isn't present.) If not, see
|
// <http://www.gnu.org/licenses/> for a copy.
|
// <http://www.gnu.org/licenses/> for a copy.
|
//
|
//
|
// License: GPL, v3, as defined and found on www.gnu.org,
|
// License: GPL, v3, as defined and found on www.gnu.org,
|
// http://www.gnu.org/licenses/gpl.html
|
// http://www.gnu.org/licenses/gpl.html
|
//
|
//
|
//
|
//
|
/////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
//
|
module wbscope(i_clk, i_ce, i_trigger, i_data,
|
module wbscope(i_clk, i_ce, i_trigger, i_data,
|
i_wb_clk, i_wb_cyc, i_wb_stb, i_wb_we, i_wb_addr, i_wb_data,
|
i_wb_clk, i_wb_cyc, i_wb_stb, i_wb_we, i_wb_addr, i_wb_data,
|
o_wb_ack, o_wb_stall, o_wb_data,
|
o_wb_ack, o_wb_stall, o_wb_data,
|
o_interrupt);
|
o_interrupt);
|
parameter LGMEM = 5'd10, BUSW = 32, SYNCHRONOUS=1;
|
parameter LGMEM = 5'd10, BUSW = 32, SYNCHRONOUS=1,
|
|
DEFAULT_HOLDOFF = ((1<<(LGMEM-1))-4),
|
|
HOLDOFFBITS = 20;
|
// The input signals that we wish to record
|
// The input signals that we wish to record
|
input i_clk, i_ce, i_trigger;
|
input i_clk, i_ce, i_trigger;
|
input [(BUSW-1):0] i_data;
|
input [(BUSW-1):0] i_data;
|
// The WISHBONE bus for reading and configuring this scope
|
// The WISHBONE bus for reading and configuring this scope
|
input i_wb_clk, i_wb_cyc, i_wb_stb, i_wb_we;
|
input i_wb_clk, i_wb_cyc, i_wb_stb, i_wb_we;
|
Line 106... |
Line 109... |
|
|
// Our status/config register
|
// Our status/config register
|
wire bw_reset_request, bw_manual_trigger,
|
wire bw_reset_request, bw_manual_trigger,
|
bw_disable_trigger, bw_reset_complete;
|
bw_disable_trigger, bw_reset_complete;
|
reg [22:0] br_config;
|
reg [22:0] br_config;
|
wire [19:0] bw_holdoff;
|
wire [(HOLDOFFBITS-1):0] bw_holdoff;
|
initial br_config = ((1<<(LGMEM-1))-4);
|
initial br_config = DEFAULT_HOLDOFF;
|
always @(posedge i_wb_clk)
|
always @(posedge i_wb_clk)
|
if ((i_wb_cyc)&&(i_wb_stb)&&(~i_wb_addr))
|
if ((i_wb_stb)&&(~i_wb_addr))
|
begin
|
begin
|
if (i_wb_we)
|
if (i_wb_we)
|
br_config <= { i_wb_data[31],
|
br_config <= { i_wb_data[31],
|
(i_wb_data[27]),
|
(i_wb_data[27]),
|
i_wb_data[26],
|
i_wb_data[26],
|
Line 121... |
Line 124... |
end else if (bw_reset_complete)
|
end else if (bw_reset_complete)
|
br_config[22] <= 1'b1;
|
br_config[22] <= 1'b1;
|
assign bw_reset_request = (~br_config[22]);
|
assign bw_reset_request = (~br_config[22]);
|
assign bw_manual_trigger = (br_config[21]);
|
assign bw_manual_trigger = (br_config[21]);
|
assign bw_disable_trigger = (br_config[20]);
|
assign bw_disable_trigger = (br_config[20]);
|
assign bw_holdoff = br_config[19:0];
|
assign bw_holdoff = br_config[(HOLDOFFBITS-1):0];
|
|
|
wire dw_reset, dw_manual_trigger, dw_disable_trigger;
|
wire dw_reset, dw_manual_trigger, dw_disable_trigger;
|
generate
|
generate
|
if (SYNCHRONOUS > 0)
|
if (SYNCHRONOUS > 0)
|
begin
|
begin
|
Line 133... |
Line 136... |
assign dw_manual_trigger = bw_manual_trigger;
|
assign dw_manual_trigger = bw_manual_trigger;
|
assign dw_disable_trigger = bw_disable_trigger;
|
assign dw_disable_trigger = bw_disable_trigger;
|
assign bw_reset_complete = bw_reset_request;
|
assign bw_reset_complete = bw_reset_request;
|
end else begin
|
end else begin
|
reg r_reset_complete;
|
reg r_reset_complete;
|
reg [2:0] r_iflags, q_iflags;
|
(* ASYNC_REG = "TRUE" *) reg [2:0] q_iflags;
|
|
reg [2:0] r_iflags;
|
|
|
// Resets are synchronous to the bus clock, not the data clock
|
// Resets are synchronous to the bus clock, not the data clock
|
// so do a clock transfer here
|
// so do a clock transfer here
|
initial q_iflags = 3'b000;
|
initial q_iflags = 3'b000;
|
initial r_reset_complete = 1'b0;
|
initial r_reset_complete = 1'b0;
|
Line 150... |
Line 154... |
|
|
assign dw_reset = r_iflags[2];
|
assign dw_reset = r_iflags[2];
|
assign dw_manual_trigger = r_iflags[1];
|
assign dw_manual_trigger = r_iflags[1];
|
assign dw_disable_trigger = r_iflags[0];
|
assign dw_disable_trigger = r_iflags[0];
|
|
|
reg q_reset_complete, qq_reset_complete;
|
(* ASYNC_REG = "TRUE" *) reg q_reset_complete;
|
|
reg qq_reset_complete;
|
// Pass an acknowledgement back from the data clock to the bus
|
// Pass an acknowledgement back from the data clock to the bus
|
// clock that the reset has been accomplished
|
// clock that the reset has been accomplished
|
initial q_reset_complete = 1'b0;
|
initial q_reset_complete = 1'b0;
|
initial qq_reset_complete = 1'b0;
|
initial qq_reset_complete = 1'b0;
|
always @(posedge i_wb_clk)
|
always @(posedge i_wb_clk)
|
Line 187... |
Line 192... |
|
|
//
|
//
|
// Determine when memory is full and capture is complete
|
// Determine when memory is full and capture is complete
|
//
|
//
|
// Writes take place on the data clock
|
// Writes take place on the data clock
|
|
// The counter is unsigned
|
|
(* ASYNC_REG="TRUE" *) reg [(HOLDOFFBITS-1):0] counter;
|
|
reg less_than_holdoff;
|
|
always @(posedge i_clk)
|
|
if (dw_reset)
|
|
less_than_holdoff <= 1'b1;
|
|
else if (i_ce)
|
|
less_than_holdoff <= (counter < bw_holdoff);
|
|
|
reg dr_stopped;
|
reg dr_stopped;
|
reg [19:0] counter; // This is unsigned
|
|
initial dr_stopped = 1'b0;
|
initial dr_stopped = 1'b0;
|
initial counter = 20'h0000;
|
initial counter = 0;
|
always @(posedge i_clk)
|
always @(posedge i_clk)
|
if (dw_reset)
|
if (dw_reset)
|
begin
|
|
counter <= 0;
|
counter <= 0;
|
dr_stopped <= 1'b0;
|
else if ((i_ce)&&(dr_triggered)&&(~dr_stopped))
|
end else if ((i_ce)&&(dr_triggered))
|
|
begin // MUST BE a < and not <=, so that we can keep this w/in
|
begin // MUST BE a < and not <=, so that we can keep this w/in
|
// 20 bits. Else we'd need to add a bit to comparison
|
// 20 bits. Else we'd need to add a bit to comparison
|
// here.
|
// here.
|
if (counter < bw_holdoff)
|
counter <= counter + 1'b1;
|
counter <= counter + 20'h01;
|
|
else
|
|
dr_stopped <= 1'b1;
|
|
end
|
end
|
|
always @(posedge i_clk)
|
|
if ((~dr_triggered)||(dw_reset))
|
|
dr_stopped <= 1'b0;
|
|
else if (i_ce)
|
|
dr_stopped <= (counter+1'b1 >= bw_holdoff);
|
|
else
|
|
dr_stopped <= (counter >= bw_holdoff);
|
|
|
//
|
//
|
// Actually do our writes to memory. Record, via 'primed' when
|
// Actually do our writes to memory. Record, via 'primed' when
|
// the memory is full.
|
// the memory is full.
|
//
|
//
|
Line 224... |
Line 239... |
always @(posedge i_clk)
|
always @(posedge i_clk)
|
if (dw_reset) // For simulation purposes, supply a valid value
|
if (dw_reset) // For simulation purposes, supply a valid value
|
begin
|
begin
|
waddr <= 0; // upon reset.
|
waddr <= 0; // upon reset.
|
dr_primed <= 1'b0;
|
dr_primed <= 1'b0;
|
end else if ((i_ce)&&((~dr_triggered)||(counter < bw_holdoff)))
|
end else if ((i_ce)&&(!dr_stopped))
|
begin
|
begin
|
// mem[waddr] <= i_data;
|
// mem[waddr] <= i_data;
|
waddr <= waddr + {{(LGMEM-1){1'b0}},1'b1};
|
waddr <= waddr + {{(LGMEM-1){1'b0}},1'b1};
|
dr_primed <= (dr_primed)||(&waddr);
|
dr_primed <= (dr_primed)||(&waddr);
|
end
|
end
|
always @(posedge i_clk)
|
always @(posedge i_clk)
|
if ((i_ce)&&((~dr_triggered)||(counter < bw_holdoff)))
|
if ((i_ce)&&(!dr_stopped))
|
mem[waddr] <= i_data;
|
mem[waddr] <= i_data;
|
|
|
//
|
//
|
// Clock transfer of the status signals
|
// Clock transfer of the status signals
|
//
|
//
|
Line 250... |
Line 265... |
// These aren't a problem, since none of these are strobe
|
// These aren't a problem, since none of these are strobe
|
// signals. They goes from low to high, and then stays high
|
// signals. They goes from low to high, and then stays high
|
// for many clocks. Swapping is thus easy--two flip flops to
|
// for many clocks. Swapping is thus easy--two flip flops to
|
// protect against meta-stability and we're done.
|
// protect against meta-stability and we're done.
|
//
|
//
|
reg [2:0] q_oflags, r_oflags;
|
(* ASYNC_REG = "TRUE" *) reg [2:0] q_oflags;
|
|
reg [2:0] r_oflags;
|
initial q_oflags = 3'h0;
|
initial q_oflags = 3'h0;
|
initial r_oflags = 3'h0;
|
initial r_oflags = 3'h0;
|
always @(posedge i_wb_clk)
|
always @(posedge i_wb_clk)
|
if (bw_reset_request)
|
if (bw_reset_request)
|
begin
|
begin
|
Line 272... |
Line 288... |
|
|
// Reads use the bus clock
|
// Reads use the bus clock
|
reg br_wb_ack;
|
reg br_wb_ack;
|
initial br_wb_ack = 1'b0;
|
initial br_wb_ack = 1'b0;
|
wire bw_cyc_stb;
|
wire bw_cyc_stb;
|
assign bw_cyc_stb = ((i_wb_cyc)&&(i_wb_stb));
|
assign bw_cyc_stb = (i_wb_stb);
|
always @(posedge i_wb_clk)
|
always @(posedge i_wb_clk)
|
begin
|
begin
|
if ((bw_reset_request)
|
if ((bw_reset_request)
|
||((bw_cyc_stb)&&(i_wb_addr)&&(i_wb_we)))
|
||((bw_cyc_stb)&&(i_wb_addr)&&(i_wb_we)))
|
raddr <= 0;
|
raddr <= 0;
|
else if ((bw_cyc_stb)&&(i_wb_addr)&&(~i_wb_we)&&(bw_stopped))
|
else if ((bw_cyc_stb)&&(i_wb_addr)&&(~i_wb_we)&&(bw_stopped))
|
raddr <= raddr + {{(LGMEM-1){1'b0}},1'b1}; // Data read, when stopped
|
raddr <= raddr + 1'b1; // Data read, when stopped
|
|
|
if ((bw_cyc_stb)&&(~i_wb_we))
|
if ((bw_cyc_stb)&&(~i_wb_we))
|
begin // Read from the bus
|
begin // Read from the bus
|
br_wb_ack <= 1'b1;
|
br_wb_ack <= 1'b1;
|
end else if ((bw_cyc_stb)&&(i_wb_we))
|
end else if ((bw_cyc_stb)&&(i_wb_we))
|
Line 297... |
Line 313... |
always @(posedge i_wb_clk)
|
always @(posedge i_wb_clk)
|
nxt_mem <= mem[raddr+waddr+
|
nxt_mem <= mem[raddr+waddr+
|
(((bw_cyc_stb)&&(i_wb_addr)&&(~i_wb_we)) ?
|
(((bw_cyc_stb)&&(i_wb_addr)&&(~i_wb_we)) ?
|
{{(LGMEM-1){1'b0}},1'b1} : { (LGMEM){1'b0}} )];
|
{{(LGMEM-1){1'b0}},1'b1} : { (LGMEM){1'b0}} )];
|
|
|
|
wire [19:0] full_holdoff;
|
|
assign full_holdoff[(HOLDOFFBITS-1):0] = bw_holdoff;
|
|
generate if (HOLDOFFBITS < 20)
|
|
assign full_holdoff[19:(HOLDOFFBITS)] = 0;
|
|
endgenerate
|
|
|
wire [4:0] bw_lgmem;
|
wire [4:0] bw_lgmem;
|
assign bw_lgmem = LGMEM;
|
assign bw_lgmem = LGMEM;
|
always @(posedge i_wb_clk)
|
always @(posedge i_wb_clk)
|
if (~i_wb_addr) // Control register read
|
if (~i_wb_addr) // Control register read
|
o_wb_data <= { bw_reset_request,
|
o_wb_data <= { bw_reset_request,
|
Line 309... |
Line 331... |
bw_primed,
|
bw_primed,
|
bw_manual_trigger,
|
bw_manual_trigger,
|
bw_disable_trigger,
|
bw_disable_trigger,
|
(raddr == {(LGMEM){1'b0}}),
|
(raddr == {(LGMEM){1'b0}}),
|
bw_lgmem,
|
bw_lgmem,
|
bw_holdoff };
|
full_holdoff };
|
else if (~bw_stopped) // read, prior to stopping
|
else if (~bw_stopped) // read, prior to stopping
|
o_wb_data <= i_data;
|
o_wb_data <= i_data;
|
else // if (i_wb_addr) // Read from FIFO memory
|
else // if (i_wb_addr) // Read from FIFO memory
|
o_wb_data <= nxt_mem; // mem[raddr+waddr];
|
o_wb_data <= nxt_mem; // mem[raddr+waddr];
|
|
|