usb_transceiver.v 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. //-----------------------------------------------------------------
  2. // USB Full Speed (12mbps) Phy
  3. // V0.2
  4. // Ultra-Embedded.com
  5. // Copyright 2015
  6. //
  7. // Email: admin@ultra-embedded.com
  8. //
  9. // License: LGPL
  10. //-----------------------------------------------------------------
  11. //
  12. // This source file may be used and distributed without
  13. // restriction provided that this copyright statement is not
  14. // removed from the file and that any derivative work contains
  15. // the original copyright notice and the associated disclaimer.
  16. //
  17. // This source file is free software; you can redistribute it
  18. // and/or modify it under the terms of the GNU Lesser General
  19. // Public License as published by the Free Software Foundation;
  20. // either version 2.1 of the License, or (at your option) any
  21. // later version.
  22. //
  23. // This source is distributed in the hope that it will be
  24. // useful, but WITHOUT ANY WARRANTY; without even the implied
  25. // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  26. // PURPOSE. See the GNU Lesser General Public License for more
  27. // details.
  28. //
  29. // You should have received a copy of the GNU Lesser General
  30. // Public License along with this source; if not, write to the
  31. // Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  32. // Boston, MA 02111-1307 USA
  33. //-----------------------------------------------------------------
  34. //-----------------------------------------------------------------
  35. // Generated File
  36. //-----------------------------------------------------------------
  37. module usb_transceiver
  38. (
  39. // Inputs
  40. input usb_phy_tx_dp_i
  41. ,input usb_phy_tx_dn_i
  42. ,input usb_phy_tx_oen_i
  43. ,input mode_i
  44. // Outputs
  45. ,inout usb_dp_io
  46. ,inout usb_dn_io
  47. ,output usb_phy_rx_rcv_o
  48. ,output usb_phy_rx_dp_o
  49. ,output usb_phy_rx_dn_o
  50. );
  51. //-----------------------------------------------------------------
  52. // Module: usb_transceiver
  53. // Emulate standard USB PHY interface and produce a D+/D- outputs.
  54. // Allows direct connection of USB port to FPGA.
  55. // Limitations:
  56. // As no differential amplifier present, no common mode noise
  57. // rejection occurs.
  58. // Unlikely to work well with longer connections!
  59. //-----------------------------------------------------------------
  60. //-----------------------------------------------------------------
  61. // Wires
  62. //-----------------------------------------------------------------
  63. reg out_dp;
  64. reg out_dn;
  65. //-----------------------------------------------------------------
  66. // Assignments
  67. //-----------------------------------------------------------------
  68. // D+/D- Tristate buffers
  69. assign usb_dp_io = (usb_phy_tx_oen_i == 1'b0) ? out_dp : 1'bz;
  70. assign usb_dn_io = (usb_phy_tx_oen_i == 1'b0) ? out_dn : 1'bz;
  71. // Receive D+/D-
  72. assign usb_phy_rx_dp_o = usb_dp_io;
  73. assign usb_phy_rx_dn_o = usb_dn_io;
  74. // Receive output
  75. assign usb_phy_rx_rcv_o = (usb_dp_io == 1'b1 && usb_dn_io == 1'b0) ? 1'b1 : 1'b0;
  76. // PHY Transmit Mode:
  77. // When phy_tx_mode_i is '0' the outputs are encoded as:
  78. // vmo_i, vpo_i
  79. // 0 0 Differential Logic '0'
  80. // 0 1 Differential Logic '1'
  81. // 1 0 Single Ended '0'
  82. // 1 1 Single Ended '0'
  83. // When phy_tx_mode_i is '1' the outputs are encoded as:
  84. // vmo_i, vpo_i
  85. // 0 0 Single Ended '0'
  86. // 0 1 Differential Logic '1'
  87. // 1 0 Differential Logic '0'
  88. // 1 1 Illegal State
  89. always @ (mode_i or usb_phy_tx_dp_i or usb_phy_tx_dn_i)
  90. begin : MUX
  91. case(mode_i)
  92. 1'b0:
  93. begin
  94. if (usb_phy_tx_dp_i == 1'b0 && usb_phy_tx_dn_i == 1'b0)
  95. begin
  96. // Logic "0"
  97. out_dp = 1'b0;
  98. out_dn = 1'b1;
  99. end
  100. else if (usb_phy_tx_dp_i == 1'b0 && usb_phy_tx_dn_i == 1'b1)
  101. begin
  102. // SE0 (both low)
  103. out_dp = 1'b0;
  104. out_dn = 1'b0;
  105. end
  106. else if (usb_phy_tx_dp_i == 1'b1 && usb_phy_tx_dn_i == 1'b0)
  107. begin
  108. // Logic "1"
  109. out_dp = 1'b1;
  110. out_dn = 1'b0;
  111. end
  112. else if (usb_phy_tx_dp_i == 1'b1 && usb_phy_tx_dn_i == 1'b1)
  113. begin
  114. // SE0 (both low)
  115. out_dp = 1'b0;
  116. out_dn = 1'b0;
  117. end
  118. end
  119. 1'b1 :
  120. begin
  121. if (usb_phy_tx_dp_i == 1'b0 && usb_phy_tx_dn_i == 1'b0)
  122. begin
  123. // SE0 (both low)
  124. out_dp = 1'b0;
  125. out_dn = 1'b0;
  126. end
  127. else if (usb_phy_tx_dp_i == 1'b0 && usb_phy_tx_dn_i == 1'b1)
  128. begin
  129. // Logic "0"
  130. out_dp = 1'b0;
  131. out_dn = 1'b1;
  132. end
  133. else if (usb_phy_tx_dp_i == 1'b1 && usb_phy_tx_dn_i == 1'b0)
  134. begin
  135. // Logic "1"
  136. out_dp = 1'b1;
  137. out_dn = 1'b0;
  138. end
  139. else if (usb_phy_tx_dp_i == 1'b1 && usb_phy_tx_dn_i == 1'b1)
  140. begin
  141. // Illegal
  142. out_dp = 1'b1;
  143. out_dn = 1'b1;
  144. end
  145. end
  146. endcase
  147. end
  148. endmodule