altera_customins_slave_translator.sv 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // (C) 2001-2018 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. // $Id: //acds/rel/18.1std/ip/merlin/altera_customins_slave_translator/altera_customins_slave_translator.sv#1 $
  13. // $Revision: #1 $
  14. // $Date: 2018/07/18 $
  15. // $Author: psgswbuild $
  16. // --------------------------------------
  17. // Custom instruction slave translator
  18. // --------------------------------------
  19. `timescale 1 ns / 1 ns
  20. module altera_customins_slave_translator
  21. #(
  22. parameter N_WIDTH = 8,
  23. USE_DONE = 1,
  24. NUM_FIXED_CYCLES = 2
  25. )
  26. (
  27. // --------------------------------------
  28. // Slave
  29. // --------------------------------------
  30. input wire [31:0] ci_slave_dataa,
  31. input wire [31:0] ci_slave_datab,
  32. output wire [31:0] ci_slave_result,
  33. input wire [7:0] ci_slave_n,
  34. input wire ci_slave_readra,
  35. input wire ci_slave_readrb,
  36. input wire ci_slave_writerc,
  37. input wire [4:0] ci_slave_a,
  38. input wire [4:0] ci_slave_b,
  39. input wire [4:0] ci_slave_c,
  40. input wire [31:0] ci_slave_ipending,
  41. input wire ci_slave_estatus,
  42. input wire ci_slave_clk,
  43. input wire ci_slave_clken,
  44. input wire ci_slave_reset,
  45. input wire ci_slave_reset_req,
  46. input wire ci_slave_start,
  47. output wire ci_slave_done,
  48. // --------------------------------------
  49. // Master
  50. // --------------------------------------
  51. output wire [31:0] ci_master_dataa,
  52. output wire [31:0] ci_master_datab,
  53. input wire [31:0] ci_master_result,
  54. output wire [N_WIDTH-1:0] ci_master_n,
  55. output wire ci_master_readra,
  56. output wire ci_master_readrb,
  57. output wire ci_master_writerc,
  58. output wire [4:0] ci_master_a,
  59. output wire [4:0] ci_master_b,
  60. output wire [4:0] ci_master_c,
  61. output wire [31:0] ci_master_ipending,
  62. output wire ci_master_estatus,
  63. output wire ci_master_clk,
  64. output wire ci_master_clken,
  65. output wire ci_master_reset,
  66. output wire ci_master_reset_req,
  67. output wire ci_master_start,
  68. input wire ci_master_done
  69. );
  70. localparam COUNTER_WIDTH = $clog2(NUM_FIXED_CYCLES);
  71. wire gen_done;
  72. reg [COUNTER_WIDTH-1:0] count;
  73. reg running;
  74. reg reg_start;
  75. assign ci_slave_result = ci_master_result;
  76. assign ci_master_writerc = ci_slave_writerc;
  77. assign ci_master_dataa = ci_slave_dataa;
  78. assign ci_master_readra = ci_slave_readra;
  79. assign ci_master_datab = ci_slave_datab;
  80. assign ci_master_readrb = ci_slave_readrb;
  81. assign ci_master_b = ci_slave_b;
  82. assign ci_master_c = ci_slave_c;
  83. assign ci_master_a = ci_slave_a;
  84. assign ci_master_ipending = ci_slave_ipending;
  85. assign ci_master_estatus = ci_slave_estatus;
  86. assign ci_master_clk = ci_slave_clk;
  87. assign ci_master_clken = ci_slave_clken;
  88. assign ci_master_reset = ci_slave_reset;
  89. assign ci_master_reset_req = ci_slave_reset_req;
  90. // --------------------------------------
  91. // Is there something we need to do if the master does not
  92. // have start?
  93. // --------------------------------------
  94. assign ci_master_start = ci_slave_start;
  95. // --------------------------------------
  96. // Create the done signal if the slave does not drive it.
  97. //
  98. // For num_cycles = 2, this is just the registered start.
  99. // Anything larger and we use a down-counter.
  100. // --------------------------------------
  101. assign ci_slave_done = (USE_DONE == 1) ? ci_master_done : gen_done;
  102. assign gen_done = (NUM_FIXED_CYCLES == 2) ? reg_start : (count == 0);
  103. always @(posedge ci_slave_clk, posedge ci_slave_reset) begin
  104. if (ci_slave_reset)
  105. reg_start <= 0;
  106. else if (ci_slave_clken)
  107. reg_start <= ci_slave_start;
  108. end
  109. always @(posedge ci_slave_clk, posedge ci_slave_reset) begin
  110. if (ci_slave_reset) begin
  111. running <= 0;
  112. count <= NUM_FIXED_CYCLES - 2;
  113. end
  114. else if (ci_slave_clken) begin
  115. if (ci_slave_start)
  116. running <= 1;
  117. if (running)
  118. count <= count - 1;
  119. if (ci_slave_done) begin
  120. running <= 0;
  121. count <= NUM_FIXED_CYCLES - 2;
  122. end
  123. end
  124. end
  125. // --------------------------------------
  126. // Opcode base addresses must be a multiple of their span,
  127. // just like base addresses. This simplifies the following
  128. // assignment (just drop the high order bits)
  129. // --------------------------------------
  130. assign ci_master_n = ci_slave_n[N_WIDTH-1:0];
  131. endmodule