2019-12-04 00:47:19 +00:00
|
|
|
/*
|
|
|
|
Copyright 2019 Blue Liang, liangkangnan@163.com
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
`include "defines.v"
|
|
|
|
|
|
|
|
// common reg module
|
2020-03-29 15:19:14 +00:00
|
|
|
module regs(
|
2019-12-04 00:47:19 +00:00
|
|
|
|
|
|
|
input wire clk,
|
|
|
|
input wire rst,
|
|
|
|
|
2020-03-29 15:19:14 +00:00
|
|
|
input wire we_i, // reg write enable
|
|
|
|
input wire[`RegAddrBus] waddr_i, // reg write addr
|
|
|
|
input wire[`RegBus] wdata_i, // reg write data
|
2019-12-04 00:47:19 +00:00
|
|
|
|
2020-03-29 15:19:14 +00:00
|
|
|
input wire jtag_we_i, // reg write enable
|
|
|
|
input wire[`RegAddrBus] jtag_addr_i, // reg write addr
|
|
|
|
input wire[`RegBus] jtag_data_i, // reg write data
|
2019-12-04 00:47:19 +00:00
|
|
|
|
2020-03-29 15:19:14 +00:00
|
|
|
input wire[`RegAddrBus] raddr1_i, // reg1 read addr
|
|
|
|
output reg[`RegBus] rdata1_o, // reg1 read data
|
|
|
|
|
|
|
|
input wire[`RegAddrBus] raddr2_i, // reg2 read addr
|
|
|
|
output reg[`RegBus] rdata2_o, // reg2 read data
|
|
|
|
|
|
|
|
output reg[`RegBus] jtag_data_o
|
2019-12-04 00:47:19 +00:00
|
|
|
|
2020-02-23 09:01:45 +00:00
|
|
|
);
|
2019-12-04 00:47:19 +00:00
|
|
|
|
|
|
|
reg[`RegBus] regs[0:`RegNum - 1];
|
|
|
|
|
2020-02-23 09:01:45 +00:00
|
|
|
// write reg
|
2019-12-04 00:47:19 +00:00
|
|
|
always @ (posedge clk) begin
|
|
|
|
if (rst == `RstDisable) begin
|
2020-03-29 15:19:14 +00:00
|
|
|
if ((we_i == `WriteEnable) && (waddr_i != `RegNumLog2'h0)) begin
|
|
|
|
regs[waddr_i] <= wdata_i;
|
|
|
|
end else if ((jtag_we_i == `WriteEnable) && (jtag_addr_i != `RegNumLog2'h0)) begin
|
|
|
|
regs[jtag_addr_i] <= jtag_data_i;
|
2019-12-04 00:47:19 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-23 09:01:45 +00:00
|
|
|
// read reg1
|
2019-12-04 00:47:19 +00:00
|
|
|
always @ (*) begin
|
2020-03-29 15:19:14 +00:00
|
|
|
if (rst == `RstEnable) begin
|
|
|
|
rdata1_o <= `ZeroWord;
|
|
|
|
end else if (raddr1_i == `RegNumLog2'h0) begin
|
|
|
|
rdata1_o <= `ZeroWord;
|
|
|
|
end else if (raddr1_i == waddr_i && we_i == `WriteEnable) begin
|
|
|
|
rdata1_o <= wdata_i;
|
2019-12-04 00:47:19 +00:00
|
|
|
end else begin
|
2020-03-29 15:19:14 +00:00
|
|
|
rdata1_o <= regs[raddr1_i];
|
2019-12-04 00:47:19 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-23 09:01:45 +00:00
|
|
|
// read reg2
|
2019-12-04 00:47:19 +00:00
|
|
|
always @ (*) begin
|
2020-03-29 15:19:14 +00:00
|
|
|
if (rst == `RstEnable) begin
|
|
|
|
rdata2_o <= `ZeroWord;
|
|
|
|
end else if (raddr2_i == `RegNumLog2'h0) begin
|
|
|
|
rdata2_o <= `ZeroWord;
|
|
|
|
end else if (raddr2_i == waddr_i && we_i == `WriteEnable) begin
|
|
|
|
rdata2_o <= wdata_i;
|
|
|
|
end else begin
|
|
|
|
rdata2_o <= regs[raddr2_i];
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
// jtag read reg
|
|
|
|
always @ (*) begin
|
|
|
|
if (rst == `RstEnable) begin
|
|
|
|
jtag_data_o <= `ZeroWord;
|
|
|
|
end else if (jtag_addr_i == `RegNumLog2'h0) begin
|
|
|
|
jtag_data_o <= `ZeroWord;
|
2019-12-04 00:47:19 +00:00
|
|
|
end else begin
|
2020-03-29 15:19:14 +00:00
|
|
|
jtag_data_o <= regs[jtag_addr_i];
|
2019-12-04 00:47:19 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
endmodule
|