module_content
stringlengths
18
1.05M
module MM_to_ST_Adapter ( clk, reset, length, length_counter, address, reads_pending, start, readdata, readdatavalid, fifo_data, fifo_write, fifo_empty, fifo_sop, fifo_eop ); parameter DATA_WIDTH = 32; // 8, 16, 32, 64, 128, or 256 are valid values (if 8 is used then disable unaligned accesses and turn on full word only accesses) parameter LENGTH_WIDTH = 32; parameter ADDRESS_WIDTH = 32; parameter BYTE_ADDRESS_WIDTH = 2; // log2(DATA_WIDTH/8) parameter READS_PENDING_WIDTH = 5; parameter EMPTY_WIDTH = 2; // log2(DATA_WIDTH/8) parameter PACKET_SUPPORT = 1; // when set to 1 eop, sop, and empty will be driven, otherwise they will be grounded // only set one of these at a time parameter UNALIGNED_ACCESS_ENABLE = 1; // when set to 1 this block will support packets and starting/ending on any boundary, do not use this if DATA_WIDTH is 8 (use 'FULL_WORD_ACCESS_ONLY') parameter FULL_WORD_ACCESS_ONLY = 0; // when set to 1 this block will assume only full words are arriving (must start and stop on a word boundary). input clk; input reset; input [LENGTH_WIDTH-1:0] length; input [LENGTH_WIDTH-1:0] length_counter; input [ADDRESS_WIDTH-1:0] address; input [READS_PENDING_WIDTH-1:0] reads_pending; input start; // one cycle strobe at the start of a transfer used to capture bytes_to_transfer input [DATA_WIDTH-1:0] readdata; input readdatavalid; output wire [DATA_WIDTH-1:0] fifo_data; output wire fifo_write; output wire [EMPTY_WIDTH-1:0] fifo_empty; output wire fifo_sop; output wire fifo_eop; // internal registers and wires reg [DATA_WIDTH-1:0] readdata_d1; reg readdatavalid_d1; wire [DATA_WIDTH-1:0] data_in; // data_in will either be readdata or a pipelined copy of readdata depending on whether unaligned access support is enabled wire valid_in; // valid in will either be readdatavalid or a pipelined copy of readdatavalid depending on whether unaligned access support is enabled reg valid_in_d1; wire [DATA_WIDTH-1:0] barrelshifter_A; // shifted current read data wire [DATA_WIDTH-1:0] barrelshifter_B; reg [DATA_WIDTH-1:0] barrelshifter_B_d1; // shifted previously read data wire [DATA_WIDTH-1:0] combined_word; // bitwise OR between barrelshifter_A and barrelshifter_B (each has zero padding so that bytelanes don't overlap) wire [DATA_WIDTH-1:0] barrelshifter_input_A [0:((DATA_WIDTH/8)-1)]; // will be used to create barrelshifter_A inputs wire [DATA_WIDTH-1:0] barrelshifter_input_B [0:((DATA_WIDTH/8)-1)]; // will be used to create barrelshifter_B inputs wire extra_access_enable; reg extra_access; wire last_unaligned_fifo_write; reg first_access_seen; reg second_access_seen; wire first_access_seen_rising_edge; wire second_access_seen_rising_edge; reg [BYTE_ADDRESS_WIDTH-1:0] byte_address; reg [EMPTY_WIDTH-1:0] last_empty; // only the last word written into the FIFO can have empty bytes reg start_and_end_same_cycle; // when the amount of data to transfer is only a full word or less generate if (UNALIGNED_ACCESS_ENABLE == 1) // unaligned so using a pipelined input begin assign data_in = readdata_d1; assign valid_in = readdatavalid_d1; end else begin assign data_in = readdata; // no barrelshifters in this case so pipelining is not necessary assign valid_in = readdatavalid; end endgenerate always @ (posedge clk or posedge reset) begin if (reset) begin readdata_d1 <= 0; end else begin if (readdatavalid == 1) begin readdata_d1 <= readdata; end end end always @ (posedge clk or posedge reset) begin if (reset) begin readdatavalid_d1 <= 0; valid_in_d1 <= 0; end else begin readdatavalid_d1 <= readdatavalid; valid_in_d1 <= valid_in; // used to flush the pipeline (extra fifo write) and prolong eop for one additional clock cycle end end always @ (posedge clk or posedge reset) begin if (reset == 1) begin barrelshifter_B_d1 <= 0; end else begin if (valid_in == 1) begin barrelshifter_B_d1 <= barrelshifter_B; end end end always @ (posedge clk or posedge reset) begin if (reset) begin first_access_seen <= 0; end else begin if (start == 1) begin first_access_seen <= 0; end else if (valid_in == 1) begin first_access_seen <= 1; end end end always @ (posedge clk or posedge reset) begin if (reset) begin second_access_seen <= 0; end else begin if (start == 1) begin second_access_seen <= 0; end else if ((first_access_seen == 1) & (valid_in == 1)) begin second_access_seen <= 1; end end end always @ (posedge clk or posedge reset) begin if (reset) begin byte_address <= 0; end else if (start == 1) begin byte_address <= address[BYTE_ADDRESS_WIDTH-1:0]; end end always @ (posedge clk or posedge reset) begin if (reset) begin last_empty <= 0; end else if (start == 1) begin last_empty <= ((DATA_WIDTH/8) - length[EMPTY_WIDTH-1:0]) & {EMPTY_WIDTH{1'b1}}; // if length isn't a multiple of the word size then we'll have some empty symbols/bytes during the last fifo write end end always @ (posedge clk or posedge reset) begin if (reset) begin extra_access <= 0; end else if (start == 1) begin extra_access <= extra_access_enable; // when set the number of reads and fifo writes are equal, otherwise there will be 1 less fifo write than reads (unaligned accesses only) end end always @ (posedge clk or posedge reset) begin if (reset) begin start_and_end_same_cycle <= 0; end else if (start == 1) begin start_and_end_same_cycle <= (length <= (DATA_WIDTH/8)); end end /* These barrelshifters will take the unaligned data coming into this block and shift the byte lanes appropriately to form a single packed word. Zeros are shifted into the byte lanes that do not contain valid data for the combined word that will be buffered. This allows both barrelshifters to be logically OR'ed together to form a single packed word. Shifter A is used to shift the current read data towards the upper bytes of the combined word (since those are the upper addresses of the combined word). Shifter B after the pipeline stage called 'barrelshifter_B_d1' contains the previously read data shifted towards the lower bytes (since those are the lower addresses of the combined word). */ generate genvar input_offset; for(input_offset = 0; input_offset < (DATA_WIDTH/8); input_offset = input_offset + 1) begin: barrel_shifter_inputs assign barrelshifter_input_A[input_offset] = data_in << (8 * ((DATA_WIDTH/8) - input_offset)); assign barrelshifter_input_B[input_offset] = data_in >> (8 * input_offset); end endgenerate assign barrelshifter_A = barrelshifter_input_A[byte_address]; // upper portion of the packed word assign barrelshifter_B = barrelshifter_input_B[byte_address]; // lower portion of the packed word (will be pipelined so it will be the previous word read by the master) assign combined_word = (barrelshifter_A | barrelshifter_B_d1); // barrelshifters shift in zeros so we can just OR the words together here to create a packed word assign first_access_seen_rising_edge = (valid_in == 1) & (first_access_seen == 0); assign second_access_seen_rising_edge = ((first_access_seen == 1) & (valid_in == 1)) & (second_access_seen == 0); assign extra_access_enable = (((DATA_WIDTH/8) - length[EMPTY_WIDTH-1:0]) & {EMPTY_WIDTH{1'b1}}) >= address[BYTE_ADDRESS_WIDTH-1:0]; // enable when empty >= byte address /* Need to keep track of the last write to the FIFO so that we can fire EOP correctly as well as flush the pipeline when unaligned accesses is enabled. The first read is filtered since it is considered to be only a partial word to be written into the FIFO but there are cases when there is extra data that is buffered in 'barrelshifter_B_d1' but the transfer is done so we need to issue an additional write. In general for every 'N' Avalon-MM reads 'N-1' writes to the FIFO will occur unless there is data still buffered in which one more write to the FIFO will immediately follow the last read. */ assign last_unaligned_fifo_write = (reads_pending == 0) & (length_counter == 0) & ( ((extra_access == 0) & (valid_in == 1)) | // don't need a pipeline flush ((extra_access == 1) & (valid_in_d1 == 1) & (valid_in == 0)) ); // last write to flush the pipeline (need to make sure valid_in isn't asserted to make sure the last data is indeed coming since valid_in is pipelined) // This block should be optimized down depending on the packet support or access type settings. In the case where packet support is off // and only full accesses are used this block should become zero logic elements. generate if (PACKET_SUPPORT == 1) begin if (UNALIGNED_ACCESS_ENABLE == 1) begin assign fifo_sop = (second_access_seen_rising_edge == 1) | ((start_and_end_same_cycle == 1) & (last_unaligned_fifo_write == 1)); assign fifo_eop = last_unaligned_fifo_write; assign fifo_empty = (fifo_eop == 1)? last_empty : 0; // always full accesses until the last word end else begin assign fifo_sop = first_access_seen_rising_edge; assign fifo_eop = (length_counter == 0) & (reads_pending == 1) & (valid_in == 1); // not using last_unaligned_fifo_write since it's pipelined and when unaligned accesses are disabled the input is not pipelined if (FULL_WORD_ACCESS_ONLY == 1) begin assign fifo_empty = 0; // full accesses so no empty symbols throughout the transfer end else begin assign fifo_empty = (fifo_eop == 1)? last_empty : 0; // always full accesses until the last word end end end else begin assign fifo_eop = 0; assign fifo_sop = 0; assign fifo_empty = 0; end if (UNALIGNED_ACCESS_ENABLE == 1) begin assign fifo_data = combined_word; assign fifo_write = (first_access_seen == 1) & ((valid_in == 1) | (last_unaligned_fifo_write == 1)); // last_unaligned_fifo_write will inject an extra pulse right after the last read occurs when flushing of the pipeline is needed end else begin // don't need to pipeline since the data will not go through the barrel shifters assign fifo_data = data_in; // don't need to barrelshift when aligned accesses are used assign fifo_write = valid_in; // the number of writes to the fifo needs to always equal the number of reads from memory end endgenerate endmodule
module acl_iface_ll_fifo(clk, reset, data_in, write, data_out, read, empty, full); /* Parameters */ parameter WIDTH = 32; parameter DEPTH = 32; /* Ports */ input clk; input reset; input [WIDTH-1:0] data_in; input write; output [WIDTH-1:0] data_out; input read; output empty; output full; /* Architecture */ // One-hot write-pointer bit (indicates next position to write at), // last bit indicates the FIFO is full reg [DEPTH:0] wptr; // Replicated copy of the stall / valid logic reg [DEPTH:0] wptr_copy /* synthesis dont_merge */; // FIFO data registers reg [DEPTH-1:0][WIDTH-1:0] data; // Write pointer updates: wire wptr_hold; // Hold the value wire wptr_dir; // Direction to shift // Data register updates: wire [DEPTH-1:0] data_hold; // Hold the value wire [DEPTH-1:0] data_new; // Write the new data value in // Write location is constant unless the occupancy changes assign wptr_hold = !(read ^ write); assign wptr_dir = read; // Hold the value unless we are reading, or writing to this // location genvar i; generate for(i = 0; i < DEPTH; i++) begin : data_mux assign data_hold[i] = !(read | (write & wptr[i])); assign data_new[i] = !read | wptr[i+1]; end endgenerate // The data registers generate for(i = 0; i < DEPTH-1; i++) begin : data_reg always@(posedge clk or posedge reset) begin if(reset == 1'b1) data[i] <= {WIDTH{1'b0}}; else data[i] <= data_hold[i] ? data[i] : data_new[i] ? data_in : data[i+1]; end end endgenerate always@(posedge clk or posedge reset) begin if(reset == 1'b1) data[DEPTH-1] <= {WIDTH{1'b0}}; else data[DEPTH-1] <= data_hold[DEPTH-1] ? data[DEPTH-1] : data_in; end // The write pointer always@(posedge clk or posedge reset) begin if(reset == 1'b1) begin wptr <= {{DEPTH{1'b0}}, 1'b1}; wptr_copy <= {{DEPTH{1'b0}}, 1'b1}; end else begin wptr <= wptr_hold ? wptr : wptr_dir ? {1'b0, wptr[DEPTH:1]} : {wptr[DEPTH-1:0], 1'b0}; wptr_copy <= wptr_hold ? wptr_copy : wptr_dir ? {1'b0, wptr_copy[DEPTH:1]} : {wptr_copy[DEPTH-1:0], 1'b0}; end end // Outputs assign empty = wptr_copy[0]; assign full = wptr_copy[DEPTH]; assign data_out = data[0]; endmodule
module snoop_adapter ( clk, reset, kernel_clk, kernel_reset, address, read, readdata, readdatavalid, write, writedata, burstcount, byteenable, waitrequest, burstbegin, snoop_data, snoop_valid, snoop_ready, export_address, export_read, export_readdata, export_readdatavalid, export_write, export_writedata, export_burstcount, export_burstbegin, export_byteenable, export_waitrequest ); parameter NUM_BYTES = 4; parameter BYTE_ADDRESS_WIDTH = 32; parameter WORD_ADDRESS_WIDTH = 32; parameter BURSTCOUNT_WIDTH = 1; localparam DATA_WIDTH = NUM_BYTES * 8; localparam ADDRESS_SHIFT = BYTE_ADDRESS_WIDTH - WORD_ADDRESS_WIDTH; localparam DEVICE_BLOCKRAM_MIN_DEPTH = 256; //Stratix IV M9Ks localparam FIFO_SIZE = DEVICE_BLOCKRAM_MIN_DEPTH; localparam LOG2_FIFO_SIZE =$clog2(FIFO_SIZE); input clk; input reset; input kernel_clk; input kernel_reset; input [WORD_ADDRESS_WIDTH-1:0] address; input read; output [DATA_WIDTH-1:0] readdata; output readdatavalid; input write; input [DATA_WIDTH-1:0] writedata; input [BURSTCOUNT_WIDTH-1:0] burstcount; input burstbegin; input [NUM_BYTES-1:0] byteenable; output waitrequest; output [1+WORD_ADDRESS_WIDTH+BURSTCOUNT_WIDTH-1:0] snoop_data; output snoop_valid; input snoop_ready; output [BYTE_ADDRESS_WIDTH-1:0] export_address; output export_read; input [DATA_WIDTH-1:0] export_readdata; input export_readdatavalid; output export_write; output [DATA_WIDTH-1:0] export_writedata; output [BURSTCOUNT_WIDTH-1:0] export_burstcount; output export_burstbegin; output [NUM_BYTES-1:0] export_byteenable; input export_waitrequest; reg snoop_overflow; // Register snoop data first reg [WORD_ADDRESS_WIDTH+BURSTCOUNT_WIDTH-1:0] snoop_data_r; //word-address reg snoop_valid_r; wire snoop_fifo_empty; wire overflow; wire [ LOG2_FIFO_SIZE-1 : 0 ] rdusedw; always@(posedge clk) begin snoop_data_r<={address,export_burstcount}; snoop_valid_r<=export_write && !export_waitrequest; end // 1) Fifo to store snooped accesses from host dcfifo dcfifo_component ( .wrclk (clk), .data (snoop_data_r), .wrreq (snoop_valid_r), .rdclk (kernel_clk), .rdreq (snoop_valid & snoop_ready), .q (snoop_data[WORD_ADDRESS_WIDTH+BURSTCOUNT_WIDTH-1:0]), .rdempty (snoop_fifo_empty), .rdfull (overflow), .aclr (1'b0), .rdusedw (rdusedw), .wrempty (), .wrfull (), .wrusedw ()); defparam dcfifo_component.intended_device_family = "Stratix IV", dcfifo_component.lpm_numwords = FIFO_SIZE, dcfifo_component.lpm_showahead = "ON", dcfifo_component.lpm_type = "dcfifo", dcfifo_component.lpm_width = WORD_ADDRESS_WIDTH+BURSTCOUNT_WIDTH, dcfifo_component.lpm_widthu = LOG2_FIFO_SIZE, dcfifo_component.overflow_checking = "ON", dcfifo_component.rdsync_delaypipe = 4, dcfifo_component.underflow_checking = "ON", dcfifo_component.use_eab = "ON", dcfifo_component.wrsync_delaypipe = 4; assign snoop_valid=~snoop_fifo_empty; always@(posedge kernel_clk) snoop_overflow = ( rdusedw >= ( FIFO_SIZE - 12 ) ); // Overflow piggy backed onto MSB of stream. Since overflow guarantees // there is something to be read out, we can be sure that this will reach // the cache. assign snoop_data[WORD_ADDRESS_WIDTH+BURSTCOUNT_WIDTH] = snoop_overflow; assign export_address = address << ADDRESS_SHIFT; assign export_read = read; assign readdata = export_readdata; assign readdatavalid = export_readdatavalid; assign export_write = write; assign export_writedata = writedata; assign export_burstcount = burstcount; assign export_burstbegin = burstbegin; assign export_byteenable = byteenable; assign waitrequest = export_waitrequest; endmodule
module generic_baseblocks_v2_1_0_comparator_sel_mask # ( parameter C_FAMILY = "virtex6", // FPGA Family. Current version: virtex6 or spartan6. parameter integer C_DATA_WIDTH = 4 // Data width for comparator. ) ( input wire CIN, input wire S, input wire [C_DATA_WIDTH-1:0] A, input wire [C_DATA_WIDTH-1:0] B, input wire [C_DATA_WIDTH-1:0] M, input wire [C_DATA_WIDTH-1:0] V, output wire COUT ); ///////////////////////////////////////////////////////////////////////////// // Variables for generating parameter controlled instances. ///////////////////////////////////////////////////////////////////////////// // Generate variable for bit vector. genvar lut_cnt; ///////////////////////////////////////////////////////////////////////////// // Local params ///////////////////////////////////////////////////////////////////////////// // Bits per LUT for this architecture. localparam integer C_BITS_PER_LUT = 1; // Constants for packing levels. localparam integer C_NUM_LUT = ( C_DATA_WIDTH + C_BITS_PER_LUT - 1 ) / C_BITS_PER_LUT; // localparam integer C_FIX_DATA_WIDTH = ( C_NUM_LUT * C_BITS_PER_LUT > C_DATA_WIDTH ) ? C_NUM_LUT * C_BITS_PER_LUT : C_DATA_WIDTH; ///////////////////////////////////////////////////////////////////////////// // Functions ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Internal signals ///////////////////////////////////////////////////////////////////////////// wire [C_FIX_DATA_WIDTH-1:0] a_local; wire [C_FIX_DATA_WIDTH-1:0] b_local; wire [C_FIX_DATA_WIDTH-1:0] m_local; wire [C_FIX_DATA_WIDTH-1:0] v_local; wire [C_NUM_LUT-1:0] sel; wire [C_NUM_LUT:0] carry_local; ///////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////// generate // Assign input to local vectors. assign carry_local[0] = CIN; // Extend input data to fit. if ( C_NUM_LUT * C_BITS_PER_LUT > C_DATA_WIDTH ) begin : USE_EXTENDED_DATA assign a_local = {A, {C_NUM_LUT * C_BITS_PER_LUT - C_DATA_WIDTH{1'b0}}}; assign b_local = {B, {C_NUM_LUT * C_BITS_PER_LUT - C_DATA_WIDTH{1'b0}}}; assign m_local = {M, {C_NUM_LUT * C_BITS_PER_LUT - C_DATA_WIDTH{1'b0}}}; assign v_local = {V, {C_NUM_LUT * C_BITS_PER_LUT - C_DATA_WIDTH{1'b0}}}; end else begin : NO_EXTENDED_DATA assign a_local = A; assign b_local = B; assign m_local = M; assign v_local = V; end // Instantiate one generic_baseblocks_v2_1_0_carry and per level. for (lut_cnt = 0; lut_cnt < C_NUM_LUT ; lut_cnt = lut_cnt + 1) begin : LUT_LEVEL // Create the local select signal assign sel[lut_cnt] = ( ( ( a_local[lut_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] & m_local[lut_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] ) == ( v_local[lut_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] & m_local[lut_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] ) ) & ( S == 1'b0 ) ) | ( ( ( b_local[lut_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] & m_local[lut_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] ) == ( v_local[lut_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] & m_local[lut_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] ) ) & ( S == 1'b1 ) ); // Instantiate each LUT level. generic_baseblocks_v2_1_0_carry_and # ( .C_FAMILY(C_FAMILY) ) compare_inst ( .COUT (carry_local[lut_cnt+1]), .CIN (carry_local[lut_cnt]), .S (sel[lut_cnt]) ); end // end for lut_cnt // Assign output from local vector. assign COUT = carry_local[C_NUM_LUT]; endgenerate endmodule
module generic_baseblocks_v2_1_0_comparator_sel_mask # ( parameter C_FAMILY = "virtex6", // FPGA Family. Current version: virtex6 or spartan6. parameter integer C_DATA_WIDTH = 4 // Data width for comparator. ) ( input wire CIN, input wire S, input wire [C_DATA_WIDTH-1:0] A, input wire [C_DATA_WIDTH-1:0] B, input wire [C_DATA_WIDTH-1:0] M, input wire [C_DATA_WIDTH-1:0] V, output wire COUT ); ///////////////////////////////////////////////////////////////////////////// // Variables for generating parameter controlled instances. ///////////////////////////////////////////////////////////////////////////// // Generate variable for bit vector. genvar lut_cnt; ///////////////////////////////////////////////////////////////////////////// // Local params ///////////////////////////////////////////////////////////////////////////// // Bits per LUT for this architecture. localparam integer C_BITS_PER_LUT = 1; // Constants for packing levels. localparam integer C_NUM_LUT = ( C_DATA_WIDTH + C_BITS_PER_LUT - 1 ) / C_BITS_PER_LUT; // localparam integer C_FIX_DATA_WIDTH = ( C_NUM_LUT * C_BITS_PER_LUT > C_DATA_WIDTH ) ? C_NUM_LUT * C_BITS_PER_LUT : C_DATA_WIDTH; ///////////////////////////////////////////////////////////////////////////// // Functions ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Internal signals ///////////////////////////////////////////////////////////////////////////// wire [C_FIX_DATA_WIDTH-1:0] a_local; wire [C_FIX_DATA_WIDTH-1:0] b_local; wire [C_FIX_DATA_WIDTH-1:0] m_local; wire [C_FIX_DATA_WIDTH-1:0] v_local; wire [C_NUM_LUT-1:0] sel; wire [C_NUM_LUT:0] carry_local; ///////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////// generate // Assign input to local vectors. assign carry_local[0] = CIN; // Extend input data to fit. if ( C_NUM_LUT * C_BITS_PER_LUT > C_DATA_WIDTH ) begin : USE_EXTENDED_DATA assign a_local = {A, {C_NUM_LUT * C_BITS_PER_LUT - C_DATA_WIDTH{1'b0}}}; assign b_local = {B, {C_NUM_LUT * C_BITS_PER_LUT - C_DATA_WIDTH{1'b0}}}; assign m_local = {M, {C_NUM_LUT * C_BITS_PER_LUT - C_DATA_WIDTH{1'b0}}}; assign v_local = {V, {C_NUM_LUT * C_BITS_PER_LUT - C_DATA_WIDTH{1'b0}}}; end else begin : NO_EXTENDED_DATA assign a_local = A; assign b_local = B; assign m_local = M; assign v_local = V; end // Instantiate one generic_baseblocks_v2_1_0_carry and per level. for (lut_cnt = 0; lut_cnt < C_NUM_LUT ; lut_cnt = lut_cnt + 1) begin : LUT_LEVEL // Create the local select signal assign sel[lut_cnt] = ( ( ( a_local[lut_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] & m_local[lut_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] ) == ( v_local[lut_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] & m_local[lut_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] ) ) & ( S == 1'b0 ) ) | ( ( ( b_local[lut_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] & m_local[lut_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] ) == ( v_local[lut_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] & m_local[lut_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] ) ) & ( S == 1'b1 ) ); // Instantiate each LUT level. generic_baseblocks_v2_1_0_carry_and # ( .C_FAMILY(C_FAMILY) ) compare_inst ( .COUT (carry_local[lut_cnt+1]), .CIN (carry_local[lut_cnt]), .S (sel[lut_cnt]) ); end // end for lut_cnt // Assign output from local vector. assign COUT = carry_local[C_NUM_LUT]; endgenerate endmodule
module generic_baseblocks_v2_1_0_comparator_mask # ( parameter C_FAMILY = "virtex6", // FPGA Family. Current version: virtex6 or spartan6. parameter integer C_DATA_WIDTH = 4 // Data width for comparator. ) ( input wire CIN, input wire [C_DATA_WIDTH-1:0] A, input wire [C_DATA_WIDTH-1:0] B, input wire [C_DATA_WIDTH-1:0] M, output wire COUT ); ///////////////////////////////////////////////////////////////////////////// // Variables for generating parameter controlled instances. ///////////////////////////////////////////////////////////////////////////// // Generate variable for bit vector. genvar lut_cnt; ///////////////////////////////////////////////////////////////////////////// // Local params ///////////////////////////////////////////////////////////////////////////// // Bits per LUT for this architecture. localparam integer C_BITS_PER_LUT = 2; // Constants for packing levels. localparam integer C_NUM_LUT = ( C_DATA_WIDTH + C_BITS_PER_LUT - 1 ) / C_BITS_PER_LUT; // localparam integer C_FIX_DATA_WIDTH = ( C_NUM_LUT * C_BITS_PER_LUT > C_DATA_WIDTH ) ? C_NUM_LUT * C_BITS_PER_LUT : C_DATA_WIDTH; ///////////////////////////////////////////////////////////////////////////// // Functions ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Internal signals ///////////////////////////////////////////////////////////////////////////// wire [C_FIX_DATA_WIDTH-1:0] a_local; wire [C_FIX_DATA_WIDTH-1:0] b_local; wire [C_FIX_DATA_WIDTH-1:0] m_local; wire [C_NUM_LUT-1:0] sel; wire [C_NUM_LUT:0] carry_local; ///////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////// generate // Assign input to local vectors. assign carry_local[0] = CIN; // Extend input data to fit. if ( C_NUM_LUT * C_BITS_PER_LUT > C_DATA_WIDTH ) begin : USE_EXTENDED_DATA assign a_local = {A, {C_NUM_LUT * C_BITS_PER_LUT - C_DATA_WIDTH{1'b0}}}; assign b_local = {B, {C_NUM_LUT * C_BITS_PER_LUT - C_DATA_WIDTH{1'b0}}}; assign m_local = {M, {C_NUM_LUT * C_BITS_PER_LUT - C_DATA_WIDTH{1'b0}}}; end else begin : NO_EXTENDED_DATA assign a_local = A; assign b_local = B; assign m_local = M; end // Instantiate one generic_baseblocks_v2_1_0_carry and per level. for (lut_cnt = 0; lut_cnt < C_NUM_LUT ; lut_cnt = lut_cnt + 1) begin : LUT_LEVEL // Create the local select signal assign sel[lut_cnt] = ( ( a_local[lut_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] & m_local[lut_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] ) == ( b_local[lut_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] & m_local[lut_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] ) ); // Instantiate each LUT level. generic_baseblocks_v2_1_0_carry_and # ( .C_FAMILY(C_FAMILY) ) compare_inst ( .COUT (carry_local[lut_cnt+1]), .CIN (carry_local[lut_cnt]), .S (sel[lut_cnt]) ); end // end for lut_cnt // Assign output from local vector. assign COUT = carry_local[C_NUM_LUT]; endgenerate endmodule
module generic_baseblocks_v2_1_0_comparator_sel # ( parameter C_FAMILY = "virtex6", // FPGA Family. Current version: virtex6 or spartan6. parameter integer C_DATA_WIDTH = 4 // Data width for comparator. ) ( input wire CIN, input wire S, input wire [C_DATA_WIDTH-1:0] A, input wire [C_DATA_WIDTH-1:0] B, input wire [C_DATA_WIDTH-1:0] V, output wire COUT ); ///////////////////////////////////////////////////////////////////////////// // Variables for generating parameter controlled instances. ///////////////////////////////////////////////////////////////////////////// // Generate variable for bit vector. genvar bit_cnt; ///////////////////////////////////////////////////////////////////////////// // Local params ///////////////////////////////////////////////////////////////////////////// // Bits per LUT for this architecture. localparam integer C_BITS_PER_LUT = 1; // Constants for packing levels. localparam integer C_NUM_LUT = ( C_DATA_WIDTH + C_BITS_PER_LUT - 1 ) / C_BITS_PER_LUT; // localparam integer C_FIX_DATA_WIDTH = ( C_NUM_LUT * C_BITS_PER_LUT > C_DATA_WIDTH ) ? C_NUM_LUT * C_BITS_PER_LUT : C_DATA_WIDTH; ///////////////////////////////////////////////////////////////////////////// // Functions ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Internal signals ///////////////////////////////////////////////////////////////////////////// wire [C_FIX_DATA_WIDTH-1:0] a_local; wire [C_FIX_DATA_WIDTH-1:0] b_local; wire [C_FIX_DATA_WIDTH-1:0] v_local; wire [C_NUM_LUT-1:0] sel; wire [C_NUM_LUT:0] carry_local; ///////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////// generate // Assign input to local vectors. assign carry_local[0] = CIN; // Extend input data to fit. if ( C_NUM_LUT * C_BITS_PER_LUT > C_DATA_WIDTH ) begin : USE_EXTENDED_DATA assign a_local = {A, {C_NUM_LUT * C_BITS_PER_LUT - C_DATA_WIDTH{1'b0}}}; assign b_local = {B, {C_NUM_LUT * C_BITS_PER_LUT - C_DATA_WIDTH{1'b0}}}; assign v_local = {V, {C_NUM_LUT * C_BITS_PER_LUT - C_DATA_WIDTH{1'b0}}}; end else begin : NO_EXTENDED_DATA assign a_local = A; assign b_local = B; assign v_local = V; end // Instantiate one generic_baseblocks_v2_1_0_carry and per level. for (bit_cnt = 0; bit_cnt < C_NUM_LUT ; bit_cnt = bit_cnt + 1) begin : LUT_LEVEL // Create the local select signal assign sel[bit_cnt] = ( ( a_local[bit_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] == v_local[bit_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] ) & ( S == 1'b0 ) ) | ( ( b_local[bit_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] == v_local[bit_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] ) & ( S == 1'b1 ) ); // Instantiate each LUT level. generic_baseblocks_v2_1_0_carry_and # ( .C_FAMILY(C_FAMILY) ) compare_inst ( .COUT (carry_local[bit_cnt+1]), .CIN (carry_local[bit_cnt]), .S (sel[bit_cnt]) ); end // end for bit_cnt // Assign output from local vector. assign COUT = carry_local[C_NUM_LUT]; endgenerate endmodule
module generic_baseblocks_v2_1_0_comparator_sel # ( parameter C_FAMILY = "virtex6", // FPGA Family. Current version: virtex6 or spartan6. parameter integer C_DATA_WIDTH = 4 // Data width for comparator. ) ( input wire CIN, input wire S, input wire [C_DATA_WIDTH-1:0] A, input wire [C_DATA_WIDTH-1:0] B, input wire [C_DATA_WIDTH-1:0] V, output wire COUT ); ///////////////////////////////////////////////////////////////////////////// // Variables for generating parameter controlled instances. ///////////////////////////////////////////////////////////////////////////// // Generate variable for bit vector. genvar bit_cnt; ///////////////////////////////////////////////////////////////////////////// // Local params ///////////////////////////////////////////////////////////////////////////// // Bits per LUT for this architecture. localparam integer C_BITS_PER_LUT = 1; // Constants for packing levels. localparam integer C_NUM_LUT = ( C_DATA_WIDTH + C_BITS_PER_LUT - 1 ) / C_BITS_PER_LUT; // localparam integer C_FIX_DATA_WIDTH = ( C_NUM_LUT * C_BITS_PER_LUT > C_DATA_WIDTH ) ? C_NUM_LUT * C_BITS_PER_LUT : C_DATA_WIDTH; ///////////////////////////////////////////////////////////////////////////// // Functions ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Internal signals ///////////////////////////////////////////////////////////////////////////// wire [C_FIX_DATA_WIDTH-1:0] a_local; wire [C_FIX_DATA_WIDTH-1:0] b_local; wire [C_FIX_DATA_WIDTH-1:0] v_local; wire [C_NUM_LUT-1:0] sel; wire [C_NUM_LUT:0] carry_local; ///////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////// generate // Assign input to local vectors. assign carry_local[0] = CIN; // Extend input data to fit. if ( C_NUM_LUT * C_BITS_PER_LUT > C_DATA_WIDTH ) begin : USE_EXTENDED_DATA assign a_local = {A, {C_NUM_LUT * C_BITS_PER_LUT - C_DATA_WIDTH{1'b0}}}; assign b_local = {B, {C_NUM_LUT * C_BITS_PER_LUT - C_DATA_WIDTH{1'b0}}}; assign v_local = {V, {C_NUM_LUT * C_BITS_PER_LUT - C_DATA_WIDTH{1'b0}}}; end else begin : NO_EXTENDED_DATA assign a_local = A; assign b_local = B; assign v_local = V; end // Instantiate one generic_baseblocks_v2_1_0_carry and per level. for (bit_cnt = 0; bit_cnt < C_NUM_LUT ; bit_cnt = bit_cnt + 1) begin : LUT_LEVEL // Create the local select signal assign sel[bit_cnt] = ( ( a_local[bit_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] == v_local[bit_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] ) & ( S == 1'b0 ) ) | ( ( b_local[bit_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] == v_local[bit_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] ) & ( S == 1'b1 ) ); // Instantiate each LUT level. generic_baseblocks_v2_1_0_carry_and # ( .C_FAMILY(C_FAMILY) ) compare_inst ( .COUT (carry_local[bit_cnt+1]), .CIN (carry_local[bit_cnt]), .S (sel[bit_cnt]) ); end // end for bit_cnt // Assign output from local vector. assign COUT = carry_local[C_NUM_LUT]; endgenerate endmodule
module generic_baseblocks_v2_1_0_comparator_sel # ( parameter C_FAMILY = "virtex6", // FPGA Family. Current version: virtex6 or spartan6. parameter integer C_DATA_WIDTH = 4 // Data width for comparator. ) ( input wire CIN, input wire S, input wire [C_DATA_WIDTH-1:0] A, input wire [C_DATA_WIDTH-1:0] B, input wire [C_DATA_WIDTH-1:0] V, output wire COUT ); ///////////////////////////////////////////////////////////////////////////// // Variables for generating parameter controlled instances. ///////////////////////////////////////////////////////////////////////////// // Generate variable for bit vector. genvar bit_cnt; ///////////////////////////////////////////////////////////////////////////// // Local params ///////////////////////////////////////////////////////////////////////////// // Bits per LUT for this architecture. localparam integer C_BITS_PER_LUT = 1; // Constants for packing levels. localparam integer C_NUM_LUT = ( C_DATA_WIDTH + C_BITS_PER_LUT - 1 ) / C_BITS_PER_LUT; // localparam integer C_FIX_DATA_WIDTH = ( C_NUM_LUT * C_BITS_PER_LUT > C_DATA_WIDTH ) ? C_NUM_LUT * C_BITS_PER_LUT : C_DATA_WIDTH; ///////////////////////////////////////////////////////////////////////////// // Functions ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Internal signals ///////////////////////////////////////////////////////////////////////////// wire [C_FIX_DATA_WIDTH-1:0] a_local; wire [C_FIX_DATA_WIDTH-1:0] b_local; wire [C_FIX_DATA_WIDTH-1:0] v_local; wire [C_NUM_LUT-1:0] sel; wire [C_NUM_LUT:0] carry_local; ///////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////// generate // Assign input to local vectors. assign carry_local[0] = CIN; // Extend input data to fit. if ( C_NUM_LUT * C_BITS_PER_LUT > C_DATA_WIDTH ) begin : USE_EXTENDED_DATA assign a_local = {A, {C_NUM_LUT * C_BITS_PER_LUT - C_DATA_WIDTH{1'b0}}}; assign b_local = {B, {C_NUM_LUT * C_BITS_PER_LUT - C_DATA_WIDTH{1'b0}}}; assign v_local = {V, {C_NUM_LUT * C_BITS_PER_LUT - C_DATA_WIDTH{1'b0}}}; end else begin : NO_EXTENDED_DATA assign a_local = A; assign b_local = B; assign v_local = V; end // Instantiate one generic_baseblocks_v2_1_0_carry and per level. for (bit_cnt = 0; bit_cnt < C_NUM_LUT ; bit_cnt = bit_cnt + 1) begin : LUT_LEVEL // Create the local select signal assign sel[bit_cnt] = ( ( a_local[bit_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] == v_local[bit_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] ) & ( S == 1'b0 ) ) | ( ( b_local[bit_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] == v_local[bit_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] ) & ( S == 1'b1 ) ); // Instantiate each LUT level. generic_baseblocks_v2_1_0_carry_and # ( .C_FAMILY(C_FAMILY) ) compare_inst ( .COUT (carry_local[bit_cnt+1]), .CIN (carry_local[bit_cnt]), .S (sel[bit_cnt]) ); end // end for bit_cnt // Assign output from local vector. assign COUT = carry_local[C_NUM_LUT]; endgenerate endmodule
module uses it .write_in (write_in), .byteenable_in (byteenable_in), .waitrequest_out (waitrequest_out), .byteenable_out (byteenable_out), .waitrequest_in (waitrequest_in) ); end else if (BYTEENABLE_WIDTH == 4) begin thirty_two_bit_byteenable_FSM the_thirty_two_bit_byteenable_FSM( .clk (clk), .reset (reset), .write_in (write_in), .byteenable_in (byteenable_in), .waitrequest_out (waitrequest_out), .byteenable_out (byteenable_out), .waitrequest_in (waitrequest_in) ); end else if (BYTEENABLE_WIDTH == 8) begin sixty_four_bit_byteenable_FSM the_sixty_four_bit_byteenable_FSM( .clk (clk), .reset (reset), .write_in (write_in), .byteenable_in (byteenable_in), .waitrequest_out (waitrequest_out), .byteenable_out (byteenable_out), .waitrequest_in (waitrequest_in) ); end else if (BYTEENABLE_WIDTH == 16) begin one_hundred_twenty_eight_bit_byteenable_FSM the_one_hundred_twenty_eight_bit_byteenable_FSM( .clk (clk), .reset (reset), .write_in (write_in), .byteenable_in (byteenable_in), .waitrequest_out (waitrequest_out), .byteenable_out (byteenable_out), .waitrequest_in (waitrequest_in) ); end else if (BYTEENABLE_WIDTH == 32) begin two_hundred_fifty_six_bit_byteenable_FSM the_two_hundred_fifty_six_bit_byteenable_FSM( .clk (clk), .reset (reset), .write_in (write_in), .byteenable_in (byteenable_in), .waitrequest_out (waitrequest_out), .byteenable_out (byteenable_out), .waitrequest_in (waitrequest_in) ); end else if (BYTEENABLE_WIDTH == 64) begin five_hundred_twelve_bit_byteenable_FSM the_five_hundred_twelve_bit_byteenable_FSM ( .clk (clk), .reset (reset), .write_in (write_in), .byteenable_in (byteenable_in), .waitrequest_out (waitrequest_out), .byteenable_out (byteenable_out), .waitrequest_in (waitrequest_in) ); end else if (BYTEENABLE_WIDTH == 128) begin one_thousand_twenty_four_byteenable_FSM the_one_thousand_twenty_four_byteenable_FSM ( .clk (clk), .reset (reset), .write_in (write_in), .byteenable_in (byteenable_in), .waitrequest_out (waitrequest_out), .byteenable_out (byteenable_out), .waitrequest_in (waitrequest_in) ); end endgenerate endmodule
module one_thousand_twenty_four_byteenable_FSM ( clk, reset, write_in, byteenable_in, waitrequest_out, byteenable_out, waitrequest_in ); input clk; input reset; input write_in; input [127:0] byteenable_in; output wire waitrequest_out; output wire [127:0] byteenable_out; input waitrequest_in; // internal statemachine signals wire partial_lower_half_transfer; wire full_lower_half_transfer; wire partial_upper_half_transfer; wire full_upper_half_transfer; wire full_word_transfer; reg state_bit; wire transfer_done; wire advance_to_next_state; wire lower_enable; wire upper_enable; wire lower_stall; wire upper_stall; wire two_stage_transfer; always @ (posedge clk or posedge reset) begin if (reset) begin state_bit <= 0; end else begin if (transfer_done == 1) begin state_bit <= 0; end else if (advance_to_next_state == 1) begin state_bit <= 1; end end end assign partial_lower_half_transfer = (byteenable_in[63:0] != 0); assign full_lower_half_transfer = (byteenable_in[63:0] == 64'hFFFFFFFFFFFFFFFF); assign partial_upper_half_transfer = (byteenable_in[127:64] != 0); assign full_upper_half_transfer = (byteenable_in[127:64] == 64'hFFFFFFFFFFFFFFFF); assign full_word_transfer = (full_lower_half_transfer == 1) & (full_upper_half_transfer == 1); assign two_stage_transfer = (full_word_transfer == 0) & (partial_lower_half_transfer == 1) & (partial_upper_half_transfer == 1); assign advance_to_next_state = (two_stage_transfer == 1) & (lower_stall == 0) & (write_in == 1) & (state_bit == 0) & (waitrequest_in == 0); // partial lower half transfer completed and there are bytes in the upper half that need to go out still assign transfer_done = ((full_word_transfer == 1) & (waitrequest_in == 0) & (write_in == 1)) | // full word transfer complete ((two_stage_transfer == 0) & (lower_stall == 0) & (upper_stall == 0) & (write_in == 1) & (waitrequest_in == 0)) | // partial upper or lower half transfer complete ((two_stage_transfer == 1) & (state_bit == 1) & (upper_stall == 0) & (write_in == 1) & (waitrequest_in == 0)); // partial upper and lower half transfers complete assign lower_enable = ((write_in == 1) & (full_word_transfer == 1)) | // full word transfer ((write_in == 1) & (two_stage_transfer == 0) & (partial_lower_half_transfer == 1)) | // only a partial lower half transfer ((write_in == 1) & (two_stage_transfer == 1) & (partial_lower_half_transfer == 1) & (state_bit == 0)); // partial lower half transfer (to be followed by an upper half transfer) assign upper_enable = ((write_in == 1) & (full_word_transfer == 1)) | // full word transfer ((write_in == 1) & (two_stage_transfer == 0) & (partial_upper_half_transfer == 1)) | // only a partial upper half transfer ((write_in == 1) & (two_stage_transfer == 1) & (partial_upper_half_transfer == 1) & (state_bit == 1)); // partial upper half transfer (after the lower half transfer) five_hundred_twelve_bit_byteenable_FSM lower_five_hundred_twelve_bit_byteenable_FSM ( .clk (clk), .reset (reset), .write_in (lower_enable), .byteenable_in (byteenable_in[63:0]), .waitrequest_out (lower_stall), .byteenable_out (byteenable_out[63:0]), .waitrequest_in (waitrequest_in) ); five_hundred_twelve_bit_byteenable_FSM upper_five_hundred_twelve_bit_byteenable_FSM ( .clk (clk), .reset (reset), .write_in (upper_enable), .byteenable_in (byteenable_in[127:64]), .waitrequest_out (upper_stall), .byteenable_out (byteenable_out[127:64]), .waitrequest_in (waitrequest_in) ); assign waitrequest_out = (waitrequest_in == 1) | ((transfer_done == 0) & (write_in == 1)); endmodule
module five_hundred_twelve_bit_byteenable_FSM ( clk, reset, write_in, byteenable_in, waitrequest_out, byteenable_out, waitrequest_in ); input clk; input reset; input write_in; input [63:0] byteenable_in; output wire waitrequest_out; output wire [63:0] byteenable_out; input waitrequest_in; // internal statemachine signals wire partial_lower_half_transfer; wire full_lower_half_transfer; wire partial_upper_half_transfer; wire full_upper_half_transfer; wire full_word_transfer; reg state_bit; wire transfer_done; wire advance_to_next_state; wire lower_enable; wire upper_enable; wire lower_stall; wire upper_stall; wire two_stage_transfer; always @ (posedge clk or posedge reset) begin if (reset) begin state_bit <= 0; end else begin if (transfer_done == 1) begin state_bit <= 0; end else if (advance_to_next_state == 1) begin state_bit <= 1; end end end assign partial_lower_half_transfer = (byteenable_in[31:0] != 0); assign full_lower_half_transfer = (byteenable_in[31:0] == 32'hFFFFFFFF); assign partial_upper_half_transfer = (byteenable_in[63:32] != 0); assign full_upper_half_transfer = (byteenable_in[63:32] == 32'hFFFFFFFF); assign full_word_transfer = (full_lower_half_transfer == 1) & (full_upper_half_transfer == 1); assign two_stage_transfer = (full_word_transfer == 0) & (partial_lower_half_transfer == 1) & (partial_upper_half_transfer == 1); assign advance_to_next_state = (two_stage_transfer == 1) & (lower_stall == 0) & (write_in == 1) & (state_bit == 0) & (waitrequest_in == 0); // partial lower half transfer completed and there are bytes in the upper half that need to go out still assign transfer_done = ((full_word_transfer == 1) & (waitrequest_in == 0) & (write_in == 1)) | // full word transfer complete ((two_stage_transfer == 0) & (lower_stall == 0) & (upper_stall == 0) & (write_in == 1) & (waitrequest_in == 0)) | // partial upper or lower half transfer complete ((two_stage_transfer == 1) & (state_bit == 1) & (upper_stall == 0) & (write_in == 1) & (waitrequest_in == 0)); // partial upper and lower half transfers complete assign lower_enable = ((write_in == 1) & (full_word_transfer == 1)) | // full word transfer ((write_in == 1) & (two_stage_transfer == 0) & (partial_lower_half_transfer == 1)) | // only a partial lower half transfer ((write_in == 1) & (two_stage_transfer == 1) & (partial_lower_half_transfer == 1) & (state_bit == 0)); // partial lower half transfer (to be followed by an upper half transfer) assign upper_enable = ((write_in == 1) & (full_word_transfer == 1)) | // full word transfer ((write_in == 1) & (two_stage_transfer == 0) & (partial_upper_half_transfer == 1)) | // only a partial upper half transfer ((write_in == 1) & (two_stage_transfer == 1) & (partial_upper_half_transfer == 1) & (state_bit == 1)); // partial upper half transfer (after the lower half transfer) two_hundred_fifty_six_bit_byteenable_FSM lower_two_hundred_fifty_six_bit_byteenable_FSM ( .clk (clk), .reset (reset), .write_in (lower_enable), .byteenable_in (byteenable_in[31:0]), .waitrequest_out (lower_stall), .byteenable_out (byteenable_out[31:0]), .waitrequest_in (waitrequest_in) ); two_hundred_fifty_six_bit_byteenable_FSM upper_two_hundred_fifty_six_bit_byteenable_FSM ( .clk (clk), .reset (reset), .write_in (upper_enable), .byteenable_in (byteenable_in[63:32]), .waitrequest_out (upper_stall), .byteenable_out (byteenable_out[63:32]), .waitrequest_in (waitrequest_in) ); assign waitrequest_out = (waitrequest_in == 1) | ((transfer_done == 0) & (write_in == 1)); endmodule
module two_hundred_fifty_six_bit_byteenable_FSM ( clk, reset, write_in, byteenable_in, waitrequest_out, byteenable_out, waitrequest_in ); input clk; input reset; input write_in; input [31:0] byteenable_in; output wire waitrequest_out; output wire [31:0] byteenable_out; input waitrequest_in; // internal statemachine signals wire partial_lower_half_transfer; wire full_lower_half_transfer; wire partial_upper_half_transfer; wire full_upper_half_transfer; wire full_word_transfer; reg state_bit; wire transfer_done; wire advance_to_next_state; wire lower_enable; wire upper_enable; wire lower_stall; wire upper_stall; wire two_stage_transfer; always @ (posedge clk or posedge reset) begin if (reset) begin state_bit <= 0; end else begin if (transfer_done == 1) begin state_bit <= 0; end else if (advance_to_next_state == 1) begin state_bit <= 1; end end end assign partial_lower_half_transfer = (byteenable_in[15:0] != 0); assign full_lower_half_transfer = (byteenable_in[15:0] == 16'hFFFF); assign partial_upper_half_transfer = (byteenable_in[31:16] != 0); assign full_upper_half_transfer = (byteenable_in[31:16] == 16'hFFFF); assign full_word_transfer = (full_lower_half_transfer == 1) & (full_upper_half_transfer == 1); assign two_stage_transfer = (full_word_transfer == 0) & (partial_lower_half_transfer == 1) & (partial_upper_half_transfer == 1); assign advance_to_next_state = (two_stage_transfer == 1) & (lower_stall == 0) & (write_in == 1) & (state_bit == 0) & (waitrequest_in == 0); // partial lower half transfer completed and there are bytes in the upper half that need to go out still assign transfer_done = ((full_word_transfer == 1) & (waitrequest_in == 0) & (write_in == 1)) | // full word transfer complete ((two_stage_transfer == 0) & (lower_stall == 0) & (upper_stall == 0) & (write_in == 1) & (waitrequest_in == 0)) | // partial upper or lower half transfer complete ((two_stage_transfer == 1) & (state_bit == 1) & (upper_stall == 0) & (write_in == 1) & (waitrequest_in == 0)); // partial upper and lower half transfers complete assign lower_enable = ((write_in == 1) & (full_word_transfer == 1)) | // full word transfer ((write_in == 1) & (two_stage_transfer == 0) & (partial_lower_half_transfer == 1)) | // only a partial lower half transfer ((write_in == 1) & (two_stage_transfer == 1) & (partial_lower_half_transfer == 1) & (state_bit == 0)); // partial lower half transfer (to be followed by an upper half transfer) assign upper_enable = ((write_in == 1) & (full_word_transfer == 1)) | // full word transfer ((write_in == 1) & (two_stage_transfer == 0) & (partial_upper_half_transfer == 1)) | // only a partial upper half transfer ((write_in == 1) & (two_stage_transfer == 1) & (partial_upper_half_transfer == 1) & (state_bit == 1)); // partial upper half transfer (after the lower half transfer) one_hundred_twenty_eight_bit_byteenable_FSM lower_one_hundred_twenty_eight_bit_byteenable_FSM ( .clk (clk), .reset (reset), .write_in (lower_enable), .byteenable_in (byteenable_in[15:0]), .waitrequest_out (lower_stall), .byteenable_out (byteenable_out[15:0]), .waitrequest_in (waitrequest_in) ); one_hundred_twenty_eight_bit_byteenable_FSM upper_one_hundred_twenty_eight_bit_byteenable_FSM ( .clk (clk), .reset (reset), .write_in (upper_enable), .byteenable_in (byteenable_in[31:16]), .waitrequest_out (upper_stall), .byteenable_out (byteenable_out[31:16]), .waitrequest_in (waitrequest_in) ); assign waitrequest_out = (waitrequest_in == 1) | ((transfer_done == 0) & (write_in == 1)); endmodule
module one_hundred_twenty_eight_bit_byteenable_FSM ( clk, reset, write_in, byteenable_in, waitrequest_out, byteenable_out, waitrequest_in ); input clk; input reset; input write_in; input [15:0] byteenable_in; output wire waitrequest_out; output wire [15:0] byteenable_out; input waitrequest_in; // internal statemachine signals wire partial_lower_half_transfer; wire full_lower_half_transfer; wire partial_upper_half_transfer; wire full_upper_half_transfer; wire full_word_transfer; reg state_bit; wire transfer_done; wire advance_to_next_state; wire lower_enable; wire upper_enable; wire lower_stall; wire upper_stall; wire two_stage_transfer; always @ (posedge clk or posedge reset) begin if (reset) begin state_bit <= 0; end else begin if (transfer_done == 1) begin state_bit <= 0; end else if (advance_to_next_state == 1) begin state_bit <= 1; end end end assign partial_lower_half_transfer = (byteenable_in[7:0] != 0); assign full_lower_half_transfer = (byteenable_in[7:0] == 8'hFF); assign partial_upper_half_transfer = (byteenable_in[15:8] != 0); assign full_upper_half_transfer = (byteenable_in[15:8] == 8'hFF); assign full_word_transfer = (full_lower_half_transfer == 1) & (full_upper_half_transfer == 1); assign two_stage_transfer = (full_word_transfer == 0) & (partial_lower_half_transfer == 1) & (partial_upper_half_transfer == 1); assign advance_to_next_state = (two_stage_transfer == 1) & (lower_stall == 0) & (write_in == 1) & (state_bit == 0) & (waitrequest_in == 0); // partial lower half transfer completed and there are bytes in the upper half that need to go out still assign transfer_done = ((full_word_transfer == 1) & (waitrequest_in == 0) & (write_in == 1)) | // full word transfer complete ((two_stage_transfer == 0) & (lower_stall == 0) & (upper_stall == 0) & (write_in == 1) & (waitrequest_in == 0)) | // partial upper or lower half transfer complete ((two_stage_transfer == 1) & (state_bit == 1) & (upper_stall == 0) & (write_in == 1) & (waitrequest_in == 0)); // partial upper and lower half transfers complete assign lower_enable = ((write_in == 1) & (full_word_transfer == 1)) | // full word transfer ((write_in == 1) & (two_stage_transfer == 0) & (partial_lower_half_transfer == 1)) | // only a partial lower half transfer ((write_in == 1) & (two_stage_transfer == 1) & (partial_lower_half_transfer == 1) & (state_bit == 0)); // partial lower half transfer (to be followed by an upper half transfer) assign upper_enable = ((write_in == 1) & (full_word_transfer == 1)) | // full word transfer ((write_in == 1) & (two_stage_transfer == 0) & (partial_upper_half_transfer == 1)) | // only a partial upper half transfer ((write_in == 1) & (two_stage_transfer == 1) & (partial_upper_half_transfer == 1) & (state_bit == 1)); // partial upper half transfer (after the lower half transfer) sixty_four_bit_byteenable_FSM lower_sixty_four_bit_byteenable_FSM ( .clk (clk), .reset (reset), .write_in (lower_enable), .byteenable_in (byteenable_in[7:0]), .waitrequest_out (lower_stall), .byteenable_out (byteenable_out[7:0]), .waitrequest_in (waitrequest_in) ); sixty_four_bit_byteenable_FSM upper_sixty_four_bit_byteenable_FSM ( .clk (clk), .reset (reset), .write_in (upper_enable), .byteenable_in (byteenable_in[15:8]), .waitrequest_out (upper_stall), .byteenable_out (byteenable_out[15:8]), .waitrequest_in (waitrequest_in) ); assign waitrequest_out = (waitrequest_in == 1) | ((transfer_done == 0) & (write_in == 1)); endmodule
module sixty_four_bit_byteenable_FSM ( clk, reset, write_in, byteenable_in, waitrequest_out, byteenable_out, waitrequest_in ); input clk; input reset; input write_in; input [7:0] byteenable_in; output wire waitrequest_out; output wire [7:0] byteenable_out; input waitrequest_in; // internal statemachine signals wire partial_lower_half_transfer; wire full_lower_half_transfer; wire partial_upper_half_transfer; wire full_upper_half_transfer; wire full_word_transfer; reg state_bit; wire transfer_done; wire advance_to_next_state; wire lower_enable; wire upper_enable; wire lower_stall; wire upper_stall; wire two_stage_transfer; always @ (posedge clk or posedge reset) begin if (reset) begin state_bit <= 0; end else begin if (transfer_done == 1) begin state_bit <= 0; end else if (advance_to_next_state == 1) begin state_bit <= 1; end end end assign partial_lower_half_transfer = (byteenable_in[3:0] != 0); assign full_lower_half_transfer = (byteenable_in[3:0] == 4'hF); assign partial_upper_half_transfer = (byteenable_in[7:4] != 0); assign full_upper_half_transfer = (byteenable_in[7:4] == 4'hF); assign full_word_transfer = (full_lower_half_transfer == 1) & (full_upper_half_transfer == 1); assign two_stage_transfer = (full_word_transfer == 0) & (partial_lower_half_transfer == 1) & (partial_upper_half_transfer == 1); assign advance_to_next_state = (two_stage_transfer == 1) & (lower_stall == 0) & (write_in == 1) & (state_bit == 0) & (waitrequest_in == 0); // partial lower half transfer completed and there are bytes in the upper half that need to go out still assign transfer_done = ((full_word_transfer == 1) & (waitrequest_in == 0) & (write_in == 1)) | // full word transfer complete ((two_stage_transfer == 0) & (lower_stall == 0) & (upper_stall == 0) & (write_in == 1) & (waitrequest_in == 0)) | // partial upper or lower half transfer complete ((two_stage_transfer == 1) & (state_bit == 1) & (upper_stall == 0) & (write_in == 1) & (waitrequest_in == 0)); // partial upper and lower half transfers complete assign lower_enable = ((write_in == 1) & (full_word_transfer == 1)) | // full word transfer ((write_in == 1) & (two_stage_transfer == 0) & (partial_lower_half_transfer == 1)) | // only a partial lower half transfer ((write_in == 1) & (two_stage_transfer == 1) & (partial_lower_half_transfer == 1) & (state_bit == 0)); // partial lower half transfer (to be followed by an upper half transfer) assign upper_enable = ((write_in == 1) & (full_word_transfer == 1)) | // full word transfer ((write_in == 1) & (two_stage_transfer == 0) & (partial_upper_half_transfer == 1)) | // only a partial upper half transfer ((write_in == 1) & (two_stage_transfer == 1) & (partial_upper_half_transfer == 1) & (state_bit == 1)); // partial upper half transfer (after the lower half transfer) thirty_two_bit_byteenable_FSM lower_thirty_two_bit_byteenable_FSM ( .clk (clk), .reset (reset), .write_in (lower_enable), .byteenable_in (byteenable_in[3:0]), .waitrequest_out (lower_stall), .byteenable_out (byteenable_out[3:0]), .waitrequest_in (waitrequest_in) ); thirty_two_bit_byteenable_FSM upper_thirty_two_bit_byteenable_FSM ( .clk (clk), .reset (reset), .write_in (upper_enable), .byteenable_in (byteenable_in[7:4]), .waitrequest_out (upper_stall), .byteenable_out (byteenable_out[7:4]), .waitrequest_in (waitrequest_in) ); assign waitrequest_out = (waitrequest_in == 1) | ((transfer_done == 0) & (write_in == 1)); endmodule
module thirty_two_bit_byteenable_FSM ( clk, reset, write_in, byteenable_in, waitrequest_out, byteenable_out, waitrequest_in ); input clk; input reset; input write_in; input [3:0] byteenable_in; output wire waitrequest_out; output wire [3:0] byteenable_out; input waitrequest_in; // internal statemachine signals wire partial_lower_half_transfer; wire full_lower_half_transfer; wire partial_upper_half_transfer; wire full_upper_half_transfer; wire full_word_transfer; reg state_bit; wire transfer_done; wire advance_to_next_state; wire lower_enable; wire upper_enable; wire lower_stall; wire upper_stall; wire two_stage_transfer; always @ (posedge clk or posedge reset) begin if (reset) begin state_bit <= 0; end else begin if (transfer_done == 1) begin state_bit <= 0; end else if (advance_to_next_state == 1) begin state_bit <= 1; end end end assign partial_lower_half_transfer = (byteenable_in[1:0] != 0); assign full_lower_half_transfer = (byteenable_in[1:0] == 2'h3); assign partial_upper_half_transfer = (byteenable_in[3:2] != 0); assign full_upper_half_transfer = (byteenable_in[3:2] == 2'h3); assign full_word_transfer = (full_lower_half_transfer == 1) & (full_upper_half_transfer == 1); assign two_stage_transfer = (full_word_transfer == 0) & (partial_lower_half_transfer == 1) & (partial_upper_half_transfer == 1); assign advance_to_next_state = (two_stage_transfer == 1) & (lower_stall == 0) & (write_in == 1) & (state_bit == 0) & (waitrequest_in == 0); // partial lower half transfer completed and there are bytes in the upper half that need to go out still assign transfer_done = ((full_word_transfer == 1) & (waitrequest_in == 0) & (write_in == 1)) | // full word transfer complete ((two_stage_transfer == 0) & (lower_stall == 0) & (upper_stall == 0) & (write_in == 1) & (waitrequest_in == 0)) | // partial upper or lower half transfer complete ((two_stage_transfer == 1) & (state_bit == 1) & (upper_stall == 0) & (write_in == 1) & (waitrequest_in == 0)); // partial upper and lower half transfers complete assign lower_enable = ((write_in == 1) & (full_word_transfer == 1)) | // full word transfer ((write_in == 1) & (two_stage_transfer == 0) & (partial_lower_half_transfer == 1)) | // only a partial lower half transfer ((write_in == 1) & (two_stage_transfer == 1) & (partial_lower_half_transfer == 1) & (state_bit == 0)); // partial lower half transfer (to be followed by an upper half transfer) assign upper_enable = ((write_in == 1) & (full_word_transfer == 1)) | // full word transfer ((write_in == 1) & (two_stage_transfer == 0) & (partial_upper_half_transfer == 1)) | // only a partial upper half transfer ((write_in == 1) & (two_stage_transfer == 1) & (partial_upper_half_transfer == 1) & (state_bit == 1)); // partial upper half transfer (after the lower half transfer) sixteen_bit_byteenable_FSM lower_sixteen_bit_byteenable_FSM ( .write_in (lower_enable), .byteenable_in (byteenable_in[1:0]), .waitrequest_out (lower_stall), .byteenable_out (byteenable_out[1:0]), .waitrequest_in (waitrequest_in) ); sixteen_bit_byteenable_FSM upper_sixteen_bit_byteenable_FSM ( .write_in (upper_enable), .byteenable_in (byteenable_in[3:2]), .waitrequest_out (upper_stall), .byteenable_out (byteenable_out[3:2]), .waitrequest_in (waitrequest_in) ); assign waitrequest_out = (waitrequest_in == 1) | ((transfer_done == 0) & (write_in == 1)); endmodule
module sixteen_bit_byteenable_FSM ( write_in, byteenable_in, waitrequest_out, byteenable_out, waitrequest_in ); input write_in; input [1:0] byteenable_in; output wire waitrequest_out; output wire [1:0] byteenable_out; input waitrequest_in; assign byteenable_out = byteenable_in & {2{write_in}}; // all 2 bit byte enable pairs are supported, masked with write in to turn the byte lanes off when writing is disabled assign waitrequest_out = (write_in == 1) & (waitrequest_in == 1); // transfer always completes on the first cycle unless waitrequest is asserted endmodule
module uses it .write_in (write_in), .byteenable_in (byteenable_in), .waitrequest_out (waitrequest_out), .byteenable_out (byteenable_out), .waitrequest_in (waitrequest_in) ); end else if (BYTEENABLE_WIDTH == 4) begin thirty_two_bit_byteenable_FSM the_thirty_two_bit_byteenable_FSM( .clk (clk), .reset (reset), .write_in (write_in), .byteenable_in (byteenable_in), .waitrequest_out (waitrequest_out), .byteenable_out (byteenable_out), .waitrequest_in (waitrequest_in) ); end else if (BYTEENABLE_WIDTH == 8) begin sixty_four_bit_byteenable_FSM the_sixty_four_bit_byteenable_FSM( .clk (clk), .reset (reset), .write_in (write_in), .byteenable_in (byteenable_in), .waitrequest_out (waitrequest_out), .byteenable_out (byteenable_out), .waitrequest_in (waitrequest_in) ); end else if (BYTEENABLE_WIDTH == 16) begin one_hundred_twenty_eight_bit_byteenable_FSM the_one_hundred_twenty_eight_bit_byteenable_FSM( .clk (clk), .reset (reset), .write_in (write_in), .byteenable_in (byteenable_in), .waitrequest_out (waitrequest_out), .byteenable_out (byteenable_out), .waitrequest_in (waitrequest_in) ); end else if (BYTEENABLE_WIDTH == 32) begin two_hundred_fifty_six_bit_byteenable_FSM the_two_hundred_fifty_six_bit_byteenable_FSM( .clk (clk), .reset (reset), .write_in (write_in), .byteenable_in (byteenable_in), .waitrequest_out (waitrequest_out), .byteenable_out (byteenable_out), .waitrequest_in (waitrequest_in) ); end else if (BYTEENABLE_WIDTH == 64) begin five_hundred_twelve_bit_byteenable_FSM the_five_hundred_twelve_bit_byteenable_FSM ( .clk (clk), .reset (reset), .write_in (write_in), .byteenable_in (byteenable_in), .waitrequest_out (waitrequest_out), .byteenable_out (byteenable_out), .waitrequest_in (waitrequest_in) ); end else if (BYTEENABLE_WIDTH == 128) begin one_thousand_twenty_four_byteenable_FSM the_one_thousand_twenty_four_byteenable_FSM ( .clk (clk), .reset (reset), .write_in (write_in), .byteenable_in (byteenable_in), .waitrequest_out (waitrequest_out), .byteenable_out (byteenable_out), .waitrequest_in (waitrequest_in) ); end endgenerate endmodule
module one_thousand_twenty_four_byteenable_FSM ( clk, reset, write_in, byteenable_in, waitrequest_out, byteenable_out, waitrequest_in ); input clk; input reset; input write_in; input [127:0] byteenable_in; output wire waitrequest_out; output wire [127:0] byteenable_out; input waitrequest_in; // internal statemachine signals wire partial_lower_half_transfer; wire full_lower_half_transfer; wire partial_upper_half_transfer; wire full_upper_half_transfer; wire full_word_transfer; reg state_bit; wire transfer_done; wire advance_to_next_state; wire lower_enable; wire upper_enable; wire lower_stall; wire upper_stall; wire two_stage_transfer; always @ (posedge clk or posedge reset) begin if (reset) begin state_bit <= 0; end else begin if (transfer_done == 1) begin state_bit <= 0; end else if (advance_to_next_state == 1) begin state_bit <= 1; end end end assign partial_lower_half_transfer = (byteenable_in[63:0] != 0); assign full_lower_half_transfer = (byteenable_in[63:0] == 64'hFFFFFFFFFFFFFFFF); assign partial_upper_half_transfer = (byteenable_in[127:64] != 0); assign full_upper_half_transfer = (byteenable_in[127:64] == 64'hFFFFFFFFFFFFFFFF); assign full_word_transfer = (full_lower_half_transfer == 1) & (full_upper_half_transfer == 1); assign two_stage_transfer = (full_word_transfer == 0) & (partial_lower_half_transfer == 1) & (partial_upper_half_transfer == 1); assign advance_to_next_state = (two_stage_transfer == 1) & (lower_stall == 0) & (write_in == 1) & (state_bit == 0) & (waitrequest_in == 0); // partial lower half transfer completed and there are bytes in the upper half that need to go out still assign transfer_done = ((full_word_transfer == 1) & (waitrequest_in == 0) & (write_in == 1)) | // full word transfer complete ((two_stage_transfer == 0) & (lower_stall == 0) & (upper_stall == 0) & (write_in == 1) & (waitrequest_in == 0)) | // partial upper or lower half transfer complete ((two_stage_transfer == 1) & (state_bit == 1) & (upper_stall == 0) & (write_in == 1) & (waitrequest_in == 0)); // partial upper and lower half transfers complete assign lower_enable = ((write_in == 1) & (full_word_transfer == 1)) | // full word transfer ((write_in == 1) & (two_stage_transfer == 0) & (partial_lower_half_transfer == 1)) | // only a partial lower half transfer ((write_in == 1) & (two_stage_transfer == 1) & (partial_lower_half_transfer == 1) & (state_bit == 0)); // partial lower half transfer (to be followed by an upper half transfer) assign upper_enable = ((write_in == 1) & (full_word_transfer == 1)) | // full word transfer ((write_in == 1) & (two_stage_transfer == 0) & (partial_upper_half_transfer == 1)) | // only a partial upper half transfer ((write_in == 1) & (two_stage_transfer == 1) & (partial_upper_half_transfer == 1) & (state_bit == 1)); // partial upper half transfer (after the lower half transfer) five_hundred_twelve_bit_byteenable_FSM lower_five_hundred_twelve_bit_byteenable_FSM ( .clk (clk), .reset (reset), .write_in (lower_enable), .byteenable_in (byteenable_in[63:0]), .waitrequest_out (lower_stall), .byteenable_out (byteenable_out[63:0]), .waitrequest_in (waitrequest_in) ); five_hundred_twelve_bit_byteenable_FSM upper_five_hundred_twelve_bit_byteenable_FSM ( .clk (clk), .reset (reset), .write_in (upper_enable), .byteenable_in (byteenable_in[127:64]), .waitrequest_out (upper_stall), .byteenable_out (byteenable_out[127:64]), .waitrequest_in (waitrequest_in) ); assign waitrequest_out = (waitrequest_in == 1) | ((transfer_done == 0) & (write_in == 1)); endmodule
module five_hundred_twelve_bit_byteenable_FSM ( clk, reset, write_in, byteenable_in, waitrequest_out, byteenable_out, waitrequest_in ); input clk; input reset; input write_in; input [63:0] byteenable_in; output wire waitrequest_out; output wire [63:0] byteenable_out; input waitrequest_in; // internal statemachine signals wire partial_lower_half_transfer; wire full_lower_half_transfer; wire partial_upper_half_transfer; wire full_upper_half_transfer; wire full_word_transfer; reg state_bit; wire transfer_done; wire advance_to_next_state; wire lower_enable; wire upper_enable; wire lower_stall; wire upper_stall; wire two_stage_transfer; always @ (posedge clk or posedge reset) begin if (reset) begin state_bit <= 0; end else begin if (transfer_done == 1) begin state_bit <= 0; end else if (advance_to_next_state == 1) begin state_bit <= 1; end end end assign partial_lower_half_transfer = (byteenable_in[31:0] != 0); assign full_lower_half_transfer = (byteenable_in[31:0] == 32'hFFFFFFFF); assign partial_upper_half_transfer = (byteenable_in[63:32] != 0); assign full_upper_half_transfer = (byteenable_in[63:32] == 32'hFFFFFFFF); assign full_word_transfer = (full_lower_half_transfer == 1) & (full_upper_half_transfer == 1); assign two_stage_transfer = (full_word_transfer == 0) & (partial_lower_half_transfer == 1) & (partial_upper_half_transfer == 1); assign advance_to_next_state = (two_stage_transfer == 1) & (lower_stall == 0) & (write_in == 1) & (state_bit == 0) & (waitrequest_in == 0); // partial lower half transfer completed and there are bytes in the upper half that need to go out still assign transfer_done = ((full_word_transfer == 1) & (waitrequest_in == 0) & (write_in == 1)) | // full word transfer complete ((two_stage_transfer == 0) & (lower_stall == 0) & (upper_stall == 0) & (write_in == 1) & (waitrequest_in == 0)) | // partial upper or lower half transfer complete ((two_stage_transfer == 1) & (state_bit == 1) & (upper_stall == 0) & (write_in == 1) & (waitrequest_in == 0)); // partial upper and lower half transfers complete assign lower_enable = ((write_in == 1) & (full_word_transfer == 1)) | // full word transfer ((write_in == 1) & (two_stage_transfer == 0) & (partial_lower_half_transfer == 1)) | // only a partial lower half transfer ((write_in == 1) & (two_stage_transfer == 1) & (partial_lower_half_transfer == 1) & (state_bit == 0)); // partial lower half transfer (to be followed by an upper half transfer) assign upper_enable = ((write_in == 1) & (full_word_transfer == 1)) | // full word transfer ((write_in == 1) & (two_stage_transfer == 0) & (partial_upper_half_transfer == 1)) | // only a partial upper half transfer ((write_in == 1) & (two_stage_transfer == 1) & (partial_upper_half_transfer == 1) & (state_bit == 1)); // partial upper half transfer (after the lower half transfer) two_hundred_fifty_six_bit_byteenable_FSM lower_two_hundred_fifty_six_bit_byteenable_FSM ( .clk (clk), .reset (reset), .write_in (lower_enable), .byteenable_in (byteenable_in[31:0]), .waitrequest_out (lower_stall), .byteenable_out (byteenable_out[31:0]), .waitrequest_in (waitrequest_in) ); two_hundred_fifty_six_bit_byteenable_FSM upper_two_hundred_fifty_six_bit_byteenable_FSM ( .clk (clk), .reset (reset), .write_in (upper_enable), .byteenable_in (byteenable_in[63:32]), .waitrequest_out (upper_stall), .byteenable_out (byteenable_out[63:32]), .waitrequest_in (waitrequest_in) ); assign waitrequest_out = (waitrequest_in == 1) | ((transfer_done == 0) & (write_in == 1)); endmodule
module two_hundred_fifty_six_bit_byteenable_FSM ( clk, reset, write_in, byteenable_in, waitrequest_out, byteenable_out, waitrequest_in ); input clk; input reset; input write_in; input [31:0] byteenable_in; output wire waitrequest_out; output wire [31:0] byteenable_out; input waitrequest_in; // internal statemachine signals wire partial_lower_half_transfer; wire full_lower_half_transfer; wire partial_upper_half_transfer; wire full_upper_half_transfer; wire full_word_transfer; reg state_bit; wire transfer_done; wire advance_to_next_state; wire lower_enable; wire upper_enable; wire lower_stall; wire upper_stall; wire two_stage_transfer; always @ (posedge clk or posedge reset) begin if (reset) begin state_bit <= 0; end else begin if (transfer_done == 1) begin state_bit <= 0; end else if (advance_to_next_state == 1) begin state_bit <= 1; end end end assign partial_lower_half_transfer = (byteenable_in[15:0] != 0); assign full_lower_half_transfer = (byteenable_in[15:0] == 16'hFFFF); assign partial_upper_half_transfer = (byteenable_in[31:16] != 0); assign full_upper_half_transfer = (byteenable_in[31:16] == 16'hFFFF); assign full_word_transfer = (full_lower_half_transfer == 1) & (full_upper_half_transfer == 1); assign two_stage_transfer = (full_word_transfer == 0) & (partial_lower_half_transfer == 1) & (partial_upper_half_transfer == 1); assign advance_to_next_state = (two_stage_transfer == 1) & (lower_stall == 0) & (write_in == 1) & (state_bit == 0) & (waitrequest_in == 0); // partial lower half transfer completed and there are bytes in the upper half that need to go out still assign transfer_done = ((full_word_transfer == 1) & (waitrequest_in == 0) & (write_in == 1)) | // full word transfer complete ((two_stage_transfer == 0) & (lower_stall == 0) & (upper_stall == 0) & (write_in == 1) & (waitrequest_in == 0)) | // partial upper or lower half transfer complete ((two_stage_transfer == 1) & (state_bit == 1) & (upper_stall == 0) & (write_in == 1) & (waitrequest_in == 0)); // partial upper and lower half transfers complete assign lower_enable = ((write_in == 1) & (full_word_transfer == 1)) | // full word transfer ((write_in == 1) & (two_stage_transfer == 0) & (partial_lower_half_transfer == 1)) | // only a partial lower half transfer ((write_in == 1) & (two_stage_transfer == 1) & (partial_lower_half_transfer == 1) & (state_bit == 0)); // partial lower half transfer (to be followed by an upper half transfer) assign upper_enable = ((write_in == 1) & (full_word_transfer == 1)) | // full word transfer ((write_in == 1) & (two_stage_transfer == 0) & (partial_upper_half_transfer == 1)) | // only a partial upper half transfer ((write_in == 1) & (two_stage_transfer == 1) & (partial_upper_half_transfer == 1) & (state_bit == 1)); // partial upper half transfer (after the lower half transfer) one_hundred_twenty_eight_bit_byteenable_FSM lower_one_hundred_twenty_eight_bit_byteenable_FSM ( .clk (clk), .reset (reset), .write_in (lower_enable), .byteenable_in (byteenable_in[15:0]), .waitrequest_out (lower_stall), .byteenable_out (byteenable_out[15:0]), .waitrequest_in (waitrequest_in) ); one_hundred_twenty_eight_bit_byteenable_FSM upper_one_hundred_twenty_eight_bit_byteenable_FSM ( .clk (clk), .reset (reset), .write_in (upper_enable), .byteenable_in (byteenable_in[31:16]), .waitrequest_out (upper_stall), .byteenable_out (byteenable_out[31:16]), .waitrequest_in (waitrequest_in) ); assign waitrequest_out = (waitrequest_in == 1) | ((transfer_done == 0) & (write_in == 1)); endmodule
module one_hundred_twenty_eight_bit_byteenable_FSM ( clk, reset, write_in, byteenable_in, waitrequest_out, byteenable_out, waitrequest_in ); input clk; input reset; input write_in; input [15:0] byteenable_in; output wire waitrequest_out; output wire [15:0] byteenable_out; input waitrequest_in; // internal statemachine signals wire partial_lower_half_transfer; wire full_lower_half_transfer; wire partial_upper_half_transfer; wire full_upper_half_transfer; wire full_word_transfer; reg state_bit; wire transfer_done; wire advance_to_next_state; wire lower_enable; wire upper_enable; wire lower_stall; wire upper_stall; wire two_stage_transfer; always @ (posedge clk or posedge reset) begin if (reset) begin state_bit <= 0; end else begin if (transfer_done == 1) begin state_bit <= 0; end else if (advance_to_next_state == 1) begin state_bit <= 1; end end end assign partial_lower_half_transfer = (byteenable_in[7:0] != 0); assign full_lower_half_transfer = (byteenable_in[7:0] == 8'hFF); assign partial_upper_half_transfer = (byteenable_in[15:8] != 0); assign full_upper_half_transfer = (byteenable_in[15:8] == 8'hFF); assign full_word_transfer = (full_lower_half_transfer == 1) & (full_upper_half_transfer == 1); assign two_stage_transfer = (full_word_transfer == 0) & (partial_lower_half_transfer == 1) & (partial_upper_half_transfer == 1); assign advance_to_next_state = (two_stage_transfer == 1) & (lower_stall == 0) & (write_in == 1) & (state_bit == 0) & (waitrequest_in == 0); // partial lower half transfer completed and there are bytes in the upper half that need to go out still assign transfer_done = ((full_word_transfer == 1) & (waitrequest_in == 0) & (write_in == 1)) | // full word transfer complete ((two_stage_transfer == 0) & (lower_stall == 0) & (upper_stall == 0) & (write_in == 1) & (waitrequest_in == 0)) | // partial upper or lower half transfer complete ((two_stage_transfer == 1) & (state_bit == 1) & (upper_stall == 0) & (write_in == 1) & (waitrequest_in == 0)); // partial upper and lower half transfers complete assign lower_enable = ((write_in == 1) & (full_word_transfer == 1)) | // full word transfer ((write_in == 1) & (two_stage_transfer == 0) & (partial_lower_half_transfer == 1)) | // only a partial lower half transfer ((write_in == 1) & (two_stage_transfer == 1) & (partial_lower_half_transfer == 1) & (state_bit == 0)); // partial lower half transfer (to be followed by an upper half transfer) assign upper_enable = ((write_in == 1) & (full_word_transfer == 1)) | // full word transfer ((write_in == 1) & (two_stage_transfer == 0) & (partial_upper_half_transfer == 1)) | // only a partial upper half transfer ((write_in == 1) & (two_stage_transfer == 1) & (partial_upper_half_transfer == 1) & (state_bit == 1)); // partial upper half transfer (after the lower half transfer) sixty_four_bit_byteenable_FSM lower_sixty_four_bit_byteenable_FSM ( .clk (clk), .reset (reset), .write_in (lower_enable), .byteenable_in (byteenable_in[7:0]), .waitrequest_out (lower_stall), .byteenable_out (byteenable_out[7:0]), .waitrequest_in (waitrequest_in) ); sixty_four_bit_byteenable_FSM upper_sixty_four_bit_byteenable_FSM ( .clk (clk), .reset (reset), .write_in (upper_enable), .byteenable_in (byteenable_in[15:8]), .waitrequest_out (upper_stall), .byteenable_out (byteenable_out[15:8]), .waitrequest_in (waitrequest_in) ); assign waitrequest_out = (waitrequest_in == 1) | ((transfer_done == 0) & (write_in == 1)); endmodule
module sixty_four_bit_byteenable_FSM ( clk, reset, write_in, byteenable_in, waitrequest_out, byteenable_out, waitrequest_in ); input clk; input reset; input write_in; input [7:0] byteenable_in; output wire waitrequest_out; output wire [7:0] byteenable_out; input waitrequest_in; // internal statemachine signals wire partial_lower_half_transfer; wire full_lower_half_transfer; wire partial_upper_half_transfer; wire full_upper_half_transfer; wire full_word_transfer; reg state_bit; wire transfer_done; wire advance_to_next_state; wire lower_enable; wire upper_enable; wire lower_stall; wire upper_stall; wire two_stage_transfer; always @ (posedge clk or posedge reset) begin if (reset) begin state_bit <= 0; end else begin if (transfer_done == 1) begin state_bit <= 0; end else if (advance_to_next_state == 1) begin state_bit <= 1; end end end assign partial_lower_half_transfer = (byteenable_in[3:0] != 0); assign full_lower_half_transfer = (byteenable_in[3:0] == 4'hF); assign partial_upper_half_transfer = (byteenable_in[7:4] != 0); assign full_upper_half_transfer = (byteenable_in[7:4] == 4'hF); assign full_word_transfer = (full_lower_half_transfer == 1) & (full_upper_half_transfer == 1); assign two_stage_transfer = (full_word_transfer == 0) & (partial_lower_half_transfer == 1) & (partial_upper_half_transfer == 1); assign advance_to_next_state = (two_stage_transfer == 1) & (lower_stall == 0) & (write_in == 1) & (state_bit == 0) & (waitrequest_in == 0); // partial lower half transfer completed and there are bytes in the upper half that need to go out still assign transfer_done = ((full_word_transfer == 1) & (waitrequest_in == 0) & (write_in == 1)) | // full word transfer complete ((two_stage_transfer == 0) & (lower_stall == 0) & (upper_stall == 0) & (write_in == 1) & (waitrequest_in == 0)) | // partial upper or lower half transfer complete ((two_stage_transfer == 1) & (state_bit == 1) & (upper_stall == 0) & (write_in == 1) & (waitrequest_in == 0)); // partial upper and lower half transfers complete assign lower_enable = ((write_in == 1) & (full_word_transfer == 1)) | // full word transfer ((write_in == 1) & (two_stage_transfer == 0) & (partial_lower_half_transfer == 1)) | // only a partial lower half transfer ((write_in == 1) & (two_stage_transfer == 1) & (partial_lower_half_transfer == 1) & (state_bit == 0)); // partial lower half transfer (to be followed by an upper half transfer) assign upper_enable = ((write_in == 1) & (full_word_transfer == 1)) | // full word transfer ((write_in == 1) & (two_stage_transfer == 0) & (partial_upper_half_transfer == 1)) | // only a partial upper half transfer ((write_in == 1) & (two_stage_transfer == 1) & (partial_upper_half_transfer == 1) & (state_bit == 1)); // partial upper half transfer (after the lower half transfer) thirty_two_bit_byteenable_FSM lower_thirty_two_bit_byteenable_FSM ( .clk (clk), .reset (reset), .write_in (lower_enable), .byteenable_in (byteenable_in[3:0]), .waitrequest_out (lower_stall), .byteenable_out (byteenable_out[3:0]), .waitrequest_in (waitrequest_in) ); thirty_two_bit_byteenable_FSM upper_thirty_two_bit_byteenable_FSM ( .clk (clk), .reset (reset), .write_in (upper_enable), .byteenable_in (byteenable_in[7:4]), .waitrequest_out (upper_stall), .byteenable_out (byteenable_out[7:4]), .waitrequest_in (waitrequest_in) ); assign waitrequest_out = (waitrequest_in == 1) | ((transfer_done == 0) & (write_in == 1)); endmodule
module thirty_two_bit_byteenable_FSM ( clk, reset, write_in, byteenable_in, waitrequest_out, byteenable_out, waitrequest_in ); input clk; input reset; input write_in; input [3:0] byteenable_in; output wire waitrequest_out; output wire [3:0] byteenable_out; input waitrequest_in; // internal statemachine signals wire partial_lower_half_transfer; wire full_lower_half_transfer; wire partial_upper_half_transfer; wire full_upper_half_transfer; wire full_word_transfer; reg state_bit; wire transfer_done; wire advance_to_next_state; wire lower_enable; wire upper_enable; wire lower_stall; wire upper_stall; wire two_stage_transfer; always @ (posedge clk or posedge reset) begin if (reset) begin state_bit <= 0; end else begin if (transfer_done == 1) begin state_bit <= 0; end else if (advance_to_next_state == 1) begin state_bit <= 1; end end end assign partial_lower_half_transfer = (byteenable_in[1:0] != 0); assign full_lower_half_transfer = (byteenable_in[1:0] == 2'h3); assign partial_upper_half_transfer = (byteenable_in[3:2] != 0); assign full_upper_half_transfer = (byteenable_in[3:2] == 2'h3); assign full_word_transfer = (full_lower_half_transfer == 1) & (full_upper_half_transfer == 1); assign two_stage_transfer = (full_word_transfer == 0) & (partial_lower_half_transfer == 1) & (partial_upper_half_transfer == 1); assign advance_to_next_state = (two_stage_transfer == 1) & (lower_stall == 0) & (write_in == 1) & (state_bit == 0) & (waitrequest_in == 0); // partial lower half transfer completed and there are bytes in the upper half that need to go out still assign transfer_done = ((full_word_transfer == 1) & (waitrequest_in == 0) & (write_in == 1)) | // full word transfer complete ((two_stage_transfer == 0) & (lower_stall == 0) & (upper_stall == 0) & (write_in == 1) & (waitrequest_in == 0)) | // partial upper or lower half transfer complete ((two_stage_transfer == 1) & (state_bit == 1) & (upper_stall == 0) & (write_in == 1) & (waitrequest_in == 0)); // partial upper and lower half transfers complete assign lower_enable = ((write_in == 1) & (full_word_transfer == 1)) | // full word transfer ((write_in == 1) & (two_stage_transfer == 0) & (partial_lower_half_transfer == 1)) | // only a partial lower half transfer ((write_in == 1) & (two_stage_transfer == 1) & (partial_lower_half_transfer == 1) & (state_bit == 0)); // partial lower half transfer (to be followed by an upper half transfer) assign upper_enable = ((write_in == 1) & (full_word_transfer == 1)) | // full word transfer ((write_in == 1) & (two_stage_transfer == 0) & (partial_upper_half_transfer == 1)) | // only a partial upper half transfer ((write_in == 1) & (two_stage_transfer == 1) & (partial_upper_half_transfer == 1) & (state_bit == 1)); // partial upper half transfer (after the lower half transfer) sixteen_bit_byteenable_FSM lower_sixteen_bit_byteenable_FSM ( .write_in (lower_enable), .byteenable_in (byteenable_in[1:0]), .waitrequest_out (lower_stall), .byteenable_out (byteenable_out[1:0]), .waitrequest_in (waitrequest_in) ); sixteen_bit_byteenable_FSM upper_sixteen_bit_byteenable_FSM ( .write_in (upper_enable), .byteenable_in (byteenable_in[3:2]), .waitrequest_out (upper_stall), .byteenable_out (byteenable_out[3:2]), .waitrequest_in (waitrequest_in) ); assign waitrequest_out = (waitrequest_in == 1) | ((transfer_done == 0) & (write_in == 1)); endmodule
module sixteen_bit_byteenable_FSM ( write_in, byteenable_in, waitrequest_out, byteenable_out, waitrequest_in ); input write_in; input [1:0] byteenable_in; output wire waitrequest_out; output wire [1:0] byteenable_out; input waitrequest_in; assign byteenable_out = byteenable_in & {2{write_in}}; // all 2 bit byte enable pairs are supported, masked with write in to turn the byte lanes off when writing is disabled assign waitrequest_out = (write_in == 1) & (waitrequest_in == 1); // transfer always completes on the first cycle unless waitrequest is asserted endmodule
module generic_baseblocks_v2_1_0_command_fifo # ( parameter C_FAMILY = "virtex6", parameter integer C_ENABLE_S_VALID_CARRY = 0, parameter integer C_ENABLE_REGISTERED_OUTPUT = 0, parameter integer C_FIFO_DEPTH_LOG = 5, // FIFO depth = 2**C_FIFO_DEPTH_LOG // Range = [4:5]. parameter integer C_FIFO_WIDTH = 64 // Width of payload [1:512] ) ( // Global inputs input wire ACLK, // Clock input wire ARESET, // Reset // Information output wire EMPTY, // FIFO empty (all stages) // Slave Port input wire [C_FIFO_WIDTH-1:0] S_MESG, // Payload (may be any set of channel signals) input wire S_VALID, // FIFO push output wire S_READY, // FIFO not full // Master Port output wire [C_FIFO_WIDTH-1:0] M_MESG, // Payload output wire M_VALID, // FIFO not empty input wire M_READY // FIFO pop ); ///////////////////////////////////////////////////////////////////////////// // Variables for generating parameter controlled instances. ///////////////////////////////////////////////////////////////////////////// // Generate variable for data vector. genvar addr_cnt; genvar bit_cnt; integer index; ///////////////////////////////////////////////////////////////////////////// // Internal signals ///////////////////////////////////////////////////////////////////////////// wire [C_FIFO_DEPTH_LOG-1:0] addr; wire buffer_Full; wire buffer_Empty; wire next_Data_Exists; reg data_Exists_I; wire valid_Write; wire new_write; wire [C_FIFO_DEPTH_LOG-1:0] hsum_A; wire [C_FIFO_DEPTH_LOG-1:0] sum_A; wire [C_FIFO_DEPTH_LOG-1:0] addr_cy; wire buffer_full_early; wire [C_FIFO_WIDTH-1:0] M_MESG_I; // Payload wire M_VALID_I; // FIFO not empty wire M_READY_I; // FIFO pop ///////////////////////////////////////////////////////////////////////////// // Create Flags ///////////////////////////////////////////////////////////////////////////// assign buffer_full_early = ( (addr == {{C_FIFO_DEPTH_LOG-1{1'b1}}, 1'b0}) & valid_Write & ~M_READY_I ) | ( buffer_Full & ~M_READY_I ); assign S_READY = ~buffer_Full; assign buffer_Empty = (addr == {C_FIFO_DEPTH_LOG{1'b0}}); assign next_Data_Exists = (data_Exists_I & ~buffer_Empty) | (buffer_Empty & S_VALID) | (data_Exists_I & ~(M_READY_I & data_Exists_I)); always @ (posedge ACLK) begin if (ARESET) begin data_Exists_I <= 1'b0; end else begin data_Exists_I <= next_Data_Exists; end end assign M_VALID_I = data_Exists_I; // Select RTL or FPGA optimized instatiations for critical parts. generate if ( C_FAMILY == "rtl" || C_ENABLE_S_VALID_CARRY == 0 ) begin : USE_RTL_VALID_WRITE reg buffer_Full_q; assign valid_Write = S_VALID & ~buffer_Full; assign new_write = (S_VALID | ~buffer_Empty); assign addr_cy[0] = valid_Write; always @ (posedge ACLK) begin if (ARESET) begin buffer_Full_q <= 1'b0; end else if ( data_Exists_I ) begin buffer_Full_q <= buffer_full_early; end end assign buffer_Full = buffer_Full_q; end else begin : USE_FPGA_VALID_WRITE wire s_valid_dummy1; wire s_valid_dummy2; wire sel_s_valid; wire sel_new_write; wire valid_Write_dummy1; wire valid_Write_dummy2; assign sel_s_valid = ~buffer_Full; generic_baseblocks_v2_1_0_carry_and # ( .C_FAMILY(C_FAMILY) ) s_valid_dummy_inst1 ( .CIN(S_VALID), .S(1'b1), .COUT(s_valid_dummy1) ); generic_baseblocks_v2_1_0_carry_and # ( .C_FAMILY(C_FAMILY) ) s_valid_dummy_inst2 ( .CIN(s_valid_dummy1), .S(1'b1), .COUT(s_valid_dummy2) ); generic_baseblocks_v2_1_0_carry_and # ( .C_FAMILY(C_FAMILY) ) valid_write_inst ( .CIN(s_valid_dummy2), .S(sel_s_valid), .COUT(valid_Write) ); assign sel_new_write = ~buffer_Empty; generic_baseblocks_v2_1_0_carry_latch_or # ( .C_FAMILY(C_FAMILY) ) new_write_inst ( .CIN(valid_Write), .I(sel_new_write), .O(new_write) ); generic_baseblocks_v2_1_0_carry_and # ( .C_FAMILY(C_FAMILY) ) valid_write_dummy_inst1 ( .CIN(valid_Write), .S(1'b1), .COUT(valid_Write_dummy1) ); generic_baseblocks_v2_1_0_carry_and # ( .C_FAMILY(C_FAMILY) ) valid_write_dummy_inst2 ( .CIN(valid_Write_dummy1), .S(1'b1), .COUT(valid_Write_dummy2) ); generic_baseblocks_v2_1_0_carry_and # ( .C_FAMILY(C_FAMILY) ) valid_write_dummy_inst3 ( .CIN(valid_Write_dummy2), .S(1'b1), .COUT(addr_cy[0]) ); FDRE #( .INIT(1'b0) // Initial value of register (1'b0 or 1'b1) ) FDRE_I1 ( .Q(buffer_Full), // Data output .C(ACLK), // Clock input .CE(data_Exists_I), // Clock enable input .R(ARESET), // Synchronous reset input .D(buffer_full_early) // Data input ); end endgenerate ///////////////////////////////////////////////////////////////////////////// // Create address pointer ///////////////////////////////////////////////////////////////////////////// generate if ( C_FAMILY == "rtl" ) begin : USE_RTL_ADDR reg [C_FIFO_DEPTH_LOG-1:0] addr_q; always @ (posedge ACLK) begin if (ARESET) begin addr_q <= {C_FIFO_DEPTH_LOG{1'b0}}; end else if ( data_Exists_I ) begin if ( valid_Write & ~(M_READY_I & data_Exists_I) ) begin addr_q <= addr_q + 1'b1; end else if ( ~valid_Write & (M_READY_I & data_Exists_I) & ~buffer_Empty ) begin addr_q <= addr_q - 1'b1; end else begin addr_q <= addr_q; end end else begin addr_q <= addr_q; end end assign addr = addr_q; end else begin : USE_FPGA_ADDR for (addr_cnt = 0; addr_cnt < C_FIFO_DEPTH_LOG ; addr_cnt = addr_cnt + 1) begin : ADDR_GEN assign hsum_A[addr_cnt] = ((M_READY_I & data_Exists_I) ^ addr[addr_cnt]) & new_write; // Don't need the last muxcy, addr_cy(last) is not used anywhere if ( addr_cnt < C_FIFO_DEPTH_LOG - 1 ) begin : USE_MUXCY MUXCY MUXCY_inst ( .DI(addr[addr_cnt]), .CI(addr_cy[addr_cnt]), .S(hsum_A[addr_cnt]), .O(addr_cy[addr_cnt+1]) ); end else begin : NO_MUXCY end XORCY XORCY_inst ( .LI(hsum_A[addr_cnt]), .CI(addr_cy[addr_cnt]), .O(sum_A[addr_cnt]) ); FDRE #( .INIT(1'b0) // Initial value of register (1'b0 or 1'b1) ) FDRE_inst ( .Q(addr[addr_cnt]), // Data output .C(ACLK), // Clock input .CE(data_Exists_I), // Clock enable input .R(ARESET), // Synchronous reset input .D(sum_A[addr_cnt]) // Data input ); end // end for bit_cnt end // C_FAMILY endgenerate ///////////////////////////////////////////////////////////////////////////// // Data storage ///////////////////////////////////////////////////////////////////////////// generate if ( C_FAMILY == "rtl" ) begin : USE_RTL_FIFO reg [C_FIFO_WIDTH-1:0] data_srl[2 ** C_FIFO_DEPTH_LOG-1:0]; always @ (posedge ACLK) begin if ( valid_Write ) begin for (index = 0; index < 2 ** C_FIFO_DEPTH_LOG-1 ; index = index + 1) begin data_srl[index+1] <= data_srl[index]; end data_srl[0] <= S_MESG; end end assign M_MESG_I = data_srl[addr]; end else begin : USE_FPGA_FIFO for (bit_cnt = 0; bit_cnt < C_FIFO_WIDTH ; bit_cnt = bit_cnt + 1) begin : DATA_GEN if ( C_FIFO_DEPTH_LOG == 5 ) begin : USE_32 SRLC32E # ( .INIT(32'h00000000) // Initial Value of Shift Register ) SRLC32E_inst ( .Q(M_MESG_I[bit_cnt]), // SRL data output .Q31(), // SRL cascade output pin .A(addr), // 5-bit shift depth select input .CE(valid_Write), // Clock enable input .CLK(ACLK), // Clock input .D(S_MESG[bit_cnt]) // SRL data input ); end else begin : USE_16 SRLC16E # ( .INIT(32'h00000000) // Initial Value of Shift Register ) SRLC16E_inst ( .Q(M_MESG_I[bit_cnt]), // SRL data output .Q15(), // SRL cascade output pin .A0(addr[0]), // 4-bit shift depth select input 0 .A1(addr[1]), // 4-bit shift depth select input 1 .A2(addr[2]), // 4-bit shift depth select input 2 .A3(addr[3]), // 4-bit shift depth select input 3 .CE(valid_Write), // Clock enable input .CLK(ACLK), // Clock input .D(S_MESG[bit_cnt]) // SRL data input ); end // C_FIFO_DEPTH_LOG end // end for bit_cnt end // C_FAMILY endgenerate ///////////////////////////////////////////////////////////////////////////// // Pipeline stage ///////////////////////////////////////////////////////////////////////////// generate if ( C_ENABLE_REGISTERED_OUTPUT != 0 ) begin : USE_FF_OUT wire [C_FIFO_WIDTH-1:0] M_MESG_FF; // Payload wire M_VALID_FF; // FIFO not empty // Select RTL or FPGA optimized instatiations for critical parts. if ( C_FAMILY == "rtl" ) begin : USE_RTL_OUTPUT_PIPELINE reg [C_FIFO_WIDTH-1:0] M_MESG_Q; // Payload reg M_VALID_Q; // FIFO not empty always @ (posedge ACLK) begin if (ARESET) begin M_MESG_Q <= {C_FIFO_WIDTH{1'b0}}; M_VALID_Q <= 1'b0; end else begin if ( M_READY_I ) begin M_MESG_Q <= M_MESG_I; M_VALID_Q <= M_VALID_I; end end end assign M_MESG_FF = M_MESG_Q; assign M_VALID_FF = M_VALID_Q; end else begin : USE_FPGA_OUTPUT_PIPELINE reg [C_FIFO_WIDTH-1:0] M_MESG_CMB; // Payload reg M_VALID_CMB; // FIFO not empty always @ * begin if ( M_READY_I ) begin M_MESG_CMB <= M_MESG_I; M_VALID_CMB <= M_VALID_I; end else begin M_MESG_CMB <= M_MESG_FF; M_VALID_CMB <= M_VALID_FF; end end for (bit_cnt = 0; bit_cnt < C_FIFO_WIDTH ; bit_cnt = bit_cnt + 1) begin : DATA_GEN FDRE #( .INIT(1'b0) // Initial value of register (1'b0 or 1'b1) ) FDRE_inst ( .Q(M_MESG_FF[bit_cnt]), // Data output .C(ACLK), // Clock input .CE(1'b1), // Clock enable input .R(ARESET), // Synchronous reset input .D(M_MESG_CMB[bit_cnt]) // Data input ); end // end for bit_cnt FDRE #( .INIT(1'b0) // Initial value of register (1'b0 or 1'b1) ) FDRE_inst ( .Q(M_VALID_FF), // Data output .C(ACLK), // Clock input .CE(1'b1), // Clock enable input .R(ARESET), // Synchronous reset input .D(M_VALID_CMB) // Data input ); end assign EMPTY = ~M_VALID_I & ~M_VALID_FF; assign M_MESG = M_MESG_FF; assign M_VALID = M_VALID_FF; assign M_READY_I = ( M_READY & M_VALID_FF ) | ~M_VALID_FF; end else begin : NO_FF_OUT assign EMPTY = ~M_VALID_I; assign M_MESG = M_MESG_I; assign M_VALID = M_VALID_I; assign M_READY_I = M_READY; end endgenerate endmodule
module axi_infrastructure_v1_1_0_vector2axi # ( /////////////////////////////////////////////////////////////////////////////// // Parameter Definitions /////////////////////////////////////////////////////////////////////////////// parameter integer C_AXI_PROTOCOL = 0, parameter integer C_AXI_ID_WIDTH = 4, parameter integer C_AXI_ADDR_WIDTH = 32, parameter integer C_AXI_DATA_WIDTH = 32, parameter integer C_AXI_SUPPORTS_USER_SIGNALS = 0, parameter integer C_AXI_SUPPORTS_REGION_SIGNALS = 0, parameter integer C_AXI_AWUSER_WIDTH = 1, parameter integer C_AXI_WUSER_WIDTH = 1, parameter integer C_AXI_BUSER_WIDTH = 1, parameter integer C_AXI_ARUSER_WIDTH = 1, parameter integer C_AXI_RUSER_WIDTH = 1, parameter integer C_AWPAYLOAD_WIDTH = 61, parameter integer C_WPAYLOAD_WIDTH = 73, parameter integer C_BPAYLOAD_WIDTH = 6, parameter integer C_ARPAYLOAD_WIDTH = 61, parameter integer C_RPAYLOAD_WIDTH = 69 ) ( /////////////////////////////////////////////////////////////////////////////// // Port Declarations /////////////////////////////////////////////////////////////////////////////// // Slave Interface Write Address Ports output wire [C_AXI_ID_WIDTH-1:0] m_axi_awid, output wire [C_AXI_ADDR_WIDTH-1:0] m_axi_awaddr, output wire [((C_AXI_PROTOCOL == 1) ? 4 : 8)-1:0] m_axi_awlen, output wire [3-1:0] m_axi_awsize, output wire [2-1:0] m_axi_awburst, output wire [((C_AXI_PROTOCOL == 1) ? 2 : 1)-1:0] m_axi_awlock, output wire [4-1:0] m_axi_awcache, output wire [3-1:0] m_axi_awprot, output wire [4-1:0] m_axi_awregion, output wire [4-1:0] m_axi_awqos, output wire [C_AXI_AWUSER_WIDTH-1:0] m_axi_awuser, // Slave Interface Write Data Ports output wire [C_AXI_ID_WIDTH-1:0] m_axi_wid, output wire [C_AXI_DATA_WIDTH-1:0] m_axi_wdata, output wire [C_AXI_DATA_WIDTH/8-1:0] m_axi_wstrb, output wire m_axi_wlast, output wire [C_AXI_WUSER_WIDTH-1:0] m_axi_wuser, // Slave Interface Write Response Ports input wire [C_AXI_ID_WIDTH-1:0] m_axi_bid, input wire [2-1:0] m_axi_bresp, input wire [C_AXI_BUSER_WIDTH-1:0] m_axi_buser, // Slave Interface Read Address Ports output wire [C_AXI_ID_WIDTH-1:0] m_axi_arid, output wire [C_AXI_ADDR_WIDTH-1:0] m_axi_araddr, output wire [((C_AXI_PROTOCOL == 1) ? 4 : 8)-1:0] m_axi_arlen, output wire [3-1:0] m_axi_arsize, output wire [2-1:0] m_axi_arburst, output wire [((C_AXI_PROTOCOL == 1) ? 2 : 1)-1:0] m_axi_arlock, output wire [4-1:0] m_axi_arcache, output wire [3-1:0] m_axi_arprot, output wire [4-1:0] m_axi_arregion, output wire [4-1:0] m_axi_arqos, output wire [C_AXI_ARUSER_WIDTH-1:0] m_axi_aruser, // Slave Interface Read Data Ports input wire [C_AXI_ID_WIDTH-1:0] m_axi_rid, input wire [C_AXI_DATA_WIDTH-1:0] m_axi_rdata, input wire [2-1:0] m_axi_rresp, input wire m_axi_rlast, input wire [C_AXI_RUSER_WIDTH-1:0] m_axi_ruser, // payloads input wire [C_AWPAYLOAD_WIDTH-1:0] m_awpayload, input wire [C_WPAYLOAD_WIDTH-1:0] m_wpayload, output wire [C_BPAYLOAD_WIDTH-1:0] m_bpayload, input wire [C_ARPAYLOAD_WIDTH-1:0] m_arpayload, output wire [C_RPAYLOAD_WIDTH-1:0] m_rpayload ); //////////////////////////////////////////////////////////////////////////////// // Functions //////////////////////////////////////////////////////////////////////////////// `include "axi_infrastructure_v1_1_0_header.vh" //////////////////////////////////////////////////////////////////////////////// // Local parameters //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // Wires/Reg declarations //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // BEGIN RTL //////////////////////////////////////////////////////////////////////////////// // AXI4, AXI4LITE, AXI3 packing assign m_axi_awaddr = m_awpayload[G_AXI_AWADDR_INDEX+:G_AXI_AWADDR_WIDTH]; assign m_axi_awprot = m_awpayload[G_AXI_AWPROT_INDEX+:G_AXI_AWPROT_WIDTH]; assign m_axi_wdata = m_wpayload[G_AXI_WDATA_INDEX+:G_AXI_WDATA_WIDTH]; assign m_axi_wstrb = m_wpayload[G_AXI_WSTRB_INDEX+:G_AXI_WSTRB_WIDTH]; assign m_bpayload[G_AXI_BRESP_INDEX+:G_AXI_BRESP_WIDTH] = m_axi_bresp; assign m_axi_araddr = m_arpayload[G_AXI_ARADDR_INDEX+:G_AXI_ARADDR_WIDTH]; assign m_axi_arprot = m_arpayload[G_AXI_ARPROT_INDEX+:G_AXI_ARPROT_WIDTH]; assign m_rpayload[G_AXI_RDATA_INDEX+:G_AXI_RDATA_WIDTH] = m_axi_rdata; assign m_rpayload[G_AXI_RRESP_INDEX+:G_AXI_RRESP_WIDTH] = m_axi_rresp; generate if (C_AXI_PROTOCOL == 0 || C_AXI_PROTOCOL == 1) begin : gen_axi4_or_axi3_packing assign m_axi_awsize = m_awpayload[G_AXI_AWSIZE_INDEX+:G_AXI_AWSIZE_WIDTH] ; assign m_axi_awburst = m_awpayload[G_AXI_AWBURST_INDEX+:G_AXI_AWBURST_WIDTH]; assign m_axi_awcache = m_awpayload[G_AXI_AWCACHE_INDEX+:G_AXI_AWCACHE_WIDTH]; assign m_axi_awlen = m_awpayload[G_AXI_AWLEN_INDEX+:G_AXI_AWLEN_WIDTH] ; assign m_axi_awlock = m_awpayload[G_AXI_AWLOCK_INDEX+:G_AXI_AWLOCK_WIDTH] ; assign m_axi_awid = m_awpayload[G_AXI_AWID_INDEX+:G_AXI_AWID_WIDTH] ; assign m_axi_awqos = m_awpayload[G_AXI_AWQOS_INDEX+:G_AXI_AWQOS_WIDTH] ; assign m_axi_wlast = m_wpayload[G_AXI_WLAST_INDEX+:G_AXI_WLAST_WIDTH] ; if (C_AXI_PROTOCOL == 1) begin : gen_axi3_wid_packing assign m_axi_wid = m_wpayload[G_AXI_WID_INDEX+:G_AXI_WID_WIDTH] ; end else begin : gen_no_axi3_wid_packing assign m_axi_wid = 1'b0; end assign m_bpayload[G_AXI_BID_INDEX+:G_AXI_BID_WIDTH] = m_axi_bid; assign m_axi_arsize = m_arpayload[G_AXI_ARSIZE_INDEX+:G_AXI_ARSIZE_WIDTH] ; assign m_axi_arburst = m_arpayload[G_AXI_ARBURST_INDEX+:G_AXI_ARBURST_WIDTH]; assign m_axi_arcache = m_arpayload[G_AXI_ARCACHE_INDEX+:G_AXI_ARCACHE_WIDTH]; assign m_axi_arlen = m_arpayload[G_AXI_ARLEN_INDEX+:G_AXI_ARLEN_WIDTH] ; assign m_axi_arlock = m_arpayload[G_AXI_ARLOCK_INDEX+:G_AXI_ARLOCK_WIDTH] ; assign m_axi_arid = m_arpayload[G_AXI_ARID_INDEX+:G_AXI_ARID_WIDTH] ; assign m_axi_arqos = m_arpayload[G_AXI_ARQOS_INDEX+:G_AXI_ARQOS_WIDTH] ; assign m_rpayload[G_AXI_RLAST_INDEX+:G_AXI_RLAST_WIDTH] = m_axi_rlast; assign m_rpayload[G_AXI_RID_INDEX+:G_AXI_RID_WIDTH] = m_axi_rid ; if (C_AXI_SUPPORTS_REGION_SIGNALS == 1 && G_AXI_AWREGION_WIDTH > 0) begin : gen_region_signals assign m_axi_awregion = m_awpayload[G_AXI_AWREGION_INDEX+:G_AXI_AWREGION_WIDTH]; assign m_axi_arregion = m_arpayload[G_AXI_ARREGION_INDEX+:G_AXI_ARREGION_WIDTH]; end else begin : gen_no_region_signals assign m_axi_awregion = 'b0; assign m_axi_arregion = 'b0; end if (C_AXI_SUPPORTS_USER_SIGNALS == 1 && C_AXI_PROTOCOL != 2) begin : gen_user_signals assign m_axi_awuser = m_awpayload[G_AXI_AWUSER_INDEX+:G_AXI_AWUSER_WIDTH]; assign m_axi_wuser = m_wpayload[G_AXI_WUSER_INDEX+:G_AXI_WUSER_WIDTH] ; assign m_bpayload[G_AXI_BUSER_INDEX+:G_AXI_BUSER_WIDTH] = m_axi_buser ; assign m_axi_aruser = m_arpayload[G_AXI_ARUSER_INDEX+:G_AXI_ARUSER_WIDTH]; assign m_rpayload[G_AXI_RUSER_INDEX+:G_AXI_RUSER_WIDTH] = m_axi_ruser ; end else begin : gen_no_user_signals assign m_axi_awuser = 'b0; assign m_axi_wuser = 'b0; assign m_axi_aruser = 'b0; end end else begin : gen_axi4lite_packing assign m_axi_awsize = (C_AXI_DATA_WIDTH == 32) ? 3'd2 : 3'd3; assign m_axi_awburst = 'b0; assign m_axi_awcache = 'b0; assign m_axi_awlen = 'b0; assign m_axi_awlock = 'b0; assign m_axi_awid = 'b0; assign m_axi_awqos = 'b0; assign m_axi_wlast = 1'b1; assign m_axi_wid = 'b0; assign m_axi_arsize = (C_AXI_DATA_WIDTH == 32) ? 3'd2 : 3'd3; assign m_axi_arburst = 'b0; assign m_axi_arcache = 'b0; assign m_axi_arlen = 'b0; assign m_axi_arlock = 'b0; assign m_axi_arid = 'b0; assign m_axi_arqos = 'b0; assign m_axi_awregion = 'b0; assign m_axi_arregion = 'b0; assign m_axi_awuser = 'b0; assign m_axi_wuser = 'b0; assign m_axi_aruser = 'b0; end endgenerate endmodule
module axi_infrastructure_v1_1_0_vector2axi # ( /////////////////////////////////////////////////////////////////////////////// // Parameter Definitions /////////////////////////////////////////////////////////////////////////////// parameter integer C_AXI_PROTOCOL = 0, parameter integer C_AXI_ID_WIDTH = 4, parameter integer C_AXI_ADDR_WIDTH = 32, parameter integer C_AXI_DATA_WIDTH = 32, parameter integer C_AXI_SUPPORTS_USER_SIGNALS = 0, parameter integer C_AXI_SUPPORTS_REGION_SIGNALS = 0, parameter integer C_AXI_AWUSER_WIDTH = 1, parameter integer C_AXI_WUSER_WIDTH = 1, parameter integer C_AXI_BUSER_WIDTH = 1, parameter integer C_AXI_ARUSER_WIDTH = 1, parameter integer C_AXI_RUSER_WIDTH = 1, parameter integer C_AWPAYLOAD_WIDTH = 61, parameter integer C_WPAYLOAD_WIDTH = 73, parameter integer C_BPAYLOAD_WIDTH = 6, parameter integer C_ARPAYLOAD_WIDTH = 61, parameter integer C_RPAYLOAD_WIDTH = 69 ) ( /////////////////////////////////////////////////////////////////////////////// // Port Declarations /////////////////////////////////////////////////////////////////////////////// // Slave Interface Write Address Ports output wire [C_AXI_ID_WIDTH-1:0] m_axi_awid, output wire [C_AXI_ADDR_WIDTH-1:0] m_axi_awaddr, output wire [((C_AXI_PROTOCOL == 1) ? 4 : 8)-1:0] m_axi_awlen, output wire [3-1:0] m_axi_awsize, output wire [2-1:0] m_axi_awburst, output wire [((C_AXI_PROTOCOL == 1) ? 2 : 1)-1:0] m_axi_awlock, output wire [4-1:0] m_axi_awcache, output wire [3-1:0] m_axi_awprot, output wire [4-1:0] m_axi_awregion, output wire [4-1:0] m_axi_awqos, output wire [C_AXI_AWUSER_WIDTH-1:0] m_axi_awuser, // Slave Interface Write Data Ports output wire [C_AXI_ID_WIDTH-1:0] m_axi_wid, output wire [C_AXI_DATA_WIDTH-1:0] m_axi_wdata, output wire [C_AXI_DATA_WIDTH/8-1:0] m_axi_wstrb, output wire m_axi_wlast, output wire [C_AXI_WUSER_WIDTH-1:0] m_axi_wuser, // Slave Interface Write Response Ports input wire [C_AXI_ID_WIDTH-1:0] m_axi_bid, input wire [2-1:0] m_axi_bresp, input wire [C_AXI_BUSER_WIDTH-1:0] m_axi_buser, // Slave Interface Read Address Ports output wire [C_AXI_ID_WIDTH-1:0] m_axi_arid, output wire [C_AXI_ADDR_WIDTH-1:0] m_axi_araddr, output wire [((C_AXI_PROTOCOL == 1) ? 4 : 8)-1:0] m_axi_arlen, output wire [3-1:0] m_axi_arsize, output wire [2-1:0] m_axi_arburst, output wire [((C_AXI_PROTOCOL == 1) ? 2 : 1)-1:0] m_axi_arlock, output wire [4-1:0] m_axi_arcache, output wire [3-1:0] m_axi_arprot, output wire [4-1:0] m_axi_arregion, output wire [4-1:0] m_axi_arqos, output wire [C_AXI_ARUSER_WIDTH-1:0] m_axi_aruser, // Slave Interface Read Data Ports input wire [C_AXI_ID_WIDTH-1:0] m_axi_rid, input wire [C_AXI_DATA_WIDTH-1:0] m_axi_rdata, input wire [2-1:0] m_axi_rresp, input wire m_axi_rlast, input wire [C_AXI_RUSER_WIDTH-1:0] m_axi_ruser, // payloads input wire [C_AWPAYLOAD_WIDTH-1:0] m_awpayload, input wire [C_WPAYLOAD_WIDTH-1:0] m_wpayload, output wire [C_BPAYLOAD_WIDTH-1:0] m_bpayload, input wire [C_ARPAYLOAD_WIDTH-1:0] m_arpayload, output wire [C_RPAYLOAD_WIDTH-1:0] m_rpayload ); //////////////////////////////////////////////////////////////////////////////// // Functions //////////////////////////////////////////////////////////////////////////////// `include "axi_infrastructure_v1_1_0_header.vh" //////////////////////////////////////////////////////////////////////////////// // Local parameters //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // Wires/Reg declarations //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // BEGIN RTL //////////////////////////////////////////////////////////////////////////////// // AXI4, AXI4LITE, AXI3 packing assign m_axi_awaddr = m_awpayload[G_AXI_AWADDR_INDEX+:G_AXI_AWADDR_WIDTH]; assign m_axi_awprot = m_awpayload[G_AXI_AWPROT_INDEX+:G_AXI_AWPROT_WIDTH]; assign m_axi_wdata = m_wpayload[G_AXI_WDATA_INDEX+:G_AXI_WDATA_WIDTH]; assign m_axi_wstrb = m_wpayload[G_AXI_WSTRB_INDEX+:G_AXI_WSTRB_WIDTH]; assign m_bpayload[G_AXI_BRESP_INDEX+:G_AXI_BRESP_WIDTH] = m_axi_bresp; assign m_axi_araddr = m_arpayload[G_AXI_ARADDR_INDEX+:G_AXI_ARADDR_WIDTH]; assign m_axi_arprot = m_arpayload[G_AXI_ARPROT_INDEX+:G_AXI_ARPROT_WIDTH]; assign m_rpayload[G_AXI_RDATA_INDEX+:G_AXI_RDATA_WIDTH] = m_axi_rdata; assign m_rpayload[G_AXI_RRESP_INDEX+:G_AXI_RRESP_WIDTH] = m_axi_rresp; generate if (C_AXI_PROTOCOL == 0 || C_AXI_PROTOCOL == 1) begin : gen_axi4_or_axi3_packing assign m_axi_awsize = m_awpayload[G_AXI_AWSIZE_INDEX+:G_AXI_AWSIZE_WIDTH] ; assign m_axi_awburst = m_awpayload[G_AXI_AWBURST_INDEX+:G_AXI_AWBURST_WIDTH]; assign m_axi_awcache = m_awpayload[G_AXI_AWCACHE_INDEX+:G_AXI_AWCACHE_WIDTH]; assign m_axi_awlen = m_awpayload[G_AXI_AWLEN_INDEX+:G_AXI_AWLEN_WIDTH] ; assign m_axi_awlock = m_awpayload[G_AXI_AWLOCK_INDEX+:G_AXI_AWLOCK_WIDTH] ; assign m_axi_awid = m_awpayload[G_AXI_AWID_INDEX+:G_AXI_AWID_WIDTH] ; assign m_axi_awqos = m_awpayload[G_AXI_AWQOS_INDEX+:G_AXI_AWQOS_WIDTH] ; assign m_axi_wlast = m_wpayload[G_AXI_WLAST_INDEX+:G_AXI_WLAST_WIDTH] ; if (C_AXI_PROTOCOL == 1) begin : gen_axi3_wid_packing assign m_axi_wid = m_wpayload[G_AXI_WID_INDEX+:G_AXI_WID_WIDTH] ; end else begin : gen_no_axi3_wid_packing assign m_axi_wid = 1'b0; end assign m_bpayload[G_AXI_BID_INDEX+:G_AXI_BID_WIDTH] = m_axi_bid; assign m_axi_arsize = m_arpayload[G_AXI_ARSIZE_INDEX+:G_AXI_ARSIZE_WIDTH] ; assign m_axi_arburst = m_arpayload[G_AXI_ARBURST_INDEX+:G_AXI_ARBURST_WIDTH]; assign m_axi_arcache = m_arpayload[G_AXI_ARCACHE_INDEX+:G_AXI_ARCACHE_WIDTH]; assign m_axi_arlen = m_arpayload[G_AXI_ARLEN_INDEX+:G_AXI_ARLEN_WIDTH] ; assign m_axi_arlock = m_arpayload[G_AXI_ARLOCK_INDEX+:G_AXI_ARLOCK_WIDTH] ; assign m_axi_arid = m_arpayload[G_AXI_ARID_INDEX+:G_AXI_ARID_WIDTH] ; assign m_axi_arqos = m_arpayload[G_AXI_ARQOS_INDEX+:G_AXI_ARQOS_WIDTH] ; assign m_rpayload[G_AXI_RLAST_INDEX+:G_AXI_RLAST_WIDTH] = m_axi_rlast; assign m_rpayload[G_AXI_RID_INDEX+:G_AXI_RID_WIDTH] = m_axi_rid ; if (C_AXI_SUPPORTS_REGION_SIGNALS == 1 && G_AXI_AWREGION_WIDTH > 0) begin : gen_region_signals assign m_axi_awregion = m_awpayload[G_AXI_AWREGION_INDEX+:G_AXI_AWREGION_WIDTH]; assign m_axi_arregion = m_arpayload[G_AXI_ARREGION_INDEX+:G_AXI_ARREGION_WIDTH]; end else begin : gen_no_region_signals assign m_axi_awregion = 'b0; assign m_axi_arregion = 'b0; end if (C_AXI_SUPPORTS_USER_SIGNALS == 1 && C_AXI_PROTOCOL != 2) begin : gen_user_signals assign m_axi_awuser = m_awpayload[G_AXI_AWUSER_INDEX+:G_AXI_AWUSER_WIDTH]; assign m_axi_wuser = m_wpayload[G_AXI_WUSER_INDEX+:G_AXI_WUSER_WIDTH] ; assign m_bpayload[G_AXI_BUSER_INDEX+:G_AXI_BUSER_WIDTH] = m_axi_buser ; assign m_axi_aruser = m_arpayload[G_AXI_ARUSER_INDEX+:G_AXI_ARUSER_WIDTH]; assign m_rpayload[G_AXI_RUSER_INDEX+:G_AXI_RUSER_WIDTH] = m_axi_ruser ; end else begin : gen_no_user_signals assign m_axi_awuser = 'b0; assign m_axi_wuser = 'b0; assign m_axi_aruser = 'b0; end end else begin : gen_axi4lite_packing assign m_axi_awsize = (C_AXI_DATA_WIDTH == 32) ? 3'd2 : 3'd3; assign m_axi_awburst = 'b0; assign m_axi_awcache = 'b0; assign m_axi_awlen = 'b0; assign m_axi_awlock = 'b0; assign m_axi_awid = 'b0; assign m_axi_awqos = 'b0; assign m_axi_wlast = 1'b1; assign m_axi_wid = 'b0; assign m_axi_arsize = (C_AXI_DATA_WIDTH == 32) ? 3'd2 : 3'd3; assign m_axi_arburst = 'b0; assign m_axi_arcache = 'b0; assign m_axi_arlen = 'b0; assign m_axi_arlock = 'b0; assign m_axi_arid = 'b0; assign m_axi_arqos = 'b0; assign m_axi_awregion = 'b0; assign m_axi_arregion = 'b0; assign m_axi_awuser = 'b0; assign m_axi_wuser = 'b0; assign m_axi_aruser = 'b0; end endgenerate endmodule
module axi_infrastructure_v1_1_0_vector2axi # ( /////////////////////////////////////////////////////////////////////////////// // Parameter Definitions /////////////////////////////////////////////////////////////////////////////// parameter integer C_AXI_PROTOCOL = 0, parameter integer C_AXI_ID_WIDTH = 4, parameter integer C_AXI_ADDR_WIDTH = 32, parameter integer C_AXI_DATA_WIDTH = 32, parameter integer C_AXI_SUPPORTS_USER_SIGNALS = 0, parameter integer C_AXI_SUPPORTS_REGION_SIGNALS = 0, parameter integer C_AXI_AWUSER_WIDTH = 1, parameter integer C_AXI_WUSER_WIDTH = 1, parameter integer C_AXI_BUSER_WIDTH = 1, parameter integer C_AXI_ARUSER_WIDTH = 1, parameter integer C_AXI_RUSER_WIDTH = 1, parameter integer C_AWPAYLOAD_WIDTH = 61, parameter integer C_WPAYLOAD_WIDTH = 73, parameter integer C_BPAYLOAD_WIDTH = 6, parameter integer C_ARPAYLOAD_WIDTH = 61, parameter integer C_RPAYLOAD_WIDTH = 69 ) ( /////////////////////////////////////////////////////////////////////////////// // Port Declarations /////////////////////////////////////////////////////////////////////////////// // Slave Interface Write Address Ports output wire [C_AXI_ID_WIDTH-1:0] m_axi_awid, output wire [C_AXI_ADDR_WIDTH-1:0] m_axi_awaddr, output wire [((C_AXI_PROTOCOL == 1) ? 4 : 8)-1:0] m_axi_awlen, output wire [3-1:0] m_axi_awsize, output wire [2-1:0] m_axi_awburst, output wire [((C_AXI_PROTOCOL == 1) ? 2 : 1)-1:0] m_axi_awlock, output wire [4-1:0] m_axi_awcache, output wire [3-1:0] m_axi_awprot, output wire [4-1:0] m_axi_awregion, output wire [4-1:0] m_axi_awqos, output wire [C_AXI_AWUSER_WIDTH-1:0] m_axi_awuser, // Slave Interface Write Data Ports output wire [C_AXI_ID_WIDTH-1:0] m_axi_wid, output wire [C_AXI_DATA_WIDTH-1:0] m_axi_wdata, output wire [C_AXI_DATA_WIDTH/8-1:0] m_axi_wstrb, output wire m_axi_wlast, output wire [C_AXI_WUSER_WIDTH-1:0] m_axi_wuser, // Slave Interface Write Response Ports input wire [C_AXI_ID_WIDTH-1:0] m_axi_bid, input wire [2-1:0] m_axi_bresp, input wire [C_AXI_BUSER_WIDTH-1:0] m_axi_buser, // Slave Interface Read Address Ports output wire [C_AXI_ID_WIDTH-1:0] m_axi_arid, output wire [C_AXI_ADDR_WIDTH-1:0] m_axi_araddr, output wire [((C_AXI_PROTOCOL == 1) ? 4 : 8)-1:0] m_axi_arlen, output wire [3-1:0] m_axi_arsize, output wire [2-1:0] m_axi_arburst, output wire [((C_AXI_PROTOCOL == 1) ? 2 : 1)-1:0] m_axi_arlock, output wire [4-1:0] m_axi_arcache, output wire [3-1:0] m_axi_arprot, output wire [4-1:0] m_axi_arregion, output wire [4-1:0] m_axi_arqos, output wire [C_AXI_ARUSER_WIDTH-1:0] m_axi_aruser, // Slave Interface Read Data Ports input wire [C_AXI_ID_WIDTH-1:0] m_axi_rid, input wire [C_AXI_DATA_WIDTH-1:0] m_axi_rdata, input wire [2-1:0] m_axi_rresp, input wire m_axi_rlast, input wire [C_AXI_RUSER_WIDTH-1:0] m_axi_ruser, // payloads input wire [C_AWPAYLOAD_WIDTH-1:0] m_awpayload, input wire [C_WPAYLOAD_WIDTH-1:0] m_wpayload, output wire [C_BPAYLOAD_WIDTH-1:0] m_bpayload, input wire [C_ARPAYLOAD_WIDTH-1:0] m_arpayload, output wire [C_RPAYLOAD_WIDTH-1:0] m_rpayload ); //////////////////////////////////////////////////////////////////////////////// // Functions //////////////////////////////////////////////////////////////////////////////// `include "axi_infrastructure_v1_1_0_header.vh" //////////////////////////////////////////////////////////////////////////////// // Local parameters //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // Wires/Reg declarations //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // BEGIN RTL //////////////////////////////////////////////////////////////////////////////// // AXI4, AXI4LITE, AXI3 packing assign m_axi_awaddr = m_awpayload[G_AXI_AWADDR_INDEX+:G_AXI_AWADDR_WIDTH]; assign m_axi_awprot = m_awpayload[G_AXI_AWPROT_INDEX+:G_AXI_AWPROT_WIDTH]; assign m_axi_wdata = m_wpayload[G_AXI_WDATA_INDEX+:G_AXI_WDATA_WIDTH]; assign m_axi_wstrb = m_wpayload[G_AXI_WSTRB_INDEX+:G_AXI_WSTRB_WIDTH]; assign m_bpayload[G_AXI_BRESP_INDEX+:G_AXI_BRESP_WIDTH] = m_axi_bresp; assign m_axi_araddr = m_arpayload[G_AXI_ARADDR_INDEX+:G_AXI_ARADDR_WIDTH]; assign m_axi_arprot = m_arpayload[G_AXI_ARPROT_INDEX+:G_AXI_ARPROT_WIDTH]; assign m_rpayload[G_AXI_RDATA_INDEX+:G_AXI_RDATA_WIDTH] = m_axi_rdata; assign m_rpayload[G_AXI_RRESP_INDEX+:G_AXI_RRESP_WIDTH] = m_axi_rresp; generate if (C_AXI_PROTOCOL == 0 || C_AXI_PROTOCOL == 1) begin : gen_axi4_or_axi3_packing assign m_axi_awsize = m_awpayload[G_AXI_AWSIZE_INDEX+:G_AXI_AWSIZE_WIDTH] ; assign m_axi_awburst = m_awpayload[G_AXI_AWBURST_INDEX+:G_AXI_AWBURST_WIDTH]; assign m_axi_awcache = m_awpayload[G_AXI_AWCACHE_INDEX+:G_AXI_AWCACHE_WIDTH]; assign m_axi_awlen = m_awpayload[G_AXI_AWLEN_INDEX+:G_AXI_AWLEN_WIDTH] ; assign m_axi_awlock = m_awpayload[G_AXI_AWLOCK_INDEX+:G_AXI_AWLOCK_WIDTH] ; assign m_axi_awid = m_awpayload[G_AXI_AWID_INDEX+:G_AXI_AWID_WIDTH] ; assign m_axi_awqos = m_awpayload[G_AXI_AWQOS_INDEX+:G_AXI_AWQOS_WIDTH] ; assign m_axi_wlast = m_wpayload[G_AXI_WLAST_INDEX+:G_AXI_WLAST_WIDTH] ; if (C_AXI_PROTOCOL == 1) begin : gen_axi3_wid_packing assign m_axi_wid = m_wpayload[G_AXI_WID_INDEX+:G_AXI_WID_WIDTH] ; end else begin : gen_no_axi3_wid_packing assign m_axi_wid = 1'b0; end assign m_bpayload[G_AXI_BID_INDEX+:G_AXI_BID_WIDTH] = m_axi_bid; assign m_axi_arsize = m_arpayload[G_AXI_ARSIZE_INDEX+:G_AXI_ARSIZE_WIDTH] ; assign m_axi_arburst = m_arpayload[G_AXI_ARBURST_INDEX+:G_AXI_ARBURST_WIDTH]; assign m_axi_arcache = m_arpayload[G_AXI_ARCACHE_INDEX+:G_AXI_ARCACHE_WIDTH]; assign m_axi_arlen = m_arpayload[G_AXI_ARLEN_INDEX+:G_AXI_ARLEN_WIDTH] ; assign m_axi_arlock = m_arpayload[G_AXI_ARLOCK_INDEX+:G_AXI_ARLOCK_WIDTH] ; assign m_axi_arid = m_arpayload[G_AXI_ARID_INDEX+:G_AXI_ARID_WIDTH] ; assign m_axi_arqos = m_arpayload[G_AXI_ARQOS_INDEX+:G_AXI_ARQOS_WIDTH] ; assign m_rpayload[G_AXI_RLAST_INDEX+:G_AXI_RLAST_WIDTH] = m_axi_rlast; assign m_rpayload[G_AXI_RID_INDEX+:G_AXI_RID_WIDTH] = m_axi_rid ; if (C_AXI_SUPPORTS_REGION_SIGNALS == 1 && G_AXI_AWREGION_WIDTH > 0) begin : gen_region_signals assign m_axi_awregion = m_awpayload[G_AXI_AWREGION_INDEX+:G_AXI_AWREGION_WIDTH]; assign m_axi_arregion = m_arpayload[G_AXI_ARREGION_INDEX+:G_AXI_ARREGION_WIDTH]; end else begin : gen_no_region_signals assign m_axi_awregion = 'b0; assign m_axi_arregion = 'b0; end if (C_AXI_SUPPORTS_USER_SIGNALS == 1 && C_AXI_PROTOCOL != 2) begin : gen_user_signals assign m_axi_awuser = m_awpayload[G_AXI_AWUSER_INDEX+:G_AXI_AWUSER_WIDTH]; assign m_axi_wuser = m_wpayload[G_AXI_WUSER_INDEX+:G_AXI_WUSER_WIDTH] ; assign m_bpayload[G_AXI_BUSER_INDEX+:G_AXI_BUSER_WIDTH] = m_axi_buser ; assign m_axi_aruser = m_arpayload[G_AXI_ARUSER_INDEX+:G_AXI_ARUSER_WIDTH]; assign m_rpayload[G_AXI_RUSER_INDEX+:G_AXI_RUSER_WIDTH] = m_axi_ruser ; end else begin : gen_no_user_signals assign m_axi_awuser = 'b0; assign m_axi_wuser = 'b0; assign m_axi_aruser = 'b0; end end else begin : gen_axi4lite_packing assign m_axi_awsize = (C_AXI_DATA_WIDTH == 32) ? 3'd2 : 3'd3; assign m_axi_awburst = 'b0; assign m_axi_awcache = 'b0; assign m_axi_awlen = 'b0; assign m_axi_awlock = 'b0; assign m_axi_awid = 'b0; assign m_axi_awqos = 'b0; assign m_axi_wlast = 1'b1; assign m_axi_wid = 'b0; assign m_axi_arsize = (C_AXI_DATA_WIDTH == 32) ? 3'd2 : 3'd3; assign m_axi_arburst = 'b0; assign m_axi_arcache = 'b0; assign m_axi_arlen = 'b0; assign m_axi_arlock = 'b0; assign m_axi_arid = 'b0; assign m_axi_arqos = 'b0; assign m_axi_awregion = 'b0; assign m_axi_arregion = 'b0; assign m_axi_awuser = 'b0; assign m_axi_wuser = 'b0; assign m_axi_aruser = 'b0; end endgenerate endmodule
module axi_infrastructure_v1_1_0_axi2vector # ( /////////////////////////////////////////////////////////////////////////////// // Parameter Definitions /////////////////////////////////////////////////////////////////////////////// parameter integer C_AXI_PROTOCOL = 0, parameter integer C_AXI_ID_WIDTH = 4, parameter integer C_AXI_ADDR_WIDTH = 32, parameter integer C_AXI_DATA_WIDTH = 32, parameter integer C_AXI_SUPPORTS_USER_SIGNALS = 0, parameter integer C_AXI_SUPPORTS_REGION_SIGNALS = 0, parameter integer C_AXI_AWUSER_WIDTH = 1, parameter integer C_AXI_WUSER_WIDTH = 1, parameter integer C_AXI_BUSER_WIDTH = 1, parameter integer C_AXI_ARUSER_WIDTH = 1, parameter integer C_AXI_RUSER_WIDTH = 1, parameter integer C_AWPAYLOAD_WIDTH = 61, parameter integer C_WPAYLOAD_WIDTH = 73, parameter integer C_BPAYLOAD_WIDTH = 6, parameter integer C_ARPAYLOAD_WIDTH = 61, parameter integer C_RPAYLOAD_WIDTH = 69 ) ( /////////////////////////////////////////////////////////////////////////////// // Port Declarations /////////////////////////////////////////////////////////////////////////////// // Slave Interface Write Address Ports input wire [C_AXI_ID_WIDTH-1:0] s_axi_awid, input wire [C_AXI_ADDR_WIDTH-1:0] s_axi_awaddr, input wire [((C_AXI_PROTOCOL == 1) ? 4 : 8)-1:0] s_axi_awlen, input wire [3-1:0] s_axi_awsize, input wire [2-1:0] s_axi_awburst, input wire [((C_AXI_PROTOCOL == 1) ? 2 : 1)-1:0] s_axi_awlock, input wire [4-1:0] s_axi_awcache, input wire [3-1:0] s_axi_awprot, input wire [4-1:0] s_axi_awregion, input wire [4-1:0] s_axi_awqos, input wire [C_AXI_AWUSER_WIDTH-1:0] s_axi_awuser, // Slave Interface Write Data Ports input wire [C_AXI_ID_WIDTH-1:0] s_axi_wid, input wire [C_AXI_DATA_WIDTH-1:0] s_axi_wdata, input wire [C_AXI_DATA_WIDTH/8-1:0] s_axi_wstrb, input wire s_axi_wlast, input wire [C_AXI_WUSER_WIDTH-1:0] s_axi_wuser, // Slave Interface Write Response Ports output wire [C_AXI_ID_WIDTH-1:0] s_axi_bid, output wire [2-1:0] s_axi_bresp, output wire [C_AXI_BUSER_WIDTH-1:0] s_axi_buser, // Slave Interface Read Address Ports input wire [C_AXI_ID_WIDTH-1:0] s_axi_arid, input wire [C_AXI_ADDR_WIDTH-1:0] s_axi_araddr, input wire [((C_AXI_PROTOCOL == 1) ? 4 : 8)-1:0] s_axi_arlen, input wire [3-1:0] s_axi_arsize, input wire [2-1:0] s_axi_arburst, input wire [((C_AXI_PROTOCOL == 1) ? 2 : 1)-1:0] s_axi_arlock, input wire [4-1:0] s_axi_arcache, input wire [3-1:0] s_axi_arprot, input wire [4-1:0] s_axi_arregion, input wire [4-1:0] s_axi_arqos, input wire [C_AXI_ARUSER_WIDTH-1:0] s_axi_aruser, // Slave Interface Read Data Ports output wire [C_AXI_ID_WIDTH-1:0] s_axi_rid, output wire [C_AXI_DATA_WIDTH-1:0] s_axi_rdata, output wire [2-1:0] s_axi_rresp, output wire s_axi_rlast, output wire [C_AXI_RUSER_WIDTH-1:0] s_axi_ruser, // payloads output wire [C_AWPAYLOAD_WIDTH-1:0] s_awpayload, output wire [C_WPAYLOAD_WIDTH-1:0] s_wpayload, input wire [C_BPAYLOAD_WIDTH-1:0] s_bpayload, output wire [C_ARPAYLOAD_WIDTH-1:0] s_arpayload, input wire [C_RPAYLOAD_WIDTH-1:0] s_rpayload ); //////////////////////////////////////////////////////////////////////////////// // Functions //////////////////////////////////////////////////////////////////////////////// `include "axi_infrastructure_v1_1_0_header.vh" //////////////////////////////////////////////////////////////////////////////// // Local parameters //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // Wires/Reg declarations //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // BEGIN RTL //////////////////////////////////////////////////////////////////////////////// // AXI4, AXI4LITE, AXI3 packing assign s_awpayload[G_AXI_AWADDR_INDEX+:G_AXI_AWADDR_WIDTH] = s_axi_awaddr; assign s_awpayload[G_AXI_AWPROT_INDEX+:G_AXI_AWPROT_WIDTH] = s_axi_awprot; assign s_wpayload[G_AXI_WDATA_INDEX+:G_AXI_WDATA_WIDTH] = s_axi_wdata; assign s_wpayload[G_AXI_WSTRB_INDEX+:G_AXI_WSTRB_WIDTH] = s_axi_wstrb; assign s_axi_bresp = s_bpayload[G_AXI_BRESP_INDEX+:G_AXI_BRESP_WIDTH]; assign s_arpayload[G_AXI_ARADDR_INDEX+:G_AXI_ARADDR_WIDTH] = s_axi_araddr; assign s_arpayload[G_AXI_ARPROT_INDEX+:G_AXI_ARPROT_WIDTH] = s_axi_arprot; assign s_axi_rdata = s_rpayload[G_AXI_RDATA_INDEX+:G_AXI_RDATA_WIDTH]; assign s_axi_rresp = s_rpayload[G_AXI_RRESP_INDEX+:G_AXI_RRESP_WIDTH]; generate if (C_AXI_PROTOCOL == 0 || C_AXI_PROTOCOL == 1) begin : gen_axi4_or_axi3_packing assign s_awpayload[G_AXI_AWSIZE_INDEX+:G_AXI_AWSIZE_WIDTH] = s_axi_awsize; assign s_awpayload[G_AXI_AWBURST_INDEX+:G_AXI_AWBURST_WIDTH] = s_axi_awburst; assign s_awpayload[G_AXI_AWCACHE_INDEX+:G_AXI_AWCACHE_WIDTH] = s_axi_awcache; assign s_awpayload[G_AXI_AWLEN_INDEX+:G_AXI_AWLEN_WIDTH] = s_axi_awlen; assign s_awpayload[G_AXI_AWLOCK_INDEX+:G_AXI_AWLOCK_WIDTH] = s_axi_awlock; assign s_awpayload[G_AXI_AWID_INDEX+:G_AXI_AWID_WIDTH] = s_axi_awid; assign s_awpayload[G_AXI_AWQOS_INDEX+:G_AXI_AWQOS_WIDTH] = s_axi_awqos; assign s_wpayload[G_AXI_WLAST_INDEX+:G_AXI_WLAST_WIDTH] = s_axi_wlast; if (C_AXI_PROTOCOL == 1) begin : gen_axi3_wid_packing assign s_wpayload[G_AXI_WID_INDEX+:G_AXI_WID_WIDTH] = s_axi_wid; end else begin : gen_no_axi3_wid_packing end assign s_axi_bid = s_bpayload[G_AXI_BID_INDEX+:G_AXI_BID_WIDTH]; assign s_arpayload[G_AXI_ARSIZE_INDEX+:G_AXI_ARSIZE_WIDTH] = s_axi_arsize; assign s_arpayload[G_AXI_ARBURST_INDEX+:G_AXI_ARBURST_WIDTH] = s_axi_arburst; assign s_arpayload[G_AXI_ARCACHE_INDEX+:G_AXI_ARCACHE_WIDTH] = s_axi_arcache; assign s_arpayload[G_AXI_ARLEN_INDEX+:G_AXI_ARLEN_WIDTH] = s_axi_arlen; assign s_arpayload[G_AXI_ARLOCK_INDEX+:G_AXI_ARLOCK_WIDTH] = s_axi_arlock; assign s_arpayload[G_AXI_ARID_INDEX+:G_AXI_ARID_WIDTH] = s_axi_arid; assign s_arpayload[G_AXI_ARQOS_INDEX+:G_AXI_ARQOS_WIDTH] = s_axi_arqos; assign s_axi_rlast = s_rpayload[G_AXI_RLAST_INDEX+:G_AXI_RLAST_WIDTH]; assign s_axi_rid = s_rpayload[G_AXI_RID_INDEX+:G_AXI_RID_WIDTH]; if (C_AXI_SUPPORTS_REGION_SIGNALS == 1 && G_AXI_AWREGION_WIDTH > 0) begin : gen_region_signals assign s_awpayload[G_AXI_AWREGION_INDEX+:G_AXI_AWREGION_WIDTH] = s_axi_awregion; assign s_arpayload[G_AXI_ARREGION_INDEX+:G_AXI_ARREGION_WIDTH] = s_axi_arregion; end else begin : gen_no_region_signals end if (C_AXI_SUPPORTS_USER_SIGNALS == 1 && C_AXI_PROTOCOL != 2) begin : gen_user_signals assign s_awpayload[G_AXI_AWUSER_INDEX+:G_AXI_AWUSER_WIDTH] = s_axi_awuser; assign s_wpayload[G_AXI_WUSER_INDEX+:G_AXI_WUSER_WIDTH] = s_axi_wuser; assign s_axi_buser = s_bpayload[G_AXI_BUSER_INDEX+:G_AXI_BUSER_WIDTH]; assign s_arpayload[G_AXI_ARUSER_INDEX+:G_AXI_ARUSER_WIDTH] = s_axi_aruser; assign s_axi_ruser = s_rpayload[G_AXI_RUSER_INDEX+:G_AXI_RUSER_WIDTH]; end else begin : gen_no_user_signals assign s_axi_buser = 'b0; assign s_axi_ruser = 'b0; end end else begin : gen_axi4lite_packing assign s_axi_bid = 'b0; assign s_axi_buser = 'b0; assign s_axi_rlast = 1'b1; assign s_axi_rid = 'b0; assign s_axi_ruser = 'b0; end endgenerate endmodule
module axi_infrastructure_v1_1_0_axi2vector # ( /////////////////////////////////////////////////////////////////////////////// // Parameter Definitions /////////////////////////////////////////////////////////////////////////////// parameter integer C_AXI_PROTOCOL = 0, parameter integer C_AXI_ID_WIDTH = 4, parameter integer C_AXI_ADDR_WIDTH = 32, parameter integer C_AXI_DATA_WIDTH = 32, parameter integer C_AXI_SUPPORTS_USER_SIGNALS = 0, parameter integer C_AXI_SUPPORTS_REGION_SIGNALS = 0, parameter integer C_AXI_AWUSER_WIDTH = 1, parameter integer C_AXI_WUSER_WIDTH = 1, parameter integer C_AXI_BUSER_WIDTH = 1, parameter integer C_AXI_ARUSER_WIDTH = 1, parameter integer C_AXI_RUSER_WIDTH = 1, parameter integer C_AWPAYLOAD_WIDTH = 61, parameter integer C_WPAYLOAD_WIDTH = 73, parameter integer C_BPAYLOAD_WIDTH = 6, parameter integer C_ARPAYLOAD_WIDTH = 61, parameter integer C_RPAYLOAD_WIDTH = 69 ) ( /////////////////////////////////////////////////////////////////////////////// // Port Declarations /////////////////////////////////////////////////////////////////////////////// // Slave Interface Write Address Ports input wire [C_AXI_ID_WIDTH-1:0] s_axi_awid, input wire [C_AXI_ADDR_WIDTH-1:0] s_axi_awaddr, input wire [((C_AXI_PROTOCOL == 1) ? 4 : 8)-1:0] s_axi_awlen, input wire [3-1:0] s_axi_awsize, input wire [2-1:0] s_axi_awburst, input wire [((C_AXI_PROTOCOL == 1) ? 2 : 1)-1:0] s_axi_awlock, input wire [4-1:0] s_axi_awcache, input wire [3-1:0] s_axi_awprot, input wire [4-1:0] s_axi_awregion, input wire [4-1:0] s_axi_awqos, input wire [C_AXI_AWUSER_WIDTH-1:0] s_axi_awuser, // Slave Interface Write Data Ports input wire [C_AXI_ID_WIDTH-1:0] s_axi_wid, input wire [C_AXI_DATA_WIDTH-1:0] s_axi_wdata, input wire [C_AXI_DATA_WIDTH/8-1:0] s_axi_wstrb, input wire s_axi_wlast, input wire [C_AXI_WUSER_WIDTH-1:0] s_axi_wuser, // Slave Interface Write Response Ports output wire [C_AXI_ID_WIDTH-1:0] s_axi_bid, output wire [2-1:0] s_axi_bresp, output wire [C_AXI_BUSER_WIDTH-1:0] s_axi_buser, // Slave Interface Read Address Ports input wire [C_AXI_ID_WIDTH-1:0] s_axi_arid, input wire [C_AXI_ADDR_WIDTH-1:0] s_axi_araddr, input wire [((C_AXI_PROTOCOL == 1) ? 4 : 8)-1:0] s_axi_arlen, input wire [3-1:0] s_axi_arsize, input wire [2-1:0] s_axi_arburst, input wire [((C_AXI_PROTOCOL == 1) ? 2 : 1)-1:0] s_axi_arlock, input wire [4-1:0] s_axi_arcache, input wire [3-1:0] s_axi_arprot, input wire [4-1:0] s_axi_arregion, input wire [4-1:0] s_axi_arqos, input wire [C_AXI_ARUSER_WIDTH-1:0] s_axi_aruser, // Slave Interface Read Data Ports output wire [C_AXI_ID_WIDTH-1:0] s_axi_rid, output wire [C_AXI_DATA_WIDTH-1:0] s_axi_rdata, output wire [2-1:0] s_axi_rresp, output wire s_axi_rlast, output wire [C_AXI_RUSER_WIDTH-1:0] s_axi_ruser, // payloads output wire [C_AWPAYLOAD_WIDTH-1:0] s_awpayload, output wire [C_WPAYLOAD_WIDTH-1:0] s_wpayload, input wire [C_BPAYLOAD_WIDTH-1:0] s_bpayload, output wire [C_ARPAYLOAD_WIDTH-1:0] s_arpayload, input wire [C_RPAYLOAD_WIDTH-1:0] s_rpayload ); //////////////////////////////////////////////////////////////////////////////// // Functions //////////////////////////////////////////////////////////////////////////////// `include "axi_infrastructure_v1_1_0_header.vh" //////////////////////////////////////////////////////////////////////////////// // Local parameters //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // Wires/Reg declarations //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // BEGIN RTL //////////////////////////////////////////////////////////////////////////////// // AXI4, AXI4LITE, AXI3 packing assign s_awpayload[G_AXI_AWADDR_INDEX+:G_AXI_AWADDR_WIDTH] = s_axi_awaddr; assign s_awpayload[G_AXI_AWPROT_INDEX+:G_AXI_AWPROT_WIDTH] = s_axi_awprot; assign s_wpayload[G_AXI_WDATA_INDEX+:G_AXI_WDATA_WIDTH] = s_axi_wdata; assign s_wpayload[G_AXI_WSTRB_INDEX+:G_AXI_WSTRB_WIDTH] = s_axi_wstrb; assign s_axi_bresp = s_bpayload[G_AXI_BRESP_INDEX+:G_AXI_BRESP_WIDTH]; assign s_arpayload[G_AXI_ARADDR_INDEX+:G_AXI_ARADDR_WIDTH] = s_axi_araddr; assign s_arpayload[G_AXI_ARPROT_INDEX+:G_AXI_ARPROT_WIDTH] = s_axi_arprot; assign s_axi_rdata = s_rpayload[G_AXI_RDATA_INDEX+:G_AXI_RDATA_WIDTH]; assign s_axi_rresp = s_rpayload[G_AXI_RRESP_INDEX+:G_AXI_RRESP_WIDTH]; generate if (C_AXI_PROTOCOL == 0 || C_AXI_PROTOCOL == 1) begin : gen_axi4_or_axi3_packing assign s_awpayload[G_AXI_AWSIZE_INDEX+:G_AXI_AWSIZE_WIDTH] = s_axi_awsize; assign s_awpayload[G_AXI_AWBURST_INDEX+:G_AXI_AWBURST_WIDTH] = s_axi_awburst; assign s_awpayload[G_AXI_AWCACHE_INDEX+:G_AXI_AWCACHE_WIDTH] = s_axi_awcache; assign s_awpayload[G_AXI_AWLEN_INDEX+:G_AXI_AWLEN_WIDTH] = s_axi_awlen; assign s_awpayload[G_AXI_AWLOCK_INDEX+:G_AXI_AWLOCK_WIDTH] = s_axi_awlock; assign s_awpayload[G_AXI_AWID_INDEX+:G_AXI_AWID_WIDTH] = s_axi_awid; assign s_awpayload[G_AXI_AWQOS_INDEX+:G_AXI_AWQOS_WIDTH] = s_axi_awqos; assign s_wpayload[G_AXI_WLAST_INDEX+:G_AXI_WLAST_WIDTH] = s_axi_wlast; if (C_AXI_PROTOCOL == 1) begin : gen_axi3_wid_packing assign s_wpayload[G_AXI_WID_INDEX+:G_AXI_WID_WIDTH] = s_axi_wid; end else begin : gen_no_axi3_wid_packing end assign s_axi_bid = s_bpayload[G_AXI_BID_INDEX+:G_AXI_BID_WIDTH]; assign s_arpayload[G_AXI_ARSIZE_INDEX+:G_AXI_ARSIZE_WIDTH] = s_axi_arsize; assign s_arpayload[G_AXI_ARBURST_INDEX+:G_AXI_ARBURST_WIDTH] = s_axi_arburst; assign s_arpayload[G_AXI_ARCACHE_INDEX+:G_AXI_ARCACHE_WIDTH] = s_axi_arcache; assign s_arpayload[G_AXI_ARLEN_INDEX+:G_AXI_ARLEN_WIDTH] = s_axi_arlen; assign s_arpayload[G_AXI_ARLOCK_INDEX+:G_AXI_ARLOCK_WIDTH] = s_axi_arlock; assign s_arpayload[G_AXI_ARID_INDEX+:G_AXI_ARID_WIDTH] = s_axi_arid; assign s_arpayload[G_AXI_ARQOS_INDEX+:G_AXI_ARQOS_WIDTH] = s_axi_arqos; assign s_axi_rlast = s_rpayload[G_AXI_RLAST_INDEX+:G_AXI_RLAST_WIDTH]; assign s_axi_rid = s_rpayload[G_AXI_RID_INDEX+:G_AXI_RID_WIDTH]; if (C_AXI_SUPPORTS_REGION_SIGNALS == 1 && G_AXI_AWREGION_WIDTH > 0) begin : gen_region_signals assign s_awpayload[G_AXI_AWREGION_INDEX+:G_AXI_AWREGION_WIDTH] = s_axi_awregion; assign s_arpayload[G_AXI_ARREGION_INDEX+:G_AXI_ARREGION_WIDTH] = s_axi_arregion; end else begin : gen_no_region_signals end if (C_AXI_SUPPORTS_USER_SIGNALS == 1 && C_AXI_PROTOCOL != 2) begin : gen_user_signals assign s_awpayload[G_AXI_AWUSER_INDEX+:G_AXI_AWUSER_WIDTH] = s_axi_awuser; assign s_wpayload[G_AXI_WUSER_INDEX+:G_AXI_WUSER_WIDTH] = s_axi_wuser; assign s_axi_buser = s_bpayload[G_AXI_BUSER_INDEX+:G_AXI_BUSER_WIDTH]; assign s_arpayload[G_AXI_ARUSER_INDEX+:G_AXI_ARUSER_WIDTH] = s_axi_aruser; assign s_axi_ruser = s_rpayload[G_AXI_RUSER_INDEX+:G_AXI_RUSER_WIDTH]; end else begin : gen_no_user_signals assign s_axi_buser = 'b0; assign s_axi_ruser = 'b0; end end else begin : gen_axi4lite_packing assign s_axi_bid = 'b0; assign s_axi_buser = 'b0; assign s_axi_rlast = 1'b1; assign s_axi_rid = 'b0; assign s_axi_ruser = 'b0; end endgenerate endmodule
module generic_baseblocks_v2_1_0_comparator_sel_static # ( parameter C_FAMILY = "virtex6", // FPGA Family. Current version: virtex6 or spartan6. parameter C_VALUE = 4'b0, // Static value to compare against. parameter integer C_DATA_WIDTH = 4 // Data width for comparator. ) ( input wire CIN, input wire S, input wire [C_DATA_WIDTH-1:0] A, input wire [C_DATA_WIDTH-1:0] B, output wire COUT ); ///////////////////////////////////////////////////////////////////////////// // Variables for generating parameter controlled instances. ///////////////////////////////////////////////////////////////////////////// // Generate variable for bit vector. genvar bit_cnt; ///////////////////////////////////////////////////////////////////////////// // Local params ///////////////////////////////////////////////////////////////////////////// // Bits per LUT for this architecture. localparam integer C_BITS_PER_LUT = 2; // Constants for packing levels. localparam integer C_NUM_LUT = ( C_DATA_WIDTH + C_BITS_PER_LUT - 1 ) / C_BITS_PER_LUT; // localparam integer C_FIX_DATA_WIDTH = ( C_NUM_LUT * C_BITS_PER_LUT > C_DATA_WIDTH ) ? C_NUM_LUT * C_BITS_PER_LUT : C_DATA_WIDTH; ///////////////////////////////////////////////////////////////////////////// // Functions ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Internal signals ///////////////////////////////////////////////////////////////////////////// wire [C_FIX_DATA_WIDTH-1:0] a_local; wire [C_FIX_DATA_WIDTH-1:0] b_local; wire [C_FIX_DATA_WIDTH-1:0] v_local; wire [C_NUM_LUT-1:0] sel; wire [C_NUM_LUT:0] carry_local; ///////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////// generate // Assign input to local vectors. assign carry_local[0] = CIN; // Extend input data to fit. if ( C_NUM_LUT * C_BITS_PER_LUT > C_DATA_WIDTH ) begin : USE_EXTENDED_DATA assign a_local = {A, {C_NUM_LUT * C_BITS_PER_LUT - C_DATA_WIDTH{1'b0}}}; assign b_local = {B, {C_NUM_LUT * C_BITS_PER_LUT - C_DATA_WIDTH{1'b0}}}; assign v_local = {C_VALUE, {C_NUM_LUT * C_BITS_PER_LUT - C_DATA_WIDTH{1'b0}}}; end else begin : NO_EXTENDED_DATA assign a_local = A; assign b_local = B; assign v_local = C_VALUE; end // Instantiate one generic_baseblocks_v2_1_0_carry and per level. for (bit_cnt = 0; bit_cnt < C_NUM_LUT ; bit_cnt = bit_cnt + 1) begin : LUT_LEVEL // Create the local select signal assign sel[bit_cnt] = ( ( a_local[bit_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] == v_local[bit_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] ) & ( S == 1'b0 ) ) | ( ( b_local[bit_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] == v_local[bit_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] ) & ( S == 1'b1 ) ); // Instantiate each LUT level. generic_baseblocks_v2_1_0_carry_and # ( .C_FAMILY(C_FAMILY) ) compare_inst ( .COUT (carry_local[bit_cnt+1]), .CIN (carry_local[bit_cnt]), .S (sel[bit_cnt]) ); end // end for bit_cnt // Assign output from local vector. assign COUT = carry_local[C_NUM_LUT]; endgenerate endmodule
module generic_baseblocks_v2_1_0_comparator # ( parameter C_FAMILY = "virtex6", // FPGA Family. Current version: virtex6 or spartan6. parameter integer C_DATA_WIDTH = 4 // Data width for comparator. ) ( input wire CIN, input wire [C_DATA_WIDTH-1:0] A, input wire [C_DATA_WIDTH-1:0] B, output wire COUT ); ///////////////////////////////////////////////////////////////////////////// // Variables for generating parameter controlled instances. ///////////////////////////////////////////////////////////////////////////// // Generate variable for bit vector. genvar bit_cnt; ///////////////////////////////////////////////////////////////////////////// // Local params ///////////////////////////////////////////////////////////////////////////// // Bits per LUT for this architecture. localparam integer C_BITS_PER_LUT = 3; // Constants for packing levels. localparam integer C_NUM_LUT = ( C_DATA_WIDTH + C_BITS_PER_LUT - 1 ) / C_BITS_PER_LUT; // localparam integer C_FIX_DATA_WIDTH = ( C_NUM_LUT * C_BITS_PER_LUT > C_DATA_WIDTH ) ? C_NUM_LUT * C_BITS_PER_LUT : C_DATA_WIDTH; ///////////////////////////////////////////////////////////////////////////// // Functions ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Internal signals ///////////////////////////////////////////////////////////////////////////// wire [C_FIX_DATA_WIDTH-1:0] a_local; wire [C_FIX_DATA_WIDTH-1:0] b_local; wire [C_NUM_LUT-1:0] sel; wire [C_NUM_LUT:0] carry_local; ///////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////// generate // Assign input to local vectors. assign carry_local[0] = CIN; // Extend input data to fit. if ( C_NUM_LUT * C_BITS_PER_LUT > C_DATA_WIDTH ) begin : USE_EXTENDED_DATA assign a_local = {A, {C_NUM_LUT * C_BITS_PER_LUT - C_DATA_WIDTH{1'b0}}}; assign b_local = {B, {C_NUM_LUT * C_BITS_PER_LUT - C_DATA_WIDTH{1'b0}}}; end else begin : NO_EXTENDED_DATA assign a_local = A; assign b_local = B; end // Instantiate one generic_baseblocks_v2_1_0_carry and per level. for (bit_cnt = 0; bit_cnt < C_NUM_LUT ; bit_cnt = bit_cnt + 1) begin : LUT_LEVEL // Create the local select signal assign sel[bit_cnt] = ( a_local[bit_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] == b_local[bit_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] ); // Instantiate each LUT level. generic_baseblocks_v2_1_0_carry_and # ( .C_FAMILY(C_FAMILY) ) compare_inst ( .COUT (carry_local[bit_cnt+1]), .CIN (carry_local[bit_cnt]), .S (sel[bit_cnt]) ); end // end for bit_cnt // Assign output from local vector. assign COUT = carry_local[C_NUM_LUT]; endgenerate endmodule
module generic_baseblocks_v2_1_0_comparator # ( parameter C_FAMILY = "virtex6", // FPGA Family. Current version: virtex6 or spartan6. parameter integer C_DATA_WIDTH = 4 // Data width for comparator. ) ( input wire CIN, input wire [C_DATA_WIDTH-1:0] A, input wire [C_DATA_WIDTH-1:0] B, output wire COUT ); ///////////////////////////////////////////////////////////////////////////// // Variables for generating parameter controlled instances. ///////////////////////////////////////////////////////////////////////////// // Generate variable for bit vector. genvar bit_cnt; ///////////////////////////////////////////////////////////////////////////// // Local params ///////////////////////////////////////////////////////////////////////////// // Bits per LUT for this architecture. localparam integer C_BITS_PER_LUT = 3; // Constants for packing levels. localparam integer C_NUM_LUT = ( C_DATA_WIDTH + C_BITS_PER_LUT - 1 ) / C_BITS_PER_LUT; // localparam integer C_FIX_DATA_WIDTH = ( C_NUM_LUT * C_BITS_PER_LUT > C_DATA_WIDTH ) ? C_NUM_LUT * C_BITS_PER_LUT : C_DATA_WIDTH; ///////////////////////////////////////////////////////////////////////////// // Functions ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Internal signals ///////////////////////////////////////////////////////////////////////////// wire [C_FIX_DATA_WIDTH-1:0] a_local; wire [C_FIX_DATA_WIDTH-1:0] b_local; wire [C_NUM_LUT-1:0] sel; wire [C_NUM_LUT:0] carry_local; ///////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////// generate // Assign input to local vectors. assign carry_local[0] = CIN; // Extend input data to fit. if ( C_NUM_LUT * C_BITS_PER_LUT > C_DATA_WIDTH ) begin : USE_EXTENDED_DATA assign a_local = {A, {C_NUM_LUT * C_BITS_PER_LUT - C_DATA_WIDTH{1'b0}}}; assign b_local = {B, {C_NUM_LUT * C_BITS_PER_LUT - C_DATA_WIDTH{1'b0}}}; end else begin : NO_EXTENDED_DATA assign a_local = A; assign b_local = B; end // Instantiate one generic_baseblocks_v2_1_0_carry and per level. for (bit_cnt = 0; bit_cnt < C_NUM_LUT ; bit_cnt = bit_cnt + 1) begin : LUT_LEVEL // Create the local select signal assign sel[bit_cnt] = ( a_local[bit_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] == b_local[bit_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] ); // Instantiate each LUT level. generic_baseblocks_v2_1_0_carry_and # ( .C_FAMILY(C_FAMILY) ) compare_inst ( .COUT (carry_local[bit_cnt+1]), .CIN (carry_local[bit_cnt]), .S (sel[bit_cnt]) ); end // end for bit_cnt // Assign output from local vector. assign COUT = carry_local[C_NUM_LUT]; endgenerate endmodule
module generic_baseblocks_v2_1_0_comparator # ( parameter C_FAMILY = "virtex6", // FPGA Family. Current version: virtex6 or spartan6. parameter integer C_DATA_WIDTH = 4 // Data width for comparator. ) ( input wire CIN, input wire [C_DATA_WIDTH-1:0] A, input wire [C_DATA_WIDTH-1:0] B, output wire COUT ); ///////////////////////////////////////////////////////////////////////////// // Variables for generating parameter controlled instances. ///////////////////////////////////////////////////////////////////////////// // Generate variable for bit vector. genvar bit_cnt; ///////////////////////////////////////////////////////////////////////////// // Local params ///////////////////////////////////////////////////////////////////////////// // Bits per LUT for this architecture. localparam integer C_BITS_PER_LUT = 3; // Constants for packing levels. localparam integer C_NUM_LUT = ( C_DATA_WIDTH + C_BITS_PER_LUT - 1 ) / C_BITS_PER_LUT; // localparam integer C_FIX_DATA_WIDTH = ( C_NUM_LUT * C_BITS_PER_LUT > C_DATA_WIDTH ) ? C_NUM_LUT * C_BITS_PER_LUT : C_DATA_WIDTH; ///////////////////////////////////////////////////////////////////////////// // Functions ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Internal signals ///////////////////////////////////////////////////////////////////////////// wire [C_FIX_DATA_WIDTH-1:0] a_local; wire [C_FIX_DATA_WIDTH-1:0] b_local; wire [C_NUM_LUT-1:0] sel; wire [C_NUM_LUT:0] carry_local; ///////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////// generate // Assign input to local vectors. assign carry_local[0] = CIN; // Extend input data to fit. if ( C_NUM_LUT * C_BITS_PER_LUT > C_DATA_WIDTH ) begin : USE_EXTENDED_DATA assign a_local = {A, {C_NUM_LUT * C_BITS_PER_LUT - C_DATA_WIDTH{1'b0}}}; assign b_local = {B, {C_NUM_LUT * C_BITS_PER_LUT - C_DATA_WIDTH{1'b0}}}; end else begin : NO_EXTENDED_DATA assign a_local = A; assign b_local = B; end // Instantiate one generic_baseblocks_v2_1_0_carry and per level. for (bit_cnt = 0; bit_cnt < C_NUM_LUT ; bit_cnt = bit_cnt + 1) begin : LUT_LEVEL // Create the local select signal assign sel[bit_cnt] = ( a_local[bit_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] == b_local[bit_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] ); // Instantiate each LUT level. generic_baseblocks_v2_1_0_carry_and # ( .C_FAMILY(C_FAMILY) ) compare_inst ( .COUT (carry_local[bit_cnt+1]), .CIN (carry_local[bit_cnt]), .S (sel[bit_cnt]) ); end // end for bit_cnt // Assign output from local vector. assign COUT = carry_local[C_NUM_LUT]; endgenerate endmodule
module will barrelshift the data from the FIFO when unaligned accesses is enabled (we are using part of the FIFO word when off boundary). When unaligned accesses is disabled then the data passes as wires. The byte enable generator might require multiple cycles to perform partial accesses so a 'stall' bit is used (triggers a stall like waitrequest) */ ST_to_MM_Adapter the_ST_to_MM_Adapter ( .clk (clk), .reset (reset), .enable (st_to_mm_adapter_enable), .address (descriptor_address[ADDRESS_WIDTH-1:0]), .start (go), .waitrequest (master_waitrequest), .stall (write_stall_from_byte_enable_generator | write_stall_from_write_burst_control), .write_data (master_writedata), .fifo_data (buffered_data), .fifo_empty (fifo_empty), .fifo_readack (fifo_read) ); defparam the_ST_to_MM_Adapter.DATA_WIDTH = DATA_WIDTH; defparam the_ST_to_MM_Adapter.BYTEENABLE_WIDTH_LOG2 = BYTE_ENABLE_WIDTH_LOG2; defparam the_ST_to_MM_Adapter.ADDRESS_WIDTH = ADDRESS_WIDTH; defparam the_ST_to_MM_Adapter.UNALIGNED_ACCESS_ENABLE = UNALIGNED_ACCESSES_ENABLE; /* this block is responsible for presenting the fabric with supported byte enable combinations which can take multiple cycles, if full word only support is enabled this block will reduce to wires during synthesis */ byte_enable_generator the_byte_enable_generator ( .clk (clk), .reset (reset), .write_in (write), .byteenable_in (unsupported_byteenable), .waitrequest_out (write_stall_from_byte_enable_generator), .byteenable_out (supported_byteenable), .waitrequest_in (master_waitrequest | write_stall_from_write_burst_control) ); defparam the_byte_enable_generator.BYTEENABLE_WIDTH = BYTE_ENABLE_WIDTH; // this block will be used to drive write, address, and burstcount to the fabric write_burst_control the_write_burst_control ( .clk (clk), .reset (reset), .sw_reset (sw_reset_in), .sw_stop (sw_stop_in), .length (length_counter), .eop_enabled (descriptor_end_on_eop_enable_d1), .eop (snk_eop), .ready (snk_ready), .valid (snk_valid), .early_termination (early_termination), .address_in (address), .write_in (write), .max_burst_count (maximum_burst_count), .write_fifo_used ({fifo_full,fifo_used}), .waitrequest (master_waitrequest), .short_first_access_enable (short_first_access_enable), .short_last_access_enable (short_last_access_enable), .short_first_and_last_access_enable (short_first_and_last_access_enable), .address_out (master_address), .write_out (master_write), // filtered version of 'write' .burst_count (master_burstcount), .stall (write_stall_from_write_burst_control), .reset_taken (reset_taken_from_write_burst_control), .stopped (stopped_from_write_burst_control) ); defparam the_write_burst_control.BURST_ENABLE = BURST_ENABLE; defparam the_write_burst_control.BURST_COUNT_WIDTH = MAX_BURST_COUNT_WIDTH; defparam the_write_burst_control.WORD_SIZE = BYTE_ENABLE_WIDTH; defparam the_write_burst_control.WORD_SIZE_LOG2 = (DATA_WIDTH == 8)? 0 : BYTE_ENABLE_WIDTH_LOG2; // need to make sure log2(word size) is 0 instead of 1 here when the data width is 8 bits defparam the_write_burst_control.ADDRESS_WIDTH = ADDRESS_WIDTH; defparam the_write_burst_control.LENGTH_WIDTH = LENGTH_WIDTH; defparam the_write_burst_control.WRITE_FIFO_USED_WIDTH = FIFO_DEPTH_LOG2; defparam the_write_burst_control.BURST_WRAPPING_SUPPORT = BURST_WRAPPING_SUPPORT; /********************************************* END MODULE INSTANTIATIONS ************************************************************************/ /********************************************* CONTROL AND COMBINATIONAL SIGNALS ****************************************************************/ // breakout the descriptor information into more manageable names assign descriptor_address = {snk_command_data[123:92], snk_command_data[31:0]}; // 64-bit addressing support assign descriptor_length = snk_command_data[63:32]; assign descriptor_programmable_burst_count = snk_command_data[75:68]; assign descriptor_stride = snk_command_data[91:76]; assign descriptor_end_on_eop_enable = snk_command_data[64]; assign sw_stop_in = snk_command_data[66]; assign sw_reset_in = snk_command_data[67]; assign stride_amount = (STRIDE_ENABLE == 1)? stride_d1[STRIDE_WIDTH-1:0] : FIXED_STRIDE; // hardcoding to FIXED_STRIDE when stride capabilities are disabled assign maximum_burst_count = (PROGRAMMABLE_BURST_ENABLE == 1)? programmable_burst_count_d1 : MAX_BURST_COUNT; assign eop_enable = (PACKET_ENABLE == 1)? descriptor_end_on_eop_enable_d1 : 1'b0; // no eop or early termination support when packet support is disabled assign done_strobe = (done == 1) & (done_d1 == 0) & (reset_taken == 0); // set_done asserts the done register so this strobe fires when the last write completes assign response_error = (ERROR_ENABLE == 1)? error : 8'b00000000; assign response_actual_bytes_transferred = (PACKET_ENABLE == 1)? actual_bytes_transferred_counter : 32'h00000000; // transfer size amounts for special cases (starting unaligned, ending with a partial word, starting unaligned and ending with a partial word on the same write) assign short_first_access_size = BYTE_ENABLE_WIDTH - start_byte_address; assign short_last_access_size = (eop_enable == 1)? (packet_beat_size + packet_bytes_buffered_d1) : (length_counter & LSB_MASK); assign short_first_and_last_access_size = (eop_enable == 1)? (BYTE_ENABLE_WIDTH - buffered_empty) : (length_counter & LSB_MASK); /* special case transfer enables and counter increment values (address_counter, length_counter, and actual_bytes_transferred) short_first_access_enable is for transfers that start aligned but reach the next word boundary short_last_access_enable is for transfers that are not the first transfer but don't end with on a word boundary short_first_and_last_access_enable is for transfers that start and end with a single transfer and don't end on a word boundary (may or may not be aligned) */ generate if (UNALIGNED_ACCESSES_ENABLE == 1) begin // all three enables are mutually exclusive to provide one-hot encoding for the bytes to transfer mux assign short_first_access_enable = (start_byte_address != 0) & (first_access == 1) & ((eop_enable == 1)? ((start_byte_address + BYTE_ENABLE_WIDTH - buffered_empty) >= BYTE_ENABLE_WIDTH) : (first_word_boundary_not_reached_d1 == 0)); assign short_last_access_enable = (first_access == 0) & ((eop_enable == 1)? ((packet_beat_size + packet_bytes_buffered_d1) < BYTE_ENABLE_WIDTH): (length_counter < BYTE_ENABLE_WIDTH)); assign short_first_and_last_access_enable = (first_access == 1) & ((eop_enable == 1)? ((start_byte_address + BYTE_ENABLE_WIDTH - buffered_empty) < BYTE_ENABLE_WIDTH) : (first_word_boundary_not_reached_d1 == 1)); assign bytes_to_transfer = bytes_to_transfer_mux; assign address_increment = bytes_to_transfer_mux; // can't use stride when unaligned accesses are enabled end else if (ONLY_FULL_ACCESS_ENABLE == 1) begin assign short_first_access_enable = 0; assign short_last_access_enable = 0; assign short_first_and_last_access_enable = 0; assign bytes_to_transfer = BYTE_ENABLE_WIDTH; if (STRIDE_ENABLE == 1) begin assign address_increment = BYTE_ENABLE_WIDTH * stride_amount; // the byte address portion of the address_counter is grounded to make sure the address presented to the fabric is aligned end else begin assign address_increment = BYTE_ENABLE_WIDTH; // the byte address portion of the address_counter is grounded to make sure the address presented to the fabric is aligned end end else // must be aligned but can end with any number of bytes begin assign short_first_access_enable = 0; assign short_last_access_enable = (eop_enable == 1)? (buffered_eop == 1) : (length_counter < BYTE_ENABLE_WIDTH); // less than a word to transfer assign short_first_and_last_access_enable = 0; assign bytes_to_transfer = bytes_to_transfer_mux; if (STRIDE_ENABLE == 1) begin assign address_increment = BYTE_ENABLE_WIDTH * stride_amount; end else begin assign address_increment = BYTE_ENABLE_WIDTH; end end endgenerate // the control logic ensures this mux is one-hot with the fall through being the typical full word aligned access always @ (short_first_access_enable or short_last_access_enable or short_first_and_last_access_enable or short_first_access_size or short_last_access_size or short_first_and_last_access_size) begin case ({short_first_and_last_access_enable, short_last_access_enable, short_first_access_enable}) 3'b001: bytes_to_transfer_mux = short_first_access_size; // unaligned and reaches the next word boundary 3'b010: bytes_to_transfer_mux = short_last_access_size; // aligned and does not reach the next word boundary 3'b100: bytes_to_transfer_mux = short_first_and_last_access_size; // unaligned and does not reach the next word boundary default: bytes_to_transfer_mux = BYTE_ENABLE_WIDTH; // aligned and reaches the next word boundary (i.e. a full word transfer) endcase end // Avalon-ST is network order (a.k.a. big endian) so we need to reverse the symbols before jamming them into the FIFO, changing the symbol width to something other than 8 might break something... generate genvar i; for(i = 0; i < DATA_WIDTH; i = i + SYMBOL_WIDTH) // the data width is always a multiple of the symbol width begin: symbol_swap assign fifo_write_data[i +SYMBOL_WIDTH -1: i] = snk_data[DATA_WIDTH -i -1: DATA_WIDTH -i - SYMBOL_WIDTH]; end endgenerate // sticking the error, empty, eop, and eop bits at the top of the FIFO write data, flooring empty to zero when eop is not asserted (empty is only valid on eop cycles) assign fifo_write_data[FIFO_WIDTH-1:DATA_WIDTH] = {snk_error, (snk_eop == 1)? snk_empty:0, snk_sop, snk_eop}; // swap the bytes if big endian is enabled (remember that this isn't tested so use at your own risk and make sure you understand the software impact this has) generate if(BIG_ENDIAN_ACCESS == 1) begin genvar j; for(j=0; j < DATA_WIDTH; j = j + 8) begin: byte_swap assign fifo_read_data_rearranged[j +8 -1: j] = fifo_read_data[DATA_WIDTH -j -1: DATA_WIDTH -j - 8]; assign master_byteenable[j/8] = supported_byteenable[(DATA_WIDTH -j -1)/8]; end end else begin assign fifo_read_data_rearranged = fifo_read_data[DATA_WIDTH-1:0]; // little endian so no byte swapping necessary assign master_byteenable = supported_byteenable; // dito end endgenerate // fifo read data is in the format of {error, empty, sop, eop, data} with the following widths {ERROR_WIDTH, NUMBER_OF_SYMBOLS_LOG2, 1, 1, DATA_WIDTH} assign buffered_data = fifo_read_data_rearranged; assign buffered_error = fifo_read_data[DATA_WIDTH +2 +NUMBER_OF_SYMBOLS_LOG2 + ERROR_WIDTH -1: DATA_WIDTH +2 +NUMBER_OF_SYMBOLS_LOG2]; generate if (PACKET_ENABLE == 1) begin assign buffered_eop = fifo_read_data[DATA_WIDTH]; assign buffered_sop = fifo_read_data[DATA_WIDTH +1]; if (ONLY_FULL_ACCESS_ENABLE == 1) begin assign buffered_empty = 0; // ignore the empty signal and assume it was a full beat end else begin assign buffered_empty = fifo_read_data[DATA_WIDTH +2 +NUMBER_OF_SYMBOLS_LOG2 -1: DATA_WIDTH +2]; // empty is packed into the upper FIFO bits end end else begin assign buffered_empty = 0; assign buffered_eop = 0; assign buffered_sop = 0; end endgenerate /* Generating mask bits based on the size of the transfer before the unaligned access adjustment. This is based on the transfer size to determine how many byte enables would be asserted in the aligned case. Afterwards the byte enables will be shifted left based on how far out of alignment the address counter is (should only happen for the first transfer). If the data path is 32 bits wide then the following masks are generated: Transfer Size Index Mask 1 0 0001 2 1 0011 3 2 0111 4 3 1111 Note that the index is just the transfer size minus one */ generate if (BYTE_ENABLE_WIDTH > 1) begin genvar k; for (k = 0; k < BYTE_ENABLE_WIDTH; k = k + 1) begin: byte_enable_loop assign byteenable_masks[k] = { {(BYTE_ENABLE_WIDTH-k-1){1'b0}}, {(k+1){1'b1}} }; // Byte enable width - k zeros followed by k ones end end else begin assign byteenable_masks[0] = 1'b1; // will be stubbed at top level end endgenerate /* byteenable_mask is based on an aligned access determined by the transfer size. This value is then shifted to the left by the unaligned offset (first transfer only) to compensate for the unaligned offset so that the correct byte enables are enabled. When the accesses are aligned then no barrelshifting is needed and when full accesses are used then all byte enables will be asserted always. */ generate if (ONLY_FULL_ACCESS_ENABLE == 1) begin assign unsupported_byteenable = {BYTE_ENABLE_WIDTH{1'b1}}; // always full accesses so the byte enables are all ones end else if (UNALIGNED_ACCESSES_ENABLE == 0) begin assign unsupported_byteenable = byteenable_masks[bytes_to_transfer_mux - 1]; // aligned so no unaligned adjustment required end else // unaligned case begin assign unsupported_byteenable = byteenable_masks[bytes_to_transfer_mux - 1] << (address_counter & LSB_MASK); // barrelshift adjusts for unaligned start address end endgenerate generate if (BYTE_ENABLE_WIDTH > 1) begin assign address = address_counter & { {(ADDRESS_WIDTH-BYTE_ENABLE_WIDTH_LOG2){1'b1}}, {BYTE_ENABLE_WIDTH_LOG2{1'b0}} }; // masking LSBs (byte offsets) since the address counter might not be aligned for the first transfer end else begin assign address = address_counter; // don't need to mask any bits as the address will only advance one byte at a time end endgenerate assign done = (length_counter == 0) | ((PACKET_ENABLE == 1) & (eop_enable == 1) & (eop_seen == 1) & (extra_write == 0)); assign packet_beat_size = (eop_seen == 1) ? 0 : (BYTE_ENABLE_WIDTH - buffered_empty); // when the eop arrives we can't add more to packet_bytes_buffered_d1 assign packet_bytes_buffered = packet_beat_size + packet_bytes_buffered_d1 - bytes_to_transfer; // extra_write is only applicable when unaligned accesses are performed. This extra access gets the remaining data buffered in the ST to MM adapter block written to memory assign extra_write = (UNALIGNED_ACCESSES_ENABLE == 1) & (((PACKET_ENABLE == 1) & (eop_enable == 1))? ((eop_seen == 1) & (packet_bytes_buffered_d1 != 0)) : // when packets are used if there are left over bytes buffered after eop is seen perform an extra write ((first_access == 0) & (start_byte_address != 0) & (short_last_access_enable == 1) & (start_byte_address >= length_counter[BYTE_ENABLE_WIDTH_LOG2-1:0]))); // non-packet transfer and there are extra bytes buffered so performing an extra access assign first_word_boundary_not_reached = (descriptor_length < BYTE_ENABLE_WIDTH) & // length is less than the word size (((descriptor_length & LSB_MASK) + (descriptor_address & LSB_MASK)) < BYTE_ENABLE_WIDTH); // start address + length doesn't reach the next word boundary (not used for packet transfers) assign write = ((fifo_empty == 0) | (extra_write == 1)) & (done == 0) & (stopped == 0); assign st_to_mm_adapter_enable = (done == 0) & (extra_write == 0); assign write_complete = (write == 1) & (master_waitrequest == 0) & (write_stall_from_byte_enable_generator == 0) & (write_stall_from_write_burst_control == 0); // writing still occuring and no reasons to prevent the write cycle from completing assign increment_address = ((write == 1) & (write_complete == 1)) & (stopped == 0); assign go = (snk_command_valid == 1) & (snk_command_ready == 1); // go with be one cycle since done will be set to 0 on the next cycle (length will be non-zero) assign snk_ready = (fifo_full == 0) & // need to make sure more streaming data doesn't come in when the FIFO is full (((PACKET_ENABLE == 1) & (snk_sop == 1) & (fifo_empty == 0)) != 1); // need to make sure that only one packet is buffered at any given time (sop will continue to be asserted until the buffer is written out) assign length_sync_reset = (((reset_taken == 1) | (early_termination_d1 == 1)) & (done == 0)) | (done_strobe == 1); // abrupt stop cases or packet transfer just completed (otherwise the length register will reach 0 by itself) assign fifo_write = (snk_ready == 1) & (snk_valid == 1); assign early_termination = (eop_enable == 1) & (write_complete == 1) & (length_counter < bytes_to_transfer); // packet transfer and the length counter is about to roll over so stop transfering assign stop_state = stopped; assign reset_delayed = (reset_taken == 0) & (sw_reset_in == 1); assign src_response_data = {{212{1'b0}}, done_strobe, early_termination_d1, response_error, stop_state, reset_delayed, response_actual_bytes_transferred}; /********************************************* END CONTROL AND COMBINATIONAL SIGNALS ************************************************************/ endmodule
module will barrelshift the data from the FIFO when unaligned accesses is enabled (we are using part of the FIFO word when off boundary). When unaligned accesses is disabled then the data passes as wires. The byte enable generator might require multiple cycles to perform partial accesses so a 'stall' bit is used (triggers a stall like waitrequest) */ ST_to_MM_Adapter the_ST_to_MM_Adapter ( .clk (clk), .reset (reset), .enable (st_to_mm_adapter_enable), .address (descriptor_address[ADDRESS_WIDTH-1:0]), .start (go), .waitrequest (master_waitrequest), .stall (write_stall_from_byte_enable_generator | write_stall_from_write_burst_control), .write_data (master_writedata), .fifo_data (buffered_data), .fifo_empty (fifo_empty), .fifo_readack (fifo_read) ); defparam the_ST_to_MM_Adapter.DATA_WIDTH = DATA_WIDTH; defparam the_ST_to_MM_Adapter.BYTEENABLE_WIDTH_LOG2 = BYTE_ENABLE_WIDTH_LOG2; defparam the_ST_to_MM_Adapter.ADDRESS_WIDTH = ADDRESS_WIDTH; defparam the_ST_to_MM_Adapter.UNALIGNED_ACCESS_ENABLE = UNALIGNED_ACCESSES_ENABLE; /* this block is responsible for presenting the fabric with supported byte enable combinations which can take multiple cycles, if full word only support is enabled this block will reduce to wires during synthesis */ byte_enable_generator the_byte_enable_generator ( .clk (clk), .reset (reset), .write_in (write), .byteenable_in (unsupported_byteenable), .waitrequest_out (write_stall_from_byte_enable_generator), .byteenable_out (supported_byteenable), .waitrequest_in (master_waitrequest | write_stall_from_write_burst_control) ); defparam the_byte_enable_generator.BYTEENABLE_WIDTH = BYTE_ENABLE_WIDTH; // this block will be used to drive write, address, and burstcount to the fabric write_burst_control the_write_burst_control ( .clk (clk), .reset (reset), .sw_reset (sw_reset_in), .sw_stop (sw_stop_in), .length (length_counter), .eop_enabled (descriptor_end_on_eop_enable_d1), .eop (snk_eop), .ready (snk_ready), .valid (snk_valid), .early_termination (early_termination), .address_in (address), .write_in (write), .max_burst_count (maximum_burst_count), .write_fifo_used ({fifo_full,fifo_used}), .waitrequest (master_waitrequest), .short_first_access_enable (short_first_access_enable), .short_last_access_enable (short_last_access_enable), .short_first_and_last_access_enable (short_first_and_last_access_enable), .address_out (master_address), .write_out (master_write), // filtered version of 'write' .burst_count (master_burstcount), .stall (write_stall_from_write_burst_control), .reset_taken (reset_taken_from_write_burst_control), .stopped (stopped_from_write_burst_control) ); defparam the_write_burst_control.BURST_ENABLE = BURST_ENABLE; defparam the_write_burst_control.BURST_COUNT_WIDTH = MAX_BURST_COUNT_WIDTH; defparam the_write_burst_control.WORD_SIZE = BYTE_ENABLE_WIDTH; defparam the_write_burst_control.WORD_SIZE_LOG2 = (DATA_WIDTH == 8)? 0 : BYTE_ENABLE_WIDTH_LOG2; // need to make sure log2(word size) is 0 instead of 1 here when the data width is 8 bits defparam the_write_burst_control.ADDRESS_WIDTH = ADDRESS_WIDTH; defparam the_write_burst_control.LENGTH_WIDTH = LENGTH_WIDTH; defparam the_write_burst_control.WRITE_FIFO_USED_WIDTH = FIFO_DEPTH_LOG2; defparam the_write_burst_control.BURST_WRAPPING_SUPPORT = BURST_WRAPPING_SUPPORT; /********************************************* END MODULE INSTANTIATIONS ************************************************************************/ /********************************************* CONTROL AND COMBINATIONAL SIGNALS ****************************************************************/ // breakout the descriptor information into more manageable names assign descriptor_address = {snk_command_data[123:92], snk_command_data[31:0]}; // 64-bit addressing support assign descriptor_length = snk_command_data[63:32]; assign descriptor_programmable_burst_count = snk_command_data[75:68]; assign descriptor_stride = snk_command_data[91:76]; assign descriptor_end_on_eop_enable = snk_command_data[64]; assign sw_stop_in = snk_command_data[66]; assign sw_reset_in = snk_command_data[67]; assign stride_amount = (STRIDE_ENABLE == 1)? stride_d1[STRIDE_WIDTH-1:0] : FIXED_STRIDE; // hardcoding to FIXED_STRIDE when stride capabilities are disabled assign maximum_burst_count = (PROGRAMMABLE_BURST_ENABLE == 1)? programmable_burst_count_d1 : MAX_BURST_COUNT; assign eop_enable = (PACKET_ENABLE == 1)? descriptor_end_on_eop_enable_d1 : 1'b0; // no eop or early termination support when packet support is disabled assign done_strobe = (done == 1) & (done_d1 == 0) & (reset_taken == 0); // set_done asserts the done register so this strobe fires when the last write completes assign response_error = (ERROR_ENABLE == 1)? error : 8'b00000000; assign response_actual_bytes_transferred = (PACKET_ENABLE == 1)? actual_bytes_transferred_counter : 32'h00000000; // transfer size amounts for special cases (starting unaligned, ending with a partial word, starting unaligned and ending with a partial word on the same write) assign short_first_access_size = BYTE_ENABLE_WIDTH - start_byte_address; assign short_last_access_size = (eop_enable == 1)? (packet_beat_size + packet_bytes_buffered_d1) : (length_counter & LSB_MASK); assign short_first_and_last_access_size = (eop_enable == 1)? (BYTE_ENABLE_WIDTH - buffered_empty) : (length_counter & LSB_MASK); /* special case transfer enables and counter increment values (address_counter, length_counter, and actual_bytes_transferred) short_first_access_enable is for transfers that start aligned but reach the next word boundary short_last_access_enable is for transfers that are not the first transfer but don't end with on a word boundary short_first_and_last_access_enable is for transfers that start and end with a single transfer and don't end on a word boundary (may or may not be aligned) */ generate if (UNALIGNED_ACCESSES_ENABLE == 1) begin // all three enables are mutually exclusive to provide one-hot encoding for the bytes to transfer mux assign short_first_access_enable = (start_byte_address != 0) & (first_access == 1) & ((eop_enable == 1)? ((start_byte_address + BYTE_ENABLE_WIDTH - buffered_empty) >= BYTE_ENABLE_WIDTH) : (first_word_boundary_not_reached_d1 == 0)); assign short_last_access_enable = (first_access == 0) & ((eop_enable == 1)? ((packet_beat_size + packet_bytes_buffered_d1) < BYTE_ENABLE_WIDTH): (length_counter < BYTE_ENABLE_WIDTH)); assign short_first_and_last_access_enable = (first_access == 1) & ((eop_enable == 1)? ((start_byte_address + BYTE_ENABLE_WIDTH - buffered_empty) < BYTE_ENABLE_WIDTH) : (first_word_boundary_not_reached_d1 == 1)); assign bytes_to_transfer = bytes_to_transfer_mux; assign address_increment = bytes_to_transfer_mux; // can't use stride when unaligned accesses are enabled end else if (ONLY_FULL_ACCESS_ENABLE == 1) begin assign short_first_access_enable = 0; assign short_last_access_enable = 0; assign short_first_and_last_access_enable = 0; assign bytes_to_transfer = BYTE_ENABLE_WIDTH; if (STRIDE_ENABLE == 1) begin assign address_increment = BYTE_ENABLE_WIDTH * stride_amount; // the byte address portion of the address_counter is grounded to make sure the address presented to the fabric is aligned end else begin assign address_increment = BYTE_ENABLE_WIDTH; // the byte address portion of the address_counter is grounded to make sure the address presented to the fabric is aligned end end else // must be aligned but can end with any number of bytes begin assign short_first_access_enable = 0; assign short_last_access_enable = (eop_enable == 1)? (buffered_eop == 1) : (length_counter < BYTE_ENABLE_WIDTH); // less than a word to transfer assign short_first_and_last_access_enable = 0; assign bytes_to_transfer = bytes_to_transfer_mux; if (STRIDE_ENABLE == 1) begin assign address_increment = BYTE_ENABLE_WIDTH * stride_amount; end else begin assign address_increment = BYTE_ENABLE_WIDTH; end end endgenerate // the control logic ensures this mux is one-hot with the fall through being the typical full word aligned access always @ (short_first_access_enable or short_last_access_enable or short_first_and_last_access_enable or short_first_access_size or short_last_access_size or short_first_and_last_access_size) begin case ({short_first_and_last_access_enable, short_last_access_enable, short_first_access_enable}) 3'b001: bytes_to_transfer_mux = short_first_access_size; // unaligned and reaches the next word boundary 3'b010: bytes_to_transfer_mux = short_last_access_size; // aligned and does not reach the next word boundary 3'b100: bytes_to_transfer_mux = short_first_and_last_access_size; // unaligned and does not reach the next word boundary default: bytes_to_transfer_mux = BYTE_ENABLE_WIDTH; // aligned and reaches the next word boundary (i.e. a full word transfer) endcase end // Avalon-ST is network order (a.k.a. big endian) so we need to reverse the symbols before jamming them into the FIFO, changing the symbol width to something other than 8 might break something... generate genvar i; for(i = 0; i < DATA_WIDTH; i = i + SYMBOL_WIDTH) // the data width is always a multiple of the symbol width begin: symbol_swap assign fifo_write_data[i +SYMBOL_WIDTH -1: i] = snk_data[DATA_WIDTH -i -1: DATA_WIDTH -i - SYMBOL_WIDTH]; end endgenerate // sticking the error, empty, eop, and eop bits at the top of the FIFO write data, flooring empty to zero when eop is not asserted (empty is only valid on eop cycles) assign fifo_write_data[FIFO_WIDTH-1:DATA_WIDTH] = {snk_error, (snk_eop == 1)? snk_empty:0, snk_sop, snk_eop}; // swap the bytes if big endian is enabled (remember that this isn't tested so use at your own risk and make sure you understand the software impact this has) generate if(BIG_ENDIAN_ACCESS == 1) begin genvar j; for(j=0; j < DATA_WIDTH; j = j + 8) begin: byte_swap assign fifo_read_data_rearranged[j +8 -1: j] = fifo_read_data[DATA_WIDTH -j -1: DATA_WIDTH -j - 8]; assign master_byteenable[j/8] = supported_byteenable[(DATA_WIDTH -j -1)/8]; end end else begin assign fifo_read_data_rearranged = fifo_read_data[DATA_WIDTH-1:0]; // little endian so no byte swapping necessary assign master_byteenable = supported_byteenable; // dito end endgenerate // fifo read data is in the format of {error, empty, sop, eop, data} with the following widths {ERROR_WIDTH, NUMBER_OF_SYMBOLS_LOG2, 1, 1, DATA_WIDTH} assign buffered_data = fifo_read_data_rearranged; assign buffered_error = fifo_read_data[DATA_WIDTH +2 +NUMBER_OF_SYMBOLS_LOG2 + ERROR_WIDTH -1: DATA_WIDTH +2 +NUMBER_OF_SYMBOLS_LOG2]; generate if (PACKET_ENABLE == 1) begin assign buffered_eop = fifo_read_data[DATA_WIDTH]; assign buffered_sop = fifo_read_data[DATA_WIDTH +1]; if (ONLY_FULL_ACCESS_ENABLE == 1) begin assign buffered_empty = 0; // ignore the empty signal and assume it was a full beat end else begin assign buffered_empty = fifo_read_data[DATA_WIDTH +2 +NUMBER_OF_SYMBOLS_LOG2 -1: DATA_WIDTH +2]; // empty is packed into the upper FIFO bits end end else begin assign buffered_empty = 0; assign buffered_eop = 0; assign buffered_sop = 0; end endgenerate /* Generating mask bits based on the size of the transfer before the unaligned access adjustment. This is based on the transfer size to determine how many byte enables would be asserted in the aligned case. Afterwards the byte enables will be shifted left based on how far out of alignment the address counter is (should only happen for the first transfer). If the data path is 32 bits wide then the following masks are generated: Transfer Size Index Mask 1 0 0001 2 1 0011 3 2 0111 4 3 1111 Note that the index is just the transfer size minus one */ generate if (BYTE_ENABLE_WIDTH > 1) begin genvar k; for (k = 0; k < BYTE_ENABLE_WIDTH; k = k + 1) begin: byte_enable_loop assign byteenable_masks[k] = { {(BYTE_ENABLE_WIDTH-k-1){1'b0}}, {(k+1){1'b1}} }; // Byte enable width - k zeros followed by k ones end end else begin assign byteenable_masks[0] = 1'b1; // will be stubbed at top level end endgenerate /* byteenable_mask is based on an aligned access determined by the transfer size. This value is then shifted to the left by the unaligned offset (first transfer only) to compensate for the unaligned offset so that the correct byte enables are enabled. When the accesses are aligned then no barrelshifting is needed and when full accesses are used then all byte enables will be asserted always. */ generate if (ONLY_FULL_ACCESS_ENABLE == 1) begin assign unsupported_byteenable = {BYTE_ENABLE_WIDTH{1'b1}}; // always full accesses so the byte enables are all ones end else if (UNALIGNED_ACCESSES_ENABLE == 0) begin assign unsupported_byteenable = byteenable_masks[bytes_to_transfer_mux - 1]; // aligned so no unaligned adjustment required end else // unaligned case begin assign unsupported_byteenable = byteenable_masks[bytes_to_transfer_mux - 1] << (address_counter & LSB_MASK); // barrelshift adjusts for unaligned start address end endgenerate generate if (BYTE_ENABLE_WIDTH > 1) begin assign address = address_counter & { {(ADDRESS_WIDTH-BYTE_ENABLE_WIDTH_LOG2){1'b1}}, {BYTE_ENABLE_WIDTH_LOG2{1'b0}} }; // masking LSBs (byte offsets) since the address counter might not be aligned for the first transfer end else begin assign address = address_counter; // don't need to mask any bits as the address will only advance one byte at a time end endgenerate assign done = (length_counter == 0) | ((PACKET_ENABLE == 1) & (eop_enable == 1) & (eop_seen == 1) & (extra_write == 0)); assign packet_beat_size = (eop_seen == 1) ? 0 : (BYTE_ENABLE_WIDTH - buffered_empty); // when the eop arrives we can't add more to packet_bytes_buffered_d1 assign packet_bytes_buffered = packet_beat_size + packet_bytes_buffered_d1 - bytes_to_transfer; // extra_write is only applicable when unaligned accesses are performed. This extra access gets the remaining data buffered in the ST to MM adapter block written to memory assign extra_write = (UNALIGNED_ACCESSES_ENABLE == 1) & (((PACKET_ENABLE == 1) & (eop_enable == 1))? ((eop_seen == 1) & (packet_bytes_buffered_d1 != 0)) : // when packets are used if there are left over bytes buffered after eop is seen perform an extra write ((first_access == 0) & (start_byte_address != 0) & (short_last_access_enable == 1) & (start_byte_address >= length_counter[BYTE_ENABLE_WIDTH_LOG2-1:0]))); // non-packet transfer and there are extra bytes buffered so performing an extra access assign first_word_boundary_not_reached = (descriptor_length < BYTE_ENABLE_WIDTH) & // length is less than the word size (((descriptor_length & LSB_MASK) + (descriptor_address & LSB_MASK)) < BYTE_ENABLE_WIDTH); // start address + length doesn't reach the next word boundary (not used for packet transfers) assign write = ((fifo_empty == 0) | (extra_write == 1)) & (done == 0) & (stopped == 0); assign st_to_mm_adapter_enable = (done == 0) & (extra_write == 0); assign write_complete = (write == 1) & (master_waitrequest == 0) & (write_stall_from_byte_enable_generator == 0) & (write_stall_from_write_burst_control == 0); // writing still occuring and no reasons to prevent the write cycle from completing assign increment_address = ((write == 1) & (write_complete == 1)) & (stopped == 0); assign go = (snk_command_valid == 1) & (snk_command_ready == 1); // go with be one cycle since done will be set to 0 on the next cycle (length will be non-zero) assign snk_ready = (fifo_full == 0) & // need to make sure more streaming data doesn't come in when the FIFO is full (((PACKET_ENABLE == 1) & (snk_sop == 1) & (fifo_empty == 0)) != 1); // need to make sure that only one packet is buffered at any given time (sop will continue to be asserted until the buffer is written out) assign length_sync_reset = (((reset_taken == 1) | (early_termination_d1 == 1)) & (done == 0)) | (done_strobe == 1); // abrupt stop cases or packet transfer just completed (otherwise the length register will reach 0 by itself) assign fifo_write = (snk_ready == 1) & (snk_valid == 1); assign early_termination = (eop_enable == 1) & (write_complete == 1) & (length_counter < bytes_to_transfer); // packet transfer and the length counter is about to roll over so stop transfering assign stop_state = stopped; assign reset_delayed = (reset_taken == 0) & (sw_reset_in == 1); assign src_response_data = {{212{1'b0}}, done_strobe, early_termination_d1, response_error, stop_state, reset_delayed, response_actual_bytes_transferred}; /********************************************* END CONTROL AND COMBINATIONAL SIGNALS ************************************************************/ endmodule
module will barrelshift the data from the FIFO when unaligned accesses is enabled (we are using part of the FIFO word when off boundary). When unaligned accesses is disabled then the data passes as wires. The byte enable generator might require multiple cycles to perform partial accesses so a 'stall' bit is used (triggers a stall like waitrequest) */ ST_to_MM_Adapter the_ST_to_MM_Adapter ( .clk (clk), .reset (reset), .enable (st_to_mm_adapter_enable), .address (descriptor_address[ADDRESS_WIDTH-1:0]), .start (go), .waitrequest (master_waitrequest), .stall (write_stall_from_byte_enable_generator | write_stall_from_write_burst_control), .write_data (master_writedata), .fifo_data (buffered_data), .fifo_empty (fifo_empty), .fifo_readack (fifo_read) ); defparam the_ST_to_MM_Adapter.DATA_WIDTH = DATA_WIDTH; defparam the_ST_to_MM_Adapter.BYTEENABLE_WIDTH_LOG2 = BYTE_ENABLE_WIDTH_LOG2; defparam the_ST_to_MM_Adapter.ADDRESS_WIDTH = ADDRESS_WIDTH; defparam the_ST_to_MM_Adapter.UNALIGNED_ACCESS_ENABLE = UNALIGNED_ACCESSES_ENABLE; /* this block is responsible for presenting the fabric with supported byte enable combinations which can take multiple cycles, if full word only support is enabled this block will reduce to wires during synthesis */ byte_enable_generator the_byte_enable_generator ( .clk (clk), .reset (reset), .write_in (write), .byteenable_in (unsupported_byteenable), .waitrequest_out (write_stall_from_byte_enable_generator), .byteenable_out (supported_byteenable), .waitrequest_in (master_waitrequest | write_stall_from_write_burst_control) ); defparam the_byte_enable_generator.BYTEENABLE_WIDTH = BYTE_ENABLE_WIDTH; // this block will be used to drive write, address, and burstcount to the fabric write_burst_control the_write_burst_control ( .clk (clk), .reset (reset), .sw_reset (sw_reset_in), .sw_stop (sw_stop_in), .length (length_counter), .eop_enabled (descriptor_end_on_eop_enable_d1), .eop (snk_eop), .ready (snk_ready), .valid (snk_valid), .early_termination (early_termination), .address_in (address), .write_in (write), .max_burst_count (maximum_burst_count), .write_fifo_used ({fifo_full,fifo_used}), .waitrequest (master_waitrequest), .short_first_access_enable (short_first_access_enable), .short_last_access_enable (short_last_access_enable), .short_first_and_last_access_enable (short_first_and_last_access_enable), .address_out (master_address), .write_out (master_write), // filtered version of 'write' .burst_count (master_burstcount), .stall (write_stall_from_write_burst_control), .reset_taken (reset_taken_from_write_burst_control), .stopped (stopped_from_write_burst_control) ); defparam the_write_burst_control.BURST_ENABLE = BURST_ENABLE; defparam the_write_burst_control.BURST_COUNT_WIDTH = MAX_BURST_COUNT_WIDTH; defparam the_write_burst_control.WORD_SIZE = BYTE_ENABLE_WIDTH; defparam the_write_burst_control.WORD_SIZE_LOG2 = (DATA_WIDTH == 8)? 0 : BYTE_ENABLE_WIDTH_LOG2; // need to make sure log2(word size) is 0 instead of 1 here when the data width is 8 bits defparam the_write_burst_control.ADDRESS_WIDTH = ADDRESS_WIDTH; defparam the_write_burst_control.LENGTH_WIDTH = LENGTH_WIDTH; defparam the_write_burst_control.WRITE_FIFO_USED_WIDTH = FIFO_DEPTH_LOG2; defparam the_write_burst_control.BURST_WRAPPING_SUPPORT = BURST_WRAPPING_SUPPORT; /********************************************* END MODULE INSTANTIATIONS ************************************************************************/ /********************************************* CONTROL AND COMBINATIONAL SIGNALS ****************************************************************/ // breakout the descriptor information into more manageable names assign descriptor_address = {snk_command_data[123:92], snk_command_data[31:0]}; // 64-bit addressing support assign descriptor_length = snk_command_data[63:32]; assign descriptor_programmable_burst_count = snk_command_data[75:68]; assign descriptor_stride = snk_command_data[91:76]; assign descriptor_end_on_eop_enable = snk_command_data[64]; assign sw_stop_in = snk_command_data[66]; assign sw_reset_in = snk_command_data[67]; assign stride_amount = (STRIDE_ENABLE == 1)? stride_d1[STRIDE_WIDTH-1:0] : FIXED_STRIDE; // hardcoding to FIXED_STRIDE when stride capabilities are disabled assign maximum_burst_count = (PROGRAMMABLE_BURST_ENABLE == 1)? programmable_burst_count_d1 : MAX_BURST_COUNT; assign eop_enable = (PACKET_ENABLE == 1)? descriptor_end_on_eop_enable_d1 : 1'b0; // no eop or early termination support when packet support is disabled assign done_strobe = (done == 1) & (done_d1 == 0) & (reset_taken == 0); // set_done asserts the done register so this strobe fires when the last write completes assign response_error = (ERROR_ENABLE == 1)? error : 8'b00000000; assign response_actual_bytes_transferred = (PACKET_ENABLE == 1)? actual_bytes_transferred_counter : 32'h00000000; // transfer size amounts for special cases (starting unaligned, ending with a partial word, starting unaligned and ending with a partial word on the same write) assign short_first_access_size = BYTE_ENABLE_WIDTH - start_byte_address; assign short_last_access_size = (eop_enable == 1)? (packet_beat_size + packet_bytes_buffered_d1) : (length_counter & LSB_MASK); assign short_first_and_last_access_size = (eop_enable == 1)? (BYTE_ENABLE_WIDTH - buffered_empty) : (length_counter & LSB_MASK); /* special case transfer enables and counter increment values (address_counter, length_counter, and actual_bytes_transferred) short_first_access_enable is for transfers that start aligned but reach the next word boundary short_last_access_enable is for transfers that are not the first transfer but don't end with on a word boundary short_first_and_last_access_enable is for transfers that start and end with a single transfer and don't end on a word boundary (may or may not be aligned) */ generate if (UNALIGNED_ACCESSES_ENABLE == 1) begin // all three enables are mutually exclusive to provide one-hot encoding for the bytes to transfer mux assign short_first_access_enable = (start_byte_address != 0) & (first_access == 1) & ((eop_enable == 1)? ((start_byte_address + BYTE_ENABLE_WIDTH - buffered_empty) >= BYTE_ENABLE_WIDTH) : (first_word_boundary_not_reached_d1 == 0)); assign short_last_access_enable = (first_access == 0) & ((eop_enable == 1)? ((packet_beat_size + packet_bytes_buffered_d1) < BYTE_ENABLE_WIDTH): (length_counter < BYTE_ENABLE_WIDTH)); assign short_first_and_last_access_enable = (first_access == 1) & ((eop_enable == 1)? ((start_byte_address + BYTE_ENABLE_WIDTH - buffered_empty) < BYTE_ENABLE_WIDTH) : (first_word_boundary_not_reached_d1 == 1)); assign bytes_to_transfer = bytes_to_transfer_mux; assign address_increment = bytes_to_transfer_mux; // can't use stride when unaligned accesses are enabled end else if (ONLY_FULL_ACCESS_ENABLE == 1) begin assign short_first_access_enable = 0; assign short_last_access_enable = 0; assign short_first_and_last_access_enable = 0; assign bytes_to_transfer = BYTE_ENABLE_WIDTH; if (STRIDE_ENABLE == 1) begin assign address_increment = BYTE_ENABLE_WIDTH * stride_amount; // the byte address portion of the address_counter is grounded to make sure the address presented to the fabric is aligned end else begin assign address_increment = BYTE_ENABLE_WIDTH; // the byte address portion of the address_counter is grounded to make sure the address presented to the fabric is aligned end end else // must be aligned but can end with any number of bytes begin assign short_first_access_enable = 0; assign short_last_access_enable = (eop_enable == 1)? (buffered_eop == 1) : (length_counter < BYTE_ENABLE_WIDTH); // less than a word to transfer assign short_first_and_last_access_enable = 0; assign bytes_to_transfer = bytes_to_transfer_mux; if (STRIDE_ENABLE == 1) begin assign address_increment = BYTE_ENABLE_WIDTH * stride_amount; end else begin assign address_increment = BYTE_ENABLE_WIDTH; end end endgenerate // the control logic ensures this mux is one-hot with the fall through being the typical full word aligned access always @ (short_first_access_enable or short_last_access_enable or short_first_and_last_access_enable or short_first_access_size or short_last_access_size or short_first_and_last_access_size) begin case ({short_first_and_last_access_enable, short_last_access_enable, short_first_access_enable}) 3'b001: bytes_to_transfer_mux = short_first_access_size; // unaligned and reaches the next word boundary 3'b010: bytes_to_transfer_mux = short_last_access_size; // aligned and does not reach the next word boundary 3'b100: bytes_to_transfer_mux = short_first_and_last_access_size; // unaligned and does not reach the next word boundary default: bytes_to_transfer_mux = BYTE_ENABLE_WIDTH; // aligned and reaches the next word boundary (i.e. a full word transfer) endcase end // Avalon-ST is network order (a.k.a. big endian) so we need to reverse the symbols before jamming them into the FIFO, changing the symbol width to something other than 8 might break something... generate genvar i; for(i = 0; i < DATA_WIDTH; i = i + SYMBOL_WIDTH) // the data width is always a multiple of the symbol width begin: symbol_swap assign fifo_write_data[i +SYMBOL_WIDTH -1: i] = snk_data[DATA_WIDTH -i -1: DATA_WIDTH -i - SYMBOL_WIDTH]; end endgenerate // sticking the error, empty, eop, and eop bits at the top of the FIFO write data, flooring empty to zero when eop is not asserted (empty is only valid on eop cycles) assign fifo_write_data[FIFO_WIDTH-1:DATA_WIDTH] = {snk_error, (snk_eop == 1)? snk_empty:0, snk_sop, snk_eop}; // swap the bytes if big endian is enabled (remember that this isn't tested so use at your own risk and make sure you understand the software impact this has) generate if(BIG_ENDIAN_ACCESS == 1) begin genvar j; for(j=0; j < DATA_WIDTH; j = j + 8) begin: byte_swap assign fifo_read_data_rearranged[j +8 -1: j] = fifo_read_data[DATA_WIDTH -j -1: DATA_WIDTH -j - 8]; assign master_byteenable[j/8] = supported_byteenable[(DATA_WIDTH -j -1)/8]; end end else begin assign fifo_read_data_rearranged = fifo_read_data[DATA_WIDTH-1:0]; // little endian so no byte swapping necessary assign master_byteenable = supported_byteenable; // dito end endgenerate // fifo read data is in the format of {error, empty, sop, eop, data} with the following widths {ERROR_WIDTH, NUMBER_OF_SYMBOLS_LOG2, 1, 1, DATA_WIDTH} assign buffered_data = fifo_read_data_rearranged; assign buffered_error = fifo_read_data[DATA_WIDTH +2 +NUMBER_OF_SYMBOLS_LOG2 + ERROR_WIDTH -1: DATA_WIDTH +2 +NUMBER_OF_SYMBOLS_LOG2]; generate if (PACKET_ENABLE == 1) begin assign buffered_eop = fifo_read_data[DATA_WIDTH]; assign buffered_sop = fifo_read_data[DATA_WIDTH +1]; if (ONLY_FULL_ACCESS_ENABLE == 1) begin assign buffered_empty = 0; // ignore the empty signal and assume it was a full beat end else begin assign buffered_empty = fifo_read_data[DATA_WIDTH +2 +NUMBER_OF_SYMBOLS_LOG2 -1: DATA_WIDTH +2]; // empty is packed into the upper FIFO bits end end else begin assign buffered_empty = 0; assign buffered_eop = 0; assign buffered_sop = 0; end endgenerate /* Generating mask bits based on the size of the transfer before the unaligned access adjustment. This is based on the transfer size to determine how many byte enables would be asserted in the aligned case. Afterwards the byte enables will be shifted left based on how far out of alignment the address counter is (should only happen for the first transfer). If the data path is 32 bits wide then the following masks are generated: Transfer Size Index Mask 1 0 0001 2 1 0011 3 2 0111 4 3 1111 Note that the index is just the transfer size minus one */ generate if (BYTE_ENABLE_WIDTH > 1) begin genvar k; for (k = 0; k < BYTE_ENABLE_WIDTH; k = k + 1) begin: byte_enable_loop assign byteenable_masks[k] = { {(BYTE_ENABLE_WIDTH-k-1){1'b0}}, {(k+1){1'b1}} }; // Byte enable width - k zeros followed by k ones end end else begin assign byteenable_masks[0] = 1'b1; // will be stubbed at top level end endgenerate /* byteenable_mask is based on an aligned access determined by the transfer size. This value is then shifted to the left by the unaligned offset (first transfer only) to compensate for the unaligned offset so that the correct byte enables are enabled. When the accesses are aligned then no barrelshifting is needed and when full accesses are used then all byte enables will be asserted always. */ generate if (ONLY_FULL_ACCESS_ENABLE == 1) begin assign unsupported_byteenable = {BYTE_ENABLE_WIDTH{1'b1}}; // always full accesses so the byte enables are all ones end else if (UNALIGNED_ACCESSES_ENABLE == 0) begin assign unsupported_byteenable = byteenable_masks[bytes_to_transfer_mux - 1]; // aligned so no unaligned adjustment required end else // unaligned case begin assign unsupported_byteenable = byteenable_masks[bytes_to_transfer_mux - 1] << (address_counter & LSB_MASK); // barrelshift adjusts for unaligned start address end endgenerate generate if (BYTE_ENABLE_WIDTH > 1) begin assign address = address_counter & { {(ADDRESS_WIDTH-BYTE_ENABLE_WIDTH_LOG2){1'b1}}, {BYTE_ENABLE_WIDTH_LOG2{1'b0}} }; // masking LSBs (byte offsets) since the address counter might not be aligned for the first transfer end else begin assign address = address_counter; // don't need to mask any bits as the address will only advance one byte at a time end endgenerate assign done = (length_counter == 0) | ((PACKET_ENABLE == 1) & (eop_enable == 1) & (eop_seen == 1) & (extra_write == 0)); assign packet_beat_size = (eop_seen == 1) ? 0 : (BYTE_ENABLE_WIDTH - buffered_empty); // when the eop arrives we can't add more to packet_bytes_buffered_d1 assign packet_bytes_buffered = packet_beat_size + packet_bytes_buffered_d1 - bytes_to_transfer; // extra_write is only applicable when unaligned accesses are performed. This extra access gets the remaining data buffered in the ST to MM adapter block written to memory assign extra_write = (UNALIGNED_ACCESSES_ENABLE == 1) & (((PACKET_ENABLE == 1) & (eop_enable == 1))? ((eop_seen == 1) & (packet_bytes_buffered_d1 != 0)) : // when packets are used if there are left over bytes buffered after eop is seen perform an extra write ((first_access == 0) & (start_byte_address != 0) & (short_last_access_enable == 1) & (start_byte_address >= length_counter[BYTE_ENABLE_WIDTH_LOG2-1:0]))); // non-packet transfer and there are extra bytes buffered so performing an extra access assign first_word_boundary_not_reached = (descriptor_length < BYTE_ENABLE_WIDTH) & // length is less than the word size (((descriptor_length & LSB_MASK) + (descriptor_address & LSB_MASK)) < BYTE_ENABLE_WIDTH); // start address + length doesn't reach the next word boundary (not used for packet transfers) assign write = ((fifo_empty == 0) | (extra_write == 1)) & (done == 0) & (stopped == 0); assign st_to_mm_adapter_enable = (done == 0) & (extra_write == 0); assign write_complete = (write == 1) & (master_waitrequest == 0) & (write_stall_from_byte_enable_generator == 0) & (write_stall_from_write_burst_control == 0); // writing still occuring and no reasons to prevent the write cycle from completing assign increment_address = ((write == 1) & (write_complete == 1)) & (stopped == 0); assign go = (snk_command_valid == 1) & (snk_command_ready == 1); // go with be one cycle since done will be set to 0 on the next cycle (length will be non-zero) assign snk_ready = (fifo_full == 0) & // need to make sure more streaming data doesn't come in when the FIFO is full (((PACKET_ENABLE == 1) & (snk_sop == 1) & (fifo_empty == 0)) != 1); // need to make sure that only one packet is buffered at any given time (sop will continue to be asserted until the buffer is written out) assign length_sync_reset = (((reset_taken == 1) | (early_termination_d1 == 1)) & (done == 0)) | (done_strobe == 1); // abrupt stop cases or packet transfer just completed (otherwise the length register will reach 0 by itself) assign fifo_write = (snk_ready == 1) & (snk_valid == 1); assign early_termination = (eop_enable == 1) & (write_complete == 1) & (length_counter < bytes_to_transfer); // packet transfer and the length counter is about to roll over so stop transfering assign stop_state = stopped; assign reset_delayed = (reset_taken == 0) & (sw_reset_in == 1); assign src_response_data = {{212{1'b0}}, done_strobe, early_termination_d1, response_error, stop_state, reset_delayed, response_actual_bytes_transferred}; /********************************************* END CONTROL AND COMBINATIONAL SIGNALS ************************************************************/ endmodule
module will barrelshift the data from the FIFO when unaligned accesses is enabled (we are using part of the FIFO word when off boundary). When unaligned accesses is disabled then the data passes as wires. The byte enable generator might require multiple cycles to perform partial accesses so a 'stall' bit is used (triggers a stall like waitrequest) */ ST_to_MM_Adapter the_ST_to_MM_Adapter ( .clk (clk), .reset (reset), .enable (st_to_mm_adapter_enable), .address (descriptor_address[ADDRESS_WIDTH-1:0]), .start (go), .waitrequest (master_waitrequest), .stall (write_stall_from_byte_enable_generator | write_stall_from_write_burst_control), .write_data (master_writedata), .fifo_data (buffered_data), .fifo_empty (fifo_empty), .fifo_readack (fifo_read) ); defparam the_ST_to_MM_Adapter.DATA_WIDTH = DATA_WIDTH; defparam the_ST_to_MM_Adapter.BYTEENABLE_WIDTH_LOG2 = BYTE_ENABLE_WIDTH_LOG2; defparam the_ST_to_MM_Adapter.ADDRESS_WIDTH = ADDRESS_WIDTH; defparam the_ST_to_MM_Adapter.UNALIGNED_ACCESS_ENABLE = UNALIGNED_ACCESSES_ENABLE; /* this block is responsible for presenting the fabric with supported byte enable combinations which can take multiple cycles, if full word only support is enabled this block will reduce to wires during synthesis */ byte_enable_generator the_byte_enable_generator ( .clk (clk), .reset (reset), .write_in (write), .byteenable_in (unsupported_byteenable), .waitrequest_out (write_stall_from_byte_enable_generator), .byteenable_out (supported_byteenable), .waitrequest_in (master_waitrequest | write_stall_from_write_burst_control) ); defparam the_byte_enable_generator.BYTEENABLE_WIDTH = BYTE_ENABLE_WIDTH; // this block will be used to drive write, address, and burstcount to the fabric write_burst_control the_write_burst_control ( .clk (clk), .reset (reset), .sw_reset (sw_reset_in), .sw_stop (sw_stop_in), .length (length_counter), .eop_enabled (descriptor_end_on_eop_enable_d1), .eop (snk_eop), .ready (snk_ready), .valid (snk_valid), .early_termination (early_termination), .address_in (address), .write_in (write), .max_burst_count (maximum_burst_count), .write_fifo_used ({fifo_full,fifo_used}), .waitrequest (master_waitrequest), .short_first_access_enable (short_first_access_enable), .short_last_access_enable (short_last_access_enable), .short_first_and_last_access_enable (short_first_and_last_access_enable), .address_out (master_address), .write_out (master_write), // filtered version of 'write' .burst_count (master_burstcount), .stall (write_stall_from_write_burst_control), .reset_taken (reset_taken_from_write_burst_control), .stopped (stopped_from_write_burst_control) ); defparam the_write_burst_control.BURST_ENABLE = BURST_ENABLE; defparam the_write_burst_control.BURST_COUNT_WIDTH = MAX_BURST_COUNT_WIDTH; defparam the_write_burst_control.WORD_SIZE = BYTE_ENABLE_WIDTH; defparam the_write_burst_control.WORD_SIZE_LOG2 = (DATA_WIDTH == 8)? 0 : BYTE_ENABLE_WIDTH_LOG2; // need to make sure log2(word size) is 0 instead of 1 here when the data width is 8 bits defparam the_write_burst_control.ADDRESS_WIDTH = ADDRESS_WIDTH; defparam the_write_burst_control.LENGTH_WIDTH = LENGTH_WIDTH; defparam the_write_burst_control.WRITE_FIFO_USED_WIDTH = FIFO_DEPTH_LOG2; defparam the_write_burst_control.BURST_WRAPPING_SUPPORT = BURST_WRAPPING_SUPPORT; /********************************************* END MODULE INSTANTIATIONS ************************************************************************/ /********************************************* CONTROL AND COMBINATIONAL SIGNALS ****************************************************************/ // breakout the descriptor information into more manageable names assign descriptor_address = {snk_command_data[123:92], snk_command_data[31:0]}; // 64-bit addressing support assign descriptor_length = snk_command_data[63:32]; assign descriptor_programmable_burst_count = snk_command_data[75:68]; assign descriptor_stride = snk_command_data[91:76]; assign descriptor_end_on_eop_enable = snk_command_data[64]; assign sw_stop_in = snk_command_data[66]; assign sw_reset_in = snk_command_data[67]; assign stride_amount = (STRIDE_ENABLE == 1)? stride_d1[STRIDE_WIDTH-1:0] : FIXED_STRIDE; // hardcoding to FIXED_STRIDE when stride capabilities are disabled assign maximum_burst_count = (PROGRAMMABLE_BURST_ENABLE == 1)? programmable_burst_count_d1 : MAX_BURST_COUNT; assign eop_enable = (PACKET_ENABLE == 1)? descriptor_end_on_eop_enable_d1 : 1'b0; // no eop or early termination support when packet support is disabled assign done_strobe = (done == 1) & (done_d1 == 0) & (reset_taken == 0); // set_done asserts the done register so this strobe fires when the last write completes assign response_error = (ERROR_ENABLE == 1)? error : 8'b00000000; assign response_actual_bytes_transferred = (PACKET_ENABLE == 1)? actual_bytes_transferred_counter : 32'h00000000; // transfer size amounts for special cases (starting unaligned, ending with a partial word, starting unaligned and ending with a partial word on the same write) assign short_first_access_size = BYTE_ENABLE_WIDTH - start_byte_address; assign short_last_access_size = (eop_enable == 1)? (packet_beat_size + packet_bytes_buffered_d1) : (length_counter & LSB_MASK); assign short_first_and_last_access_size = (eop_enable == 1)? (BYTE_ENABLE_WIDTH - buffered_empty) : (length_counter & LSB_MASK); /* special case transfer enables and counter increment values (address_counter, length_counter, and actual_bytes_transferred) short_first_access_enable is for transfers that start aligned but reach the next word boundary short_last_access_enable is for transfers that are not the first transfer but don't end with on a word boundary short_first_and_last_access_enable is for transfers that start and end with a single transfer and don't end on a word boundary (may or may not be aligned) */ generate if (UNALIGNED_ACCESSES_ENABLE == 1) begin // all three enables are mutually exclusive to provide one-hot encoding for the bytes to transfer mux assign short_first_access_enable = (start_byte_address != 0) & (first_access == 1) & ((eop_enable == 1)? ((start_byte_address + BYTE_ENABLE_WIDTH - buffered_empty) >= BYTE_ENABLE_WIDTH) : (first_word_boundary_not_reached_d1 == 0)); assign short_last_access_enable = (first_access == 0) & ((eop_enable == 1)? ((packet_beat_size + packet_bytes_buffered_d1) < BYTE_ENABLE_WIDTH): (length_counter < BYTE_ENABLE_WIDTH)); assign short_first_and_last_access_enable = (first_access == 1) & ((eop_enable == 1)? ((start_byte_address + BYTE_ENABLE_WIDTH - buffered_empty) < BYTE_ENABLE_WIDTH) : (first_word_boundary_not_reached_d1 == 1)); assign bytes_to_transfer = bytes_to_transfer_mux; assign address_increment = bytes_to_transfer_mux; // can't use stride when unaligned accesses are enabled end else if (ONLY_FULL_ACCESS_ENABLE == 1) begin assign short_first_access_enable = 0; assign short_last_access_enable = 0; assign short_first_and_last_access_enable = 0; assign bytes_to_transfer = BYTE_ENABLE_WIDTH; if (STRIDE_ENABLE == 1) begin assign address_increment = BYTE_ENABLE_WIDTH * stride_amount; // the byte address portion of the address_counter is grounded to make sure the address presented to the fabric is aligned end else begin assign address_increment = BYTE_ENABLE_WIDTH; // the byte address portion of the address_counter is grounded to make sure the address presented to the fabric is aligned end end else // must be aligned but can end with any number of bytes begin assign short_first_access_enable = 0; assign short_last_access_enable = (eop_enable == 1)? (buffered_eop == 1) : (length_counter < BYTE_ENABLE_WIDTH); // less than a word to transfer assign short_first_and_last_access_enable = 0; assign bytes_to_transfer = bytes_to_transfer_mux; if (STRIDE_ENABLE == 1) begin assign address_increment = BYTE_ENABLE_WIDTH * stride_amount; end else begin assign address_increment = BYTE_ENABLE_WIDTH; end end endgenerate // the control logic ensures this mux is one-hot with the fall through being the typical full word aligned access always @ (short_first_access_enable or short_last_access_enable or short_first_and_last_access_enable or short_first_access_size or short_last_access_size or short_first_and_last_access_size) begin case ({short_first_and_last_access_enable, short_last_access_enable, short_first_access_enable}) 3'b001: bytes_to_transfer_mux = short_first_access_size; // unaligned and reaches the next word boundary 3'b010: bytes_to_transfer_mux = short_last_access_size; // aligned and does not reach the next word boundary 3'b100: bytes_to_transfer_mux = short_first_and_last_access_size; // unaligned and does not reach the next word boundary default: bytes_to_transfer_mux = BYTE_ENABLE_WIDTH; // aligned and reaches the next word boundary (i.e. a full word transfer) endcase end // Avalon-ST is network order (a.k.a. big endian) so we need to reverse the symbols before jamming them into the FIFO, changing the symbol width to something other than 8 might break something... generate genvar i; for(i = 0; i < DATA_WIDTH; i = i + SYMBOL_WIDTH) // the data width is always a multiple of the symbol width begin: symbol_swap assign fifo_write_data[i +SYMBOL_WIDTH -1: i] = snk_data[DATA_WIDTH -i -1: DATA_WIDTH -i - SYMBOL_WIDTH]; end endgenerate // sticking the error, empty, eop, and eop bits at the top of the FIFO write data, flooring empty to zero when eop is not asserted (empty is only valid on eop cycles) assign fifo_write_data[FIFO_WIDTH-1:DATA_WIDTH] = {snk_error, (snk_eop == 1)? snk_empty:0, snk_sop, snk_eop}; // swap the bytes if big endian is enabled (remember that this isn't tested so use at your own risk and make sure you understand the software impact this has) generate if(BIG_ENDIAN_ACCESS == 1) begin genvar j; for(j=0; j < DATA_WIDTH; j = j + 8) begin: byte_swap assign fifo_read_data_rearranged[j +8 -1: j] = fifo_read_data[DATA_WIDTH -j -1: DATA_WIDTH -j - 8]; assign master_byteenable[j/8] = supported_byteenable[(DATA_WIDTH -j -1)/8]; end end else begin assign fifo_read_data_rearranged = fifo_read_data[DATA_WIDTH-1:0]; // little endian so no byte swapping necessary assign master_byteenable = supported_byteenable; // dito end endgenerate // fifo read data is in the format of {error, empty, sop, eop, data} with the following widths {ERROR_WIDTH, NUMBER_OF_SYMBOLS_LOG2, 1, 1, DATA_WIDTH} assign buffered_data = fifo_read_data_rearranged; assign buffered_error = fifo_read_data[DATA_WIDTH +2 +NUMBER_OF_SYMBOLS_LOG2 + ERROR_WIDTH -1: DATA_WIDTH +2 +NUMBER_OF_SYMBOLS_LOG2]; generate if (PACKET_ENABLE == 1) begin assign buffered_eop = fifo_read_data[DATA_WIDTH]; assign buffered_sop = fifo_read_data[DATA_WIDTH +1]; if (ONLY_FULL_ACCESS_ENABLE == 1) begin assign buffered_empty = 0; // ignore the empty signal and assume it was a full beat end else begin assign buffered_empty = fifo_read_data[DATA_WIDTH +2 +NUMBER_OF_SYMBOLS_LOG2 -1: DATA_WIDTH +2]; // empty is packed into the upper FIFO bits end end else begin assign buffered_empty = 0; assign buffered_eop = 0; assign buffered_sop = 0; end endgenerate /* Generating mask bits based on the size of the transfer before the unaligned access adjustment. This is based on the transfer size to determine how many byte enables would be asserted in the aligned case. Afterwards the byte enables will be shifted left based on how far out of alignment the address counter is (should only happen for the first transfer). If the data path is 32 bits wide then the following masks are generated: Transfer Size Index Mask 1 0 0001 2 1 0011 3 2 0111 4 3 1111 Note that the index is just the transfer size minus one */ generate if (BYTE_ENABLE_WIDTH > 1) begin genvar k; for (k = 0; k < BYTE_ENABLE_WIDTH; k = k + 1) begin: byte_enable_loop assign byteenable_masks[k] = { {(BYTE_ENABLE_WIDTH-k-1){1'b0}}, {(k+1){1'b1}} }; // Byte enable width - k zeros followed by k ones end end else begin assign byteenable_masks[0] = 1'b1; // will be stubbed at top level end endgenerate /* byteenable_mask is based on an aligned access determined by the transfer size. This value is then shifted to the left by the unaligned offset (first transfer only) to compensate for the unaligned offset so that the correct byte enables are enabled. When the accesses are aligned then no barrelshifting is needed and when full accesses are used then all byte enables will be asserted always. */ generate if (ONLY_FULL_ACCESS_ENABLE == 1) begin assign unsupported_byteenable = {BYTE_ENABLE_WIDTH{1'b1}}; // always full accesses so the byte enables are all ones end else if (UNALIGNED_ACCESSES_ENABLE == 0) begin assign unsupported_byteenable = byteenable_masks[bytes_to_transfer_mux - 1]; // aligned so no unaligned adjustment required end else // unaligned case begin assign unsupported_byteenable = byteenable_masks[bytes_to_transfer_mux - 1] << (address_counter & LSB_MASK); // barrelshift adjusts for unaligned start address end endgenerate generate if (BYTE_ENABLE_WIDTH > 1) begin assign address = address_counter & { {(ADDRESS_WIDTH-BYTE_ENABLE_WIDTH_LOG2){1'b1}}, {BYTE_ENABLE_WIDTH_LOG2{1'b0}} }; // masking LSBs (byte offsets) since the address counter might not be aligned for the first transfer end else begin assign address = address_counter; // don't need to mask any bits as the address will only advance one byte at a time end endgenerate assign done = (length_counter == 0) | ((PACKET_ENABLE == 1) & (eop_enable == 1) & (eop_seen == 1) & (extra_write == 0)); assign packet_beat_size = (eop_seen == 1) ? 0 : (BYTE_ENABLE_WIDTH - buffered_empty); // when the eop arrives we can't add more to packet_bytes_buffered_d1 assign packet_bytes_buffered = packet_beat_size + packet_bytes_buffered_d1 - bytes_to_transfer; // extra_write is only applicable when unaligned accesses are performed. This extra access gets the remaining data buffered in the ST to MM adapter block written to memory assign extra_write = (UNALIGNED_ACCESSES_ENABLE == 1) & (((PACKET_ENABLE == 1) & (eop_enable == 1))? ((eop_seen == 1) & (packet_bytes_buffered_d1 != 0)) : // when packets are used if there are left over bytes buffered after eop is seen perform an extra write ((first_access == 0) & (start_byte_address != 0) & (short_last_access_enable == 1) & (start_byte_address >= length_counter[BYTE_ENABLE_WIDTH_LOG2-1:0]))); // non-packet transfer and there are extra bytes buffered so performing an extra access assign first_word_boundary_not_reached = (descriptor_length < BYTE_ENABLE_WIDTH) & // length is less than the word size (((descriptor_length & LSB_MASK) + (descriptor_address & LSB_MASK)) < BYTE_ENABLE_WIDTH); // start address + length doesn't reach the next word boundary (not used for packet transfers) assign write = ((fifo_empty == 0) | (extra_write == 1)) & (done == 0) & (stopped == 0); assign st_to_mm_adapter_enable = (done == 0) & (extra_write == 0); assign write_complete = (write == 1) & (master_waitrequest == 0) & (write_stall_from_byte_enable_generator == 0) & (write_stall_from_write_burst_control == 0); // writing still occuring and no reasons to prevent the write cycle from completing assign increment_address = ((write == 1) & (write_complete == 1)) & (stopped == 0); assign go = (snk_command_valid == 1) & (snk_command_ready == 1); // go with be one cycle since done will be set to 0 on the next cycle (length will be non-zero) assign snk_ready = (fifo_full == 0) & // need to make sure more streaming data doesn't come in when the FIFO is full (((PACKET_ENABLE == 1) & (snk_sop == 1) & (fifo_empty == 0)) != 1); // need to make sure that only one packet is buffered at any given time (sop will continue to be asserted until the buffer is written out) assign length_sync_reset = (((reset_taken == 1) | (early_termination_d1 == 1)) & (done == 0)) | (done_strobe == 1); // abrupt stop cases or packet transfer just completed (otherwise the length register will reach 0 by itself) assign fifo_write = (snk_ready == 1) & (snk_valid == 1); assign early_termination = (eop_enable == 1) & (write_complete == 1) & (length_counter < bytes_to_transfer); // packet transfer and the length counter is about to roll over so stop transfering assign stop_state = stopped; assign reset_delayed = (reset_taken == 0) & (sw_reset_in == 1); assign src_response_data = {{212{1'b0}}, done_strobe, early_termination_d1, response_error, stop_state, reset_delayed, response_actual_bytes_transferred}; /********************************************* END CONTROL AND COMBINATIONAL SIGNALS ************************************************************/ endmodule
module generic_baseblocks_v2_1_0_carry_and # ( parameter C_FAMILY = "virtex6" // FPGA Family. Current version: virtex6 or spartan6. ) ( input wire CIN, input wire S, output wire COUT ); ///////////////////////////////////////////////////////////////////////////// // Variables for generating parameter controlled instances. ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Local params ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Functions ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Internal signals ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Instantiate or use RTL code ///////////////////////////////////////////////////////////////////////////// generate if ( C_FAMILY == "rtl" ) begin : USE_RTL assign COUT = CIN & S; end else begin : USE_FPGA MUXCY and_inst ( .O (COUT), .CI (CIN), .DI (1'b0), .S (S) ); end endgenerate endmodule
module generic_baseblocks_v2_1_0_carry_and # ( parameter C_FAMILY = "virtex6" // FPGA Family. Current version: virtex6 or spartan6. ) ( input wire CIN, input wire S, output wire COUT ); ///////////////////////////////////////////////////////////////////////////// // Variables for generating parameter controlled instances. ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Local params ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Functions ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Internal signals ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Instantiate or use RTL code ///////////////////////////////////////////////////////////////////////////// generate if ( C_FAMILY == "rtl" ) begin : USE_RTL assign COUT = CIN & S; end else begin : USE_FPGA MUXCY and_inst ( .O (COUT), .CI (CIN), .DI (1'b0), .S (S) ); end endgenerate endmodule
module axi_infrastructure_v1_1_0_axic_srl_fifo #( /////////////////////////////////////////////////////////////////////////////// // Parameter Definitions /////////////////////////////////////////////////////////////////////////////// parameter C_FAMILY = "virtex7", parameter integer C_PAYLOAD_WIDTH = 1, parameter integer C_FIFO_DEPTH = 16 // Range: 4-16. ) ( /////////////////////////////////////////////////////////////////////////////// // Port Declarations /////////////////////////////////////////////////////////////////////////////// input wire aclk, // Clock input wire aresetn, // Reset input wire [C_PAYLOAD_WIDTH-1:0] s_payload, // Input data input wire s_valid, // Input data valid output reg s_ready, // Input data ready output wire [C_PAYLOAD_WIDTH-1:0] m_payload, // Output data output reg m_valid, // Output data valid input wire m_ready // Output data ready ); //////////////////////////////////////////////////////////////////////////////// // Functions //////////////////////////////////////////////////////////////////////////////// // ceiling logb2 function integer f_clogb2 (input integer size); integer s; begin s = size; s = s - 1; for (f_clogb2=1; s>1; f_clogb2=f_clogb2+1) s = s >> 1; end endfunction // clogb2 //////////////////////////////////////////////////////////////////////////////// // Local parameters //////////////////////////////////////////////////////////////////////////////// localparam integer LP_LOG_FIFO_DEPTH = f_clogb2(C_FIFO_DEPTH); //////////////////////////////////////////////////////////////////////////////// // Wires/Reg declarations //////////////////////////////////////////////////////////////////////////////// reg [LP_LOG_FIFO_DEPTH-1:0] fifo_index; wire [4-1:0] fifo_addr; wire push; wire pop ; reg areset_r1; //////////////////////////////////////////////////////////////////////////////// // BEGIN RTL //////////////////////////////////////////////////////////////////////////////// always @(posedge aclk) begin areset_r1 <= ~aresetn; end always @(posedge aclk) begin if (~aresetn) begin fifo_index <= {LP_LOG_FIFO_DEPTH{1'b1}}; end else begin fifo_index <= push & ~pop ? fifo_index + 1'b1 : ~push & pop ? fifo_index - 1'b1 : fifo_index; end end assign push = s_valid & s_ready; always @(posedge aclk) begin if (~aresetn) begin s_ready <= 1'b0; end else begin s_ready <= areset_r1 ? 1'b1 : push & ~pop && (fifo_index == (C_FIFO_DEPTH - 2'd2)) ? 1'b0 : ~push & pop ? 1'b1 : s_ready; end end assign pop = m_valid & m_ready; always @(posedge aclk) begin if (~aresetn) begin m_valid <= 1'b0; end else begin m_valid <= ~push & pop && (fifo_index == {LP_LOG_FIFO_DEPTH{1'b0}}) ? 1'b0 : push & ~pop ? 1'b1 : m_valid; end end generate if (LP_LOG_FIFO_DEPTH < 4) begin : gen_pad_fifo_addr assign fifo_addr[0+:LP_LOG_FIFO_DEPTH] = fifo_index[LP_LOG_FIFO_DEPTH-1:0]; assign fifo_addr[LP_LOG_FIFO_DEPTH+:(4-LP_LOG_FIFO_DEPTH)] = {4-LP_LOG_FIFO_DEPTH{1'b0}}; end else begin : gen_fifo_addr assign fifo_addr[LP_LOG_FIFO_DEPTH-1:0] = fifo_index[LP_LOG_FIFO_DEPTH-1:0]; end endgenerate generate genvar i; for (i = 0; i < C_PAYLOAD_WIDTH; i = i + 1) begin : gen_data_bit SRL16E u_srl_fifo( .Q ( m_payload[i] ) , .A0 ( fifo_addr[0] ) , .A1 ( fifo_addr[1] ) , .A2 ( fifo_addr[2] ) , .A3 ( fifo_addr[3] ) , .CE ( push ) , .CLK ( aclk ) , .D ( s_payload[i] ) ); end endgenerate endmodule
module axi_infrastructure_v1_1_0_axic_srl_fifo #( /////////////////////////////////////////////////////////////////////////////// // Parameter Definitions /////////////////////////////////////////////////////////////////////////////// parameter C_FAMILY = "virtex7", parameter integer C_PAYLOAD_WIDTH = 1, parameter integer C_FIFO_DEPTH = 16 // Range: 4-16. ) ( /////////////////////////////////////////////////////////////////////////////// // Port Declarations /////////////////////////////////////////////////////////////////////////////// input wire aclk, // Clock input wire aresetn, // Reset input wire [C_PAYLOAD_WIDTH-1:0] s_payload, // Input data input wire s_valid, // Input data valid output reg s_ready, // Input data ready output wire [C_PAYLOAD_WIDTH-1:0] m_payload, // Output data output reg m_valid, // Output data valid input wire m_ready // Output data ready ); //////////////////////////////////////////////////////////////////////////////// // Functions //////////////////////////////////////////////////////////////////////////////// // ceiling logb2 function integer f_clogb2 (input integer size); integer s; begin s = size; s = s - 1; for (f_clogb2=1; s>1; f_clogb2=f_clogb2+1) s = s >> 1; end endfunction // clogb2 //////////////////////////////////////////////////////////////////////////////// // Local parameters //////////////////////////////////////////////////////////////////////////////// localparam integer LP_LOG_FIFO_DEPTH = f_clogb2(C_FIFO_DEPTH); //////////////////////////////////////////////////////////////////////////////// // Wires/Reg declarations //////////////////////////////////////////////////////////////////////////////// reg [LP_LOG_FIFO_DEPTH-1:0] fifo_index; wire [4-1:0] fifo_addr; wire push; wire pop ; reg areset_r1; //////////////////////////////////////////////////////////////////////////////// // BEGIN RTL //////////////////////////////////////////////////////////////////////////////// always @(posedge aclk) begin areset_r1 <= ~aresetn; end always @(posedge aclk) begin if (~aresetn) begin fifo_index <= {LP_LOG_FIFO_DEPTH{1'b1}}; end else begin fifo_index <= push & ~pop ? fifo_index + 1'b1 : ~push & pop ? fifo_index - 1'b1 : fifo_index; end end assign push = s_valid & s_ready; always @(posedge aclk) begin if (~aresetn) begin s_ready <= 1'b0; end else begin s_ready <= areset_r1 ? 1'b1 : push & ~pop && (fifo_index == (C_FIFO_DEPTH - 2'd2)) ? 1'b0 : ~push & pop ? 1'b1 : s_ready; end end assign pop = m_valid & m_ready; always @(posedge aclk) begin if (~aresetn) begin m_valid <= 1'b0; end else begin m_valid <= ~push & pop && (fifo_index == {LP_LOG_FIFO_DEPTH{1'b0}}) ? 1'b0 : push & ~pop ? 1'b1 : m_valid; end end generate if (LP_LOG_FIFO_DEPTH < 4) begin : gen_pad_fifo_addr assign fifo_addr[0+:LP_LOG_FIFO_DEPTH] = fifo_index[LP_LOG_FIFO_DEPTH-1:0]; assign fifo_addr[LP_LOG_FIFO_DEPTH+:(4-LP_LOG_FIFO_DEPTH)] = {4-LP_LOG_FIFO_DEPTH{1'b0}}; end else begin : gen_fifo_addr assign fifo_addr[LP_LOG_FIFO_DEPTH-1:0] = fifo_index[LP_LOG_FIFO_DEPTH-1:0]; end endgenerate generate genvar i; for (i = 0; i < C_PAYLOAD_WIDTH; i = i + 1) begin : gen_data_bit SRL16E u_srl_fifo( .Q ( m_payload[i] ) , .A0 ( fifo_addr[0] ) , .A1 ( fifo_addr[1] ) , .A2 ( fifo_addr[2] ) , .A3 ( fifo_addr[3] ) , .CE ( push ) , .CLK ( aclk ) , .D ( s_payload[i] ) ); end endgenerate endmodule
module axi_infrastructure_v1_1_0_axic_srl_fifo #( /////////////////////////////////////////////////////////////////////////////// // Parameter Definitions /////////////////////////////////////////////////////////////////////////////// parameter C_FAMILY = "virtex7", parameter integer C_PAYLOAD_WIDTH = 1, parameter integer C_FIFO_DEPTH = 16 // Range: 4-16. ) ( /////////////////////////////////////////////////////////////////////////////// // Port Declarations /////////////////////////////////////////////////////////////////////////////// input wire aclk, // Clock input wire aresetn, // Reset input wire [C_PAYLOAD_WIDTH-1:0] s_payload, // Input data input wire s_valid, // Input data valid output reg s_ready, // Input data ready output wire [C_PAYLOAD_WIDTH-1:0] m_payload, // Output data output reg m_valid, // Output data valid input wire m_ready // Output data ready ); //////////////////////////////////////////////////////////////////////////////// // Functions //////////////////////////////////////////////////////////////////////////////// // ceiling logb2 function integer f_clogb2 (input integer size); integer s; begin s = size; s = s - 1; for (f_clogb2=1; s>1; f_clogb2=f_clogb2+1) s = s >> 1; end endfunction // clogb2 //////////////////////////////////////////////////////////////////////////////// // Local parameters //////////////////////////////////////////////////////////////////////////////// localparam integer LP_LOG_FIFO_DEPTH = f_clogb2(C_FIFO_DEPTH); //////////////////////////////////////////////////////////////////////////////// // Wires/Reg declarations //////////////////////////////////////////////////////////////////////////////// reg [LP_LOG_FIFO_DEPTH-1:0] fifo_index; wire [4-1:0] fifo_addr; wire push; wire pop ; reg areset_r1; //////////////////////////////////////////////////////////////////////////////// // BEGIN RTL //////////////////////////////////////////////////////////////////////////////// always @(posedge aclk) begin areset_r1 <= ~aresetn; end always @(posedge aclk) begin if (~aresetn) begin fifo_index <= {LP_LOG_FIFO_DEPTH{1'b1}}; end else begin fifo_index <= push & ~pop ? fifo_index + 1'b1 : ~push & pop ? fifo_index - 1'b1 : fifo_index; end end assign push = s_valid & s_ready; always @(posedge aclk) begin if (~aresetn) begin s_ready <= 1'b0; end else begin s_ready <= areset_r1 ? 1'b1 : push & ~pop && (fifo_index == (C_FIFO_DEPTH - 2'd2)) ? 1'b0 : ~push & pop ? 1'b1 : s_ready; end end assign pop = m_valid & m_ready; always @(posedge aclk) begin if (~aresetn) begin m_valid <= 1'b0; end else begin m_valid <= ~push & pop && (fifo_index == {LP_LOG_FIFO_DEPTH{1'b0}}) ? 1'b0 : push & ~pop ? 1'b1 : m_valid; end end generate if (LP_LOG_FIFO_DEPTH < 4) begin : gen_pad_fifo_addr assign fifo_addr[0+:LP_LOG_FIFO_DEPTH] = fifo_index[LP_LOG_FIFO_DEPTH-1:0]; assign fifo_addr[LP_LOG_FIFO_DEPTH+:(4-LP_LOG_FIFO_DEPTH)] = {4-LP_LOG_FIFO_DEPTH{1'b0}}; end else begin : gen_fifo_addr assign fifo_addr[LP_LOG_FIFO_DEPTH-1:0] = fifo_index[LP_LOG_FIFO_DEPTH-1:0]; end endgenerate generate genvar i; for (i = 0; i < C_PAYLOAD_WIDTH; i = i + 1) begin : gen_data_bit SRL16E u_srl_fifo( .Q ( m_payload[i] ) , .A0 ( fifo_addr[0] ) , .A1 ( fifo_addr[1] ) , .A2 ( fifo_addr[2] ) , .A3 ( fifo_addr[3] ) , .CE ( push ) , .CLK ( aclk ) , .D ( s_payload[i] ) ); end endgenerate endmodule
module reset_and_status #( parameter PIO_WIDTH=32 ) ( input clk, input resetn, output reg [PIO_WIDTH-1 : 0 ] pio_in, input [PIO_WIDTH-1 : 0 ] pio_out, input lock_kernel_pll, input fixedclk_locked, // pcie fixedclk lock input mem0_local_cal_success, input mem0_local_cal_fail, input mem0_local_init_done, input mem1_local_cal_success, input mem1_local_cal_fail, input mem1_local_init_done, output reg [1:0] mem_organization, output [1:0] mem_organization_export, output pll_reset, output reg sw_reset_n_out ); reg [1:0] pio_out_ddr_mode; reg pio_out_pll_reset; reg pio_out_sw_reset; reg [9:0] reset_count; always@(posedge clk or negedge resetn) if (!resetn) reset_count <= 10'b0; else if (pio_out_sw_reset) reset_count <= 10'b0; else if (!reset_count[9]) reset_count <= reset_count + 2'b01; // false paths set for pio_out_* (* altera_attribute = "-name SDC_STATEMENT \"set_false_path -to [get_registers *pio_out_*]\"" *) always@(posedge clk) begin pio_out_ddr_mode = pio_out[9:8]; pio_out_pll_reset = pio_out[30]; pio_out_sw_reset = pio_out[31]; end // false paths for pio_in - these are asynchronous (* altera_attribute = "-name SDC_STATEMENT \"set_false_path -to [get_registers *pio_in*]\"" *) always@(posedge clk) begin pio_in = { lock_kernel_pll, fixedclk_locked, 1'b0, 1'b0, mem1_local_cal_fail, mem0_local_cal_fail, mem1_local_cal_success, mem1_local_init_done, mem0_local_cal_success, mem0_local_init_done}; end (* altera_attribute = "-name SDC_STATEMENT \"set_false_path -from [get_registers *mem_organization*]\"" *) always@(posedge clk) mem_organization = pio_out_ddr_mode; assign mem_organization_export = mem_organization; assign pll_reset = pio_out_pll_reset; // Export sw kernel reset out of iface to connect to kernel always@(posedge clk) sw_reset_n_out = !(!reset_count[9] && (reset_count[8:0] != 0)); endmodule
module generic_baseblocks_v2_1_0_mux # ( parameter C_FAMILY = "rtl", // FPGA Family. Current version: virtex6 or spartan6. parameter integer C_SEL_WIDTH = 4, // Data width for comparator. parameter integer C_DATA_WIDTH = 2 // Data width for comparator. ) ( input wire [C_SEL_WIDTH-1:0] S, input wire [(2**C_SEL_WIDTH)*C_DATA_WIDTH-1:0] A, output wire [C_DATA_WIDTH-1:0] O ); ///////////////////////////////////////////////////////////////////////////// // Variables for generating parameter controlled instances. ///////////////////////////////////////////////////////////////////////////// // Generate variable for bit vector. genvar bit_cnt; ///////////////////////////////////////////////////////////////////////////// // Local params ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Functions ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Internal signals ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Instantiate or use RTL code ///////////////////////////////////////////////////////////////////////////// generate if ( C_FAMILY == "rtl" || C_SEL_WIDTH < 3 ) begin : USE_RTL assign O = A[(S)*C_DATA_WIDTH +: C_DATA_WIDTH]; end else begin : USE_FPGA wire [C_DATA_WIDTH-1:0] C; wire [C_DATA_WIDTH-1:0] D; // Lower half recursively. generic_baseblocks_v2_1_0_mux # ( .C_FAMILY (C_FAMILY), .C_SEL_WIDTH (C_SEL_WIDTH-1), .C_DATA_WIDTH (C_DATA_WIDTH) ) mux_c_inst ( .S (S[C_SEL_WIDTH-2:0]), .A (A[(2**(C_SEL_WIDTH-1))*C_DATA_WIDTH-1 : 0]), .O (C) ); // Upper half recursively. generic_baseblocks_v2_1_0_mux # ( .C_FAMILY (C_FAMILY), .C_SEL_WIDTH (C_SEL_WIDTH-1), .C_DATA_WIDTH (C_DATA_WIDTH) ) mux_d_inst ( .S (S[C_SEL_WIDTH-2:0]), .A (A[(2**C_SEL_WIDTH)*C_DATA_WIDTH-1 : (2**(C_SEL_WIDTH-1))*C_DATA_WIDTH]), .O (D) ); // Generate instantiated generic_baseblocks_v2_1_0_mux components as required. for (bit_cnt = 0; bit_cnt < C_DATA_WIDTH ; bit_cnt = bit_cnt + 1) begin : NUM if ( C_SEL_WIDTH == 4 ) begin : USE_F8 MUXF8 muxf8_inst ( .I0 (C[bit_cnt]), .I1 (D[bit_cnt]), .S (S[C_SEL_WIDTH-1]), .O (O[bit_cnt]) ); end else if ( C_SEL_WIDTH == 3 ) begin : USE_F7 MUXF7 muxf7_inst ( .I0 (C[bit_cnt]), .I1 (D[bit_cnt]), .S (S[C_SEL_WIDTH-1]), .O (O[bit_cnt]) ); end // C_SEL_WIDTH end // end for bit_cnt end endgenerate endmodule
module generic_baseblocks_v2_1_0_mux # ( parameter C_FAMILY = "rtl", // FPGA Family. Current version: virtex6 or spartan6. parameter integer C_SEL_WIDTH = 4, // Data width for comparator. parameter integer C_DATA_WIDTH = 2 // Data width for comparator. ) ( input wire [C_SEL_WIDTH-1:0] S, input wire [(2**C_SEL_WIDTH)*C_DATA_WIDTH-1:0] A, output wire [C_DATA_WIDTH-1:0] O ); ///////////////////////////////////////////////////////////////////////////// // Variables for generating parameter controlled instances. ///////////////////////////////////////////////////////////////////////////// // Generate variable for bit vector. genvar bit_cnt; ///////////////////////////////////////////////////////////////////////////// // Local params ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Functions ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Internal signals ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Instantiate or use RTL code ///////////////////////////////////////////////////////////////////////////// generate if ( C_FAMILY == "rtl" || C_SEL_WIDTH < 3 ) begin : USE_RTL assign O = A[(S)*C_DATA_WIDTH +: C_DATA_WIDTH]; end else begin : USE_FPGA wire [C_DATA_WIDTH-1:0] C; wire [C_DATA_WIDTH-1:0] D; // Lower half recursively. generic_baseblocks_v2_1_0_mux # ( .C_FAMILY (C_FAMILY), .C_SEL_WIDTH (C_SEL_WIDTH-1), .C_DATA_WIDTH (C_DATA_WIDTH) ) mux_c_inst ( .S (S[C_SEL_WIDTH-2:0]), .A (A[(2**(C_SEL_WIDTH-1))*C_DATA_WIDTH-1 : 0]), .O (C) ); // Upper half recursively. generic_baseblocks_v2_1_0_mux # ( .C_FAMILY (C_FAMILY), .C_SEL_WIDTH (C_SEL_WIDTH-1), .C_DATA_WIDTH (C_DATA_WIDTH) ) mux_d_inst ( .S (S[C_SEL_WIDTH-2:0]), .A (A[(2**C_SEL_WIDTH)*C_DATA_WIDTH-1 : (2**(C_SEL_WIDTH-1))*C_DATA_WIDTH]), .O (D) ); // Generate instantiated generic_baseblocks_v2_1_0_mux components as required. for (bit_cnt = 0; bit_cnt < C_DATA_WIDTH ; bit_cnt = bit_cnt + 1) begin : NUM if ( C_SEL_WIDTH == 4 ) begin : USE_F8 MUXF8 muxf8_inst ( .I0 (C[bit_cnt]), .I1 (D[bit_cnt]), .S (S[C_SEL_WIDTH-1]), .O (O[bit_cnt]) ); end else if ( C_SEL_WIDTH == 3 ) begin : USE_F7 MUXF7 muxf7_inst ( .I0 (C[bit_cnt]), .I1 (D[bit_cnt]), .S (S[C_SEL_WIDTH-1]), .O (O[bit_cnt]) ); end // C_SEL_WIDTH end // end for bit_cnt end endgenerate endmodule
module dispatcher ( clk, reset, // 128/256 bit write only port for feeding the dispatcher descriptors, no address since it's only one word wide, blocking when too many descriptors are buffered descriptor_writedata, descriptor_byteenable, descriptor_write, descriptor_waitrequest, // control and status port, 32 bits wide with a read latency of 2 and non-blocking csr_writedata, csr_byteenable, csr_write, csr_readdata, csr_read, csr_address, // 4 addresses when ENHANCED_FEATURES is off (zero) otherwise 8 addresses are available csr_irq, // only available if the response port is not an ST source (in that case the SGDMA pre-fetching block will issue interrupts) // response slave port (when "RESPONSE_PORT" is set to 0), 32 bits wide, read only, and a read latency of 3 cycles mm_response_readdata, mm_response_read, mm_response_address, // only two addresses mm_response_byteenable, // last byte read pops the response FIFO mm_response_waitrequest, // response source port (when "RESPONSE_PORT" is set to 1), src_response_data, src_response_valid, src_response_ready, // write master source port (sends commands to write master) src_write_master_data, src_write_master_valid, src_write_master_ready, // write master sink port (recieves response from write master) snk_write_master_data, snk_write_master_valid, snk_write_master_ready, // read master source port (sends commands to read master) src_read_master_data, src_read_master_valid, src_read_master_ready, // read master sink port (recieves response from the read master) snk_read_master_data, snk_read_master_valid, snk_read_master_ready ); // y = log2(x) function integer log2; input integer x; begin x = x-1; for(log2=0; x>0; log2=log2+1) x = x>>1; end endfunction parameter MODE = 0; // 0 for MM->MM, 1 for MM->ST, 2 for ST->MM parameter RESPONSE_PORT = 0; // 0 for MM, 1 for ST, 2 for Disabled // normally disabled for all but ST->MM transfers parameter DESCRIPTOR_FIFO_DEPTH = 128; // 16-1024 in powers of 2 parameter ENHANCED_FEATURES = 1; // 1 for Enabled, 0 for Disabled parameter DESCRIPTOR_WIDTH = 256; // 256 when enhanced mode is on, 128 for off (needs to be controlled by callback since it influences data width) parameter DESCRIPTOR_BYTEENABLE_WIDTH = 32; // 32 when enhanced mode is on, 16 for off (needs to be controlled by callback since it influences byte enable width) parameter CSR_ADDRESS_WIDTH = 3; // always 3 bits wide localparam RESPONSE_FIFO_DEPTH = 2 * DESCRIPTOR_FIFO_DEPTH; localparam DESCRIPTOR_FIFO_DEPTH_LOG2 = log2(DESCRIPTOR_FIFO_DEPTH); localparam RESPONSE_FIFO_DEPTH_LOG2 = log2(RESPONSE_FIFO_DEPTH); input clk; input reset; input [DESCRIPTOR_WIDTH-1:0] descriptor_writedata; input [DESCRIPTOR_BYTEENABLE_WIDTH-1:0] descriptor_byteenable; input descriptor_write; output wire descriptor_waitrequest; input [31:0] csr_writedata; input [3:0] csr_byteenable; input csr_write; output wire [31:0] csr_readdata; input csr_read; input [CSR_ADDRESS_WIDTH-1:0] csr_address; output wire csr_irq; // Used by a host with a master (like Nios II) output wire [31:0] mm_response_readdata; input mm_response_read; input mm_response_address; input [3:0] mm_response_byteenable; output wire mm_response_waitrequest; // Used by a pre-fetching master output wire [255:0] src_response_data; // making wide in case we need to jam more signals in here, unnecessary bits will be grounded/optimized away output wire src_response_valid; input src_response_ready; output wire [255:0] src_write_master_data; // don't know how many bits the master will use, unnecessary bits will be grounded/optimized away output wire src_write_master_valid; input src_write_master_ready; input [255:0] snk_write_master_data; // might need to jam more bits in...... input snk_write_master_valid; output wire snk_write_master_ready; output wire [255:0] src_read_master_data; // don't know how many bits the master will use, unnecessary bits will be grounded/optimized away output wire src_read_master_valid; input src_read_master_ready; input [255:0] snk_read_master_data; // might need to jam more bits in...... input snk_read_master_valid; output wire snk_read_master_ready; /* Internal wires and registers */ // descriptor information wire read_command_valid; wire read_command_ready; wire [255:0] read_command_data; wire read_command_empty; wire read_command_full; wire [DESCRIPTOR_FIFO_DEPTH_LOG2:0] read_command_used; // true used signal so extra MSB is included wire write_command_valid; wire write_command_ready; wire [255:0] write_command_data; wire write_command_empty; wire write_command_full; wire [DESCRIPTOR_FIFO_DEPTH_LOG2:0] write_command_used; // true used signal so extra MSB is included wire [31:0] sequence_number; wire transfer_complete_IRQ_mask; wire early_termination_IRQ_mask; wire [7:0] error_IRQ_mask; wire descriptor_buffer_empty; wire descriptor_buffer_full; wire [15:0] write_descriptor_watermark; wire [15:0] read_descriptor_watermark; wire [31:0] descriptor_watermark; wire busy; wire done; wire done_strobe; wire stop_issuing_commands; wire stop; wire sw_reset; wire stop_on_error; wire stop_on_early_termination; wire stop_descriptors; wire reset_stalled; wire master_stop_state; wire descriptors_stop_state; wire stop_state; wire stopped_on_error; wire stopped_on_early_termination; wire response_fifo_full; wire response_fifo_empty; wire [15:0] response_watermark; wire [7:0] response_error; wire response_early_termination; wire [31:0] response_actual_bytes_transferred; /************************************************ REGISTERS *******************************************************/ /********************************************** END REGISTERS *****************************************************/ /******************************************* MODULE DECLERATIONS **************************************************/ // the descriptor buffers block instantiates the descriptor FIFOs and handshaking logic with the master command ports descriptor_buffers the_descriptor_buffers ( .clk (clk), .reset (reset), .writedata (descriptor_writedata), .write (descriptor_write), .byteenable (descriptor_byteenable), .waitrequest (descriptor_waitrequest), .read_command_valid (read_command_valid), .read_command_ready (read_command_ready), .read_command_data (read_command_data), .read_command_empty (read_command_empty), .read_command_full (read_command_full), .read_command_used (read_command_used), .write_command_valid (write_command_valid), .write_command_ready (write_command_ready), .write_command_data (write_command_data), .write_command_empty (write_command_empty), .write_command_full (write_command_full), .write_command_used (write_command_used), .stop_issuing_commands (stop_issuing_commands), .stop (stop), .sw_reset (sw_reset), .sequence_number (sequence_number), .transfer_complete_IRQ_mask (transfer_complete_IRQ_mask), .early_termination_IRQ_mask (early_termination_IRQ_mask), .error_IRQ_mask (error_IRQ_mask) ); defparam the_descriptor_buffers.MODE = MODE; defparam the_descriptor_buffers.DATA_WIDTH = DESCRIPTOR_WIDTH; defparam the_descriptor_buffers.BYTE_ENABLE_WIDTH = DESCRIPTOR_WIDTH/8; defparam the_descriptor_buffers.FIFO_DEPTH = DESCRIPTOR_FIFO_DEPTH; defparam the_descriptor_buffers.FIFO_DEPTH_LOG2 = DESCRIPTOR_FIFO_DEPTH_LOG2; // Control and status registers (and interrupts when a host connects directly to this block) csr_block the_csr_block ( .clk (clk), .reset (reset), .csr_writedata (csr_writedata), .csr_write (csr_write), .csr_byteenable (csr_byteenable), .csr_readdata (csr_readdata), .csr_read (csr_read), .csr_address (csr_address), .csr_irq (csr_irq), .done_strobe (done_strobe), .busy (busy), .descriptor_buffer_empty (descriptor_buffer_empty), .descriptor_buffer_full (descriptor_buffer_full), .stop_state (stop_state), .stopped_on_error (stopped_on_error), .stopped_on_early_termination (stopped_on_early_termination), .stop_descriptors (stop_descriptors), .reset_stalled (reset_stalled), // from the master(s) to tell the CSR block that it's still resetting .stop (stop), .sw_reset (sw_reset), .stop_on_error (stop_on_error), .stop_on_early_termination (stop_on_early_termination), .sequence_number (sequence_number), .descriptor_watermark (descriptor_watermark), .response_watermark (response_watermark), .response_buffer_empty (response_fifo_empty), .response_buffer_full (response_fifo_full), .transfer_complete_IRQ_mask (transfer_complete_IRQ_mask), .error_IRQ_mask (error_IRQ_mask), .early_termination_IRQ_mask (early_termination_IRQ_mask), .error (response_error), .early_termination (response_early_termination) ); defparam the_csr_block.ADDRESS_WIDTH = CSR_ADDRESS_WIDTH; // Optional response port. When using a directly connected host it'll be a slave port and using a pre-fetching descriptor master it will be a streaming source port. response_block the_response_block ( .clk (clk), .reset (reset), .mm_response_readdata (mm_response_readdata), .mm_response_read (mm_response_read), .mm_response_address (mm_response_address), .mm_response_byteenable (mm_response_byteenable), .mm_response_waitrequest (mm_response_waitrequest), .src_response_data (src_response_data), .src_response_valid (src_response_valid), .src_response_ready (src_response_ready), .sw_reset (sw_reset), .response_watermark (response_watermark), .response_fifo_full (response_fifo_full), .response_fifo_empty (response_fifo_empty), .done_strobe (done_strobe), .actual_bytes_transferred (response_actual_bytes_transferred), .error (response_error), .early_termination (response_early_termination), .transfer_complete_IRQ_mask (transfer_complete_IRQ_mask), .error_IRQ_mask (error_IRQ_mask), .early_termination_IRQ_mask (early_termination_IRQ_mask), .descriptor_buffer_full (descriptor_buffer_full) ); defparam the_response_block.RESPONSE_PORT = RESPONSE_PORT; defparam the_response_block.FIFO_DEPTH = RESPONSE_FIFO_DEPTH; defparam the_response_block.FIFO_DEPTH_LOG2 = RESPONSE_FIFO_DEPTH_LOG2; /***************************************** END MODULE DECLERATIONS ************************************************/ /****************************************** COMBINATIONAL SIGNALS *************************************************/ // this block issues the commands so it's always ready for a response. The response FIFO fill level will be used to // make sure additional ST-->MM commands are not issued if there is no room to catch the response. assign snk_write_master_ready = 1'b1; assign snk_read_master_ready = 1'b1; assign done = (MODE == 1)? snk_read_master_ready : snk_write_master_ready; assign done_strobe = (MODE == 1)? (snk_read_master_ready & snk_read_master_valid) : (snk_write_master_ready & snk_write_master_valid); assign stop_issuing_commands = (response_fifo_full == 1) | (stop_descriptors == 1); assign src_write_master_valid = write_command_valid; assign write_command_ready = src_write_master_ready; assign src_write_master_data = write_command_data; assign src_read_master_valid = read_command_valid; assign read_command_ready = src_read_master_ready; assign src_read_master_data = read_command_data; assign busy = (read_command_empty == 0) | (write_command_empty == 0) | // still have descriptors buffered in the FIFOs (done == 0); // current transfer is still occuring assign descriptor_buffer_empty = (read_command_empty == 1) & (write_command_empty == 1); assign descriptor_buffer_full = (read_command_full == 1) | (write_command_full == 1); assign write_descriptor_watermark = 16'h0000 | write_command_used; // zero padding the upper unused bits assign read_descriptor_watermark = 16'h0000 | read_command_used; // zero padding the upper unused bits assign descriptor_watermark = {write_descriptor_watermark, read_descriptor_watermark}; assign reset_stalled = snk_read_master_data[0] | snk_write_master_data[32]; assign master_stop_state = ((MODE == 0)? (snk_read_master_data[1] & snk_write_master_data[33]) : (MODE == 1)? snk_read_master_data[1] : snk_write_master_data[33]); assign descriptors_stop_state = (stop_descriptors == 1) & ((MODE == 0)? ((src_read_master_ready == 1) & (src_write_master_ready == 1)) : (MODE == 1)? (src_read_master_ready == 1) : (src_write_master_ready == 1)); assign stop_state = (master_stop_state == 1) | (descriptors_stop_state == 1); assign response_actual_bytes_transferred = snk_write_master_data[31:0]; assign response_error = snk_write_master_data[41:34]; assign response_early_termination = snk_write_master_data[42]; /**************************************** END COMBINATIONAL SIGNALS ***********************************************/ endmodule
module channel_ram ( // System input txclk, input reset, // USB side input [31:0] datain, input WR, input WR_done, output have_space, // Reader side output [31:0] dataout, input RD, input RD_done, output packet_waiting); reg [6:0] wr_addr, rd_addr; reg [1:0] which_ram_wr, which_ram_rd; reg [2:0] nb_packets; reg [31:0] ram0 [0:127]; reg [31:0] ram1 [0:127]; reg [31:0] ram2 [0:127]; reg [31:0] ram3 [0:127]; reg [31:0] dataout0; reg [31:0] dataout1; reg [31:0] dataout2; reg [31:0] dataout3; wire wr_done_int; wire rd_done_int; wire [6:0] rd_addr_final; wire [1:0] which_ram_rd_final; // USB side always @(posedge txclk) if(WR & (which_ram_wr == 2'd0)) ram0[wr_addr] <= datain; always @(posedge txclk) if(WR & (which_ram_wr == 2'd1)) ram1[wr_addr] <= datain; always @(posedge txclk) if(WR & (which_ram_wr == 2'd2)) ram2[wr_addr] <= datain; always @(posedge txclk) if(WR & (which_ram_wr == 2'd3)) ram3[wr_addr] <= datain; assign wr_done_int = ((WR && (wr_addr == 7'd127)) || WR_done); always @(posedge txclk) if(reset) wr_addr <= 0; else if (WR_done) wr_addr <= 0; else if (WR) wr_addr <= wr_addr + 7'd1; always @(posedge txclk) if(reset) which_ram_wr <= 0; else if (wr_done_int) which_ram_wr <= which_ram_wr + 2'd1; assign have_space = (nb_packets < 3'd3); // Reader side // short hand fifo // rd_addr_final is what rd_addr is going to be next clock cycle // which_ram_rd_final is what which_ram_rd is going to be next clock cycle always @(posedge txclk) dataout0 <= ram0[rd_addr_final]; always @(posedge txclk) dataout1 <= ram1[rd_addr_final]; always @(posedge txclk) dataout2 <= ram2[rd_addr_final]; always @(posedge txclk) dataout3 <= ram3[rd_addr_final]; assign dataout = (which_ram_rd_final[1]) ? (which_ram_rd_final[0] ? dataout3 : dataout2) : (which_ram_rd_final[0] ? dataout1 : dataout0); //RD_done is the only way to signal the end of one packet assign rd_done_int = RD_done; always @(posedge txclk) if (reset) rd_addr <= 0; else if (RD_done) rd_addr <= 0; else if (RD) rd_addr <= rd_addr + 7'd1; assign rd_addr_final = (reset|RD_done) ? (6'd0) : ((RD)?(rd_addr+7'd1):rd_addr); always @(posedge txclk) if (reset) which_ram_rd <= 0; else if (rd_done_int) which_ram_rd <= which_ram_rd + 2'd1; assign which_ram_rd_final = (reset) ? (2'd0): ((rd_done_int) ? (which_ram_rd + 2'd1) : which_ram_rd); //packet_waiting is set to zero if rd_done_int is high //because there is no guarantee that nb_packets will be pos. assign packet_waiting = (nb_packets > 1) | ((nb_packets == 1)&(~rd_done_int)); always @(posedge txclk) if (reset) nb_packets <= 0; else if (wr_done_int & ~rd_done_int) nb_packets <= nb_packets + 3'd1; else if (rd_done_int & ~wr_done_int) nb_packets <= nb_packets - 3'd1; endmodule
module channel_ram ( // System input txclk, input reset, // USB side input [31:0] datain, input WR, input WR_done, output have_space, // Reader side output [31:0] dataout, input RD, input RD_done, output packet_waiting); reg [6:0] wr_addr, rd_addr; reg [1:0] which_ram_wr, which_ram_rd; reg [2:0] nb_packets; reg [31:0] ram0 [0:127]; reg [31:0] ram1 [0:127]; reg [31:0] ram2 [0:127]; reg [31:0] ram3 [0:127]; reg [31:0] dataout0; reg [31:0] dataout1; reg [31:0] dataout2; reg [31:0] dataout3; wire wr_done_int; wire rd_done_int; wire [6:0] rd_addr_final; wire [1:0] which_ram_rd_final; // USB side always @(posedge txclk) if(WR & (which_ram_wr == 2'd0)) ram0[wr_addr] <= datain; always @(posedge txclk) if(WR & (which_ram_wr == 2'd1)) ram1[wr_addr] <= datain; always @(posedge txclk) if(WR & (which_ram_wr == 2'd2)) ram2[wr_addr] <= datain; always @(posedge txclk) if(WR & (which_ram_wr == 2'd3)) ram3[wr_addr] <= datain; assign wr_done_int = ((WR && (wr_addr == 7'd127)) || WR_done); always @(posedge txclk) if(reset) wr_addr <= 0; else if (WR_done) wr_addr <= 0; else if (WR) wr_addr <= wr_addr + 7'd1; always @(posedge txclk) if(reset) which_ram_wr <= 0; else if (wr_done_int) which_ram_wr <= which_ram_wr + 2'd1; assign have_space = (nb_packets < 3'd3); // Reader side // short hand fifo // rd_addr_final is what rd_addr is going to be next clock cycle // which_ram_rd_final is what which_ram_rd is going to be next clock cycle always @(posedge txclk) dataout0 <= ram0[rd_addr_final]; always @(posedge txclk) dataout1 <= ram1[rd_addr_final]; always @(posedge txclk) dataout2 <= ram2[rd_addr_final]; always @(posedge txclk) dataout3 <= ram3[rd_addr_final]; assign dataout = (which_ram_rd_final[1]) ? (which_ram_rd_final[0] ? dataout3 : dataout2) : (which_ram_rd_final[0] ? dataout1 : dataout0); //RD_done is the only way to signal the end of one packet assign rd_done_int = RD_done; always @(posedge txclk) if (reset) rd_addr <= 0; else if (RD_done) rd_addr <= 0; else if (RD) rd_addr <= rd_addr + 7'd1; assign rd_addr_final = (reset|RD_done) ? (6'd0) : ((RD)?(rd_addr+7'd1):rd_addr); always @(posedge txclk) if (reset) which_ram_rd <= 0; else if (rd_done_int) which_ram_rd <= which_ram_rd + 2'd1; assign which_ram_rd_final = (reset) ? (2'd0): ((rd_done_int) ? (which_ram_rd + 2'd1) : which_ram_rd); //packet_waiting is set to zero if rd_done_int is high //because there is no guarantee that nb_packets will be pos. assign packet_waiting = (nb_packets > 1) | ((nb_packets == 1)&(~rd_done_int)); always @(posedge txclk) if (reset) nb_packets <= 0; else if (wr_done_int & ~rd_done_int) nb_packets <= nb_packets + 3'd1; else if (rd_done_int & ~wr_done_int) nb_packets <= nb_packets - 3'd1; endmodule
module channel_ram ( // System input txclk, input reset, // USB side input [31:0] datain, input WR, input WR_done, output have_space, // Reader side output [31:0] dataout, input RD, input RD_done, output packet_waiting); reg [6:0] wr_addr, rd_addr; reg [1:0] which_ram_wr, which_ram_rd; reg [2:0] nb_packets; reg [31:0] ram0 [0:127]; reg [31:0] ram1 [0:127]; reg [31:0] ram2 [0:127]; reg [31:0] ram3 [0:127]; reg [31:0] dataout0; reg [31:0] dataout1; reg [31:0] dataout2; reg [31:0] dataout3; wire wr_done_int; wire rd_done_int; wire [6:0] rd_addr_final; wire [1:0] which_ram_rd_final; // USB side always @(posedge txclk) if(WR & (which_ram_wr == 2'd0)) ram0[wr_addr] <= datain; always @(posedge txclk) if(WR & (which_ram_wr == 2'd1)) ram1[wr_addr] <= datain; always @(posedge txclk) if(WR & (which_ram_wr == 2'd2)) ram2[wr_addr] <= datain; always @(posedge txclk) if(WR & (which_ram_wr == 2'd3)) ram3[wr_addr] <= datain; assign wr_done_int = ((WR && (wr_addr == 7'd127)) || WR_done); always @(posedge txclk) if(reset) wr_addr <= 0; else if (WR_done) wr_addr <= 0; else if (WR) wr_addr <= wr_addr + 7'd1; always @(posedge txclk) if(reset) which_ram_wr <= 0; else if (wr_done_int) which_ram_wr <= which_ram_wr + 2'd1; assign have_space = (nb_packets < 3'd3); // Reader side // short hand fifo // rd_addr_final is what rd_addr is going to be next clock cycle // which_ram_rd_final is what which_ram_rd is going to be next clock cycle always @(posedge txclk) dataout0 <= ram0[rd_addr_final]; always @(posedge txclk) dataout1 <= ram1[rd_addr_final]; always @(posedge txclk) dataout2 <= ram2[rd_addr_final]; always @(posedge txclk) dataout3 <= ram3[rd_addr_final]; assign dataout = (which_ram_rd_final[1]) ? (which_ram_rd_final[0] ? dataout3 : dataout2) : (which_ram_rd_final[0] ? dataout1 : dataout0); //RD_done is the only way to signal the end of one packet assign rd_done_int = RD_done; always @(posedge txclk) if (reset) rd_addr <= 0; else if (RD_done) rd_addr <= 0; else if (RD) rd_addr <= rd_addr + 7'd1; assign rd_addr_final = (reset|RD_done) ? (6'd0) : ((RD)?(rd_addr+7'd1):rd_addr); always @(posedge txclk) if (reset) which_ram_rd <= 0; else if (rd_done_int) which_ram_rd <= which_ram_rd + 2'd1; assign which_ram_rd_final = (reset) ? (2'd0): ((rd_done_int) ? (which_ram_rd + 2'd1) : which_ram_rd); //packet_waiting is set to zero if rd_done_int is high //because there is no guarantee that nb_packets will be pos. assign packet_waiting = (nb_packets > 1) | ((nb_packets == 1)&(~rd_done_int)); always @(posedge txclk) if (reset) nb_packets <= 0; else if (wr_done_int & ~rd_done_int) nb_packets <= nb_packets + 3'd1; else if (rd_done_int & ~wr_done_int) nb_packets <= nb_packets - 3'd1; endmodule
module usb_packet_fifo ( input reset, input clock_in, input clock_out, input [15:0]ram_data_in, input write_enable, output reg [15:0]ram_data_out, output reg pkt_waiting, output reg have_space, input read_enable, input skip_packet ) ; /* Some parameters for usage later on */ parameter DATA_WIDTH = 16 ; parameter NUM_PACKETS = 4 ; /* Create the RAM here */ reg [DATA_WIDTH-1:0] usb_ram [256*NUM_PACKETS-1:0] ; /* Create the address signals */ reg [7-2+NUM_PACKETS:0] usb_ram_ain ; reg [7:0] usb_ram_offset ; reg [1:0] usb_ram_packet ; wire [7-2+NUM_PACKETS:0] usb_ram_aout ; reg isfull; assign usb_ram_aout = {usb_ram_packet,usb_ram_offset} ; // Check if there is one full packet to process always @(usb_ram_ain, usb_ram_aout) begin if (reset) pkt_waiting <= 0; else if (usb_ram_ain == usb_ram_aout) pkt_waiting <= isfull; else if (usb_ram_ain > usb_ram_aout) pkt_waiting <= (usb_ram_ain - usb_ram_aout) >= 256; else pkt_waiting <= (usb_ram_ain + 10'b1111111111 - usb_ram_aout) >= 256; end // Check if there is room always @(usb_ram_ain, usb_ram_aout) begin if (reset) have_space <= 1; else if (usb_ram_ain == usb_ram_aout) have_space <= ~isfull; else if (usb_ram_ain > usb_ram_aout) have_space <= (usb_ram_ain - usb_ram_aout) <= 256 * (NUM_PACKETS - 1); else have_space <= (usb_ram_aout - usb_ram_ain) >= 256; end /* RAM Write Address process */ always @(posedge clock_in) begin if( reset ) usb_ram_ain <= 0 ; else if( write_enable ) begin usb_ram_ain <= usb_ram_ain + 1 ; if (usb_ram_ain + 1 == usb_ram_aout) isfull <= 1; end end /* RAM Writing process */ always @(posedge clock_in) begin if( write_enable ) begin usb_ram[usb_ram_ain] <= ram_data_in ; end end /* RAM Read Address process */ always @(posedge clock_out) begin if( reset ) begin usb_ram_packet <= 0 ; usb_ram_offset <= 0 ; isfull <= 0; end else if( skip_packet ) begin usb_ram_packet <= usb_ram_packet + 1 ; usb_ram_offset <= 0 ; end else if(read_enable) if( usb_ram_offset == 8'b11111111 ) begin usb_ram_offset <= 0 ; usb_ram_packet <= usb_ram_packet + 1 ; end else usb_ram_offset <= usb_ram_offset + 1 ; if (usb_ram_ain == usb_ram_aout) isfull <= 0; end /* RAM Reading Process */ always @(posedge clock_out) begin ram_data_out <= usb_ram[usb_ram_aout] ; end endmodule
module usb_packet_fifo ( input reset, input clock_in, input clock_out, input [15:0]ram_data_in, input write_enable, output reg [15:0]ram_data_out, output reg pkt_waiting, output reg have_space, input read_enable, input skip_packet ) ; /* Some parameters for usage later on */ parameter DATA_WIDTH = 16 ; parameter NUM_PACKETS = 4 ; /* Create the RAM here */ reg [DATA_WIDTH-1:0] usb_ram [256*NUM_PACKETS-1:0] ; /* Create the address signals */ reg [7-2+NUM_PACKETS:0] usb_ram_ain ; reg [7:0] usb_ram_offset ; reg [1:0] usb_ram_packet ; wire [7-2+NUM_PACKETS:0] usb_ram_aout ; reg isfull; assign usb_ram_aout = {usb_ram_packet,usb_ram_offset} ; // Check if there is one full packet to process always @(usb_ram_ain, usb_ram_aout) begin if (reset) pkt_waiting <= 0; else if (usb_ram_ain == usb_ram_aout) pkt_waiting <= isfull; else if (usb_ram_ain > usb_ram_aout) pkt_waiting <= (usb_ram_ain - usb_ram_aout) >= 256; else pkt_waiting <= (usb_ram_ain + 10'b1111111111 - usb_ram_aout) >= 256; end // Check if there is room always @(usb_ram_ain, usb_ram_aout) begin if (reset) have_space <= 1; else if (usb_ram_ain == usb_ram_aout) have_space <= ~isfull; else if (usb_ram_ain > usb_ram_aout) have_space <= (usb_ram_ain - usb_ram_aout) <= 256 * (NUM_PACKETS - 1); else have_space <= (usb_ram_aout - usb_ram_ain) >= 256; end /* RAM Write Address process */ always @(posedge clock_in) begin if( reset ) usb_ram_ain <= 0 ; else if( write_enable ) begin usb_ram_ain <= usb_ram_ain + 1 ; if (usb_ram_ain + 1 == usb_ram_aout) isfull <= 1; end end /* RAM Writing process */ always @(posedge clock_in) begin if( write_enable ) begin usb_ram[usb_ram_ain] <= ram_data_in ; end end /* RAM Read Address process */ always @(posedge clock_out) begin if( reset ) begin usb_ram_packet <= 0 ; usb_ram_offset <= 0 ; isfull <= 0; end else if( skip_packet ) begin usb_ram_packet <= usb_ram_packet + 1 ; usb_ram_offset <= 0 ; end else if(read_enable) if( usb_ram_offset == 8'b11111111 ) begin usb_ram_offset <= 0 ; usb_ram_packet <= usb_ram_packet + 1 ; end else usb_ram_offset <= usb_ram_offset + 1 ; if (usb_ram_ain == usb_ram_aout) isfull <= 0; end /* RAM Reading Process */ always @(posedge clock_out) begin ram_data_out <= usb_ram[usb_ram_aout] ; end endmodule
module usb_packet_fifo ( input reset, input clock_in, input clock_out, input [15:0]ram_data_in, input write_enable, output reg [15:0]ram_data_out, output reg pkt_waiting, output reg have_space, input read_enable, input skip_packet ) ; /* Some parameters for usage later on */ parameter DATA_WIDTH = 16 ; parameter NUM_PACKETS = 4 ; /* Create the RAM here */ reg [DATA_WIDTH-1:0] usb_ram [256*NUM_PACKETS-1:0] ; /* Create the address signals */ reg [7-2+NUM_PACKETS:0] usb_ram_ain ; reg [7:0] usb_ram_offset ; reg [1:0] usb_ram_packet ; wire [7-2+NUM_PACKETS:0] usb_ram_aout ; reg isfull; assign usb_ram_aout = {usb_ram_packet,usb_ram_offset} ; // Check if there is one full packet to process always @(usb_ram_ain, usb_ram_aout) begin if (reset) pkt_waiting <= 0; else if (usb_ram_ain == usb_ram_aout) pkt_waiting <= isfull; else if (usb_ram_ain > usb_ram_aout) pkt_waiting <= (usb_ram_ain - usb_ram_aout) >= 256; else pkt_waiting <= (usb_ram_ain + 10'b1111111111 - usb_ram_aout) >= 256; end // Check if there is room always @(usb_ram_ain, usb_ram_aout) begin if (reset) have_space <= 1; else if (usb_ram_ain == usb_ram_aout) have_space <= ~isfull; else if (usb_ram_ain > usb_ram_aout) have_space <= (usb_ram_ain - usb_ram_aout) <= 256 * (NUM_PACKETS - 1); else have_space <= (usb_ram_aout - usb_ram_ain) >= 256; end /* RAM Write Address process */ always @(posedge clock_in) begin if( reset ) usb_ram_ain <= 0 ; else if( write_enable ) begin usb_ram_ain <= usb_ram_ain + 1 ; if (usb_ram_ain + 1 == usb_ram_aout) isfull <= 1; end end /* RAM Writing process */ always @(posedge clock_in) begin if( write_enable ) begin usb_ram[usb_ram_ain] <= ram_data_in ; end end /* RAM Read Address process */ always @(posedge clock_out) begin if( reset ) begin usb_ram_packet <= 0 ; usb_ram_offset <= 0 ; isfull <= 0; end else if( skip_packet ) begin usb_ram_packet <= usb_ram_packet + 1 ; usb_ram_offset <= 0 ; end else if(read_enable) if( usb_ram_offset == 8'b11111111 ) begin usb_ram_offset <= 0 ; usb_ram_packet <= usb_ram_packet + 1 ; end else usb_ram_offset <= usb_ram_offset + 1 ; if (usb_ram_ain == usb_ram_aout) isfull <= 0; end /* RAM Reading Process */ always @(posedge clock_out) begin ram_data_out <= usb_ram[usb_ram_aout] ; end endmodule
module write_signal_breakout ( write_command_data_in, // descriptor from the write FIFO write_command_data_out, // reformated descriptor to the write master // breakout of command information write_address, write_length, write_park, write_end_on_eop, write_transfer_complete_IRQ_mask, write_early_termination_IRQ_mask, write_error_IRQ_mask, write_burst_count, // when 'ENHANCED_FEATURES' is 0 this will be driven to ground write_stride, // when 'ENHANCED_FEATURES' is 0 this will be driven to ground write_sequence_number, // when 'ENHANCED_FEATURES' is 0 this will be driven to ground // additional control information that needs to go out asynchronously with the command data write_stop, write_sw_reset ); parameter DATA_WIDTH = 256; // 256 bits when enhanced settings are enabled otherwise 128 bits input [DATA_WIDTH-1:0] write_command_data_in; output wire [255:0] write_command_data_out; output wire [63:0] write_address; output wire [31:0] write_length; output wire write_park; output wire write_end_on_eop; output wire write_transfer_complete_IRQ_mask; output wire write_early_termination_IRQ_mask; output wire [7:0] write_error_IRQ_mask; output wire [7:0] write_burst_count; output wire [15:0] write_stride; output wire [15:0] write_sequence_number; input write_stop; input write_sw_reset; assign write_address[31:0] = write_command_data_in[63:32]; assign write_length = write_command_data_in[95:64]; generate if (DATA_WIDTH == 256) begin assign write_park = write_command_data_in[235]; assign write_end_on_eop = write_command_data_in[236]; assign write_transfer_complete_IRQ_mask = write_command_data_in[238]; assign write_early_termination_IRQ_mask = write_command_data_in[239]; assign write_error_IRQ_mask = write_command_data_in[247:240]; assign write_burst_count = write_command_data_in[127:120]; assign write_stride = write_command_data_in[159:144]; assign write_sequence_number = write_command_data_in[111:96]; assign write_address[63:32] = write_command_data_in[223:192]; end else begin assign write_park = write_command_data_in[107]; assign write_end_on_eop = write_command_data_in[108]; assign write_transfer_complete_IRQ_mask = write_command_data_in[110]; assign write_early_termination_IRQ_mask = write_command_data_in[111]; assign write_error_IRQ_mask = write_command_data_in[119:112]; assign write_burst_count = 8'h00; assign write_stride = 16'h0000; assign write_sequence_number = 16'h0000; assign write_address[63:32] = 32'h00000000; end endgenerate // big concat statement to glue all the signals back together to go out to the write master (MSBs to LSBs) assign write_command_data_out = {{132{1'b0}}, // zero pad the upper 132 bits write_address[63:32], write_stride, write_burst_count, write_sw_reset, write_stop, 1'b0, // used to be the early termination bit so now it's reserved write_end_on_eop, write_length, write_address[31:0]}; endmodule
module write_signal_breakout ( write_command_data_in, // descriptor from the write FIFO write_command_data_out, // reformated descriptor to the write master // breakout of command information write_address, write_length, write_park, write_end_on_eop, write_transfer_complete_IRQ_mask, write_early_termination_IRQ_mask, write_error_IRQ_mask, write_burst_count, // when 'ENHANCED_FEATURES' is 0 this will be driven to ground write_stride, // when 'ENHANCED_FEATURES' is 0 this will be driven to ground write_sequence_number, // when 'ENHANCED_FEATURES' is 0 this will be driven to ground // additional control information that needs to go out asynchronously with the command data write_stop, write_sw_reset ); parameter DATA_WIDTH = 256; // 256 bits when enhanced settings are enabled otherwise 128 bits input [DATA_WIDTH-1:0] write_command_data_in; output wire [255:0] write_command_data_out; output wire [63:0] write_address; output wire [31:0] write_length; output wire write_park; output wire write_end_on_eop; output wire write_transfer_complete_IRQ_mask; output wire write_early_termination_IRQ_mask; output wire [7:0] write_error_IRQ_mask; output wire [7:0] write_burst_count; output wire [15:0] write_stride; output wire [15:0] write_sequence_number; input write_stop; input write_sw_reset; assign write_address[31:0] = write_command_data_in[63:32]; assign write_length = write_command_data_in[95:64]; generate if (DATA_WIDTH == 256) begin assign write_park = write_command_data_in[235]; assign write_end_on_eop = write_command_data_in[236]; assign write_transfer_complete_IRQ_mask = write_command_data_in[238]; assign write_early_termination_IRQ_mask = write_command_data_in[239]; assign write_error_IRQ_mask = write_command_data_in[247:240]; assign write_burst_count = write_command_data_in[127:120]; assign write_stride = write_command_data_in[159:144]; assign write_sequence_number = write_command_data_in[111:96]; assign write_address[63:32] = write_command_data_in[223:192]; end else begin assign write_park = write_command_data_in[107]; assign write_end_on_eop = write_command_data_in[108]; assign write_transfer_complete_IRQ_mask = write_command_data_in[110]; assign write_early_termination_IRQ_mask = write_command_data_in[111]; assign write_error_IRQ_mask = write_command_data_in[119:112]; assign write_burst_count = 8'h00; assign write_stride = 16'h0000; assign write_sequence_number = 16'h0000; assign write_address[63:32] = 32'h00000000; end endgenerate // big concat statement to glue all the signals back together to go out to the write master (MSBs to LSBs) assign write_command_data_out = {{132{1'b0}}, // zero pad the upper 132 bits write_address[63:32], write_stride, write_burst_count, write_sw_reset, write_stop, 1'b0, // used to be the early termination bit so now it's reserved write_end_on_eop, write_length, write_address[31:0]}; endmodule
module unpipeline # ( parameter WIDTH_D = 256, parameter S_WIDTH_A = 26, parameter M_WIDTH_A = S_WIDTH_A+$clog2(WIDTH_D/8), parameter BURSTCOUNT_WIDTH = 1, parameter BYTEENABLE_WIDTH = WIDTH_D, parameter MAX_PENDING_READS = 64 ) ( input clk, input resetn, // Slave port input [S_WIDTH_A-1:0] slave_address, // Word address input [WIDTH_D-1:0] slave_writedata, input slave_read, input slave_write, input [BURSTCOUNT_WIDTH-1:0] slave_burstcount, input [BYTEENABLE_WIDTH-1:0] slave_byteenable, output slave_waitrequest, output [WIDTH_D-1:0] slave_readdata, output slave_readdatavalid, output [M_WIDTH_A-1:0] master_address, // Byte address output [WIDTH_D-1:0] master_writedata, output master_read, output master_write, output [BYTEENABLE_WIDTH-1:0] master_byteenable, input master_waitrequest, input [WIDTH_D-1:0] master_readdata ); assign master_read = slave_read; assign master_write = slave_write; assign master_writedata = slave_writedata; assign master_address = {slave_address,{$clog2(WIDTH_D/8){1'b0}}}; //byteaddr assign master_byteenable = slave_byteenable; assign slave_waitrequest = master_waitrequest; assign slave_readdatavalid = slave_read & ~master_waitrequest; assign slave_readdata = master_readdata; endmodule
module unpipeline # ( parameter WIDTH_D = 256, parameter S_WIDTH_A = 26, parameter M_WIDTH_A = S_WIDTH_A+$clog2(WIDTH_D/8), parameter BURSTCOUNT_WIDTH = 1, parameter BYTEENABLE_WIDTH = WIDTH_D, parameter MAX_PENDING_READS = 64 ) ( input clk, input resetn, // Slave port input [S_WIDTH_A-1:0] slave_address, // Word address input [WIDTH_D-1:0] slave_writedata, input slave_read, input slave_write, input [BURSTCOUNT_WIDTH-1:0] slave_burstcount, input [BYTEENABLE_WIDTH-1:0] slave_byteenable, output slave_waitrequest, output [WIDTH_D-1:0] slave_readdata, output slave_readdatavalid, output [M_WIDTH_A-1:0] master_address, // Byte address output [WIDTH_D-1:0] master_writedata, output master_read, output master_write, output [BYTEENABLE_WIDTH-1:0] master_byteenable, input master_waitrequest, input [WIDTH_D-1:0] master_readdata ); assign master_read = slave_read; assign master_write = slave_write; assign master_writedata = slave_writedata; assign master_address = {slave_address,{$clog2(WIDTH_D/8){1'b0}}}; //byteaddr assign master_byteenable = slave_byteenable; assign slave_waitrequest = master_waitrequest; assign slave_readdatavalid = slave_read & ~master_waitrequest; assign slave_readdata = master_readdata; endmodule
module csr_block ( clk, reset, csr_writedata, csr_write, csr_byteenable, csr_readdata, csr_read, csr_address, csr_irq, done_strobe, busy, descriptor_buffer_empty, descriptor_buffer_full, stop_state, stopped_on_error, stopped_on_early_termination, reset_stalled, stop, sw_reset, stop_on_error, stop_on_early_termination, stop_descriptors, sequence_number, descriptor_watermark, response_watermark, response_buffer_empty, response_buffer_full, transfer_complete_IRQ_mask, error_IRQ_mask, early_termination_IRQ_mask, error, early_termination ); parameter ADDRESS_WIDTH = 3; localparam CONTROL_REGISTER_ADDRESS = 3'b001; input clk; input reset; input [31:0] csr_writedata; input csr_write; input [3:0] csr_byteenable; output wire [31:0] csr_readdata; input csr_read; input [ADDRESS_WIDTH-1:0] csr_address; output wire csr_irq; input done_strobe; input busy; input descriptor_buffer_empty; input descriptor_buffer_full; input stop_state; // when the DMA runs into some error condition and you have enabled the stop on error (or when the stop control bit is written to) input reset_stalled; // the read or write master could be in the middle of a transfer/burst so it might take a while to flush the buffers output wire stop; output reg stopped_on_error; output reg stopped_on_early_termination; output reg sw_reset; output wire stop_on_error; output wire stop_on_early_termination; output wire stop_descriptors; input [31:0] sequence_number; input [31:0] descriptor_watermark; input [15:0] response_watermark; input response_buffer_empty; input response_buffer_full; input transfer_complete_IRQ_mask; input [7:0] error_IRQ_mask; input early_termination_IRQ_mask; input [7:0] error; input early_termination; /* Internal wires and registers */ wire [31:0] status; reg [31:0] control; reg [31:0] readdata; reg [31:0] readdata_d1; reg irq; // writing to the status register clears the irq bit wire set_irq; wire clear_irq; reg [15:0] irq_count; // writing to bit 0 clears the counter wire clear_irq_count; wire incr_irq_count; wire set_stopped_on_error; wire set_stopped_on_early_termination; wire set_stop; wire clear_stop; wire global_interrupt_enable; wire sw_reset_strobe; // this strobe will be one cycle earlier than sw_reset wire set_sw_reset; wire clear_sw_reset; /********************************************** Registers ***************************************************/ // read latency is 1 cycle always @ (posedge clk or posedge reset) begin if (reset) begin readdata_d1 <= 0; end else if (csr_read == 1) begin readdata_d1 <= readdata; end end always @ (posedge clk or posedge reset) begin if (reset) begin control[31:1] <= 0; end else begin if (sw_reset_strobe == 1) // reset strobe is a strobe due to this sync reset begin control[31:1] <= 0; end else begin if ((csr_address == CONTROL_REGISTER_ADDRESS) & (csr_write == 1) & (csr_byteenable[0] == 1)) begin control[7:1] <= csr_writedata[7:1]; // stop bit will be handled seperately since it can be set by the csr slave port access or the SGDMA hitting an error condition end if ((csr_address == CONTROL_REGISTER_ADDRESS) & (csr_write == 1) & (csr_byteenable[1] == 1)) begin control[15:8] <= csr_writedata[15:8]; end if ((csr_address == CONTROL_REGISTER_ADDRESS) & (csr_write == 1) & (csr_byteenable[2] == 1)) begin control[23:16] <= csr_writedata[23:16]; end if ((csr_address == CONTROL_REGISTER_ADDRESS) & (csr_write == 1) & (csr_byteenable[3] == 1)) begin control[31:24] <= csr_writedata[31:24]; end end end end // control bit 0 (stop) is set by different sources so handling it seperately always @ (posedge clk or posedge reset) begin if (reset) begin control[0] <= 0; end else begin if (sw_reset_strobe == 1) begin control[0] <= 0; end else begin case ({set_stop, clear_stop}) 2'b00: control[0] <= control[0]; 2'b01: control[0] <= 1'b0; 2'b10: control[0] <= 1'b1; 2'b11: control[0] <= 1'b1; // setting will win, this case happens control[0] is being set to 0 (resume) at the same time an error/early termination stop condition occurs endcase end end end always @ (posedge clk or posedge reset) begin if (reset) begin sw_reset <= 0; end else begin if (set_sw_reset == 1) begin sw_reset <= 1; end else if (clear_sw_reset == 1) begin sw_reset <= 0; end end end always @ (posedge clk or posedge reset) begin if (reset) begin stopped_on_error <= 0; end else begin case ({set_stopped_on_error, clear_stop}) 2'b00: stopped_on_error <= stopped_on_error; 2'b01: stopped_on_error <= 1'b0; 2'b10: stopped_on_error <= 1'b1; 2'b11: stopped_on_error <= 1'b0; endcase end end always @ (posedge clk or posedge reset) begin if (reset) begin stopped_on_early_termination <= 0; end else begin case ({set_stopped_on_early_termination, clear_stop}) 2'b00: stopped_on_early_termination <= stopped_on_early_termination; 2'b01: stopped_on_early_termination <= 1'b0; 2'b10: stopped_on_early_termination <= 1'b1; 2'b11: stopped_on_early_termination <= 1'b0; endcase end end always @ (posedge clk or posedge reset) begin if (reset) begin irq <= 0; end else begin if (sw_reset_strobe == 1) begin irq <= 0; end else begin case ({clear_irq, set_irq}) 2'b00: irq <= irq; 2'b01: irq <= 1'b1; 2'b10: irq <= 1'b0; 2'b11: irq <= 1'b1; // setting will win over a clear endcase end end end always @ (posedge clk or posedge reset) begin if (reset) begin irq_count <= {16{1'b0}}; end else begin if (sw_reset_strobe == 1) begin irq_count <= {16{1'b0}}; end else begin case ({clear_irq_count, incr_irq_count}) 2'b00: irq_count <= irq_count; 2'b01: irq_count <= irq_count + 1; 2'b10: irq_count <= {16{1'b0}}; 2'b11: irq_count <= {{15{1'b0}}, 1'b1}; endcase end end end /******************************************** End Registers *************************************************/ /**************************************** Combinational Signals *********************************************/ generate if (ADDRESS_WIDTH == 3) begin always @ (csr_address or status or control or descriptor_watermark or response_watermark or sequence_number) begin case (csr_address) 3'b000: readdata = status; 3'b001: readdata = control; 3'b010: readdata = descriptor_watermark; 3'b011: readdata = response_watermark; default: readdata = sequence_number; // all other addresses will decode to the sequence number endcase end end else begin always @ (csr_address or status or control or descriptor_watermark or response_watermark) begin case (csr_address) 3'b000: readdata = status; 3'b001: readdata = control; 3'b010: readdata = descriptor_watermark; default: readdata = response_watermark; // all other addresses will decode to the response watermark endcase end end endgenerate assign clear_irq = (csr_address == 0) & (csr_write == 1) & (csr_byteenable[1] == 1) & (csr_writedata[9] == 1); // this is the IRQ bit assign set_irq = (global_interrupt_enable == 1) & (done_strobe == 1) & // transfer ended and interrupts are enabled ((transfer_complete_IRQ_mask == 1) | // transfer ended and the transfer complete IRQ is enabled ((error & error_IRQ_mask) != 0) | // transfer ended with an error and this IRQ is enabled ((early_termination & early_termination_IRQ_mask) == 1)); // transfer ended early due to early termination and this IRQ is enabled assign csr_irq = irq; // Done count assign incr_irq_count = set_irq; // Done count just counts the number of interrupts since the last reset assign clear_irq_count = (csr_address == 0) & (csr_write == 1) & (csr_byteenable[2] == 1) & (csr_writedata[16] == 1); // the LSB irq_count bit assign clear_stop = (csr_address == CONTROL_REGISTER_ADDRESS) & (csr_write == 1) & (csr_byteenable[0] == 1) & (csr_writedata[0] == 0); assign set_stopped_on_error = (done_strobe == 1) & (stop_on_error == 1) & (error != 0); // when clear_stop is set then the stopped_on_error register will be cleared assign set_stopped_on_early_termination = (done_strobe == 1) & (stop_on_early_termination == 1) & (early_termination == 1); // when clear_stop is set then the stopped_on_early_termination register will be cleared assign set_stop = ((csr_address == CONTROL_REGISTER_ADDRESS) & (csr_write == 1) & (csr_byteenable[0] == 1) & (csr_writedata[0] == 1)) | // host set the stop bit (set_stopped_on_error == 1) | // SGDMA setup to stop when an error occurs from the write master (set_stopped_on_early_termination == 1) ; // SGDMA setup to stop when the write master overflows assign stop = control[0]; assign set_sw_reset = (csr_address == CONTROL_REGISTER_ADDRESS) & (csr_write == 1) & (csr_byteenable[0] == 1) & (csr_writedata[1] == 1); assign clear_sw_reset = (sw_reset == 1) & (reset_stalled == 0); assign sw_reset_strobe = control[1]; assign stop_on_error = control[2]; assign stop_on_early_termination = control[3]; assign global_interrupt_enable = control[4]; assign stop_descriptors = control[5]; assign csr_readdata = readdata_d1; assign status = {irq_count, {6{1'b0}}, irq, stopped_on_early_termination, stopped_on_error, sw_reset, stop_state, response_buffer_full, response_buffer_empty, descriptor_buffer_full, descriptor_buffer_empty, busy}; // writing to the lower byte of the status register clears the irq bit /**************************************** Combinational Signals *********************************************/ endmodule
module csr_block ( clk, reset, csr_writedata, csr_write, csr_byteenable, csr_readdata, csr_read, csr_address, csr_irq, done_strobe, busy, descriptor_buffer_empty, descriptor_buffer_full, stop_state, stopped_on_error, stopped_on_early_termination, reset_stalled, stop, sw_reset, stop_on_error, stop_on_early_termination, stop_descriptors, sequence_number, descriptor_watermark, response_watermark, response_buffer_empty, response_buffer_full, transfer_complete_IRQ_mask, error_IRQ_mask, early_termination_IRQ_mask, error, early_termination ); parameter ADDRESS_WIDTH = 3; localparam CONTROL_REGISTER_ADDRESS = 3'b001; input clk; input reset; input [31:0] csr_writedata; input csr_write; input [3:0] csr_byteenable; output wire [31:0] csr_readdata; input csr_read; input [ADDRESS_WIDTH-1:0] csr_address; output wire csr_irq; input done_strobe; input busy; input descriptor_buffer_empty; input descriptor_buffer_full; input stop_state; // when the DMA runs into some error condition and you have enabled the stop on error (or when the stop control bit is written to) input reset_stalled; // the read or write master could be in the middle of a transfer/burst so it might take a while to flush the buffers output wire stop; output reg stopped_on_error; output reg stopped_on_early_termination; output reg sw_reset; output wire stop_on_error; output wire stop_on_early_termination; output wire stop_descriptors; input [31:0] sequence_number; input [31:0] descriptor_watermark; input [15:0] response_watermark; input response_buffer_empty; input response_buffer_full; input transfer_complete_IRQ_mask; input [7:0] error_IRQ_mask; input early_termination_IRQ_mask; input [7:0] error; input early_termination; /* Internal wires and registers */ wire [31:0] status; reg [31:0] control; reg [31:0] readdata; reg [31:0] readdata_d1; reg irq; // writing to the status register clears the irq bit wire set_irq; wire clear_irq; reg [15:0] irq_count; // writing to bit 0 clears the counter wire clear_irq_count; wire incr_irq_count; wire set_stopped_on_error; wire set_stopped_on_early_termination; wire set_stop; wire clear_stop; wire global_interrupt_enable; wire sw_reset_strobe; // this strobe will be one cycle earlier than sw_reset wire set_sw_reset; wire clear_sw_reset; /********************************************** Registers ***************************************************/ // read latency is 1 cycle always @ (posedge clk or posedge reset) begin if (reset) begin readdata_d1 <= 0; end else if (csr_read == 1) begin readdata_d1 <= readdata; end end always @ (posedge clk or posedge reset) begin if (reset) begin control[31:1] <= 0; end else begin if (sw_reset_strobe == 1) // reset strobe is a strobe due to this sync reset begin control[31:1] <= 0; end else begin if ((csr_address == CONTROL_REGISTER_ADDRESS) & (csr_write == 1) & (csr_byteenable[0] == 1)) begin control[7:1] <= csr_writedata[7:1]; // stop bit will be handled seperately since it can be set by the csr slave port access or the SGDMA hitting an error condition end if ((csr_address == CONTROL_REGISTER_ADDRESS) & (csr_write == 1) & (csr_byteenable[1] == 1)) begin control[15:8] <= csr_writedata[15:8]; end if ((csr_address == CONTROL_REGISTER_ADDRESS) & (csr_write == 1) & (csr_byteenable[2] == 1)) begin control[23:16] <= csr_writedata[23:16]; end if ((csr_address == CONTROL_REGISTER_ADDRESS) & (csr_write == 1) & (csr_byteenable[3] == 1)) begin control[31:24] <= csr_writedata[31:24]; end end end end // control bit 0 (stop) is set by different sources so handling it seperately always @ (posedge clk or posedge reset) begin if (reset) begin control[0] <= 0; end else begin if (sw_reset_strobe == 1) begin control[0] <= 0; end else begin case ({set_stop, clear_stop}) 2'b00: control[0] <= control[0]; 2'b01: control[0] <= 1'b0; 2'b10: control[0] <= 1'b1; 2'b11: control[0] <= 1'b1; // setting will win, this case happens control[0] is being set to 0 (resume) at the same time an error/early termination stop condition occurs endcase end end end always @ (posedge clk or posedge reset) begin if (reset) begin sw_reset <= 0; end else begin if (set_sw_reset == 1) begin sw_reset <= 1; end else if (clear_sw_reset == 1) begin sw_reset <= 0; end end end always @ (posedge clk or posedge reset) begin if (reset) begin stopped_on_error <= 0; end else begin case ({set_stopped_on_error, clear_stop}) 2'b00: stopped_on_error <= stopped_on_error; 2'b01: stopped_on_error <= 1'b0; 2'b10: stopped_on_error <= 1'b1; 2'b11: stopped_on_error <= 1'b0; endcase end end always @ (posedge clk or posedge reset) begin if (reset) begin stopped_on_early_termination <= 0; end else begin case ({set_stopped_on_early_termination, clear_stop}) 2'b00: stopped_on_early_termination <= stopped_on_early_termination; 2'b01: stopped_on_early_termination <= 1'b0; 2'b10: stopped_on_early_termination <= 1'b1; 2'b11: stopped_on_early_termination <= 1'b0; endcase end end always @ (posedge clk or posedge reset) begin if (reset) begin irq <= 0; end else begin if (sw_reset_strobe == 1) begin irq <= 0; end else begin case ({clear_irq, set_irq}) 2'b00: irq <= irq; 2'b01: irq <= 1'b1; 2'b10: irq <= 1'b0; 2'b11: irq <= 1'b1; // setting will win over a clear endcase end end end always @ (posedge clk or posedge reset) begin if (reset) begin irq_count <= {16{1'b0}}; end else begin if (sw_reset_strobe == 1) begin irq_count <= {16{1'b0}}; end else begin case ({clear_irq_count, incr_irq_count}) 2'b00: irq_count <= irq_count; 2'b01: irq_count <= irq_count + 1; 2'b10: irq_count <= {16{1'b0}}; 2'b11: irq_count <= {{15{1'b0}}, 1'b1}; endcase end end end /******************************************** End Registers *************************************************/ /**************************************** Combinational Signals *********************************************/ generate if (ADDRESS_WIDTH == 3) begin always @ (csr_address or status or control or descriptor_watermark or response_watermark or sequence_number) begin case (csr_address) 3'b000: readdata = status; 3'b001: readdata = control; 3'b010: readdata = descriptor_watermark; 3'b011: readdata = response_watermark; default: readdata = sequence_number; // all other addresses will decode to the sequence number endcase end end else begin always @ (csr_address or status or control or descriptor_watermark or response_watermark) begin case (csr_address) 3'b000: readdata = status; 3'b001: readdata = control; 3'b010: readdata = descriptor_watermark; default: readdata = response_watermark; // all other addresses will decode to the response watermark endcase end end endgenerate assign clear_irq = (csr_address == 0) & (csr_write == 1) & (csr_byteenable[1] == 1) & (csr_writedata[9] == 1); // this is the IRQ bit assign set_irq = (global_interrupt_enable == 1) & (done_strobe == 1) & // transfer ended and interrupts are enabled ((transfer_complete_IRQ_mask == 1) | // transfer ended and the transfer complete IRQ is enabled ((error & error_IRQ_mask) != 0) | // transfer ended with an error and this IRQ is enabled ((early_termination & early_termination_IRQ_mask) == 1)); // transfer ended early due to early termination and this IRQ is enabled assign csr_irq = irq; // Done count assign incr_irq_count = set_irq; // Done count just counts the number of interrupts since the last reset assign clear_irq_count = (csr_address == 0) & (csr_write == 1) & (csr_byteenable[2] == 1) & (csr_writedata[16] == 1); // the LSB irq_count bit assign clear_stop = (csr_address == CONTROL_REGISTER_ADDRESS) & (csr_write == 1) & (csr_byteenable[0] == 1) & (csr_writedata[0] == 0); assign set_stopped_on_error = (done_strobe == 1) & (stop_on_error == 1) & (error != 0); // when clear_stop is set then the stopped_on_error register will be cleared assign set_stopped_on_early_termination = (done_strobe == 1) & (stop_on_early_termination == 1) & (early_termination == 1); // when clear_stop is set then the stopped_on_early_termination register will be cleared assign set_stop = ((csr_address == CONTROL_REGISTER_ADDRESS) & (csr_write == 1) & (csr_byteenable[0] == 1) & (csr_writedata[0] == 1)) | // host set the stop bit (set_stopped_on_error == 1) | // SGDMA setup to stop when an error occurs from the write master (set_stopped_on_early_termination == 1) ; // SGDMA setup to stop when the write master overflows assign stop = control[0]; assign set_sw_reset = (csr_address == CONTROL_REGISTER_ADDRESS) & (csr_write == 1) & (csr_byteenable[0] == 1) & (csr_writedata[1] == 1); assign clear_sw_reset = (sw_reset == 1) & (reset_stalled == 0); assign sw_reset_strobe = control[1]; assign stop_on_error = control[2]; assign stop_on_early_termination = control[3]; assign global_interrupt_enable = control[4]; assign stop_descriptors = control[5]; assign csr_readdata = readdata_d1; assign status = {irq_count, {6{1'b0}}, irq, stopped_on_early_termination, stopped_on_error, sw_reset, stop_state, response_buffer_full, response_buffer_empty, descriptor_buffer_full, descriptor_buffer_empty, busy}; // writing to the lower byte of the status register clears the irq bit /**************************************** Combinational Signals *********************************************/ endmodule
module csr_block ( clk, reset, csr_writedata, csr_write, csr_byteenable, csr_readdata, csr_read, csr_address, csr_irq, done_strobe, busy, descriptor_buffer_empty, descriptor_buffer_full, stop_state, stopped_on_error, stopped_on_early_termination, reset_stalled, stop, sw_reset, stop_on_error, stop_on_early_termination, stop_descriptors, sequence_number, descriptor_watermark, response_watermark, response_buffer_empty, response_buffer_full, transfer_complete_IRQ_mask, error_IRQ_mask, early_termination_IRQ_mask, error, early_termination ); parameter ADDRESS_WIDTH = 3; localparam CONTROL_REGISTER_ADDRESS = 3'b001; input clk; input reset; input [31:0] csr_writedata; input csr_write; input [3:0] csr_byteenable; output wire [31:0] csr_readdata; input csr_read; input [ADDRESS_WIDTH-1:0] csr_address; output wire csr_irq; input done_strobe; input busy; input descriptor_buffer_empty; input descriptor_buffer_full; input stop_state; // when the DMA runs into some error condition and you have enabled the stop on error (or when the stop control bit is written to) input reset_stalled; // the read or write master could be in the middle of a transfer/burst so it might take a while to flush the buffers output wire stop; output reg stopped_on_error; output reg stopped_on_early_termination; output reg sw_reset; output wire stop_on_error; output wire stop_on_early_termination; output wire stop_descriptors; input [31:0] sequence_number; input [31:0] descriptor_watermark; input [15:0] response_watermark; input response_buffer_empty; input response_buffer_full; input transfer_complete_IRQ_mask; input [7:0] error_IRQ_mask; input early_termination_IRQ_mask; input [7:0] error; input early_termination; /* Internal wires and registers */ wire [31:0] status; reg [31:0] control; reg [31:0] readdata; reg [31:0] readdata_d1; reg irq; // writing to the status register clears the irq bit wire set_irq; wire clear_irq; reg [15:0] irq_count; // writing to bit 0 clears the counter wire clear_irq_count; wire incr_irq_count; wire set_stopped_on_error; wire set_stopped_on_early_termination; wire set_stop; wire clear_stop; wire global_interrupt_enable; wire sw_reset_strobe; // this strobe will be one cycle earlier than sw_reset wire set_sw_reset; wire clear_sw_reset; /********************************************** Registers ***************************************************/ // read latency is 1 cycle always @ (posedge clk or posedge reset) begin if (reset) begin readdata_d1 <= 0; end else if (csr_read == 1) begin readdata_d1 <= readdata; end end always @ (posedge clk or posedge reset) begin if (reset) begin control[31:1] <= 0; end else begin if (sw_reset_strobe == 1) // reset strobe is a strobe due to this sync reset begin control[31:1] <= 0; end else begin if ((csr_address == CONTROL_REGISTER_ADDRESS) & (csr_write == 1) & (csr_byteenable[0] == 1)) begin control[7:1] <= csr_writedata[7:1]; // stop bit will be handled seperately since it can be set by the csr slave port access or the SGDMA hitting an error condition end if ((csr_address == CONTROL_REGISTER_ADDRESS) & (csr_write == 1) & (csr_byteenable[1] == 1)) begin control[15:8] <= csr_writedata[15:8]; end if ((csr_address == CONTROL_REGISTER_ADDRESS) & (csr_write == 1) & (csr_byteenable[2] == 1)) begin control[23:16] <= csr_writedata[23:16]; end if ((csr_address == CONTROL_REGISTER_ADDRESS) & (csr_write == 1) & (csr_byteenable[3] == 1)) begin control[31:24] <= csr_writedata[31:24]; end end end end // control bit 0 (stop) is set by different sources so handling it seperately always @ (posedge clk or posedge reset) begin if (reset) begin control[0] <= 0; end else begin if (sw_reset_strobe == 1) begin control[0] <= 0; end else begin case ({set_stop, clear_stop}) 2'b00: control[0] <= control[0]; 2'b01: control[0] <= 1'b0; 2'b10: control[0] <= 1'b1; 2'b11: control[0] <= 1'b1; // setting will win, this case happens control[0] is being set to 0 (resume) at the same time an error/early termination stop condition occurs endcase end end end always @ (posedge clk or posedge reset) begin if (reset) begin sw_reset <= 0; end else begin if (set_sw_reset == 1) begin sw_reset <= 1; end else if (clear_sw_reset == 1) begin sw_reset <= 0; end end end always @ (posedge clk or posedge reset) begin if (reset) begin stopped_on_error <= 0; end else begin case ({set_stopped_on_error, clear_stop}) 2'b00: stopped_on_error <= stopped_on_error; 2'b01: stopped_on_error <= 1'b0; 2'b10: stopped_on_error <= 1'b1; 2'b11: stopped_on_error <= 1'b0; endcase end end always @ (posedge clk or posedge reset) begin if (reset) begin stopped_on_early_termination <= 0; end else begin case ({set_stopped_on_early_termination, clear_stop}) 2'b00: stopped_on_early_termination <= stopped_on_early_termination; 2'b01: stopped_on_early_termination <= 1'b0; 2'b10: stopped_on_early_termination <= 1'b1; 2'b11: stopped_on_early_termination <= 1'b0; endcase end end always @ (posedge clk or posedge reset) begin if (reset) begin irq <= 0; end else begin if (sw_reset_strobe == 1) begin irq <= 0; end else begin case ({clear_irq, set_irq}) 2'b00: irq <= irq; 2'b01: irq <= 1'b1; 2'b10: irq <= 1'b0; 2'b11: irq <= 1'b1; // setting will win over a clear endcase end end end always @ (posedge clk or posedge reset) begin if (reset) begin irq_count <= {16{1'b0}}; end else begin if (sw_reset_strobe == 1) begin irq_count <= {16{1'b0}}; end else begin case ({clear_irq_count, incr_irq_count}) 2'b00: irq_count <= irq_count; 2'b01: irq_count <= irq_count + 1; 2'b10: irq_count <= {16{1'b0}}; 2'b11: irq_count <= {{15{1'b0}}, 1'b1}; endcase end end end /******************************************** End Registers *************************************************/ /**************************************** Combinational Signals *********************************************/ generate if (ADDRESS_WIDTH == 3) begin always @ (csr_address or status or control or descriptor_watermark or response_watermark or sequence_number) begin case (csr_address) 3'b000: readdata = status; 3'b001: readdata = control; 3'b010: readdata = descriptor_watermark; 3'b011: readdata = response_watermark; default: readdata = sequence_number; // all other addresses will decode to the sequence number endcase end end else begin always @ (csr_address or status or control or descriptor_watermark or response_watermark) begin case (csr_address) 3'b000: readdata = status; 3'b001: readdata = control; 3'b010: readdata = descriptor_watermark; default: readdata = response_watermark; // all other addresses will decode to the response watermark endcase end end endgenerate assign clear_irq = (csr_address == 0) & (csr_write == 1) & (csr_byteenable[1] == 1) & (csr_writedata[9] == 1); // this is the IRQ bit assign set_irq = (global_interrupt_enable == 1) & (done_strobe == 1) & // transfer ended and interrupts are enabled ((transfer_complete_IRQ_mask == 1) | // transfer ended and the transfer complete IRQ is enabled ((error & error_IRQ_mask) != 0) | // transfer ended with an error and this IRQ is enabled ((early_termination & early_termination_IRQ_mask) == 1)); // transfer ended early due to early termination and this IRQ is enabled assign csr_irq = irq; // Done count assign incr_irq_count = set_irq; // Done count just counts the number of interrupts since the last reset assign clear_irq_count = (csr_address == 0) & (csr_write == 1) & (csr_byteenable[2] == 1) & (csr_writedata[16] == 1); // the LSB irq_count bit assign clear_stop = (csr_address == CONTROL_REGISTER_ADDRESS) & (csr_write == 1) & (csr_byteenable[0] == 1) & (csr_writedata[0] == 0); assign set_stopped_on_error = (done_strobe == 1) & (stop_on_error == 1) & (error != 0); // when clear_stop is set then the stopped_on_error register will be cleared assign set_stopped_on_early_termination = (done_strobe == 1) & (stop_on_early_termination == 1) & (early_termination == 1); // when clear_stop is set then the stopped_on_early_termination register will be cleared assign set_stop = ((csr_address == CONTROL_REGISTER_ADDRESS) & (csr_write == 1) & (csr_byteenable[0] == 1) & (csr_writedata[0] == 1)) | // host set the stop bit (set_stopped_on_error == 1) | // SGDMA setup to stop when an error occurs from the write master (set_stopped_on_early_termination == 1) ; // SGDMA setup to stop when the write master overflows assign stop = control[0]; assign set_sw_reset = (csr_address == CONTROL_REGISTER_ADDRESS) & (csr_write == 1) & (csr_byteenable[0] == 1) & (csr_writedata[1] == 1); assign clear_sw_reset = (sw_reset == 1) & (reset_stalled == 0); assign sw_reset_strobe = control[1]; assign stop_on_error = control[2]; assign stop_on_early_termination = control[3]; assign global_interrupt_enable = control[4]; assign stop_descriptors = control[5]; assign csr_readdata = readdata_d1; assign status = {irq_count, {6{1'b0}}, irq, stopped_on_early_termination, stopped_on_error, sw_reset, stop_state, response_buffer_full, response_buffer_empty, descriptor_buffer_full, descriptor_buffer_empty, busy}; // writing to the lower byte of the status register clears the irq bit /**************************************** Combinational Signals *********************************************/ endmodule
module generic_baseblocks_v2_1_0_carry_or # ( parameter C_FAMILY = "virtex6" // FPGA Family. Current version: virtex6 or spartan6. ) ( input wire CIN, input wire S, output wire COUT ); ///////////////////////////////////////////////////////////////////////////// // Variables for generating parameter controlled instances. ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Local params ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Functions ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Internal signals ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Instantiate or use RTL code ///////////////////////////////////////////////////////////////////////////// generate if ( C_FAMILY == "rtl" ) begin : USE_RTL assign COUT = CIN | S; end else begin : USE_FPGA wire S_n; assign S_n = ~S; MUXCY and_inst ( .O (COUT), .CI (CIN), .DI (1'b1), .S (S_n) ); end endgenerate endmodule
module generic_baseblocks_v2_1_0_carry # ( parameter C_FAMILY = "virtex6" // FPGA Family. Current version: virtex6 or spartan6. ) ( input wire CIN, input wire S, input wire DI, output wire COUT ); ///////////////////////////////////////////////////////////////////////////// // Variables for generating parameter controlled instances. ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Local params ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Functions ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Internal signals ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Instantiate or use RTL code ///////////////////////////////////////////////////////////////////////////// generate if ( C_FAMILY == "rtl" ) begin : USE_RTL assign COUT = (CIN & S) | (DI & ~S); end else begin : USE_FPGA MUXCY and_inst ( .O (COUT), .CI (CIN), .DI (DI), .S (S) ); end endgenerate endmodule
module generic_baseblocks_v2_1_0_carry # ( parameter C_FAMILY = "virtex6" // FPGA Family. Current version: virtex6 or spartan6. ) ( input wire CIN, input wire S, input wire DI, output wire COUT ); ///////////////////////////////////////////////////////////////////////////// // Variables for generating parameter controlled instances. ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Local params ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Functions ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Internal signals ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Instantiate or use RTL code ///////////////////////////////////////////////////////////////////////////// generate if ( C_FAMILY == "rtl" ) begin : USE_RTL assign COUT = (CIN & S) | (DI & ~S); end else begin : USE_FPGA MUXCY and_inst ( .O (COUT), .CI (CIN), .DI (DI), .S (S) ); end endgenerate endmodule
module generic_baseblocks_v2_1_0_carry # ( parameter C_FAMILY = "virtex6" // FPGA Family. Current version: virtex6 or spartan6. ) ( input wire CIN, input wire S, input wire DI, output wire COUT ); ///////////////////////////////////////////////////////////////////////////// // Variables for generating parameter controlled instances. ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Local params ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Functions ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Internal signals ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Instantiate or use RTL code ///////////////////////////////////////////////////////////////////////////// generate if ( C_FAMILY == "rtl" ) begin : USE_RTL assign COUT = (CIN & S) | (DI & ~S); end else begin : USE_FPGA MUXCY and_inst ( .O (COUT), .CI (CIN), .DI (DI), .S (S) ); end endgenerate endmodule
module generic_baseblocks_v2_1_0_carry_latch_or # ( parameter C_FAMILY = "virtex6" // FPGA Family. Current version: virtex6 or spartan6. ) ( input wire CIN, input wire I, output wire O ); ///////////////////////////////////////////////////////////////////////////// // Variables for generating parameter controlled instances. ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Local params ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Functions ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Internal signals ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Instantiate or use RTL code ///////////////////////////////////////////////////////////////////////////// generate if ( C_FAMILY == "rtl" ) begin : USE_RTL assign O = CIN | I; end else begin : USE_FPGA OR2L or2l_inst1 ( .O(O), .DI(CIN), .SRI(I) ); end endgenerate endmodule
module generic_baseblocks_v2_1_0_carry_latch_or # ( parameter C_FAMILY = "virtex6" // FPGA Family. Current version: virtex6 or spartan6. ) ( input wire CIN, input wire I, output wire O ); ///////////////////////////////////////////////////////////////////////////// // Variables for generating parameter controlled instances. ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Local params ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Functions ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Internal signals ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Instantiate or use RTL code ///////////////////////////////////////////////////////////////////////////// generate if ( C_FAMILY == "rtl" ) begin : USE_RTL assign O = CIN | I; end else begin : USE_FPGA OR2L or2l_inst1 ( .O(O), .DI(CIN), .SRI(I) ); end endgenerate endmodule
module fifo_4k_18 ( aclr, data, rdclk, rdreq, wrclk, wrreq, q, rdempty, rdusedw, wrfull, wrusedw); input aclr; input [17:0] data; input rdclk; input rdreq; input wrclk; input wrreq; output [17:0] q; output rdempty; output [11:0] rdusedw; output wrfull; output [11:0] wrusedw; wire sub_wire0; wire [11:0] sub_wire1; wire sub_wire2; wire [17:0] sub_wire3; wire [11:0] sub_wire4; wire rdempty = sub_wire0; wire [11:0] wrusedw = sub_wire1[11:0]; wire wrfull = sub_wire2; wire [17:0] q = sub_wire3[17:0]; wire [11:0] rdusedw = sub_wire4[11:0]; dcfifo dcfifo_component ( .wrclk (wrclk), .rdreq (rdreq), .aclr (aclr), .rdclk (rdclk), .wrreq (wrreq), .data (data), .rdempty (sub_wire0), .wrusedw (sub_wire1), .wrfull (sub_wire2), .q (sub_wire3), .rdusedw (sub_wire4) // synopsys translate_off , .rdfull (), .wrempty () // synopsys translate_on ); defparam dcfifo_component.add_ram_output_register = "OFF", dcfifo_component.clocks_are_synchronized = "FALSE", dcfifo_component.intended_device_family = "Cyclone", dcfifo_component.lpm_numwords = 4096, dcfifo_component.lpm_showahead = "ON", dcfifo_component.lpm_type = "dcfifo", dcfifo_component.lpm_width = 18, dcfifo_component.lpm_widthu = 12, dcfifo_component.overflow_checking = "OFF", dcfifo_component.underflow_checking = "OFF", dcfifo_component.use_eab = "ON"; endmodule
module fifo_4k_18 ( aclr, data, rdclk, rdreq, wrclk, wrreq, q, rdempty, rdusedw, wrfull, wrusedw); input aclr; input [17:0] data; input rdclk; input rdreq; input wrclk; input wrreq; output [17:0] q; output rdempty; output [11:0] rdusedw; output wrfull; output [11:0] wrusedw; wire sub_wire0; wire [11:0] sub_wire1; wire sub_wire2; wire [17:0] sub_wire3; wire [11:0] sub_wire4; wire rdempty = sub_wire0; wire [11:0] wrusedw = sub_wire1[11:0]; wire wrfull = sub_wire2; wire [17:0] q = sub_wire3[17:0]; wire [11:0] rdusedw = sub_wire4[11:0]; dcfifo dcfifo_component ( .wrclk (wrclk), .rdreq (rdreq), .aclr (aclr), .rdclk (rdclk), .wrreq (wrreq), .data (data), .rdempty (sub_wire0), .wrusedw (sub_wire1), .wrfull (sub_wire2), .q (sub_wire3), .rdusedw (sub_wire4) // synopsys translate_off , .rdfull (), .wrempty () // synopsys translate_on ); defparam dcfifo_component.add_ram_output_register = "OFF", dcfifo_component.clocks_are_synchronized = "FALSE", dcfifo_component.intended_device_family = "Cyclone", dcfifo_component.lpm_numwords = 4096, dcfifo_component.lpm_showahead = "ON", dcfifo_component.lpm_type = "dcfifo", dcfifo_component.lpm_width = 18, dcfifo_component.lpm_widthu = 12, dcfifo_component.overflow_checking = "OFF", dcfifo_component.underflow_checking = "OFF", dcfifo_component.use_eab = "ON"; endmodule
module fake_nonburstboundary # ( parameter WIDTH_D = 256, parameter S_WIDTH_A = 26, parameter M_WIDTH_A = S_WIDTH_A+$clog2(WIDTH_D/8), parameter BURSTCOUNT_WIDTH = 6, parameter BYTEENABLE_WIDTH = WIDTH_D, parameter MAX_PENDING_READS = 64 ) ( input clk, input resetn, // Slave port input [S_WIDTH_A-1:0] slave_address, // Word address input [WIDTH_D-1:0] slave_writedata, input slave_read, input slave_write, input [BURSTCOUNT_WIDTH-1:0] slave_burstcount, input [BYTEENABLE_WIDTH-1:0] slave_byteenable, output slave_waitrequest, output [WIDTH_D-1:0] slave_readdata, output slave_readdatavalid, output [M_WIDTH_A-1:0] master_address, // Byte address output [WIDTH_D-1:0] master_writedata, output master_read, output master_write, output [BURSTCOUNT_WIDTH-1:0] master_burstcount, output [BYTEENABLE_WIDTH-1:0] master_byteenable, input master_waitrequest, input [WIDTH_D-1:0] master_readdata, input master_readdatavalid ); assign master_read = slave_read; assign master_write = slave_write; assign master_writedata = slave_writedata; assign master_burstcount = slave_burstcount; assign master_address = {slave_address,{$clog2(WIDTH_D/8){1'b0}}}; //byteaddr assign master_byteenable = slave_byteenable; assign slave_waitrequest = master_waitrequest; assign slave_readdatavalid = master_readdatavalid; assign slave_readdata = master_readdata; endmodule
module generic_baseblocks_v2_1_0_comparator_static # ( parameter C_FAMILY = "virtex6", // FPGA Family. Current version: virtex6 or spartan6. parameter C_VALUE = 4'b0, // Static value to compare against. parameter integer C_DATA_WIDTH = 4 // Data width for comparator. ) ( input wire CIN, input wire [C_DATA_WIDTH-1:0] A, output wire COUT ); ///////////////////////////////////////////////////////////////////////////// // Variables for generating parameter controlled instances. ///////////////////////////////////////////////////////////////////////////// // Generate variable for bit vector. genvar bit_cnt; ///////////////////////////////////////////////////////////////////////////// // Local params ///////////////////////////////////////////////////////////////////////////// // Bits per LUT for this architecture. localparam integer C_BITS_PER_LUT = 6; // Constants for packing levels. localparam integer C_NUM_LUT = ( C_DATA_WIDTH + C_BITS_PER_LUT - 1 ) / C_BITS_PER_LUT; // localparam integer C_FIX_DATA_WIDTH = ( C_NUM_LUT * C_BITS_PER_LUT > C_DATA_WIDTH ) ? C_NUM_LUT * C_BITS_PER_LUT : C_DATA_WIDTH; ///////////////////////////////////////////////////////////////////////////// // Functions ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Internal signals ///////////////////////////////////////////////////////////////////////////// wire [C_FIX_DATA_WIDTH-1:0] a_local; wire [C_FIX_DATA_WIDTH-1:0] b_local; wire [C_NUM_LUT-1:0] sel; wire [C_NUM_LUT:0] carry_local; ///////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////// generate // Assign input to local vectors. assign carry_local[0] = CIN; // Extend input data to fit. if ( C_NUM_LUT * C_BITS_PER_LUT > C_DATA_WIDTH ) begin : USE_EXTENDED_DATA assign a_local = {A, {C_NUM_LUT * C_BITS_PER_LUT - C_DATA_WIDTH{1'b0}}}; assign b_local = {C_VALUE, {C_NUM_LUT * C_BITS_PER_LUT - C_DATA_WIDTH{1'b0}}}; end else begin : NO_EXTENDED_DATA assign a_local = A; assign b_local = C_VALUE; end // Instantiate one generic_baseblocks_v2_1_0_carry and per level. for (bit_cnt = 0; bit_cnt < C_NUM_LUT ; bit_cnt = bit_cnt + 1) begin : LUT_LEVEL // Create the local select signal assign sel[bit_cnt] = ( a_local[bit_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] == b_local[bit_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] ); // Instantiate each LUT level. generic_baseblocks_v2_1_0_carry_and # ( .C_FAMILY(C_FAMILY) ) compare_inst ( .COUT (carry_local[bit_cnt+1]), .CIN (carry_local[bit_cnt]), .S (sel[bit_cnt]) ); end // end for bit_cnt // Assign output from local vector. assign COUT = carry_local[C_NUM_LUT]; endgenerate endmodule
module generic_baseblocks_v2_1_0_comparator_mask_static # ( parameter C_FAMILY = "virtex6", // FPGA Family. Current version: virtex6 or spartan6. parameter C_VALUE = 4'b0, // Static value to compare against. parameter integer C_DATA_WIDTH = 4 // Data width for comparator. ) ( input wire CIN, input wire [C_DATA_WIDTH-1:0] A, input wire [C_DATA_WIDTH-1:0] M, output wire COUT ); ///////////////////////////////////////////////////////////////////////////// // Variables for generating parameter controlled instances. ///////////////////////////////////////////////////////////////////////////// // Generate variable for bit vector. genvar lut_cnt; ///////////////////////////////////////////////////////////////////////////// // Local params ///////////////////////////////////////////////////////////////////////////// // Bits per LUT for this architecture. localparam integer C_BITS_PER_LUT = 3; // Constants for packing levels. localparam integer C_NUM_LUT = ( C_DATA_WIDTH + C_BITS_PER_LUT - 1 ) / C_BITS_PER_LUT; // localparam integer C_FIX_DATA_WIDTH = ( C_NUM_LUT * C_BITS_PER_LUT > C_DATA_WIDTH ) ? C_NUM_LUT * C_BITS_PER_LUT : C_DATA_WIDTH; ///////////////////////////////////////////////////////////////////////////// // Functions ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Internal signals ///////////////////////////////////////////////////////////////////////////// wire [C_FIX_DATA_WIDTH-1:0] a_local; wire [C_FIX_DATA_WIDTH-1:0] b_local; wire [C_FIX_DATA_WIDTH-1:0] m_local; wire [C_NUM_LUT-1:0] sel; wire [C_NUM_LUT:0] carry_local; ///////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////// generate // Assign input to local vectors. assign carry_local[0] = CIN; // Extend input data to fit. if ( C_NUM_LUT * C_BITS_PER_LUT > C_DATA_WIDTH ) begin : USE_EXTENDED_DATA assign a_local = {A, {C_NUM_LUT * C_BITS_PER_LUT - C_DATA_WIDTH{1'b0}}}; assign b_local = {C_VALUE, {C_NUM_LUT * C_BITS_PER_LUT - C_DATA_WIDTH{1'b0}}}; assign m_local = {M, {C_NUM_LUT * C_BITS_PER_LUT - C_DATA_WIDTH{1'b0}}}; end else begin : NO_EXTENDED_DATA assign a_local = A; assign b_local = C_VALUE; assign m_local = M; end // Instantiate one generic_baseblocks_v2_1_0_carry and per level. for (lut_cnt = 0; lut_cnt < C_NUM_LUT ; lut_cnt = lut_cnt + 1) begin : LUT_LEVEL // Create the local select signal assign sel[lut_cnt] = ( ( a_local[lut_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] & m_local[lut_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] ) == ( b_local[lut_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] & m_local[lut_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] ) ); // Instantiate each LUT level. generic_baseblocks_v2_1_0_carry_and # ( .C_FAMILY(C_FAMILY) ) compare_inst ( .COUT (carry_local[lut_cnt+1]), .CIN (carry_local[lut_cnt]), .S (sel[lut_cnt]) ); end // end for lut_cnt // Assign output from local vector. assign COUT = carry_local[C_NUM_LUT]; endgenerate endmodule
module generic_baseblocks_v2_1_0_comparator_mask_static # ( parameter C_FAMILY = "virtex6", // FPGA Family. Current version: virtex6 or spartan6. parameter C_VALUE = 4'b0, // Static value to compare against. parameter integer C_DATA_WIDTH = 4 // Data width for comparator. ) ( input wire CIN, input wire [C_DATA_WIDTH-1:0] A, input wire [C_DATA_WIDTH-1:0] M, output wire COUT ); ///////////////////////////////////////////////////////////////////////////// // Variables for generating parameter controlled instances. ///////////////////////////////////////////////////////////////////////////// // Generate variable for bit vector. genvar lut_cnt; ///////////////////////////////////////////////////////////////////////////// // Local params ///////////////////////////////////////////////////////////////////////////// // Bits per LUT for this architecture. localparam integer C_BITS_PER_LUT = 3; // Constants for packing levels. localparam integer C_NUM_LUT = ( C_DATA_WIDTH + C_BITS_PER_LUT - 1 ) / C_BITS_PER_LUT; // localparam integer C_FIX_DATA_WIDTH = ( C_NUM_LUT * C_BITS_PER_LUT > C_DATA_WIDTH ) ? C_NUM_LUT * C_BITS_PER_LUT : C_DATA_WIDTH; ///////////////////////////////////////////////////////////////////////////// // Functions ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Internal signals ///////////////////////////////////////////////////////////////////////////// wire [C_FIX_DATA_WIDTH-1:0] a_local; wire [C_FIX_DATA_WIDTH-1:0] b_local; wire [C_FIX_DATA_WIDTH-1:0] m_local; wire [C_NUM_LUT-1:0] sel; wire [C_NUM_LUT:0] carry_local; ///////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////// generate // Assign input to local vectors. assign carry_local[0] = CIN; // Extend input data to fit. if ( C_NUM_LUT * C_BITS_PER_LUT > C_DATA_WIDTH ) begin : USE_EXTENDED_DATA assign a_local = {A, {C_NUM_LUT * C_BITS_PER_LUT - C_DATA_WIDTH{1'b0}}}; assign b_local = {C_VALUE, {C_NUM_LUT * C_BITS_PER_LUT - C_DATA_WIDTH{1'b0}}}; assign m_local = {M, {C_NUM_LUT * C_BITS_PER_LUT - C_DATA_WIDTH{1'b0}}}; end else begin : NO_EXTENDED_DATA assign a_local = A; assign b_local = C_VALUE; assign m_local = M; end // Instantiate one generic_baseblocks_v2_1_0_carry and per level. for (lut_cnt = 0; lut_cnt < C_NUM_LUT ; lut_cnt = lut_cnt + 1) begin : LUT_LEVEL // Create the local select signal assign sel[lut_cnt] = ( ( a_local[lut_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] & m_local[lut_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] ) == ( b_local[lut_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] & m_local[lut_cnt*C_BITS_PER_LUT +: C_BITS_PER_LUT] ) ); // Instantiate each LUT level. generic_baseblocks_v2_1_0_carry_and # ( .C_FAMILY(C_FAMILY) ) compare_inst ( .COUT (carry_local[lut_cnt+1]), .CIN (carry_local[lut_cnt]), .S (sel[lut_cnt]) ); end // end for lut_cnt // Assign output from local vector. assign COUT = carry_local[C_NUM_LUT]; endgenerate endmodule
module fifo_with_byteenables ( clk, areset, sreset, write_data, write_byteenables, write, push, read_data, pop, used, full, empty ); parameter DATA_WIDTH = 32; parameter FIFO_DEPTH = 128; parameter FIFO_DEPTH_LOG2 = 7; // this impacts the width of the used port so it can't be local parameter LATENCY = 1; // number of clock cycles after asserting 'pop' that valid data comes out input clk; input areset; input sreset; input [DATA_WIDTH-1:0] write_data; input [(DATA_WIDTH/8)-1:0] write_byteenables; input write; input push; // when you have written to all the byte lanes assert this to commit the word (you can use it at the same time as the byte enables) output wire [DATA_WIDTH-1:0] read_data; input pop; // use this to read a word out of the FIFO output wire [FIFO_DEPTH_LOG2:0] used; output wire full; output wire empty; reg [FIFO_DEPTH_LOG2-1:0] write_address; reg [FIFO_DEPTH_LOG2-1:0] read_address; reg [FIFO_DEPTH_LOG2:0] internal_used; wire internal_full; wire internal_empty; always @ (posedge clk or posedge areset) begin if (areset) begin write_address <= 0; end else begin if (sreset) begin write_address <= 0; end else if (push == 1) begin write_address <= write_address + 1'b1; end end end always @ (posedge clk or posedge areset) begin if (areset) begin read_address <= 0; end else begin if (sreset) begin read_address <= 0; end else if (pop == 1) begin read_address <= read_address + 1'b1; end end end // TODO: Change this to an inferrered RAM when Quartus II supports byte enables for inferred RAM altsyncram the_dp_ram ( .clock0 (clk), .wren_a (write), .byteena_a (write_byteenables), .data_a (write_data), .address_a (write_address), .q_b (read_data), .address_b (read_address) ); defparam the_dp_ram.operation_mode = "DUAL_PORT"; // simple dual port (one read, one write port) defparam the_dp_ram.lpm_type = "altsyncram"; defparam the_dp_ram.read_during_write_mode_mixed_ports = "DONT_CARE"; defparam the_dp_ram.power_up_uninitialized = "TRUE"; defparam the_dp_ram.byte_size = 8; defparam the_dp_ram.width_a = DATA_WIDTH; defparam the_dp_ram.width_b = DATA_WIDTH; defparam the_dp_ram.widthad_a = FIFO_DEPTH_LOG2; defparam the_dp_ram.widthad_b = FIFO_DEPTH_LOG2; defparam the_dp_ram.width_byteena_a = (DATA_WIDTH/8); defparam the_dp_ram.numwords_a = FIFO_DEPTH; defparam the_dp_ram.numwords_b = FIFO_DEPTH; defparam the_dp_ram.address_reg_b = "CLOCK0"; defparam the_dp_ram.outdata_reg_b = (LATENCY == 2)? "CLOCK0" : "UNREGISTERED"; always @ (posedge clk or posedge areset) begin if (areset) begin internal_used <= 0; end else begin if (sreset) begin internal_used <= 0; end else begin case ({push, pop}) 2'b01: internal_used <= internal_used - 1'b1; 2'b10: internal_used <= internal_used + 1'b1; default: internal_used <= internal_used; endcase end end end assign internal_empty = (read_address == write_address) & (internal_used == 0); assign internal_full = (write_address == read_address) & (internal_used != 0); assign used = internal_used; // this signal reflects the number of words in the FIFO assign empty = internal_empty; // combinational so it'll glitch a little bit assign full = internal_full; // dito endmodule
module fifo_with_byteenables ( clk, areset, sreset, write_data, write_byteenables, write, push, read_data, pop, used, full, empty ); parameter DATA_WIDTH = 32; parameter FIFO_DEPTH = 128; parameter FIFO_DEPTH_LOG2 = 7; // this impacts the width of the used port so it can't be local parameter LATENCY = 1; // number of clock cycles after asserting 'pop' that valid data comes out input clk; input areset; input sreset; input [DATA_WIDTH-1:0] write_data; input [(DATA_WIDTH/8)-1:0] write_byteenables; input write; input push; // when you have written to all the byte lanes assert this to commit the word (you can use it at the same time as the byte enables) output wire [DATA_WIDTH-1:0] read_data; input pop; // use this to read a word out of the FIFO output wire [FIFO_DEPTH_LOG2:0] used; output wire full; output wire empty; reg [FIFO_DEPTH_LOG2-1:0] write_address; reg [FIFO_DEPTH_LOG2-1:0] read_address; reg [FIFO_DEPTH_LOG2:0] internal_used; wire internal_full; wire internal_empty; always @ (posedge clk or posedge areset) begin if (areset) begin write_address <= 0; end else begin if (sreset) begin write_address <= 0; end else if (push == 1) begin write_address <= write_address + 1'b1; end end end always @ (posedge clk or posedge areset) begin if (areset) begin read_address <= 0; end else begin if (sreset) begin read_address <= 0; end else if (pop == 1) begin read_address <= read_address + 1'b1; end end end // TODO: Change this to an inferrered RAM when Quartus II supports byte enables for inferred RAM altsyncram the_dp_ram ( .clock0 (clk), .wren_a (write), .byteena_a (write_byteenables), .data_a (write_data), .address_a (write_address), .q_b (read_data), .address_b (read_address) ); defparam the_dp_ram.operation_mode = "DUAL_PORT"; // simple dual port (one read, one write port) defparam the_dp_ram.lpm_type = "altsyncram"; defparam the_dp_ram.read_during_write_mode_mixed_ports = "DONT_CARE"; defparam the_dp_ram.power_up_uninitialized = "TRUE"; defparam the_dp_ram.byte_size = 8; defparam the_dp_ram.width_a = DATA_WIDTH; defparam the_dp_ram.width_b = DATA_WIDTH; defparam the_dp_ram.widthad_a = FIFO_DEPTH_LOG2; defparam the_dp_ram.widthad_b = FIFO_DEPTH_LOG2; defparam the_dp_ram.width_byteena_a = (DATA_WIDTH/8); defparam the_dp_ram.numwords_a = FIFO_DEPTH; defparam the_dp_ram.numwords_b = FIFO_DEPTH; defparam the_dp_ram.address_reg_b = "CLOCK0"; defparam the_dp_ram.outdata_reg_b = (LATENCY == 2)? "CLOCK0" : "UNREGISTERED"; always @ (posedge clk or posedge areset) begin if (areset) begin internal_used <= 0; end else begin if (sreset) begin internal_used <= 0; end else begin case ({push, pop}) 2'b01: internal_used <= internal_used - 1'b1; 2'b10: internal_used <= internal_used + 1'b1; default: internal_used <= internal_used; endcase end end end assign internal_empty = (read_address == write_address) & (internal_used == 0); assign internal_full = (write_address == read_address) & (internal_used != 0); assign used = internal_used; // this signal reflects the number of words in the FIFO assign empty = internal_empty; // combinational so it'll glitch a little bit assign full = internal_full; // dito endmodule
module fifo_with_byteenables ( clk, areset, sreset, write_data, write_byteenables, write, push, read_data, pop, used, full, empty ); parameter DATA_WIDTH = 32; parameter FIFO_DEPTH = 128; parameter FIFO_DEPTH_LOG2 = 7; // this impacts the width of the used port so it can't be local parameter LATENCY = 1; // number of clock cycles after asserting 'pop' that valid data comes out input clk; input areset; input sreset; input [DATA_WIDTH-1:0] write_data; input [(DATA_WIDTH/8)-1:0] write_byteenables; input write; input push; // when you have written to all the byte lanes assert this to commit the word (you can use it at the same time as the byte enables) output wire [DATA_WIDTH-1:0] read_data; input pop; // use this to read a word out of the FIFO output wire [FIFO_DEPTH_LOG2:0] used; output wire full; output wire empty; reg [FIFO_DEPTH_LOG2-1:0] write_address; reg [FIFO_DEPTH_LOG2-1:0] read_address; reg [FIFO_DEPTH_LOG2:0] internal_used; wire internal_full; wire internal_empty; always @ (posedge clk or posedge areset) begin if (areset) begin write_address <= 0; end else begin if (sreset) begin write_address <= 0; end else if (push == 1) begin write_address <= write_address + 1'b1; end end end always @ (posedge clk or posedge areset) begin if (areset) begin read_address <= 0; end else begin if (sreset) begin read_address <= 0; end else if (pop == 1) begin read_address <= read_address + 1'b1; end end end // TODO: Change this to an inferrered RAM when Quartus II supports byte enables for inferred RAM altsyncram the_dp_ram ( .clock0 (clk), .wren_a (write), .byteena_a (write_byteenables), .data_a (write_data), .address_a (write_address), .q_b (read_data), .address_b (read_address) ); defparam the_dp_ram.operation_mode = "DUAL_PORT"; // simple dual port (one read, one write port) defparam the_dp_ram.lpm_type = "altsyncram"; defparam the_dp_ram.read_during_write_mode_mixed_ports = "DONT_CARE"; defparam the_dp_ram.power_up_uninitialized = "TRUE"; defparam the_dp_ram.byte_size = 8; defparam the_dp_ram.width_a = DATA_WIDTH; defparam the_dp_ram.width_b = DATA_WIDTH; defparam the_dp_ram.widthad_a = FIFO_DEPTH_LOG2; defparam the_dp_ram.widthad_b = FIFO_DEPTH_LOG2; defparam the_dp_ram.width_byteena_a = (DATA_WIDTH/8); defparam the_dp_ram.numwords_a = FIFO_DEPTH; defparam the_dp_ram.numwords_b = FIFO_DEPTH; defparam the_dp_ram.address_reg_b = "CLOCK0"; defparam the_dp_ram.outdata_reg_b = (LATENCY == 2)? "CLOCK0" : "UNREGISTERED"; always @ (posedge clk or posedge areset) begin if (areset) begin internal_used <= 0; end else begin if (sreset) begin internal_used <= 0; end else begin case ({push, pop}) 2'b01: internal_used <= internal_used - 1'b1; 2'b10: internal_used <= internal_used + 1'b1; default: internal_used <= internal_used; endcase end end end assign internal_empty = (read_address == write_address) & (internal_used == 0); assign internal_full = (write_address == read_address) & (internal_used != 0); assign used = internal_used; // this signal reflects the number of words in the FIFO assign empty = internal_empty; // combinational so it'll glitch a little bit assign full = internal_full; // dito endmodule
module fifo_with_byteenables ( clk, areset, sreset, write_data, write_byteenables, write, push, read_data, pop, used, full, empty ); parameter DATA_WIDTH = 32; parameter FIFO_DEPTH = 128; parameter FIFO_DEPTH_LOG2 = 7; // this impacts the width of the used port so it can't be local parameter LATENCY = 1; // number of clock cycles after asserting 'pop' that valid data comes out input clk; input areset; input sreset; input [DATA_WIDTH-1:0] write_data; input [(DATA_WIDTH/8)-1:0] write_byteenables; input write; input push; // when you have written to all the byte lanes assert this to commit the word (you can use it at the same time as the byte enables) output wire [DATA_WIDTH-1:0] read_data; input pop; // use this to read a word out of the FIFO output wire [FIFO_DEPTH_LOG2:0] used; output wire full; output wire empty; reg [FIFO_DEPTH_LOG2-1:0] write_address; reg [FIFO_DEPTH_LOG2-1:0] read_address; reg [FIFO_DEPTH_LOG2:0] internal_used; wire internal_full; wire internal_empty; always @ (posedge clk or posedge areset) begin if (areset) begin write_address <= 0; end else begin if (sreset) begin write_address <= 0; end else if (push == 1) begin write_address <= write_address + 1'b1; end end end always @ (posedge clk or posedge areset) begin if (areset) begin read_address <= 0; end else begin if (sreset) begin read_address <= 0; end else if (pop == 1) begin read_address <= read_address + 1'b1; end end end // TODO: Change this to an inferrered RAM when Quartus II supports byte enables for inferred RAM altsyncram the_dp_ram ( .clock0 (clk), .wren_a (write), .byteena_a (write_byteenables), .data_a (write_data), .address_a (write_address), .q_b (read_data), .address_b (read_address) ); defparam the_dp_ram.operation_mode = "DUAL_PORT"; // simple dual port (one read, one write port) defparam the_dp_ram.lpm_type = "altsyncram"; defparam the_dp_ram.read_during_write_mode_mixed_ports = "DONT_CARE"; defparam the_dp_ram.power_up_uninitialized = "TRUE"; defparam the_dp_ram.byte_size = 8; defparam the_dp_ram.width_a = DATA_WIDTH; defparam the_dp_ram.width_b = DATA_WIDTH; defparam the_dp_ram.widthad_a = FIFO_DEPTH_LOG2; defparam the_dp_ram.widthad_b = FIFO_DEPTH_LOG2; defparam the_dp_ram.width_byteena_a = (DATA_WIDTH/8); defparam the_dp_ram.numwords_a = FIFO_DEPTH; defparam the_dp_ram.numwords_b = FIFO_DEPTH; defparam the_dp_ram.address_reg_b = "CLOCK0"; defparam the_dp_ram.outdata_reg_b = (LATENCY == 2)? "CLOCK0" : "UNREGISTERED"; always @ (posedge clk or posedge areset) begin if (areset) begin internal_used <= 0; end else begin if (sreset) begin internal_used <= 0; end else begin case ({push, pop}) 2'b01: internal_used <= internal_used - 1'b1; 2'b10: internal_used <= internal_used + 1'b1; default: internal_used <= internal_used; endcase end end end assign internal_empty = (read_address == write_address) & (internal_used == 0); assign internal_full = (write_address == read_address) & (internal_used != 0); assign used = internal_used; // this signal reflects the number of words in the FIFO assign empty = internal_empty; // combinational so it'll glitch a little bit assign full = internal_full; // dito endmodule
module generic_baseblocks_v2_1_0_nto1_mux # ( parameter integer C_RATIO = 1, // Range: >=1 parameter integer C_SEL_WIDTH = 1, // Range: >=1; recommended: ceil_log2(C_RATIO) parameter integer C_DATAOUT_WIDTH = 1, // Range: >=1 parameter integer C_ONEHOT = 0 // Values: 0 = binary-encoded (use SEL); 1 = one-hot (use SEL_ONEHOT) ) ( input wire [C_RATIO-1:0] SEL_ONEHOT, // One-hot generic_baseblocks_v2_1_0_mux select (only used if C_ONEHOT=1) input wire [C_SEL_WIDTH-1:0] SEL, // Binary-encoded generic_baseblocks_v2_1_0_mux select (only used if C_ONEHOT=0) input wire [C_RATIO*C_DATAOUT_WIDTH-1:0] IN, // Data input array (num_selections x data_width) output wire [C_DATAOUT_WIDTH-1:0] OUT // Data output vector ); wire [C_DATAOUT_WIDTH*C_RATIO-1:0] carry; genvar i; generate if (C_ONEHOT == 0) begin : gen_encoded assign carry[C_DATAOUT_WIDTH-1:0] = {C_DATAOUT_WIDTH{(SEL==0)?1'b1:1'b0}} & IN[C_DATAOUT_WIDTH-1:0]; for (i=1;i<C_RATIO;i=i+1) begin : gen_carrychain_enc assign carry[(i+1)*C_DATAOUT_WIDTH-1:i*C_DATAOUT_WIDTH] = carry[i*C_DATAOUT_WIDTH-1:(i-1)*C_DATAOUT_WIDTH] | {C_DATAOUT_WIDTH{(SEL==i)?1'b1:1'b0}} & IN[(i+1)*C_DATAOUT_WIDTH-1:i*C_DATAOUT_WIDTH]; end end else begin : gen_onehot assign carry[C_DATAOUT_WIDTH-1:0] = {C_DATAOUT_WIDTH{SEL_ONEHOT[0]}} & IN[C_DATAOUT_WIDTH-1:0]; for (i=1;i<C_RATIO;i=i+1) begin : gen_carrychain_hot assign carry[(i+1)*C_DATAOUT_WIDTH-1:i*C_DATAOUT_WIDTH] = carry[i*C_DATAOUT_WIDTH-1:(i-1)*C_DATAOUT_WIDTH] | {C_DATAOUT_WIDTH{SEL_ONEHOT[i]}} & IN[(i+1)*C_DATAOUT_WIDTH-1:i*C_DATAOUT_WIDTH]; end end endgenerate assign OUT = carry[C_DATAOUT_WIDTH*C_RATIO-1: C_DATAOUT_WIDTH*(C_RATIO-1)]; endmodule
module generic_baseblocks_v2_1_0_nto1_mux # ( parameter integer C_RATIO = 1, // Range: >=1 parameter integer C_SEL_WIDTH = 1, // Range: >=1; recommended: ceil_log2(C_RATIO) parameter integer C_DATAOUT_WIDTH = 1, // Range: >=1 parameter integer C_ONEHOT = 0 // Values: 0 = binary-encoded (use SEL); 1 = one-hot (use SEL_ONEHOT) ) ( input wire [C_RATIO-1:0] SEL_ONEHOT, // One-hot generic_baseblocks_v2_1_0_mux select (only used if C_ONEHOT=1) input wire [C_SEL_WIDTH-1:0] SEL, // Binary-encoded generic_baseblocks_v2_1_0_mux select (only used if C_ONEHOT=0) input wire [C_RATIO*C_DATAOUT_WIDTH-1:0] IN, // Data input array (num_selections x data_width) output wire [C_DATAOUT_WIDTH-1:0] OUT // Data output vector ); wire [C_DATAOUT_WIDTH*C_RATIO-1:0] carry; genvar i; generate if (C_ONEHOT == 0) begin : gen_encoded assign carry[C_DATAOUT_WIDTH-1:0] = {C_DATAOUT_WIDTH{(SEL==0)?1'b1:1'b0}} & IN[C_DATAOUT_WIDTH-1:0]; for (i=1;i<C_RATIO;i=i+1) begin : gen_carrychain_enc assign carry[(i+1)*C_DATAOUT_WIDTH-1:i*C_DATAOUT_WIDTH] = carry[i*C_DATAOUT_WIDTH-1:(i-1)*C_DATAOUT_WIDTH] | {C_DATAOUT_WIDTH{(SEL==i)?1'b1:1'b0}} & IN[(i+1)*C_DATAOUT_WIDTH-1:i*C_DATAOUT_WIDTH]; end end else begin : gen_onehot assign carry[C_DATAOUT_WIDTH-1:0] = {C_DATAOUT_WIDTH{SEL_ONEHOT[0]}} & IN[C_DATAOUT_WIDTH-1:0]; for (i=1;i<C_RATIO;i=i+1) begin : gen_carrychain_hot assign carry[(i+1)*C_DATAOUT_WIDTH-1:i*C_DATAOUT_WIDTH] = carry[i*C_DATAOUT_WIDTH-1:(i-1)*C_DATAOUT_WIDTH] | {C_DATAOUT_WIDTH{SEL_ONEHOT[i]}} & IN[(i+1)*C_DATAOUT_WIDTH-1:i*C_DATAOUT_WIDTH]; end end endgenerate assign OUT = carry[C_DATAOUT_WIDTH*C_RATIO-1: C_DATAOUT_WIDTH*(C_RATIO-1)]; endmodule
module generic_baseblocks_v2_1_0_nto1_mux # ( parameter integer C_RATIO = 1, // Range: >=1 parameter integer C_SEL_WIDTH = 1, // Range: >=1; recommended: ceil_log2(C_RATIO) parameter integer C_DATAOUT_WIDTH = 1, // Range: >=1 parameter integer C_ONEHOT = 0 // Values: 0 = binary-encoded (use SEL); 1 = one-hot (use SEL_ONEHOT) ) ( input wire [C_RATIO-1:0] SEL_ONEHOT, // One-hot generic_baseblocks_v2_1_0_mux select (only used if C_ONEHOT=1) input wire [C_SEL_WIDTH-1:0] SEL, // Binary-encoded generic_baseblocks_v2_1_0_mux select (only used if C_ONEHOT=0) input wire [C_RATIO*C_DATAOUT_WIDTH-1:0] IN, // Data input array (num_selections x data_width) output wire [C_DATAOUT_WIDTH-1:0] OUT // Data output vector ); wire [C_DATAOUT_WIDTH*C_RATIO-1:0] carry; genvar i; generate if (C_ONEHOT == 0) begin : gen_encoded assign carry[C_DATAOUT_WIDTH-1:0] = {C_DATAOUT_WIDTH{(SEL==0)?1'b1:1'b0}} & IN[C_DATAOUT_WIDTH-1:0]; for (i=1;i<C_RATIO;i=i+1) begin : gen_carrychain_enc assign carry[(i+1)*C_DATAOUT_WIDTH-1:i*C_DATAOUT_WIDTH] = carry[i*C_DATAOUT_WIDTH-1:(i-1)*C_DATAOUT_WIDTH] | {C_DATAOUT_WIDTH{(SEL==i)?1'b1:1'b0}} & IN[(i+1)*C_DATAOUT_WIDTH-1:i*C_DATAOUT_WIDTH]; end end else begin : gen_onehot assign carry[C_DATAOUT_WIDTH-1:0] = {C_DATAOUT_WIDTH{SEL_ONEHOT[0]}} & IN[C_DATAOUT_WIDTH-1:0]; for (i=1;i<C_RATIO;i=i+1) begin : gen_carrychain_hot assign carry[(i+1)*C_DATAOUT_WIDTH-1:i*C_DATAOUT_WIDTH] = carry[i*C_DATAOUT_WIDTH-1:(i-1)*C_DATAOUT_WIDTH] | {C_DATAOUT_WIDTH{SEL_ONEHOT[i]}} & IN[(i+1)*C_DATAOUT_WIDTH-1:i*C_DATAOUT_WIDTH]; end end endgenerate assign OUT = carry[C_DATAOUT_WIDTH*C_RATIO-1: C_DATAOUT_WIDTH*(C_RATIO-1)]; endmodule
module generic_baseblocks_v2_1_0_nto1_mux # ( parameter integer C_RATIO = 1, // Range: >=1 parameter integer C_SEL_WIDTH = 1, // Range: >=1; recommended: ceil_log2(C_RATIO) parameter integer C_DATAOUT_WIDTH = 1, // Range: >=1 parameter integer C_ONEHOT = 0 // Values: 0 = binary-encoded (use SEL); 1 = one-hot (use SEL_ONEHOT) ) ( input wire [C_RATIO-1:0] SEL_ONEHOT, // One-hot generic_baseblocks_v2_1_0_mux select (only used if C_ONEHOT=1) input wire [C_SEL_WIDTH-1:0] SEL, // Binary-encoded generic_baseblocks_v2_1_0_mux select (only used if C_ONEHOT=0) input wire [C_RATIO*C_DATAOUT_WIDTH-1:0] IN, // Data input array (num_selections x data_width) output wire [C_DATAOUT_WIDTH-1:0] OUT // Data output vector ); wire [C_DATAOUT_WIDTH*C_RATIO-1:0] carry; genvar i; generate if (C_ONEHOT == 0) begin : gen_encoded assign carry[C_DATAOUT_WIDTH-1:0] = {C_DATAOUT_WIDTH{(SEL==0)?1'b1:1'b0}} & IN[C_DATAOUT_WIDTH-1:0]; for (i=1;i<C_RATIO;i=i+1) begin : gen_carrychain_enc assign carry[(i+1)*C_DATAOUT_WIDTH-1:i*C_DATAOUT_WIDTH] = carry[i*C_DATAOUT_WIDTH-1:(i-1)*C_DATAOUT_WIDTH] | {C_DATAOUT_WIDTH{(SEL==i)?1'b1:1'b0}} & IN[(i+1)*C_DATAOUT_WIDTH-1:i*C_DATAOUT_WIDTH]; end end else begin : gen_onehot assign carry[C_DATAOUT_WIDTH-1:0] = {C_DATAOUT_WIDTH{SEL_ONEHOT[0]}} & IN[C_DATAOUT_WIDTH-1:0]; for (i=1;i<C_RATIO;i=i+1) begin : gen_carrychain_hot assign carry[(i+1)*C_DATAOUT_WIDTH-1:i*C_DATAOUT_WIDTH] = carry[i*C_DATAOUT_WIDTH-1:(i-1)*C_DATAOUT_WIDTH] | {C_DATAOUT_WIDTH{SEL_ONEHOT[i]}} & IN[(i+1)*C_DATAOUT_WIDTH-1:i*C_DATAOUT_WIDTH]; end end endgenerate assign OUT = carry[C_DATAOUT_WIDTH*C_RATIO-1: C_DATAOUT_WIDTH*(C_RATIO-1)]; endmodule
module generic_baseblocks_v2_1_0_nto1_mux # ( parameter integer C_RATIO = 1, // Range: >=1 parameter integer C_SEL_WIDTH = 1, // Range: >=1; recommended: ceil_log2(C_RATIO) parameter integer C_DATAOUT_WIDTH = 1, // Range: >=1 parameter integer C_ONEHOT = 0 // Values: 0 = binary-encoded (use SEL); 1 = one-hot (use SEL_ONEHOT) ) ( input wire [C_RATIO-1:0] SEL_ONEHOT, // One-hot generic_baseblocks_v2_1_0_mux select (only used if C_ONEHOT=1) input wire [C_SEL_WIDTH-1:0] SEL, // Binary-encoded generic_baseblocks_v2_1_0_mux select (only used if C_ONEHOT=0) input wire [C_RATIO*C_DATAOUT_WIDTH-1:0] IN, // Data input array (num_selections x data_width) output wire [C_DATAOUT_WIDTH-1:0] OUT // Data output vector ); wire [C_DATAOUT_WIDTH*C_RATIO-1:0] carry; genvar i; generate if (C_ONEHOT == 0) begin : gen_encoded assign carry[C_DATAOUT_WIDTH-1:0] = {C_DATAOUT_WIDTH{(SEL==0)?1'b1:1'b0}} & IN[C_DATAOUT_WIDTH-1:0]; for (i=1;i<C_RATIO;i=i+1) begin : gen_carrychain_enc assign carry[(i+1)*C_DATAOUT_WIDTH-1:i*C_DATAOUT_WIDTH] = carry[i*C_DATAOUT_WIDTH-1:(i-1)*C_DATAOUT_WIDTH] | {C_DATAOUT_WIDTH{(SEL==i)?1'b1:1'b0}} & IN[(i+1)*C_DATAOUT_WIDTH-1:i*C_DATAOUT_WIDTH]; end end else begin : gen_onehot assign carry[C_DATAOUT_WIDTH-1:0] = {C_DATAOUT_WIDTH{SEL_ONEHOT[0]}} & IN[C_DATAOUT_WIDTH-1:0]; for (i=1;i<C_RATIO;i=i+1) begin : gen_carrychain_hot assign carry[(i+1)*C_DATAOUT_WIDTH-1:i*C_DATAOUT_WIDTH] = carry[i*C_DATAOUT_WIDTH-1:(i-1)*C_DATAOUT_WIDTH] | {C_DATAOUT_WIDTH{SEL_ONEHOT[i]}} & IN[(i+1)*C_DATAOUT_WIDTH-1:i*C_DATAOUT_WIDTH]; end end endgenerate assign OUT = carry[C_DATAOUT_WIDTH*C_RATIO-1: C_DATAOUT_WIDTH*(C_RATIO-1)]; endmodule
module write_burst_control ( clk, reset, sw_reset, sw_stop, length, eop_enabled, eop, ready, valid, early_termination, address_in, write_in, max_burst_count, write_fifo_used, waitrequest, short_first_access_enable, short_last_access_enable, short_first_and_last_access_enable, address_out, write_out, burst_count, stall, reset_taken, stopped ); parameter BURST_ENABLE = 1; // set to 0 to hardwire the address and write signals straight out parameter BURST_COUNT_WIDTH = 3; parameter WORD_SIZE = 4; parameter WORD_SIZE_LOG2 = 2; parameter ADDRESS_WIDTH = 32; parameter LENGTH_WIDTH = 32; parameter WRITE_FIFO_USED_WIDTH = 5; parameter BURST_WRAPPING_SUPPORT = 1; // set 1 for on, set 0 for off. This parameter can't be enabled when the master supports programmable bursting. localparam BURST_OFFSET_WIDTH = (BURST_COUNT_WIDTH == 1)? 1: (BURST_COUNT_WIDTH-1); input clk; input reset; input sw_reset; input sw_stop; input [LENGTH_WIDTH-1:0] length; input eop_enabled; input eop; input ready; input valid; input early_termination; input [ADDRESS_WIDTH-1:0] address_in; input write_in; input [BURST_COUNT_WIDTH-1:0] max_burst_count; // will be either a hardcoded input or programmable input [WRITE_FIFO_USED_WIDTH:0] write_fifo_used; // using the fifo full MSB as well input waitrequest; // this needs to be the waitrequest from the fabric and not the byte enable generator since partial transfers count as burst beats input short_first_access_enable; input short_last_access_enable; input short_first_and_last_access_enable; output wire [ADDRESS_WIDTH-1:0] address_out; output wire write_out; output wire [BURST_COUNT_WIDTH-1:0] burst_count; output wire stall; // need to issue a stall if there isn't enough data buffered to start a burst output wire reset_taken; // if a reset occurs in the middle of a burst larger than 1 then the write master needs to know that the burst hasn't completed yet output wire stopped; // if a stop occurs in the middle of a burst larger than 1 then the write master needs to know that the burst hasn't completed yet reg [ADDRESS_WIDTH-1:0] address_d1; reg [BURST_COUNT_WIDTH-1:0] burst_counter; // interal statemachine register wire idle_state; wire decrement_burst_counter; wire ready_during_idle_state; // when there is enough data buffered to start up the burst counter state machine again wire ready_for_quick_burst; // when there is enough data bufferred to start another burst immediately wire burst_begin_from_idle_state; wire burst_begin_quickly; // start another burst immediately after the previous burst completes wire burst_begin; wire burst_of_one_enable; // asserted when partial word accesses are occuring or the last early termination word is being written out wire [BURST_COUNT_WIDTH-1:0] short_length_burst; wire [BURST_COUNT_WIDTH-1:0] short_packet_burst; wire short_length_burst_enable; wire short_early_termination_burst_enable; wire short_packet_burst_enable; wire [3:0] mux_select; reg [BURST_COUNT_WIDTH-1:0] internal_burst_count; reg [BURST_COUNT_WIDTH-1:0] internal_burst_count_d1; reg packet_complete; wire [BURST_OFFSET_WIDTH-1:0] burst_offset; always @ (posedge clk or posedge reset) begin if (reset) begin packet_complete <= 0; end else begin if ((packet_complete == 1) & (write_fifo_used == 0)) begin packet_complete <= 0; end else if ((eop == 1) & (ready == 1) & (valid == 1)) begin packet_complete <= 1; end end end always @ (posedge clk or posedge reset) begin if (reset) begin address_d1 <= 0; end else if (burst_begin == 1) begin address_d1 <= (burst_begin_quickly == 1)? (address_in + WORD_SIZE) : address_in; end end always @ (posedge clk or posedge reset) begin if (reset) begin burst_counter <= 0; end else if ((burst_begin == 1) & (sw_reset == 0) & (sw_stop == 0)) // for reset and stop we need to let the burst complete so the fabric doesn't lock up begin burst_counter <= internal_burst_count; end else if (decrement_burst_counter == 1) begin burst_counter <= burst_counter - 1'b1; end end always @ (posedge clk or posedge reset) begin if (reset) begin internal_burst_count_d1 <= 0; end else if (burst_begin == 1) begin internal_burst_count_d1 <= internal_burst_count; end end // state machine status and control assign idle_state = (burst_counter == 0); // any time idle_state is set then there is no burst underway assign decrement_burst_counter = (idle_state == 0) & (waitrequest == 0); // control for all the various cases that a burst of one beat needs to be posted assign burst_offset = address_in[BURST_OFFSET_WIDTH+WORD_SIZE_LOG2-1:WORD_SIZE_LOG2]; assign burst_of_one_enable = (short_first_access_enable == 1) | (short_last_access_enable == 1) | (short_first_and_last_access_enable == 1) | (early_termination == 1) | ((BURST_WRAPPING_SUPPORT == 1) & (idle_state == 1) & (burst_offset != 0)) | // need to make sure bursts start on burst boundaries ((BURST_WRAPPING_SUPPORT == 1) & (idle_state == 0) & (burst_offset != (max_burst_count - 1))); // need to make sure bursts start on burst boundaries assign short_length_burst_enable = ((length >> WORD_SIZE_LOG2) < max_burst_count) & (eop_enabled == 0) & (burst_of_one_enable == 0); assign short_early_termination_burst_enable = ((length >> WORD_SIZE_LOG2) < max_burst_count) & (eop_enabled == 1) & (burst_of_one_enable == 0); // trim back the burst count regardless if there is enough data buffered for a full burst assign short_packet_burst_enable = (short_early_termination_burst_enable == 0) & (eop_enabled == 1) & (packet_complete == 1) & (write_fifo_used < max_burst_count) & (burst_of_one_enable == 0); // various burst amounts that are not the max burst count or 1 that feed the internal_burst_count mux. short_length_burst is used when short_length_burst_enable or short_early_termination_burst_enable is asserted. assign short_length_burst = (length >> WORD_SIZE_LOG2) & {(BURST_COUNT_WIDTH-1){1'b1}}; assign short_packet_burst = (write_fifo_used & {(BURST_COUNT_WIDTH-1){1'b1}}); // since the write master may not have enough data buffered in the FIFO to start a burst the FIFO fill level must be checked before starting another burst assign ready_during_idle_state = (burst_of_one_enable == 1) | // burst of one is only enabled when there is data in the write fifo so write_fifo_used doesn't need to be checked in this case ((write_fifo_used >= short_length_burst) & (short_length_burst_enable == 1)) | ((write_fifo_used >= short_length_burst) & (short_early_termination_burst_enable == 1)) | ((write_fifo_used >= short_packet_burst) & (short_packet_burst_enable == 1)) | (write_fifo_used >= max_burst_count); // same as ready_during_idle_state only we need to make sure there is more data in the fifo than the burst being posted (since the FIFO is in the middle of being popped) assign ready_for_quick_burst = (length >= (max_burst_count << WORD_SIZE_LOG2)) & (burst_of_one_enable == 0) & // address and length lags by one clock cycle so this will let the state machine catch up ( ((write_fifo_used > short_length_burst) & (short_length_burst_enable == 1)) | ((write_fifo_used > short_length_burst) & (short_early_termination_burst_enable == 1)) | ((write_fifo_used > short_packet_burst) & (short_packet_burst_enable == 1)) | (write_fifo_used > max_burst_count) ); // burst begin signals used to start up the burst counter state machine assign burst_begin_from_idle_state = (write_in == 1) & (idle_state == 1) & (ready_during_idle_state == 1); // start the state machine up again assign burst_begin_quickly = (write_in == 1) & (burst_counter == 1) & (waitrequest == 0) & (ready_for_quick_burst == 1); // enough data is buffered to start another burst immediately after the current burst assign burst_begin = (burst_begin_quickly == 1) | (burst_begin_from_idle_state == 1); assign mux_select = {short_packet_burst_enable, short_early_termination_burst_enable, short_length_burst_enable, burst_of_one_enable}; // one-hot mux that selects the appropriate burst count to present to the fabric always @ (short_length_burst or short_packet_burst or max_burst_count or mux_select) begin case (mux_select) 4'b0001 : internal_burst_count = 1; 4'b0010 : internal_burst_count = short_length_burst; 4'b0100 : internal_burst_count = short_length_burst; 4'b1000 : internal_burst_count = short_packet_burst; default : internal_burst_count = max_burst_count; endcase end generate if (BURST_ENABLE == 1) begin // outputs that need to be held constant throughout the entire burst transaction assign address_out = address_d1; assign burst_count = internal_burst_count_d1; assign write_out = (idle_state == 0); assign stall = (idle_state == 1); assign reset_taken = (sw_reset == 1) & (idle_state == 1); // for bursts of 1 the write master logic will handle the correct reset timing assign stopped = (sw_stop == 1) & (idle_state == 1); // for bursts of 1 the write master logic will handle the correct stop timing end else begin assign address_out = address_in; assign burst_count = 1; // this will be stubbed at the top level assign write_out = write_in; assign stall = 0; assign reset_taken = sw_reset; assign stopped = sw_stop; end endgenerate endmodule
module write_burst_control ( clk, reset, sw_reset, sw_stop, length, eop_enabled, eop, ready, valid, early_termination, address_in, write_in, max_burst_count, write_fifo_used, waitrequest, short_first_access_enable, short_last_access_enable, short_first_and_last_access_enable, address_out, write_out, burst_count, stall, reset_taken, stopped ); parameter BURST_ENABLE = 1; // set to 0 to hardwire the address and write signals straight out parameter BURST_COUNT_WIDTH = 3; parameter WORD_SIZE = 4; parameter WORD_SIZE_LOG2 = 2; parameter ADDRESS_WIDTH = 32; parameter LENGTH_WIDTH = 32; parameter WRITE_FIFO_USED_WIDTH = 5; parameter BURST_WRAPPING_SUPPORT = 1; // set 1 for on, set 0 for off. This parameter can't be enabled when the master supports programmable bursting. localparam BURST_OFFSET_WIDTH = (BURST_COUNT_WIDTH == 1)? 1: (BURST_COUNT_WIDTH-1); input clk; input reset; input sw_reset; input sw_stop; input [LENGTH_WIDTH-1:0] length; input eop_enabled; input eop; input ready; input valid; input early_termination; input [ADDRESS_WIDTH-1:0] address_in; input write_in; input [BURST_COUNT_WIDTH-1:0] max_burst_count; // will be either a hardcoded input or programmable input [WRITE_FIFO_USED_WIDTH:0] write_fifo_used; // using the fifo full MSB as well input waitrequest; // this needs to be the waitrequest from the fabric and not the byte enable generator since partial transfers count as burst beats input short_first_access_enable; input short_last_access_enable; input short_first_and_last_access_enable; output wire [ADDRESS_WIDTH-1:0] address_out; output wire write_out; output wire [BURST_COUNT_WIDTH-1:0] burst_count; output wire stall; // need to issue a stall if there isn't enough data buffered to start a burst output wire reset_taken; // if a reset occurs in the middle of a burst larger than 1 then the write master needs to know that the burst hasn't completed yet output wire stopped; // if a stop occurs in the middle of a burst larger than 1 then the write master needs to know that the burst hasn't completed yet reg [ADDRESS_WIDTH-1:0] address_d1; reg [BURST_COUNT_WIDTH-1:0] burst_counter; // interal statemachine register wire idle_state; wire decrement_burst_counter; wire ready_during_idle_state; // when there is enough data buffered to start up the burst counter state machine again wire ready_for_quick_burst; // when there is enough data bufferred to start another burst immediately wire burst_begin_from_idle_state; wire burst_begin_quickly; // start another burst immediately after the previous burst completes wire burst_begin; wire burst_of_one_enable; // asserted when partial word accesses are occuring or the last early termination word is being written out wire [BURST_COUNT_WIDTH-1:0] short_length_burst; wire [BURST_COUNT_WIDTH-1:0] short_packet_burst; wire short_length_burst_enable; wire short_early_termination_burst_enable; wire short_packet_burst_enable; wire [3:0] mux_select; reg [BURST_COUNT_WIDTH-1:0] internal_burst_count; reg [BURST_COUNT_WIDTH-1:0] internal_burst_count_d1; reg packet_complete; wire [BURST_OFFSET_WIDTH-1:0] burst_offset; always @ (posedge clk or posedge reset) begin if (reset) begin packet_complete <= 0; end else begin if ((packet_complete == 1) & (write_fifo_used == 0)) begin packet_complete <= 0; end else if ((eop == 1) & (ready == 1) & (valid == 1)) begin packet_complete <= 1; end end end always @ (posedge clk or posedge reset) begin if (reset) begin address_d1 <= 0; end else if (burst_begin == 1) begin address_d1 <= (burst_begin_quickly == 1)? (address_in + WORD_SIZE) : address_in; end end always @ (posedge clk or posedge reset) begin if (reset) begin burst_counter <= 0; end else if ((burst_begin == 1) & (sw_reset == 0) & (sw_stop == 0)) // for reset and stop we need to let the burst complete so the fabric doesn't lock up begin burst_counter <= internal_burst_count; end else if (decrement_burst_counter == 1) begin burst_counter <= burst_counter - 1'b1; end end always @ (posedge clk or posedge reset) begin if (reset) begin internal_burst_count_d1 <= 0; end else if (burst_begin == 1) begin internal_burst_count_d1 <= internal_burst_count; end end // state machine status and control assign idle_state = (burst_counter == 0); // any time idle_state is set then there is no burst underway assign decrement_burst_counter = (idle_state == 0) & (waitrequest == 0); // control for all the various cases that a burst of one beat needs to be posted assign burst_offset = address_in[BURST_OFFSET_WIDTH+WORD_SIZE_LOG2-1:WORD_SIZE_LOG2]; assign burst_of_one_enable = (short_first_access_enable == 1) | (short_last_access_enable == 1) | (short_first_and_last_access_enable == 1) | (early_termination == 1) | ((BURST_WRAPPING_SUPPORT == 1) & (idle_state == 1) & (burst_offset != 0)) | // need to make sure bursts start on burst boundaries ((BURST_WRAPPING_SUPPORT == 1) & (idle_state == 0) & (burst_offset != (max_burst_count - 1))); // need to make sure bursts start on burst boundaries assign short_length_burst_enable = ((length >> WORD_SIZE_LOG2) < max_burst_count) & (eop_enabled == 0) & (burst_of_one_enable == 0); assign short_early_termination_burst_enable = ((length >> WORD_SIZE_LOG2) < max_burst_count) & (eop_enabled == 1) & (burst_of_one_enable == 0); // trim back the burst count regardless if there is enough data buffered for a full burst assign short_packet_burst_enable = (short_early_termination_burst_enable == 0) & (eop_enabled == 1) & (packet_complete == 1) & (write_fifo_used < max_burst_count) & (burst_of_one_enable == 0); // various burst amounts that are not the max burst count or 1 that feed the internal_burst_count mux. short_length_burst is used when short_length_burst_enable or short_early_termination_burst_enable is asserted. assign short_length_burst = (length >> WORD_SIZE_LOG2) & {(BURST_COUNT_WIDTH-1){1'b1}}; assign short_packet_burst = (write_fifo_used & {(BURST_COUNT_WIDTH-1){1'b1}}); // since the write master may not have enough data buffered in the FIFO to start a burst the FIFO fill level must be checked before starting another burst assign ready_during_idle_state = (burst_of_one_enable == 1) | // burst of one is only enabled when there is data in the write fifo so write_fifo_used doesn't need to be checked in this case ((write_fifo_used >= short_length_burst) & (short_length_burst_enable == 1)) | ((write_fifo_used >= short_length_burst) & (short_early_termination_burst_enable == 1)) | ((write_fifo_used >= short_packet_burst) & (short_packet_burst_enable == 1)) | (write_fifo_used >= max_burst_count); // same as ready_during_idle_state only we need to make sure there is more data in the fifo than the burst being posted (since the FIFO is in the middle of being popped) assign ready_for_quick_burst = (length >= (max_burst_count << WORD_SIZE_LOG2)) & (burst_of_one_enable == 0) & // address and length lags by one clock cycle so this will let the state machine catch up ( ((write_fifo_used > short_length_burst) & (short_length_burst_enable == 1)) | ((write_fifo_used > short_length_burst) & (short_early_termination_burst_enable == 1)) | ((write_fifo_used > short_packet_burst) & (short_packet_burst_enable == 1)) | (write_fifo_used > max_burst_count) ); // burst begin signals used to start up the burst counter state machine assign burst_begin_from_idle_state = (write_in == 1) & (idle_state == 1) & (ready_during_idle_state == 1); // start the state machine up again assign burst_begin_quickly = (write_in == 1) & (burst_counter == 1) & (waitrequest == 0) & (ready_for_quick_burst == 1); // enough data is buffered to start another burst immediately after the current burst assign burst_begin = (burst_begin_quickly == 1) | (burst_begin_from_idle_state == 1); assign mux_select = {short_packet_burst_enable, short_early_termination_burst_enable, short_length_burst_enable, burst_of_one_enable}; // one-hot mux that selects the appropriate burst count to present to the fabric always @ (short_length_burst or short_packet_burst or max_burst_count or mux_select) begin case (mux_select) 4'b0001 : internal_burst_count = 1; 4'b0010 : internal_burst_count = short_length_burst; 4'b0100 : internal_burst_count = short_length_burst; 4'b1000 : internal_burst_count = short_packet_burst; default : internal_burst_count = max_burst_count; endcase end generate if (BURST_ENABLE == 1) begin // outputs that need to be held constant throughout the entire burst transaction assign address_out = address_d1; assign burst_count = internal_burst_count_d1; assign write_out = (idle_state == 0); assign stall = (idle_state == 1); assign reset_taken = (sw_reset == 1) & (idle_state == 1); // for bursts of 1 the write master logic will handle the correct reset timing assign stopped = (sw_stop == 1) & (idle_state == 1); // for bursts of 1 the write master logic will handle the correct stop timing end else begin assign address_out = address_in; assign burst_count = 1; // this will be stubbed at the top level assign write_out = write_in; assign stall = 0; assign reset_taken = sw_reset; assign stopped = sw_stop; end endgenerate endmodule
module mem_window ( clk, reset, // Memory slave port s1_address, s1_read, s1_readdata, s1_readdatavalid, s1_write, s1_writedata, s1_burstcount, s1_byteenable, s1_waitrequest, // Configuration register slave port cra_write, cra_writedata, cra_byteenable, // Bridged master port to memory m1_address, m1_read, m1_readdata, m1_readdatavalid, m1_write, m1_writedata, m1_burstcount, m1_byteenable, m1_waitrequest ); parameter PAGE_ADDRESS_WIDTH = 20; parameter MEM_ADDRESS_WIDTH = 32; parameter NUM_BYTES = 32; parameter BURSTCOUNT_WIDTH = 1; parameter CRA_BITWIDTH = 32; localparam ADDRESS_SHIFT = $clog2(NUM_BYTES); localparam PAGE_ID_WIDTH = MEM_ADDRESS_WIDTH - PAGE_ADDRESS_WIDTH - ADDRESS_SHIFT; localparam DATA_WIDTH = NUM_BYTES * 8; input clk; input reset; // Memory slave port input [PAGE_ADDRESS_WIDTH-1:0] s1_address; input s1_read; output [DATA_WIDTH-1:0] s1_readdata; output s1_readdatavalid; input s1_write; input [DATA_WIDTH-1:0] s1_writedata; input [BURSTCOUNT_WIDTH-1:0] s1_burstcount; input [NUM_BYTES-1:0] s1_byteenable; output s1_waitrequest; // Bridged master port to memory output [MEM_ADDRESS_WIDTH-1:0] m1_address; output m1_read; input [DATA_WIDTH-1:0] m1_readdata; input m1_readdatavalid; output m1_write; output [DATA_WIDTH-1:0] m1_writedata; output [BURSTCOUNT_WIDTH-1:0] m1_burstcount; output [NUM_BYTES-1:0] m1_byteenable; input m1_waitrequest; // CRA slave input cra_write; input [CRA_BITWIDTH-1:0] cra_writedata; input [CRA_BITWIDTH/8-1:0] cra_byteenable; // Architecture // CRA slave allows the master to change the active page reg [PAGE_ID_WIDTH-1:0] page_id; reg [CRA_BITWIDTH-1:0] cra_writemask; integer i; always@* for (i=0; i<CRA_BITWIDTH; i=i+1) cra_writemask[i] = cra_byteenable[i/8] & cra_write; always@(posedge clk or posedge reset) begin if(reset == 1'b1) page_id <= {PAGE_ID_WIDTH{1'b0}}; else page_id <= (cra_writedata & cra_writemask) | (page_id & ~cra_writemask); end // The s1 port bridges to the m1 port - with the page ID tacked on to the address assign m1_address = {page_id, s1_address, {ADDRESS_SHIFT{1'b0}}}; assign m1_read = s1_read; assign s1_readdata = m1_readdata; assign s1_readdatavalid = m1_readdatavalid; assign m1_write = s1_write; assign m1_writedata = s1_writedata; assign m1_burstcount = s1_burstcount; assign m1_byteenable = s1_byteenable; assign s1_waitrequest = m1_waitrequest; endmodule
module channel_demux #(parameter NUM_CHAN = 2) ( //usb Side input [31:0]usbdata_final, input WR_final, // TX Side input reset, input txclk, output reg [NUM_CHAN:0] WR_channel, output reg [31:0] ram_data, output reg [NUM_CHAN:0] WR_done_channel ); /* Parse header and forward to ram */ reg [2:0]reader_state; reg [4:0]channel ; reg [6:0]read_length ; // States parameter IDLE = 3'd0; parameter HEADER = 3'd1; parameter WAIT = 3'd2; parameter FORWARD = 3'd3; `define CHANNEL 20:16 `define PKT_SIZE 127 wire [4:0] true_channel; assign true_channel = (usbdata_final[`CHANNEL] == 5'h1f) ? NUM_CHAN : (usbdata_final[`CHANNEL]); always @(posedge txclk) begin if (reset) begin reader_state <= IDLE; WR_channel <= 0; WR_done_channel <= 0; end else case (reader_state) IDLE: begin if (WR_final) reader_state <= HEADER; end // Store channel and forware header HEADER: begin channel <= true_channel; WR_channel[true_channel] <= 1; ram_data <= usbdata_final; read_length <= 7'd0 ; reader_state <= WAIT; end WAIT: begin WR_channel[channel] <= 0; if (read_length == `PKT_SIZE) reader_state <= IDLE; else if (WR_final) reader_state <= FORWARD; end FORWARD: begin WR_channel[channel] <= 1; ram_data <= usbdata_final; read_length <= read_length + 7'd1; reader_state <= WAIT; end default: begin //error handling reader_state <= IDLE; end endcase end endmodule
module read_master ( clk, reset, // descriptor commands sink port snk_command_data, snk_command_valid, snk_command_ready, // response source port src_response_data, src_response_valid, src_response_ready, // data path sink port src_data, src_valid, src_ready, src_sop, src_eop, src_empty, src_error, src_channel, // data path master port master_address, master_read, master_byteenable, master_readdata, master_waitrequest, master_readdatavalid, master_burstcount ); parameter UNALIGNED_ACCESSES_ENABLE = 0; // when enabled allows transfers to begin from off word boundaries parameter ONLY_FULL_ACCESS_ENABLE = 0; // when enabled allows transfers to end with partial access, master achieve a much higher fmax when this is enabled parameter STRIDE_ENABLE = 0; // stride support can only be enabled when unaligned accesses is disabled parameter STRIDE_WIDTH = 1; // when stride support is enabled this value controls the rate in which the address increases (in words), the stride width + log2(byte enable width) + 1 cannot exceed address width parameter PACKET_ENABLE = 0; parameter ERROR_ENABLE = 0; parameter ERROR_WIDTH = 8; // must be between 1-8, this will only be enabled in the GUI when error enable is turned on parameter CHANNEL_ENABLE = 0; parameter CHANNEL_WIDTH = 8; // must be between 1-8, this will only be enabled in the GUI when the channel enable is turned on parameter DATA_WIDTH = 32; parameter BYTE_ENABLE_WIDTH = 4; // set by the .tcl file (hidden in GUI) parameter BYTE_ENABLE_WIDTH_LOG2 = 2; // set by the .tcl file (hidden in GUI) parameter ADDRESS_WIDTH = 32; // set in the .tcl file (hidden in GUI) by the address span of the master parameter LENGTH_WIDTH = 32; // GUI setting with warning if ADDRESS_WIDTH < LENGTH_WIDTH (waste of logic for the length counter) parameter FIFO_DEPTH = 32; parameter FIFO_DEPTH_LOG2 = 5; // set by the .tcl file (hidden in GUI) parameter FIFO_SPEED_OPTIMIZATION = 1; // set by the .tcl file (hidden in GUI) The default will be on since it only impacts the latency of the entire transfer by 1 clock cycle and adds very little additional logic. parameter SYMBOL_WIDTH = 8; // set in the .tcl file (hidden in GUI) parameter NUMBER_OF_SYMBOLS = 4; // set in the .tcl file (hidden in GUI) parameter NUMBER_OF_SYMBOLS_LOG2 = 2; // set by the .tcl file (hidden in GUI) parameter BURST_ENABLE = 0; // when enabled stride must be disabled, 1 to enable, 0 to disable parameter MAX_BURST_COUNT = 2; // must be a power of 2, when BURST_ENABLE = 0 set maximum_burst_count to 1 (will be automatically done by .tcl file) parameter MAX_BURST_COUNT_WIDTH = 2; // set by the .tcl file (hidden in GUI) = log2(maximum_burst_count) + 1 parameter PROGRAMMABLE_BURST_ENABLE = 0; // when enabled the user must set the burst count, if 0 is set then the value "maximum_burst_count" will be used instead parameter BURST_WRAPPING_SUPPORT = 1; // will only be used when bursting is enabled. This cannot be enabled with programmable burst capabilities. Enabling it will make sure the master gets back into burst alignment (data width in bytes * maximum burst count alignment) localparam FIFO_USE_MEMORY = 1; // set to 0 to use LEs instead, not exposed since FPGAs have a lot of memory these days localparam BIG_ENDIAN_ACCESS = 0; // hiding this since it can blow your foot off if you are not careful. It's big endian with respect to the write master width and not necessarily to the width of the data type used by a host CPU. // handy mask for seperating the word address from the byte address bits, so for 32 bit masters this mask is 0x3, for 64 bit masters it'll be 0x7 localparam LSB_MASK = {BYTE_ENABLE_WIDTH_LOG2{1'b1}}; // when packet data is supported then we need to buffer the empty, eop, sop, error, and channel bits localparam FIFO_WIDTH = DATA_WIDTH + NUMBER_OF_SYMBOLS_LOG2 + 2 + ERROR_WIDTH + CHANNEL_WIDTH; localparam ADDRESS_INCREMENT_WIDTH = (BYTE_ENABLE_WIDTH_LOG2 + MAX_BURST_COUNT_WIDTH + STRIDE_WIDTH); localparam FIXED_STRIDE = 1'b1; // default stride distance used when stride is disabled. 1 means increment the address by a word (i.e. sequential transfer) input clk; input reset; // descriptor commands sink port input [255:0] snk_command_data; input snk_command_valid; output reg snk_command_ready; // response source port output wire [255:0] src_response_data; output reg src_response_valid; input src_response_ready; // data path source port output wire [DATA_WIDTH-1:0] src_data; output wire src_valid; input src_ready; output wire src_sop; output wire src_eop; output wire [NUMBER_OF_SYMBOLS_LOG2-1:0] src_empty; output wire [ERROR_WIDTH-1:0] src_error; output wire [CHANNEL_WIDTH-1:0] src_channel; // master inputs and outputs input master_waitrequest; output wire [ADDRESS_WIDTH-1:0] master_address; output wire master_read; output wire [BYTE_ENABLE_WIDTH-1:0] master_byteenable; input [DATA_WIDTH-1:0] master_readdata; input master_readdatavalid; output wire [MAX_BURST_COUNT_WIDTH-1:0] master_burstcount; // internal signals wire [63:0] descriptor_address; wire [31:0] descriptor_length; wire [15:0] descriptor_stride; wire [7:0] descriptor_channel; wire descriptor_generate_sop; wire descriptor_generate_eop; wire [7:0] descriptor_error; wire [7:0] descriptor_programmable_burst_count; wire descriptor_early_done_enable; wire sw_stop_in; wire sw_reset_in; reg early_done_enable_d1; reg [ERROR_WIDTH-1:0] error_d1; reg [MAX_BURST_COUNT_WIDTH-1:0] programmable_burst_count_d1; wire [MAX_BURST_COUNT_WIDTH-1:0] maximum_burst_count; reg generate_sop_d1; reg generate_eop_d1; reg [ADDRESS_WIDTH-1:0] address_counter; reg [LENGTH_WIDTH-1:0] length_counter; reg [CHANNEL_WIDTH-1:0] channel_d1; reg [STRIDE_WIDTH-1:0] stride_d1; wire [STRIDE_WIDTH-1:0] stride_amount; // either set to be stride_d1 or hardcoded to 1 depending on the parameterization reg [BYTE_ENABLE_WIDTH_LOG2-1:0] start_byte_address; // used to determine how far out of alignment the master starts reg first_access; // used to determine if the first read is occuring wire first_word_boundary_not_reached; // set when the first access doesn't reach the next word boundary reg first_word_boundary_not_reached_d1; reg [FIFO_DEPTH_LOG2:0] pending_reads_counter; reg [FIFO_DEPTH_LOG2:0] pending_reads_mux; wire [FIFO_WIDTH-1:0] fifo_write_data; wire [FIFO_WIDTH-1:0] fifo_read_data; wire fifo_write; wire fifo_read; wire fifo_empty; wire fifo_full; wire [FIFO_DEPTH_LOG2-1:0] fifo_used; wire too_many_pending_reads; wire read_complete; // handy signal for determining when a read has occured and completed wire address_increment_enable; wire [ADDRESS_INCREMENT_WIDTH-1:0] address_increment; // amount of bytes to increment the address wire [ADDRESS_INCREMENT_WIDTH-1:0] bytes_to_transfer; wire short_first_access_enable; // when starting unaligned and the amount of data to transfer reaches the next word boundary wire short_last_access_enable; // when address is aligned (can be an unaligned buffer transfer) but the amount of data doesn't reach the next word boundary wire short_first_and_last_access_enable; // when starting unaligned and the amount of data to transfer doesn't reach the next word boundary wire [ADDRESS_INCREMENT_WIDTH-1:0] short_first_access_size; wire [ADDRESS_INCREMENT_WIDTH-1:0] short_last_access_size; wire [ADDRESS_INCREMENT_WIDTH-1:0] short_first_and_last_access_size; reg [ADDRESS_INCREMENT_WIDTH-1:0] bytes_to_transfer_mux; wire go; wire done; // asserted when last read is issued reg done_d1; wire done_strobe; wire all_reads_returned; // asserted when last read returns reg all_reads_returned_d1; wire all_reads_returned_strobe; reg all_reads_returned_strobe_d1; reg all_reads_returned_strobe_d2; // used to trigger src_response_ready later than when the last read returns since the MM to ST has two pipeline stages wire [DATA_WIDTH-1:0] MM_to_ST_adapter_dataout; wire [DATA_WIDTH-1:0] MM_to_ST_adapter_dataout_rearranged; wire MM_to_ST_adapter_sop; wire MM_to_ST_adapter_eop; wire [NUMBER_OF_SYMBOLS_LOG2-1:0] MM_to_ST_adapter_empty; wire masked_sop; wire masked_eop; reg flush; reg stopped; wire length_sync_reset; wire set_src_response_valid; reg master_read_reg; /********************************************* REGISTERS **************************************************/ // registering descriptor information always @ (posedge clk or posedge reset) begin if (reset) begin error_d1 <= 0; generate_sop_d1 <= 0; generate_eop_d1 <= 0; channel_d1 <= 0; stride_d1 <= 0; programmable_burst_count_d1 <= 0; early_done_enable_d1 <= 0; end else if (go == 1) begin error_d1 <= descriptor_error[ERROR_WIDTH-1:0]; generate_sop_d1 <= descriptor_generate_sop; generate_eop_d1 <= descriptor_generate_eop; channel_d1 <= descriptor_channel[CHANNEL_WIDTH-1:0]; stride_d1 <= descriptor_stride[STRIDE_WIDTH-1:0]; programmable_burst_count_d1 <= (descriptor_programmable_burst_count == 0)? MAX_BURST_COUNT : descriptor_programmable_burst_count; early_done_enable_d1 <= ((UNALIGNED_ACCESSES_ENABLE == 1) | (PACKET_ENABLE == 1))? 0 : descriptor_early_done_enable; // early done cannot be used when unaligned data or packet support is enabled end end // master word increment counter always @ (posedge clk or posedge reset) begin if (reset) begin address_counter <= 0; end else begin if (go == 1) begin address_counter <= descriptor_address[ADDRESS_WIDTH-1:0]; end else if (address_increment_enable == 1) begin address_counter <= address_counter + address_increment; end end end // master byte address, used to determine how far out of alignment the master began transfering data always @ (posedge clk or posedge reset) begin if (reset) begin start_byte_address <= 0; end else if (go == 1) begin start_byte_address <= descriptor_address[BYTE_ENABLE_WIDTH_LOG2-1:0]; end end // first_access will be asserted only for the first read of a transaction, this will be used to determine what value will be used to increment the counters always @ (posedge clk or posedge reset) begin if (reset == 1) begin first_access <= 0; end else begin if (go == 1) begin first_access <= 1; end else if ((first_access == 1) & (address_increment_enable == 1)) begin first_access <= 0; end end end // this register is used to determine if the first word boundary will be reached always @ (posedge clk or posedge reset) begin if (reset) begin first_word_boundary_not_reached_d1 <= 0; end else if (go == 1) begin first_word_boundary_not_reached_d1 <= first_word_boundary_not_reached; end end // master length logic, this will typically be the critical path followed by the FIFO always @ (posedge clk or posedge reset) begin if (reset) begin length_counter <= 0; end else begin if (length_sync_reset == 1) begin length_counter <= 0; end else if (go == 1) begin length_counter <= descriptor_length[LENGTH_WIDTH-1:0]; end else if (address_increment_enable == 1) begin length_counter <= length_counter - bytes_to_transfer; // not using address_increment because stride might be enabled end end end // the pending reads counter is used to determine how many outstanding reads are posted. This will be used to determine // if more reads can be posted based on the number of unused words in the FIFO. always @ (posedge clk or posedge reset) begin if (reset) begin pending_reads_counter <= 0; end else begin pending_reads_counter <= pending_reads_mux; end end always @ (posedge clk or posedge reset) begin if (reset) begin done_d1 <= 1; // master is done coming out of reset (need this to be set high so that done_strobe doesn't fire) end else begin done_d1 <= done; end end // this is the 'final done' condition, since reads are pipelined need to make sure they have all returned before the master is really done. always @ (posedge clk or posedge reset) begin if (reset) begin all_reads_returned_d1 <= 1; end else begin all_reads_returned_d1 <= all_reads_returned; end end always @ (posedge clk or posedge reset) begin if (reset == 1) begin flush <= 0; end else begin if ((pending_reads_counter == 0) & (flush == 1)) begin flush <= 0; end else if ((sw_reset_in == 1) & ((read_complete == 1) | (snk_command_ready == 1) | (master_read_reg == 0))) begin flush <= 1; // will be used to reset the length counter to 0 and flush out pending reads (by letting them return without buffering them) end end end always @ (posedge clk or posedge reset) begin if (reset) begin stopped <= 0; end else begin if ((sw_stop_in == 0) | (sw_reset_in == 1)) begin stopped <= 0; end else if ((sw_stop_in == 1) & ((read_complete == 1) | (snk_command_ready == 1) | (master_read_reg == 0))) begin stopped <= 1; end end end always @ (posedge clk or posedge reset) begin if (reset) begin snk_command_ready <= 1; // have to start ready to take commands end else begin if (go == 1) begin snk_command_ready <= 0; end else if ((src_response_ready == 1) & (src_response_valid == 1)) // need to make sure the response is popped before accepting more commands begin snk_command_ready <= 1; end end end always @ (posedge clk or posedge reset) begin if (reset) begin all_reads_returned_strobe_d1 <= 0; all_reads_returned_strobe_d2 <= 0; end else begin all_reads_returned_strobe_d1 <= all_reads_returned_strobe; all_reads_returned_strobe_d2 <= all_reads_returned_strobe_d1; end end always @ (posedge clk or posedge reset) begin if (reset) begin src_response_valid <= 0; end else begin if (flush == 1) begin src_response_valid <= 0; end else if (set_src_response_valid == 1) // all the reads have returned with MM to ST adapter latency taken into consideration begin src_response_valid <= 1; // will be set only once end else if ((src_response_valid == 1) & (src_response_ready == 1)) begin src_response_valid <= 0; // will be reset only once when the dispatcher captures the data end end end always @ (posedge clk or posedge reset) begin if (reset) begin master_read_reg <= 0; end else begin if ((done == 0) & (too_many_pending_reads == 0) & (sw_stop_in == 0) & (sw_reset_in == 0)) begin master_read_reg <= 1; end else if ((done == 1) | ((read_complete == 1) & ((too_many_pending_reads == 1) | (sw_stop_in == 1)))) begin master_read_reg <= 0; end end end /******************************************* END REGISTERS ************************************************/ /************************************** MODULE INSTANTIATIONS *********************************************/ // This block is pipelined and can't throttle the reads MM_to_ST_Adapter the_MM_to_ST_adapter ( .clk (clk), .reset (reset), .length (descriptor_length[LENGTH_WIDTH-1:0]), .length_counter (length_counter), .address (descriptor_address[ADDRESS_WIDTH-1:0]), .reads_pending (pending_reads_counter), .start (go), .readdata (master_readdata), .readdatavalid (master_readdatavalid), .fifo_data (MM_to_ST_adapter_dataout), .fifo_write (fifo_write), .fifo_empty (MM_to_ST_adapter_empty), .fifo_sop (MM_to_ST_adapter_sop), .fifo_eop (MM_to_ST_adapter_eop) ); defparam the_MM_to_ST_adapter.DATA_WIDTH = DATA_WIDTH; defparam the_MM_to_ST_adapter.LENGTH_WIDTH = LENGTH_WIDTH; defparam the_MM_to_ST_adapter.ADDRESS_WIDTH = ADDRESS_WIDTH; defparam the_MM_to_ST_adapter.BYTE_ADDRESS_WIDTH = BYTE_ENABLE_WIDTH_LOG2; defparam the_MM_to_ST_adapter.READS_PENDING_WIDTH = FIFO_DEPTH_LOG2 + 1; defparam the_MM_to_ST_adapter.EMPTY_WIDTH = NUMBER_OF_SYMBOLS_LOG2; defparam the_MM_to_ST_adapter.PACKET_SUPPORT = PACKET_ENABLE; defparam the_MM_to_ST_adapter.UNALIGNED_ACCESS_ENABLE = UNALIGNED_ACCESSES_ENABLE; defparam the_MM_to_ST_adapter.FULL_WORD_ACCESS_ONLY = ONLY_FULL_ACCESS_ENABLE; // buffered sop, eop, empty, data (in that order). sop, eop, and empty are only buffered when packet support is enabled scfifo the_master_to_st_fifo ( .aclr (reset), .clock (clk), .data (fifo_write_data), .full (fifo_full), .empty (fifo_empty), .usedw (fifo_used), .q (fifo_read_data), .rdreq (fifo_read), .wrreq (fifo_write) ); defparam the_master_to_st_fifo.lpm_width = FIFO_WIDTH; defparam the_master_to_st_fifo.lpm_numwords = FIFO_DEPTH; defparam the_master_to_st_fifo.lpm_widthu = FIFO_DEPTH_LOG2; defparam the_master_to_st_fifo.lpm_showahead = "ON"; // slower but doesn't require complex control logic to time with waitrequest defparam the_master_to_st_fifo.use_eab = (FIFO_USE_MEMORY == 1)? "ON" : "OFF"; defparam the_master_to_st_fifo.add_ram_output_register = (FIFO_SPEED_OPTIMIZATION == 1)? "ON" : "OFF"; defparam the_master_to_st_fifo.underflow_checking = "OFF"; defparam the_master_to_st_fifo.overflow_checking = "OFF"; // burst block that takes the length and short access enables and forms a burst count based on them. If any of the short access bits are asserted the block will default to a burst count of 1 read_burst_control the_read_burst_control ( .address (master_address), .length (length_counter), .maximum_burst_count (maximum_burst_count), .short_first_access_enable (short_first_access_enable), .short_last_access_enable (short_last_access_enable), .short_first_and_last_access_enable (short_first_and_last_access_enable), .burst_count (master_burstcount) ); defparam the_read_burst_control.BURST_ENABLE = BURST_ENABLE; defparam the_read_burst_control.BURST_COUNT_WIDTH = MAX_BURST_COUNT_WIDTH; defparam the_read_burst_control.WORD_SIZE_LOG2 = (DATA_WIDTH == 8)? 0 : BYTE_ENABLE_WIDTH_LOG2; // need to make sure log2(word size) is 0 instead of 1 here when the data width is 8 bits defparam the_read_burst_control.ADDRESS_WIDTH = ADDRESS_WIDTH; defparam the_read_burst_control.LENGTH_WIDTH = LENGTH_WIDTH; defparam the_read_burst_control.BURST_WRAPPING_SUPPORT = BURST_WRAPPING_SUPPORT; /************************************ END MODULE INSTANTIATIONS *******************************************/ /******************************** CONTROL AND COMBINATIONAL SIGNALS ***************************************/ // breakout the descriptor information into more manageable names assign descriptor_address = {snk_command_data[140:109], snk_command_data[31:0]}; // 64-bit addressing support assign descriptor_length = snk_command_data[63:32]; assign descriptor_channel = snk_command_data[71:64]; assign descriptor_generate_sop = snk_command_data[72]; assign descriptor_generate_eop = snk_command_data[73]; assign descriptor_programmable_burst_count = snk_command_data[83:76]; assign descriptor_stride = snk_command_data[99:84]; assign descriptor_error = snk_command_data[107:100]; assign descriptor_early_done_enable = snk_command_data[108]; assign sw_stop_in = snk_command_data[74]; assign sw_reset_in = snk_command_data[75]; assign stride_amount = (STRIDE_ENABLE == 1)? stride_d1[STRIDE_WIDTH-1:0] : FIXED_STRIDE; // hardcoding to FIXED_STRIDE when stride capabilities are disabled assign maximum_burst_count = (PROGRAMMABLE_BURST_ENABLE == 1)? programmable_burst_count_d1 : MAX_BURST_COUNT; // swap the bytes if big endian is enabled generate if (BIG_ENDIAN_ACCESS == 1) begin genvar j; for(j=0; j < DATA_WIDTH; j = j + 8) begin: byte_swap assign MM_to_ST_adapter_dataout_rearranged[j +8 -1: j] = MM_to_ST_adapter_dataout[DATA_WIDTH -j -1: DATA_WIDTH -j - 8]; end end else begin assign MM_to_ST_adapter_dataout_rearranged = MM_to_ST_adapter_dataout; end endgenerate assign masked_sop = MM_to_ST_adapter_sop & generate_sop_d1; assign masked_eop = MM_to_ST_adapter_eop & generate_eop_d1; assign fifo_write_data = {error_d1, channel_d1, masked_sop, masked_eop, ((masked_eop == 1)? MM_to_ST_adapter_empty : {NUMBER_OF_SYMBOLS_LOG2{1'b0}} ), MM_to_ST_adapter_dataout_rearranged}; // Avalon-ST is network order (a.k.a. big endian) so we need to reverse the symbols before sending them to the data stream generate genvar i; for(i = 0; i < DATA_WIDTH; i = i + SYMBOL_WIDTH) // the data width is always a multiple of the symbol width begin: symbol_swap assign src_data[i +SYMBOL_WIDTH -1: i] = fifo_read_data[DATA_WIDTH -i -1: DATA_WIDTH -i - SYMBOL_WIDTH]; end endgenerate assign src_empty = (PACKET_ENABLE == 1)? fifo_read_data[(DATA_WIDTH + NUMBER_OF_SYMBOLS_LOG2 - 1) : DATA_WIDTH] : 0; assign src_eop = (PACKET_ENABLE == 1)? fifo_read_data[DATA_WIDTH + NUMBER_OF_SYMBOLS_LOG2] : 0; assign src_sop = (PACKET_ENABLE == 1)? fifo_read_data[DATA_WIDTH + NUMBER_OF_SYMBOLS_LOG2 + 1] : 0; assign src_channel = (CHANNEL_ENABLE == 1)? fifo_read_data[(DATA_WIDTH + NUMBER_OF_SYMBOLS_LOG2 + ERROR_WIDTH + 1): (DATA_WIDTH + NUMBER_OF_SYMBOLS_LOG2 + 2)] : 0; assign src_error = (ERROR_ENABLE == 1)? fifo_read_data[(FIFO_WIDTH-1):(DATA_WIDTH + NUMBER_OF_SYMBOLS_LOG2 + ERROR_WIDTH + 2)] : 0; assign short_first_access_size = BYTE_ENABLE_WIDTH - (address_counter & LSB_MASK); assign short_last_access_size = length_counter & LSB_MASK; assign short_first_and_last_access_size = length_counter & LSB_MASK; /* special case transfer enables and counter increment values (address and length counter) short_first_access_enable is for transfers that start unaligned but reach the next word boundary short_last_access_enable is for transfers that are not the first transfer but don't end on a word boundary short_first_and_last_access_enable is for transfers that start and end with a single transfer and don't end on a word boundary (aligned or unaligned) */ generate if (UNALIGNED_ACCESSES_ENABLE == 1) begin assign short_first_access_enable = ((address_counter & LSB_MASK) != 0) & (first_access == 1) & (first_word_boundary_not_reached_d1 == 0); assign short_last_access_enable = (first_access == 0) & (length_counter < BYTE_ENABLE_WIDTH); assign short_first_and_last_access_enable = (first_access == 1) & (first_word_boundary_not_reached_d1 == 1); assign bytes_to_transfer = bytes_to_transfer_mux; assign address_increment = bytes_to_transfer_mux; // can't use stride when unaligned accesses are enabled end else if (ONLY_FULL_ACCESS_ENABLE == 1) begin assign short_first_access_enable = 0; assign short_last_access_enable = 0; assign short_first_and_last_access_enable = 0; assign bytes_to_transfer = BYTE_ENABLE_WIDTH * master_burstcount; if (STRIDE_ENABLE == 1) begin assign address_increment = BYTE_ENABLE_WIDTH * stride_amount * master_burstcount; // stride must be a static '1' when bursting is enabled end else begin assign address_increment = BYTE_ENABLE_WIDTH * master_burstcount; // stride must be a static '1' when bursting is enabled end end else // must be aligned but can end with any number of bytes begin assign short_first_access_enable = 0; assign short_last_access_enable = length_counter < BYTE_ENABLE_WIDTH; // less than a word to transfer assign short_first_and_last_access_enable = 0; assign bytes_to_transfer = bytes_to_transfer_mux; if (STRIDE_ENABLE == 1) begin assign address_increment = BYTE_ENABLE_WIDTH * stride_amount * master_burstcount; // stride must be a static '1' when bursting is enabled end else begin assign address_increment = BYTE_ENABLE_WIDTH * master_burstcount; // stride must be a static '1' when bursting is enabled end end endgenerate // the burst count will be 1 for all short accesses always @ (short_first_access_enable or short_last_access_enable or short_first_and_last_access_enable or short_first_access_size or short_last_access_size or short_first_and_last_access_size or master_burstcount) begin case ({short_first_and_last_access_enable, short_last_access_enable, short_first_access_enable}) 3'b001: bytes_to_transfer_mux = short_first_access_size; 3'b010: bytes_to_transfer_mux = short_last_access_size; 3'b100: bytes_to_transfer_mux = short_first_and_last_access_size; default: bytes_to_transfer_mux = BYTE_ENABLE_WIDTH * master_burstcount; // this is the only time master_burstcount can be a value other than 1 endcase end always @ (master_readdatavalid or read_complete or pending_reads_counter or master_burstcount) begin case ({master_readdatavalid, read_complete}) 2'b00: pending_reads_mux = pending_reads_counter; // no read posted and no read data returned 2'b01: pending_reads_mux = (pending_reads_counter + master_burstcount); // read posted and no read data returned 2'b10: pending_reads_mux = (pending_reads_counter - 1'b1); // no read posted but read data returned 2'b11: pending_reads_mux = (pending_reads_counter + master_burstcount - 1'b1); // read posted and read data returned endcase end assign src_valid = (fifo_empty == 0); assign first_word_boundary_not_reached = (descriptor_length < BYTE_ENABLE_WIDTH) & // length is less than the word size (((descriptor_length & LSB_MASK) + (descriptor_address & LSB_MASK)) < BYTE_ENABLE_WIDTH); // start address + length doesn't reach the next word boundary assign go = (snk_command_valid == 1) & (snk_command_ready == 1); // go with be one cycle since done will be set to 0 on the next cycle (length will be non-zero) assign done = (length_counter == 0); // all reads are posted but the master is not done since there could be reads pending assign done_strobe = (done == 1) & (done_d1 == 0); assign fifo_read = (src_valid == 1) & (src_ready == 1); assign length_sync_reset = (flush == 1) & (pending_reads_counter == 0); // resetting the length counter will trigger the done condition assign too_many_pending_reads = (({fifo_full,fifo_used} + pending_reads_counter) > (FIFO_DEPTH - (maximum_burst_count << 1))); // making sure a full burst can be posted, using 2x maximum_burst_count since the read signal is pipelined and so this signal will be late using maximum_burst_count alone assign read_complete = (master_read == 1) & (master_waitrequest == 0); assign address_increment_enable = read_complete; assign master_byteenable = {BYTE_ENABLE_WIDTH{1'b1}}; // master always asserts all byte enables and filters the data as it comes in (may lead to destructive reads in some cases) generate if (DATA_WIDTH > 8) begin assign master_address = address_counter & { {(ADDRESS_WIDTH-BYTE_ENABLE_WIDTH_LOG2){1'b1}}, {BYTE_ENABLE_WIDTH_LOG2{1'b0}} }; // masking LSBs (byte offsets) since the address counter might not be aligned for the first transfer end else begin assign master_address = address_counter; // don't need to mask any bits as the address will only advance one byte at a time end endgenerate assign master_read = master_read_reg & (done == 0); // need to mask the read with done so that it doesn't issue one extra read at the end assign all_reads_returned = (done == 1) & (pending_reads_counter == 0); assign all_reads_returned_strobe = (all_reads_returned == 1) & (all_reads_returned_d1 == 0); // for now the done and early done strobes are the same. Both will be triggered when the last data returns generate if (UNALIGNED_ACCESSES_ENABLE == 1) // need to use the delayed strobe since there are two stages of pipelining in the MM to ST adapter begin assign src_response_data = {{252{1'b0}}, all_reads_returned_strobe_d2, done_strobe, stopped, flush}; // 252 zeros: done strobe: early done strobe: stop state: reset delayed end else begin assign src_response_data = {{252{1'b0}}, all_reads_returned_strobe, done_strobe, stopped, flush}; // 252 zeros: done strobe: early done strobe: stop state: reset delayed end endgenerate assign set_src_response_valid = (UNALIGNED_ACCESSES_ENABLE == 1)? all_reads_returned_strobe_d2 : // all the reads have returned with MM to ST adapter latency taken into consideration (early_done_enable_d1 == 1)? done_strobe : all_reads_returned_strobe; // when early done is enabled then the done strobe is sufficient to trigger the next command can enter, otherwise need to wait for the pending reads to return /****************************** END CONTROL AND COMBINATIONAL SIGNALS *************************************/ endmodule
module read_master ( clk, reset, // descriptor commands sink port snk_command_data, snk_command_valid, snk_command_ready, // response source port src_response_data, src_response_valid, src_response_ready, // data path sink port src_data, src_valid, src_ready, src_sop, src_eop, src_empty, src_error, src_channel, // data path master port master_address, master_read, master_byteenable, master_readdata, master_waitrequest, master_readdatavalid, master_burstcount ); parameter UNALIGNED_ACCESSES_ENABLE = 0; // when enabled allows transfers to begin from off word boundaries parameter ONLY_FULL_ACCESS_ENABLE = 0; // when enabled allows transfers to end with partial access, master achieve a much higher fmax when this is enabled parameter STRIDE_ENABLE = 0; // stride support can only be enabled when unaligned accesses is disabled parameter STRIDE_WIDTH = 1; // when stride support is enabled this value controls the rate in which the address increases (in words), the stride width + log2(byte enable width) + 1 cannot exceed address width parameter PACKET_ENABLE = 0; parameter ERROR_ENABLE = 0; parameter ERROR_WIDTH = 8; // must be between 1-8, this will only be enabled in the GUI when error enable is turned on parameter CHANNEL_ENABLE = 0; parameter CHANNEL_WIDTH = 8; // must be between 1-8, this will only be enabled in the GUI when the channel enable is turned on parameter DATA_WIDTH = 32; parameter BYTE_ENABLE_WIDTH = 4; // set by the .tcl file (hidden in GUI) parameter BYTE_ENABLE_WIDTH_LOG2 = 2; // set by the .tcl file (hidden in GUI) parameter ADDRESS_WIDTH = 32; // set in the .tcl file (hidden in GUI) by the address span of the master parameter LENGTH_WIDTH = 32; // GUI setting with warning if ADDRESS_WIDTH < LENGTH_WIDTH (waste of logic for the length counter) parameter FIFO_DEPTH = 32; parameter FIFO_DEPTH_LOG2 = 5; // set by the .tcl file (hidden in GUI) parameter FIFO_SPEED_OPTIMIZATION = 1; // set by the .tcl file (hidden in GUI) The default will be on since it only impacts the latency of the entire transfer by 1 clock cycle and adds very little additional logic. parameter SYMBOL_WIDTH = 8; // set in the .tcl file (hidden in GUI) parameter NUMBER_OF_SYMBOLS = 4; // set in the .tcl file (hidden in GUI) parameter NUMBER_OF_SYMBOLS_LOG2 = 2; // set by the .tcl file (hidden in GUI) parameter BURST_ENABLE = 0; // when enabled stride must be disabled, 1 to enable, 0 to disable parameter MAX_BURST_COUNT = 2; // must be a power of 2, when BURST_ENABLE = 0 set maximum_burst_count to 1 (will be automatically done by .tcl file) parameter MAX_BURST_COUNT_WIDTH = 2; // set by the .tcl file (hidden in GUI) = log2(maximum_burst_count) + 1 parameter PROGRAMMABLE_BURST_ENABLE = 0; // when enabled the user must set the burst count, if 0 is set then the value "maximum_burst_count" will be used instead parameter BURST_WRAPPING_SUPPORT = 1; // will only be used when bursting is enabled. This cannot be enabled with programmable burst capabilities. Enabling it will make sure the master gets back into burst alignment (data width in bytes * maximum burst count alignment) localparam FIFO_USE_MEMORY = 1; // set to 0 to use LEs instead, not exposed since FPGAs have a lot of memory these days localparam BIG_ENDIAN_ACCESS = 0; // hiding this since it can blow your foot off if you are not careful. It's big endian with respect to the write master width and not necessarily to the width of the data type used by a host CPU. // handy mask for seperating the word address from the byte address bits, so for 32 bit masters this mask is 0x3, for 64 bit masters it'll be 0x7 localparam LSB_MASK = {BYTE_ENABLE_WIDTH_LOG2{1'b1}}; // when packet data is supported then we need to buffer the empty, eop, sop, error, and channel bits localparam FIFO_WIDTH = DATA_WIDTH + NUMBER_OF_SYMBOLS_LOG2 + 2 + ERROR_WIDTH + CHANNEL_WIDTH; localparam ADDRESS_INCREMENT_WIDTH = (BYTE_ENABLE_WIDTH_LOG2 + MAX_BURST_COUNT_WIDTH + STRIDE_WIDTH); localparam FIXED_STRIDE = 1'b1; // default stride distance used when stride is disabled. 1 means increment the address by a word (i.e. sequential transfer) input clk; input reset; // descriptor commands sink port input [255:0] snk_command_data; input snk_command_valid; output reg snk_command_ready; // response source port output wire [255:0] src_response_data; output reg src_response_valid; input src_response_ready; // data path source port output wire [DATA_WIDTH-1:0] src_data; output wire src_valid; input src_ready; output wire src_sop; output wire src_eop; output wire [NUMBER_OF_SYMBOLS_LOG2-1:0] src_empty; output wire [ERROR_WIDTH-1:0] src_error; output wire [CHANNEL_WIDTH-1:0] src_channel; // master inputs and outputs input master_waitrequest; output wire [ADDRESS_WIDTH-1:0] master_address; output wire master_read; output wire [BYTE_ENABLE_WIDTH-1:0] master_byteenable; input [DATA_WIDTH-1:0] master_readdata; input master_readdatavalid; output wire [MAX_BURST_COUNT_WIDTH-1:0] master_burstcount; // internal signals wire [63:0] descriptor_address; wire [31:0] descriptor_length; wire [15:0] descriptor_stride; wire [7:0] descriptor_channel; wire descriptor_generate_sop; wire descriptor_generate_eop; wire [7:0] descriptor_error; wire [7:0] descriptor_programmable_burst_count; wire descriptor_early_done_enable; wire sw_stop_in; wire sw_reset_in; reg early_done_enable_d1; reg [ERROR_WIDTH-1:0] error_d1; reg [MAX_BURST_COUNT_WIDTH-1:0] programmable_burst_count_d1; wire [MAX_BURST_COUNT_WIDTH-1:0] maximum_burst_count; reg generate_sop_d1; reg generate_eop_d1; reg [ADDRESS_WIDTH-1:0] address_counter; reg [LENGTH_WIDTH-1:0] length_counter; reg [CHANNEL_WIDTH-1:0] channel_d1; reg [STRIDE_WIDTH-1:0] stride_d1; wire [STRIDE_WIDTH-1:0] stride_amount; // either set to be stride_d1 or hardcoded to 1 depending on the parameterization reg [BYTE_ENABLE_WIDTH_LOG2-1:0] start_byte_address; // used to determine how far out of alignment the master starts reg first_access; // used to determine if the first read is occuring wire first_word_boundary_not_reached; // set when the first access doesn't reach the next word boundary reg first_word_boundary_not_reached_d1; reg [FIFO_DEPTH_LOG2:0] pending_reads_counter; reg [FIFO_DEPTH_LOG2:0] pending_reads_mux; wire [FIFO_WIDTH-1:0] fifo_write_data; wire [FIFO_WIDTH-1:0] fifo_read_data; wire fifo_write; wire fifo_read; wire fifo_empty; wire fifo_full; wire [FIFO_DEPTH_LOG2-1:0] fifo_used; wire too_many_pending_reads; wire read_complete; // handy signal for determining when a read has occured and completed wire address_increment_enable; wire [ADDRESS_INCREMENT_WIDTH-1:0] address_increment; // amount of bytes to increment the address wire [ADDRESS_INCREMENT_WIDTH-1:0] bytes_to_transfer; wire short_first_access_enable; // when starting unaligned and the amount of data to transfer reaches the next word boundary wire short_last_access_enable; // when address is aligned (can be an unaligned buffer transfer) but the amount of data doesn't reach the next word boundary wire short_first_and_last_access_enable; // when starting unaligned and the amount of data to transfer doesn't reach the next word boundary wire [ADDRESS_INCREMENT_WIDTH-1:0] short_first_access_size; wire [ADDRESS_INCREMENT_WIDTH-1:0] short_last_access_size; wire [ADDRESS_INCREMENT_WIDTH-1:0] short_first_and_last_access_size; reg [ADDRESS_INCREMENT_WIDTH-1:0] bytes_to_transfer_mux; wire go; wire done; // asserted when last read is issued reg done_d1; wire done_strobe; wire all_reads_returned; // asserted when last read returns reg all_reads_returned_d1; wire all_reads_returned_strobe; reg all_reads_returned_strobe_d1; reg all_reads_returned_strobe_d2; // used to trigger src_response_ready later than when the last read returns since the MM to ST has two pipeline stages wire [DATA_WIDTH-1:0] MM_to_ST_adapter_dataout; wire [DATA_WIDTH-1:0] MM_to_ST_adapter_dataout_rearranged; wire MM_to_ST_adapter_sop; wire MM_to_ST_adapter_eop; wire [NUMBER_OF_SYMBOLS_LOG2-1:0] MM_to_ST_adapter_empty; wire masked_sop; wire masked_eop; reg flush; reg stopped; wire length_sync_reset; wire set_src_response_valid; reg master_read_reg; /********************************************* REGISTERS **************************************************/ // registering descriptor information always @ (posedge clk or posedge reset) begin if (reset) begin error_d1 <= 0; generate_sop_d1 <= 0; generate_eop_d1 <= 0; channel_d1 <= 0; stride_d1 <= 0; programmable_burst_count_d1 <= 0; early_done_enable_d1 <= 0; end else if (go == 1) begin error_d1 <= descriptor_error[ERROR_WIDTH-1:0]; generate_sop_d1 <= descriptor_generate_sop; generate_eop_d1 <= descriptor_generate_eop; channel_d1 <= descriptor_channel[CHANNEL_WIDTH-1:0]; stride_d1 <= descriptor_stride[STRIDE_WIDTH-1:0]; programmable_burst_count_d1 <= (descriptor_programmable_burst_count == 0)? MAX_BURST_COUNT : descriptor_programmable_burst_count; early_done_enable_d1 <= ((UNALIGNED_ACCESSES_ENABLE == 1) | (PACKET_ENABLE == 1))? 0 : descriptor_early_done_enable; // early done cannot be used when unaligned data or packet support is enabled end end // master word increment counter always @ (posedge clk or posedge reset) begin if (reset) begin address_counter <= 0; end else begin if (go == 1) begin address_counter <= descriptor_address[ADDRESS_WIDTH-1:0]; end else if (address_increment_enable == 1) begin address_counter <= address_counter + address_increment; end end end // master byte address, used to determine how far out of alignment the master began transfering data always @ (posedge clk or posedge reset) begin if (reset) begin start_byte_address <= 0; end else if (go == 1) begin start_byte_address <= descriptor_address[BYTE_ENABLE_WIDTH_LOG2-1:0]; end end // first_access will be asserted only for the first read of a transaction, this will be used to determine what value will be used to increment the counters always @ (posedge clk or posedge reset) begin if (reset == 1) begin first_access <= 0; end else begin if (go == 1) begin first_access <= 1; end else if ((first_access == 1) & (address_increment_enable == 1)) begin first_access <= 0; end end end // this register is used to determine if the first word boundary will be reached always @ (posedge clk or posedge reset) begin if (reset) begin first_word_boundary_not_reached_d1 <= 0; end else if (go == 1) begin first_word_boundary_not_reached_d1 <= first_word_boundary_not_reached; end end // master length logic, this will typically be the critical path followed by the FIFO always @ (posedge clk or posedge reset) begin if (reset) begin length_counter <= 0; end else begin if (length_sync_reset == 1) begin length_counter <= 0; end else if (go == 1) begin length_counter <= descriptor_length[LENGTH_WIDTH-1:0]; end else if (address_increment_enable == 1) begin length_counter <= length_counter - bytes_to_transfer; // not using address_increment because stride might be enabled end end end // the pending reads counter is used to determine how many outstanding reads are posted. This will be used to determine // if more reads can be posted based on the number of unused words in the FIFO. always @ (posedge clk or posedge reset) begin if (reset) begin pending_reads_counter <= 0; end else begin pending_reads_counter <= pending_reads_mux; end end always @ (posedge clk or posedge reset) begin if (reset) begin done_d1 <= 1; // master is done coming out of reset (need this to be set high so that done_strobe doesn't fire) end else begin done_d1 <= done; end end // this is the 'final done' condition, since reads are pipelined need to make sure they have all returned before the master is really done. always @ (posedge clk or posedge reset) begin if (reset) begin all_reads_returned_d1 <= 1; end else begin all_reads_returned_d1 <= all_reads_returned; end end always @ (posedge clk or posedge reset) begin if (reset == 1) begin flush <= 0; end else begin if ((pending_reads_counter == 0) & (flush == 1)) begin flush <= 0; end else if ((sw_reset_in == 1) & ((read_complete == 1) | (snk_command_ready == 1) | (master_read_reg == 0))) begin flush <= 1; // will be used to reset the length counter to 0 and flush out pending reads (by letting them return without buffering them) end end end always @ (posedge clk or posedge reset) begin if (reset) begin stopped <= 0; end else begin if ((sw_stop_in == 0) | (sw_reset_in == 1)) begin stopped <= 0; end else if ((sw_stop_in == 1) & ((read_complete == 1) | (snk_command_ready == 1) | (master_read_reg == 0))) begin stopped <= 1; end end end always @ (posedge clk or posedge reset) begin if (reset) begin snk_command_ready <= 1; // have to start ready to take commands end else begin if (go == 1) begin snk_command_ready <= 0; end else if ((src_response_ready == 1) & (src_response_valid == 1)) // need to make sure the response is popped before accepting more commands begin snk_command_ready <= 1; end end end always @ (posedge clk or posedge reset) begin if (reset) begin all_reads_returned_strobe_d1 <= 0; all_reads_returned_strobe_d2 <= 0; end else begin all_reads_returned_strobe_d1 <= all_reads_returned_strobe; all_reads_returned_strobe_d2 <= all_reads_returned_strobe_d1; end end always @ (posedge clk or posedge reset) begin if (reset) begin src_response_valid <= 0; end else begin if (flush == 1) begin src_response_valid <= 0; end else if (set_src_response_valid == 1) // all the reads have returned with MM to ST adapter latency taken into consideration begin src_response_valid <= 1; // will be set only once end else if ((src_response_valid == 1) & (src_response_ready == 1)) begin src_response_valid <= 0; // will be reset only once when the dispatcher captures the data end end end always @ (posedge clk or posedge reset) begin if (reset) begin master_read_reg <= 0; end else begin if ((done == 0) & (too_many_pending_reads == 0) & (sw_stop_in == 0) & (sw_reset_in == 0)) begin master_read_reg <= 1; end else if ((done == 1) | ((read_complete == 1) & ((too_many_pending_reads == 1) | (sw_stop_in == 1)))) begin master_read_reg <= 0; end end end /******************************************* END REGISTERS ************************************************/ /************************************** MODULE INSTANTIATIONS *********************************************/ // This block is pipelined and can't throttle the reads MM_to_ST_Adapter the_MM_to_ST_adapter ( .clk (clk), .reset (reset), .length (descriptor_length[LENGTH_WIDTH-1:0]), .length_counter (length_counter), .address (descriptor_address[ADDRESS_WIDTH-1:0]), .reads_pending (pending_reads_counter), .start (go), .readdata (master_readdata), .readdatavalid (master_readdatavalid), .fifo_data (MM_to_ST_adapter_dataout), .fifo_write (fifo_write), .fifo_empty (MM_to_ST_adapter_empty), .fifo_sop (MM_to_ST_adapter_sop), .fifo_eop (MM_to_ST_adapter_eop) ); defparam the_MM_to_ST_adapter.DATA_WIDTH = DATA_WIDTH; defparam the_MM_to_ST_adapter.LENGTH_WIDTH = LENGTH_WIDTH; defparam the_MM_to_ST_adapter.ADDRESS_WIDTH = ADDRESS_WIDTH; defparam the_MM_to_ST_adapter.BYTE_ADDRESS_WIDTH = BYTE_ENABLE_WIDTH_LOG2; defparam the_MM_to_ST_adapter.READS_PENDING_WIDTH = FIFO_DEPTH_LOG2 + 1; defparam the_MM_to_ST_adapter.EMPTY_WIDTH = NUMBER_OF_SYMBOLS_LOG2; defparam the_MM_to_ST_adapter.PACKET_SUPPORT = PACKET_ENABLE; defparam the_MM_to_ST_adapter.UNALIGNED_ACCESS_ENABLE = UNALIGNED_ACCESSES_ENABLE; defparam the_MM_to_ST_adapter.FULL_WORD_ACCESS_ONLY = ONLY_FULL_ACCESS_ENABLE; // buffered sop, eop, empty, data (in that order). sop, eop, and empty are only buffered when packet support is enabled scfifo the_master_to_st_fifo ( .aclr (reset), .clock (clk), .data (fifo_write_data), .full (fifo_full), .empty (fifo_empty), .usedw (fifo_used), .q (fifo_read_data), .rdreq (fifo_read), .wrreq (fifo_write) ); defparam the_master_to_st_fifo.lpm_width = FIFO_WIDTH; defparam the_master_to_st_fifo.lpm_numwords = FIFO_DEPTH; defparam the_master_to_st_fifo.lpm_widthu = FIFO_DEPTH_LOG2; defparam the_master_to_st_fifo.lpm_showahead = "ON"; // slower but doesn't require complex control logic to time with waitrequest defparam the_master_to_st_fifo.use_eab = (FIFO_USE_MEMORY == 1)? "ON" : "OFF"; defparam the_master_to_st_fifo.add_ram_output_register = (FIFO_SPEED_OPTIMIZATION == 1)? "ON" : "OFF"; defparam the_master_to_st_fifo.underflow_checking = "OFF"; defparam the_master_to_st_fifo.overflow_checking = "OFF"; // burst block that takes the length and short access enables and forms a burst count based on them. If any of the short access bits are asserted the block will default to a burst count of 1 read_burst_control the_read_burst_control ( .address (master_address), .length (length_counter), .maximum_burst_count (maximum_burst_count), .short_first_access_enable (short_first_access_enable), .short_last_access_enable (short_last_access_enable), .short_first_and_last_access_enable (short_first_and_last_access_enable), .burst_count (master_burstcount) ); defparam the_read_burst_control.BURST_ENABLE = BURST_ENABLE; defparam the_read_burst_control.BURST_COUNT_WIDTH = MAX_BURST_COUNT_WIDTH; defparam the_read_burst_control.WORD_SIZE_LOG2 = (DATA_WIDTH == 8)? 0 : BYTE_ENABLE_WIDTH_LOG2; // need to make sure log2(word size) is 0 instead of 1 here when the data width is 8 bits defparam the_read_burst_control.ADDRESS_WIDTH = ADDRESS_WIDTH; defparam the_read_burst_control.LENGTH_WIDTH = LENGTH_WIDTH; defparam the_read_burst_control.BURST_WRAPPING_SUPPORT = BURST_WRAPPING_SUPPORT; /************************************ END MODULE INSTANTIATIONS *******************************************/ /******************************** CONTROL AND COMBINATIONAL SIGNALS ***************************************/ // breakout the descriptor information into more manageable names assign descriptor_address = {snk_command_data[140:109], snk_command_data[31:0]}; // 64-bit addressing support assign descriptor_length = snk_command_data[63:32]; assign descriptor_channel = snk_command_data[71:64]; assign descriptor_generate_sop = snk_command_data[72]; assign descriptor_generate_eop = snk_command_data[73]; assign descriptor_programmable_burst_count = snk_command_data[83:76]; assign descriptor_stride = snk_command_data[99:84]; assign descriptor_error = snk_command_data[107:100]; assign descriptor_early_done_enable = snk_command_data[108]; assign sw_stop_in = snk_command_data[74]; assign sw_reset_in = snk_command_data[75]; assign stride_amount = (STRIDE_ENABLE == 1)? stride_d1[STRIDE_WIDTH-1:0] : FIXED_STRIDE; // hardcoding to FIXED_STRIDE when stride capabilities are disabled assign maximum_burst_count = (PROGRAMMABLE_BURST_ENABLE == 1)? programmable_burst_count_d1 : MAX_BURST_COUNT; // swap the bytes if big endian is enabled generate if (BIG_ENDIAN_ACCESS == 1) begin genvar j; for(j=0; j < DATA_WIDTH; j = j + 8) begin: byte_swap assign MM_to_ST_adapter_dataout_rearranged[j +8 -1: j] = MM_to_ST_adapter_dataout[DATA_WIDTH -j -1: DATA_WIDTH -j - 8]; end end else begin assign MM_to_ST_adapter_dataout_rearranged = MM_to_ST_adapter_dataout; end endgenerate assign masked_sop = MM_to_ST_adapter_sop & generate_sop_d1; assign masked_eop = MM_to_ST_adapter_eop & generate_eop_d1; assign fifo_write_data = {error_d1, channel_d1, masked_sop, masked_eop, ((masked_eop == 1)? MM_to_ST_adapter_empty : {NUMBER_OF_SYMBOLS_LOG2{1'b0}} ), MM_to_ST_adapter_dataout_rearranged}; // Avalon-ST is network order (a.k.a. big endian) so we need to reverse the symbols before sending them to the data stream generate genvar i; for(i = 0; i < DATA_WIDTH; i = i + SYMBOL_WIDTH) // the data width is always a multiple of the symbol width begin: symbol_swap assign src_data[i +SYMBOL_WIDTH -1: i] = fifo_read_data[DATA_WIDTH -i -1: DATA_WIDTH -i - SYMBOL_WIDTH]; end endgenerate assign src_empty = (PACKET_ENABLE == 1)? fifo_read_data[(DATA_WIDTH + NUMBER_OF_SYMBOLS_LOG2 - 1) : DATA_WIDTH] : 0; assign src_eop = (PACKET_ENABLE == 1)? fifo_read_data[DATA_WIDTH + NUMBER_OF_SYMBOLS_LOG2] : 0; assign src_sop = (PACKET_ENABLE == 1)? fifo_read_data[DATA_WIDTH + NUMBER_OF_SYMBOLS_LOG2 + 1] : 0; assign src_channel = (CHANNEL_ENABLE == 1)? fifo_read_data[(DATA_WIDTH + NUMBER_OF_SYMBOLS_LOG2 + ERROR_WIDTH + 1): (DATA_WIDTH + NUMBER_OF_SYMBOLS_LOG2 + 2)] : 0; assign src_error = (ERROR_ENABLE == 1)? fifo_read_data[(FIFO_WIDTH-1):(DATA_WIDTH + NUMBER_OF_SYMBOLS_LOG2 + ERROR_WIDTH + 2)] : 0; assign short_first_access_size = BYTE_ENABLE_WIDTH - (address_counter & LSB_MASK); assign short_last_access_size = length_counter & LSB_MASK; assign short_first_and_last_access_size = length_counter & LSB_MASK; /* special case transfer enables and counter increment values (address and length counter) short_first_access_enable is for transfers that start unaligned but reach the next word boundary short_last_access_enable is for transfers that are not the first transfer but don't end on a word boundary short_first_and_last_access_enable is for transfers that start and end with a single transfer and don't end on a word boundary (aligned or unaligned) */ generate if (UNALIGNED_ACCESSES_ENABLE == 1) begin assign short_first_access_enable = ((address_counter & LSB_MASK) != 0) & (first_access == 1) & (first_word_boundary_not_reached_d1 == 0); assign short_last_access_enable = (first_access == 0) & (length_counter < BYTE_ENABLE_WIDTH); assign short_first_and_last_access_enable = (first_access == 1) & (first_word_boundary_not_reached_d1 == 1); assign bytes_to_transfer = bytes_to_transfer_mux; assign address_increment = bytes_to_transfer_mux; // can't use stride when unaligned accesses are enabled end else if (ONLY_FULL_ACCESS_ENABLE == 1) begin assign short_first_access_enable = 0; assign short_last_access_enable = 0; assign short_first_and_last_access_enable = 0; assign bytes_to_transfer = BYTE_ENABLE_WIDTH * master_burstcount; if (STRIDE_ENABLE == 1) begin assign address_increment = BYTE_ENABLE_WIDTH * stride_amount * master_burstcount; // stride must be a static '1' when bursting is enabled end else begin assign address_increment = BYTE_ENABLE_WIDTH * master_burstcount; // stride must be a static '1' when bursting is enabled end end else // must be aligned but can end with any number of bytes begin assign short_first_access_enable = 0; assign short_last_access_enable = length_counter < BYTE_ENABLE_WIDTH; // less than a word to transfer assign short_first_and_last_access_enable = 0; assign bytes_to_transfer = bytes_to_transfer_mux; if (STRIDE_ENABLE == 1) begin assign address_increment = BYTE_ENABLE_WIDTH * stride_amount * master_burstcount; // stride must be a static '1' when bursting is enabled end else begin assign address_increment = BYTE_ENABLE_WIDTH * master_burstcount; // stride must be a static '1' when bursting is enabled end end endgenerate // the burst count will be 1 for all short accesses always @ (short_first_access_enable or short_last_access_enable or short_first_and_last_access_enable or short_first_access_size or short_last_access_size or short_first_and_last_access_size or master_burstcount) begin case ({short_first_and_last_access_enable, short_last_access_enable, short_first_access_enable}) 3'b001: bytes_to_transfer_mux = short_first_access_size; 3'b010: bytes_to_transfer_mux = short_last_access_size; 3'b100: bytes_to_transfer_mux = short_first_and_last_access_size; default: bytes_to_transfer_mux = BYTE_ENABLE_WIDTH * master_burstcount; // this is the only time master_burstcount can be a value other than 1 endcase end always @ (master_readdatavalid or read_complete or pending_reads_counter or master_burstcount) begin case ({master_readdatavalid, read_complete}) 2'b00: pending_reads_mux = pending_reads_counter; // no read posted and no read data returned 2'b01: pending_reads_mux = (pending_reads_counter + master_burstcount); // read posted and no read data returned 2'b10: pending_reads_mux = (pending_reads_counter - 1'b1); // no read posted but read data returned 2'b11: pending_reads_mux = (pending_reads_counter + master_burstcount - 1'b1); // read posted and read data returned endcase end assign src_valid = (fifo_empty == 0); assign first_word_boundary_not_reached = (descriptor_length < BYTE_ENABLE_WIDTH) & // length is less than the word size (((descriptor_length & LSB_MASK) + (descriptor_address & LSB_MASK)) < BYTE_ENABLE_WIDTH); // start address + length doesn't reach the next word boundary assign go = (snk_command_valid == 1) & (snk_command_ready == 1); // go with be one cycle since done will be set to 0 on the next cycle (length will be non-zero) assign done = (length_counter == 0); // all reads are posted but the master is not done since there could be reads pending assign done_strobe = (done == 1) & (done_d1 == 0); assign fifo_read = (src_valid == 1) & (src_ready == 1); assign length_sync_reset = (flush == 1) & (pending_reads_counter == 0); // resetting the length counter will trigger the done condition assign too_many_pending_reads = (({fifo_full,fifo_used} + pending_reads_counter) > (FIFO_DEPTH - (maximum_burst_count << 1))); // making sure a full burst can be posted, using 2x maximum_burst_count since the read signal is pipelined and so this signal will be late using maximum_burst_count alone assign read_complete = (master_read == 1) & (master_waitrequest == 0); assign address_increment_enable = read_complete; assign master_byteenable = {BYTE_ENABLE_WIDTH{1'b1}}; // master always asserts all byte enables and filters the data as it comes in (may lead to destructive reads in some cases) generate if (DATA_WIDTH > 8) begin assign master_address = address_counter & { {(ADDRESS_WIDTH-BYTE_ENABLE_WIDTH_LOG2){1'b1}}, {BYTE_ENABLE_WIDTH_LOG2{1'b0}} }; // masking LSBs (byte offsets) since the address counter might not be aligned for the first transfer end else begin assign master_address = address_counter; // don't need to mask any bits as the address will only advance one byte at a time end endgenerate assign master_read = master_read_reg & (done == 0); // need to mask the read with done so that it doesn't issue one extra read at the end assign all_reads_returned = (done == 1) & (pending_reads_counter == 0); assign all_reads_returned_strobe = (all_reads_returned == 1) & (all_reads_returned_d1 == 0); // for now the done and early done strobes are the same. Both will be triggered when the last data returns generate if (UNALIGNED_ACCESSES_ENABLE == 1) // need to use the delayed strobe since there are two stages of pipelining in the MM to ST adapter begin assign src_response_data = {{252{1'b0}}, all_reads_returned_strobe_d2, done_strobe, stopped, flush}; // 252 zeros: done strobe: early done strobe: stop state: reset delayed end else begin assign src_response_data = {{252{1'b0}}, all_reads_returned_strobe, done_strobe, stopped, flush}; // 252 zeros: done strobe: early done strobe: stop state: reset delayed end endgenerate assign set_src_response_valid = (UNALIGNED_ACCESSES_ENABLE == 1)? all_reads_returned_strobe_d2 : // all the reads have returned with MM to ST adapter latency taken into consideration (early_done_enable_d1 == 1)? done_strobe : all_reads_returned_strobe; // when early done is enabled then the done strobe is sufficient to trigger the next command can enter, otherwise need to wait for the pending reads to return /****************************** END CONTROL AND COMBINATIONAL SIGNALS *************************************/ endmodule
module read_master ( clk, reset, // descriptor commands sink port snk_command_data, snk_command_valid, snk_command_ready, // response source port src_response_data, src_response_valid, src_response_ready, // data path sink port src_data, src_valid, src_ready, src_sop, src_eop, src_empty, src_error, src_channel, // data path master port master_address, master_read, master_byteenable, master_readdata, master_waitrequest, master_readdatavalid, master_burstcount ); parameter UNALIGNED_ACCESSES_ENABLE = 0; // when enabled allows transfers to begin from off word boundaries parameter ONLY_FULL_ACCESS_ENABLE = 0; // when enabled allows transfers to end with partial access, master achieve a much higher fmax when this is enabled parameter STRIDE_ENABLE = 0; // stride support can only be enabled when unaligned accesses is disabled parameter STRIDE_WIDTH = 1; // when stride support is enabled this value controls the rate in which the address increases (in words), the stride width + log2(byte enable width) + 1 cannot exceed address width parameter PACKET_ENABLE = 0; parameter ERROR_ENABLE = 0; parameter ERROR_WIDTH = 8; // must be between 1-8, this will only be enabled in the GUI when error enable is turned on parameter CHANNEL_ENABLE = 0; parameter CHANNEL_WIDTH = 8; // must be between 1-8, this will only be enabled in the GUI when the channel enable is turned on parameter DATA_WIDTH = 32; parameter BYTE_ENABLE_WIDTH = 4; // set by the .tcl file (hidden in GUI) parameter BYTE_ENABLE_WIDTH_LOG2 = 2; // set by the .tcl file (hidden in GUI) parameter ADDRESS_WIDTH = 32; // set in the .tcl file (hidden in GUI) by the address span of the master parameter LENGTH_WIDTH = 32; // GUI setting with warning if ADDRESS_WIDTH < LENGTH_WIDTH (waste of logic for the length counter) parameter FIFO_DEPTH = 32; parameter FIFO_DEPTH_LOG2 = 5; // set by the .tcl file (hidden in GUI) parameter FIFO_SPEED_OPTIMIZATION = 1; // set by the .tcl file (hidden in GUI) The default will be on since it only impacts the latency of the entire transfer by 1 clock cycle and adds very little additional logic. parameter SYMBOL_WIDTH = 8; // set in the .tcl file (hidden in GUI) parameter NUMBER_OF_SYMBOLS = 4; // set in the .tcl file (hidden in GUI) parameter NUMBER_OF_SYMBOLS_LOG2 = 2; // set by the .tcl file (hidden in GUI) parameter BURST_ENABLE = 0; // when enabled stride must be disabled, 1 to enable, 0 to disable parameter MAX_BURST_COUNT = 2; // must be a power of 2, when BURST_ENABLE = 0 set maximum_burst_count to 1 (will be automatically done by .tcl file) parameter MAX_BURST_COUNT_WIDTH = 2; // set by the .tcl file (hidden in GUI) = log2(maximum_burst_count) + 1 parameter PROGRAMMABLE_BURST_ENABLE = 0; // when enabled the user must set the burst count, if 0 is set then the value "maximum_burst_count" will be used instead parameter BURST_WRAPPING_SUPPORT = 1; // will only be used when bursting is enabled. This cannot be enabled with programmable burst capabilities. Enabling it will make sure the master gets back into burst alignment (data width in bytes * maximum burst count alignment) localparam FIFO_USE_MEMORY = 1; // set to 0 to use LEs instead, not exposed since FPGAs have a lot of memory these days localparam BIG_ENDIAN_ACCESS = 0; // hiding this since it can blow your foot off if you are not careful. It's big endian with respect to the write master width and not necessarily to the width of the data type used by a host CPU. // handy mask for seperating the word address from the byte address bits, so for 32 bit masters this mask is 0x3, for 64 bit masters it'll be 0x7 localparam LSB_MASK = {BYTE_ENABLE_WIDTH_LOG2{1'b1}}; // when packet data is supported then we need to buffer the empty, eop, sop, error, and channel bits localparam FIFO_WIDTH = DATA_WIDTH + NUMBER_OF_SYMBOLS_LOG2 + 2 + ERROR_WIDTH + CHANNEL_WIDTH; localparam ADDRESS_INCREMENT_WIDTH = (BYTE_ENABLE_WIDTH_LOG2 + MAX_BURST_COUNT_WIDTH + STRIDE_WIDTH); localparam FIXED_STRIDE = 1'b1; // default stride distance used when stride is disabled. 1 means increment the address by a word (i.e. sequential transfer) input clk; input reset; // descriptor commands sink port input [255:0] snk_command_data; input snk_command_valid; output reg snk_command_ready; // response source port output wire [255:0] src_response_data; output reg src_response_valid; input src_response_ready; // data path source port output wire [DATA_WIDTH-1:0] src_data; output wire src_valid; input src_ready; output wire src_sop; output wire src_eop; output wire [NUMBER_OF_SYMBOLS_LOG2-1:0] src_empty; output wire [ERROR_WIDTH-1:0] src_error; output wire [CHANNEL_WIDTH-1:0] src_channel; // master inputs and outputs input master_waitrequest; output wire [ADDRESS_WIDTH-1:0] master_address; output wire master_read; output wire [BYTE_ENABLE_WIDTH-1:0] master_byteenable; input [DATA_WIDTH-1:0] master_readdata; input master_readdatavalid; output wire [MAX_BURST_COUNT_WIDTH-1:0] master_burstcount; // internal signals wire [63:0] descriptor_address; wire [31:0] descriptor_length; wire [15:0] descriptor_stride; wire [7:0] descriptor_channel; wire descriptor_generate_sop; wire descriptor_generate_eop; wire [7:0] descriptor_error; wire [7:0] descriptor_programmable_burst_count; wire descriptor_early_done_enable; wire sw_stop_in; wire sw_reset_in; reg early_done_enable_d1; reg [ERROR_WIDTH-1:0] error_d1; reg [MAX_BURST_COUNT_WIDTH-1:0] programmable_burst_count_d1; wire [MAX_BURST_COUNT_WIDTH-1:0] maximum_burst_count; reg generate_sop_d1; reg generate_eop_d1; reg [ADDRESS_WIDTH-1:0] address_counter; reg [LENGTH_WIDTH-1:0] length_counter; reg [CHANNEL_WIDTH-1:0] channel_d1; reg [STRIDE_WIDTH-1:0] stride_d1; wire [STRIDE_WIDTH-1:0] stride_amount; // either set to be stride_d1 or hardcoded to 1 depending on the parameterization reg [BYTE_ENABLE_WIDTH_LOG2-1:0] start_byte_address; // used to determine how far out of alignment the master starts reg first_access; // used to determine if the first read is occuring wire first_word_boundary_not_reached; // set when the first access doesn't reach the next word boundary reg first_word_boundary_not_reached_d1; reg [FIFO_DEPTH_LOG2:0] pending_reads_counter; reg [FIFO_DEPTH_LOG2:0] pending_reads_mux; wire [FIFO_WIDTH-1:0] fifo_write_data; wire [FIFO_WIDTH-1:0] fifo_read_data; wire fifo_write; wire fifo_read; wire fifo_empty; wire fifo_full; wire [FIFO_DEPTH_LOG2-1:0] fifo_used; wire too_many_pending_reads; wire read_complete; // handy signal for determining when a read has occured and completed wire address_increment_enable; wire [ADDRESS_INCREMENT_WIDTH-1:0] address_increment; // amount of bytes to increment the address wire [ADDRESS_INCREMENT_WIDTH-1:0] bytes_to_transfer; wire short_first_access_enable; // when starting unaligned and the amount of data to transfer reaches the next word boundary wire short_last_access_enable; // when address is aligned (can be an unaligned buffer transfer) but the amount of data doesn't reach the next word boundary wire short_first_and_last_access_enable; // when starting unaligned and the amount of data to transfer doesn't reach the next word boundary wire [ADDRESS_INCREMENT_WIDTH-1:0] short_first_access_size; wire [ADDRESS_INCREMENT_WIDTH-1:0] short_last_access_size; wire [ADDRESS_INCREMENT_WIDTH-1:0] short_first_and_last_access_size; reg [ADDRESS_INCREMENT_WIDTH-1:0] bytes_to_transfer_mux; wire go; wire done; // asserted when last read is issued reg done_d1; wire done_strobe; wire all_reads_returned; // asserted when last read returns reg all_reads_returned_d1; wire all_reads_returned_strobe; reg all_reads_returned_strobe_d1; reg all_reads_returned_strobe_d2; // used to trigger src_response_ready later than when the last read returns since the MM to ST has two pipeline stages wire [DATA_WIDTH-1:0] MM_to_ST_adapter_dataout; wire [DATA_WIDTH-1:0] MM_to_ST_adapter_dataout_rearranged; wire MM_to_ST_adapter_sop; wire MM_to_ST_adapter_eop; wire [NUMBER_OF_SYMBOLS_LOG2-1:0] MM_to_ST_adapter_empty; wire masked_sop; wire masked_eop; reg flush; reg stopped; wire length_sync_reset; wire set_src_response_valid; reg master_read_reg; /********************************************* REGISTERS **************************************************/ // registering descriptor information always @ (posedge clk or posedge reset) begin if (reset) begin error_d1 <= 0; generate_sop_d1 <= 0; generate_eop_d1 <= 0; channel_d1 <= 0; stride_d1 <= 0; programmable_burst_count_d1 <= 0; early_done_enable_d1 <= 0; end else if (go == 1) begin error_d1 <= descriptor_error[ERROR_WIDTH-1:0]; generate_sop_d1 <= descriptor_generate_sop; generate_eop_d1 <= descriptor_generate_eop; channel_d1 <= descriptor_channel[CHANNEL_WIDTH-1:0]; stride_d1 <= descriptor_stride[STRIDE_WIDTH-1:0]; programmable_burst_count_d1 <= (descriptor_programmable_burst_count == 0)? MAX_BURST_COUNT : descriptor_programmable_burst_count; early_done_enable_d1 <= ((UNALIGNED_ACCESSES_ENABLE == 1) | (PACKET_ENABLE == 1))? 0 : descriptor_early_done_enable; // early done cannot be used when unaligned data or packet support is enabled end end // master word increment counter always @ (posedge clk or posedge reset) begin if (reset) begin address_counter <= 0; end else begin if (go == 1) begin address_counter <= descriptor_address[ADDRESS_WIDTH-1:0]; end else if (address_increment_enable == 1) begin address_counter <= address_counter + address_increment; end end end // master byte address, used to determine how far out of alignment the master began transfering data always @ (posedge clk or posedge reset) begin if (reset) begin start_byte_address <= 0; end else if (go == 1) begin start_byte_address <= descriptor_address[BYTE_ENABLE_WIDTH_LOG2-1:0]; end end // first_access will be asserted only for the first read of a transaction, this will be used to determine what value will be used to increment the counters always @ (posedge clk or posedge reset) begin if (reset == 1) begin first_access <= 0; end else begin if (go == 1) begin first_access <= 1; end else if ((first_access == 1) & (address_increment_enable == 1)) begin first_access <= 0; end end end // this register is used to determine if the first word boundary will be reached always @ (posedge clk or posedge reset) begin if (reset) begin first_word_boundary_not_reached_d1 <= 0; end else if (go == 1) begin first_word_boundary_not_reached_d1 <= first_word_boundary_not_reached; end end // master length logic, this will typically be the critical path followed by the FIFO always @ (posedge clk or posedge reset) begin if (reset) begin length_counter <= 0; end else begin if (length_sync_reset == 1) begin length_counter <= 0; end else if (go == 1) begin length_counter <= descriptor_length[LENGTH_WIDTH-1:0]; end else if (address_increment_enable == 1) begin length_counter <= length_counter - bytes_to_transfer; // not using address_increment because stride might be enabled end end end // the pending reads counter is used to determine how many outstanding reads are posted. This will be used to determine // if more reads can be posted based on the number of unused words in the FIFO. always @ (posedge clk or posedge reset) begin if (reset) begin pending_reads_counter <= 0; end else begin pending_reads_counter <= pending_reads_mux; end end always @ (posedge clk or posedge reset) begin if (reset) begin done_d1 <= 1; // master is done coming out of reset (need this to be set high so that done_strobe doesn't fire) end else begin done_d1 <= done; end end // this is the 'final done' condition, since reads are pipelined need to make sure they have all returned before the master is really done. always @ (posedge clk or posedge reset) begin if (reset) begin all_reads_returned_d1 <= 1; end else begin all_reads_returned_d1 <= all_reads_returned; end end always @ (posedge clk or posedge reset) begin if (reset == 1) begin flush <= 0; end else begin if ((pending_reads_counter == 0) & (flush == 1)) begin flush <= 0; end else if ((sw_reset_in == 1) & ((read_complete == 1) | (snk_command_ready == 1) | (master_read_reg == 0))) begin flush <= 1; // will be used to reset the length counter to 0 and flush out pending reads (by letting them return without buffering them) end end end always @ (posedge clk or posedge reset) begin if (reset) begin stopped <= 0; end else begin if ((sw_stop_in == 0) | (sw_reset_in == 1)) begin stopped <= 0; end else if ((sw_stop_in == 1) & ((read_complete == 1) | (snk_command_ready == 1) | (master_read_reg == 0))) begin stopped <= 1; end end end always @ (posedge clk or posedge reset) begin if (reset) begin snk_command_ready <= 1; // have to start ready to take commands end else begin if (go == 1) begin snk_command_ready <= 0; end else if ((src_response_ready == 1) & (src_response_valid == 1)) // need to make sure the response is popped before accepting more commands begin snk_command_ready <= 1; end end end always @ (posedge clk or posedge reset) begin if (reset) begin all_reads_returned_strobe_d1 <= 0; all_reads_returned_strobe_d2 <= 0; end else begin all_reads_returned_strobe_d1 <= all_reads_returned_strobe; all_reads_returned_strobe_d2 <= all_reads_returned_strobe_d1; end end always @ (posedge clk or posedge reset) begin if (reset) begin src_response_valid <= 0; end else begin if (flush == 1) begin src_response_valid <= 0; end else if (set_src_response_valid == 1) // all the reads have returned with MM to ST adapter latency taken into consideration begin src_response_valid <= 1; // will be set only once end else if ((src_response_valid == 1) & (src_response_ready == 1)) begin src_response_valid <= 0; // will be reset only once when the dispatcher captures the data end end end always @ (posedge clk or posedge reset) begin if (reset) begin master_read_reg <= 0; end else begin if ((done == 0) & (too_many_pending_reads == 0) & (sw_stop_in == 0) & (sw_reset_in == 0)) begin master_read_reg <= 1; end else if ((done == 1) | ((read_complete == 1) & ((too_many_pending_reads == 1) | (sw_stop_in == 1)))) begin master_read_reg <= 0; end end end /******************************************* END REGISTERS ************************************************/ /************************************** MODULE INSTANTIATIONS *********************************************/ // This block is pipelined and can't throttle the reads MM_to_ST_Adapter the_MM_to_ST_adapter ( .clk (clk), .reset (reset), .length (descriptor_length[LENGTH_WIDTH-1:0]), .length_counter (length_counter), .address (descriptor_address[ADDRESS_WIDTH-1:0]), .reads_pending (pending_reads_counter), .start (go), .readdata (master_readdata), .readdatavalid (master_readdatavalid), .fifo_data (MM_to_ST_adapter_dataout), .fifo_write (fifo_write), .fifo_empty (MM_to_ST_adapter_empty), .fifo_sop (MM_to_ST_adapter_sop), .fifo_eop (MM_to_ST_adapter_eop) ); defparam the_MM_to_ST_adapter.DATA_WIDTH = DATA_WIDTH; defparam the_MM_to_ST_adapter.LENGTH_WIDTH = LENGTH_WIDTH; defparam the_MM_to_ST_adapter.ADDRESS_WIDTH = ADDRESS_WIDTH; defparam the_MM_to_ST_adapter.BYTE_ADDRESS_WIDTH = BYTE_ENABLE_WIDTH_LOG2; defparam the_MM_to_ST_adapter.READS_PENDING_WIDTH = FIFO_DEPTH_LOG2 + 1; defparam the_MM_to_ST_adapter.EMPTY_WIDTH = NUMBER_OF_SYMBOLS_LOG2; defparam the_MM_to_ST_adapter.PACKET_SUPPORT = PACKET_ENABLE; defparam the_MM_to_ST_adapter.UNALIGNED_ACCESS_ENABLE = UNALIGNED_ACCESSES_ENABLE; defparam the_MM_to_ST_adapter.FULL_WORD_ACCESS_ONLY = ONLY_FULL_ACCESS_ENABLE; // buffered sop, eop, empty, data (in that order). sop, eop, and empty are only buffered when packet support is enabled scfifo the_master_to_st_fifo ( .aclr (reset), .clock (clk), .data (fifo_write_data), .full (fifo_full), .empty (fifo_empty), .usedw (fifo_used), .q (fifo_read_data), .rdreq (fifo_read), .wrreq (fifo_write) ); defparam the_master_to_st_fifo.lpm_width = FIFO_WIDTH; defparam the_master_to_st_fifo.lpm_numwords = FIFO_DEPTH; defparam the_master_to_st_fifo.lpm_widthu = FIFO_DEPTH_LOG2; defparam the_master_to_st_fifo.lpm_showahead = "ON"; // slower but doesn't require complex control logic to time with waitrequest defparam the_master_to_st_fifo.use_eab = (FIFO_USE_MEMORY == 1)? "ON" : "OFF"; defparam the_master_to_st_fifo.add_ram_output_register = (FIFO_SPEED_OPTIMIZATION == 1)? "ON" : "OFF"; defparam the_master_to_st_fifo.underflow_checking = "OFF"; defparam the_master_to_st_fifo.overflow_checking = "OFF"; // burst block that takes the length and short access enables and forms a burst count based on them. If any of the short access bits are asserted the block will default to a burst count of 1 read_burst_control the_read_burst_control ( .address (master_address), .length (length_counter), .maximum_burst_count (maximum_burst_count), .short_first_access_enable (short_first_access_enable), .short_last_access_enable (short_last_access_enable), .short_first_and_last_access_enable (short_first_and_last_access_enable), .burst_count (master_burstcount) ); defparam the_read_burst_control.BURST_ENABLE = BURST_ENABLE; defparam the_read_burst_control.BURST_COUNT_WIDTH = MAX_BURST_COUNT_WIDTH; defparam the_read_burst_control.WORD_SIZE_LOG2 = (DATA_WIDTH == 8)? 0 : BYTE_ENABLE_WIDTH_LOG2; // need to make sure log2(word size) is 0 instead of 1 here when the data width is 8 bits defparam the_read_burst_control.ADDRESS_WIDTH = ADDRESS_WIDTH; defparam the_read_burst_control.LENGTH_WIDTH = LENGTH_WIDTH; defparam the_read_burst_control.BURST_WRAPPING_SUPPORT = BURST_WRAPPING_SUPPORT; /************************************ END MODULE INSTANTIATIONS *******************************************/ /******************************** CONTROL AND COMBINATIONAL SIGNALS ***************************************/ // breakout the descriptor information into more manageable names assign descriptor_address = {snk_command_data[140:109], snk_command_data[31:0]}; // 64-bit addressing support assign descriptor_length = snk_command_data[63:32]; assign descriptor_channel = snk_command_data[71:64]; assign descriptor_generate_sop = snk_command_data[72]; assign descriptor_generate_eop = snk_command_data[73]; assign descriptor_programmable_burst_count = snk_command_data[83:76]; assign descriptor_stride = snk_command_data[99:84]; assign descriptor_error = snk_command_data[107:100]; assign descriptor_early_done_enable = snk_command_data[108]; assign sw_stop_in = snk_command_data[74]; assign sw_reset_in = snk_command_data[75]; assign stride_amount = (STRIDE_ENABLE == 1)? stride_d1[STRIDE_WIDTH-1:0] : FIXED_STRIDE; // hardcoding to FIXED_STRIDE when stride capabilities are disabled assign maximum_burst_count = (PROGRAMMABLE_BURST_ENABLE == 1)? programmable_burst_count_d1 : MAX_BURST_COUNT; // swap the bytes if big endian is enabled generate if (BIG_ENDIAN_ACCESS == 1) begin genvar j; for(j=0; j < DATA_WIDTH; j = j + 8) begin: byte_swap assign MM_to_ST_adapter_dataout_rearranged[j +8 -1: j] = MM_to_ST_adapter_dataout[DATA_WIDTH -j -1: DATA_WIDTH -j - 8]; end end else begin assign MM_to_ST_adapter_dataout_rearranged = MM_to_ST_adapter_dataout; end endgenerate assign masked_sop = MM_to_ST_adapter_sop & generate_sop_d1; assign masked_eop = MM_to_ST_adapter_eop & generate_eop_d1; assign fifo_write_data = {error_d1, channel_d1, masked_sop, masked_eop, ((masked_eop == 1)? MM_to_ST_adapter_empty : {NUMBER_OF_SYMBOLS_LOG2{1'b0}} ), MM_to_ST_adapter_dataout_rearranged}; // Avalon-ST is network order (a.k.a. big endian) so we need to reverse the symbols before sending them to the data stream generate genvar i; for(i = 0; i < DATA_WIDTH; i = i + SYMBOL_WIDTH) // the data width is always a multiple of the symbol width begin: symbol_swap assign src_data[i +SYMBOL_WIDTH -1: i] = fifo_read_data[DATA_WIDTH -i -1: DATA_WIDTH -i - SYMBOL_WIDTH]; end endgenerate assign src_empty = (PACKET_ENABLE == 1)? fifo_read_data[(DATA_WIDTH + NUMBER_OF_SYMBOLS_LOG2 - 1) : DATA_WIDTH] : 0; assign src_eop = (PACKET_ENABLE == 1)? fifo_read_data[DATA_WIDTH + NUMBER_OF_SYMBOLS_LOG2] : 0; assign src_sop = (PACKET_ENABLE == 1)? fifo_read_data[DATA_WIDTH + NUMBER_OF_SYMBOLS_LOG2 + 1] : 0; assign src_channel = (CHANNEL_ENABLE == 1)? fifo_read_data[(DATA_WIDTH + NUMBER_OF_SYMBOLS_LOG2 + ERROR_WIDTH + 1): (DATA_WIDTH + NUMBER_OF_SYMBOLS_LOG2 + 2)] : 0; assign src_error = (ERROR_ENABLE == 1)? fifo_read_data[(FIFO_WIDTH-1):(DATA_WIDTH + NUMBER_OF_SYMBOLS_LOG2 + ERROR_WIDTH + 2)] : 0; assign short_first_access_size = BYTE_ENABLE_WIDTH - (address_counter & LSB_MASK); assign short_last_access_size = length_counter & LSB_MASK; assign short_first_and_last_access_size = length_counter & LSB_MASK; /* special case transfer enables and counter increment values (address and length counter) short_first_access_enable is for transfers that start unaligned but reach the next word boundary short_last_access_enable is for transfers that are not the first transfer but don't end on a word boundary short_first_and_last_access_enable is for transfers that start and end with a single transfer and don't end on a word boundary (aligned or unaligned) */ generate if (UNALIGNED_ACCESSES_ENABLE == 1) begin assign short_first_access_enable = ((address_counter & LSB_MASK) != 0) & (first_access == 1) & (first_word_boundary_not_reached_d1 == 0); assign short_last_access_enable = (first_access == 0) & (length_counter < BYTE_ENABLE_WIDTH); assign short_first_and_last_access_enable = (first_access == 1) & (first_word_boundary_not_reached_d1 == 1); assign bytes_to_transfer = bytes_to_transfer_mux; assign address_increment = bytes_to_transfer_mux; // can't use stride when unaligned accesses are enabled end else if (ONLY_FULL_ACCESS_ENABLE == 1) begin assign short_first_access_enable = 0; assign short_last_access_enable = 0; assign short_first_and_last_access_enable = 0; assign bytes_to_transfer = BYTE_ENABLE_WIDTH * master_burstcount; if (STRIDE_ENABLE == 1) begin assign address_increment = BYTE_ENABLE_WIDTH * stride_amount * master_burstcount; // stride must be a static '1' when bursting is enabled end else begin assign address_increment = BYTE_ENABLE_WIDTH * master_burstcount; // stride must be a static '1' when bursting is enabled end end else // must be aligned but can end with any number of bytes begin assign short_first_access_enable = 0; assign short_last_access_enable = length_counter < BYTE_ENABLE_WIDTH; // less than a word to transfer assign short_first_and_last_access_enable = 0; assign bytes_to_transfer = bytes_to_transfer_mux; if (STRIDE_ENABLE == 1) begin assign address_increment = BYTE_ENABLE_WIDTH * stride_amount * master_burstcount; // stride must be a static '1' when bursting is enabled end else begin assign address_increment = BYTE_ENABLE_WIDTH * master_burstcount; // stride must be a static '1' when bursting is enabled end end endgenerate // the burst count will be 1 for all short accesses always @ (short_first_access_enable or short_last_access_enable or short_first_and_last_access_enable or short_first_access_size or short_last_access_size or short_first_and_last_access_size or master_burstcount) begin case ({short_first_and_last_access_enable, short_last_access_enable, short_first_access_enable}) 3'b001: bytes_to_transfer_mux = short_first_access_size; 3'b010: bytes_to_transfer_mux = short_last_access_size; 3'b100: bytes_to_transfer_mux = short_first_and_last_access_size; default: bytes_to_transfer_mux = BYTE_ENABLE_WIDTH * master_burstcount; // this is the only time master_burstcount can be a value other than 1 endcase end always @ (master_readdatavalid or read_complete or pending_reads_counter or master_burstcount) begin case ({master_readdatavalid, read_complete}) 2'b00: pending_reads_mux = pending_reads_counter; // no read posted and no read data returned 2'b01: pending_reads_mux = (pending_reads_counter + master_burstcount); // read posted and no read data returned 2'b10: pending_reads_mux = (pending_reads_counter - 1'b1); // no read posted but read data returned 2'b11: pending_reads_mux = (pending_reads_counter + master_burstcount - 1'b1); // read posted and read data returned endcase end assign src_valid = (fifo_empty == 0); assign first_word_boundary_not_reached = (descriptor_length < BYTE_ENABLE_WIDTH) & // length is less than the word size (((descriptor_length & LSB_MASK) + (descriptor_address & LSB_MASK)) < BYTE_ENABLE_WIDTH); // start address + length doesn't reach the next word boundary assign go = (snk_command_valid == 1) & (snk_command_ready == 1); // go with be one cycle since done will be set to 0 on the next cycle (length will be non-zero) assign done = (length_counter == 0); // all reads are posted but the master is not done since there could be reads pending assign done_strobe = (done == 1) & (done_d1 == 0); assign fifo_read = (src_valid == 1) & (src_ready == 1); assign length_sync_reset = (flush == 1) & (pending_reads_counter == 0); // resetting the length counter will trigger the done condition assign too_many_pending_reads = (({fifo_full,fifo_used} + pending_reads_counter) > (FIFO_DEPTH - (maximum_burst_count << 1))); // making sure a full burst can be posted, using 2x maximum_burst_count since the read signal is pipelined and so this signal will be late using maximum_burst_count alone assign read_complete = (master_read == 1) & (master_waitrequest == 0); assign address_increment_enable = read_complete; assign master_byteenable = {BYTE_ENABLE_WIDTH{1'b1}}; // master always asserts all byte enables and filters the data as it comes in (may lead to destructive reads in some cases) generate if (DATA_WIDTH > 8) begin assign master_address = address_counter & { {(ADDRESS_WIDTH-BYTE_ENABLE_WIDTH_LOG2){1'b1}}, {BYTE_ENABLE_WIDTH_LOG2{1'b0}} }; // masking LSBs (byte offsets) since the address counter might not be aligned for the first transfer end else begin assign master_address = address_counter; // don't need to mask any bits as the address will only advance one byte at a time end endgenerate assign master_read = master_read_reg & (done == 0); // need to mask the read with done so that it doesn't issue one extra read at the end assign all_reads_returned = (done == 1) & (pending_reads_counter == 0); assign all_reads_returned_strobe = (all_reads_returned == 1) & (all_reads_returned_d1 == 0); // for now the done and early done strobes are the same. Both will be triggered when the last data returns generate if (UNALIGNED_ACCESSES_ENABLE == 1) // need to use the delayed strobe since there are two stages of pipelining in the MM to ST adapter begin assign src_response_data = {{252{1'b0}}, all_reads_returned_strobe_d2, done_strobe, stopped, flush}; // 252 zeros: done strobe: early done strobe: stop state: reset delayed end else begin assign src_response_data = {{252{1'b0}}, all_reads_returned_strobe, done_strobe, stopped, flush}; // 252 zeros: done strobe: early done strobe: stop state: reset delayed end endgenerate assign set_src_response_valid = (UNALIGNED_ACCESSES_ENABLE == 1)? all_reads_returned_strobe_d2 : // all the reads have returned with MM to ST adapter latency taken into consideration (early_done_enable_d1 == 1)? done_strobe : all_reads_returned_strobe; // when early done is enabled then the done strobe is sufficient to trigger the next command can enter, otherwise need to wait for the pending reads to return /****************************** END CONTROL AND COMBINATIONAL SIGNALS *************************************/ endmodule
module fifo_1c_1k ( data, wrreq, rdreq, rdclk, wrclk, aclr, q, rdfull, rdempty, rdusedw, wrfull, wrempty, wrusedw); parameter width = 32; parameter depth = 1024; //`define rd_req 0; // Set this to 0 for rd_ack, 1 for rd_req input [31:0] data; input wrreq; input rdreq; input rdclk; input wrclk; input aclr; output [31:0] q; output rdfull; output rdempty; output [9:0] rdusedw; output wrfull; output wrempty; output [9:0] wrusedw; reg [width-1:0] mem [0:depth-1]; reg [7:0] rdptr; reg [7:0] wrptr; `ifdef rd_req reg [width-1:0] q; `else wire [width-1:0] q; `endif reg [9:0] rdusedw; reg [9:0] wrusedw; integer i; always @( aclr) begin wrptr <= #1 0; rdptr <= #1 0; for(i=0;i<depth;i=i+1) mem[i] <= #1 0; end always @(posedge wrclk) if(wrreq) begin wrptr <= #1 wrptr+1; mem[wrptr] <= #1 data; end always @(posedge rdclk) if(rdreq) begin rdptr <= #1 rdptr+1; `ifdef rd_req q <= #1 mem[rdptr]; `endif end `ifdef rd_req `else assign q = mem[rdptr]; `endif // Fix these always @(posedge wrclk) wrusedw <= #1 wrptr - rdptr; always @(posedge rdclk) rdusedw <= #1 wrptr - rdptr; assign wrempty = (wrusedw == 0); assign wrfull = (wrusedw == depth-1); assign rdempty = (rdusedw == 0); assign rdfull = (rdusedw == depth-1); endmodule
module pll ( inclk0, c0); input inclk0; output c0; endmodule
module pll ( inclk0, c0); input inclk0; output c0; endmodule
module rx_chain_dual (input clock, input clock_2x, input reset, input enable, input wire [7:0] decim_rate, input sample_strobe, input decimator_strobe, input wire [31:0] freq0, input wire [15:0] i_in0, input wire [15:0] q_in0, output wire [15:0] i_out0, output wire [15:0] q_out0, input wire [31:0] freq1, input wire [15:0] i_in1, input wire [15:0] q_in1, output wire [15:0] i_out1, output wire [15:0] q_out1 ); wire [15:0] phase; wire [15:0] bb_i, bb_q; wire [15:0] i_in, q_in; wire [31:0] phase0; wire [31:0] phase1; reg [15:0] bb_i0, bb_q0; reg [15:0] bb_i1, bb_q1; // We want to time-share the CORDIC by double-clocking it phase_acc rx_phase_acc_0 (.clk(clock),.reset(reset),.enable(enable), .strobe(sample_strobe),.freq(freq0),.phase(phase0) ); phase_acc rx_phase_acc_1 (.clk(clock),.reset(reset),.enable(enable), .strobe(sample_strobe),.freq(freq1),.phase(phase1) ); assign phase = clock ? phase0[31:16] : phase1[31:16]; assign i_in = clock ? i_in0 : i_in1; assign q_in = clock ? q_in0 : q_in1; // This appears reversed because of the number of CORDIC stages always @(posedge clock_2x) if(clock) begin bb_i1 <= #1 bb_i; bb_q1 <= #1 bb_q; end else begin bb_i0 <= #1 bb_i; bb_q0 <= #1 bb_q; end cordic rx_cordic ( .clock(clock_2x),.reset(reset),.enable(enable), .xi(i_in),.yi(q_in),.zi(phase), .xo(bb_i),.yo(bb_q),.zo() ); cic_decim cic_decim_i_0 ( .clock(clock),.reset(reset),.enable(enable), .rate(decim_rate),.strobe_in(sample_strobe),.strobe_out(decimator_strobe), .signal_in(bb_i0),.signal_out(i_out0) ); cic_decim cic_decim_q_0 ( .clock(clock),.reset(reset),.enable(enable), .rate(decim_rate),.strobe_in(sample_strobe),.strobe_out(decimator_strobe), .signal_in(bb_q0),.signal_out(q_out0) ); cic_decim cic_decim_i_1 ( .clock(clock),.reset(reset),.enable(enable), .rate(decim_rate),.strobe_in(sample_strobe),.strobe_out(decimator_strobe), .signal_in(bb_i1),.signal_out(i_out1) ); cic_decim cic_decim_q_1 ( .clock(clock),.reset(reset),.enable(enable), .rate(decim_rate),.strobe_in(sample_strobe),.strobe_out(decimator_strobe), .signal_in(bb_q1),.signal_out(q_out1) ); endmodule
module rx_chain_dual (input clock, input clock_2x, input reset, input enable, input wire [7:0] decim_rate, input sample_strobe, input decimator_strobe, input wire [31:0] freq0, input wire [15:0] i_in0, input wire [15:0] q_in0, output wire [15:0] i_out0, output wire [15:0] q_out0, input wire [31:0] freq1, input wire [15:0] i_in1, input wire [15:0] q_in1, output wire [15:0] i_out1, output wire [15:0] q_out1 ); wire [15:0] phase; wire [15:0] bb_i, bb_q; wire [15:0] i_in, q_in; wire [31:0] phase0; wire [31:0] phase1; reg [15:0] bb_i0, bb_q0; reg [15:0] bb_i1, bb_q1; // We want to time-share the CORDIC by double-clocking it phase_acc rx_phase_acc_0 (.clk(clock),.reset(reset),.enable(enable), .strobe(sample_strobe),.freq(freq0),.phase(phase0) ); phase_acc rx_phase_acc_1 (.clk(clock),.reset(reset),.enable(enable), .strobe(sample_strobe),.freq(freq1),.phase(phase1) ); assign phase = clock ? phase0[31:16] : phase1[31:16]; assign i_in = clock ? i_in0 : i_in1; assign q_in = clock ? q_in0 : q_in1; // This appears reversed because of the number of CORDIC stages always @(posedge clock_2x) if(clock) begin bb_i1 <= #1 bb_i; bb_q1 <= #1 bb_q; end else begin bb_i0 <= #1 bb_i; bb_q0 <= #1 bb_q; end cordic rx_cordic ( .clock(clock_2x),.reset(reset),.enable(enable), .xi(i_in),.yi(q_in),.zi(phase), .xo(bb_i),.yo(bb_q),.zo() ); cic_decim cic_decim_i_0 ( .clock(clock),.reset(reset),.enable(enable), .rate(decim_rate),.strobe_in(sample_strobe),.strobe_out(decimator_strobe), .signal_in(bb_i0),.signal_out(i_out0) ); cic_decim cic_decim_q_0 ( .clock(clock),.reset(reset),.enable(enable), .rate(decim_rate),.strobe_in(sample_strobe),.strobe_out(decimator_strobe), .signal_in(bb_q0),.signal_out(q_out0) ); cic_decim cic_decim_i_1 ( .clock(clock),.reset(reset),.enable(enable), .rate(decim_rate),.strobe_in(sample_strobe),.strobe_out(decimator_strobe), .signal_in(bb_i1),.signal_out(i_out1) ); cic_decim cic_decim_q_1 ( .clock(clock),.reset(reset),.enable(enable), .rate(decim_rate),.strobe_in(sample_strobe),.strobe_out(decimator_strobe), .signal_in(bb_q1),.signal_out(q_out1) ); endmodule
module rx_chain_dual (input clock, input clock_2x, input reset, input enable, input wire [7:0] decim_rate, input sample_strobe, input decimator_strobe, input wire [31:0] freq0, input wire [15:0] i_in0, input wire [15:0] q_in0, output wire [15:0] i_out0, output wire [15:0] q_out0, input wire [31:0] freq1, input wire [15:0] i_in1, input wire [15:0] q_in1, output wire [15:0] i_out1, output wire [15:0] q_out1 ); wire [15:0] phase; wire [15:0] bb_i, bb_q; wire [15:0] i_in, q_in; wire [31:0] phase0; wire [31:0] phase1; reg [15:0] bb_i0, bb_q0; reg [15:0] bb_i1, bb_q1; // We want to time-share the CORDIC by double-clocking it phase_acc rx_phase_acc_0 (.clk(clock),.reset(reset),.enable(enable), .strobe(sample_strobe),.freq(freq0),.phase(phase0) ); phase_acc rx_phase_acc_1 (.clk(clock),.reset(reset),.enable(enable), .strobe(sample_strobe),.freq(freq1),.phase(phase1) ); assign phase = clock ? phase0[31:16] : phase1[31:16]; assign i_in = clock ? i_in0 : i_in1; assign q_in = clock ? q_in0 : q_in1; // This appears reversed because of the number of CORDIC stages always @(posedge clock_2x) if(clock) begin bb_i1 <= #1 bb_i; bb_q1 <= #1 bb_q; end else begin bb_i0 <= #1 bb_i; bb_q0 <= #1 bb_q; end cordic rx_cordic ( .clock(clock_2x),.reset(reset),.enable(enable), .xi(i_in),.yi(q_in),.zi(phase), .xo(bb_i),.yo(bb_q),.zo() ); cic_decim cic_decim_i_0 ( .clock(clock),.reset(reset),.enable(enable), .rate(decim_rate),.strobe_in(sample_strobe),.strobe_out(decimator_strobe), .signal_in(bb_i0),.signal_out(i_out0) ); cic_decim cic_decim_q_0 ( .clock(clock),.reset(reset),.enable(enable), .rate(decim_rate),.strobe_in(sample_strobe),.strobe_out(decimator_strobe), .signal_in(bb_q0),.signal_out(q_out0) ); cic_decim cic_decim_i_1 ( .clock(clock),.reset(reset),.enable(enable), .rate(decim_rate),.strobe_in(sample_strobe),.strobe_out(decimator_strobe), .signal_in(bb_i1),.signal_out(i_out1) ); cic_decim cic_decim_q_1 ( .clock(clock),.reset(reset),.enable(enable), .rate(decim_rate),.strobe_in(sample_strobe),.strobe_out(decimator_strobe), .signal_in(bb_q1),.signal_out(q_out1) ); endmodule
module phase_acc (clk,reset,enable,strobe,serial_addr,serial_data,serial_strobe,phase); parameter FREQADDR = 0; parameter PHASEADDR = 0; parameter resolution = 32; input clk, reset, enable, strobe; input [6:0] serial_addr; input [31:0] serial_data; input serial_strobe; output reg [resolution-1:0] phase; wire [resolution-1:0] freq; setting_reg #(FREQADDR) sr_rxfreq0(.clock(clk),.reset(1'b0),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(freq)); always @(posedge clk) if(reset) phase <= #1 32'b0; else if(serial_strobe & (serial_addr == PHASEADDR)) phase <= #1 serial_data; else if(enable & strobe) phase <= #1 phase + freq; endmodule
module phase_acc (clk,reset,enable,strobe,serial_addr,serial_data,serial_strobe,phase); parameter FREQADDR = 0; parameter PHASEADDR = 0; parameter resolution = 32; input clk, reset, enable, strobe; input [6:0] serial_addr; input [31:0] serial_data; input serial_strobe; output reg [resolution-1:0] phase; wire [resolution-1:0] freq; setting_reg #(FREQADDR) sr_rxfreq0(.clock(clk),.reset(1'b0),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(freq)); always @(posedge clk) if(reset) phase <= #1 32'b0; else if(serial_strobe & (serial_addr == PHASEADDR)) phase <= #1 serial_data; else if(enable & strobe) phase <= #1 phase + freq; endmodule
module phase_acc (clk,reset,enable,strobe,serial_addr,serial_data,serial_strobe,phase); parameter FREQADDR = 0; parameter PHASEADDR = 0; parameter resolution = 32; input clk, reset, enable, strobe; input [6:0] serial_addr; input [31:0] serial_data; input serial_strobe; output reg [resolution-1:0] phase; wire [resolution-1:0] freq; setting_reg #(FREQADDR) sr_rxfreq0(.clock(clk),.reset(1'b0),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(freq)); always @(posedge clk) if(reset) phase <= #1 32'b0; else if(serial_strobe & (serial_addr == PHASEADDR)) phase <= #1 serial_data; else if(enable & strobe) phase <= #1 phase + freq; endmodule
module phase_acc (clk,reset,enable,strobe,serial_addr,serial_data,serial_strobe,phase); parameter FREQADDR = 0; parameter PHASEADDR = 0; parameter resolution = 32; input clk, reset, enable, strobe; input [6:0] serial_addr; input [31:0] serial_data; input serial_strobe; output reg [resolution-1:0] phase; wire [resolution-1:0] freq; setting_reg #(FREQADDR) sr_rxfreq0(.clock(clk),.reset(1'b0),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(freq)); always @(posedge clk) if(reset) phase <= #1 32'b0; else if(serial_strobe & (serial_addr == PHASEADDR)) phase <= #1 serial_data; else if(enable & strobe) phase <= #1 phase + freq; endmodule
module bustri ( data, enabledt, tridata); input [15:0] data; input enabledt; inout [15:0] tridata; lpm_bustri lpm_bustri_component ( .tridata (tridata), .enabledt (enabledt), .data (data)); defparam lpm_bustri_component.lpm_width = 16, lpm_bustri_component.lpm_type = "LPM_BUSTRI"; endmodule