raspi4.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #ifndef __RASPI4_H__
  2. #define __RASPI4_H__
  3. #include <rthw.h>
  4. #define __REG32(x) (*((volatile unsigned int *)(x)))
  5. //base address
  6. #define PER_BASE (0xFE000000)
  7. //gpio offset
  8. #define GPIO_BASE_OFFSET (0x00200000)
  9. //pl011 offset
  10. #define PL011_UART_BASE_OFFSET (0x00201000)
  11. //pactl cs offset
  12. #define PACTL_CS_OFFSET (0x00204E00)
  13. //aux offset
  14. #define AUX_BASE_OFFSET (0x00215000)
  15. //gpio
  16. #define GPIO_BASE (PER_BASE + GPIO_BASE_OFFSET)
  17. #define GPIO_IRQ_NUM (3) //40 pin mode
  18. #define IRQ_GPIO0 (96 + 49) //bank0 (0 to 27)
  19. #define IRQ_GPIO1 (96 + 50) //bank1 (28 to 45)
  20. #define IRQ_GPIO2 (96 + 51) //bank2 (46 to 57)
  21. #define IRQ_GPIO3 (96 + 52) //bank3
  22. //system timer
  23. #define ARM_TIMER_IRQ (64)
  24. #define ARM_TIMER_BASE (PER_BASE + 0xB000)
  25. #define ARM_TIMER_LOAD HWREG32(ARM_TIMER_BASE + 0x400)
  26. #define ARM_TIMER_VALUE HWREG32(ARM_TIMER_BASE + 0x404)
  27. #define ARM_TIMER_CTRL HWREG32(ARM_TIMER_BASE + 0x408)
  28. #define ARM_TIMER_IRQCLR HWREG32(ARM_TIMER_BASE + 0x40C)
  29. #define ARM_TIMER_RAWIRQ HWREG32(ARM_TIMER_BASE + 0x410)
  30. #define ARM_TIMER_MASKIRQ HWREG32(ARM_TIMER_BASE + 0x414)
  31. #define ARM_TIMER_RELOAD HWREG32(ARM_TIMER_BASE + 0x418)
  32. #define ARM_TIMER_PREDIV HWREG32(ARM_TIMER_BASE + 0x41C)
  33. #define ARM_TIMER_CNTR HWREG32(ARM_TIMER_BASE + 0x420)
  34. //uart
  35. #define UART_BASE (PER_BASE + PL011_UART_BASE_OFFSET)
  36. #define UART0_BASE (UART_BASE + 0x0)
  37. #define UART2_BASE (UART_BASE + 0x400)
  38. #define UART3_BASE (UART_BASE + 0x600)
  39. #define UART4_BASE (UART_BASE + 0x800)
  40. #define UART5_BASE (UART_BASE + 0xA00)
  41. #define IRQ_AUX_UART (96 + 29)
  42. #define UART_REFERENCE_CLOCK (48000000)
  43. //aux
  44. #define AUX_BASE (PER_BASE + AUX_BASE_OFFSET)
  45. #define IRQ_PL011 (96 + 57)
  46. //pactl cs
  47. #define PACTL_CS_ADDR (PER_BASE + PACTL_CS_OFFSET)
  48. #define PACTL_CS HWREG32(PACTL_CS_ADDR)
  49. typedef enum
  50. {
  51. IRQ_SPI0 = 0x00000000,
  52. IRQ_SPI1 = 0x00000002,
  53. IRQ_SPI2 = 0x00000004,
  54. IRQ_SPI3 = 0x00000008,
  55. IRQ_SPI4 = 0x00000010,
  56. IRQ_SPI5 = 0x00000020,
  57. IRQ_SPI6 = 0x00000040,
  58. IRQ_I2C0 = 0x00000100,
  59. IRQ_I2C1 = 0x00000200,
  60. IRQ_I2C2 = 0x00000400,
  61. IRQ_I2C3 = 0x00000800,
  62. IRQ_I2C4 = 0x00001000,
  63. IRQ_I2C5 = 0x00002000,
  64. IRQ_I2C6 = 0x00004000,
  65. IRQ_I2C7 = 0x00008000,
  66. IRQ_UART5 = 0x00010000,
  67. IRQ_UART4 = 0x00020000,
  68. IRQ_UART3 = 0x00040000,
  69. IRQ_UART2 = 0x00080000,
  70. IRQ_UART0 = 0x00100000
  71. } PACTL_CS_VAL;
  72. // 0x40, 0x44, 0x48, 0x4c: Core 0~3 Timers interrupt control
  73. #define CORE0_TIMER_IRQ_CTRL HWREG32(0xFF800040)
  74. #define TIMER_IRQ 30
  75. #define NON_SECURE_TIMER_IRQ (1 << 1)
  76. //core timer
  77. #define ST_BASE_OFFSET (0x003000)
  78. #define STIMER_BASE (PER_BASE + ST_BASE_OFFSET)
  79. #define STIMER_CS HWREG32(STIMER_BASE + 0x0000)
  80. #define STIMER_CLO HWREG32(STIMER_BASE + 0x0004)
  81. #define STIMER_CHI HWREG32(STIMER_BASE + 0x0008)
  82. #define STIMER_C0 HWREG32(STIMER_BASE + 0x000C)
  83. #define STIMER_C1 HWREG32(STIMER_BASE + 0x0010)
  84. #define STIMER_C2 HWREG32(STIMER_BASE + 0x0014)
  85. #define STIMER_C3 HWREG32(STIMER_BASE + 0x0018)
  86. #define DELAY_MICROS(micros) \
  87. do { \
  88. rt_uint32_t compare = STIMER_CLO + micros * 25; \
  89. while (STIMER_CLO < compare); \
  90. } while (0) \
  91. //mmc
  92. #define MMC0_BASE_ADDR (PER_BASE + 0x300000)
  93. #define MMC2_BASE_ADDR (PER_BASE + 0x340000)
  94. //eth
  95. #define MAC_REG_BASE_ADDR (void *)(0xfd580000)
  96. #define ETH_IRQ (160 + 29)
  97. #define SEND_DATA_NO_CACHE (0x08200000)
  98. #define RECV_DATA_NO_CACHE (0x08400000)
  99. //gic max
  100. #define MAX_HANDLERS (256)
  101. #define ARM_GIC_NR_IRQS (512)
  102. #define INTC_BASE (0xff800000)
  103. #define ARM_GIC_MAX_NR (512)
  104. #define GIC_V2_BASE (INTC_BASE + 0x00040000)
  105. #define GIC_V2_DISTRIBUTOR_BASE (INTC_BASE + 0x00041000)
  106. #define GIC_V2_CPU_INTERFACE_BASE (INTC_BASE + 0x00042000)
  107. #define GIC_V2_HYPERVISOR_BASE (INTC_BASE + 0x00044000)
  108. #define GIC_V2_VIRTUAL_CPU_BASE (INTC_BASE + 0x00046000)
  109. #define GIC_IRQ_START 0
  110. #define GIC_ACK_INTID_MASK 0x000003ff
  111. #define GIC_PL400_DISTRIBUTOR_PPTR GIC_V2_DISTRIBUTOR_BASE
  112. #define GIC_PL400_CONTROLLER_PPTR GIC_V2_CPU_INTERFACE_BASE
  113. /* the basic constants and interfaces needed by gic */
  114. rt_inline rt_uint32_t platform_get_gic_dist_base(void)
  115. {
  116. return GIC_PL400_DISTRIBUTOR_PPTR;
  117. }
  118. rt_inline rt_uint32_t platform_get_gic_cpu_base(void)
  119. {
  120. return GIC_PL400_CONTROLLER_PPTR;
  121. }
  122. #endif