2
0

ioregs.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #ifndef IODEV_H
  2. #define IODEV_H
  3. #include "compiler.h"
  4. #include "iodevs.h"
  5. /* Address for I/O device d, subregister r, offset o */
  6. #define IODEVA(b,r,o) ((b ## _BASE)+((r) << 2)+(o))
  7. #ifdef __ASSEMBLY__
  8. /*
  9. * The I/O device range is designed so that it can be addressed via
  10. * negative offsets from the zero register, so no explicit base
  11. * pointer register is necesary.
  12. */
  13. #define IODEVV(d,r) IODEVA(d,r,0)(zero)
  14. #define IODEVB(d,r) IODEVV(d,r,0)
  15. #define IODEVH(d,r) IODEVV(d,r,0)
  16. #define IODEVL(d,r) IODEVV(d,r,0)
  17. #define PTR(x) x
  18. #else
  19. /* Writable registers */
  20. #define IODEVV(d,r) (*(volatile void *)IODEVA(d,r,0))
  21. #define IODEVB(d,r) (*(volatile uint8_t *)IODEVA(d,r,0))
  22. #define IODEVB0(d,r) (*(volatile uint8_t *)IODEVA(d,r,0))
  23. #define IODEVB1(d,r) (*(volatile uint8_t *)IODEVA(d,r,1))
  24. #define IODEVB2(d,r) (*(volatile uint8_t *)IODEVA(d,r,2))
  25. #define IODEVB3(d,r) (*(volatile uint8_t *)IODEVA(d,r,3))
  26. #define IODEVH(d,r) (*(volatile uint16_t *)IODEVA(d,r,0))
  27. #define IODEVH0(d,r) (*(volatile uint16_t *)IODEVA(d,r,0))
  28. #define IODEVH1(d,r) (*(volatile uint16_t *)IODEVA(d,r,2))
  29. #define IODEVL(d,r) (*(volatile uint32_t *)IODEVA(d,r,0))
  30. /* Readonly registers */
  31. #define IODEVRV(d,r) (*(const volatile void *)IODEVA(d,r,0))
  32. #define IODEVRB(d,r) (*(const volatile uint8_t *)IODEVA(d,r,0))
  33. #define IODEVRB0(d,r) (*(const volatile uint8_t *)IODEVA(d,r,0))
  34. #define IODEVRB1(d,r) (*(const volatile uint8_t *)IODEVA(d,r,1))
  35. #define IODEVRB2(d,r) (*(const volatile uint8_t *)IODEVA(d,r,2))
  36. #define IODEVRB3(d,r) (*(const volatile uint8_t *)IODEVA(d,r,3))
  37. #define IODEVRH(d,r) (*(const volatile uint16_t *)IODEVA(d,r,0))
  38. #define IODEVRH0(d,r) (*(const volatile uint16_t *)IODEVA(d,r,0))
  39. #define IODEVRH1(d,r) (*(const volatile uint16_t *)IODEVA(d,r,2))
  40. #define IODEVRL(d,r) (*(const volatile uint32_t *)IODEVA(d,r,0))
  41. #define PTR(x) (&(x))
  42. #endif
  43. #define CPU_HZ 84000000
  44. #define TIMER_HZ (1 << TIMER_SHIFT)
  45. /* Basic system registers */
  46. #define SYS_MAGIC IODEVRL(SYS,0)
  47. #define SYS_BOARDCFG IODEVRL(SYS,1)
  48. #define SYS_BOARDFIX IODEVRB0(SYS,1)
  49. #define SYS_BOARDMINOR IODEVRB1(SYS,1)
  50. #define SYS_BOARDMAJOR IODEVRB2(SYS,1)
  51. #define SYS_BOARDFPGA IODEVRB3(SYS,1)
  52. #define SYS_LED IODEVL(SYS,2)
  53. #define SYS_RESET IODEVL(SYS,3)
  54. #define SYS_RESET_SOFT 1
  55. #define SYS_RESET_HARD 2
  56. #define SYS_RESET_RECONFIG 3
  57. #define ROMCOPY_RAMADDR IODEVL(ROMCOPY,0)
  58. #define ROMCOPY_ROMCMD IODEVL(ROMCOPY,1)
  59. #define ROMCOPY_DATALEN IODEVL(ROMCOPY,2)
  60. #define ROMCOPY_SPI_CMDLEN(x) ((x) << 24)
  61. #define ROMCOPY_ZERO_BUFFER ROMCOPY_SPI_CMDLEN(0)
  62. #define ROMCOPY_SPI_DUAL (1 << 27)
  63. #define ROMCOPY_SPI_MORE (1 << 28)
  64. #define ROMCOPY_WRITE_RAM (1 << 29)
  65. #define ROMCOPY_STATUS IODEVRL(ROMCOPY,3)
  66. #define ROMCOPY_INPUT IODEVRL(ROMCOPY,4)
  67. #define ROMCOPY_STATUS_DONE 1
  68. #define CON_DATA IODEVB(CONSOLE,0)
  69. #define CON_WATERCTL IODEVL(CONSOLE,1)
  70. #define CON_WATERCTL_TX_LOW(x) ((x) << 0)
  71. #define CON_WATERCTL_TX_HIGH(x) ((x) << 4)
  72. #define CON_WATERCTL_RX_LOW(x) ((x) << 8)
  73. #define CON_WATERCTL_RX_HIGH(x) ((x) << 12)
  74. #define CON_STATUS IODEVL(CONSOLE,2)
  75. #define CON_STATUS_TX_EMPTY 0x0001
  76. #define CON_STATUS_TX_LOW 0x0002
  77. #define CON_STATUS_TX_HIGH 0x0004
  78. #define CON_STATUS_TX_FULL 0x0008
  79. #define CON_STATUS_RX_EMPTY 0x0010
  80. #define CON_STATUS_RX_LOW 0x0020
  81. #define CON_STATUS_RX_HIGH 0x0040
  82. #define CON_STATUS_RX_FULL 0x0080
  83. #define CON_STATUS_RX_STALE 0x0100
  84. #define CON_STATUS_RX_BREAK 0x0200
  85. #define CON_STATUS_USB_CONFIG 0x0400
  86. #define CON_IRQEN IODEVL(CONSOLE,3)
  87. #define SDCARD_CTL IODEVL(SDCARD,0)
  88. #define SDCARD_CTL_SPEED IODEVB0(SDCARD,0)
  89. #define SDCARD_CTL_IRQEN IODEVB1(SDCARD,0)
  90. #define SDCARD_CTL_CLRCRC IODEVB2(SDCARD,0)
  91. #define SDCARD_CRC7_RD IODEVRB0(SDCARD,4)
  92. #define SDCARD_CRC16_RD IODEVRH1(SDCARD,4)
  93. #define SDCARD_CRC7_WR IODEVRB0(SDCARD,5)
  94. #define SDCARD_CRC16_WR IODEVRH1(SDCARD,5)
  95. #define SDCARD_IRQ_READY 1
  96. #define SDCARD_IRQ_CD 2
  97. #define SDCARD_IRQ_EXT 4
  98. /* Speed values, not including -1 adjustment */
  99. #define SD_SLOW 128 /* 328 kHz */
  100. #define SD_20MHZ 3 /* Really 14 MHz */
  101. #define SD_25MHZ 2 /* Really 21 MHz */
  102. #define SD_50MHZ 1 /* Really 42 MHz */
  103. #define I2C_WDATA IODEVL(I2C,0)
  104. #define I2C_WDATA_DATA IODEVB1(I2C,0)
  105. #define I2C_RDATA IODEVL(I2C,1)
  106. #define I2C_RDATA_DATA IODEVB1(I2C,1)
  107. #define I2C_BUSY 1
  108. #define I2C_SR 2
  109. #define I2C_P 4
  110. #define I2C_DUMMY 6
  111. #define I2C_STARTED 0x10
  112. #define I2C_SCL 0x20
  113. #define I2C_SDA 0x40
  114. #define I2C_NAK 0x80
  115. #define I2C_DIVISOR IODEVL(I2C,2)
  116. #define SYSCLOCK_DATETIME IODEVL(SYSCLOCK,0)
  117. #define SYSCLOCK_TICK IODEVL(SYSCLOCK,1)
  118. #define SYSCLOCK_TICK_HOLD IODEVH0(SYSCLOCK,1)
  119. #define SYSCLOCK_TICK_NOW IODEVH1(SYSCLOCK,1)
  120. #define ABC_STATUS IODEVL(ABC,0)
  121. #define ABC_STATUS_LIVE 1
  122. #define ABC_STATUS_RST 2
  123. #define ABC_STATUS_800 4
  124. #define ABC_IOSEL IODEVL(ABC,1)
  125. #define ABC_IOSEL_INVALID 0x100
  126. #define ABC_BUSY IODEVL(ABC,2)
  127. #define ABC_BUSY_STATUS IODEVH0(ABC,2)
  128. #define ABC_BUSY_MASK IODEVH1(ABC,2)
  129. #define ABC_BUSY_OUT 0x00ff
  130. #define ABC_BUSY_INP 0x0300
  131. #define ABC_BUSY_BUSCHG 0xf000
  132. #define ABC_BUSCTL IODEVL(ABC,3)
  133. #define ABC_BUSCTL_WAIT 1
  134. #define ABC_BUSCTL_INT 2
  135. #define ABC_BUSCTL_NMI 4
  136. #define ABC_BUSCTL_RESET 8
  137. #define ABC_OUT IODEVL(ABC,4)
  138. #define ABC_OUT_DATA IODEVB0(ABC,4)
  139. #define ABC_OUT_ADDR IODEVB1(ABC,4)
  140. #define ABC_INP IODEVL(ABC,5)
  141. #define ABC_INP0_DATA IODEVB0(ABC,5)
  142. #define ABC_INP1_DATA IODEVB1(ABC,5)
  143. #define ABC_INP_ENABLE IODEVB2(ABC,5)
  144. #define ABCMEMMAP_PAGE(n) IODEVL(ABCMEMMAP,n)
  145. #define ABCMEMMAP_WRPORT(n) IODEVL(ABCMEMMAP,128+((n) << 1))
  146. #define ABCMEMMAP_RDPORT(n) IODEVL(ABCMEMMAP,129+((n) << 1))
  147. #define ABCMEMMAP_WRCOUNT(n) IODEVL(ABCMEMMAP,384+((n) << 1))
  148. #define ABCMEMMAP_RDCOUNT(n) IODEVL(ABCMEMMAP,385+((n) << 1))
  149. #define ABCMEMMAP_WR (1 << 30)
  150. #define ABCMEMMAP_RD (1 << 31)
  151. #define ABCMEMMAP_STATUS(n) IODEVL(ABCMEMMAP,512+(n))
  152. #define ABCMEMMAP_CLR7DMA 0x800
  153. #define ABCMEMMAP_CLR1WEMP 0x400
  154. #define ABCMEMMAP_CLR0WEMP 0x200
  155. #define ABCMEMMAP_CLR0REMP 0x100
  156. #define RANDOM_DATA IODEVRL(RANDOM,0)
  157. #define USBDESC_ROM IODEVL(USBDESC,0)
  158. #define usbdesc_rom PTR(USBDESC_ROM)
  159. #endif /* IODEV_H */