eagle_soc.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /*
  2. * ESPRESSIF MIT License
  3. *
  4. * Copyright (c) 2016 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
  5. *
  6. * Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, in which case,
  7. * it is free of charge, to any person obtaining a copy of this software and associated
  8. * documentation files (the "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. * and/or sell copies of the Software, and to permit persons to whom the Software is furnished
  11. * to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in all copies or
  14. * substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. *
  23. */
  24. #ifndef _EAGLE_SOC_H_
  25. #define _EAGLE_SOC_H_
  26. //Register Bits{{
  27. #define BIT31 0x80000000
  28. #define BIT30 0x40000000
  29. #define BIT29 0x20000000
  30. #define BIT28 0x10000000
  31. #define BIT27 0x08000000
  32. #define BIT26 0x04000000
  33. #define BIT25 0x02000000
  34. #define BIT24 0x01000000
  35. #define BIT23 0x00800000
  36. #define BIT22 0x00400000
  37. #define BIT21 0x00200000
  38. #define BIT20 0x00100000
  39. #define BIT19 0x00080000
  40. #define BIT18 0x00040000
  41. #define BIT17 0x00020000
  42. #define BIT16 0x00010000
  43. #define BIT15 0x00008000
  44. #define BIT14 0x00004000
  45. #define BIT13 0x00002000
  46. #define BIT12 0x00001000
  47. #define BIT11 0x00000800
  48. #define BIT10 0x00000400
  49. #define BIT9 0x00000200
  50. #define BIT8 0x00000100
  51. #define BIT7 0x00000080
  52. #define BIT6 0x00000040
  53. #define BIT5 0x00000020
  54. #define BIT4 0x00000010
  55. #define BIT3 0x00000008
  56. #define BIT2 0x00000004
  57. #define BIT1 0x00000002
  58. #define BIT0 0x00000001
  59. //}}
  60. //Registers Operation {{
  61. #define ETS_UNCACHED_ADDR(addr) (addr)
  62. #define ETS_CACHED_ADDR(addr) (addr)
  63. #define READ_PERI_REG(addr) (*((volatile uint32_t *)ETS_UNCACHED_ADDR(addr)))
  64. #define WRITE_PERI_REG(addr, val) (*((volatile uint32_t *)ETS_UNCACHED_ADDR(addr))) = (uint32_t)(val)
  65. #define CLEAR_PERI_REG_MASK(reg, mask) WRITE_PERI_REG((reg), (READ_PERI_REG(reg)&(~(mask))))
  66. #define SET_PERI_REG_MASK(reg, mask) WRITE_PERI_REG((reg), (READ_PERI_REG(reg)|(mask)))
  67. #define GET_PERI_REG_BITS(reg, hipos,lowpos) ((READ_PERI_REG(reg)>>(lowpos))&((1<<((hipos)-(lowpos)+1))-1))
  68. #define SET_PERI_REG_BITS(reg,bit_map,value,shift) (WRITE_PERI_REG((reg),(READ_PERI_REG(reg)&(~((bit_map)<<(shift))))|((value)<<(shift)) ))
  69. //}}
  70. //Periheral Clock {{
  71. #define APB_CLK_FREQ 80*1000000 //unit: Hz
  72. #define UART_CLK_FREQ APB_CLK_FREQ
  73. #define TIMER_CLK_FREQ (APB_CLK_FREQ>>8) //divided by 256
  74. //}}
  75. //Peripheral device base address define{{
  76. #define PERIPHS_DPORT_BASEADDR 0x3ff00000
  77. #define PERIPHS_GPIO_BASEADDR 0x60000300
  78. #define PERIPHS_TIMER_BASEDDR 0x60000600
  79. #define PERIPHS_RTC_BASEADDR 0x60000700
  80. #define PERIPHS_IO_MUX 0x60000800
  81. //}}
  82. //Interrupt remap control registers define{{
  83. #define EDGE_INT_ENABLE_REG (PERIPHS_DPORT_BASEADDR+0x04)
  84. #define TM1_EDGE_INT_ENABLE() SET_PERI_REG_MASK(EDGE_INT_ENABLE_REG, BIT1)
  85. #define TM1_EDGE_INT_DISABLE() CLEAR_PERI_REG_MASK(EDGE_INT_ENABLE_REG, BIT1)
  86. //}}
  87. //GPIO reg {{
  88. #define GPIO_REG_READ(reg) READ_PERI_REG(PERIPHS_GPIO_BASEADDR + reg)
  89. #define GPIO_REG_WRITE(reg, val) WRITE_PERI_REG(PERIPHS_GPIO_BASEADDR + reg, val)
  90. #define GPIO_OUT_ADDRESS 0x00
  91. #define GPIO_OUT_W1TS_ADDRESS 0x04
  92. #define GPIO_OUT_W1TC_ADDRESS 0x08
  93. #define GPIO_ENABLE_ADDRESS 0x0c
  94. #define GPIO_ENABLE_W1TS_ADDRESS 0x10
  95. #define GPIO_ENABLE_W1TC_ADDRESS 0x14
  96. #define GPIO_OUT_W1TC_DATA_MASK 0x0000ffff
  97. #define GPIO_IN_ADDRESS 0x18
  98. #define GPIO_STATUS_ADDRESS 0x1c
  99. #define GPIO_STATUS_W1TS_ADDRESS 0x20
  100. #define GPIO_STATUS_W1TC_ADDRESS 0x24
  101. #define GPIO_STATUS_INTERRUPT_MASK 0x0000ffff
  102. #define GPIO_RTC_CALIB_SYNC PERIPHS_GPIO_BASEADDR+0x6c
  103. #define RTC_CALIB_START BIT31 //first write to zero, then to one to start
  104. #define RTC_PERIOD_NUM_MASK 0x3ff //max 8ms
  105. #define GPIO_RTC_CALIB_VALUE PERIPHS_GPIO_BASEADDR+0x70
  106. #define RTC_CALIB_RDY_S 31 //after measure, flag to one, when start from zero to one, turn to zero
  107. #define RTC_CALIB_VALUE_MASK 0xfffff
  108. #define GPIO_PIN0_ADDRESS 0x28
  109. #define GPIO_ID_PIN0 0
  110. #define GPIO_ID_PIN(n) (GPIO_ID_PIN0+(n))
  111. #define GPIO_LAST_REGISTER_ID GPIO_ID_PIN(15)
  112. #define GPIO_ID_NONE 0xffffffff
  113. #define GPIO_PIN_COUNT 16
  114. #define GPIO_PIN_CONFIG_MSB 12
  115. #define GPIO_PIN_CONFIG_LSB 11
  116. #define GPIO_PIN_CONFIG_MASK 0x00001800
  117. #define GPIO_PIN_CONFIG_GET(x) (((x) & GPIO_PIN_CONFIG_MASK) >> GPIO_PIN_CONFIG_LSB)
  118. #define GPIO_PIN_CONFIG_SET(x) (((x) << GPIO_PIN_CONFIG_LSB) & GPIO_PIN_CONFIG_MASK)
  119. #define GPIO_WAKEUP_ENABLE 1
  120. #define GPIO_WAKEUP_DISABLE (~GPIO_WAKEUP_ENABLE)
  121. #define GPIO_PIN_WAKEUP_ENABLE_MSB 10
  122. #define GPIO_PIN_WAKEUP_ENABLE_LSB 10
  123. #define GPIO_PIN_WAKEUP_ENABLE_MASK 0x00000400
  124. #define GPIO_PIN_WAKEUP_ENABLE_GET(x) (((x) & GPIO_PIN_WAKEUP_ENABLE_MASK) >> GPIO_PIN_WAKEUP_ENABLE_LSB)
  125. #define GPIO_PIN_WAKEUP_ENABLE_SET(x) (((x) << GPIO_PIN_WAKEUP_ENABLE_LSB) & GPIO_PIN_WAKEUP_ENABLE_MASK)
  126. #define GPIO_PIN_INT_TYPE_MASK 0x380
  127. #define GPIO_PIN_INT_TYPE_MSB 9
  128. #define GPIO_PIN_INT_TYPE_LSB 7
  129. #define GPIO_PIN_INT_TYPE_GET(x) (((x) & GPIO_PIN_INT_TYPE_MASK) >> GPIO_PIN_INT_TYPE_LSB)
  130. #define GPIO_PIN_INT_TYPE_SET(x) (((x) << GPIO_PIN_INT_TYPE_LSB) & GPIO_PIN_INT_TYPE_MASK)
  131. #define GPIO_PAD_DRIVER_ENABLE 1
  132. #define GPIO_PAD_DRIVER_DISABLE (~GPIO_PAD_DRIVER_ENABLE)
  133. #define GPIO_PIN_PAD_DRIVER_MSB 2
  134. #define GPIO_PIN_PAD_DRIVER_LSB 2
  135. #define GPIO_PIN_PAD_DRIVER_MASK 0x00000004
  136. #define GPIO_PIN_PAD_DRIVER_GET(x) (((x) & GPIO_PIN_PAD_DRIVER_MASK) >> GPIO_PIN_PAD_DRIVER_LSB)
  137. #define GPIO_PIN_PAD_DRIVER_SET(x) (((x) << GPIO_PIN_PAD_DRIVER_LSB) & GPIO_PIN_PAD_DRIVER_MASK)
  138. #define GPIO_AS_PIN_SOURCE 0
  139. #define SIGMA_AS_PIN_SOURCE (~GPIO_AS_PIN_SOURCE)
  140. #define GPIO_PIN_SOURCE_MSB 0
  141. #define GPIO_PIN_SOURCE_LSB 0
  142. #define GPIO_PIN_SOURCE_MASK 0x00000001
  143. #define GPIO_PIN_SOURCE_GET(x) (((x) & GPIO_PIN_SOURCE_MASK) >> GPIO_PIN_SOURCE_LSB)
  144. #define GPIO_PIN_SOURCE_SET(x) (((x) << GPIO_PIN_SOURCE_LSB) & GPIO_PIN_SOURCE_MASK)
  145. // }}
  146. // TIMER reg {{
  147. #define RTC_REG_READ(addr) READ_PERI_REG(PERIPHS_TIMER_BASEDDR + addr)
  148. #define RTC_REG_WRITE(addr, val) WRITE_PERI_REG(PERIPHS_TIMER_BASEDDR + addr, val)
  149. #define RTC_CLR_REG_MASK(reg, mask) CLEAR_PERI_REG_MASK(PERIPHS_TIMER_BASEDDR +reg, mask)
  150. /* Returns the current time according to the timer timer. */
  151. #define NOW() RTC_REG_READ(FRC2_COUNT_ADDRESS)
  152. //load initial_value to timer1
  153. #define FRC1_LOAD_ADDRESS 0x00
  154. //timer1's counter value(count from initial_value to 0)
  155. #define FRC1_COUNT_ADDRESS 0x04
  156. #define FRC1_CTRL_ADDRESS 0x08
  157. //clear timer1's interrupt when write this address
  158. #define FRC1_INT_ADDRESS 0x0c
  159. #define FRC1_INT_CLR_MASK 0x00000001
  160. //timer2's counter value(count from initial_value to 0)
  161. #define FRC2_COUNT_ADDRESS 0x24
  162. // }}
  163. //RTC reg {{
  164. #define REG_RTC_BASE PERIPHS_RTC_BASEADDR
  165. #define RTC_STORE0 (REG_RTC_BASE + 0x030)
  166. #define RTC_STORE1 (REG_RTC_BASE + 0x034)
  167. #define RTC_STORE2 (REG_RTC_BASE + 0x038)
  168. #define RTC_STORE3 (REG_RTC_BASE + 0x03C)
  169. #define RTC_GPIO_OUT (REG_RTC_BASE + 0x068)
  170. #define RTC_GPIO_ENABLE (REG_RTC_BASE + 0x074)
  171. #define RTC_GPIO_IN_DATA (REG_RTC_BASE + 0x08C)
  172. #define RTC_GPIO_CONF (REG_RTC_BASE + 0x090)
  173. #define PAD_XPD_DCDC_CONF (REG_RTC_BASE + 0x0A0)
  174. //}}
  175. //PIN Mux reg {{
  176. #define PERIPHS_IO_MUX_FUNC 0x13
  177. #define PERIPHS_IO_MUX_FUNC_S 4
  178. #define PERIPHS_IO_MUX_PULLUP BIT7
  179. #define PERIPHS_IO_MUX_PULLUP2 BIT6
  180. #define PERIPHS_IO_MUX_SLEEP_PULLUP BIT3
  181. #define PERIPHS_IO_MUX_SLEEP_PULLUP2 BIT2
  182. #define PERIPHS_IO_MUX_SLEEP_OE BIT1
  183. #define PERIPHS_IO_MUX_OE BIT0
  184. #define PERIPHS_IO_MUX_CONF_U (PERIPHS_IO_MUX + 0x00)
  185. #define SPI0_CLK_EQU_SYS_CLK BIT8
  186. #define SPI1_CLK_EQU_SYS_CLK BIT9
  187. #define PERIPHS_IO_MUX_MTDI_U (PERIPHS_IO_MUX + 0x04)
  188. #define FUNC_GPIO12 3
  189. #define PERIPHS_IO_MUX_MTCK_U (PERIPHS_IO_MUX + 0x08)
  190. #define FUNC_GPIO13 3
  191. #define PERIPHS_IO_MUX_MTMS_U (PERIPHS_IO_MUX + 0x0C)
  192. #define FUNC_GPIO14 3
  193. #define PERIPHS_IO_MUX_MTDO_U (PERIPHS_IO_MUX + 0x10)
  194. #define FUNC_GPIO15 3
  195. #define FUNC_U0RTS 4
  196. #define PERIPHS_IO_MUX_U0RXD_U (PERIPHS_IO_MUX + 0x14)
  197. #define FUNC_GPIO3 3
  198. #define PERIPHS_IO_MUX_U0TXD_U (PERIPHS_IO_MUX + 0x18)
  199. #define FUNC_U0TXD 0
  200. #define FUNC_GPIO1 3
  201. #define PERIPHS_IO_MUX_SD_CLK_U (PERIPHS_IO_MUX + 0x1c)
  202. #define FUNC_SDCLK 0
  203. #define FUNC_SPICLK 1
  204. #define PERIPHS_IO_MUX_SD_DATA0_U (PERIPHS_IO_MUX + 0x20)
  205. #define FUNC_SDDATA0 0
  206. #define FUNC_SPIQ 1
  207. #define FUNC_U1TXD 4
  208. #define PERIPHS_IO_MUX_SD_DATA1_U (PERIPHS_IO_MUX + 0x24)
  209. #define FUNC_SDDATA1 0
  210. #define FUNC_SPID 1
  211. #define FUNC_U1RXD 4
  212. #define FUNC_SDDATA1_U1RXD 7
  213. #define PERIPHS_IO_MUX_SD_DATA2_U (PERIPHS_IO_MUX + 0x28)
  214. #define FUNC_SDDATA2 0
  215. #define FUNC_SPIHD 1
  216. #define FUNC_GPIO9 3
  217. #define PERIPHS_IO_MUX_SD_DATA3_U (PERIPHS_IO_MUX + 0x2c)
  218. #define FUNC_SDDATA3 0
  219. #define FUNC_SPIWP 1
  220. #define FUNC_GPIO10 3
  221. #define PERIPHS_IO_MUX_SD_CMD_U (PERIPHS_IO_MUX + 0x30)
  222. #define FUNC_SDCMD 0
  223. #define FUNC_SPICS0 1
  224. #define PERIPHS_IO_MUX_GPIO0_U (PERIPHS_IO_MUX + 0x34)
  225. #define FUNC_GPIO0 0
  226. #define PERIPHS_IO_MUX_GPIO2_U (PERIPHS_IO_MUX + 0x38)
  227. #define FUNC_GPIO2 0
  228. #define FUNC_U1TXD_BK 2
  229. #define FUNC_U0TXD_BK 4
  230. #define PERIPHS_IO_MUX_GPIO4_U (PERIPHS_IO_MUX + 0x3C)
  231. #define FUNC_GPIO4 0
  232. #define PERIPHS_IO_MUX_GPIO5_U (PERIPHS_IO_MUX + 0x40)
  233. #define FUNC_GPIO5 0
  234. #define PIN_PULLUP_DIS(PIN_NAME) CLEAR_PERI_REG_MASK(PIN_NAME, PERIPHS_IO_MUX_PULLUP)
  235. #define PIN_PULLUP_EN(PIN_NAME) SET_PERI_REG_MASK(PIN_NAME, PERIPHS_IO_MUX_PULLUP)
  236. #define PIN_FUNC_SELECT(PIN_NAME, FUNC) do { \
  237. WRITE_PERI_REG(PIN_NAME, \
  238. (READ_PERI_REG(PIN_NAME) \
  239. & (~(PERIPHS_IO_MUX_FUNC<<PERIPHS_IO_MUX_FUNC_S))) \
  240. |( (((FUNC&BIT2)<<2)|(FUNC&0x3))<<PERIPHS_IO_MUX_FUNC_S) ); \
  241. } while (0)
  242. //}}
  243. #endif //_EAGLE_SOC_H_