index.html 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <!doctype html>
  2. <title>CodeMirror: Verilog mode</title>
  3. <meta charset="utf-8"/>
  4. <link rel=stylesheet href="../../doc/docs.css">
  5. <link rel="stylesheet" href="../../lib/codemirror.css">
  6. <script src="../../lib/codemirror.js"></script>
  7. <script src="verilog.js"></script>
  8. <style>.CodeMirror {border: 2px inset #dee;}</style>
  9. <div id=nav>
  10. <a href="http://codemirror.net"><img id=logo src="../../doc/logo.png"></a>
  11. <ul>
  12. <li><a href="../../index.html">Home</a>
  13. <li><a href="../../doc/manual.html">Manual</a>
  14. <li><a href="https://github.com/marijnh/codemirror">Code</a>
  15. </ul>
  16. <ul>
  17. <li><a href="../index.html">Language modes</a>
  18. <li><a class=active href="#">Verilog</a>
  19. </ul>
  20. </div>
  21. <article>
  22. <h2>Verilog mode</h2>
  23. <form><textarea id="code" name="code">
  24. /* Verilog demo code */
  25. module butterfly
  26. #(
  27. parameter WIDTH = 32,
  28. parameter MWIDTH = 1
  29. )
  30. (
  31. input wire clk,
  32. input wire rst_n,
  33. // m_in contains data that passes through this block with no change.
  34. input wire [MWIDTH-1:0] m_in,
  35. // The twiddle factor.
  36. input wire signed [WIDTH-1:0] w,
  37. // XA
  38. input wire signed [WIDTH-1:0] xa,
  39. // XB
  40. input wire signed [WIDTH-1:0] xb,
  41. // Set to 1 when new data is present on inputs.
  42. input wire x_nd,
  43. // delayed version of m_in.
  44. output reg [MWIDTH-1:0] m_out,
  45. // YA = XA + W*XB
  46. // YB = XA - W*XB
  47. output wire signed [WIDTH-1:0] ya,
  48. output wire signed [WIDTH-1:0] yb,
  49. output reg y_nd,
  50. output reg error
  51. );
  52. // Set wire to the real and imag parts for convenience.
  53. wire signed [WIDTH/2-1:0] xa_re;
  54. wire signed [WIDTH/2-1:0] xa_im;
  55. assign xa_re = xa[WIDTH-1:WIDTH/2];
  56. assign xa_im = xa[WIDTH/2-1:0];
  57. wire signed [WIDTH/2-1: 0] ya_re;
  58. wire signed [WIDTH/2-1: 0] ya_im;
  59. assign ya = {ya_re, ya_im};
  60. wire signed [WIDTH/2-1: 0] yb_re;
  61. wire signed [WIDTH/2-1: 0] yb_im;
  62. assign yb = {yb_re, yb_im};
  63. // Delayed stuff.
  64. reg signed [WIDTH/2-1:0] xa_re_z;
  65. reg signed [WIDTH/2-1:0] xa_im_z;
  66. // Output of multiplier
  67. wire signed [WIDTH-1:0] xbw;
  68. wire signed [WIDTH/2-1:0] xbw_re;
  69. wire signed [WIDTH/2-1:0] xbw_im;
  70. assign xbw_re = xbw[WIDTH-1:WIDTH/2];
  71. assign xbw_im = xbw[WIDTH/2-1:0];
  72. // Do summing
  73. // I don't think we should get overflow here because of the
  74. // size of the twiddle factors.
  75. // If we do testing should catch it.
  76. assign ya_re = xa_re_z + xbw_re;
  77. assign ya_im = xa_im_z + xbw_im;
  78. assign yb_re = xa_re_z - xbw_re;
  79. assign yb_im = xa_im_z - xbw_im;
  80. // Create the multiply module.
  81. multiply_complex #(WIDTH) multiply_complex_0
  82. (.clk(clk),
  83. .rst_n(rst_n),
  84. .x(xb),
  85. .y(w),
  86. .z(xbw)
  87. );
  88. always @ (posedge clk)
  89. begin
  90. if (!rst_n)
  91. begin
  92. y_nd <= 1'b0;
  93. error <= 1'b0;
  94. end
  95. else
  96. begin
  97. // Set delay for x_nd_old and m.
  98. y_nd <= x_nd;
  99. m_out <= m_in;
  100. if (x_nd)
  101. begin
  102. xa_re_z <= xa_re/2;
  103. xa_im_z <= xa_im/2;
  104. end
  105. end
  106. end
  107. endmodule
  108. </textarea></form>
  109. <script>
  110. var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
  111. lineNumbers: true,
  112. mode: "text/x-verilog"
  113. });
  114. </script>
  115. <p>Simple mode that tries to handle Verilog-like languages as well as it
  116. can. Takes one configuration parameters: <code>keywords</code>, an
  117. object whose property names are the keywords in the language.</p>
  118. <p><strong>MIME types defined:</strong> <code>text/x-verilog</code> (Verilog code).</p>
  119. </article>