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 58... |
Line 57... |
// 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
|
Line 112... |
Line 111... |
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 [19:0] bw_holdoff;
|
initial br_config = DEFAULT_HOLDOFF;
|
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 198... |
Line 197... |
(* ASYNC_REG="TRUE" *) reg [19:0] counter;// This is unsigned
|
(* ASYNC_REG="TRUE" *) reg [19:0] counter;// This is unsigned
|
initial dr_stopped = 1'b0;
|
initial dr_stopped = 1'b0;
|
initial counter = 20'h0000;
|
initial counter = 20'h0000;
|
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 + 20'h01;
|
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+20'd1 >= 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 229... |
Line 230... |
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_triggered)||(!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_triggered)||(!dr_stopped)))
|
mem[waddr] <= i_data;
|
mem[waddr] <= i_data;
|
|
|
//
|
//
|
// Clock transfer of the status signals
|
// Clock transfer of the status signals
|
//
|
//
|
Line 278... |
Line 279... |
|
|
// 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;
|