Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

AXI4_Master_Stream.sv 14 KiB

před 3 roky
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. `timescale 1 ns / 1 ps
  2. //////////////////////////////////////////////////////////////////////////////////
  3. // Company: BITSILICA PRIVATE LIMITED
  4. // Design Name: AXI4_STREAM_MASTER_INTERFACE
  5. // Module Name: DOUT_M_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 Master Interface is used to stream out output data from
  10. // the polar Encoder.
  11. //
  12. ////////////////////////////////////////////////////////////////////////////////////
  13. module DOUT_M_AXIS #
  14. (
  15. // Width of S_AXIS address bus. The slave accepts the read and write addresses of width C_M_AXIS_TDATA_WIDTH.
  16. parameter integer C_M_AXIS_TDATA_WIDTH = 32,
  17. parameter integer C_S_AXIS_TDATA_WIDTH = 512,
  18. parameter integer DEPTH = 16,
  19. // Start count is the numeber of clock cycles the master will wait before initiating/issuing any transaction.
  20. parameter integer C_M_START_COUNT = 2
  21. )
  22. (
  23. // Global ports
  24. input logic M_AXIS_ACLK,
  25. //
  26. input logic M_AXIS_ARESETN,
  27. // Master Stream Ports. TVALID indicates that the master is driving a valid transfer, A transfer takes place when both TVALID and TREADY are asserted.
  28. output logic M_AXIS_TVALID,
  29. // TDATA is the primary payload that is used to provide the data that is passing across the interface from the master.
  30. output logic [C_M_AXIS_TDATA_WIDTH-1 : 0] M_AXIS_TDATA,
  31. // TLAST indicates the boundary of a packet.
  32. output logic M_AXIS_TLAST,
  33. // TREADY indicates that the slave can accept a transfer in the current cycle.
  34. input logic M_AXIS_TREADY,
  35. // Input from PBCH Encoder Core of Width 864 bits
  36. input logic [C_S_AXIS_TDATA_WIDTH-1:0]S_AXIS_TDATA,
  37. // Input from PBCH Encoder Core
  38. input logic DONE
  39. );
  40. //Total number of output data.
  41. // Total number of output data
  42. localparam NUMBER_OF_OUTPUT_WORDS = 27;
  43. // function called clogb2 that returns an integer which has the
  44. // value of the ceiling of the log base 2.
  45. function integer clogb2 (input integer bit_depth);
  46. begin
  47. for(clogb2=0; bit_depth>0; clogb2=clogb2+1)
  48. bit_depth = bit_depth >> 1;
  49. end
  50. endfunction
  51. // WAIT_COUNT_BITS is the width of the wait counter.
  52. localparam integer WAIT_COUNT_BITS = clogb2(C_M_START_COUNT-1);
  53. // bit_num gives the minimum number of bits needed to address 'depth' size of FIFO.
  54. localparam bit_num = clogb2(NUMBER_OF_OUTPUT_WORDS);
  55. // Define the states of state machine
  56. // The control state machine oversees the writing of input streaming data to the FIFO,
  57. // and outputs the streaming data from the FIFO
  58. parameter [1:0] IDLE = 2'b00, // This is the initial/idle state
  59. INIT_COUNTER = 2'b01, // This state initializes the counter, ones
  60. // the counter reaches C_M_START_COUNT count,
  61. // the state machine changes state to INIT_WRITE
  62. SEND_STREAM = 2'b10; // In this state the
  63. // stream data is output through M_AXIS_TDATA
  64. // State variable
  65. logic [1:0] mst_exec_state;
  66. // FIFO read pointer
  67. logic [bit_num-1:0] read_pointer;
  68. // AXI Stream internal signals
  69. //wait counter. The master waits for the user defined number of clock cycles before initiating a transfer.
  70. logic [WAIT_COUNT_BITS-1 : 0] count;
  71. //streaming data valid
  72. logic axis_tvalid;
  73. //streaming data valid delayed by one clock cycle
  74. logic axis_tvalid_delay;
  75. //Last of the streaming data
  76. logic axis_tlast;
  77. //Last of the streaming data delayed by one clock cycle
  78. logic axis_tlast_delay;
  79. //FIFO implementation signals
  80. logic [C_M_AXIS_TDATA_WIDTH-1 : 0] stream_data_out;
  81. logic tx_en;
  82. //The master has issued all the streaming data stored in FIFO
  83. logic tx_done;
  84. (* ram_style="register" *)
  85. logic [C_M_AXIS_TDATA_WIDTH-1:0] slv_reg0 [0:DEPTH-1];
  86. // I/O Connections assignments
  87. assign M_AXIS_TVALID = axis_tvalid_delay;
  88. assign M_AXIS_TDATA = stream_data_out;
  89. assign M_AXIS_TLAST = axis_tlast_delay;
  90. integer i;
  91. integer byte_index;
  92. always_ff @( posedge M_AXIS_ACLK )
  93. begin
  94. if (!M_AXIS_ARESETN )
  95. begin
  96. stream_data_out <= 0;
  97. for(i = 0; i <= DEPTH - 1 ; i = i+1)
  98. slv_reg0[i] <= 0;
  99. end
  100. else
  101. begin
  102. if (DONE)
  103. for ( byte_index = 0; byte_index <= DEPTH - 1; byte_index = byte_index+1 )
  104. slv_reg0[byte_index] <= S_AXIS_TDATA[(byte_index*C_M_AXIS_TDATA_WIDTH) +: C_M_AXIS_TDATA_WIDTH];
  105. else if (tx_en)
  106. begin
  107. stream_data_out <= slv_reg0[read_pointer];
  108. end
  109. end
  110. end
  111. // Control state machine implementation
  112. always_ff @(posedge M_AXIS_ACLK)
  113. begin
  114. // Synchronous reset (active low)
  115. if (!M_AXIS_ARESETN)
  116. begin
  117. mst_exec_state <= IDLE;
  118. count <= 0;
  119. end
  120. else
  121. case (mst_exec_state)
  122. IDLE:
  123. // The slave starts accepting tdata when
  124. // there tvalid is asserted to mark the
  125. // presence of valid streaming data
  126. mst_exec_state <= INIT_COUNTER;
  127. INIT_COUNTER:
  128. // The slave starts accepting tdata when
  129. // there tvalid is asserted to mark the
  130. // presence of valid streaming data
  131. if ( count == C_M_START_COUNT - 1 )
  132. begin
  133. mst_exec_state <= SEND_STREAM;
  134. end
  135. else
  136. begin
  137. count <= count + 1;
  138. mst_exec_state <= INIT_COUNTER;
  139. end
  140. SEND_STREAM:
  141. // The example design streaming master functionality starts
  142. // when the master drives output tdata from the FIFO and the slave
  143. // has finished storing the S_AXIS_TDATA
  144. if (tx_done)
  145. begin
  146. mst_exec_state <= IDLE;
  147. end
  148. else
  149. begin
  150. mst_exec_state <= SEND_STREAM;
  151. end
  152. endcase
  153. end
  154. //tvalid generation
  155. //axis_tvalid is asserted when the control state machine's state is SEND_STREAM and
  156. //number of output streaming data is less than the NUMBER_OF_OUTPUT_WORDS.
  157. assign axis_tvalid = ((mst_exec_state == SEND_STREAM) && (read_pointer < NUMBER_OF_OUTPUT_WORDS));
  158. // AXI tlast generation
  159. // axis_tlast is asserted number of output streaming data is NUMBER_OF_OUTPUT_WORDS-1
  160. // (0 to NUMBER_OF_OUTPUT_WORDS-1)
  161. assign axis_tlast = (read_pointer == NUMBER_OF_OUTPUT_WORDS-1);
  162. // Delay the axis_tvalid and axis_tlast signal by one clock cycle
  163. // to match the latency of M_AXIS_TDATA
  164. always_ff @(posedge M_AXIS_ACLK)
  165. begin
  166. if (!M_AXIS_ARESETN)
  167. begin
  168. axis_tvalid_delay <= 1'b0;
  169. axis_tlast_delay <= 1'b0;
  170. end
  171. else
  172. begin
  173. axis_tvalid_delay <= axis_tvalid;
  174. axis_tlast_delay <= axis_tlast;
  175. end
  176. end
  177. //read_pointer pointer
  178. always_ff@(posedge M_AXIS_ACLK)
  179. begin
  180. if(!M_AXIS_ARESETN)
  181. begin
  182. read_pointer <= 0;
  183. tx_done <= 1'b0;
  184. end
  185. else
  186. if (read_pointer <= NUMBER_OF_OUTPUT_WORDS-1)
  187. begin
  188. if (tx_en)
  189. // read pointer is incremented after every read from the FIFO
  190. // when FIFO read signal is enabled.
  191. begin
  192. read_pointer <= read_pointer + 1;
  193. tx_done <= 1'b0;
  194. end
  195. end
  196. else if (read_pointer == NUMBER_OF_OUTPUT_WORDS)
  197. begin
  198. // tx_done is asserted when NUMBER_OF_OUTPUT_WORDS numbers of streaming data
  199. // has been out.
  200. tx_done <= 1'b1;
  201. if(DONE)read_pointer <= 0;
  202. end
  203. end
  204. //FIFO read enable generation
  205. assign tx_en = M_AXIS_TREADY && axis_tvalid;
  206. endmodule