nios2_uc_mm_interconnect_0_router_002.sv 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. // (C) 2001-2019 Intel Corporation. All rights reserved.
  2. // Your use of Intel Corporation's design tools, logic functions and other
  3. // software and tools, and its AMPP partner logic functions, and any output
  4. // files from any of the foregoing (including device programming or simulation
  5. // files), and any associated documentation or information are expressly subject
  6. // to the terms and conditions of the Intel Program License Subscription
  7. // Agreement, Intel FPGA IP License Agreement, or other applicable
  8. // license agreement, including, without limitation, that your use is for the
  9. // sole purpose of programming logic devices manufactured by Intel and sold by
  10. // Intel or its authorized distributors. Please refer to the applicable
  11. // agreement for further details.
  12. // Your use of Altera Corporation's design tools, logic functions and other
  13. // software and tools, and its AMPP partner logic functions, and any output
  14. // files any of the foregoing (including device programming or simulation
  15. // files), and any associated documentation or information are expressly subject
  16. // to the terms and conditions of the Altera Program License Subscription
  17. // Agreement, Altera MegaCore Function License Agreement, or other applicable
  18. // license agreement, including, without limitation, that your use is for the
  19. // sole purpose of programming logic devices manufactured by Altera and sold by
  20. // Altera or its authorized distributors. Please refer to the applicable
  21. // agreement for further details.
  22. // $Id: //acds/rel/19.1std/ip/merlin/altera_merlin_router/altera_merlin_router.sv.terp#1 $
  23. // $Revision: #1 $
  24. // $Date: 2018/11/07 $
  25. // $Author: psgswbuild $
  26. // -------------------------------------------------------
  27. // Merlin Router
  28. //
  29. // Asserts the appropriate one-hot encoded channel based on
  30. // either (a) the address or (b) the dest id. The DECODER_TYPE
  31. // parameter controls this behaviour. 0 means address decoder,
  32. // 1 means dest id decoder.
  33. //
  34. // In the case of (a), it also sets the destination id.
  35. // -------------------------------------------------------
  36. `timescale 1 ns / 1 ns
  37. module nios2_uc_mm_interconnect_0_router_002_default_decode
  38. #(
  39. parameter DEFAULT_CHANNEL = 0,
  40. DEFAULT_WR_CHANNEL = -1,
  41. DEFAULT_RD_CHANNEL = -1,
  42. DEFAULT_DESTID = 0
  43. )
  44. (output [80 - 79 : 0] default_destination_id,
  45. output [4-1 : 0] default_wr_channel,
  46. output [4-1 : 0] default_rd_channel,
  47. output [4-1 : 0] default_src_channel
  48. );
  49. assign default_destination_id =
  50. DEFAULT_DESTID[80 - 79 : 0];
  51. generate
  52. if (DEFAULT_CHANNEL == -1) begin : no_default_channel_assignment
  53. assign default_src_channel = '0;
  54. end
  55. else begin : default_channel_assignment
  56. assign default_src_channel = 4'b1 << DEFAULT_CHANNEL;
  57. end
  58. endgenerate
  59. generate
  60. if (DEFAULT_RD_CHANNEL == -1) begin : no_default_rw_channel_assignment
  61. assign default_wr_channel = '0;
  62. assign default_rd_channel = '0;
  63. end
  64. else begin : default_rw_channel_assignment
  65. assign default_wr_channel = 4'b1 << DEFAULT_WR_CHANNEL;
  66. assign default_rd_channel = 4'b1 << DEFAULT_RD_CHANNEL;
  67. end
  68. endgenerate
  69. endmodule
  70. module nios2_uc_mm_interconnect_0_router_002
  71. (
  72. // -------------------
  73. // Clock & Reset
  74. // -------------------
  75. input clk,
  76. input reset,
  77. // -------------------
  78. // Command Sink (Input)
  79. // -------------------
  80. input sink_valid,
  81. input [94-1 : 0] sink_data,
  82. input sink_startofpacket,
  83. input sink_endofpacket,
  84. output sink_ready,
  85. // -------------------
  86. // Command Source (Output)
  87. // -------------------
  88. output src_valid,
  89. output reg [94-1 : 0] src_data,
  90. output reg [4-1 : 0] src_channel,
  91. output src_startofpacket,
  92. output src_endofpacket,
  93. input src_ready
  94. );
  95. // -------------------------------------------------------
  96. // Local parameters and variables
  97. // -------------------------------------------------------
  98. localparam PKT_ADDR_H = 55;
  99. localparam PKT_ADDR_L = 36;
  100. localparam PKT_DEST_ID_H = 80;
  101. localparam PKT_DEST_ID_L = 79;
  102. localparam PKT_PROTECTION_H = 84;
  103. localparam PKT_PROTECTION_L = 82;
  104. localparam ST_DATA_W = 94;
  105. localparam ST_CHANNEL_W = 4;
  106. localparam DECODER_TYPE = 1;
  107. localparam PKT_TRANS_WRITE = 58;
  108. localparam PKT_TRANS_READ = 59;
  109. localparam PKT_ADDR_W = PKT_ADDR_H-PKT_ADDR_L + 1;
  110. localparam PKT_DEST_ID_W = PKT_DEST_ID_H-PKT_DEST_ID_L + 1;
  111. // -------------------------------------------------------
  112. // Figure out the number of bits to mask off for each slave span
  113. // during address decoding
  114. // -------------------------------------------------------
  115. // -------------------------------------------------------
  116. // Work out which address bits are significant based on the
  117. // address range of the slaves. If the required width is too
  118. // large or too small, we use the address field width instead.
  119. // -------------------------------------------------------
  120. localparam ADDR_RANGE = 64'h0;
  121. localparam RANGE_ADDR_WIDTH = log2ceil(ADDR_RANGE);
  122. localparam OPTIMIZED_ADDR_H = (RANGE_ADDR_WIDTH > PKT_ADDR_W) ||
  123. (RANGE_ADDR_WIDTH == 0) ?
  124. PKT_ADDR_H :
  125. PKT_ADDR_L + RANGE_ADDR_WIDTH - 1;
  126. localparam RG = RANGE_ADDR_WIDTH;
  127. localparam REAL_ADDRESS_RANGE = OPTIMIZED_ADDR_H - PKT_ADDR_L;
  128. reg [PKT_DEST_ID_W-1 : 0] destid;
  129. // -------------------------------------------------------
  130. // Pass almost everything through, untouched
  131. // -------------------------------------------------------
  132. assign sink_ready = src_ready;
  133. assign src_valid = sink_valid;
  134. assign src_startofpacket = sink_startofpacket;
  135. assign src_endofpacket = sink_endofpacket;
  136. wire [4-1 : 0] default_src_channel;
  137. // -------------------------------------------------------
  138. // Write and read transaction signals
  139. // -------------------------------------------------------
  140. wire read_transaction;
  141. assign read_transaction = sink_data[PKT_TRANS_READ];
  142. nios2_uc_mm_interconnect_0_router_002_default_decode the_default_decode(
  143. .default_destination_id (),
  144. .default_wr_channel (),
  145. .default_rd_channel (),
  146. .default_src_channel (default_src_channel)
  147. );
  148. always @* begin
  149. src_data = sink_data;
  150. src_channel = default_src_channel;
  151. // --------------------------------------------------
  152. // DestinationID Decoder
  153. // Sets the channel based on the destination ID.
  154. // --------------------------------------------------
  155. destid = sink_data[PKT_DEST_ID_H : PKT_DEST_ID_L];
  156. if (destid == 0 ) begin
  157. src_channel = 4'b01;
  158. end
  159. if (destid == 1 && read_transaction) begin
  160. src_channel = 4'b10;
  161. end
  162. end
  163. // --------------------------------------------------
  164. // Ceil(log2()) function
  165. // --------------------------------------------------
  166. function integer log2ceil;
  167. input reg[65:0] val;
  168. reg [65:0] i;
  169. begin
  170. i = 1;
  171. log2ceil = 0;
  172. while (i < val) begin
  173. log2ceil = log2ceil + 1;
  174. i = i << 1;
  175. end
  176. end
  177. endfunction
  178. endmodule