串口版本太复杂,新增简单的spi版本—基本仿真无误

This commit is contained in:
yangshenbo 2026-04-08 18:16:13 +08:00
parent 9f29575d70
commit 7d227dad2e
575 changed files with 14058 additions and 534 deletions

View File

@ -1 +0,0 @@
.//../simv.daidir//_131020_archive_1.so

View File

@ -1 +0,0 @@
.//../simv.daidir//_131039_archive_1.so

View File

@ -1 +0,0 @@
.//../simv.daidir//_131040_archive_1.so

View File

@ -1 +0,0 @@
.//../simv.daidir//_14790_archive_1.so

View File

@ -1 +0,0 @@
.//../simv.daidir//_14816_archive_1.so

View File

@ -1 +0,0 @@
.//../simv.daidir//_26119_archive_1.so

View File

@ -1 +0,0 @@
.//../simv.daidir//_30584_archive_1.so

View File

@ -1 +0,0 @@
.//../simv.daidir//_30603_archive_1.so

View File

@ -1 +0,0 @@
.//../simv.daidir//_34047_archive_1.so

View File

@ -1 +0,0 @@
.//../simv.daidir//_34065_archive_1.so

View File

@ -1 +0,0 @@
.//../simv.daidir//_37423_archive_1.so

View File

@ -1 +0,0 @@
.//../simv.daidir//_37441_archive_1.so

View File

@ -1 +0,0 @@
.//../simv.daidir//_39101_archive_1.so

View File

@ -1 +0,0 @@
.//../simv.daidir//_39120_archive_1.so

View File

@ -1 +0,0 @@
.//../simv.daidir//_40330_archive_1.so

View File

@ -1 +0,0 @@
.//../simv.daidir//_40348_archive_1.so

View File

@ -1 +0,0 @@
.//../simv.daidir//_41475_archive_1.so

View File

@ -1 +0,0 @@
.//../simv.daidir//_41494_archive_1.so

View File

@ -1 +0,0 @@
.//../simv.daidir//_42301_archive_1.so

View File

@ -1 +0,0 @@
.//../simv.daidir//_42320_archive_1.so

View File

@ -1 +0,0 @@
.//../simv.daidir//_43406_archive_1.so

View File

@ -1 +0,0 @@
.//../simv.daidir//_43443_archive_1.so

View File

@ -1 +0,0 @@
.//../simv.daidir//_45855_archive_1.so

View File

@ -1 +0,0 @@
.//../simv.daidir//_45891_archive_1.so

View File

@ -1 +0,0 @@
.//../simv.daidir//_50099_archive_1.so

View File

@ -1 +0,0 @@
.//../simv.daidir//_50120_archive_1.so

View File

@ -1 +0,0 @@
.//../simv.daidir//_52045_archive_1.so

View File

@ -1 +0,0 @@
.//../simv.daidir//_52081_archive_1.so

View File

@ -1 +0,0 @@
.//../simv.daidir//_53444_archive_1.so

View File

@ -1 +0,0 @@
.//../simv.daidir//_53462_archive_1.so

View File

@ -1 +0,0 @@
.//../simv.daidir//_54606_archive_1.so

View File

@ -1 +0,0 @@
.//../simv.daidir//_54624_archive_1.so

View File

@ -1 +0,0 @@
.//../simv.daidir//_56094_archive_1.so

View File

@ -1 +0,0 @@
.//../simv.daidir//_56112_archive_1.so

View File

@ -1 +0,0 @@
.//../simv.daidir//_57246_archive_1.so

View File

@ -1 +0,0 @@
.//../simv.daidir//_57264_archive_1.so

View File

@ -1 +0,0 @@
.//../simv.daidir//_csrc0.so

View File

@ -1 +0,0 @@
.//../simv.daidir//_prev_archive_1.so

View File

@ -0,0 +1,92 @@
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 2026/04/03 22:01:15
// Design Name:
// Module Name: digital_top
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module digital_top(
input clk,
input rst_n,
//spi_slave
input sclk,
input [4:0]cfgid,
input csn,
input mosi,
output miso,
output oen,
//pulse_counter
input sig_in
);
wire [31:0] wrdata;
wire [24:0] addr;
wire wren;
wire rden;
wire [31:0]rddata;
wire [23:0] win_us;
wire cnt_vld;
wire [23:0]cnt_out;
// 实例化 DUT
spi_sys u_spi_sys (
.clk (clk ),
.rst_n (rst_n ),
.cfgid (cfgid ),
.sclk (sclk ),
.csn (csn ),
.mosi (mosi ),
.miso (miso ),
.oen (oen ),
.wrdata (wrdata ),
.addr (addr ),
.wren (wren ),
.rden (rden ),
.rddata (rddata )
);
system_regfile u_system_regfile (
.clk (clk),
.rst_n (rst_n),
.wrdata (wrdata),
.wren (wren),
.rwaddr (addr),
.rden (rden),
.rddata (rddata),
// digital_thermometer
.win_us(win_us),
.pulse_cnt_out(cnt_out),
.pules_cnt_vld(cnt_vld)
);
pulse_cnt #(
.CLK_FREQ(50_000_000)
) u_pulse_cnt (
.clk (clk),
.rst_n (rst_n),
.sig_in (sig_in),
.win_us (win_us),
.cnt_out(cnt_out),
.vld_out(cnt_vld)
);
endmodule

View File

@ -0,0 +1,292 @@
//+FHDR--------------------------------------------------------------------------------------------------------
// Company:
//-----------------------------------------------------------------------------------------------------------------
// File Name : spi_sys.v
// Department :
// Author : PWY
// Author's Tel :
//-----------------------------------------------------------------------------------------------------------------
// Relese History
// Version Date Author Description
// 0.1 2024-04-13 PWY SPI BUS for System
// 0.2 2024-06-24 PWY {spi_dout[31:0],1'b0} -> {spi_dout[30:0],1'b0}
//-----------------------------------------------------------------------------------------------------------------
// Keywords :
//
//-----------------------------------------------------------------------------------------------------------------
// Parameter
//
//-----------------------------------------------------------------------------------------------------------------
// Purpose :
//
//-----------------------------------------------------------------------------------------------------------------
// Target Device:
// Tool versions:
//-----------------------------------------------------------------------------------------------------------------
// Reuse Issues
// Reset Strategy:
// Clock Domains:
// Critical Timing:
// Asynchronous I/F:
// Synthesizable (y/n):
// Other:
//-FHDR--------------------------------------------------------------------------------------------------------
//-----------------------------Spi Frame-------------------------------------------------------------------------------------
////MSB------------->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>..............................................>>>>>>>>------->LSB
///|<-----------MSB 32 bits------------------->||<---------Second 32-bit---->||<-------x 32-bit---->||<-------n 32-bit---->|
// +-----++----------------------++------------++-----++---------------------++---------------------++---------------------+
// | 31 || 30:6 || 5:1 || 0 || 31:0 || ...... || 31:0 |
// +-----++----------------------++------------++-----++---------------------++---------------------++---------------------+
// +-----++----------------------++------------++-----++---------------------++---------------------++---------------------+
// | wnr || addr[24:0] || CHIPID ||resv || data[31:0] || ...... || data[31:0] |
// +-----++----------------------++------------++-----++---------------------++---------------------++---------------------+
//-----------------------------Spi Frame-------------------------------------------------------------------------------------
module spi_sys (
//system port
input clk // System Main Clock
,input rst_n // Spi Reset active low
//cfg ID
,input [4 :0] cfgid //ID number for the entire chip
//spi port
,input sclk // Spi Clock
,input csn // Spi Chip Select active low
,input mosi // Spi Mosi
,output miso // Spi Miso
,output oen // Spi Miso output enable
,output [31:0] wrdata //write data to sram
,output [24:0] addr //sram address
,output wren //write enable sram
,output rden //rden enable sram
,input [31:0] rddata //read data from sram
);
localparam IDLE = 2'b00,
RECVCMD = 2'b01,
WRITE = 2'b10,
READ = 2'b11;
//-----------------------------------------------------------------------
//SPI module reset processing
//-----------------------------------------------------------------------
//spi_rstn
//wire spi_rstn;
//assign spi_rstn = rst_n & (~csn);
//////////////////////////////////////////////////////////////////////////
//capture the sck
//////////////////////////////////////////////////////////////////////////
wire [2:0] sclk_reg;
//sync sclk to the main clock using a 3-bits shift register
sirv_gnrl_dffrs #(3) sclk_reg_dffrs ({sclk_reg[1:0],sclk}, sclk_reg, clk, rst_n);
//sclk's rising edges
wire sclk_p = (sclk_reg[2:1] == 2'b01);
//sclk's falling edges
//assign sclk_n = (sclk_reg[2:1] == 2'b10);
//////////////////////////////////////////////////////////////////////////
//capture the csn
//////////////////////////////////////////////////////////////////////////
wire [2:0] csn_reg;
//sync csn to the main clock using a 2-bits shift register
sirv_gnrl_dffrs #(3) csn_reg_dffrs ({csn_reg[1:0],csn}, csn_reg, clk, rst_n);
// csn is active low
wire csn_active = ~csn_reg[1];
//csn's rising edges
wire csn_p = (csn_reg[2:1] == 2'b01);
//csn's falling edges
wire csn_n = (csn_reg[2:1] == 2'b10);
//////////////////////////////////////////////////////////////////////////
//capture the mosi
//////////////////////////////////////////////////////////////////////////
wire [1:0] mosi_reg;
//sync mosi to the main clock using a 2-bits shift register
sirv_gnrl_dffr #(2) mosi_reg_dffr ({mosi_reg[0],mosi}, mosi_reg, clk, rst_n);
//mosi_data
wire mosi_data = mosi_reg[1];
//////////////////////////////////////////////////////////////////////////
//cnt
//////////////////////////////////////////////////////////////////////////
wire [4:0] cnt_c;
//add_cnt
wire add_cnt = sclk_p && csn_active;
//end_cnt
wire end_cnt = (add_cnt && (cnt_c == 5'd31)) | csn_p;
wire [4:0] cnt_n = end_cnt ? 5'h0 :
add_cnt ? cnt_c + 5'b1 :
cnt_c ;
sirv_gnrl_dffr #(5) cnt_c_dffr (cnt_n, cnt_c, clk, rst_n);
///////////////////////////////////////////////////////////////////////
//SPI data sample
///////////////////////////////////////////////////////////////////////
generate
genvar i;
wire [31:0] recv_vld ;
wire [31:0] spi_din ;
for(i=0;i<32;i=i+1) begin: spi_sys_recv
assign recv_vld[i] = add_cnt & (cnt_c == i );
sirv_gnrl_dfflr #(1) spi_din_dfflr (recv_vld[i], mosi_data, spi_din[31-i], clk, rst_n);
end
endgenerate
wire [1:0] state_c;
wire [1:0] state_n;
///////////////////////////////////////////////////////////////////////
//init_addr capture
///////////////////////////////////////////////////////////////////////
wire [24:0] initaddr;
wire initaddr_vld = (state_c == RECVCMD ) & add_cnt && (cnt_c == 5'd26);
wire [1:0] initaddr_vld_r;
sirv_gnrl_dffr #(2) initaddr_vld_r_dffr ({initaddr_vld_r[0],initaddr_vld}, initaddr_vld_r, clk, rst_n);
sirv_gnrl_dfflr #(25) initaddr_dfflr (initaddr_vld_r[0], spi_din[30:6], initaddr, clk, rst_n);
///////////////////////////////////////////////////////////////////////
//CMD capture
///////////////////////////////////////////////////////////////////////
wire cmd ;
sirv_gnrl_dfflr #(1) cmd_dfflr ( initaddr_vld_r[0], spi_din[31], cmd, clk, rst_n);
///////////////////////////////////////////////////////////////////////
//CHIPID capture
///////////////////////////////////////////////////////////////////////
wire [4:0] chipid;
wire [1:0] chipid_vld_r;
wire chipid_vld = (state_c == RECVCMD ) & add_cnt & (cnt_c == 5'd30);
//register cmd_vld to align it with cmd
sirv_gnrl_dffr #(2) chipid_vld_r_dffr ({chipid_vld_r[0],chipid_vld}, chipid_vld_r, clk, rst_n);
sirv_gnrl_dfflr #(5) chipid_dfflr (chipid_vld_r[0], spi_din[5:1], chipid, clk, rst_n);
///////////////////////////////////////////////////////////////////////
//ID matching determination
///////////////////////////////////////////////////////////////////////
wire chipid_match = (chipid == cfgid);
wire chipid_dismatch = (chipid != cfgid);
///////////////////////////////////////////////////////////////////////
//SPI Module State Machine
///////////////////////////////////////////////////////////////////////
//Generating jump conditions for state machines
wire ilde2recvcmd = (state_c == IDLE ) && csn_active && csn_n ;
wire recvcmd2ilde = (state_c == RECVCMD ) && chipid_dismatch & end_cnt;
wire recvcmd2write = (state_c == RECVCMD ) && chipid_match && ~cmd & end_cnt;
wire recvcmd2read = (state_c == RECVCMD ) && chipid_match && cmd & end_cnt;
wire write2idle = (state_c == WRITE ) && csn_p;
wire read2idle = (state_c == READ ) && csn_p;
//The first section of the state machine
//state_c
sirv_gnrl_dffr #(2) state_c_dffr (state_n, state_c, clk, rst_n);
//state_n
assign state_n = ((state_c == IDLE ) && ilde2recvcmd ) ? RECVCMD :
((state_c == RECVCMD ) && recvcmd2ilde ) ? IDLE :
((state_c == RECVCMD ) && recvcmd2write ) ? WRITE :
((state_c == RECVCMD ) && recvcmd2read ) ? READ :
((state_c == WRITE ) && write2idle ) ? IDLE :
((state_c == READ ) && read2idle ) ? IDLE :
state_c ;
///////////////////////////////////////////////////////////////////////////////////////////////////////
//Address generation for read and write operations
//The address to be used for updating in the next
//27 clock cycles in the read-write state
///////////////////////////////////////////////////////////////////////////////////////////////////////
wire second_falling;
wire second_falling_w = (state_c == WRITE);
sirv_gnrl_dfflr #(1) second_falling_dfflr (end_cnt ,second_falling_w, second_falling, clk, rst_n);
wire addr_update = ((state_c == READ) | ((state_c == WRITE) & second_falling)) & add_cnt & (cnt_c == 5'd27);
wire [24:0] addr_c;
wire [24:0] addr_n = ilde2recvcmd ? 25'd0 :
initaddr_vld_r[1] ? initaddr :
addr_update ? addr_c + 25'd4 :
addr_c ;
sirv_gnrl_dffr #(25) addr_c_dffr (addr_n, addr_c, clk, rst_n);
assign addr = addr_c;
///////////////////////////////////////////////////////////////////////////////////////////////////////
//Write data and write signals generation
///////////////////////////////////////////////////////////////////////////////////////////////////////
wire wren_r;
wire wren_w = (state_c == WRITE) & add_cnt & (cnt_c == 5'd31);
//wdata
sirv_gnrl_dfflr #(32) wrdata_dfflr (wren_r, spi_din[31:0], wrdata, clk, rst_n);
//wren_r
sirv_gnrl_dffr #(1) wren_r_dffr (wren_w, wren_r, clk, rst_n);
//wren
sirv_gnrl_dffr #(1) wren_dffr (wren_r, wren, clk, rst_n);
///////////////////////////////////////////////////////////////////////////////////////////////////////
//read signals generation
///////////////////////////////////////////////////////////////////////////////////////////////////////
wire rden_w = chipid_match & cmd & add_cnt & (cnt_c == 5'd28);
sirv_gnrl_dffr #(1) rden_dffr (rden_w, rden, clk, rst_n);
//Read data register
wire rddata_vld = cmd & add_cnt & (cnt_c == 5'd30);
wire [31:0] rddata_reg;
sirv_gnrl_dfflr #(32) rddata_reg_dfflr (rddata_vld, rddata[31:0], rddata_reg, clk, rst_n);
///////////////////////////////////////////////////////////////////////////////////////////////////////
//SPI send data update
///////////////////////////////////////////////////////////////////////////////////////////////////////
wire [31:0] spi_dout ;
wire update_flag = cmd & add_cnt & (cnt_c == 5'd31);
wire [31:0] rddata_sr = update_flag ? rddata_reg[31:0] :
((state_c == READ) & add_cnt) ? {spi_dout[30:0],1'b0} : //M 2024-06-24
spi_dout ;
sirv_gnrl_dffr #(32) spi_dout_dffr (rddata_sr, spi_dout, clk, rst_n);
///////////////////////////////////////////////////////////////////////////////////////////////////////
//SPI send data
///////////////////////////////////////////////////////////////////////////////////////////////////////
assign miso = spi_dout[31];
///////////////////////////////////////////////////////////////////////////////////////////////////////
//SPI output enable
///////////////////////////////////////////////////////////////////////////////////////////////////////
sirv_gnrl_dffrs #(1) oen_dffr (~(state_c == READ), oen, clk, rst_n);
endmodule

View File

@ -1,342 +1,342 @@
/* /*
Copyright 2018-2020 Nuclei System Technology, Inc. Copyright 2018-2020 Nuclei System Technology, Inc.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
//===================================================================== //=====================================================================
// //
// Designer : Bob Hu // Designer : Bob Hu
// //
// Description: // Description:
// All of the general DFF and Latch modules // All of the general DFF and Latch modules
// //
// ==================================================================== // ====================================================================
// //
// //
// =========================================================================== // ===========================================================================
// //
// Description: // Description:
// Verilog module sirv_gnrl DFF with Load-enable and Reset // Verilog module sirv_gnrl DFF with Load-enable and Reset
// Default reset value is 1 // Default reset value is 1
// //
// =========================================================================== // ===========================================================================
`define DISABLE_SV_ASSERTION `define DISABLE_SV_ASSERTION
`define dly #0.2 `define dly #0.2
module sirv_gnrl_dfflrs # ( module sirv_gnrl_dfflrs # (
parameter DW = 32 parameter DW = 32
) ( ) (
input lden, input lden,
input [DW-1:0] dnxt, input [DW-1:0] dnxt,
output [DW-1:0] qout, output [DW-1:0] qout,
input clk, input clk,
input rst_n input rst_n
); );
reg [DW-1:0] qout_r; reg [DW-1:0] qout_r;
always @(posedge clk or negedge rst_n) always @(posedge clk or negedge rst_n)
begin : DFFLRS_PROC begin : DFFLRS_PROC
if (rst_n == 1'b0) if (rst_n == 1'b0)
qout_r <= {DW{1'b1}}; qout_r <= {DW{1'b1}};
else if (lden == 1'b1) else if (lden == 1'b1)
qout_r <= `dly dnxt; qout_r <= `dly dnxt;
end end
assign qout = qout_r; assign qout = qout_r;
`ifndef FPGA_SOURCE//{ `ifndef FPGA_SOURCE//{
`ifndef DISABLE_SV_ASSERTION//{ `ifndef DISABLE_SV_ASSERTION//{
//synopsys translate_off //synopsys translate_off
sirv_gnrl_xchecker # ( sirv_gnrl_xchecker # (
.DW(1) .DW(1)
) sirv_gnrl_xchecker( ) sirv_gnrl_xchecker(
.i_dat(lden), .i_dat(lden),
.clk (clk) .clk (clk)
); );
//synopsys translate_on //synopsys translate_on
`endif//} `endif//}
`endif//} `endif//}
endmodule endmodule
// =========================================================================== // ===========================================================================
// //
// Description: // Description:
// Verilog module sirv_gnrl DFF with Load-enable and Reset // Verilog module sirv_gnrl DFF with Load-enable and Reset
// Default reset value is 0 // Default reset value is 0
// //
// =========================================================================== // ===========================================================================
module sirv_gnrl_dfflr # ( module sirv_gnrl_dfflr # (
parameter DW = 32 parameter DW = 32
) ( ) (
input lden, input lden,
input [DW-1:0] dnxt, input [DW-1:0] dnxt,
output [DW-1:0] qout, output [DW-1:0] qout,
input clk, input clk,
input rst_n input rst_n
); );
reg [DW-1:0] qout_r; reg [DW-1:0] qout_r;
always @(posedge clk or negedge rst_n) always @(posedge clk or negedge rst_n)
begin : DFFLR_PROC begin : DFFLR_PROC
if (rst_n == 1'b0) if (rst_n == 1'b0)
qout_r <= {DW{1'b0}}; qout_r <= {DW{1'b0}};
else if (lden == 1'b1) else if (lden == 1'b1)
qout_r <= `dly dnxt; qout_r <= `dly dnxt;
end end
assign qout = qout_r; assign qout = qout_r;
`ifndef FPGA_SOURCE//{ `ifndef FPGA_SOURCE//{
`ifndef DISABLE_SV_ASSERTION//{ `ifndef DISABLE_SV_ASSERTION//{
//synopsys translate_off //synopsys translate_off
sirv_gnrl_xchecker # ( sirv_gnrl_xchecker # (
.DW(1) .DW(1)
) sirv_gnrl_xchecker( ) sirv_gnrl_xchecker(
.i_dat(lden), .i_dat(lden),
.clk (clk) .clk (clk)
); );
//synopsys translate_on //synopsys translate_on
`endif//} `endif//}
`endif//} `endif//}
endmodule endmodule
// =========================================================================== // ===========================================================================
// //
// Description: // Description:
// Verilog module sirv_gnrl DFF with Load-enable and Reset // Verilog module sirv_gnrl DFF with Load-enable and Reset
// Default reset value is input // Default reset value is input
// //
// =========================================================================== // ===========================================================================
module sirv_gnrl_dfflrd # ( module sirv_gnrl_dfflrd # (
parameter DW = 32 parameter DW = 32
) ( ) (
input [DW-1:0] init, input [DW-1:0] init,
input lden, input lden,
input [DW-1:0] dnxt, input [DW-1:0] dnxt,
output [DW-1:0] qout, output [DW-1:0] qout,
input clk, input clk,
input rst_n input rst_n
); );
reg [DW-1:0] qout_r; reg [DW-1:0] qout_r;
always @(posedge clk or negedge rst_n) always @(posedge clk or negedge rst_n)
begin : DFFLR_PROC begin : DFFLR_PROC
if (rst_n == 1'b0) if (rst_n == 1'b0)
qout_r <= init; qout_r <= init;
else if (lden == 1'b1) else if (lden == 1'b1)
qout_r <= `dly dnxt; qout_r <= `dly dnxt;
end end
assign qout = qout_r; assign qout = qout_r;
`ifndef FPGA_SOURCE//{ `ifndef FPGA_SOURCE//{
`ifndef DISABLE_SV_ASSERTION//{ `ifndef DISABLE_SV_ASSERTION//{
//synopsys translate_off //synopsys translate_off
sirv_gnrl_xchecker # ( sirv_gnrl_xchecker # (
.DW(1) .DW(1)
) sirv_gnrl_xchecker( ) sirv_gnrl_xchecker(
.i_dat(lden), .i_dat(lden),
.clk (clk) .clk (clk)
); );
//synopsys translate_on //synopsys translate_on
`endif//} `endif//}
`endif//} `endif//}
endmodule endmodule
// =========================================================================== // ===========================================================================
// //
// Description: // Description:
// Verilog module sirv_gnrl DFF with Load-enable, no reset // Verilog module sirv_gnrl DFF with Load-enable, no reset
// //
// =========================================================================== // ===========================================================================
module sirv_gnrl_dffl # ( module sirv_gnrl_dffl # (
parameter DW = 32 parameter DW = 32
) ( ) (
input lden, input lden,
input [DW-1:0] dnxt, input [DW-1:0] dnxt,
output [DW-1:0] qout, output [DW-1:0] qout,
input clk input clk
); );
reg [DW-1:0] qout_r; reg [DW-1:0] qout_r;
always @(posedge clk) always @(posedge clk)
begin : DFFL_PROC begin : DFFL_PROC
if (lden == 1'b1) if (lden == 1'b1)
qout_r <= `dly dnxt; qout_r <= `dly dnxt;
end end
assign qout = qout_r; assign qout = qout_r;
`ifndef FPGA_SOURCE//{ `ifndef FPGA_SOURCE//{
`ifndef DISABLE_SV_ASSERTION//{ `ifndef DISABLE_SV_ASSERTION//{
//synopsys translate_off //synopsys translate_off
sirv_gnrl_xchecker # ( sirv_gnrl_xchecker # (
.DW(1) .DW(1)
) sirv_gnrl_xchecker( ) sirv_gnrl_xchecker(
.i_dat(lden), .i_dat(lden),
.clk (clk) .clk (clk)
); );
//synopsys translate_on //synopsys translate_on
`endif//} `endif//}
`endif//} `endif//}
endmodule endmodule
// =========================================================================== // ===========================================================================
// //
// Description: // Description:
// Verilog module sirv_gnrl DFF with Reset, no load-enable // Verilog module sirv_gnrl DFF with Reset, no load-enable
// Default reset value is 1 // Default reset value is 1
// //
// =========================================================================== // ===========================================================================
module sirv_gnrl_dffrs # ( module sirv_gnrl_dffrs # (
parameter DW = 32 parameter DW = 32
) ( ) (
input [DW-1:0] dnxt, input [DW-1:0] dnxt,
output [DW-1:0] qout, output [DW-1:0] qout,
input clk, input clk,
input rst_n input rst_n
); );
reg [DW-1:0] qout_r; reg [DW-1:0] qout_r;
always @(posedge clk or negedge rst_n) always @(posedge clk or negedge rst_n)
begin : DFFRS_PROC begin : DFFRS_PROC
if (rst_n == 1'b0) if (rst_n == 1'b0)
qout_r <= {DW{1'b1}}; qout_r <= {DW{1'b1}};
else else
qout_r <= `dly dnxt; qout_r <= `dly dnxt;
end end
assign qout = qout_r; assign qout = qout_r;
endmodule endmodule
// =========================================================================== // ===========================================================================
// //
// Description: // Description:
// Verilog module sirv_gnrl DFF with Reset, no load-enable // Verilog module sirv_gnrl DFF with Reset, no load-enable
// Default reset value is 0 // Default reset value is 0
// //
// =========================================================================== // ===========================================================================
module sirv_gnrl_dffr # ( module sirv_gnrl_dffr # (
parameter DW = 32 parameter DW = 32
) ( ) (
input [DW-1:0] dnxt, input [DW-1:0] dnxt,
output [DW-1:0] qout, output [DW-1:0] qout,
input clk, input clk,
input rst_n input rst_n
); );
reg [DW-1:0] qout_r; reg [DW-1:0] qout_r;
always @(posedge clk or negedge rst_n) always @(posedge clk or negedge rst_n)
begin : DFFR_PROC begin : DFFR_PROC
if (rst_n == 1'b0) if (rst_n == 1'b0)
qout_r <= {DW{1'b0}}; qout_r <= {DW{1'b0}};
else else
qout_r <= `dly dnxt; qout_r <= `dly dnxt;
end end
assign qout = qout_r; assign qout = qout_r;
endmodule endmodule
// =========================================================================== // ===========================================================================
// //
// Description: // Description:
// Verilog module for general latch // Verilog module for general latch
// //
// =========================================================================== // ===========================================================================
module sirv_gnrl_ltch # ( module sirv_gnrl_ltch # (
parameter DW = 32 parameter DW = 32
) ( ) (
//input test_mode, //input test_mode,
input lden, input lden,
input [DW-1:0] dnxt, input [DW-1:0] dnxt,
output [DW-1:0] qout output [DW-1:0] qout
); );
reg [DW-1:0] qout_r; reg [DW-1:0] qout_r;
always @ * always @ *
begin : LTCH_PROC begin : LTCH_PROC
if (lden == 1'b1) if (lden == 1'b1)
qout_r <= dnxt; qout_r <= dnxt;
end end
//assign qout = test_mode ? dnxt : qout_r; //assign qout = test_mode ? dnxt : qout_r;
assign qout = qout_r; assign qout = qout_r;
`ifndef FPGA_SOURCE//{ `ifndef FPGA_SOURCE//{
`ifndef DISABLE_SV_ASSERTION//{ `ifndef DISABLE_SV_ASSERTION//{
//synopsys translate_off //synopsys translate_off
always_comb always_comb
begin begin
CHECK_THE_X_VALUE: CHECK_THE_X_VALUE:
assert (lden !== 1'bx) assert (lden !== 1'bx)
else $fatal ("\n Error: Oops, detected a X value!!! This should never happen. \n"); else $fatal ("\n Error: Oops, detected a X value!!! This should never happen. \n");
end end
//synopsys translate_on //synopsys translate_on
`endif//} `endif//}
`endif//} `endif//}
endmodule endmodule
// module sirv_gnrl_edffr #(parameter type T = logic) ( // module sirv_gnrl_edffr #(parameter type T = logic) (
// input T dnxt, // input T dnxt,
// output T qout, // output T qout,
// input clk, rst_n // input clk, rst_n
// ); // );
// T qout_r; // T qout_r;
// always_ff @(posedge clk or negedge rst_n) begin // always_ff @(posedge clk or negedge rst_n) begin
// if (!rst_n) qout_r <= T'('0); // if (!rst_n) qout_r <= T'('0);
// else qout_r <= `dly dnxt; // else qout_r <= `dly dnxt;
// end // end
// assign qout = qout_r; // assign qout = qout_r;
// endmodule // endmodule

View File

@ -0,0 +1,111 @@
//+FHDR--------------------------------------------------------------------------------------------------------
// Add a new register:
// SECTION A: Add localparam ADDR_NEW = 16'hXX;.
// SECTION B: Declare wire sel_new, we_new, [31:0] reg_new;.
// SECTION C: Add decoding logic: assign sel_new = (reg_idx == ADDR_NEW >> 2);.
// SECTION D: Instantiate the underlying library, e.g., sirv_gnrl_dfflr #(32) new_dff (we_new, wrdata, reg_new, clk, rst_n);.
// SECTION F: Add else if (sel_new) rddata_reg = reg_new; in the always block.
// SECTION G: Map reg_new to the module's output ports.
//-FHDR--------------------------------------------------------------------------------------------------------
module system_regfile (
// [BLOCK 0] System and Bus Interface
input clk,
input rst_n,
input [31:0] wrdata,
input wren,
input [24:0] rwaddr,
input rden,
output [31:0] rddata,
output [23:0]win_us,
input [23:0]pulse_cnt_out,
input pules_cnt_vld
);
// =============================================================================
// [SECTION A] Address Offset Definition (Localparams)
// =============================================================================
localparam TESTR = 16'h00, DATER = 16'h04;
localparam WIN_TIME_R =16'h08 ;
localparam RESULT_R =16'h0c ;
// =============================================================================
// [SECTION B] Internal Wire Declaration (Wires)
// =============================================================================
// Register selection signals (Enable Wires)
wire sel_testr, sel_dater;
wire sel_win_time, sel_result;
// Write enable signals (Write Enable Wires)
wire we_testr, we_dater;
wire we_win_time;
// Register storage wires (Storage Wires)
wire [31:0] testr, dater;
wire [23:0] win_time_r, result_r;
// =============================================================================
// [SECTION C] Decoding Logic (Decoding)
// =============================================================================
assign sel_testr = (rwaddr[15:0] == TESTR );
assign sel_dater = (rwaddr[15:0] == DATER );
assign sel_win_time = (rwaddr[15:0] == WIN_TIME_R );
assign sel_result = (rwaddr[15:0] == RESULT_R );
// Write enable allocation
assign we_testr = sel_testr & wren;
assign we_dater = sel_dater & wren;
assign we_win_time = sel_win_time & wren;
// =============================================================================
// [SECTION D] Register Instantiation (Storage Implementation)
// =============================================================================
// --- General and Test Registers ---
sirv_gnrl_dfflrd #(32) testr_dff (32'h01234567, we_testr, wrdata[31:0], testr, clk, rst_n);
sirv_gnrl_dfflrd #(32) sfrtr_dff (32'h20260406, we_dater, wrdata[31:0], dater, clk, rst_n);
// --- Thermometer Functional Registers ---
sirv_gnrl_dfflrd #(24) win_time_dff (32'h00_03E8, we_win_time, wrdata, win_time_r, clk, rst_n);
sirv_gnrl_dfflr #(24) result_dff (pules_cnt_vld,pulse_cnt_out,result_r, clk, rst_n);
// =============================================================================
// [SECTION E] Special Business Logic (Business Logic)
// =============================================================================
// LVDS Real-time status register
// sirv_gnrl_dffr #(8) lvdssr_inst ({link_down, train_ready, crc_error_r, phase_adj_req_r, phase_tap[2:0], prefilling}, lvdssr, clk, rst_n);
// =============================================================================
// [SECTION F] Readback Logic (Readback Mux)
// =============================================================================
reg [31:0] rddata_reg;
always @(*) begin
rddata_reg = 32'b0;
if (sel_testr) rddata_reg = testr;
else if (sel_dater) rddata_reg = dater;
else if (sel_win_time) rddata_reg = {8'b0,win_time_r};
else if (sel_result) rddata_reg = {8'b0,result_r};
end
sirv_gnrl_dfflr #(32) rddata_out_dff (rden, rddata_reg, rddata, clk, rst_n);
// =============================================================================
// [SECTION G] Output Mapping (Output Assignments)
// =============================================================================
assign win_us = win_time_r;
endmodule

View File

@ -18,10 +18,10 @@ module TB();
// Clock Generation // Clock Generation
initial clk = 0; initial clk = 0;
always #(CLK_PERIOD/2) clk = ~clk; always #(CLK_PERIOD/2) clk = ~clk;
initial begin // initial begin
$fsdbDumpfile("wave.fsdb"); // $fsdbDumpfile("wave.fsdb");
$fsdbDumpvars(); // $fsdbDumpvars();
end // end
// ========================================== // ==========================================
// DUT Instantiation // DUT Instantiation
// ========================================== // ==========================================

View File

@ -0,0 +1 @@
.//../simv.daidir//_131020_archive_1.so

View File

@ -0,0 +1 @@
.//../simv.daidir//_131039_archive_1.so

View File

@ -0,0 +1 @@
.//../simv.daidir//_131040_archive_1.so

View File

@ -0,0 +1 @@
.//../simv.daidir//_14790_archive_1.so

View File

@ -0,0 +1 @@
.//../simv.daidir//_14816_archive_1.so

View File

@ -0,0 +1 @@
.//../simv.daidir//_26119_archive_1.so

View File

@ -0,0 +1 @@
.//../simv.daidir//_30584_archive_1.so

View File

@ -0,0 +1 @@
.//../simv.daidir//_30603_archive_1.so

View File

@ -0,0 +1 @@
.//../simv.daidir//_34047_archive_1.so

View File

@ -0,0 +1 @@
.//../simv.daidir//_34065_archive_1.so

View File

@ -0,0 +1 @@
.//../simv.daidir//_37423_archive_1.so

View File

@ -0,0 +1 @@
.//../simv.daidir//_37441_archive_1.so

View File

@ -0,0 +1 @@
.//../simv.daidir//_39101_archive_1.so

View File

@ -0,0 +1 @@
.//../simv.daidir//_39120_archive_1.so

View File

@ -0,0 +1 @@
.//../simv.daidir//_40330_archive_1.so

View File

@ -0,0 +1 @@
.//../simv.daidir//_40348_archive_1.so

View File

@ -0,0 +1 @@
.//../simv.daidir//_41475_archive_1.so

View File

@ -0,0 +1 @@
.//../simv.daidir//_41494_archive_1.so

View File

@ -0,0 +1 @@
.//../simv.daidir//_42301_archive_1.so

View File

@ -0,0 +1 @@
.//../simv.daidir//_42320_archive_1.so

View File

@ -0,0 +1 @@
.//../simv.daidir//_43406_archive_1.so

View File

@ -0,0 +1 @@
.//../simv.daidir//_43443_archive_1.so

View File

@ -0,0 +1 @@
.//../simv.daidir//_45855_archive_1.so

View File

@ -0,0 +1 @@
.//../simv.daidir//_45891_archive_1.so

View File

@ -0,0 +1 @@
.//../simv.daidir//_50099_archive_1.so

View File

@ -0,0 +1 @@
.//../simv.daidir//_50120_archive_1.so

View File

@ -0,0 +1 @@
.//../simv.daidir//_52045_archive_1.so

View File

@ -0,0 +1 @@
.//../simv.daidir//_52081_archive_1.so

View File

@ -0,0 +1 @@
.//../simv.daidir//_53444_archive_1.so

View File

@ -0,0 +1 @@
.//../simv.daidir//_53462_archive_1.so

View File

@ -0,0 +1 @@
.//../simv.daidir//_54606_archive_1.so

View File

@ -0,0 +1 @@
.//../simv.daidir//_54624_archive_1.so

View File

@ -0,0 +1 @@
.//../simv.daidir//_56094_archive_1.so

View File

@ -0,0 +1 @@
.//../simv.daidir//_56112_archive_1.so

View File

@ -0,0 +1 @@
.//../simv.daidir//_57246_archive_1.so

Some files were not shown because too many files have changed in this diff Show More