I tried to use CDMA
to transfer zynq’s data into block memory and after doing some operation(multiplication) and then retrieve answer from block memory to zynq
.
Last, I can read answer in zynq
memory through mmio
.
Following is ip what I use
I expect to write input(a) in address : 0x30000000 and input(b) in :0x30000004 and output(ans) in
0x3000000C
this is my jupyter code, are there anything wrong in my code?
from pynq import Overlay
design = Overlay('./new.bit')
design.ip_dict
cdma_address = design.ip_dict['axi_cdma_0']['phys_addr']
sys_in1 = 0x30000000 # zynq's addr
cdma_ctrl = cdma_address+0x00
cdma_sa = cdma_address+0x18
cdma_da = cdma_address+0x20
cdma_btt = cdma_address+0x28
from pynq import MMIO
sys = MMIO(sys_in1,0x14)
ctrl = MMIO(cdma_ctrl,0x18)
sa = MMIO(cdma_sa,0x8)
da = MMIO(cdma_da,0x8)
btt = MMIO(cdma_btt,0x10)
sys.write(0x0,6) # a
sys.write(0x4,6) # b
ctrl.write(0x0,0x04)
sa.write(0x0,0x30000000) # write source(zynq's addr)
da.write(0x0,0xC0000000) # write destination(bram's addr)
btt.write(0x0,0x8)
ctrl.write(0x0,0x04)
sa.write(0x0,0xC0000000) # write source(bram's addr)
da.write(0x0,0x30000000) # write destination(zynq's addr)
btt.write(0x0,0x10)
print(sys.read(0x000C)) # a*b
following is verilog code for multiplication
module mul16(rst, clk, R_req, addr, R_data, W_req, W_data);
input rst;
input clk;
output R_req;
output [31:0] addr;
input [31:0] R_data;
output [3:0] W_req;
output [31:0] W_data;
wire w_r;
reg [1:0] C_state;
wire [1:0] N_state;
reg [31:0] indata [1:0];
assign W_data = indata[0][15:0] * indata[1][15:0];
assign N_state = C_state + 1;
assign w_r = C_state[0] & C_state[1];
assign R_req = 1;
assign W_req = {w_r, w_r, w_r, w_r};
assign addr = {28'b0,C_state,2'b0};
always@(posedge clk or negedge rst)begin
if(!rst)begin
C_state <= 0;
indata[0] <= 0;
indata[1] <= 0;
end
else begin
C_state <= N_state;
indata[N_state[0]]<=R_data;
end
end
endmodule