ioregs.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #define LED IODEVB(LED,0)
  43. #define RESET_CMD IODEVL(RESET,0)
  44. #define ROMCOPY_DONE IODEVRL(ROMCOPY,0)
  45. #define CON_DATA IODEVB(CONSOLE,0)
  46. #define CON_BAUDDIV IODEVL(CONSOLE,1)
  47. #define CON_BAUD_BASE (CPU_HZ >> 4)
  48. #define CON_BAUD_BITS 24
  49. #define CON_STATUS IODEVRL(CONSOLE,2)
  50. #define CON_IRQEN IODEVL(CONSOLE,3)
  51. #define SDCARD_CTL IODEVL(SDCARD,0)
  52. #define SDCARD_CTL_SPEED IODEVB0(SDCARD,0)
  53. #define SDCARD_CTL_CLRCRC IODEVB1(SDCARD,0)
  54. #define SDCARD_CRC7_RD IODEVRB0(SDCARD,4)
  55. #define SDCARD_CRC16_RD IODEVRH1(SDCARD,4)
  56. #define SDCARD_CRC7_WR IODEVRB0(SDCARD,5)
  57. #define SDCARD_CRC16_WR IODEVRH1(SDCARD,5)
  58. /* Speed values, not including -1 adjustment */
  59. #define SD_SLOW 128 /* 328 kHz */
  60. #define SD_20MHZ 3 /* Really 14 MHz */
  61. #define SD_25MHZ 2 /* Really 21 MHz */
  62. #define SD_50MHZ 1 /* Really 42 MHz */
  63. #define SYSCLOCK_DATETIME IODEVL(SYSCLOCK,0)
  64. #define SYSCLOCK_TICK IODEVL(SYSCLOCK,1)
  65. #define SYSCLOCK_TICK_HOLD IODEVH0(SYSCLOCK,1)
  66. #define SYSCLOCK_TICK_NOW IODEVH1(SYSCLOCK,1)
  67. #define ABCMEMMAP_PAGE(n) IODEVL(ABCMEMMAP,n)
  68. #define ABCMEMMAP_WR 0x10000
  69. #define ABCMEMMAP_RD 0x20000
  70. #endif /* IODEV_H */