axi_usb_fx3: Integrated actual GPIF II interface, with 2 address lines

main
Adrian Costina 2016-04-19 14:38:26 +03:00
parent 8a574cd8ba
commit d7d8b2cf1c
3 changed files with 471 additions and 375 deletions

View File

@ -112,12 +112,12 @@ module axi_usb_fx3 (
input dma_rdy;
input dma_wmk;
input [10:0] fifo_rdy;
input [ 3:0] fifo_rdy;
output pclk;
output [31:0] data;
output [4:0] addr;
inout [31:0] data;
output [ 1:0] addr;
output slcs_n;
output slrd_n;
@ -127,8 +127,8 @@ module axi_usb_fx3 (
output epswitch_n;
// DEBUG
output [35:0] debug_fx32dma;
output [34:0] debug_dma2fx3;
output [74:0] debug_fx32dma;
output [73:0] debug_dma2fx3;
output [14:0] debug_status;
// irq
@ -223,6 +223,7 @@ module axi_usb_fx3 (
wire fifo8_direction;
wire fifo9_direction;
wire fifoa_direction;
wire [10:0] fifo_direction;
wire fx32dma_valid;
wire fx32dma_ready;
@ -251,11 +252,13 @@ module axi_usb_fx3 (
assign pclk = s_axi_aclk;
assign up_rstn = s_axi_aresetn;
assign fifo_direction = {fifo9_direction, fifo8_direction, fifo7_direction, fifo6_direction, fifo5_direction, fifo4_direction, fifo3_direction, fifo2_direction, fifo1_direction, fifo0_direction};
// DEBUG
assign debug_dma2fx3 = {dma2fx3_ready, dma2fx3_valid, dma2fx3_data, dma2fx3_eop};
assign debug_fx32dma = {fx32dma_eop,fx32dma_ready, fx32dma_valid, fx32dma_data, fx32dma_sop};
assign debug_status = {irq, error, monitor_error, test_mode_tpg, test_mode_tpm, trig, fifo_num};
assign debug_dma2fx3 = {s_axis_tdata, dma2fx3_data, s_axis_tkeep, s_axis_tlast, s_axis_tvalid, s_axis_tready, dma2fx3_ready, dma2fx3_valid, dma2fx3_eop};
assign debug_fx32dma = {fx32dma_eop, m_axis_tdata, fx32dma_data, m_axis_tkeep, m_axis_tlast, m_axis_tvalid, m_axis_tready, fx32dma_ready, fx32dma_valid, fx32dma_sop};
assign debug_status = {irq, error, monitor_error, test_mode_tpg, test_mode_tpm, trig, fifo_num};
// packetizer, TPM/TPG and DMA interface
@ -397,10 +400,12 @@ module axi_usb_fx3 (
axi_usb_fx3_if fx3_if(
.pclk(pclk), //output clk 100 Mhz and 180 phase shift
.reset_n(up_rstn),
.dma_rdy(dma_rdy),
.dma_wmk(dma_wmk),
.fifo_rdy(fifo_rdy),
.pclk(pclk), //output clk 100 Mhz and 180 phase shift
.data(data),
.addr(addr), //output fifo address
.slcs_n(slcs_n), //output chip select
@ -409,11 +414,13 @@ module axi_usb_fx3 (
.slwr_n(slwr_n), //output write select
.pktend_n(pktend_n), //output pkt end
.epswitch_n(epswitch_n), //output pkt end
.fifo_num(fifo_num),
.trig(trig),
.test_mode_tpm(test_mode_tpm),
.fifo_ready(fifo_ready),
.fifo_num(fifo_num),
.fifo_direction(fifo_direction),
.trig(trig),
.fx32dma_valid(fx32dma_valid),
.fx32dma_ready(fx32dma_ready),
.fx32dma_data(fx32dma_data),

View File

@ -268,12 +268,13 @@ module axi_usb_fx3_core (
reg [ 7:0] header_pointer = 8'h0;
reg header_read = 1'b0;
reg [31:0] dma2fx3_counter = 1'b0;
reg [31:0] footer_pointer = 1'b0;
reg [31:0] dma2fx3_counter = 32'h0;
reg [ 7:0] footer_pointer = 8'h0;
reg s_axis_tready = 1'b0;
reg dma2fx3_valid = 1'b0;
reg [31:0] dma2fx3_data = 32'h0;
reg [31:0] dma2fx3_data_reg = 32'h0;
reg dma2fx3_eop = 1'b0;
reg [31:0] expected_data = 32'h0;
@ -369,132 +370,6 @@ module axi_usb_fx3_core (
assign fx32dma_ready = m_axis_tready;
// state machine
always @(posedge clk) begin
if (reset == 1'b1 || error_fx32dma == 1'b1) begin
state_fx32dma <= IDLE;
end else begin
state_fx32dma <= next_state_fx32dma;
end
end
always @(*) begin
case(state_fx32dma)
IDLE:
if(fx32dma_sop == 1'b1) begin
next_state_fx32dma = READ_HEADER;
end else begin
next_state_fx32dma = state_fx32dma;
end
READ_HEADER:
if(header_read == 1'b1) begin
next_state_fx32dma = READ_DATA;
end else begin
next_state_fx32dma = state_fx32dma;
end
READ_DATA:
if(data_size_transaction <= 4) begin
next_state_fx32dma = IDLE;
end else begin
next_state_fx32dma = state_fx32dma;
end
default: next_state_fx32dma = IDLE;
endcase
end
always @(posedge clk) begin
case(state_fx32dma)
IDLE: begin
m_axis_tvalid <= 1'b0;
m_axis_tkeep <= 4'h0;
m_axis_tlast <= 1'b0;
error_fx32dma <= 1'b0;
eot_fx32dma <= 1'b0;
header_read <= 1'b0;
header_pointer <= 8'h4;
first_transfer <= 1'b1;
monitor_error <= 1'b0;
if (fx32dma_sop == 1'b1) begin
if(fx32dma_valid == 1'b1) begin
if(fx32dma_data != 32'hf00ff00f) begin
error_fx32dma <= 1'b1;
end else begin
error_fx32dma <= 1'b0;
end
end
end
case (test_mode_tpm)
4'h1: expected_data <= 32'haaaaaaaa;
default: expected_data <= 32'hffffffff;
endcase
end
READ_HEADER: begin
m_axis_tvalid <= 1'b0;
m_axis_tkeep <= 4'h0;
m_axis_tlast <= 1'b0;
error_fx32dma <= 1'b0;
eot_fx32dma <= 1'b0;
first_transfer <= 1'b1;
monitor_error <= 1'b0;
if( fx32dma_valid == 1'b1) begin
if(header_pointer < header_size_current - 8) begin
header_pointer <= header_pointer + 4;
end else begin
header_read <= 1'b1;
end
if (header_pointer == 4) begin
data_size_transaction <= fx32dma_data;
if (fx32dma_data > buffer_size_current) begin
error_fx32dma <= 1'b1;
end
end
end
end
READ_DATA: begin
m_axis_tvalid <= fx32dma_valid;
m_axis_tdata <= fx32dma_data;
if (fx32dma_valid == 1'b1) begin
first_transfer <= 1'b0;
if (data_size_transaction > 4) begin
m_axis_tkeep <= 4'hf;
m_axis_tlast <= 1'b0;
data_size_transaction <= data_size_transaction - 4;
end else begin
m_axis_tlast <= 1'b1;
eot_fx32dma <= 1'b1;
case (data_size_transaction)
1: m_axis_tkeep <= 4'h1;
2: m_axis_tkeep <= 4'h3;
3: m_axis_tkeep <= 4'h7;
default: m_axis_tkeep <= 4'hf;
endcase
end
end
// monitor
if (test_mode_active_tpm == 1'b1) begin
if (first_transfer == 1) begin
expected_data <= fx32dma_data;
end else begin
case (test_mode_tpm)
4'h1: expected_data <= ~expected_data;
4'h2: expected_data <= ~expected_data;
4'h3: expected_data <= pn9(expected_data);
4'h4: expected_data <= pn23(expected_data);
4'h7: expected_data <= expected_data + 1;
default: expected_data <= 0;
endcase
if (expected_data != m_axis_tdata) begin
monitor_error <= 1'b1;
end else begin
monitor_error <= 1'b0;
end
end
end
end
endcase
end
always @(*) begin
case (fifo_num)
5'h0: buffer_size_current = fifo0_buffer_size;
@ -536,6 +411,148 @@ module axi_usb_fx3_core (
endcase
end
// state machine
always @(posedge clk) begin
if (reset == 1'b1 || error_fx32dma == 1'b1) begin
state_fx32dma <= IDLE;
end else begin
state_fx32dma <= next_state_fx32dma;
end
end
always @(*) begin
case(state_fx32dma)
IDLE:
if(fx32dma_sop == 1'b1) begin
next_state_fx32dma = READ_HEADER;
end else begin
next_state_fx32dma = state_fx32dma;
end
READ_HEADER:
if(header_read == 1'b1) begin
next_state_fx32dma = READ_DATA;
end else begin
next_state_fx32dma = state_fx32dma;
end
READ_DATA:
if(data_size_transaction <= 4) begin
next_state_fx32dma = IDLE;
end else begin
next_state_fx32dma = state_fx32dma;
end
default: next_state_fx32dma = IDLE;
endcase
end
always @(*) begin
m_axis_tdata = fx32dma_data;
case(state_fx32dma)
IDLE: begin
m_axis_tvalid = 1'b0;
m_axis_tkeep = 4'h0;
m_axis_tlast = 1'b0;
eot_fx32dma = 1'b0;
end
READ_HEADER: begin
m_axis_tvalid = 1'b0;
m_axis_tkeep = 4'h0;
m_axis_tlast = 1'b0;
eot_fx32dma = 1'b0;
end
READ_DATA: begin
m_axis_tvalid = fx32dma_valid;
m_axis_tlast = fx32dma_eop;
eot_fx32dma = fx32dma_eop;
if (fx32dma_valid == 1'b1) begin
if (data_size_transaction > 4) begin
m_axis_tkeep = 4'hf;
eot_fx32dma = 1'b0;
end else begin
eot_fx32dma = 1'b1;
m_axis_tlast = 1'b1;
case (data_size_transaction)
1: m_axis_tkeep = 4'h1;
2: m_axis_tkeep = 4'h3;
3: m_axis_tkeep = 4'h7;
default: m_axis_tkeep = 4'hf;
endcase
end
end else begin
m_axis_tkeep = 4'h0;
eot_fx32dma = 1'b0;
end
end
default: begin
m_axis_tvalid = 1'b0;
m_axis_tkeep = 4'h0;
m_axis_tlast = 1'b0;
eot_fx32dma = 1'b0;
end
endcase
end
always @(posedge clk) begin
header_read <= 1'b0;
if (state_fx32dma == IDLE) begin
if (fx32dma_sop == 1'b1) begin
header_pointer <= 8'h4;
if (fx32dma_data != 32'hf00ff00f) begin
error_fx32dma <= 1'b1;
end else begin
error_fx32dma <= 1'b0;
end
end
case (test_mode_tpm)
4'h1: expected_data <= 32'haaaaaaaa;
default: expected_data <= 32'hffffffff;
endcase
end
if (state_fx32dma == READ_HEADER) begin
if (fx32dma_valid == 1'b1) begin
if(header_pointer < header_size_current - 4) begin
header_pointer <= header_pointer + 8;
end else begin
header_read <= 1'b1;
end
if (header_pointer == 4) begin
data_size_transaction <= fx32dma_data;
if (fx32dma_data > buffer_size_current) begin
error_fx32dma <= 1'b1;
end
end
end
end
if (state_fx32dma == READ_DATA) begin
first_transfer <= 1'b1;
if (fx32dma_valid == 1'b1) begin
first_transfer <= 1'b0;
if (data_size_transaction > 4) begin
data_size_transaction <= data_size_transaction - 4;
end
end
// monitor
if (test_mode_active_tpm == 1'b1) begin
if (first_transfer == 1) begin
expected_data <= fx32dma_data;
end else begin
case (test_mode_tpm)
4'h1: expected_data <= ~expected_data;
4'h2: expected_data <= ~expected_data;
4'h3: expected_data <= pn9(expected_data);
4'h4: expected_data <= pn23(expected_data);
4'h7: expected_data <= expected_data + 1;
default: expected_data <= 0;
endcase
if (expected_data != m_axis_tdata) begin
monitor_error <= 1'b1;
end else begin
monitor_error <= 1'b0;
end
end
end
end
end
// dma2fx3
always @(posedge clk) begin
@ -552,92 +569,120 @@ module axi_usb_fx3_core (
if(dma2fx3_ready == 1'b1) begin
next_state_dma2fx3 = READ_DATA;
end else begin
next_state_dma2fx3 = state_dma2fx3;
next_state_dma2fx3 = IDLE;
end
READ_DATA:
if(s_axis_tlast == 1'b1 || dma2fx3_counter >= buffer_size_current - 4) begin
next_state_dma2fx3 = ADD_FOOTER;
end else begin
next_state_dma2fx3 = state_dma2fx3;
next_state_dma2fx3 = READ_DATA;
end
ADD_FOOTER:
if(dma2fx3_eop == 1'b1) begin
next_state_dma2fx3 = IDLE;
end else begin
next_state_dma2fx3 = state_dma2fx3;
next_state_dma2fx3 = ADD_FOOTER;
end
default: next_state_dma2fx3 = IDLE;
default: next_state_dma2fx3 = IDLE;
endcase
end
always @(*) begin
case(state_dma2fx3)
IDLE: begin
s_axis_tready = 1'b0;
dma2fx3_valid = 1'b0;
eot_dma2fx3 = 1'b0;
dma2fx3_eop = 1'b0;
dma2fx3_data = dma2fx3_data_reg;
end
READ_DATA: begin
eot_dma2fx3 = 1'b0;
if (test_mode_active_tpg == 1'b1) begin
s_axis_tready = 1'b0;
dma2fx3_valid = 1'b1;
end else begin
dma2fx3_valid = s_axis_tvalid & s_axis_tready;
s_axis_tready = dma2fx3_ready;
end
dma2fx3_eop = 1'b0;
if (test_mode_active_tpg == 1'b1) begin
dma2fx3_data = dma2fx3_data_reg;
end else begin
dma2fx3_data = s_axis_tdata;
end
end
ADD_FOOTER: begin
s_axis_tready = 1'b0;
dma2fx3_valid = 1'b1;
if (footer_pointer == header_size_current) begin
dma2fx3_eop = 1'b1;
eot_dma2fx3 = 1'b1;
end else begin
dma2fx3_eop = 1'b0;
eot_dma2fx3 = 1'b0;
end
dma2fx3_data = dma2fx3_data_reg;
end
default: begin
s_axis_tready = 1'b0;
dma2fx3_valid = 1'b0;
eot_dma2fx3 = 1'b0;
dma2fx3_eop = 1'b0;
dma2fx3_data = dma2fx3_data_reg;
end
endcase
end
always @(posedge clk) begin
case(state_dma2fx3)
IDLE: begin
dma2fx3_eop <= 1'b0;
eot_dma2fx3 <= 1'b0;
s_axis_tready <= 1'b0;
footer_pointer <= 0;
dma2fx3_counter <= 0;
dma2fx3_valid <= 1'b0;
case (test_mode_tpg)
4'h1: dma2fx3_data <= 32'haaaaaaaa;
default: dma2fx3_data <= 32'hffffffff;
endcase
end
READ_DATA: begin
dma2fx3_eop <= 1'b0;
eot_dma2fx3 <= 1'b0;
footer_pointer <= 0;
if (test_mode_active_tpg == 1'b1) begin
s_axis_tready <= 1'b0;
dma2fx3_valid <= 1'b1;
if (dma2fx3_ready == 1'b1) begin
dma2fx3_counter <= dma2fx3_counter + 4;
case (test_mode_tpg)
4'h1: dma2fx3_data <= ~dma2fx3_data;
4'h2: dma2fx3_data <= ~dma2fx3_data;
4'h3: dma2fx3_data <= pn9(dma2fx3_data);
4'h4: dma2fx3_data <= pn23(dma2fx3_data);
4'h7: dma2fx3_data <= dma2fx3_data + 1;
default: dma2fx3_data <= 0;
endcase
end
end else begin
dma2fx3_data <= s_axis_tdata;
if (s_axis_tlast == 1'b0) begin
s_axis_tready <= dma2fx3_ready;
if(state_dma2fx3 == IDLE) begin
footer_pointer <= 0;
dma2fx3_counter <= 0;
case (test_mode_tpg)
4'h1: dma2fx3_data_reg <= 32'haaaaaaaa;
default: dma2fx3_data_reg <= 32'hffffffff;
endcase
end
if(state_dma2fx3 == READ_DATA) begin
footer_pointer <= 4;
if (test_mode_active_tpg == 1'b1) begin
if (dma2fx3_ready == 1'b1) begin
dma2fx3_counter <= dma2fx3_counter + 4;
if (dma2fx3_counter >= buffer_size_current - 4) begin
dma2fx3_data_reg <= 32'hf00ff00f;
end else begin
s_axis_tready <= 1'b0;
end
dma2fx3_valid <= s_axis_tvalid & s_axis_tready;
if (s_axis_tvalid== 1'b1 && s_axis_tready == 1'b1) begin
case (s_axis_tkeep)
1: dma2fx3_counter <= dma2fx3_counter + 1;
3: dma2fx3_counter <= dma2fx3_counter + 2;
7: dma2fx3_counter <= dma2fx3_counter + 3;
default: dma2fx3_counter <= dma2fx3_counter + 4;
case (test_mode_tpg)
4'h1: dma2fx3_data_reg <= ~dma2fx3_data_reg;
4'h2: dma2fx3_data_reg <= ~dma2fx3_data_reg;
4'h3: dma2fx3_data_reg <= pn9(dma2fx3_data_reg);
4'h4: dma2fx3_data_reg <= pn23(dma2fx3_data_reg);
4'h7: dma2fx3_data_reg <= dma2fx3_data_reg + 1;
default: dma2fx3_data_reg <= 0;
endcase
end
end
end
ADD_FOOTER: begin
dma2fx3_valid <= ~eot_dma2fx3;
dma2fx3_eop <= 1'b0;
eot_dma2fx3 <= 1'b0;
s_axis_tready <= 1'b0;
footer_pointer <= footer_pointer + 4;
case(footer_pointer)
32'h0: dma2fx3_data <= 32'hf00ff00f;
32'h4: dma2fx3_data <= dma2fx3_counter;
32'h8: dma2fx3_data <= 32'h0;
default: dma2fx3_data <= 32'h0;
endcase
if (footer_pointer == header_size_current - 4) begin
dma2fx3_eop <= 1'b1;
eot_dma2fx3 <= 1'b1;
end else begin
dma2fx3_data_reg <= 32'hf00ff00f;
if (s_axis_tvalid== 1'b1 && s_axis_tready == 1'b1) begin
case (s_axis_tkeep)
1: dma2fx3_counter <= dma2fx3_counter + 1;
3: dma2fx3_counter <= dma2fx3_counter + 2;
7: dma2fx3_counter <= dma2fx3_counter + 3;
default: dma2fx3_counter <= dma2fx3_counter + 4;
endcase
end
end
endcase
end
if(state_dma2fx3 == ADD_FOOTER) begin
footer_pointer <= footer_pointer + 4;
case(footer_pointer)
32'h4: dma2fx3_data_reg <= dma2fx3_counter;
32'h8: dma2fx3_data_reg <= 32'h0;
default: dma2fx3_data_reg <= 32'h0;
endcase
end
end
endmodule

View File

@ -45,6 +45,7 @@ module axi_usb_fx3_if (
fifo_rdy,
pclk, //output clk 100 Mhz and 180 phase shift
reset_n,
data,
addr, //output fifo address
@ -57,11 +58,10 @@ module axi_usb_fx3_if (
epswitch_n, //output pkt end
fifo_num,
fifo_direction,
trig,
fifo_ready,
test_mode_tpm,
fx32dma_valid,
fx32dma_ready,
fx32dma_data,
@ -73,15 +73,16 @@ module axi_usb_fx3_if (
dma2fx3_data,
dma2fx3_eop);
input pclk;
input reset_n;
input dma_rdy;
input dma_wmk;
input [10:0] fifo_rdy;
input [ 3:0] fifo_rdy;
input pclk;
output [31:0] data;
output [4:0] addr;
inout [31:0] data;
output [ 1:0] addr;
output slcs_n;
output slrd_n;
@ -92,9 +93,8 @@ module axi_usb_fx3_if (
output [10:0] fifo_ready;
input [ 2:0] test_mode_tpm;
input [4:0] fifo_num;
input [ 4:0] fifo_num;
input [10:0] fifo_direction;
input trig;
output fx32dma_valid;
@ -108,183 +108,227 @@ module axi_usb_fx3_if (
input [31:0] dma2fx3_data;
input dma2fx3_eop;
// internal wires
wire fx32dma_sop;
// internal registers
wire fx32dma_valid;
reg [10:0] fifo_ready;
reg [10:0] fifo_ready;
reg internal_trig = 0;
reg trig_d = 0;
reg [31:0] internal_counter = 0;
reg [ 2:0] packet_number = 0;
reg [31:0] data_size = 0;
reg [31:0] fx32dma_data = 0;
reg [31:0] generated_data = 0;
reg fx32dma_eop;
reg [31:0] fx32dma_data = 0;
reg fx32dma_eop;
reg transaction_in_progress = 0;
reg [ 1:0] rd_oe_delay;
assign fx32dma_sop = internal_trig ;
assign fx32dma_valid = transaction_in_progress;
function [31:0] pn23;
input [31:0] din;
reg [31:0] dout;
begin
dout[31] = din[22] ^ din[17];
dout[30] = din[21] ^ din[16];
dout[29] = din[20] ^ din[15];
dout[28] = din[19] ^ din[14];
dout[27] = din[18] ^ din[13];
dout[26] = din[17] ^ din[12];
dout[25] = din[16] ^ din[11];
dout[24] = din[15] ^ din[10];
dout[23] = din[14] ^ din[ 9];
dout[22] = din[13] ^ din[ 8];
dout[21] = din[12] ^ din[ 7];
dout[20] = din[11] ^ din[ 6];
dout[19] = din[10] ^ din[ 5];
dout[18] = din[ 9] ^ din[ 4];
dout[17] = din[ 8] ^ din[ 3];
dout[16] = din[ 7] ^ din[ 2];
dout[15] = din[ 6] ^ din[ 1];
dout[14] = din[ 5] ^ din[ 0];
dout[13] = din[ 4] ^ din[22] ^ din[17];
dout[12] = din[ 3] ^ din[21] ^ din[16];
dout[11] = din[ 2] ^ din[20] ^ din[15];
dout[10] = din[ 1] ^ din[19] ^ din[14];
dout[ 9] = din[ 0] ^ din[18] ^ din[13];
dout[ 8] = din[22] ^ din[12];
dout[ 7] = din[21] ^ din[11];
dout[ 6] = din[20] ^ din[10];
dout[ 5] = din[19] ^ din[ 9];
dout[ 4] = din[18] ^ din[ 8];
dout[ 3] = din[17] ^ din[ 7];
dout[ 2] = din[16] ^ din[ 6];
dout[ 1] = din[15] ^ din[ 5];
dout[ 0] = din[14] ^ din[ 4];
pn23 = dout;
end
endfunction
reg [ 3:0] state_gpif_ii = 4'h0;
reg [ 3:0] next_state_gpif_ii = 4'h0;
function [31:0] pn9;
input [31:0] din;
reg [31:0] dout;
begin
dout[31] = din[ 8] ^ din[ 4];
dout[30] = din[ 7] ^ din[ 3];
dout[29] = din[ 6] ^ din[ 2];
dout[28] = din[ 5] ^ din[ 1];
dout[27] = din[ 4] ^ din[ 0];
dout[26] = din[ 3] ^ din[ 8] ^ din[ 4];
dout[25] = din[ 2] ^ din[ 7] ^ din[ 3];
dout[24] = din[ 1] ^ din[ 6] ^ din[ 2];
dout[23] = din[ 0] ^ din[ 5] ^ din[ 1];
dout[22] = din[ 8] ^ din[ 0];
dout[21] = din[ 7] ^ din[ 8] ^ din[ 4];
dout[20] = din[ 6] ^ din[ 7] ^ din[ 3];
dout[19] = din[ 5] ^ din[ 6] ^ din[ 2];
dout[18] = din[ 4] ^ din[ 5] ^ din[ 1];
dout[17] = din[ 3] ^ din[ 4] ^ din[ 0];
dout[16] = din[ 2] ^ din[ 3] ^ din[ 8] ^ din[ 4];
dout[15] = din[ 1] ^ din[ 2] ^ din[ 7] ^ din[ 3];
dout[14] = din[ 0] ^ din[ 1] ^ din[ 6] ^ din[ 2];
dout[13] = din[ 8] ^ din[ 0] ^ din[ 4] ^ din[ 5] ^ din[ 1];
dout[12] = din[ 7] ^ din[ 8] ^ din[ 3] ^ din[ 0];
dout[11] = din[ 6] ^ din[ 7] ^ din[ 2] ^ din[ 8] ^ din[ 4];
dout[10] = din[ 5] ^ din[ 6] ^ din[ 1] ^ din[ 7] ^ din[ 3];
dout[ 9] = din[ 4] ^ din[ 5] ^ din[ 0] ^ din[ 6] ^ din[ 2];
dout[ 8] = din[ 3] ^ din[ 8] ^ din[ 5] ^ din[ 1];
dout[ 7] = din[ 2] ^ din[ 4] ^ din[ 7] ^ din[ 0];
dout[ 6] = din[ 1] ^ din[ 3] ^ din[ 6] ^ din[ 8] ^ din[ 4];
dout[ 5] = din[ 0] ^ din[ 2] ^ din[ 5] ^ din[ 7] ^ din[ 3];
dout[ 4] = din[ 8] ^ din[ 1] ^ din[ 6] ^ din[ 2];
dout[ 3] = din[ 7] ^ din[ 0] ^ din[ 5] ^ din[ 1];
dout[ 2] = din[ 6] ^ din[ 8] ^ din[ 0];
dout[ 1] = din[5] ^ din[7] ^ din[8] ^ din[4];
dout[ 0] = din[4] ^ din[6] ^ din[7] ^ din[3];
pn9 = dout;
end
endfunction
reg current_direction;
reg current_fifo;
reg current_fifo_d1;
reg current_fifo_d2;
reg current_fifo_d3;
reg slcs_n;
reg slrd_n;
reg sloe_n;
reg [ 1:0] addr;
reg sloe_n_d1;
reg sloe_n_d2;
reg sloe_n_d3;
reg slwr_n;
reg fx32dma_valid;
reg dma2fx3_ready;
reg fx32dma_sop;
reg fx32dma_sop_d1;
reg pktend_n;
always @(posedge pclk) begin
trig_d <= trig;
fx32dma_eop <= 1'b0;
internal_trig <= trig & ~trig_d;
if (transaction_in_progress == 1'b0) begin
transaction_in_progress <= trig & ~trig_d;
end else begin
if (internal_counter >= data_size + 12) begin
transaction_in_progress = 1'b0;
fx32dma_eop <= 1'b1;
localparam IDLE = 4'b0001;
localparam READ_START = 4'b0010;
localparam READ_DATA = 4'b0100;
localparam WRITE_DATA = 4'b1000;
assign data = (state_gpif_ii == WRITE_DATA && dma2fx3_valid && current_fifo) ? {dma2fx3_data[7:0],dma2fx3_data[15:8],dma2fx3_data[23:16], dma2fx3_data[31:24]} : 32'hz;
assign epswitch_n = 1'b1;
always @(fifo_num, fifo_rdy, fifo_direction) begin
case(fifo_num)
5'h0: begin
current_direction = fifo_direction[0];
current_fifo = fifo_rdy[0];
end
5'h1: begin
current_direction = fifo_direction[1];
current_fifo = fifo_rdy[1];
end
5'h2: begin
current_direction = fifo_direction[2];
current_fifo = fifo_rdy[2];
end
5'h3: begin
current_direction = fifo_direction[3];
current_fifo = fifo_rdy[3];
end
5'h4: begin
current_direction = fifo_direction[4];
current_fifo = fifo_rdy[0];
end
5'h5: begin
current_direction = fifo_direction[5];
current_fifo = fifo_rdy[0];
end
5'h6: begin
current_direction = fifo_direction[6];
current_fifo = fifo_rdy[0];
end
5'h7: begin
current_direction = fifo_direction[7];
current_fifo = fifo_rdy[0];
end
5'h8: begin
current_direction = fifo_direction[8];
current_fifo = fifo_rdy[0];
end
5'h9: begin
current_direction = fifo_direction[9];
current_fifo = fifo_rdy[0];
end
default: begin
current_direction = 0;
current_fifo = fifo_rdy[0];
end
end
end
always @(posedge pclk) begin
if (internal_trig == 1'b1 )begin
internal_counter <= 4;
packet_number <= packet_number + 1;
end else if (transaction_in_progress == 1'b1) begin
internal_counter <= internal_counter + 4;
end else begin
internal_counter <= 0;
end
end
always @(packet_number) begin
case (packet_number)
0: data_size = 1;
1: data_size = 2;
2: data_size = 3;
3: data_size = 4;
4: data_size = 512;
5: data_size = 1024;
6: data_size = 32767;
7: data_size = 32768;
default: data_size = 16;
endcase
end
always@(internal_counter, data_size, internal_counter, generated_data) begin
case (internal_counter)
5'h0: fx32dma_data <= 32'hf00ff00f;
5'h4: fx32dma_data <= data_size;
5'h8: fx32dma_data <= 0;
5'hc: fx32dma_data <= 32'hffffffff;
default: fx32dma_data <= generated_data;
endcase
end
always @(posedge pclk) begin
if (fx32dma_sop == 1'b1) begin
if (test_mode_tpm == 3'h1) begin
generated_data <= 32'haaaaaaaa;
end else begin
generated_data <= 32'hffffffff;
end
if (reset_n == 1'b0) begin
state_gpif_ii <= IDLE;
end else begin
case(test_mode_tpm)
4'h0: generated_data <= generated_data + 32'h10;
4'h1: generated_data <= ~generated_data;
4'h2: generated_data <= ~generated_data;
4'h3: generated_data <= pn9(generated_data);
4'h4: generated_data <= pn23(generated_data);
4'h7: generated_data <= generated_data + 1;
default: generated_data <= generated_data + 32'h10;
endcase
state_gpif_ii <= next_state_gpif_ii;
end
end
// dma2fx3
assign dma2fx3_ready = 1'b1;
assign data = dma2fx3_data;
assign pktend_n = ~dma2fx3_eop;
assign slwr_n = ~dma2fx3_valid;
always @(*) begin
case(state_gpif_ii)
IDLE:
if(trig == 1'b1 && current_fifo == 1'b1) begin
if (current_direction == 0) begin
next_state_gpif_ii = READ_START;
end else begin
next_state_gpif_ii = WRITE_DATA;
end
end else begin
next_state_gpif_ii = IDLE;
end
READ_START:
if(rd_oe_delay == 2'h3) begin
next_state_gpif_ii = READ_DATA;
end else begin
next_state_gpif_ii = READ_START;
end
READ_DATA:
if (sloe_n == 1'b1) begin
next_state_gpif_ii = IDLE;
end else begin
next_state_gpif_ii = READ_DATA;
end
WRITE_DATA:
if(dma2fx3_eop == 1'b1) begin
next_state_gpif_ii = IDLE;
end else begin
next_state_gpif_ii = WRITE_DATA;
end
default: next_state_gpif_ii = IDLE;
endcase
end
always @(*) begin
case(state_gpif_ii)
IDLE: begin
slcs_n = 1'b1;
sloe_n = 1'b1;
slrd_n = 1'b1;
fx32dma_valid = 1'b0;
fx32dma_sop = 1'b0;
fx32dma_data = 32'h0;
slwr_n = 1'b1;
pktend_n = 1'b1;
dma2fx3_ready = 1'b0;
fx32dma_eop = 1'b0;
end
READ_START: begin
slcs_n = 1'b0;
sloe_n = 1'b0;
slrd_n = 1'b0;
fx32dma_valid = 1'b0;
fx32dma_sop = 1'b0;
fx32dma_data = 32'h0;
slwr_n = 1'b1;
pktend_n = 1'b1;
dma2fx3_ready = 1'b0;
fx32dma_eop = 1'b0;
end
READ_DATA: begin
slcs_n = 1'b0;
sloe_n = sloe_n_d2;
slrd_n = !current_fifo_d3;
fx32dma_valid = !sloe_n_d3;
fx32dma_sop = fx32dma_sop_d1;
fx32dma_data = {data[7:0],data[15:8],data[23:16], data[31:24]};
//fx32dma_data = data;
slwr_n = 1'b1;
pktend_n = 1'b1;
dma2fx3_ready = 1'b0;
fx32dma_eop = sloe_n_d2;
end
WRITE_DATA: begin
slcs_n = 1'b0;
sloe_n = 1'b1;
slrd_n = 1'b1;
fx32dma_valid = 1'b0;
fx32dma_sop = 1'b0;
fx32dma_data = 32'h0;
slwr_n = (state_gpif_ii == WRITE_DATA) ? (!dma2fx3_valid | !current_fifo) : 1'b1;
dma2fx3_ready = current_fifo;
pktend_n = (state_gpif_ii == WRITE_DATA ) ? !dma2fx3_eop : 1'b1;
fx32dma_eop = 1'b0;
end
default: begin
slcs_n = 1'b1;
sloe_n = 1'b1;
slrd_n = 1'b1;
fx32dma_valid = 1'b0;
fx32dma_sop = 1'b0;
fx32dma_data = 32'h0;
slwr_n = 1'b1;
pktend_n = 1'b1;
dma2fx3_ready = 1'b0;
fx32dma_eop = 1'b0;
end
endcase
end
always @(posedge pclk) begin
current_fifo_d1 <= current_fifo;
current_fifo_d2 <= current_fifo_d1;
current_fifo_d3 <= current_fifo_d2;
fifo_ready <= {7'h0,fifo_rdy};
if(state_gpif_ii == READ_DATA) begin
fx32dma_sop_d1 <= 1'b0;
end else begin
fx32dma_sop_d1 <= 1'b1;
end
sloe_n_d1 <= slrd_n;
sloe_n_d2 <= sloe_n_d1;
sloe_n_d3 <= sloe_n_d2;
addr <= fifo_num[1:0];
if(state_gpif_ii == READ_START) begin
rd_oe_delay <= rd_oe_delay + 1'b1;
end else begin
rd_oe_delay <= 2'h0;
end
end
endmodule