yc3121.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. /*
  2. File Name : yc3121.h
  3. Author : Yichip
  4. Version : V1.0
  5. Date : 2018/03/27
  6. Description : Register and hardware information.
  7. */
  8. #ifndef __YC3121_H__
  9. #define __YC3121_H__
  10. #include "type.h"
  11. #include "system.h"
  12. #include <string.h>
  13. #include "rom_api.h"
  14. #define NO_BT 0
  15. #define EXIST_BT 1
  16. #define NO_XTAL 2
  17. #define VERSIONS EXIST_BT
  18. #define M0_FPGA 1
  19. #define POS_FPGA 2
  20. #define POS_CHIP 3
  21. #define HARDWAER POS_CHIP
  22. #if (HARDWAER == M0_FPGA)
  23. #define CPU_MHZ (24*1000000)
  24. #elif (HARDWAER == POS_CHIP)
  25. #define CRYSTAL_CLK (192*1000000)
  26. #define CPU_MHZ ((CRYSTAL_CLK)/((SYSCTRL_HCLK_CON&0x0f)+2))
  27. #endif
  28. #define noinline __attribute__((noinline))
  29. #define IPC_HOLD_BT *(volatile byte*)0xC4FEF
  30. #define IPC_RX_START_ADDR (volatile byte*)0xc4ff0
  31. #define IPC_RX_END_ADDR (volatile byte*)0xc4ff2
  32. #define IPC_RX_READ_PTR (volatile byte*)0xc4ff4
  33. #define IPC_RX_WRITE_PTR (volatile byte*)0xc4ff6
  34. #define IPC_TX_START_ADDR (volatile byte*)0xc4ff8
  35. #define IPC_TX_END_ADDR (volatile byte*)0xc4ffa
  36. #define IPC_TX_READ_PTR (volatile byte*)0xc4ffc
  37. #define IPC_TX_WRITE_PTR (volatile byte*)0xc4ffe
  38. #define BT_REV *(volatile byte*)0xc8000
  39. #define BT_STEP *(volatile byte*)0xc8001
  40. #define BT_PC *(volatile word*)0xc800e
  41. #define BT_RESET *(volatile byte*)0xc8010
  42. #define BT_UCODE_HI *(volatile byte*)0xc8022
  43. #define BT_UCODE_CTRL *(volatile byte*)0xc8023
  44. #define BT_UCODE_LO *(volatile byte*)0xc8024
  45. #define BT_UCODE_DATA *(volatile byte*)0xc8025
  46. #define BT_RHALFSLOT_LOW *(volatile byte*)0xc8040
  47. #define BT_CONTRU *(volatile byte*)0xc812c
  48. #define BT_CONTWU *(volatile byte*)0xc812e
  49. #define BT_CONFIG *(volatile byte*)0xc8043
  50. #define BT_CLKPLL_EN *(volatile byte*)0xc8905
  51. #define BT_CHGPUMP_EN *(volatile byte*)0xc8973
  52. #define WAKEUP_BT *(volatile byte*)0xF853C
  53. #define BT_INIT_FLAG 7
  54. #define WAKEUP_BT_FLAG 2
  55. //register base address
  56. #define WDT_BASEADDR 0xf0000
  57. #define SCI7816_BASEADDR 0xf0400
  58. #define TIMER_BASEADDR 0xf0c00
  59. #define SM4_BASEADDR 0xf5200
  60. #define RSA_BASEADDR 0xf5800
  61. #define USB_BASEADDR 0xf6000
  62. #define DES_BASEADDR 0xf8000
  63. #define CRC_BASEADDR 0xf8200
  64. #define AES_BASEADDR 0xf8300
  65. #define LPM_BASEADDR 0xf8400
  66. #define SYSCTRL_BASEADDR 0xf8500
  67. #define SECURE_BASEADDR 0xf8540
  68. #define CLKGEN_BASEADDR 0xf8560
  69. #define MPU_BASEADDR 0xf8580
  70. #define SHA_BASEADDR 0xf8600
  71. #define GPIO_BASEADDR 0xf8700
  72. #define DMA_BASEADDR 0xf8800
  73. #define QSPI_BASEADDR DMA_BASEADDR
  74. #define ISO7811_BASEADDR 0xf8f00
  75. #define WD_CONFIG *(volatile int*)(WDT_BASEADDR + 0x00)
  76. #define WD_STATUS *(volatile int*)(WDT_BASEADDR + 0x04)
  77. #define WD_KICK *(volatile int*)(WDT_BASEADDR + 0x08)
  78. #define WD_CLEAR *(volatile int*)(WDT_BASEADDR + 0x0c)
  79. #define SCI7816_MODE *(volatile int*)(SCI7816_BASEADDR + 0x00)
  80. #define SCI7816_CTRL *(volatile int*)(SCI7816_BASEADDR + 0x08)
  81. #define SCI7816_STAT *(volatile int*)(SCI7816_BASEADDR + 0x0c)
  82. #define SCI7816_INT *(volatile int*)(SCI7816_BASEADDR + 0x10)
  83. #define SCI7816_DATA *(volatile int*)(SCI7816_BASEADDR + 0x20)
  84. #define SCI7816_ETU *(volatile int*)(SCI7816_BASEADDR + 0x28)
  85. #define SCI7816_BGT *(volatile int*)(SCI7816_BASEADDR + 0x2c)
  86. #define SCI7816_CWT *(volatile int*)(SCI7816_BASEADDR + 0x30)
  87. #define SCI7816_EDC *(volatile int*)(SCI7816_BASEADDR + 0x34)
  88. #define PWM_TOTAL 9
  89. #define TIM_PCNT(x) *(volatile int*)(TIMER_BASEADDR + x*8)
  90. #define TIM_NCNT(x) *(volatile int*)(TIMER_BASEADDR + 4 + x*8)
  91. #define TIM_CTRL *(volatile int*)(TIMER_BASEADDR + PWM_TOTAL*8)
  92. #define TIM_CTRL1 *(volatile int*)(TIMER_BASEADDR + PWM_TOTAL*8 + 4)
  93. #define TIM_CNT(x) *(volatile int*)(TIMER_BASEADDR + PWM_TOTAL*8 + (PWM_TOTAL*4 + 31)/32*4 + x*4)
  94. #define SHA_DATA(x) *(volatile int*)(SHA_BASEADDR + 0x00 + x*4)
  95. #define SHA_BDATA(x) *(volatile uint8_t*)(SHA_BASEADDR + 0x00 + x)
  96. #define SHA_RESULT(x) *(volatile int*)(SHA_BASEADDR + 0x80 + x*4)
  97. #define SHA_CTRL *(volatile int*)(SHA_BASEADDR + 0xc0)
  98. #define SYSCTRL_PRIV_CTRL *(volatile int*)(SYSCTRL_BASEADDR + 0x0)
  99. #define SYSCTRL_STATUS *(volatile int*)(SYSCTRL_BASEADDR + 0x4)
  100. #define OTP_ADDR *(volatile short*)(SYSCTRL_BASEADDR + 0x8)
  101. #define OTP_CTRL *(volatile short*)(SYSCTRL_BASEADDR + 0xa)
  102. #define OTP_RDATA *(volatile byte*)(SYSCTRL_BASEADDR + 0xc)
  103. #define OTP_STATUS *(volatile int*)(SYSCTRL_BASEADDR + 0xc)
  104. #define SYSCTRL_LPM_RDATA *(volatile int*)(SYSCTRL_BASEADDR + 0x10)
  105. #define SYSCTRL_LPM_SCB *(volatile int*)(SYSCTRL_BASEADDR + 0x14)
  106. #define SYSCTRL_HWCTRL(x) *(volatile uint8_t*)(SYSCTRL_BASEADDR + 0x18 + x)
  107. #define SYSCTRL_RNG_CTRL *(volatile int*)(SYSCTRL_BASEADDR + 0x28)
  108. #define SYSCTRL_RNG_DATAB(x) *(volatile uint8_t*)(SYSCTRL_BASEADDR + 0x2c+x)
  109. #define SYSCTRL_RNG_DATA(x) *(volatile int*)(SYSCTRL_BASEADDR + 0x2c+x*4)
  110. #define SYSCTRL_ROM_SWITCH *(volatile uint8_t*)(SYSCTRL_BASEADDR + 0x3c)
  111. #define SYSCTRL_LPM_STATUS *(volatile byte *)(SYSCTRL_BASEADDR + 0x3d)
  112. #define SYSCTRL_OTPN_ADDR *(volatile uint8_t*)(SYSCTRL_BASEADDR + 0x3e)
  113. #define SYSCTRL_OTPU_ADDR *(volatile uint8_t*)(SYSCTRL_BASEADDR + 0x3f)
  114. #define SECURE_CTRL *(volatile int*)(SECURE_BASEADDR + 0x0)
  115. #define SECURE_STATUS *(volatile int*)(SECURE_BASEADDR + 0x4)
  116. #define SECURE_MEDCON *(volatile int*)(SECURE_BASEADDR + 0x8)
  117. #define SECURE_RAMKEY *(volatile int*)(SECURE_BASEADDR + 0xc)
  118. #define SYSCTRL_HCLK_CON *(volatile int*)(CLKGEN_BASEADDR + 0x00)
  119. #define SYSCTRL_RSACLK *(volatile int*)(CLKGEN_BASEADDR + 0x08)
  120. #define SYSCTRL_CLK_CLS *(volatile int*)(CLKGEN_BASEADDR + 0x0c)
  121. #define SYSCTRL_RST_EN *(volatile int*)(CLKGEN_BASEADDR + 0x14)
  122. #define SYSCTRL_RST_TYPE *(volatile int*)(CLKGEN_BASEADDR + 0x18)
  123. #define SYSCTRL_RESET *(volatile int*)(CLKGEN_BASEADDR + 0x1c)
  124. #define MPUCTRL_ID *(volatile int*)(MPU_BASEADDR + 0x00)
  125. #define MPUCTRL_CTRL *(volatile int*)(MPU_BASEADDR + 0x04)
  126. #define MPUCTRL_FSR *(volatile int*)(MPU_BASEADDR + 0x0c)
  127. #define MPUCTRL_FAR *(volatile int*)(MPU_BASEADDR + 0x10)
  128. #define MPUCTRL_PROTECTION *(volatile int*)(MPU_BASEADDR + 0x14)
  129. #define MPUCTRL_USER_START *(volatile int*)(MPU_BASEADDR + 0x18)
  130. #define MPUCTRL_REGION_BASE(x) *(volatile int*)(MPU_BASEADDR + 0x40 + x*4)
  131. #define MPUCTRL_REGION_LIMIT(x) *(volatile int*)(MPU_BASEADDR + 0x60 + x*4)
  132. #define LPM_CTRL (volatile int*)(LPM_BASEADDR + 0x00)
  133. #define LPM_SENSOR (volatile int*)(LPM_BASEADDR + 0x04)
  134. #define LPM_WKUP_TIMER (volatile int*)(LPM_BASEADDR + 0x08)
  135. #define LPM_SECMAX (volatile int*)(LPM_BASEADDR+0x0c)
  136. #define LPM_GPIO_WKUP (volatile int*)(LPM_BASEADDR + 0x10)
  137. #define LPM_GPIO_WKHI (volatile int*)(LPM_BASEADDR + 0x14)
  138. #define LPM_SLEEP (volatile int*)(LPM_BASEADDR + 0x20)
  139. #define LPM_CLR_INTR (volatile int*)(LPM_BASEADDR + 0x24)
  140. #define LPM_STATUS (volatile int*)(LPM_BASEADDR + 0x78)
  141. #define LPM_RTC_CNT (volatile int*)(LPM_BASEADDR + 0x7c)
  142. #define LPM_KEY(x) (volatile int*)(LPM_BASEADDR + 0x80 + x*4)
  143. #define GPIO_GROUP_NUM 3
  144. #define GPIO_PIN_NUM 16
  145. #define GPIO_CONFIG(x) *((volatile uint8_t*)(GPIO_BASEADDR + x))
  146. #define GPIO_INTR_EN(groupx) *((volatile uint16_t*)(GPIO_BASEADDR+GPIO_GROUP_NUM*GPIO_PIN_NUM) + groupx)
  147. #define GPIO_TRIG_MODE(groupx) *((volatile uint16_t*)(GPIO_BASEADDR+(GPIO_GROUP_NUM*GPIO_PIN_NUM) +GPIO_GROUP_NUM*2) +groupx)
  148. #define GPIO_IN(groupx) *((volatile uint16_t*)(GPIO_BASEADDR+(GPIO_GROUP_NUM*GPIO_PIN_NUM) +GPIO_GROUP_NUM*4)+groupx)
  149. #define DMA_SRC_ADDR(x) *(volatile int*)(DMA_BASEADDR + 0x00 + x*0x100)
  150. #define DMA_DEST_ADDR(x) *(volatile int*)(DMA_BASEADDR + 0x04 + x*0x100)
  151. #define DMA_LEN(x) *(volatile int*)(DMA_BASEADDR + 0x08 + x*0x100)
  152. #define DMA_CONFIG(x) *(volatile uint8_t*)(DMA_BASEADDR + 0x0c + x*0x100)
  153. #define DMA_START(x) *(volatile uint8_t*)(DMA_BASEADDR + 0x0f + x*0x100)
  154. #define DMA_STATUS(x) *(volatile int*)(DMA_BASEADDR + 0x10 + x*0x100)
  155. #define DMA_RPTR(x) *(volatile int*)(DMA_BASEADDR + 0x14 + x*0x100)
  156. #define DMA_WPTR(x) *(volatile int*)(DMA_BASEADDR + 0x18 + x*0x100)
  157. #define QSPI_CTRL *(volatile int*)(QSPI_BASEADDR + 0x1c)
  158. #define QAES_ADDRKEY *(volatile int*)(QSPI_BASEADDR + 0x20)
  159. #define QAES_CTRL *(volatile int*)(QSPI_BASEADDR + 0x24)
  160. #define QAES_RAND(x) *(volatile int*)(QSPI_BASEADDR + 0x28 + x*4)
  161. #define QAES_KEY(x) *(volatile int*)(QSPI_BASEADDR + 0x30 + x*4)
  162. #define QAES_DATA(x) *(volatile int*)(QSPI_BASEADDR + 0x40 + x*4)
  163. #define QAES_KEYB(x) *(volatile byte*)(QSPI_BASEADDR + 0x30 + x)
  164. #define SPID0_CTRL *(volatile int*)0xf891c
  165. #define SPID1_CTRL *(volatile int*)0xf8a1c
  166. #define UART0_CTRL *(volatile int*)0xf8b1c
  167. #define UART0_INTR *(volatile int*)0xf8b20
  168. #define UART0_RDATA *(volatile byte*)0xf8b24
  169. #define UART0_STATUS *(volatile int*)0xf8b28
  170. #define UART1_CTRL *(volatile int*)0xf8c1c
  171. #define UART1_INTR *(volatile int*)0xf8c20
  172. #define UART1_RDATA *(volatile byte*)0xf8c24
  173. #define UART1_STATUS *(volatile int*)0xf8c28
  174. #define IICD_DELAY *(volatile int*)0xf8d1c
  175. #define IICD_CTRL *(volatile int*)0xf8d20
  176. #define USB_CONFIG *(volatile byte*)USB_BASEADDR
  177. #define USB_INT_MASK(x) *(volatile byte*)(USB_BASEADDR + 1 + x)
  178. #define USB_ADDR *(volatile byte*)(USB_BASEADDR + 4)
  179. #define USB_TRG *(volatile byte*)(USB_BASEADDR + 0x10)
  180. #define USB_STALL *(volatile byte*)(USB_BASEADDR + 0x11)
  181. #define USB_CLEAR *(volatile byte*)(USB_BASEADDR + 0x12)
  182. #define USB_EP(x) *(volatile byte*)(USB_BASEADDR + 0x18 + x)
  183. #define USB_EP_LEN(x) *(volatile byte*)(USB_BASEADDR + 0x20 + x)
  184. #define USB_STATUS *(volatile byte*)(USB_BASEADDR + 0x26)
  185. #define USB_FIFO_EMPTY *(volatile byte*)(USB_BASEADDR + 0x27)
  186. #define USB_FIFO_FULL *(volatile byte*)(USB_BASEADDR + 0x28)
  187. #define AES_CNTRL_REG *((volatile uint32_t *)(AES_BASEADDR))
  188. #define AES_DATA_REG0 ((volatile uint32_t *)(AES_BASEADDR+0x10))
  189. #define AES_DATA_REG1 ((volatile uint32_t *)(AES_BASEADDR+0x14))
  190. #define AES_DATA_REG2 ((volatile uint32_t *)(AES_BASEADDR+0x18))
  191. #define AES_DATA_REG3 ((volatile uint32_t *)(AES_BASEADDR+0x1C))
  192. #define AES_KEY_REG0 ((volatile uint32_t *)(AES_BASEADDR+0x20))
  193. #define AES_KEY_REG1 ((volatile uint32_t *)(AES_BASEADDR+0x24))
  194. #define AES_KEY_REG2 ((volatile uint32_t *)(AES_BASEADDR+0x28))
  195. #define AES_KEY_REG3 ((volatile uint32_t *)(AES_BASEADDR+0x2C))
  196. #define AES_KEY_REG4 ((volatile uint32_t *)(AES_BASEADDR+0x30))
  197. #define AES_KEY_REG5 ((volatile uint32_t *)(AES_BASEADDR+0x34))
  198. #define AES_KEY_REG6 ((volatile uint32_t *)(AES_BASEADDR+0x38))
  199. #define AES_KEY_REG7 ((volatile uint32_t *)(AES_BASEADDR+0x3C))
  200. #define AES_RAND_REG0 ((volatile uint32_t *)(AES_BASEADDR+0x40))
  201. #define AES_RAND_REG1 ((volatile uint32_t *)(AES_BASEADDR+0x44))
  202. #define AES_FKEY_REG0 ((volatile uint32_t *)(AES_BASEADDR+0x50))
  203. #define AES_DATAB(x) *(volatile byte*)(AES_BASEADDR + 0x10 + (x))
  204. #define AES_KEYB(x) *(volatile byte*)(AES_BASEADDR + 0x20 + (x))
  205. #define DESCNTRL_REG *((volatile uint32_t *)(DES_BASEADDR+0x00))
  206. #define DESRAND_REG ((volatile uint32_t *)(DES_BASEADDR+0x0c))
  207. #define DESFAKE_KEY ((volatile uint32_t *)(DES_BASEADDR+0x10))
  208. #define DESIV_REG ((volatile uint32_t *)(DES_BASEADDR+0x18))
  209. #define DESDATA_REG ((volatile uint32_t *)(DES_BASEADDR+0x20))
  210. #define DESKEY1_REG ((volatile uint32_t *)(DES_BASEADDR+0x28))
  211. #define DESKEY2_REG ((volatile uint32_t *)(DES_BASEADDR+0x30))
  212. #define DESKEY3_REG ((volatile uint32_t *)(DES_BASEADDR+0x38))
  213. #define DES_KEYB(x) *(volatile byte *)(DES_BASEADDR+0x28 + x)
  214. #define DES_DATAB(x) *(volatile byte *)(DES_BASEADDR+0x20 + x)
  215. #define SM4_REG0 (*(volatile uint32_t *)(SM4_BASEADDR + 0x0))
  216. #define SM4_REG1 (*(volatile uint32_t *)(SM4_BASEADDR + 0x4))
  217. #define SM4_IER (*(volatile uint32_t *)(SM4_BASEADDR + 0x8))
  218. #define SM4_MR (*(volatile uint32_t *)(SM4_BASEADDR + 0xc))
  219. #define SM4_KEY0 ((volatile uint32_t *)(SM4_BASEADDR + 0x10))
  220. #define SM4_KEY1 ((volatile uint32_t *)(SM4_BASEADDR + 0x14))
  221. #define SM4_KEY2 ((volatile uint32_t *)(SM4_BASEADDR + 0x18))
  222. #define SM4_KEY3 ((volatile uint32_t *)(SM4_BASEADDR + 0x1c))
  223. #define SM4_IV0 ((volatile uint32_t *)(SM4_BASEADDR + 0x20))
  224. #define SM4_IV1 ((volatile uint32_t *)(SM4_BASEADDR + 0x24))
  225. #define SM4_IV2 ((volatile uint32_t *)(SM4_BASEADDR + 0x28))
  226. #define SM4_IV3 ((volatile uint32_t *)(SM4_BASEADDR + 0x2c))
  227. #define SM4_DATA0 ((volatile uint32_t *)(SM4_BASEADDR + 0x30))
  228. #define SM4_DATA1 ((volatile uint32_t *)(SM4_BASEADDR + 0x34))
  229. #define SM4_DATA2 ((volatile uint32_t *)(SM4_BASEADDR + 0x38))
  230. #define SM4_DATA3 ((volatile uint32_t *)(SM4_BASEADDR + 0x3c))
  231. #define RECR (*((volatile uint32_t *)(RSA_BASEADDR+0x00)))
  232. #define RESR (*((volatile uint32_t *)(RSA_BASEADDR+0x04)))
  233. #define REFR (*((volatile uint32_t *)(RSA_BASEADDR+0x08)))
  234. #define RESCR (*((volatile uint32_t *)(RSA_BASEADDR+0x0c)))
  235. #define REDQR (*((volatile uint32_t *)(RSA_BASEADDR+0x10)))
  236. #define REINT (*((volatile uint32_t *)(RSA_BASEADDR+0x14)))
  237. #define RECFR (*((volatile uint32_t *)(RSA_BASEADDR+0x18)))
  238. #define REBKR ((volatile uint32_t *)(RSA_BASEADDR+0x1c))
  239. #define REDRR (*((volatile uint32_t *)(RSA_BASEADDR+0x24)))
  240. #define REDAR ((volatile uint32_t *)(RSA_BASEADDR+0x100))
  241. #define REDAR1 ((volatile uint32_t *)(RSA_BASEADDR+0x120))
  242. #define REDAR2 ((volatile uint32_t *)(RSA_BASEADDR+0x140))
  243. #define REDAR3 ((volatile uint32_t *)(RSA_BASEADDR+0x160))
  244. #define REDXR ((volatile uint32_t *)(RSA_BASEADDR+0x200))
  245. #define REDXR1 ((volatile uint32_t *)(RSA_BASEADDR+0x220))
  246. #define REDXR2 ((volatile uint32_t *)(RSA_BASEADDR+0x240))
  247. #define REDXR3 ((volatile uint32_t *)(RSA_BASEADDR+0x260))
  248. #define REDYR ((volatile uint32_t *)(RSA_BASEADDR+0x280))
  249. #define REDYR1 ((volatile uint32_t *)(RSA_BASEADDR+0x2a0))
  250. #define REDYR2 ((volatile uint32_t *)(RSA_BASEADDR+0x2c0))
  251. #define REDYR3 ((volatile uint32_t *)(RSA_BASEADDR+0x2e0))
  252. #define REDBR ((volatile uint32_t *)(RSA_BASEADDR+0x300))
  253. #define REDBR1 ((volatile uint32_t *)(RSA_BASEADDR+0x320))
  254. #define REDBR2 ((volatile uint32_t *)(RSA_BASEADDR+0x340))
  255. #define REDBR3 ((volatile uint32_t *)(RSA_BASEADDR+0x360))
  256. #define REDBRH ((volatile uint32_t *)(RSA_BASEADDR+0x380))
  257. #define REDCR ((volatile uint32_t *)(RSA_BASEADDR+0x500))
  258. #define REDCR1 ((volatile uint32_t *)(RSA_BASEADDR+0x520))
  259. #define REDCR2 ((volatile uint32_t *)(RSA_BASEADDR+0x540))
  260. #define REDCR3 ((volatile uint32_t *)(RSA_BASEADDR+0x560))
  261. #define REDCRH ((volatile uint32_t *)(RSA_BASEADDR+0x580))
  262. #define REDUR ((volatile uint32_t *)(RSA_BASEADDR+0x600))
  263. #define REDVR ((volatile uint32_t *)(RSA_BASEADDR+0x680))
  264. #define REDVR2 ((volatile uint32_t *)(RSA_BASEADDR+0x6c0))
  265. #define REDPR ((volatile uint32_t *)(RSA_BASEADDR+0x700))
  266. #define REDPR1 ((volatile uint32_t *)(RSA_BASEADDR+0x720))
  267. #define REDPR2 ((volatile uint32_t *)(RSA_BASEADDR+0x740))
  268. #define REDPR3 ((volatile uint32_t *)(RSA_BASEADDR+0x760))
  269. #define REDPRH ((volatile uint32_t *)(RSA_BASEADDR+0x780))
  270. #define ISO7811_BASE_ADDR_T1 *((volatile uint32_t *)(ISO7811_BASEADDR+0x00))
  271. #define ISO7811_BASE_ADDR_T2 *((volatile uint32_t *)(ISO7811_BASEADDR+0x04))
  272. #define ISO7811_BASE_ADDR_T3 *((volatile uint32_t *)(ISO7811_BASEADDR+0x08))
  273. #define ISO7811_CTRL *((volatile uint32_t *)(ISO7811_BASEADDR+0x0C))
  274. #define ISO7811_T1_PEAK_VALUE_CFG *((volatile uint32_t *)(ISO7811_BASEADDR+0x10))
  275. #define ISO7811_T1_PEAK_WIDTH_CFG *((volatile uint32_t *)(ISO7811_BASEADDR+0x14))
  276. #define ISO7811_T1_PULSE_WIDTH_CFG *((volatile uint32_t *)(ISO7811_BASEADDR+0x18))
  277. #define ISO7811_T1_AGC_CFG *((volatile uint32_t *)(ISO7811_BASEADDR+0x1c))
  278. #define ISO7811_T2_PEAK_VALUE_CFG *((volatile uint32_t *)(ISO7811_BASEADDR+0x20))
  279. #define ISO7811_T2_PEAK_WIDTH_CFG *((volatile uint32_t *)(ISO7811_BASEADDR+0x24))
  280. #define ISO7811_T2_PULSE_WIDTH_CFG *((volatile uint32_t *)(ISO7811_BASEADDR+0x28))
  281. #define ISO7811_T2_AGC_CFG *((volatile uint32_t *)(ISO7811_BASEADDR+0x2c))
  282. #define ISO7811_T3_PEAK_VALUE_CFG *((volatile uint32_t *)(ISO7811_BASEADDR+0x30))
  283. #define ISO7811_T3_PEAK_WIDTH_CFG *((volatile uint32_t *)(ISO7811_BASEADDR+0x34))
  284. #define ISO7811_T3_PULSE_WIDTH_CFG *((volatile uint32_t *)(ISO7811_BASEADDR+0x38))
  285. #define ISO7811_T3_AGC_CFG *((volatile uint32_t *)(ISO7811_BASEADDR+0x3c))
  286. #define ISO7811_STATUS *((volatile uint32_t *)(ISO7811_BASEADDR+0x40))
  287. #define ISO7811_CHAR_NUM *((volatile uint32_t *)(ISO7811_BASEADDR+0x44))
  288. #define ISO7811_INTERFER_CHAR_NUM *((volatile uint32_t *)(ISO7811_BASEADDR+0x48))
  289. #define ISO7811_DC_EST *((volatile uint32_t *)(ISO7811_BASEADDR+0x4c))
  290. #define ISO7811_INTF_PEAK *((volatile uint32_t *)(ISO7811_BASEADDR+0x50))
  291. #define ISO7811_AGC_PEAK_VAL *((volatile uint32_t *)(ISO7811_BASEADDR +0x54))
  292. #define SYST_CSR *(volatile int*)0xE000E010
  293. #define SYST_RVR *(volatile int*)0xE000E014
  294. #define SYST_CVR *(volatile int*)0xE000E018
  295. #define TRACE_FIFO *(volatile int*)0xe0002020
  296. #define NVIC_ISER *(volatile int*)0xe000e100
  297. #define NVIC_ICER *(volatile int*)0xe000e180
  298. #define NVIC_ISPR *(volatile int*)0xe000e200
  299. #define NVIC_ICPR *(volatile int*)0xe000e280
  300. #define CRC_RESULT_REG *(volatile uint32_t *)(CRC_BASEADDR+0X04)
  301. #define CRC_MASK_REG *(volatile uint32_t *)(CRC_BASEADDR+0X08)
  302. #define CRC_DATAB_REG *(volatile byte *)(CRC_BASEADDR+0X80)
  303. #define CRC_DATAS_REG *(volatile short int *)(CRC_BASEADDR+0X80)
  304. #define CRC_DATA_REG *(volatile int *)(CRC_BASEADDR+0X80)
  305. #define ADC_CTRL0 *(volatile uint8_t*)0xC8970
  306. #define ADC_CTRL1 *(volatile uint8_t*)0xC8971
  307. #define ADC_CTRL2 *(volatile uint8_t*)0xC8972
  308. #define ADC_CTRL3 *(volatile uint8_t*)0xC8973
  309. #define ADC_ENBLE *(volatile uint8_t*)0xC8906
  310. #define ADC_RDATA *(volatile uint16_t*)0xf850e
  311. /* SysTick registers */
  312. /* SysTick control & status */
  313. #define SYSTICK_CSR ((volatile unsigned int *)0xE000E010)
  314. /* SysTick Reload value */
  315. #define SYSTICK_RVR ((volatile unsigned int *)0xE000E014)
  316. /* SysTick Current value */
  317. #define SYSTICK_CVR ((volatile unsigned int *)0xE000E018)
  318. /* SysTick CSR register bits */
  319. #define SYSTICK_CSR_COUNTFLAG 16
  320. #define SYSTICK_CSR_CLKSOURCE 2
  321. #define SYSTICK_CSR_TICKINT 1
  322. #define SYSTICK_CSR_ENABLE 0
  323. //================ bit definitions ====================
  324. #define OTBIT_DIN 1<<0
  325. #define OTBIT_DLE 1<<1
  326. #define OTBIT_CEB 1<<2
  327. #define OTBIT_RSTB 1<<3
  328. #define OTBIT_CLE 1<<4
  329. #define OTBIT_PGMEN 1<<5
  330. #define OTBIT_PGMVFY 1<<6
  331. #define OTBIT_READEN 1<<7
  332. #define OTBIT_VPPEN 1<<8
  333. #define OTBIT_WEB 1<<9
  334. #define AES_CNTRL_REG_START 0x1
  335. #define AES_CNTRL_KEY_SEL_128 0X00
  336. #define AES_CNTRL_KEY_SEL_192 0X08
  337. #define AES_CNTRL_KEY_SEL_256 0X10
  338. #define AES_CNTRL_ENC 0X00
  339. #define AES_CNTRL_DEC 0X02
  340. #define AES_CNTRL_ENABLE_RAND 0X20
  341. #define DMACH_QSPI 0
  342. #define DMACH_SPID0 1
  343. #define DMACH_SPID1 2
  344. #define DMACH_UART0 3
  345. #define DMACH_UART1 4
  346. #define DMACH_IICD 5
  347. #define DMACH_MEMCP 6
  348. #define DMA_START_BIT 7
  349. #define DMA_CLR_INTR_BIT 6
  350. #define DMA_RESET_BIT 5
  351. //==DES==
  352. #define DESCNTRL_REG_START 0x1
  353. #define DESCNTRL_REG_ENCRYPT 0x2
  354. #define DESCNTRL_REG_KEY_SEL 0xc
  355. #define DESCNTRL_REG_DES_MODE 0x10
  356. #define DESCNTRL_REG_OP_MODE 0x60
  357. #define DESCNTRL_REG_RAND_EN 0x80
  358. #define DESCNTRL_REG_ENCRYPT_ENC 0X00
  359. #define DESCNTRL_REG_ENCRYPT_DEC 0X02
  360. #define DESCNTRL_REG_KEY_SEL_DES1 0x00
  361. #define DESCNTRL_REG_KEY_SEL_DES2 0x04
  362. #define DESCNTRL_REG_KEY_SEL_DES3 0x08
  363. #define DESCNTRL_REG_KEY_SEL_TDES2 0x00
  364. #define DESCNTRL_REG_KEY_SEL_TDES3 0x04
  365. #define DESCNTRL_REG_DES_MODE_DES 0X00
  366. #define DESCNTRL_REG_DES_MODE_TDES 0X10
  367. #define DESCNTRL_REG_OP_MODE_ECB 0x00
  368. #define DESCNTRL_REG_OP_MODE_CBC 0x20
  369. //==DES==END==
  370. //==RSA==
  371. //sfr bit
  372. // RECR register
  373. #define RECR_start 0x01
  374. #define RECR_idle_run 0x02
  375. #define RECR_bus_crypt_en 0x04
  376. // RESR register
  377. #define RESR_error_flag 0x01
  378. #define RESR_opdata_error 0x02
  379. //REINT register
  380. #define REINT_rsa_int 0x01
  381. //==RSA==END==
  382. #define CLKCLS_INT 1
  383. #define CLKCLS_SHA 2
  384. #define CLKCLS_CRC 3
  385. #define CLKCLS_TIM 4
  386. #define CLKCLS_WDT 5
  387. #define CLKCLS_USB 6
  388. #define CLKCLS_SPI 7
  389. #define CLKCLS_DES 8
  390. #define CLKCLS_RSA 9
  391. #define CLKCLS_AES 10
  392. #define CLKCLS_GPIO 11
  393. #define CLKCLS_7816 12
  394. #define CLKCLS_BT 13
  395. #define CLKCLS_SM4 14
  396. #define CLKCLS_UART 15
  397. #define CLKCLS_7811 16
  398. #define CLKCLS_ADC7811 17
  399. #define CLKCLS_CP 18
  400. #define INTR_USB 0
  401. #define INTR_IIC 1
  402. #define INTR_QSPI 2
  403. #define INTR_SPI0 3
  404. #define INTR_SPI1 4
  405. #define INTR_UART0 5
  406. #define INTR_UART1 6
  407. #define INTR_MEMCP 7
  408. #define INTR_RSA 8
  409. #define INTR_SCI0 9
  410. #define INTR_SCI1 10
  411. #define INTR_BT 11
  412. #define INTR_GPIO 12
  413. #define INTR_TMR0 13
  414. #define INTR_TMR1 14
  415. #define INTR_TMR2 15
  416. #define INTR_TMR3 16
  417. #define INTR_TMR4 17
  418. #define INTR_TMR5 18
  419. #define INTR_TMR6 19
  420. #define INTR_TMR7 20
  421. #define INTR_TMR8 21
  422. #define INTR_SM4 22
  423. #define INTR_SEC 23
  424. #define INTR_ISO7811 24
  425. #define INTR_TRNG 25
  426. #define INTR_WDT 26
  427. #define SCICFG_TMODE 0
  428. #define SCICFG_BIT_ORDER 1
  429. #define SCICFG_PAD_TYPE 2
  430. #define SCICFG_ETU_SEL 3
  431. #define SCICFG_RETRY 5
  432. #define SCICFG_RETRY_EN 8
  433. #define SCICFG_IO_EN 9
  434. #define SCICFG_BGTEN 10
  435. #define SCICFG_CWTEN 11
  436. #define SCICFG_MCLK_SEL 12
  437. #define SCICFG_MASTER 15
  438. #define SCICFG_EDCEN 16
  439. #define KCFG_COL 3
  440. #define KCFG_MDDBC 8
  441. #define KCFG_MUDBC 12
  442. #define KCFG_UDBC 16
  443. #define KCFG_CYLE 20
  444. #define SM4_CNTRL_ECB 0X00
  445. #define SM4_CNTRL_CBC 0X02
  446. #define SM4_CNTRL_ENC 0X01
  447. #define SM4_CNTRL_DEC 0X00
  448. /* =============== qspi flash command =================== */
  449. #define W25X_WRITE_ENABLE 0x06
  450. #define W25X_WRITE_DISABLE 0x04
  451. #define W25X_READ_STATUS1 0x05
  452. #define W25X_READ_STATUS2 0x35
  453. #define W25X_WRITE_STATUS 0x01
  454. #define W25X_READ_DATA 0x03
  455. #define W25X_FASTREAD_DATA 0x0B
  456. #define W25X_FASTREAD_DUAL1 0x3B
  457. #define W25X_FASTREAD_DUAL2 0xBB
  458. #define W25X_FASTREAD_QUAD1 0x6B
  459. #define W25X_FASTREAD_QUAD2 0xEB
  460. #define W25X_FASTREAD_QUAD3 0xE7
  461. #define W25X_PAGE_PROGRAM 0x02
  462. #define W25X_SECTOR_ERASE 0x20
  463. #define W25X_BLOCK_ERASE32K 0x52
  464. #define W25X_BLOCK_ERASE64K 0xD8
  465. #define W25X_CHIP_ERASE 0xC7
  466. #define W25X_POWER_DOWN 0xB9
  467. #define W25X_RELEASE_POWERDOWN 0xAB
  468. #define W25X_DEVICEID 0xAB
  469. #define W25X_MANUFACT_DEVICEID 0x90
  470. #define W25X_JEDEC_DEVICEID 0x9F
  471. #define QSPICFG_XIPEN 1 << 12
  472. #define QSPICFG_DECEN 1 << 13
  473. #define QSPICFG_DUAL_MODE 1 << 0
  474. #define QSPICFG_QUAD_MODE 2 << 0
  475. #define QSPICFG_MBYTE 1 << 2
  476. #define QSPICFG_MBYTE_CONT 1 << 3
  477. #define QSPICFG_RETRY 3 << 24
  478. #define QCSFT_DUMMY 8
  479. #define QCSFT_CMD 16
  480. #define QSPICFG_MODE_3B QSPICFG_DUAL_MODE | W25X_FASTREAD_DUAL1 << QCSFT_CMD | 8 << QCSFT_DUMMY
  481. #define QSPICFG_MODE_6B QSPICFG_QUAD_MODE | W25X_FASTREAD_QUAD1 << QCSFT_CMD | 8 << QCSFT_DUMMY
  482. #define QSPICFG_MODE_BB QSPICFG_DUAL_MODE | QSPICFG_MBYTE | 0x60 | W25X_FASTREAD_DUAL2 << QCSFT_CMD
  483. #define QSPICFG_MODE_EB QSPICFG_QUAD_MODE | QSPICFG_MBYTE | 0x60 | W25X_FASTREAD_QUAD2 << QCSFT_CMD | 4 << QCSFT_DUMMY
  484. #define QSPICFG_MODE_E7 QSPICFG_QUAD_MODE | QSPICFG_MBYTE | 0x60 | W25X_FASTREAD_QUAD3 << QCSFT_CMD | 2 << QCSFT_DUMMY
  485. #define LPMCFG_BUCK_EN 1 << 25
  486. #define LPMCFG_TIMER_EN 1 << 28
  487. #define LPMCFG_KRST_EN 1 << 29
  488. #define LPMCFG_SENSOR_DUR 1 << 30
  489. #define LPMSEN_SENSOR_DLY 5
  490. #define LPMSEN_SENSOR_LOCK 7
  491. #define LPMSEN_SHIELD_IO_EN 8
  492. #define LPMSEN_SHIELD_IO_TYPE 12
  493. #define LPMSEN_SHIELD_IO_PU 16
  494. #define LPMSEN_SHIELD_INTERVAL 24
  495. #define LPMSEN_SHIELD_ENABLE 27
  496. #define LPMSEN_SHIELD_PU_DLY 28
  497. #define LPMSEN_SHIELD_A_DLY 30
  498. #define LPMCFG_SENSOR_LOCK 31
  499. //gpio ctrl bit define
  500. #define GPCFG_INPUT 0
  501. #define GPCFG_QSPI_NCS 2
  502. #define GPCFG_QSPI_SCK 3
  503. #define GPCFG_QSPI_IO0 4
  504. #define GPCFG_QSPI_IO1 5
  505. #define GPCFG_QSPI_IO2 6
  506. #define GPCFG_QSPI_IO3 7
  507. #define GPCFG_UART0_TXD 8
  508. #define GPCFG_UART0_RXD 9
  509. #define GPCFG_UART0_RTS 10
  510. #define GPCFG_UART0_CTS 11
  511. #define GPCFG_UART1_TXD 12
  512. #define GPCFG_UART1_RXD 13
  513. #define GPCFG_UART1_RTS 14
  514. #define GPCFG_UART1_CTS 15
  515. #define GPCFG_PWM_OUT0 16
  516. #define GPCFG_PWM_OUT1 17
  517. #define GPCFG_PWM_OUT2 18
  518. #define GPCFG_PWM_OUT3 19
  519. #define GPCFG_PWM_OUT4 20
  520. #define GPCFG_PWM_OUT5 21
  521. #define GPCFG_PWM_OUT6 22
  522. #define GPCFG_PWM_OUT7 23
  523. #define GPCFG_SPID0_NCS 24
  524. #define GPCFG_SPID0_SCK 25
  525. #define GPCFG_SPID0_MOSI 26
  526. #define GPCFG_SPID0_SDIO 27
  527. #define GPCFG_SPID0_MISO 28
  528. #define GPCFG_SPID0_NCSIN 29
  529. #define GPCFG_SPID0_SCKIN 30
  530. #define GPCFG_PWM_OUT8 31
  531. #define GPCFG_SPID1_NCS 48
  532. #define GPCFG_SPID1_SCK 49
  533. #define GPCFG_SPID1_MOSI 50
  534. #define GPCFG_SPID1_SDIO 51
  535. #define GPCFG_SPID1_MISO 52
  536. #define GPCFG_SPID1_NCSIN 53
  537. #define GPCFG_SPID1_SCKIN 54
  538. #define GPCFG_NFC_CLK_OUT 55
  539. #define GPCFG_SCI7816_IO 56
  540. #define GPCFG_ICE 57
  541. #define GPCFG_IIC_SCL 58
  542. #define GPCFG_IIC_SDA 59
  543. #define GPCFG_JTAG_SWCLK 60
  544. #define GPCFG_JTAG_SWDAT 61
  545. #define GPCFG_OUTPUT_LOW 62
  546. #define GPCFG_OUTPUT_HIGH 63
  547. #define GPCFG_PU 64
  548. #define GPCFG_PD 128
  549. #define GPCFG_ANALOG 192
  550. #define TIM_CTRL_ENABLE ((uint32_t)0)
  551. #define TIM_CTRL_START_LEVEL ((uint32_t)1)
  552. #define TIM_CTRL_MODE ((uint32_t)2)
  553. #define TIM_CTRL_AUTO_RELOAD ((uint32_t)3)
  554. /* =============== macros =================== */
  555. #define PREFETCH_LINE(addr) *(volatile int*)addr = 0
  556. #define GETWORD(p) ((uint16_t)((*(volatile uint8_t *)((uint32_t)p)) |((((uint16_t)(*(volatile uint8_t *)((uint32_t)(p+1))))<<8) & 0xff00)))
  557. static inline void enable_clock(int id)
  558. {
  559. SYSCTRL_CLK_CLS &= ~(1 << id);
  560. }
  561. static inline void disable_clock(int id)
  562. {
  563. SYSCTRL_CLK_CLS |= 1 << id;
  564. }
  565. static inline void enable_intr(int intid)
  566. {
  567. NVIC_ISER |= 1 << intid;
  568. }
  569. static inline void disable_intr(int intid)
  570. {
  571. NVIC_ICER = 1 << intid;
  572. }
  573. extern void delay(int);//delay(x)=delay(x*110+450ns)
  574. extern void invalidate_icache(int addr, int len);
  575. //#define SCY_FALSE seesim1()
  576. /*********************************************/
  577. #define SYSCTRL_PCLK_CON *(volatile int*)0xf7208
  578. #define SYSCTRL_POWERMODE *(volatile int*)0xf7218
  579. //#define debug
  580. #endif /* __YC3121_H__ */