2
0

v2.vh 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. //
  2. // Top level module for the FPGA on the MAX80 board by
  3. // Per Mårtensson and H. Peter Anvin
  4. //
  5. // MAX80 v2
  6. //
  7. module `TOP
  8. (
  9. // Clock oscillator
  10. input clock_16, // 16 MHz
  11. input board_id, // This better match the firmware
  12. // ABC-bus
  13. inout abc_clk, // ABC-bus 3 MHz clock
  14. inout [15:0] abc_a, // ABC address bus
  15. inout [7:0] abc_d, // ABC data bus
  16. output abc_d_oe, // Data bus inout enable
  17. inout abc_rst_n, // ABC bus reset strobe
  18. inout abc_cs_n, // ABC card select strobe
  19. inout [4:0] abc_out_n, // OUT, C1-C4 strobe
  20. inout [1:0] abc_inp_n, // INP, STATUS strobe
  21. inout abc_xmemfl_n, // Memory read strobe
  22. inout abc_xmemw800_n, // Memory write strobe (ABC800)
  23. inout abc_xmemw80_n, // Memory write strobe (ABC80)
  24. inout abc_xinpstb_n, // I/O read strobe (ABC800)
  25. inout abc_xoutpstb_n, // I/O write strobe (ABC80)
  26. // The following are inverted versus the bus IF
  27. // the corresponding MOSFETs are installed
  28. inout abc_rdy_x, // RDY = WAIT#
  29. inout abc_resin_x, // System reset request
  30. inout abc_int80_x, // System INT request (ABC80)
  31. inout abc_int800_x, // System INT request (ABC800)
  32. inout abc_nmi_x, // System NMI request (ABC800)
  33. inout abc_xm_x, // System memory override (ABC800)
  34. // Host/device control
  35. output abc_host, // 1 = host, 0 = target
  36. // ABC-bus extension header
  37. // (Note: cannot use an array here because HC and HH are
  38. // input only.)
  39. inout exth_ha,
  40. inout exth_hb,
  41. input exth_hc,
  42. inout exth_hd,
  43. inout exth_he,
  44. inout exth_hf,
  45. inout exth_hg,
  46. input exth_hh,
  47. // SDRAM bus
  48. output sr_clk,
  49. output [1:0] sr_ba, // Bank address
  50. output [12:0] sr_a, // Address within bank
  51. inout [15:0] sr_dq, // Also known as D or IO
  52. output [1:0] sr_dqm, // DQML and DQMH
  53. output sr_cs_n,
  54. output sr_we_n,
  55. output sr_cas_n,
  56. output sr_ras_n,
  57. // SD card
  58. input sd_cd_n,
  59. output sd_cs_n,
  60. output sd_clk,
  61. output sd_di,
  62. input sd_do,
  63. // SPI flash memory (also configuration)
  64. output flash_cs_n,
  65. output flash_sck,
  66. inout [1:0] flash_io,
  67. // SPI bus (connected to ESP32 so can be bidirectional)
  68. inout spi_clk, // ESP32 IO12
  69. inout [1:0] spi_io, // ESP32 IO13,IO11
  70. inout spi_cs_esp_n, // ESP32 IO10
  71. inout spi_cs_flash_n, // ESP32 IO01
  72. // Other ESP32 connections
  73. inout esp_io0, // ESP32 IO00
  74. inout esp_int, // ESP32 IO09
  75. // I2C bus (RTC and external)
  76. inout i2c_scl,
  77. inout i2c_sda,
  78. input rtc_32khz,
  79. input rtc_int_n,
  80. // LED (2 = D17/Y, 1 = D22/G, 0 = D23/B)
  81. output [2:0] led,
  82. // USB
  83. inout usb_dp,
  84. inout usb_dn,
  85. output usb_pu,
  86. input usb_rx,
  87. // GPIO
  88. inout [5:0] gpio,
  89. // HDMI
  90. output [2:0] hdmi_d,
  91. output hdmi_clk,
  92. inout hdmi_scl,
  93. inout hdmi_sda,
  94. inout hdmi_hpd,
  95. // Unconnected pins with pullups, used for randomness
  96. inout [2:0] rngio
  97. );
  98. // GPIO assignments for debug serial port:
  99. // gpio[0] - TxD
  100. // gpio[2] - RxD
  101. // gpio[4] - DTR#
  102. // Master PLL: 16 -> 336 MHz
  103. wire reset_plls;
  104. wire master_pll_locked;
  105. wire master_clk; // 336 MHz
  106. wire slow_clk; // 12 MHz
  107. pll2_16 pll2 (
  108. .areset ( reset_plls ),
  109. .locked ( master_pll_locked ),
  110. .inclk0 ( clock_16 ),
  111. .c0 ( master_clk ),
  112. .c1 ( slow_clk )
  113. );
  114. wire usb_clk;
  115. wire sys_clk;
  116. `MAIN #(.x_mosfet(6'b000000),
  117. .fpga_ver(8'd2))
  118. `MAIN (
  119. .master_clk ( master_clk ),
  120. .slow_clk ( slow_clk ),
  121. .master_pll_locked ( master_pll_locked ),
  122. .reset_plls ( reset_plls ),
  123. .board_id ( board_id ),
  124. .abc_clk ( abc_clk ),
  125. .abc_a ( abc_a ),
  126. .abc_d ( abc_d ),
  127. .abc_d_oe ( abc_d_oe ),
  128. .abc_rst_n ( abc_rst_n ),
  129. .abc_cs_n ( abc_cs_n ),
  130. .abc_out_n ( abc_out_n ),
  131. .abc_inp_n ( abc_inp_n ),
  132. .abc_xmemfl_n ( abc_xmemfl_n ),
  133. .abc_xmemw800_n ( abc_xmemw800_n ),
  134. .abc_xmemw80_n ( abc_xmemw80_n ),
  135. .abc_xinpstb_n ( abc_xinpstb_n ),
  136. .abc_xoutpstb_n ( abc_xoutpstb_n ),
  137. .abc_rdy_x ( abc_rdy_x ),
  138. .abc_resin_x ( abc_resin_x ),
  139. .abc_int80_x ( abc_int80_x ),
  140. .abc_int800_x ( abc_int800_x ),
  141. .abc_nmi_x ( abc_nmi_x ),
  142. .abc_xm_x ( abc_xm_x ),
  143. .abc_host ( abc_host ),
  144. .exth_ha ( exth_ha ),
  145. .exth_hb ( exth_hb ),
  146. .exth_hc ( exth_hc ),
  147. .exth_hd ( exth_hd ),
  148. .exth_he ( exth_he ),
  149. .exth_hf ( exth_hf ),
  150. .exth_hg ( exth_hg ),
  151. .exth_hh ( exth_hh ),
  152. .sr_clk ( sr_clk ),
  153. .sr_ba ( sr_ba ),
  154. .sr_a ( sr_a ),
  155. .sr_dq ( sr_dq ),
  156. .sr_dqm ( sr_dqm ),
  157. .sr_cs_n ( sr_cs_n ),
  158. .sr_we_n ( sr_we_n ),
  159. .sr_cas_n ( sr_cas_n ),
  160. .sr_ras_n ( sr_ras_n ),
  161. .sd_cd_n ( 1'b0 ), // Needs rework on my board
  162. .sd_cs_n ( sd_cs_n ),
  163. .sd_clk ( sd_clk ),
  164. .sd_di ( sd_di ),
  165. .sd_do ( sd_do ),
  166. .tty_txd ( gpio[0] ),
  167. .tty_rxd ( gpio[2] ),
  168. .tty_rts ( 1'b0 ),
  169. .tty_cts ( ),
  170. .tty_dtr ( gpio[4] ),
  171. .flash_cs_n ( flash_cs_n ),
  172. .flash_sck ( flash_sck ),
  173. .flash_io ( flash_io ),
  174. .spi_clk ( spi_clk ),
  175. .spi_io ( spi_io ),
  176. .spi_cs_esp_n ( spi_cs_esp_n ),
  177. .spi_cs_flash_n ( spi_cs_flash_n ),
  178. .esp_io0 ( esp_io0 ),
  179. .esp_int ( esp_int ),
  180. .i2c_scl ( i2c_scl ),
  181. .i2c_sda ( i2c_sda ),
  182. .rtc_32khz ( rtc_32khz ),
  183. .rtc_int_n ( rtc_int_n ),
  184. .led ( led ),
  185. .usb_dp ( usb_dp ),
  186. .usb_dn ( usb_dn ),
  187. .usb_rx ( usb_rx ),
  188. .usb_rx_ok ( 1'b1 ),
  189. .usb_pu ( usb_pu ),
  190. .hdmi_d ( hdmi_d ),
  191. .hdmi_clk ( hdmi_clk ),
  192. .hdmi_scl ( hdmi_scl ),
  193. .hdmi_sda ( hdmi_sda ),
  194. .hdmi_hpd ( hdmi_hpd ),
  195. .rngio ( rngio ),
  196. .sys_clk ( sys_clk ),
  197. .usb_clk ( usb_clk )
  198. );
  199. // sys_clk and usb_clk to GPIO
  200. clk_buf sys_clk_buf ( .clk ( sys_clk ), .pin ( gpio[1] ) );
  201. clk_buf usb_clk_buf ( .clk ( usb_clk ), .pin ( gpio[3] ) );
  202. // 4 Hz test signal on gpio[5], derived from sys_clk (84 MHz)
  203. reg [23:0] ctr_8hz;
  204. reg test_4hz;
  205. always @(posedge sys_clk)
  206. begin
  207. if (ctr_8hz >= 24'd10_500_000)
  208. begin
  209. ctr_8hz <= 24'd1;
  210. test_4hz <= ~test_4hz;
  211. end
  212. else
  213. begin
  214. ctr_8hz <= ctr_8hz + 1'b1;
  215. end
  216. end // always @ (posedge sys_clk)
  217. assign gpio[5] = test_4hz;
  218. endmodule // v2