iodevs.vh 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. localparam IODEV_ADDR_BITS = 'h00000004; // 4
  2. localparam IODEV_ADDR_SHIFT = 'h00000007; // 7
  3. localparam SDRAM_ADDR = 'h40000000; // 1073741824
  4. localparam SDRAM_BITS = 'h00000019; // 25
  5. localparam SRAM_ADDR = 'h00000000; // 0
  6. localparam SRAM_BITS = 'h0000000f; // 15
  7. localparam SYS_MAGIC_MAX80 = 'h3858414d; // 945307981
  8. localparam TIMER_SHIFT = 'h00000005; // 5
  9. localparam TTY_CHANNELS = 'h00000002; // 2
  10. localparam XDEV_ADDR_BITS = 'h00000002; // 2
  11. localparam XDEV_ADDR_SHIFT = 'h0000001c; // 28
  12. localparam _PC_IRQ = 'h00000020; // 32
  13. localparam _PC_RESET = 'h00000010; // 16
  14. reg [31:0] nxdev_rdata;
  15. reg [31:0] iodev_rdata;
  16. wire [ 3:0] xdev_valid = iodev_mem_valid << cpu_mem_addr[29:28];
  17. wire [15:0] iodev_valid = xdev_valid[3] << cpu_mem_addr[10:7];
  18. wire [31:0] iodev_rdata_sys;
  19. wire [ 0:0] iodev_valid_sys = iodev_valid[0:0];
  20. localparam [31:0] iodev_sys_base = 32'hfffff800;
  21. tri1 [ 0:0] iodev_wait_n_sys;
  22. wire [31:0] iodev_rdata_abc;
  23. wire [ 0:0] iodev_irq_abc;
  24. wire [ 0:0] iodev_valid_abc = iodev_valid[1:1];
  25. localparam [31:0] iodev_abc_base = 32'hfffff880;
  26. tri1 [ 0:0] iodev_wait_n_abc;
  27. wire [31:0] iodev_rdata_abcmemmap;
  28. wire [ 0:0] iodev_valid_abcmemmap = xdev_valid[0:0];
  29. localparam [31:0] iodev_abcmemmap_base = 32'hc0000000;
  30. tri1 [ 0:0] iodev_wait_n_abcmemmap;
  31. wire [31:0] iodev_rdata_sysclock;
  32. wire [ 0:0] iodev_irq_sysclock;
  33. wire [ 0:0] iodev_valid_sysclock = iodev_valid[2:2];
  34. localparam [31:0] iodev_sysclock_base = 32'hfffff900;
  35. tri1 [ 0:0] iodev_wait_n_sysclock;
  36. wire [31:0] iodev_rdata_tty;
  37. wire [ 1:0] iodev_irq_tty;
  38. wire [ 0:0] iodev_valid_tty = iodev_valid[3:3];
  39. localparam [31:0] iodev_tty_base = 32'hfffff980;
  40. tri1 [ 0:0] iodev_wait_n_tty;
  41. wire [31:0] iodev_rdata_usbdesc;
  42. wire [ 0:0] iodev_valid_usbdesc = xdev_valid[1:1];
  43. localparam [31:0] iodev_usbdesc_base = 32'hd0000000;
  44. tri1 [ 0:0] iodev_wait_n_usbdesc;
  45. wire [31:0] iodev_rdata_romcopy;
  46. wire [ 0:0] iodev_irq_romcopy;
  47. wire [ 0:0] iodev_valid_romcopy = iodev_valid[4:4];
  48. localparam [31:0] iodev_romcopy_base = 32'hfffffa00;
  49. tri1 [ 0:0] iodev_wait_n_romcopy;
  50. wire [31:0] iodev_rdata_sdcard;
  51. wire [ 0:0] iodev_irq_sdcard;
  52. wire [ 0:0] iodev_valid_sdcard = iodev_valid[5:5];
  53. localparam [31:0] iodev_sdcard_base = 32'hfffffa80;
  54. tri1 [ 0:0] iodev_wait_n_sdcard;
  55. wire [31:0] iodev_rdata_i2c;
  56. wire [ 0:0] iodev_irq_i2c;
  57. wire [ 0:0] iodev_valid_i2c = iodev_valid[6:6];
  58. localparam [31:0] iodev_i2c_base = 32'hfffffb00;
  59. tri1 [ 0:0] iodev_wait_n_i2c;
  60. wire [31:0] iodev_rdata_esp;
  61. wire [ 0:0] iodev_irq_esp;
  62. wire [ 0:0] iodev_valid_esp = iodev_valid[7:7];
  63. localparam [31:0] iodev_esp_base = 32'hfffffb80;
  64. tri1 [ 0:0] iodev_wait_n_esp;
  65. wire [31:0] iodev_rdata_random;
  66. wire [ 0:0] iodev_irq_random;
  67. wire [ 0:0] iodev_valid_random = iodev_valid[8:8];
  68. localparam [31:0] iodev_random_base = 32'hfffffc00;
  69. tri1 [ 0:0] iodev_wait_n_random;
  70. wire [31:0] iodev_rdata_vjtag;
  71. wire [ 0:0] iodev_irq_vjtag;
  72. wire [ 0:0] iodev_valid_vjtag = iodev_valid[9:9];
  73. localparam [31:0] iodev_vjtag_base = 32'hfffffc80;
  74. tri1 [ 0:0] iodev_wait_n_vjtag;
  75. // I/O input MUX
  76. always_comb
  77. case (cpu_mem_addr[29:28])
  78. 2'd0: iodev_rdata = iodev_rdata_abcmemmap;
  79. 2'd1: iodev_rdata = iodev_rdata_usbdesc;
  80. 2'd3:
  81. case (cpu_mem_addr[10:7])
  82. 4'd0: iodev_rdata = iodev_rdata_sys;
  83. 4'd1: iodev_rdata = iodev_rdata_abc;
  84. 4'd2: iodev_rdata = iodev_rdata_sysclock;
  85. 4'd3: iodev_rdata = iodev_rdata_tty;
  86. 4'd4: iodev_rdata = iodev_rdata_romcopy;
  87. 4'd5: iodev_rdata = iodev_rdata_sdcard;
  88. 4'd6: iodev_rdata = iodev_rdata_i2c;
  89. 4'd7: iodev_rdata = iodev_rdata_esp;
  90. 4'd8: iodev_rdata = iodev_rdata_random;
  91. 4'd9: iodev_rdata = iodev_rdata_vjtag;
  92. default: iodev_rdata = 32'hxxxxxxxx;
  93. endcase
  94. default: iodev_rdata = 32'hxxxxxxxx;
  95. endcase
  96. tri0 [31:0] sys_irq;
  97. assign sys_irq[ 3] = iodev_irq_abc[0];
  98. assign sys_irq[ 4] = iodev_irq_sysclock[0];
  99. assign sys_irq[ 5] = iodev_irq_tty[0];
  100. assign sys_irq[ 6] = iodev_irq_tty[1];
  101. assign sys_irq[ 7] = iodev_irq_romcopy[0];
  102. assign sys_irq[ 8] = iodev_irq_sdcard[0];
  103. assign sys_irq[ 9] = iodev_irq_i2c[0];
  104. assign sys_irq[10] = iodev_irq_esp[0];
  105. assign sys_irq[11] = iodev_irq_random[0];
  106. assign sys_irq[12] = iodev_irq_vjtag[0];
  107. localparam [31:0] irq_edge_mask = 32'h00001010;
  108. localparam [31:0] irq_masked = ~32'h00001fff;
  109. wire iodev_wait_n = (&iodev_wait_n_sys) &
  110. (&iodev_wait_n_abc) &
  111. (&iodev_wait_n_abcmemmap) &
  112. (&iodev_wait_n_sysclock) &
  113. (&iodev_wait_n_tty) &
  114. (&iodev_wait_n_usbdesc) &
  115. (&iodev_wait_n_romcopy) &
  116. (&iodev_wait_n_sdcard) &
  117. (&iodev_wait_n_i2c) &
  118. (&iodev_wait_n_esp) &
  119. (&iodev_wait_n_random) &
  120. (&iodev_wait_n_vjtag);