////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
//
|
//
|
// Filename: wbubus.v
|
// Filename: wbubus.v
|
//
|
//
|
// Project: XuLA2 board
|
// Project: XuLA2 board
|
//
|
//
|
// Purpose: This is the top level file for the entire JTAG-USB to Wishbone
|
// Purpose: This is the top level file for the entire JTAG-USB to Wishbone
|
// bus conversion. (It's also the place to start debugging, should
|
// bus conversion. (It's also the place to start debugging, should
|
// things not go as planned.) Bytes come into this routine, bytes go out,
|
// things not go as planned.) Bytes come into this routine, bytes go out,
|
// and the wishbone bus (external to this routine) is commanded in between.
|
// and the wishbone bus (external to this routine) is commanded in between.
|
//
|
//
|
//
|
//
|
//
|
//
|
// 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, 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.
|
//
|
//
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
// 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.
|
//
|
//
|
// 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 wbubus(i_clk, i_rx_stb, i_rx_data,
|
module wbubus(i_clk, i_rx_stb, i_rx_data,
|
o_wb_cyc, o_wb_stb, o_wb_we, o_wb_addr, o_wb_data,
|
o_wb_cyc, o_wb_stb, o_wb_we, o_wb_addr, o_wb_data,
|
i_wb_ack, i_wb_stall, i_wb_err, i_wb_data,
|
i_wb_ack, i_wb_stall, i_wb_err, i_wb_data,
|
i_interrupt,
|
i_interrupt,
|
o_tx_stb, o_tx_data, i_tx_busy);
|
o_tx_stb, o_tx_data, i_tx_busy);
|
parameter LGWATCHDOG=19;
|
parameter LGWATCHDOG=19;
|
input i_clk;
|
input i_clk;
|
input i_rx_stb;
|
input i_rx_stb;
|
input [7:0] i_rx_data;
|
input [7:0] i_rx_data;
|
output wire o_wb_cyc, o_wb_stb, o_wb_we;
|
output wire o_wb_cyc, o_wb_stb, o_wb_we;
|
output wire [31:0] o_wb_addr, o_wb_data;
|
output wire [31:0] o_wb_addr, o_wb_data;
|
input i_wb_ack, i_wb_stall, i_wb_err;
|
input i_wb_ack, i_wb_stall, i_wb_err;
|
input [31:0] i_wb_data;
|
input [31:0] i_wb_data;
|
input i_interrupt;
|
input i_interrupt;
|
output wire o_tx_stb;
|
output wire o_tx_stb;
|
output wire [7:0] o_tx_data;
|
output wire [7:0] o_tx_data;
|
input i_tx_busy;
|
input i_tx_busy;
|
// output wire [31:0] o_dbg;
|
// output wire [31:0] o_dbg;
|
|
|
|
|
reg r_wdt_reset;
|
reg r_wdt_reset;
|
|
|
// Decode ASCII input requests into WB bus cycle requests
|
// Decode ASCII input requests into WB bus cycle requests
|
wire in_stb;
|
wire in_stb;
|
wire [35:0] in_word;
|
wire [35:0] in_word;
|
wbuinput getinput(i_clk, i_rx_stb, i_rx_data, in_stb, in_word);
|
wbuinput getinput(i_clk, i_rx_stb, i_rx_data, in_stb, in_word);
|
|
|
wire w_bus_busy, fifo_in_stb, exec_stb, w_bus_reset;
|
wire w_bus_busy, fifo_in_stb, exec_stb, w_bus_reset;
|
wire [35:0] fifo_in_word, exec_word;
|
wire [35:0] fifo_in_word, exec_word;
|
// `define NO_INPUT_FIFO
|
// `define NO_INPUT_FIFO
|
`ifdef NO_INPUT_FIFO
|
`ifdef NO_INPUT_FIFO
|
assign fifo_in_stb = in_stb;
|
assign fifo_in_stb = in_stb;
|
assign fifo_in_word = in_word;
|
assign fifo_in_word = in_word;
|
assign w_bus_reset = 1'b0;
|
assign w_bus_reset = 1'b0;
|
`else
|
`else
|
wire ififo_empty_n, ififo_err;
|
wire ififo_empty_n, ififo_err;
|
assign fifo_in_stb = (~w_bus_busy)&&(ififo_empty_n);
|
assign fifo_in_stb = (~w_bus_busy)&&(ififo_empty_n);
|
assign w_bus_reset = r_wdt_reset;
|
assign w_bus_reset = r_wdt_reset;
|
wbufifo #(36,6) padififo(i_clk, w_bus_reset,
|
wbufifo #(36,6) padififo(i_clk, w_bus_reset,
|
in_stb, in_word, fifo_in_stb, fifo_in_word,
|
in_stb, in_word, fifo_in_stb, fifo_in_word,
|
ififo_empty_n, ififo_err);
|
ififo_empty_n, ififo_err);
|
`endif
|
`endif
|
|
|
// Take requests in, Run the bus, send results out
|
// Take requests in, Run the bus, send results out
|
// This only works if no requests come in while requests
|
// This only works if no requests come in while requests
|
// are pending.
|
// are pending.
|
wbuexec runwb(i_clk, r_wdt_reset, fifo_in_stb, fifo_in_word, w_bus_busy,
|
wbuexec runwb(i_clk, r_wdt_reset, fifo_in_stb, fifo_in_word, w_bus_busy,
|
o_wb_cyc, o_wb_stb, o_wb_we, o_wb_addr, o_wb_data,
|
o_wb_cyc, o_wb_stb, o_wb_we, o_wb_addr, o_wb_data,
|
i_wb_ack, i_wb_stall, i_wb_err, i_wb_data,
|
i_wb_ack, i_wb_stall, i_wb_err, i_wb_data,
|
exec_stb, exec_word);
|
exec_stb, exec_word);
|
|
|
/*
|
/*
|
wire [31:0] cyc_debug;
|
wire [31:0] cyc_debug;
|
assign cyc_debug = { 1'b0, o_wb_cyc, o_wb_stb, o_wb_we, i_wb_ack, i_wb_stall,
|
assign cyc_debug = { 1'b0, o_wb_cyc, o_wb_stb, o_wb_we, i_wb_ack, i_wb_stall,
|
(i_wb_err||r_wdt_reset), o_wb_addr[14:0],
|
(i_wb_err||r_wdt_reset), o_wb_addr[14:0],
|
o_wb_data[4:0], i_wb_data[4:0] };
|
o_wb_data[4:0], i_wb_data[4:0] };
|
assign o_dbg = cyc_debug;
|
assign o_dbg = cyc_debug;
|
*/
|
*/
|
|
|
/*
|
/*
|
wire [31:0] fif_debug;
|
wire [31:0] fif_debug;
|
assign fif_debug = {
|
assign fif_debug = {
|
(exec_stb)&&(exec_word[35:30] == 6'h05),// 1
|
(exec_stb)&&(exec_word[35:30] == 6'h05),// 1
|
fifo_in_stb, fifo_in_word[35:30], // 7
|
fifo_in_stb, fifo_in_word[35:30], // 7
|
exec_stb, exec_word[35:30], // 7
|
exec_stb, exec_word[35:30], // 7
|
o_wb_cyc, o_wb_stb, o_wb_we,
|
o_wb_cyc, o_wb_stb, o_wb_we,
|
i_wb_ack, i_wb_stall, // 5
|
i_wb_ack, i_wb_stall, // 5
|
w_bus_busy, ififo_empty_n, w_bus_reset, // 3
|
w_bus_busy, ififo_empty_n, w_bus_reset, // 3
|
i_rx_stb, o_wb_addr[7:0] }; // 9
|
i_rx_stb, o_wb_addr[7:0] }; // 9
|
assign o_dbg = fif_debug;
|
assign o_dbg = fif_debug;
|
*/
|
*/
|
|
|
wire ofifo_err;
|
wire ofifo_err;
|
// wire [30:0] out_dbg;
|
// wire [30:0] out_dbg;
|
wbuoutput wroutput(i_clk, w_bus_reset,
|
wbuoutput wroutput(i_clk, w_bus_reset,
|
exec_stb, exec_word,
|
exec_stb, exec_word,
|
o_wb_cyc, i_interrupt, exec_stb,
|
o_wb_cyc, i_interrupt, exec_stb,
|
o_tx_stb, o_tx_data, i_tx_busy, ofifo_err);
|
o_tx_stb, o_tx_data, i_tx_busy, ofifo_err);
|
|
|
// Add in a watchdog timer to the bus
|
// Add in a watchdog timer to the bus
|
reg [(LGWATCHDOG-1):0] r_wdt_timer;
|
reg [(LGWATCHDOG-1):0] r_wdt_timer;
|
initial r_wdt_reset = 1'b0;
|
initial r_wdt_reset = 1'b0;
|
initial r_wdt_timer = 0;
|
initial r_wdt_timer = 0;
|
always @(posedge i_clk)
|
always @(posedge i_clk)
|
if ((~o_wb_cyc)||(i_wb_ack))
|
if ((~o_wb_cyc)||(i_wb_ack))
|
begin
|
begin
|
r_wdt_timer <= 0;
|
r_wdt_timer <= 0;
|
r_wdt_reset <= 1'b0;
|
r_wdt_reset <= 1'b0;
|
end else if (&r_wdt_timer)
|
end else if (&r_wdt_timer)
|
begin
|
begin
|
r_wdt_reset <= 1'b1;
|
r_wdt_reset <= 1'b1;
|
r_wdt_timer <= 0;
|
r_wdt_timer <= 0;
|
end else begin
|
end else begin
|
r_wdt_timer <= r_wdt_timer+1;
|
r_wdt_timer <= r_wdt_timer+{{(LGWATCHDOG-1){1'b0}},1'b1};
|
r_wdt_reset <= 1'b0;
|
r_wdt_reset <= 1'b0;
|
end
|
end
|
|
|
endmodule
|
endmodule
|
|
|
|
|