2
0

iodevs.vh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. tri1 [ 0:0] iodev_wait_n_sys;
  21. wire [31:0] iodev_rdata_abc;
  22. wire [ 0:0] iodev_irq_abc;
  23. wire [ 0:0] iodev_valid_abc = iodev_valid[1:1];
  24. tri1 [ 0:0] iodev_wait_n_abc;
  25. wire [31:0] iodev_rdata_abcmemmap;
  26. wire [ 0:0] iodev_valid_abcmemmap = xdev_valid[0:0];
  27. tri1 [ 0:0] iodev_wait_n_abcmemmap;
  28. wire [31:0] iodev_rdata_sysclock;
  29. wire [ 0:0] iodev_irq_sysclock;
  30. wire [ 0:0] iodev_valid_sysclock = iodev_valid[2:2];
  31. tri1 [ 0:0] iodev_wait_n_sysclock;
  32. wire [31:0] iodev_rdata_tty;
  33. wire [ 1:0] iodev_irq_tty;
  34. wire [ 0:0] iodev_valid_tty = iodev_valid[3:3];
  35. tri1 [ 0:0] iodev_wait_n_tty;
  36. wire [31:0] iodev_rdata_usbdesc;
  37. wire [ 0:0] iodev_valid_usbdesc = xdev_valid[1:1];
  38. tri1 [ 0:0] iodev_wait_n_usbdesc;
  39. wire [31:0] iodev_rdata_romcopy;
  40. wire [ 0:0] iodev_irq_romcopy;
  41. wire [ 0:0] iodev_valid_romcopy = iodev_valid[4:4];
  42. tri1 [ 0:0] iodev_wait_n_romcopy;
  43. wire [31:0] iodev_rdata_sdcard;
  44. wire [ 0:0] iodev_irq_sdcard;
  45. wire [ 0:0] iodev_valid_sdcard = iodev_valid[5:5];
  46. tri1 [ 0:0] iodev_wait_n_sdcard;
  47. wire [31:0] iodev_rdata_i2c;
  48. wire [ 0:0] iodev_irq_i2c;
  49. wire [ 0:0] iodev_valid_i2c = iodev_valid[6:6];
  50. tri1 [ 0:0] iodev_wait_n_i2c;
  51. wire [31:0] iodev_rdata_esp;
  52. wire [ 0:0] iodev_irq_esp;
  53. wire [ 0:0] iodev_valid_esp = iodev_valid[7:7];
  54. tri1 [ 0:0] iodev_wait_n_esp;
  55. wire [31:0] iodev_rdata_random;
  56. wire [ 0:0] iodev_irq_random;
  57. wire [ 0:0] iodev_valid_random = iodev_valid[8:8];
  58. tri1 [ 0:0] iodev_wait_n_random;
  59. wire [31:0] iodev_rdata_vjtag;
  60. wire [ 0:0] iodev_irq_vjtag;
  61. wire [ 0:0] iodev_valid_vjtag = iodev_valid[9:9];
  62. tri1 [ 0:0] iodev_wait_n_vjtag;
  63. // I/O input MUX
  64. always_comb
  65. case (cpu_mem_addr[29:28])
  66. 2'd0: iodev_rdata = iodev_rdata_abcmemmap;
  67. 2'd1: iodev_rdata = iodev_rdata_usbdesc;
  68. 2'd3:
  69. case (cpu_mem_addr[10:7])
  70. 4'd0: iodev_rdata = iodev_rdata_sys;
  71. 4'd1: iodev_rdata = iodev_rdata_abc;
  72. 4'd2: iodev_rdata = iodev_rdata_sysclock;
  73. 4'd3: iodev_rdata = iodev_rdata_tty;
  74. 4'd4: iodev_rdata = iodev_rdata_romcopy;
  75. 4'd5: iodev_rdata = iodev_rdata_sdcard;
  76. 4'd6: iodev_rdata = iodev_rdata_i2c;
  77. 4'd7: iodev_rdata = iodev_rdata_esp;
  78. 4'd8: iodev_rdata = iodev_rdata_random;
  79. 4'd9: iodev_rdata = iodev_rdata_vjtag;
  80. default: iodev_rdata = 32'hxxxxxxxx;
  81. endcase
  82. default: iodev_rdata = 32'hxxxxxxxx;
  83. endcase
  84. tri0 [31:0] sys_irq;
  85. assign sys_irq[ 3] = iodev_irq_abc[0];
  86. assign sys_irq[ 4] = iodev_irq_sysclock[0];
  87. assign sys_irq[ 5] = iodev_irq_tty[0];
  88. assign sys_irq[ 6] = iodev_irq_tty[1];
  89. assign sys_irq[ 7] = iodev_irq_romcopy[0];
  90. assign sys_irq[ 8] = iodev_irq_sdcard[0];
  91. assign sys_irq[ 9] = iodev_irq_i2c[0];
  92. assign sys_irq[10] = iodev_irq_esp[0];
  93. assign sys_irq[11] = iodev_irq_random[0];
  94. assign sys_irq[12] = iodev_irq_vjtag[0];
  95. localparam [31:0] irq_edge_mask = 32'h00001010;
  96. localparam [31:0] irq_masked = ~32'h00001fff;
  97. wire iodev_wait_n = (&iodev_wait_n_sys) &
  98. (&iodev_wait_n_abc) &
  99. (&iodev_wait_n_abcmemmap) &
  100. (&iodev_wait_n_sysclock) &
  101. (&iodev_wait_n_tty) &
  102. (&iodev_wait_n_usbdesc) &
  103. (&iodev_wait_n_romcopy) &
  104. (&iodev_wait_n_sdcard) &
  105. (&iodev_wait_n_i2c) &
  106. (&iodev_wait_n_esp) &
  107. (&iodev_wait_n_random) &
  108. (&iodev_wait_n_vjtag);