iodevs.vh 5.1 KB

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