Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

AXI4_Slave_Stream.sv 5.4 KiB

3 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. `timescale 1 ns / 1 ps
  2. //////////////////////////////////////////////////////////////////////////////////
  3. // Company: BITSILICA PRIVATE LIMITED
  4. // Design Name: AXI4_STREAM_SLAVE_INTERFACE
  5. // Module Name: S_AXIS
  6. // Project Name: POLAR ENCODER-DECODER
  7. // Target Devices: Zynq UltraScale+ ZCU111 Evaluation Platform (xczu28dr-ffvg1517-2-e)
  8. // Tool Versions: VIVADO 2020.1
  9. // Description: AXI4 Stream Slave Interface is used to stream input data to the
  10. // polar Encoder.
  11. //
  12. ////////////////////////////////////////////////////////////////////////////////////
  13. module S_AXIS #
  14. ( // AXI4Stream sink: Data Width
  15. parameter integer C_S_AXIS_TDATA_WIDTH = 32
  16. )
  17. ( // AXI4Stream sink: Clock
  18. input wire S_AXIS_ACLK,
  19. // AXI4Stream sink: Reset
  20. input wire S_AXIS_ARESETN,
  21. // Ready to accept data in
  22. output wire S_AXIS_TREADY,
  23. // Data out
  24. output [C_S_AXIS_TDATA_WIDTH-1 : 0] M_AXIS_TDATA,
  25. // Data in
  26. input wire [C_S_AXIS_TDATA_WIDTH-1 : 0] S_AXIS_TDATA,
  27. // Indicates boundary of last packet
  28. input wire S_AXIS_TLAST,
  29. // Data is in valid
  30. input wire S_AXIS_TVALID,
  31. input wire tready_in,
  32. output logic read_en
  33. );
  34. // function called clogb2 that returns an integer which has the
  35. // value of the ceiling of the log base 2.
  36. function integer clogb2 (input integer bit_depth);
  37. begin
  38. for(clogb2=0; bit_depth>0; clogb2=clogb2+1)
  39. bit_depth = bit_depth >> 1;
  40. end
  41. endfunction
  42. // Total number of input data.
  43. localparam NUMBER_OF_INPUT_WORDS = 8;
  44. localparam NUMBER_OF_OUTPUT_WORDS = 8;
  45. // bit_num gives the minimum number of bits needed to address 'NUMBER_OF_INPUT_WORDS' size of FIFO.
  46. localparam bit_num = clogb2(NUMBER_OF_INPUT_WORDS-1);
  47. localparam aw = clogb2(C_S_AXIS_TDATA_WIDTH);
  48. // The control state machine oversees the writing of input streaming data to the FIFO,
  49. // and outputs the streaming data from the FIFO
  50. localparam [1:0] IDLE = 2'b00, // This is the initial/idle state
  51. WRITE_FIFO = 2'b01, // In this state FIFO is written with the
  52. // input stream data S_AXIS_TDATA
  53. FIRST_READ = 2'b10, // Read first from FIFO as soon as it writes
  54. READ_FIFO = 2'b11; // Read State
  55. logic axis_tready;
  56. logic [1:0] mst_exec_state; // State variable
  57. logic fifo_wren; // FIFO write enable
  58. logic fifo_full_flag; // FIFO full flag
  59. logic fifo_empty; // FIFO Empty
  60. logic full_n; // FIFO is being written
  61. logic first_read_en; // First Read Enable
  62. logic [5:0] count;
  63. logic tx_en;
  64. // I/O Connections assignments
  65. assign read_en = (tready_in || first_read_en);
  66. assign S_AXIS_TREADY = axis_tready;
  67. // Control state machine implementation
  68. always @(posedge S_AXIS_ACLK)
  69. begin
  70. if (!S_AXIS_ARESETN)
  71. // Synchronous reset (active low)
  72. begin
  73. mst_exec_state <= IDLE;
  74. first_read_en <= 0;
  75. end
  76. else
  77. case (mst_exec_state)
  78. IDLE: begin
  79. // The sink starts accepting tdata when
  80. // there tvalid is asserted to mark the
  81. // presence of valid streaming data
  82. first_read_en <= 0;
  83. if (S_AXIS_TVALID)
  84. begin
  85. mst_exec_state <= WRITE_FIFO;
  86. end
  87. else
  88. begin
  89. mst_exec_state <= IDLE;
  90. end
  91. end
  92. WRITE_FIFO: begin
  93. // When the sink has accepted all the streaming input data,
  94. // the interface swiches functionality to a streaming master
  95. // if (writes_done)
  96. first_read_en <= 0;
  97. if(full_n && count == 1)
  98. mst_exec_state <= FIRST_READ;
  99. else if (fifo_full_flag)
  100. begin
  101. mst_exec_state <= READ_FIFO;
  102. end
  103. else
  104. begin
  105. // The sink accepts and stores tdata
  106. // into FIFO
  107. mst_exec_state <= WRITE_FIFO;
  108. end
  109. end
  110. FIRST_READ: begin
  111. first_read_en <= 1'b1;
  112. if(!fifo_full_flag)
  113. mst_exec_state <= WRITE_FIFO;
  114. else
  115. mst_exec_state <= READ_FIFO;
  116. end
  117. READ_FIFO : begin
  118. first_read_en <= 0;
  119. if(fifo_empty)
  120. mst_exec_state <= IDLE;
  121. else if(!fifo_full_flag)
  122. mst_exec_state <= WRITE_FIFO;
  123. else
  124. mst_exec_state <= READ_FIFO;
  125. end
  126. endcase
  127. end
  128. // AXI Streaming Sink
  129. //
  130. // design sink is always ready to accept the S_AXIS_TDATA until
  131. // the FIFO is not filled with NUMBER_OF_INPUT_WORDS number of input words.
  132. assign axis_tready = ((mst_exec_state == WRITE_FIFO) || (mst_exec_state == READ_FIFO)) && !fifo_full_flag && !S_AXIS_TLAST;
  133. // FIFO write enable generation
  134. assign fifo_wren = S_AXIS_TVALID && axis_tready && !fifo_full_flag && !S_AXIS_TLAST;
  135. fifo #(.dw(C_S_AXIS_TDATA_WIDTH),.aw(aw-1),.n(C_S_AXIS_TDATA_WIDTH))FIFO(.clk(S_AXIS_ACLK),.rst(S_AXIS_ARESETN),.din(S_AXIS_TDATA),.we(fifo_wren),.dout(M_AXIS_TDATA),.re(read_en),
  136. .full(),.empty(),.full_r(fifo_full_flag),.empty_r(fifo_empty),.full_n(full_n), .empty_n(), .full_n_r(), .empty_n_r(),.level(),.count(count));
  137. //FIFO read enable generation
  138. assign tx_en = axis_tready && S_AXIS_TVALID && tready_in;
  139. endmodule