iodev.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #ifndef IODEV_H
  2. #define IODEV_H
  3. /* Address for I/O device d, subregister r, offset o */
  4. #define IODEVA(d,r,o) (0xfffff800+((d) << 7)+((r) << 2)+(o))
  5. #ifdef __ASSEMBLY__
  6. /*
  7. * The I/O device range is designed so that it can be addressed via
  8. * negative offsets from the zero register, so no explicit base
  9. * pointer register is necesary.
  10. */
  11. #define IODEVV(d,r) IODEVA(d,r,0)(zero)
  12. #define IODEVB(d,r) IODEVV(d,r,0)
  13. #define IODEVH(d,r) IODEVV(d,r,0)
  14. #define IODEVL(d,r) IODEVV(d,r,0)
  15. #else
  16. #include <stdint.h>
  17. /* Writable registers */
  18. #define IODEVV(d,r) (*(volatile void *)IODEVA(d,r,0))
  19. #define IODEVB(d,r) (*(volatile uint8_t *)IODEVA(d,r,0))
  20. #define IODEVB0(d,r) (*(volatile uint8_t *)IODEVA(d,r,0))
  21. #define IODEVB1(d,r) (*(volatile uint8_t *)IODEVA(d,r,1))
  22. #define IODEVB2(d,r) (*(volatile uint8_t *)IODEVA(d,r,2))
  23. #define IODEVB3(d,r) (*(volatile uint8_t *)IODEVA(d,r,3))
  24. #define IODEVH(d,r) (*(volatile uint16_t *)IODEVA(d,r,0))
  25. #define IODEVH0(d,r) (*(volatile uint16_t *)IODEVA(d,r,0))
  26. #define IODEVH1(d,r) (*(volatile uint16_t *)IODEVA(d,r,2))
  27. #define IODEVL(d,r) (*(volatile uint32_t *)IODEVA(d,r,0))
  28. /* Readonly registers */
  29. #define IODEVRV(d,r) (*(const volatile void *)IODEVA(d,r,0))
  30. #define IODEVRB(d,r) (*(const volatile uint8_t *)IODEVA(d,r,0))
  31. #define IODEVRB0(d,r) (*(const volatile uint8_t *)IODEVA(d,r,0))
  32. #define IODEVRB1(d,r) (*(const volatile uint8_t *)IODEVA(d,r,1))
  33. #define IODEVRB2(d,r) (*(const volatile uint8_t *)IODEVA(d,r,2))
  34. #define IODEVRB3(d,r) (*(const volatile uint8_t *)IODEVA(d,r,3))
  35. #define IODEVRH(d,r) (*(const volatile uint16_t *)IODEVA(d,r,0))
  36. #define IODEVRH0(d,r) (*(const volatile uint16_t *)IODEVA(d,r,0))
  37. #define IODEVRH1(d,r) (*(const volatile uint16_t *)IODEVA(d,r,2))
  38. #define IODEVRL(d,r) (*(const volatile uint32_t *)IODEVA(d,r,0))
  39. #endif
  40. #define CPU_HZ 84000000
  41. #define LED_DEV 0
  42. #define LED IODEVB(LED_DEV,0)
  43. #define RESET_DEV 1
  44. #define RESET_CMD IODEVL(RESET_DEV,0)
  45. #define ROMCOPY_DEV 2
  46. #define ROMCOPY_DONE IODEVRL(ROMCOPY_DEV,0)
  47. #define CON_DEV 3
  48. #define CONSOLE IODEVB(CON_DEV,0)
  49. #define CON_BAUDDIV IODEVL(CON_DEV,1)
  50. #define CON_BAUD_BASE (CPU_HZ >> 4)
  51. #define CON_BAUD_BITS 24
  52. #define CON_STATUS IODEVRL(CON_DEV,2)
  53. #define CON_IRQEN IODEVL(CON_DEV,3)
  54. #define SD_DEV 4
  55. #define SD_CTL IODEVL(SD_DEV,0)
  56. #define SD_CTL_SPEED IODEVB0(SD_DEV,0)
  57. #define SD_CTL_CLRCRC IODEVB1(SD_DEV,0)
  58. #define SD_CRC7_RD IODEVRB0(SD_DEV,2)
  59. #define SD_CRC16_RD IODEVRH1(SD_DEV,2)
  60. #define SD_CRC7_WR IODEVRB0(SD_DEV,3)
  61. #define SD_CRC16_WR IODEVRH1(SD_DEV,3)
  62. /* Speed values, not including -1 adjustment */
  63. #define SD_SLOW 128 /* 328 kHz */
  64. #define SD_20MHZ 3 /* Really 14 MHz */
  65. #define SD_25MHZ 2 /* Really 21 MHz */
  66. #define SD_50MHZ 1 /* Really 42 MHz */
  67. #define SYSCLOCK_DEV 5
  68. #define SYSCLOCK_DATETIME IODEVL(SYSCLOCK_DEV,0)
  69. #define SYSCLOCK_TICK IODEVL(SYSCLOCK_DEV,1)
  70. #define SYSCLOCK_TICK_HOLD IODEVH0(SYSCLOCK_DEV,1)
  71. #define SYSCLOCK_TICK_NOW IODEVH1(SYSCLOCK_DEV,1)
  72. #endif /* IODEV_H */