ice40_oserdes.v 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * ice40_oserdes.v
  3. *
  4. * vim: ts=4 sw=4
  5. *
  6. * Copyright (C) 2020 Sylvain Munaut <tnt@246tNt.com>
  7. * All rights reserved.
  8. *
  9. * BSD 3-clause, see LICENSE.bsd
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions are met:
  13. * * Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * * Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. * * Neither the name of the <organization> nor the
  19. * names of its contributors may be used to endorse or promote products
  20. * derived from this software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  23. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  24. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  26. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  27. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  28. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  29. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. */
  33. `default_nettype none
  34. module ice40_oserdes #(
  35. parameter MODE = "DATA", // "DATA" / "CLK90_2X" / "CLK90_4X"
  36. parameter integer SERDES_GRP = 0
  37. )(
  38. input wire [3:0] d,
  39. output wire [1:0] q,
  40. input wire sync,
  41. input wire clk_1x,
  42. input wire clk_4x
  43. );
  44. genvar i;
  45. // Signals
  46. // -------
  47. wire [3:0] cap_in;
  48. wire [3:0] cap_out;
  49. wire [3:0] shift_in;
  50. wire [3:0] shift_out;
  51. wire delay_out;
  52. // Capture
  53. // -------
  54. assign cap_in = (MODE == "CLK90_2X") ? { d[1], 1'b0, d[0], 1'b0 } : d;
  55. generate
  56. for (i=0; i<4; i=i+1)
  57. ice40_serdes_dff #(
  58. .SERDES_GRP( (SERDES_GRP << 8) | 'h00 | i )
  59. ) dff_cap_I (
  60. .d(cap_in[i]),
  61. .q(cap_out[i]),
  62. .c(clk_1x)
  63. );
  64. endgenerate
  65. // Shifter
  66. // -------
  67. assign shift_in = sync ? cap_out : { shift_out[2:0], 1'b0 };
  68. generate
  69. for (i=0; i<4; i=i+1)
  70. ice40_serdes_dff #(
  71. .SERDES_GRP( (SERDES_GRP << 8) | 'h10 | i )
  72. ) dff_shift_I (
  73. .d(shift_in[i]),
  74. .q(shift_out[i]),
  75. .c(clk_4x)
  76. );
  77. endgenerate
  78. // Output
  79. // ------
  80. generate
  81. if ((MODE == "CLK90_2X") || (MODE == "CLK90_4X")) begin
  82. // Delay FF for falling edge
  83. ice40_serdes_dff #(
  84. .SERDES_GRP( (SERDES_GRP << 8) | 'h20 )
  85. ) dff_out_I (
  86. .d(shift_out[3]),
  87. .q(delay_out),
  88. .c(clk_4x)
  89. );
  90. // Output depends on clock mode
  91. assign q[0] = (MODE == "CLK90_2X") ? delay_out : 1'b0;
  92. assign q[1] = delay_out;
  93. end else begin
  94. // Simple data map, fall edge output un-used
  95. assign q[0] = shift_out[3];
  96. assign q[1] = 1'b0;
  97. end
  98. endgenerate
  99. endmodule