// DMAC/SIM/TB/AXI_INTF.sv
interface APB (
input clk
);
logic psel;
logic penable;
logic [31:0] paddr;
logic pwrite;
logic [31:0] pwdata;
logic pready;
logic [31:0] prdata;
logic pslverr;
modport master (
input clk,
input pready, prdata, pslverr,
output psel, penable, paddr, pwrite, pwdata
);
task init();
psel = 1'b0;
penable = 1'b0;
paddr = 32'd0;
pwrite = 1'b0;
pwdata = 32'd0;
endtask
task write(input int addr,
input int data);
#1
psel = 1'b1;
penable = 1'b0;
paddr = addr;
pwrite = 1'b1;
pwdata = data;
@(posedge clk);
#1
penable = 1'b1;
@(posedge clk);
while (pready==1'b0) begin
@(posedge clk);
end
psel = 1'b0;
penable = 1'b0;
paddr = 'hX;
pwrite = 1'bx;
pwdata = 'hX;
endtask
task read(input int addr,
output int data);
#1
psel = 1'b1;
penable = 1'b0;
paddr = addr;
pwrite = 1'b0;
pwdata = 'hX;
@(posedge clk);
#1
penable = 1'b1;
@(posedge clk);
while (pready==1'b0) begin
@(posedge clk);
end
data = prdata;
psel = 1'b0;
penable = 1'b0;
paddr = 'hX;
pwrite = 1'bx;
pwdata = 'hX;
endtask
endinterface
// DMAC/SIM/TB/DMAC_CFG_TB.sv
define SRC_ADDR 32'h100 define DST_ADDR 32'h104
define LEN_ADDR 32'h108 define STAT_ADDR 32'h110
define START_ADDR 32'h10c define TIMEOUT_CYCLE 10000000
module DMAC_CFG_TB ();
reg clk;
reg rst_n;
// clock generation
initial begin
clk = 1'b0;
forever #10 clk = !clk;
end
// reset generation
initial begin
rst_n = 1'b0; // active at time 0
repeat (3) @(posedge clk); // after 3 cycles,
rst_n = 1'b1; // release the reset
end
// enable waveform dump
initial begin
dumpvars(0,uDUT);dumpfile("dump.vcd");
end
// timeout
initial begin
#TIMEOUT_CYCLE $display("Timeout!"); $finish; end APB apb_if (.clk(clk)); reg [31:0] test_vector; initial begin int data; apb_if.init(); @(posedge rst_n); // wait for a release of the reset repeat (10) @(posedge clk); // wait another 10 cycles apb_if.read(32'h0, data); $display("---------------------------------------------------"); $display("IP version: %x", data); if (data!=='h0001_2024) $display("Wrong IP version"); $display("---------------------------------------------------"); $display("---------------------------------------------------"); $display("Reset value test"); $display("---------------------------------------------------"); apb_if.read(SRC_ADDR, data);
if (data===0)
display("DMASRC(pass):elsedisplay("DMA_SRC(fail): %x", data);
@(posedge clk);
finish;endapbif.readdisplay("DMA_DST(pass): %x", data);
else begin
display("DMADST(fail):finish;
end
apb_if.read(LEN_ADDR, data); if (data===0) $display("DMA_LEN(pass): %x", data); else begin $display("DMA_LEN(fail): %x", data); @(posedge clk); $finish; end apb_if.read(STAT_ADDR, data);
if (data===1)
display("DMASTATUS(pass):display("DMA_STATUS(fail): %x", data);
@(posedge clk);
finish;enddisplay("---------------------------------------------------");
display("Configurationtest");display("---------------------------------------------------");
test_vector = 32'h1000;
apb_if.write(SRC_ADDR, test_vector); apb_if.read(SRC_ADDR, data);
if (data===test_vector)
display("DMASRC(pass):elsedisplay("DMA_SRC(fail): %x", data);
@(posedge clk);
display("DMA_DST(pass): %x", data);
else begin
display("DMADST(fail):finish;
end
test_vector = 32'h100;
apb_if.write(LEN_ADDR, test_vector); apb_if.read(LEN_ADDR, data);
if (data===test_vector)
display("DMALEN(pass):elsedisplay("DMA_LEN(fail): %x", data);
@(posedge clk);
finish;enddisplay("---------------------------------------------------");
display("DMAstart");display("---------------------------------------------------");
test_vector = 32'h1;
apb_if.write(START_ADDR, test_vector); $display("---------------------------------------------------"); $display("Wait for a DMA completion"); $display("---------------------------------------------------"); data = 0; while (data != 1) begin apb_if.read(STAT_ADDR, data);
repeat (100) @(posedge clk);
write(".");enddisplay("");
@(posedge clk);
display("−−−−−−display("DMA completed");
display("−−−−−−finish;
end
DMAC_CFG u_DUT (
.clk (clk),
.rst_n (rst_n),
// APB interface
.psel_i (apb_if.psel),
.penable_i (apb_if.penable),
.paddr_i (apb_if.paddr[11:0]),
.pwrite_i (apb_if.pwrite),
.pwdata_i (apb_if.pwdata),
.pready_o (apb_if.pready),
.prdata_o (apb_if.prdata),
.pslverr_o (apb_if.pslverr),
.src_addr_o (/* FLOATING /),
.dst_addr_o (/ FLOATING /),
.byte_len_o (/ FLOATING /),
.start_o (/ FLOATING */),
.done_i (1'b1)
);
endmodule
It looks like you're designing a Direct Memory Access Controller (DMAC) configuration module DMAC_CFG with an APB interface for read and write operations, and you're also preparing test benches to verify its functionality.
To complete the DMAC_CFG module, especially parts where it says // fill your code here, let's break down what needs to be done in those sections:
- Write Operation Handling:
- APB write occurs with
psel_i, penable_i, and pwrite_i are all high.
- Write Enable (
wren) signal generation.
assign wren = psel_i && penable_i && pwrite_i;
- Configuration of Register Write Operations:
- Handling write operations based on the
paddr_i (APB address bus).
always @(posedge clk) begin
if (!rst_n) begin
src_addr <= 32'b0;
dst_addr <= 32'b0;
byte_len <= 16'b0;
// Potentially reset more registers you define for CMD and STATUS.
end else if (wren) begin
case (paddr_i)
`SRC_ADDR: src_addr <= pwdata_i;
`DST_ADDR: dst_addr <= pwdata_i;
`LEN_ADDR: byte_len <= pwdata_i[15:0];
// Additional registers like for DMA_CMD could be here as well.
// Example: DMA_CMD register to trigger start
`START_ADDR: start_trigger <= pwdata_i[0]; // Assuming 1-bit register to start DMA
// Default cases could be added based on need.
endcase
end
end
- Read Operation Handling:
- APB read occurs with
psel_i and penable_i are high, and pwrite_i is low.
- The
always block for reading that buffers the addressed register data into rdata.
always @(posedge clk) begin
if (!rst_n) begin
rdata <= 32'b0;
end else if (psel_i && !penable_i && !pwrite_i) begin // Setup phase of APB read
case (paddr_i)
`SRC_ADDR: rdata <= src_addr;
`DST_ADDR: rdata <= dst_addr;
`LEN_ADDR: rdata <= {16'b0, byte_len}; // Padding higher bits with 0 for 32-bit bus.
// Add handling for reading other configuration registers
// Example: For a status or command read, assign `rdata` accordingly.
// Default cases could be added based on need.
endcase
end
end
- Start Signal Generation:
- Assuming you have a register or mechanism to decide when to start the DMA operation (e.g., based on an APB write to a certain address/register).
- We introduced
start_trigger in the write operation section, let's assume it triggers the start.
reg start_trigger;
always @(posedge clk) begin
if (!rst_n)
start_trigger <= 1'b0;
// Resetting start_trigger should be handled according to your design specifics,
// e.g., after acknowledging the start, or after DMA operation completion.
end
assign start = start_trigger;
Adjustments may be necessary depending on additional specifics of your DMAC design, such as handling of a done_i signal from the DMA logic, how to reset the start_trigger, among others. Also, errors, illegal address access, or command interpretation might require additional logic, particularly for setting pslverr_o.
Finally, ensure to define appropriate addresses (SRC_ADDR, DST_ADDR, LEN_ADDR, START_ADDR) as parameters or local parameters matching their intended use in the simulation test bench (DMAC_CFG_TB.sv). The snippets here assume these are defined as define or localparam at the beginning of your SystemVerilog file or within an included header file.