nios2_uc_mm_interconnect_0_router.sv 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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_default_decode
  38. #(
  39. parameter DEFAULT_CHANNEL = 2,
  40. DEFAULT_WR_CHANNEL = -1,
  41. DEFAULT_RD_CHANNEL = -1,
  42. DEFAULT_DESTID = 2
  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
  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 = 0;
  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. localparam PAD0 = log2ceil(64'h80000 - 64'h40000);
  116. localparam PAD1 = log2ceil(64'h81000 - 64'h80800);
  117. localparam PAD2 = log2ceil(64'h81020 - 64'h81010);
  118. localparam PAD3 = log2ceil(64'h81030 - 64'h81028);
  119. // -------------------------------------------------------
  120. // Work out which address bits are significant based on the
  121. // address range of the slaves. If the required width is too
  122. // large or too small, we use the address field width instead.
  123. // -------------------------------------------------------
  124. localparam ADDR_RANGE = 64'h81030;
  125. localparam RANGE_ADDR_WIDTH = log2ceil(ADDR_RANGE);
  126. localparam OPTIMIZED_ADDR_H = (RANGE_ADDR_WIDTH > PKT_ADDR_W) ||
  127. (RANGE_ADDR_WIDTH == 0) ?
  128. PKT_ADDR_H :
  129. PKT_ADDR_L + RANGE_ADDR_WIDTH - 1;
  130. localparam RG = RANGE_ADDR_WIDTH-1;
  131. localparam REAL_ADDRESS_RANGE = OPTIMIZED_ADDR_H - PKT_ADDR_L;
  132. reg [PKT_ADDR_W-1 : 0] address;
  133. always @* begin
  134. address = {PKT_ADDR_W{1'b0}};
  135. address [REAL_ADDRESS_RANGE:0] = sink_data[OPTIMIZED_ADDR_H : PKT_ADDR_L];
  136. end
  137. // -------------------------------------------------------
  138. // Pass almost everything through, untouched
  139. // -------------------------------------------------------
  140. assign sink_ready = src_ready;
  141. assign src_valid = sink_valid;
  142. assign src_startofpacket = sink_startofpacket;
  143. assign src_endofpacket = sink_endofpacket;
  144. wire [PKT_DEST_ID_W-1:0] default_destid;
  145. wire [4-1 : 0] default_src_channel;
  146. nios2_uc_mm_interconnect_0_router_default_decode the_default_decode(
  147. .default_destination_id (default_destid),
  148. .default_wr_channel (),
  149. .default_rd_channel (),
  150. .default_src_channel (default_src_channel)
  151. );
  152. always @* begin
  153. src_data = sink_data;
  154. src_channel = default_src_channel;
  155. src_data[PKT_DEST_ID_H:PKT_DEST_ID_L] = default_destid;
  156. // --------------------------------------------------
  157. // Address Decoder
  158. // Sets the channel and destination ID based on the address
  159. // --------------------------------------------------
  160. // ( 0x40000 .. 0x80000 )
  161. if ( {address[RG:PAD0],{PAD0{1'b0}}} == 20'h40000 ) begin
  162. src_channel = 4'b0100;
  163. src_data[PKT_DEST_ID_H:PKT_DEST_ID_L] = 2;
  164. end
  165. // ( 0x80800 .. 0x81000 )
  166. if ( {address[RG:PAD1],{PAD1{1'b0}}} == 20'h80800 ) begin
  167. src_channel = 4'b0010;
  168. src_data[PKT_DEST_ID_H:PKT_DEST_ID_L] = 1;
  169. end
  170. // ( 0x81010 .. 0x81020 )
  171. if ( {address[RG:PAD2],{PAD2{1'b0}}} == 20'h81010 ) begin
  172. src_channel = 4'b1000;
  173. src_data[PKT_DEST_ID_H:PKT_DEST_ID_L] = 3;
  174. end
  175. // ( 0x81028 .. 0x81030 )
  176. if ( {address[RG:PAD3],{PAD3{1'b0}}} == 20'h81028 ) begin
  177. src_channel = 4'b0001;
  178. src_data[PKT_DEST_ID_H:PKT_DEST_ID_L] = 0;
  179. end
  180. end
  181. // --------------------------------------------------
  182. // Ceil(log2()) function
  183. // --------------------------------------------------
  184. function integer log2ceil;
  185. input reg[65:0] val;
  186. reg [65:0] i;
  187. begin
  188. i = 1;
  189. log2ceil = 0;
  190. while (i < val) begin
  191. log2ceil = log2ceil + 1;
  192. i = i << 1;
  193. end
  194. end
  195. endfunction
  196. endmodule