raspi4.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #ifndef __RASPI4_H__
  2. #define __RASPI4_H__
  3. //https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2711/rpi_DATA_2711_1p0.pdf
  4. #define __REG32(x) (*((volatile unsigned int *)(x)))
  5. #define __REG16(x) (*((volatile unsigned short *)(x)))
  6. /* GIC IRQ MAX */
  7. #define MAX_HANDLERS (256)
  8. /* base address */
  9. #define PER_BASE (0xFE000000)
  10. /* GPIO */
  11. #define GPIO_BASE (PER_BASE + 0x00200000)
  12. /* Timer (ARM side) */
  13. #define ARM_TIMER_IRQ (64)
  14. #define ARM_TIMER_BASE (PER_BASE + 0xB000)
  15. #define ARM_TIMER_LOAD HWREG32(ARM_TIMER_BASE + 0x400)
  16. #define ARM_TIMER_VALUE HWREG32(ARM_TIMER_BASE + 0x404)
  17. #define ARM_TIMER_CTRL HWREG32(ARM_TIMER_BASE + 0x408)
  18. #define ARM_TIMER_IRQCLR HWREG32(ARM_TIMER_BASE + 0x40C)
  19. #define ARM_TIMER_RAWIRQ HWREG32(ARM_TIMER_BASE + 0x410)
  20. #define ARM_TIMER_MASKIRQ HWREG32(ARM_TIMER_BASE + 0x414)
  21. #define ARM_TIMER_RELOAD HWREG32(ARM_TIMER_BASE + 0x418)
  22. #define ARM_TIMER_PREDIV HWREG32(ARM_TIMER_BASE + 0x41C)
  23. #define ARM_TIMER_CNTR HWREG32(ARM_TIMER_BASE + 0x420)
  24. /* UART PL011 */
  25. #define UART0_BASE (PER_BASE + 0x00201000)
  26. #define PL011_BASE UART0_BASE
  27. #define IRQ_PL011 (96 + 57)
  28. #define UART_REFERENCE_CLOCK (48000000)
  29. // 0x40, 0x44, 0x48, 0x4c: Core 0~3 Timers interrupt control
  30. #define CORE0_TIMER_IRQ_CTRL HWREG32(0xFF800040)
  31. #define TIMER_IRQ 30
  32. #define NON_SECURE_TIMER_IRQ (1 << 1)
  33. /* GIC */
  34. #define INTC_BASE (0xff800000)
  35. #define ARM_GIC_NR_IRQS (512)
  36. #define ARM_GIC_MAX_NR (512)
  37. #define GIC_V2_DISTRIBUTOR_BASE (INTC_BASE + 0x00041000)
  38. #define GIC_V2_CPU_INTERFACE_BASE (INTC_BASE + 0x00042000)
  39. #define GIC_V2_HYPERVISOR_BASE (INTC_BASE + 0x00044000)
  40. #define GIC_V2_VIRTUAL_CPU_BASE (INTC_BASE + 0x00046000)
  41. #define GIC_PL400_DISTRIBUTOR_PPTR GIC_V2_DISTRIBUTOR_BASE
  42. #define GIC_PL400_CONTROLLER_PPTR GIC_V2_CPU_INTERFACE_BASE
  43. #define GIC_IRQ_START 0
  44. #define GIC_ACK_INTID_MASK 0x000003ff
  45. /* the basic constants and interfaces needed by gic */
  46. rt_inline rt_uint32_t platform_get_gic_dist_base(void)
  47. {
  48. return GIC_PL400_DISTRIBUTOR_PPTR;
  49. }
  50. rt_inline rt_uint32_t platform_get_gic_cpu_base(void)
  51. {
  52. return GIC_PL400_CONTROLLER_PPTR;
  53. }
  54. static inline void __DSB(void)
  55. {
  56. __asm__ volatile ("dsb 0xF":::"memory");
  57. }
  58. #endif