delay.v 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * delay.v
  3. *
  4. * vim: ts=4 sw=4
  5. *
  6. * Generates a delay line/bus
  7. *
  8. * Copyright (C) 2019 Sylvain Munaut <tnt@246tNt.com>
  9. * All rights reserved.
  10. *
  11. * BSD 3-clause, see LICENSE.bsd
  12. *
  13. * Redistribution and use in source and binary forms, with or without
  14. * modification, are permitted provided that the following conditions are met:
  15. * * Redistributions of source code must retain the above copyright
  16. * notice, this list of conditions and the following disclaimer.
  17. * * Redistributions in binary form must reproduce the above copyright
  18. * notice, this list of conditions and the following disclaimer in the
  19. * documentation and/or other materials provided with the distribution.
  20. * * Neither the name of the <organization> nor the
  21. * names of its contributors may be used to endorse or promote products
  22. * derived from this software without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  25. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  26. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  28. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  29. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  30. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  31. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  32. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  33. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. `default_nettype none
  36. // ---------------------------------------------------------------------------
  37. // Single line delay
  38. // ---------------------------------------------------------------------------
  39. module delay_bit #(
  40. parameter integer DELAY = 1
  41. )(
  42. input wire d,
  43. output wire q,
  44. input wire clk
  45. );
  46. reg [DELAY-1:0] dl;
  47. generate
  48. if (DELAY > 1)
  49. always @(posedge clk)
  50. dl <= { dl[DELAY-2:0], d };
  51. else
  52. always @(posedge clk)
  53. dl <= d;
  54. endgenerate
  55. assign q = dl[DELAY-1];
  56. endmodule // delay_bit
  57. // ---------------------------------------------------------------------------
  58. // Bus delay
  59. // ---------------------------------------------------------------------------
  60. module delay_bus #(
  61. parameter integer DELAY = 1,
  62. parameter integer WIDTH = 1
  63. )(
  64. input wire [WIDTH-1:0] d,
  65. output wire [WIDTH-1:0] q,
  66. input wire clk
  67. );
  68. genvar i;
  69. reg [WIDTH-1:0] dl[0:DELAY-1];
  70. always @(posedge clk)
  71. dl[0] <= d;
  72. generate
  73. for (i=1; i<DELAY; i=i+1)
  74. always @(posedge clk)
  75. dl[i] <= dl[i-1];
  76. endgenerate
  77. assign q = dl[DELAY-1];
  78. endmodule // delay_bus
  79. // ---------------------------------------------------------------------------
  80. // Toggle delay
  81. // ---------------------------------------------------------------------------
  82. module delay_toggle #(
  83. parameter integer DELAY = 1
  84. )(
  85. input wire d,
  86. output wire q,
  87. input wire clk
  88. );
  89. // FIXME: TODO
  90. endmodule // delay_toggle