soc.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2022-07-15 Emuzit first version
  9. */
  10. #ifndef __SOC_H__
  11. #define __SOC_H__
  12. #include <stdint.h>
  13. #include <stddef.h>
  14. #include <assert.h>
  15. #include <rtdef.h>
  16. #if !defined(SOC_CH567) && \
  17. !defined(SOC_CH568) && \
  18. !defined(SOC_SERIES_CH569)
  19. #define SOC_SERIES_CH569
  20. #endif
  21. #ifndef __packed
  22. #define __packed __attribute__((packed))
  23. #endif
  24. #define CHECK_STRUCT_SIZE(s, size) \
  25. static_assert(sizeof(s) == size, #s " has wrong size")
  26. #define BITS_SET(x, bits) do x |= bits; while(0)
  27. #define BITS_CLR(x, bits) do x &= ~bits; while(0)
  28. #define FLASH_BASE_ADDRESS 0x00000000
  29. #define RAMS_BASE_ADDRESS 0x20000000
  30. #define BUS8_BASE_ADDRESS 0x80000000
  31. #ifdef SOC_SERIES_CH569
  32. #define RAMX_BASE_ADDRESS 0x20020000
  33. #define RAMS_SIZE 16
  34. #else
  35. #define RAMS_SIZE 32
  36. #endif
  37. #define RAMS_END (RAMS_BASE_ADDRESS + RAMS_SIZE * 1024)
  38. #define SYS_REG_BASE 0x40001000
  39. #define GPIO_REG_BASE 0x40001000
  40. #define GPIO_REG_BASE_PA 0x40001040
  41. #define GPIO_REG_BASE_PB 0x40001060
  42. #define GPIO_PORTS 2 // 2 ports : PA & PB
  43. #define GPIO_PA_PIN_START 0 // PA : pin number 0~31
  44. #define GPIO_PB_PIN_START 32 // PB : pin number 32~63
  45. #ifdef SOC_SERIES_CH569
  46. #define GPIO_PA_PIN_MARK 0x00ffffff // PA : bits 0~23
  47. #define GPIO_PB_PIN_MARK 0x01ffffff // PB : bits 0~24
  48. #else
  49. #define GPIO_PA_PIN_MARK 0x0000ffff // PA : bits 0~15
  50. #define GPIO_PB_PIN_MARK 0x00003fff // PB : bits 0~13
  51. #endif
  52. #define TMR0_REG_BASE 0x40002000
  53. #define TMR1_REG_BASE 0x40002400
  54. #define TMR2_REG_BASE 0x40002800
  55. #define UART0_REG_BASE 0x40003000
  56. #define UART1_REG_BASE 0x40003400
  57. #define UART2_REG_BASE 0x40003800
  58. #define UART3_REG_BASE 0x40003c00
  59. #define SPI0_REG_BASE 0x40004000
  60. #define SPI1_REG_BASE 0x40004400
  61. #define PWMX_REG_BASE 0x40005000
  62. #define PFIC_REG_BASE 0xe000e000
  63. #define SysTick_REG_BASE 0xe000f000
  64. #ifdef SOC_SERIES_CH569
  65. #define HSPI_REG_BASE 0x40006000 // CH569W
  66. #define ECDC_REG_BASE 0x40007000
  67. #define USBSS_REG_BASE 0x40008000
  68. #define USBHS_REG_BASE 0x40009000
  69. #define EMMC_REG_BASE 0x4000a000
  70. #define SERDES_REG_BASE 0x4000b000
  71. #define ETH_REG_BASE 0x4000c000 // CH565W/CH569W
  72. #define DVP_REG_BASE 0x4000e000 // CH565W/CH565M
  73. #else
  74. #define LED_REG_BASE 0x40006000
  75. #define USB0_REG_BASE 0x40008000 // CH567
  76. #define USB1_REG_BASE 0x40009000 // CH567
  77. #define USB_REG_BASE 0x40009000 // CH568
  78. #define SDC_REG_BASE 0x4000a000
  79. #define SATA_REG_BASE 0x4000b000 // CH568
  80. #define ECDC_REG_BASE 0x4000c400
  81. #endif
  82. #if defined(SOC_SERIES_CH569)
  83. typedef enum
  84. {
  85. PWMX_OFFn = 0,
  86. NMI_IRQn = 2,
  87. EXC_IRQn = 3,
  88. SysTick_IRQn = 12,
  89. SWI_IRQn = 14,
  90. WDOG_IRQn = 16,
  91. TMR0_IRQn = 17,
  92. GPIO_IRQn = 18,
  93. SPI0_IRQn = 19,
  94. USBSS_IRQn = 20,
  95. LINK_IRQn = 21,
  96. TMR1_IRQn = 22,
  97. TMR2_IRQn = 23,
  98. UART0_IRQn = 24,
  99. USBHS_IRQn = 25,
  100. EMMC_IRQn = 26,
  101. DVP_IRQn = 27,
  102. HSPI_IRQn = 28,
  103. SPI1_IRQn = 29,
  104. UART1_IRQn = 30,
  105. UART2_IRQn = 31,
  106. UART3_IRQn = 32,
  107. SerDes_IRQn = 33,
  108. ETH_IRQn = 34,
  109. PMT_IRQn = 35,
  110. ECDC_IRQn = 36,
  111. END_OF_IRQn
  112. } irq_number_t;
  113. #else
  114. typedef enum
  115. {
  116. PWMX_OFFn = 0,
  117. SOFT_IRQn = 0,
  118. TMR0_IRQn = 1,
  119. GPIO_IRQn = 2,
  120. SPI0_IRQn = 3,
  121. USB0_IRQn = 4, // CH567
  122. SATA_IRQn = 4, // CH568
  123. TMR1_IRQn = 5,
  124. TMR2_IRQn = 6,
  125. UART0_IRQn = 7,
  126. USB1_IRQn = 8,
  127. SDC_IRQn = 9,
  128. ECDC_IRQn = 10,
  129. LED_IRQn = 11,
  130. SPI1_IRQn = 12,
  131. UART1_IRQn = 13,
  132. UART2_IRQn = 14,
  133. UART3_IRQn = 15,
  134. END_OF_IRQn
  135. } irq_number_t;
  136. #endif
  137. #endif