switch lsp to clangd and reconstruct project
This commit is contained in:
95
rtl/RAM/DiffWidthSyncFIFO.sv
Executable file
95
rtl/RAM/DiffWidthSyncFIFO.sv
Executable file
@@ -0,0 +1,95 @@
|
||||
`timescale 1ns / 1ps
|
||||
|
||||
module DiffWidthSyncFIFO #(
|
||||
parameter reg [7:0] DATA_WIDTH = 8,
|
||||
parameter reg [7:0] DATA_DEPTH = 12,
|
||||
parameter reg [7:0] READ_DEPTH = 3,
|
||||
parameter reg [7:0] WRITE_DEPTH = 4
|
||||
) (
|
||||
input wire clk,
|
||||
input wire reset,
|
||||
|
||||
input wire read_ready,
|
||||
output reg read_en,
|
||||
output reg [DATA_WIDTH - 1 : 0] read_data[READ_DEPTH],
|
||||
|
||||
output wire write_ready,
|
||||
input wire write_en,
|
||||
input wire [DATA_WIDTH - 1 : 0] write_data[WRITE_DEPTH]
|
||||
);
|
||||
reg [DATA_WIDTH - 1 : 0] data[DATA_DEPTH];
|
||||
reg [7:0] occupancy;
|
||||
reg [7:0] cnt_read, cnt_write;
|
||||
reg [7:0] wi, ri;
|
||||
reg read_finish, write_finish;
|
||||
|
||||
always @(posedge clk or posedge reset) begin
|
||||
if (reset) begin
|
||||
occupancy <= 0;
|
||||
end
|
||||
else begin
|
||||
if (read_finish && write_finish) begin
|
||||
occupancy <= occupancy + (WRITE_DEPTH - READ_DEPTH);
|
||||
end
|
||||
else if (read_finish) begin
|
||||
occupancy <= occupancy - READ_DEPTH;
|
||||
end
|
||||
else if (write_finish) begin
|
||||
occupancy <= occupancy + WRITE_DEPTH;
|
||||
end
|
||||
else begin
|
||||
occupancy <= occupancy;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
// write data to fifo
|
||||
assign write_ready = ((DATA_DEPTH - occupancy) >= WRITE_DEPTH && !write_en) ? 1 : 0;
|
||||
always @(posedge clk or posedge reset) begin
|
||||
if (reset) begin
|
||||
cnt_write <= 0;
|
||||
wi <= 0;
|
||||
write_finish <= 0;
|
||||
end else begin
|
||||
if (write_en && (DATA_DEPTH - occupancy) >= WRITE_DEPTH) begin
|
||||
for (wi = 0; wi < WRITE_DEPTH; wi = wi + 1) begin
|
||||
data[cnt_write] <= write_data[wi];
|
||||
|
||||
if (cnt_write < DATA_DEPTH - 1) cnt_write <= cnt_write + 1;
|
||||
else cnt_write <= 0;
|
||||
end
|
||||
write_finish <= 1;
|
||||
end else begin
|
||||
write_finish <= 0;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
integer i;
|
||||
always @(posedge clk or posedge reset) begin
|
||||
if (reset) begin
|
||||
for (i = 0; i < READ_DEPTH; i = i + 1) begin
|
||||
read_data[i] <= 0;
|
||||
end
|
||||
ri <= 0;
|
||||
read_en <= 0;
|
||||
cnt_read <= 0;
|
||||
read_finish <= 0;
|
||||
end else begin
|
||||
if (read_ready && occupancy >= READ_DEPTH) begin
|
||||
read_en <= 1;
|
||||
for (ri = 0; ri < READ_DEPTH; ri = ri + 1) begin
|
||||
read_data[ri] <= data[cnt_read];
|
||||
|
||||
if (cnt_read < DATA_DEPTH - 1) cnt_read <= cnt_read + 1;
|
||||
else cnt_read <= 0;
|
||||
end
|
||||
read_finish <= 1;
|
||||
end else begin
|
||||
read_en <= 0;
|
||||
read_finish <= 0;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
endmodule
|
92
rtl/RAM/RGB_to_RAM.v
Executable file
92
rtl/RAM/RGB_to_RAM.v
Executable file
@@ -0,0 +1,92 @@
|
||||
`timescale 1ns/1ps
|
||||
|
||||
module RGB_to_RAM #(
|
||||
parameter COLOR_DEPTH = 8,
|
||||
parameter FIFO_SIZE = 128
|
||||
) (
|
||||
input clk,
|
||||
input reset,
|
||||
|
||||
// 数据输入
|
||||
output reg in_que,
|
||||
input in_en,
|
||||
input [3 * COLOR_DEPTH - 1:0] data_in,
|
||||
|
||||
// 写入SRAM
|
||||
input write_que,
|
||||
output write_en,
|
||||
output [15:0] data_write
|
||||
);
|
||||
// 状态机
|
||||
localparam READ_DATA = 0;
|
||||
localparam SEND_R = 1;
|
||||
localparam SEND_GB = 2;
|
||||
|
||||
reg [2:0] state, nextState;
|
||||
reg [3 * COLOR_DEPTH - 1:0] data_cache;
|
||||
reg [15:0] fifo_data;
|
||||
wire fifo_full, fifo_empty;
|
||||
|
||||
async_fifo #(
|
||||
.DSIZE(16),
|
||||
.ASIZE(FIFO_SIZE)
|
||||
) fifo_image (
|
||||
.wclk(clk),
|
||||
.wrst_n(reset),
|
||||
.rclk(clk),
|
||||
.rrst_n(reset),
|
||||
|
||||
.winc(in_en),
|
||||
.wdata(fifo_data),
|
||||
.wfull(fifo_full),
|
||||
/* verilator lint_off PINCONNECTEMPTY */
|
||||
.awfull(),
|
||||
|
||||
.rinc(write_en),
|
||||
.rdata(data_write),
|
||||
.rempty(fifo_empty),
|
||||
/* verilator lint_off PINCONNECTEMPTY */
|
||||
.arempty()
|
||||
);
|
||||
|
||||
// 当有数据请求且FIFO不为空时,输出数据
|
||||
assign write_en = (write_que && !fifo_empty) ? 1 : 0;
|
||||
|
||||
always @(posedge clk or posedge reset) begin
|
||||
if (reset)
|
||||
state <= READ_DATA;
|
||||
else
|
||||
state <= nextState;
|
||||
end
|
||||
|
||||
always @(posedge clk or posedge reset) begin
|
||||
if (reset) begin
|
||||
fifo_data <= 0;
|
||||
data_cache <= 0;
|
||||
end
|
||||
else begin
|
||||
case (state)
|
||||
// 读取数据
|
||||
READ_DATA: begin
|
||||
in_que <= 1;
|
||||
if (in_en) begin
|
||||
data_cache <= data_in;
|
||||
nextState <= SEND_R;
|
||||
end
|
||||
end
|
||||
|
||||
SEND_R: begin
|
||||
in_que <= 0;
|
||||
fifo_data <= {8'b0, data_cache[3 * COLOR_DEPTH - 1:16]};
|
||||
nextState <= SEND_GB;
|
||||
end
|
||||
|
||||
SEND_GB: begin
|
||||
fifo_data <= data_cache[15:0];
|
||||
nextState <= READ_DATA;
|
||||
end
|
||||
endcase
|
||||
end
|
||||
end
|
||||
|
||||
endmodule
|
29
rtl/RAM/SDRAM.v
Executable file
29
rtl/RAM/SDRAM.v
Executable file
@@ -0,0 +1,29 @@
|
||||
module SDRAM (
|
||||
input wire clk,
|
||||
|
||||
input wire read_en,
|
||||
input wire [31:0] read_addr,
|
||||
output wire [31:0] read_data,
|
||||
output wire read_ready,
|
||||
|
||||
input wire write_en,
|
||||
input wire [31:0] write_addr,
|
||||
input reg [31:0] write_data,
|
||||
output wire write_ready
|
||||
);
|
||||
reg [31:0] ram[1920*1080];
|
||||
|
||||
assign read_ready = (!read_en) ? 1 : 0;
|
||||
assign write_ready = (!write_en) ? 1 : 0;
|
||||
|
||||
always @(posedge clk) begin
|
||||
if (read_en)
|
||||
ram[read_addr] <= read_data;
|
||||
end
|
||||
|
||||
always @(posedge clk) begin
|
||||
if (write_en)
|
||||
write_data <= ram[write_addr];
|
||||
end
|
||||
|
||||
endmodule
|
74
rtl/RAM/tb_DiffWidthSyncFIFO.sv
Executable file
74
rtl/RAM/tb_DiffWidthSyncFIFO.sv
Executable file
@@ -0,0 +1,74 @@
|
||||
`timescale 1ns / 1ps
|
||||
`include "DiffWidthSyncFIFO.v"
|
||||
`default_nettype none
|
||||
|
||||
module tb_DiffWidthSyncFIFO;
|
||||
localparam reg [7:0] DATA_WIDTH = 8;
|
||||
localparam reg [7:0] DATA_DEPTH = 12;
|
||||
localparam reg [7:0] READ_DEPTH = 3;
|
||||
localparam reg [7:0] WRITE_DEPTH = 4;
|
||||
reg clk;
|
||||
reg reset;
|
||||
reg write_en;
|
||||
reg [DATA_WIDTH - 1 : 0] write_data[WRITE_DEPTH];
|
||||
|
||||
wire read_en, write_ready, read_ready;
|
||||
wire [DATA_WIDTH - 1 : 0] read_data[READ_DEPTH];
|
||||
|
||||
|
||||
DiffWidthSyncFIFO #(
|
||||
.DATA_WIDTH (DATA_WIDTH),
|
||||
.DATA_DEPTH (DATA_DEPTH),
|
||||
.READ_DEPTH (READ_DEPTH),
|
||||
.WRITE_DEPTH(WRITE_DEPTH)
|
||||
) inst_fifo (
|
||||
.clk (clk),
|
||||
.reset(reset),
|
||||
|
||||
.read_ready(read_ready),
|
||||
.read_en(read_en),
|
||||
.read_data(read_data),
|
||||
|
||||
.write_ready(write_ready),
|
||||
.write_en(write_en),
|
||||
.write_data(write_data)
|
||||
);
|
||||
|
||||
localparam CLK_PERIOD = 10;
|
||||
always #(CLK_PERIOD / 2) clk = ~clk;
|
||||
|
||||
initial begin
|
||||
$dumpfile("tb_DiffWidthSyncFIFO.vcd");
|
||||
$dumpvars(0, tb_DiffWidthSyncFIFO);
|
||||
end
|
||||
|
||||
assign read_ready = read_en ? 0 : 1;
|
||||
|
||||
integer j;
|
||||
initial begin
|
||||
clk = 0;
|
||||
reset = 1;
|
||||
write_en = 0;
|
||||
for(j = 0; j < WRITE_DEPTH; j = j + 1)begin
|
||||
write_data[j] = 0;
|
||||
end
|
||||
end
|
||||
|
||||
integer i;
|
||||
initial begin
|
||||
#(10 * CLK_PERIOD) reset = 0;
|
||||
for (i = 0; i < 20; i = i + 1) begin
|
||||
#CLK_PERIOD
|
||||
for (j = 0; j < WRITE_DEPTH; j = j + 1) begin
|
||||
write_data[j] = {$mti_random} % (32'b1 << DATA_DEPTH);
|
||||
end
|
||||
write_en = 1;
|
||||
#CLK_PERIOD write_en = 0;
|
||||
end
|
||||
|
||||
$finish(100 * CLK_PERIOD);
|
||||
end
|
||||
|
||||
|
||||
endmodule
|
||||
`default_nettype wire
|
Reference in New Issue
Block a user