ioregs.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #ifndef IODEV_H
  2. #define IODEV_H
  3. #include "iodevs.h"
  4. /* Address for I/O device d, subregister r, offset o */
  5. #define IODEVA(b,r,o) ((b ## _BASE)+((r) << 2)+(o))
  6. #ifdef __ASSEMBLY__
  7. /*
  8. * The I/O device range is designed so that it can be addressed via
  9. * negative offsets from the zero register, so no explicit base
  10. * pointer register is necesary.
  11. */
  12. #define IODEVV(d,r) IODEVA(d,r,0)(zero)
  13. #define IODEVB(d,r) IODEVV(d,r,0)
  14. #define IODEVH(d,r) IODEVV(d,r,0)
  15. #define IODEVL(d,r) IODEVV(d,r,0)
  16. #else
  17. #include <stdint.h>
  18. /* Writable registers */
  19. #define IODEVV(d,r) (*(volatile void *)IODEVA(d,r,0))
  20. #define IODEVB(d,r) (*(volatile uint8_t *)IODEVA(d,r,0))
  21. #define IODEVB0(d,r) (*(volatile uint8_t *)IODEVA(d,r,0))
  22. #define IODEVB1(d,r) (*(volatile uint8_t *)IODEVA(d,r,1))
  23. #define IODEVB2(d,r) (*(volatile uint8_t *)IODEVA(d,r,2))
  24. #define IODEVB3(d,r) (*(volatile uint8_t *)IODEVA(d,r,3))
  25. #define IODEVH(d,r) (*(volatile uint16_t *)IODEVA(d,r,0))
  26. #define IODEVH0(d,r) (*(volatile uint16_t *)IODEVA(d,r,0))
  27. #define IODEVH1(d,r) (*(volatile uint16_t *)IODEVA(d,r,2))
  28. #define IODEVL(d,r) (*(volatile uint32_t *)IODEVA(d,r,0))
  29. /* Readonly registers */
  30. #define IODEVRV(d,r) (*(const volatile void *)IODEVA(d,r,0))
  31. #define IODEVRB(d,r) (*(const volatile uint8_t *)IODEVA(d,r,0))
  32. #define IODEVRB0(d,r) (*(const volatile uint8_t *)IODEVA(d,r,0))
  33. #define IODEVRB1(d,r) (*(const volatile uint8_t *)IODEVA(d,r,1))
  34. #define IODEVRB2(d,r) (*(const volatile uint8_t *)IODEVA(d,r,2))
  35. #define IODEVRB3(d,r) (*(const volatile uint8_t *)IODEVA(d,r,3))
  36. #define IODEVRH(d,r) (*(const volatile uint16_t *)IODEVA(d,r,0))
  37. #define IODEVRH0(d,r) (*(const volatile uint16_t *)IODEVA(d,r,0))
  38. #define IODEVRH1(d,r) (*(const volatile uint16_t *)IODEVA(d,r,2))
  39. #define IODEVRL(d,r) (*(const volatile uint32_t *)IODEVA(d,r,0))
  40. #endif
  41. #define CPU_HZ 84000000
  42. /* Basic system registers */
  43. #define SYS_MAGIC IODEVL(SYS,0)
  44. #define SYS_BOARDCFG IODEVL(SYS,1)
  45. #define SYS_LED IODEVL(SYS,2)
  46. #define SYS_RESET IODEVL(SYS,3)
  47. #define SYS_ROMCOPY IODEVL(SYS,4)
  48. #define SYS_ROMCOPY_DONE 1
  49. #define CON_DATA IODEVB(CONSOLE,0)
  50. #define CON_BAUDDIV IODEVL(CONSOLE,1)
  51. #define CON_BAUD_BASE (CPU_HZ >> 4)
  52. #define CON_BAUD_BITS 24
  53. #define CON_STATUS IODEVRL(CONSOLE,2)
  54. #define CON_IRQEN IODEVL(CONSOLE,3)
  55. #define SDCARD_CTL IODEVL(SDCARD,0)
  56. #define SDCARD_CTL_SPEED IODEVB0(SDCARD,0)
  57. #define SDCARD_CTL_IRQEN IODEVB1(SDCARD,0)
  58. #define SDCARD_CTL_CLRCRC IODEVB2(SDCARD,0)
  59. #define SDCARD_CRC7_RD IODEVRB0(SDCARD,4)
  60. #define SDCARD_CRC16_RD IODEVRH1(SDCARD,4)
  61. #define SDCARD_CRC7_WR IODEVRB0(SDCARD,5)
  62. #define SDCARD_CRC16_WR IODEVRH1(SDCARD,5)
  63. #define SDCARD_IRQ_READY 1
  64. #define SDCARD_IRQ_CD 2
  65. #define SDCARD_IRQ_EXT 4
  66. /* Speed values, not including -1 adjustment */
  67. #define SD_SLOW 128 /* 328 kHz */
  68. #define SD_20MHZ 3 /* Really 14 MHz */
  69. #define SD_25MHZ 2 /* Really 21 MHz */
  70. #define SD_50MHZ 1 /* Really 42 MHz */
  71. #define I2C_WDATA IODEVL(I2C,0)
  72. #define I2C_RDATA IODEVL(I2C,1)
  73. #define I2C_DIVISOR IODEVL(I2C,2)
  74. #define I2C_BUSY 1
  75. #define I2C_SR 2
  76. #define I2C_P 4
  77. #define I2C_NAK 0x80
  78. #define SYSCLOCK_DATETIME IODEVL(SYSCLOCK,0)
  79. #define SYSCLOCK_TICK IODEVL(SYSCLOCK,1)
  80. #define SYSCLOCK_TICK_HOLD IODEVH0(SYSCLOCK,1)
  81. #define SYSCLOCK_TICK_NOW IODEVH1(SYSCLOCK,1)
  82. #define ABC_STATUS IODEVL(ABC,0)
  83. #define ABC_STATUS_LIVE 1
  84. #define ABC_STATUS_RST 2
  85. #define ABC_STATUS_800 4
  86. #define ABC_IOSEL IODEVL(ABC,1)
  87. #define ABC_IOBASE IODEVL(ABC,2)
  88. #define ABC_IOSTATUS IODEVL(ABC,3)
  89. #define ABC_OUTSTATUS IODEVB0(ABC,3)
  90. #define ABC_INPSTATUS IODEVB1(ABC,3)
  91. #define ABCMEMMAP_PAGE(n) IODEVL(ABCMEMMAP,n)
  92. #define ABCMEMMAP_WRPORT(n) IODEVL(ABCMEMMAP,128+((n) << 1))
  93. #define ABCMEMMAP_RDPORT(n) IODEVL(ABCMEMMAP,129+((n) << 1))
  94. #define ABCMEMMAP_WRCOUNT(n) IODEVL(ABCMEMMAP,384+((n) << 1))
  95. #define ABCMEMMAP_RDCOUNT(n) IODEVL(ABCMEMMAP,385+((n) << 1))
  96. #define ABCMEMMAP_WR (1 << 30)
  97. #define ABCMEMMAP_RD (1 << 31)
  98. #endif /* IODEV_H */