localparam FIFO_DEPTH = (1<<DEPTH_LG2);
reg [DATA_WIDTH-1:0] data[FIFO_DEPTH];
reg full, full_n,
empty, empty_n;
reg [DEPTH_LG2:0] wrptr, wrptr_n,
rdptr, rdptr_n;
// reset entries to all 0s
always_ff @(posedge clk)
if (!rst_n) begin
full <= 1'b0;
empty <= 1'b1; // empty after as reset
wrptr <= {(DEPTH_LG2+1){1'b0}};
rdptr <= {(DEPTH_LG2+1){1'b0}};
for (int i=0; i<FIFO_DEPTH; i++) begin
data[i] <= {DATA_WIDTH{1'b0}};
end
end
else begin
full <= full_n;
empty <= empty_n;
wrptr <= wrptr_n;
rdptr <= rdptr_n;
if (wren_i) begin
data[wrptr[DEPTH_LG2-1:0]] <= wdata_i;
end
end
always_comb begin
wrptr_n = wrptr;
rdptr_n = rdptr;
if (wren_i) begin
wrptr_n = wrptr + 'd1;
end
if (rden_i) begin
rdptr_n = rdptr + 'd1;
end
empty_n = (wrptr_n == rdptr_n);
full_n = (wrptr_n[DEPTH_LG2]!=rdptr_n[DEPTH_LG2])
&(wrptr_n[DEPTH_LG2-1:0]==rdptr_n[DEPTH_LG2-1:0]);
end
// synthesis translate_off
always @(posedge clk) begin
if (full_o & wren_i) begin
\$display("FIFO overflow");
@(posedge clk);
\$finish;
end
end
always @(posedge clk) begin
if (empty_o & rden_i) begin
\$display("FIFO underflow");
@(posedge clk);
\$finish;
end
end
// synthesis translate_on
assign full_o = full;
assign empty_o = empty;
assign rdata_o = data[rdptr[DEPTH_LG2-1:0]];
echo "Cleaning up the old directory"
rm -rf $RUN_DIR
echo "Creating a new directory"
mkdir -p $RUN_DIR
cd $RUN_DIR
echo "Compiling"
$COMPILE_CMD $COMPILE_OPTIONS -f $FILELIST_TB -f $FILELIST_RTL
<<EndOfFile:DMAC/SIM/run.compile>>
echo "Cleaning up the old directory"
rm -rf $RUN_DIR
echo "Creating a new directory"
mkdir -p $RUN_DIR
cd $RUN_DIR
echo "Compiling"
$COMPILE_CMD $COMPILE_OPTIONS $COV_OPTIONS -f $FILELIST_TB -f $FILELIST_RTL
<<EndOfFile:DMAC/SIM/run.compile4cov>>
if [ -e $RUN_DIR/dump.vcd ];
then
cd $RUN_DIR
$WAVE_CMD $WAVE_OPTIONS -i dump.vcd
else
echo "Dump file does not exist"
exit 1
fi
<<EndOfFile:DMAC/SIM/run.waveform>>
///
Direct Memory Access (DMA) Controller
Design Document V1.0
1 Overview
This document specifies the design and implementation of a Direct Memory Access Controller (DMAC) as a part of System-on-a-Chip (SoC). The main purpose of this DMAC design is to integrate into SoC for exchange a large volume of data between memory and peripherals at high speed. The proposed DMAC works on ARM’s Advanced Microcontroller Bus Architecture (AMBA) specification. The DMAC provides an AMBA APB interface to configure the IP, and an AMBA AXI interface to transfer data.
2 Architecture Specification
2.1 General Description
Some applications require transferring a volume of data between memory and peripherals without any modification on data. In software, it is commonly served by executing the memcpy library function in C, C++ or other languages. In C, the function has the following interface and copies len bytes from the object pointed by src to the object pointed by dst: void* memcpy(void* dst, const void* src, size_t len).
While a pure software-based implementation of memcpy transfers data using CPU instructions, DMA does not use expensive CPU cycles but uses a hardware engine (DMAC) for the transfer. This can significantly speed up data transfers and allows using CPU for other jobs.
2.2 Usage Constraints
Below describe constraints in utilizing DMAC v1.
-The src and dst addresses are physical addresses.
-The src and dst addresses must be a multiple of 4.
-The len must be a multiple of 4.
-The maximum len is 0xFFFF
-Source and destination ranges must not overlap.
2.3 Programming Model
Software can use the following sequence to transfer data using DMAC.
-1.Write the source address to DMA_SRC register
-2.Write the destination address to DMA_DST register
-3.Write length to DMA_LEN register
-4.Write 1 to bit[0] of DMA_CMD register
-5.Wait until DMA_STATUS register has bit[0] as 1.
The version of this DMA controller. The upper 16 bits represent the major version. The lower 16 bits represent the released year of the version. This document describes behaviors of major version 1.
2.4.2 DMA_SRC
Field name
Bit range
R/W
Reset value
Desciption
start_addr
[31:0]
R/W
0x0000_0000
start address of the source range.
2.4.3 DMA_DST
Field name
Bit range
R/W
Reset value
Desciption
start_addr
[31:0]
R/W
0x0000_0000
start address of the destination range.
2.4.4 DMA_LEN
Field name
Bit range
R/W
Reset value
Desciption
byte_len
[15:0]
R/W
0x0000
Number of bytes to be transferred from the source to the destination.
2.4.5 DMA_CMD Field
Field name
Bit range
R/W
Reset value
Desciption
start
[0]
W
N/A
Writing 1 to this field will initiate a DMA transfer based on DMA_SRC, DMA_DST, and DMA_LEN registers. Software must not write 1 when there’s an on-going transfer. Writing 0 to this field does not affect operation
2.4.6 DMA_STATUS
Field name
Bit range
R/W
Reset value
Desciption
done
[0]
R
1
This field is 1 when there’s no on-going DMA transfer. Software must wait this field to be 1 for a completion of a transfer. Software must not initiate a DMA transfer when this field is 0.
3 Micro-architecture v1.1 Specification
This section describes microarchitecture of a simple DMAC. It reads data from memory, buffers the data, and write the data into memory. It repeats this procedure until it completes transferring the specified number of bytes.
For simplicity, it read/writes one-cycle data (4 bytes) at a time (in other words, burst-1 transfers). For simplicity, this microarchitecture does not consider write responses from the AXI interface. Later versions will support burst transfers and write responses.
3.1 External Interface
DMAC v1.1 has the following external interfaces to communicate with other hardware IPs.
-AMBA APB interface for configuration
-AMBA AXI interface for data transfer
The image you’ve uploaded is a diagram showing the on-chip interconnect of a computer system. Here’s a detailed description:
The diagram illustrates how the CPU core, memory, and DMAC (Direct Memory Access Controller) are connected through an on-chip interconnect.
The connections also include specific interfaces like Config interface (APB) and Data interface (AXI).
“CPU core” is a box on the left side connected to the central “On-chip interconnect” cloud shape with a bidirectional arrow.
Below the “CPU core,” there’s another box labeled “Memory,” also connected to the “On-chip interconnect” with a bidirectional arrow.
On the right side, there’s a box labeled “DMAC” connected to both “Config interface (APB)” and “Data interface (AXI)” which are in turn connected to the central “On-chip interconnect” with bidirectional arrows.
The arrows indicate that data can flow in both directions between these components.
3.2 Block Diagram
DMAC v1.1 has the following blocks inside.
The diagram is divided into three main blocks labeled “DMAC_TOP,” “DMAC_CFG,” and “DMAC_ENGINE.”
“clk” and “rst” are inputs to the “DMAC_TOP” block.
An arrow labeled “APB” connects the “DMAC_TOP” block to the “DMAC_CFG” block.
Another arrow labeled “AXI” connects both the “DMAC_TOP” and “DMAC_CFG” blocks to the “DMAC_ENGINE” block.
Inside the “DMAC_ENGINE” block, there are four internal components labeled as follows:
SRC_ADDR
DST_ADDR
CNT
DATA BUF
There’s also a small circular graph with nodes labeled 0 to 3 inside this block.
This diagram is likely used to illustrate the flow of data or control signals between these components in a Direct Memory Access Controller configuration. Please let me know if you need more information!
3.3 Configuration Register (lab2)
This block receives read/write requests from the APB and configures the registers describes in Section 2.4.
3.4 Finite State Machine (lab3)
DMA engine utilizes the following state machine to control operations.
The diagram contains five blue circles representing different states: IDLE, RREQ, RDATA, WREQ, and WDATA.
Arrows connect these circles indicating the flow from one state to another.
Each arrow has text annotations that describe the conditions for transitioning from one state to another. For example, transitioning from IDLE to RREQ requires writing 1 to DMA_CMD & LEN!=0, and copying DMA_SRC/DST/LEN.
There are also annotations on the state circles themselves, such as “done=1” on IDLE and “AWVALID=1” on WDATA.
4 Micro-architecture v1.2 Specification (lab4)
A problem with microarchitecture v1.1 is that it reads/writes data one-by-one. As memory read takes some time, DMAC v1.1 will suffer from poor performance with a long memory read latency (그림 2). We will improve the microarchitecture to transfer a burst of data to minimize performance degradation.
{ "signal": [
{ "name": "clk", "wave": "p....|.................." },
{ "name": "state", "wave": "2.3.4|..5.6.3.4|..5.6.3.", "data": ["IDLE", "RREQ", "RDATA", "WREQ", "WDATA", "RREQ", "RDATA", "WREQ", "WDATA", "RREQ"] },
{ "name": "write to CMD", "wave": "010..|.........|........", "data": ["1"] },
{},
[ "AR ch",
{ "name": "ARVALID(out)", "wave": "0.1.0|......1.0|......1.", "data": ["SRC"] },
{ "name": "ARADDR(out)", "wave": "x.3.x|......3.x|......3.", "data": ["SRC", "SRC+4", "SRC+8"] },
{ "name": "ARLEN(out)", "wave": "2....|.........|........", "data": ["0"] },
{ "name": "ARREADY(in)", "wave": "0..10|.......10|.......1" },
],
[ "R ch",
{ "name": "RREADY(out)", "wave": "0...1|..0.....1|..0....." },
{ "name": "RVALID(in)", "wave": "0....|.10......|.10....." },
{ "name": "RDATA(in)", "wave": "x....|.4x......|.4x.....", "data": ["DATA", "DATA"] },
],
[ "AW ch",
{ "name": "AWVALID(out)", "wave": "0....|..1.0....|..1.0..." },
{ "name": "AWADDR(out)", "wave": "x....|..5.x....|..5.x...", "data": ["DST", "DST+4"] },
{ "name": "AWLEN(out)", "wave": "2....|.........|........", "data": ["0"] },
{ "name": "AWREADY(in)", "wave": "0....|...10....|...10..." },
],
[ "W ch",
{ "name": "WVALID(out)", "wave": "0....|....1.0..|....1.0." },
{ "name": "WDATA(out)", "wave": "x....|....4.x..|....4.x.", "data": ["DATA", "DATA"] },
{ "name": "WREADY(in)", "wave": "0....|.....10..|.....10." }
]
],
"head" : {
"tick" : "0"
},
"foot" : {
"tick" : "0"
}
}
그림 2. DMA operation with microarchitecture 1.1. At a time, it transfers single burst of data
In Microarchitecture version 2, DMAC transfers up to 16 cycles of data with a single access.
This can significantly reduce execution time by transferring data in bursts (그림 3).
The implementation of burst transfers in a DMA controller can significantly enhance the data throughput between memory and peripherals, particularly in systems where memory read and write latencies critically affect performance. The enhancement to support burst transfers, detailed as microarchitecture v1.2, proposes a more efficient approach to manage data transactions by minimizing the latency impact through batch processing of data.
Enhanced Data Transfer Process with Burst Mode
In the upgraded version of the DMA controller (v1.2 or later), initiating a burst transfer allows the controller to read a block of data (up to 16 cycles or words) from the source address in memory and then write this block to the destination address. This method contrasts sharply with the previous implementation (v1.1), where data was transferred one word at a time, requiring a separate read and write operation for each word, thus significantly increasing the overall transaction time due to latency.
Improved Performance through Burst Transfers
The implementation of burst transfers effectively reduces the number of read and write operations that need to be initiated, directly diminishing the impact of read and write latencies. By grouping multiple data words into a single read or write operation, the DMA controller can maintain a higher data transfer rate, thus making it more efficient for large volume data transactions, such as in multimedia processing, large dataset transfers between different memory areas, or high-speed data buffering in networking hardware.
Burst Transfer Implementation Considerations
Burst Length Configuration: Software needs to configure the DMA controller with the length of the burst, often limited by the AXI interface specifications or the capabilities of the memory subsystem. The burst length significantly influences the transfer efficiency and should be optimized based on the system's use case.
Address Increment: During a burst transfer, the source and destination addresses need to be incremented properly to ensure that data is read from and written to the correct memory locations. The DMA controller should automatically handle address increments, aligning them with the burst length and ensuring data integrity.
Interface Compatibility: For systems utilizing both v1.1 and v1.2 architectures or migrating from one to the other, ensuring interface compatibility is essential. Changes in the data handling logic, including burst mode operation, should not disrupt the existing data flow or require extensive reconfiguration of the interconnected systems.
Error Handling: Given the larger data block transfers, error detection and handling mechanisms become even more critical. The DMA controller needs to effectively manage errors such as data corruption or transfer failures, possibly retrying or aborting the transfer based on predefined conditions.
Software Integration: Software layers, including drivers and application interfaces, must be adapted to leverage the capabilities of burst transfers. This might include updates to DMA configuration settings, transfer initiation processes, and handling of transfer completions or errors.
Future Directions
Beyond burst transfers, future iterations of DMA controllers might explore additional optimizations such as predictive pre-fetching, tighter integration with cache hierarchies for reduced latency, or dynamic transfer size adjustments based on real-time analysis of the system's state. This continual evolution aims to maximize data transfer efficiency, catering to the increasing demands of modern computing environments.