当前位置:网站首页>[CPU design practice] fundamentals of digital logic circuit design (I)
[CPU design practice] fundamentals of digital logic circuit design (I)
2022-06-22 06:32:00 【Abaabaababa】
cpu In design , There are some rules to follow
- It is forbidden to appear initial sentence
- It is forbidden to appear casex,casez
- No use # Expression circuit delay
- Clock signal clock Only allowed in [email protected](posedge clk) in
- Trigger with reset , Or all of them
Synchronous reset, Or all of themAsynchronous reset
Some suggested code styles
If the signals on both sides of the operator are single bits , Should use the “&” instead of “&&”,“|” instead of “||”
When expressing a logical relationship , use “&&” and “||”
When representing a logic gate , Such as carry ahead generation logic of carry ahead adder 、 The Wallace tree in the multiplier , Then use “|” and “&”
Practice task 1 : Register heap emulation
regfine.v
module regfile(
input clk,
input [ 4:0] raddr1,
output [31:0] rdata1,
input [ 4:0] raddr2,
output [31:0] rdata2,
input we,
input [ 4:0] waddr,
input [31:0] wdata
);
reg [31:0] rf[31:0];
// WRITE
always @(posedge clk) begin
if (we) rf[waddr]<= wdata;// If write enable Write the data to the corresponding register
end
// READ OUT 1
assign rdata1 = (raddr1==5'b0) ? 32'b0 : rf[raddr1];// According to the register address Read out the value in the corresponding register
// READ OUT 2
assign rdata2 = (raddr2==5'b0) ? 32'b0 : rf[raddr2];
endmodule
rf_tb.v
`timescale 1ns / 1ps
module tb_top();
reg clk;
reg [ 4:0] raddr1;
wire [31:0] rdata1;
reg [ 4:0] raddr2;
wire [31:0] rdata2;
reg we;
reg [ 4:0] waddr;
reg [31:0] wdata;
reg [ 3:0] task_phase;
regfile regfile0(
.clk (clk ),
.raddr1 (raddr1 ),
.rdata1 (rdata1 ),
.raddr2 (raddr2 ),
.rdata2 (rdata2 ),
.we (we ),
.waddr (waddr ),
.wdata (wdata )
);
//clk
initial
begin
clk = 1'b1;
end
always #5 clk = ~clk;
initial
begin
raddr1 = 5'd0;
raddr2 = 5'd0;
waddr = 5'd0;
wdata = 32'd0;
we = 1'd0;
task_phase = 4'd0;
#2000;
$display("=============================");
$display("Test Begin");
#1;
// Part 0 Begin
#10;
task_phase = 4'd0;
we = 1'b0;
waddr = 5'd1;
wdata = 32'hffffffff;
raddr1 = 5'd1;
#10;
we = 1'b1;
waddr = 5'd1;
wdata = 32'h1111ffff;
#10;
we = 1'b0;
raddr1 = 5'd2;
raddr2 = 5'd1;
#10;
raddr1 = 5'd1;
#200;
// Part 1 Begin
#10;
task_phase = 4'd1;
we = 1'b1;
wdata = 32'h0000ffff;
waddr = 5'h10;
raddr1 = 5'h10;
raddr2 = 5'h0f;
#10;
wdata = 32'h1111ffff;
waddr = 5'h11;
raddr1 = 5'h11;
raddr2 = 5'h10;
#10;
wdata = 32'h2222ffff;
waddr = 5'h12;
raddr1 = 5'h12;
raddr2 = 5'h11;
#10;
wdata = 32'h3333ffff;
waddr = 5'h13;
raddr1 = 5'h13;
raddr2 = 5'h12;
#10;
wdata = 32'h4444ffff;
waddr = 5'h14;
raddr1 = 5'h14;
raddr2 = 5'h13;
#10;
raddr1 = 5'h15;
raddr2 = 5'h14;
#10;
#200;
// Part 2 Begin
#10;
task_phase = 4'd2;
we = 1'b1;
raddr1 = 5'h10;
raddr2 = 5'h0f;
#10;
raddr1 = 5'h11;
raddr2 = 5'h10;
#10;
raddr1 = 5'h12;
raddr2 = 5'h11;
#10;
raddr1 = 5'h13;
raddr2 = 5'h12;
#10;
raddr1 = 5'h14;
raddr2 = 5'h13;
#10;
#50;
$display("TEST END");
$finish;
end
endmodule
Simulation




Practical task 2 : Sync RAM And asynchronous RAM Simulation 、 Synthesis and implementation
For synchronization RAM、 asynchronous RAM Build one project each , call IP Instantiate synchronization RAM, asynchronous RAM.
Sync
module ram_top (
input clk ,
input [15:0] ram_addr ,
input [31:0] ram_wdata,
input ram_wen ,
output [31:0] ram_rdata
);
block_ram block_ram (
.clka (clk ),
.wea (ram_wen ),
.addra(ram_addr ),
.dina (ram_wdata ),
.douta(ram_rdata )
);
endmodule
asynchronous
module ram_top (
input clk ,
input [15:0] ram_addr ,
input [31:0] ram_wdata,
input ram_wen ,
output [31:0] ram_rdata
);
distributed_ram distributed_ram(
.clk (clk ),
.we (ram_wen ),
.a (ram_addr ),
.d (ram_wdata ),
.spo (ram_rdata )
);
endmodule
test
`timescale 1ns / 1ps
module tb_top();
reg clk;
reg ram_wen;
reg [15:0] ram_addr;
reg [31:0] ram_wdata;
wire [31:0] ram_rdata;
reg [3 :0] task_phase;
ram_top u_ram_top(
.clk (clk ),
.ram_wen (ram_wen ),
.ram_addr (ram_addr ),
.ram_wdata(ram_wdata ),
.ram_rdata(ram_rdata )
);
//clk
initial
begin
clk = 1'b1;
end
always #5 clk = ~clk;
initial
begin
ram_addr = 16'd0;
ram_wdata = 32'd0;
ram_wen = 1'd0;
task_phase = 4'd0;
#2000;
$display("=============================");
$display("Test Begin");
#1;
// Part 0 Begin
#10;
task_phase = 4'd0;
ram_wen = 1'b0;
ram_addr = 16'hf0;
ram_wdata = 32'hffffffff;
#10;
ram_wen = 1'b1;
ram_addr = 16'hf0;
ram_wdata = 32'h11223344;
#10;
ram_wen = 1'b0;
ram_addr = 16'hf1;
#10;
ram_wen = 1'b0;
ram_addr = 16'hf0;
#200;
// Part 1 Begin
#10;
task_phase = 4'd1;
ram_wen = 1'b1;
ram_wdata = 32'hff00;
ram_addr = 16'hf0;
#10;
ram_wdata = 32'hff11;
ram_addr = 16'hf1;
#10;
ram_wdata = 32'hff22;
ram_addr = 16'hf2;
#10;
ram_wdata = 32'hff33;
ram_addr = 16'hf3;
#10;
ram_wdata = 32'hff44;
ram_addr = 16'hf4;
#10;
#200;
// Part 2 Begin
#10;
task_phase = 4'd2;
ram_wen = 1'b0;
ram_addr = 16'hf0;
ram_wdata = 32'hffffffff;
#10;
ram_addr = 16'hf1;
#10;
ram_addr = 16'hf2;
#10;
ram_addr = 16'hf3;
#10;
ram_addr = 16'hf4;
#10;
#50;
$display("TEST END");
$finish;
end
endmodule
Simulation ( It's really different )
The top four are asynchronous The following four pictures are synchronized Now I don't know why ..............







边栏推荐
- Bathymetry along Jamaica coast based on Satellite Sounding
- ForkJoinPool
- Laravel excel 3.1 column width setting does not work
- 【5G NR】NGAP协议之NG Setup
- College entrance examination is a post station on the journey of life
- import keras时遇到的错误 TypeError: Descriptors cannot not be created directly. If this call came from a _
- Configuration files required for SSM integration and error reports caused by common configuration errors
- SQL injection vulnerability (x) secondary injection
- IO intensive and CPU intensive
- SQL 注入漏洞(十三)base64注入
猜你喜欢
随机推荐
Geoswath plus technology and data acquisition and processing
Producer and consumer issues
[openairinterface5g] rrcsetuprequest for RRC NR resolution
5g terminal identification Supi, suci and IMSI analysis
[M32] SCM xxx Simple interpretation of map file
【M32】单片机 Code、RO Data、RW Data、ZI Data 简单解读
【5G NR】NG接口
Usage of trim, ltrim and rtrim functions of Oracle
College entrance examination is a post station on the journey of life
SQL 注入漏洞(十四)xff 注入攻击
Little bear school bearpi HM micro officially integrated into openharmony trunk
【OpenAirInterface5g】ITTI消息收发机制
Paging tool class pageutil < t >
Vertical maximum and minimum and horizontal maximum and minimum greatest(), least(), max(), min()
[openairinterface5g] RRC NR resolution (I)
MySQL Niuke brush questions
Chrome install driver
SQL injection vulnerability (XI) wide byte injection
仙人掌之歌——上线运营(4)
集合类并发不安全问题

![[PHP] composer 安装](/img/37/7adaca01b95085b42a116bc6b08165.png)


![[5g NR] mobile phone ID number IMEI and imeisv](/img/f0/2613fc9f59f7d0d4335b13f0273fc2.png)




