iodevs.vh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 XDEV_ADDR_BITS = 'h00000002; // 2
  10. localparam XDEV_ADDR_SHIFT = 'h0000001c; // 28
  11. localparam _PC_IRQ = 'h00000020; // 32
  12. localparam _PC_RESET = 'h00000010; // 16
  13. reg [31:0] nxdev_rdata;
  14. reg [31:0] iodev_rdata;
  15. wire [ 3:0] xdev_valid = iodev_mem_valid << cpu_mem_addr[29:28];
  16. wire [15:0] iodev_valid = xdev_valid[3] << cpu_mem_addr[10:7];
  17. wire [31:0] iodev_rdata_sys;
  18. wire [ 0:0] iodev_valid_sys = iodev_valid[0:0];
  19. tri1 [ 0:0] iodev_wait_n_sys;
  20. wire [31:0] iodev_rdata_sysclock;
  21. wire [ 0:0] iodev_irq_sysclock;
  22. wire [ 0:0] iodev_valid_sysclock = iodev_valid[1:1];
  23. tri1 [ 0:0] iodev_wait_n_sysclock;
  24. wire [31:0] iodev_rdata_console;
  25. wire [ 0:0] iodev_irq_console;
  26. wire [ 0:0] iodev_valid_console = iodev_valid[2:2];
  27. tri1 [ 0:0] iodev_wait_n_console;
  28. wire [31:0] iodev_rdata_romcopy;
  29. wire [ 0:0] iodev_irq_romcopy;
  30. wire [ 0:0] iodev_valid_romcopy = iodev_valid[3:3];
  31. tri1 [ 0:0] iodev_wait_n_romcopy;
  32. wire [31:0] iodev_rdata_sdcard;
  33. wire [ 0:0] iodev_irq_sdcard;
  34. wire [ 0:0] iodev_valid_sdcard = iodev_valid[4:4];
  35. tri1 [ 0:0] iodev_wait_n_sdcard;
  36. wire [31:0] iodev_rdata_i2c;
  37. wire [ 0:0] iodev_irq_i2c;
  38. wire [ 0:0] iodev_valid_i2c = iodev_valid[5:5];
  39. tri1 [ 0:0] iodev_wait_n_i2c;
  40. wire [31:0] iodev_rdata_esp;
  41. wire [ 0:0] iodev_irq_esp;
  42. wire [ 0:0] iodev_valid_esp = iodev_valid[6:6];
  43. tri1 [ 0:0] iodev_wait_n_esp;
  44. wire [31:0] iodev_rdata_abc;
  45. wire [ 0:0] iodev_irq_abc;
  46. wire [ 0:0] iodev_valid_abc = iodev_valid[7:7];
  47. tri1 [ 0:0] iodev_wait_n_abc;
  48. wire [31:0] iodev_rdata_abcmemmap;
  49. wire [ 0:0] iodev_valid_abcmemmap = xdev_valid[0:0];
  50. tri1 [ 0:0] iodev_wait_n_abcmemmap;
  51. // I/O input MUX
  52. always_comb
  53. case (cpu_mem_addr[29:28])
  54. 2'd0: iodev_rdata = iodev_rdata_abcmemmap;
  55. 2'd3:
  56. case (cpu_mem_addr[10:7])
  57. 4'd0: iodev_rdata = iodev_rdata_sys;
  58. 4'd1: iodev_rdata = iodev_rdata_sysclock;
  59. 4'd2: iodev_rdata = iodev_rdata_console;
  60. 4'd3: iodev_rdata = iodev_rdata_romcopy;
  61. 4'd4: iodev_rdata = iodev_rdata_sdcard;
  62. 4'd5: iodev_rdata = iodev_rdata_i2c;
  63. 4'd6: iodev_rdata = iodev_rdata_esp;
  64. 4'd7: iodev_rdata = iodev_rdata_abc;
  65. default: iodev_rdata = 32'hxxxxxxxx;
  66. endcase
  67. default: iodev_rdata = 32'hxxxxxxxx;
  68. endcase
  69. tri0 [31:0] sys_irq;
  70. assign sys_irq[ 3] = iodev_irq_sysclock[0];
  71. assign sys_irq[ 4] = iodev_irq_console[0];
  72. assign sys_irq[ 5] = iodev_irq_romcopy[0];
  73. assign sys_irq[ 6] = iodev_irq_sdcard[0];
  74. assign sys_irq[ 7] = iodev_irq_i2c[0];
  75. assign sys_irq[ 8] = iodev_irq_esp[0];
  76. assign sys_irq[ 9] = iodev_irq_abc[0];
  77. localparam [31:0] irq_edge_mask = 32'h00000008;
  78. localparam [31:0] irq_masked = ~32'h000003ff;
  79. wire iodev_wait_n = (&iodev_wait_n_sys) &
  80. (&iodev_wait_n_sysclock) &
  81. (&iodev_wait_n_console) &
  82. (&iodev_wait_n_romcopy) &
  83. (&iodev_wait_n_sdcard) &
  84. (&iodev_wait_n_i2c) &
  85. (&iodev_wait_n_esp) &
  86. (&iodev_wait_n_abc) &
  87. (&iodev_wait_n_abcmemmap);