CH579SFR.h 123 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934
  1. /* Define for CH579 */
  2. /* Website: http://wch.cn */
  3. /* Email: tech@wch.cn */
  4. /* Author: W.ch 2016.10 */
  5. /* V0.2 SpecialFunctionRegister */
  6. // multi-blocks: __BASE_TYPE__, __CH579SFR_H__, __CH579ETHSFR_H__, __CH579USBSFR_H__, __USB_TYPE__...
  7. #ifndef __BASE_TYPE__
  8. #define __BASE_TYPE__
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. /* ********************************************************************************************************************* */
  13. /* Base types & constants */
  14. #ifndef TRUE
  15. #define TRUE 1
  16. #define FALSE 0
  17. #endif
  18. #ifndef NULL
  19. #define NULL 0
  20. #endif
  21. #ifndef VOID
  22. #define VOID void
  23. #endif
  24. #ifndef CONST
  25. #define CONST const
  26. #endif
  27. #ifndef BOOL
  28. typedef unsigned char BOOL;
  29. #endif
  30. #ifndef BOOLEAN
  31. typedef unsigned char BOOLEAN;
  32. #endif
  33. #ifndef CHAR
  34. typedef char CHAR;
  35. #endif
  36. #ifndef INT8
  37. typedef char INT8;
  38. #endif
  39. #ifndef INT16
  40. typedef short INT16;
  41. #endif
  42. #ifndef INT32
  43. typedef long INT32;
  44. #endif
  45. #ifndef UINT8
  46. typedef unsigned char UINT8;
  47. #endif
  48. #ifndef UINT16
  49. typedef unsigned short UINT16;
  50. #endif
  51. #ifndef UINT32
  52. typedef unsigned long UINT32;
  53. #endif
  54. #ifndef UINT8V
  55. typedef unsigned char volatile UINT8V;
  56. #endif
  57. #ifndef UINT16V
  58. typedef unsigned short volatile UINT16V;
  59. #endif
  60. #ifndef UINT32V
  61. typedef unsigned long volatile UINT32V;
  62. #endif
  63. #ifndef PVOID
  64. typedef void *PVOID;
  65. #endif
  66. #ifndef PCHAR
  67. typedef char *PCHAR;
  68. #endif
  69. #ifndef PCHAR
  70. typedef const char *PCCHAR;
  71. #endif
  72. #ifndef PINT8
  73. typedef char *PINT8;
  74. #endif
  75. #ifndef PINT16
  76. typedef short *PINT16;
  77. #endif
  78. #ifndef PINT32
  79. typedef long *PINT32;
  80. #endif
  81. #ifndef PUINT8
  82. typedef unsigned char *PUINT8;
  83. #endif
  84. #ifndef PUINT16
  85. typedef unsigned short *PUINT16;
  86. #endif
  87. #ifndef PUINT32
  88. typedef unsigned long *PUINT32;
  89. #endif
  90. #ifndef PUINT8V
  91. typedef volatile unsigned char *PUINT8V;
  92. #endif
  93. #ifndef PUINT16V
  94. typedef volatile unsigned short *PUINT16V;
  95. #endif
  96. #ifndef PUINT32V
  97. typedef volatile unsigned long *PUINT32V;
  98. #endif
  99. /* ********************************************************************************************************************* */
  100. /* Base macros */
  101. #ifndef min
  102. #define min(a,b) (((a) < (b)) ? (a) : (b))
  103. #endif
  104. #ifndef max
  105. #define max(a,b) (((a) > (b)) ? (a) : (b))
  106. #endif
  107. #ifdef DEBUG
  108. #define PRINT(X...) printf(X)
  109. #else
  110. #define PRINT(X...)
  111. #endif
  112. /* Calculate the byte offset of a field in a structure of type */
  113. #define FIELD_OFFSET(Type, Field) ((UINT16)&(((Type *)0)->Field))
  114. /* Calculate the size of a field in a structure of type */
  115. #define FIELD_SIZE(Type, Field) (sizeof(((Type *)0)->Field))
  116. /* An expression that yields the type of a field in a struct */
  117. #define FIELD_TYPE(Type, Field) (((Type *)0)->Field)
  118. /* Return the number of elements in a statically sized array */
  119. #define NUMBER_OF(Array) (sizeof(Array)/sizeof((Array)[0]))
  120. #define NUMBER_OF_FIELD(Type, Field) (NUMBER_OF(FIELD_TYPE(Type, Field)))
  121. #ifdef __cplusplus
  122. }
  123. #endif
  124. #endif // __BASE_TYPE__
  125. #ifndef __CH579SFR_H__
  126. #define __CH579SFR_H__
  127. #ifdef __cplusplus
  128. extern "C" {
  129. #endif
  130. /* ********************************************************************************************************************* */
  131. // Address Space
  132. // CODE: 00000000H - 0003FFFFH 256K
  133. // DATA: 20000000H - 20007FFFH 32KB
  134. // SFR: 40000000H - 4000FFFFH 64KB
  135. // PPB: E0000000H - E000FFFFH 64KB
  136. //
  137. // SFR: 40000000H - 4000FFFFH, 64KB
  138. // SYS: +1000H - 1BFFH, include base configuration, interrupt, GPIO, etc...
  139. // TMR0: +2000H - 23FFH
  140. // TMR1: +2400H - 27FFH
  141. // TMR2: +2800H - 2BFFH
  142. // TMR3: +2C00H - 2FFFH
  143. // UART0: +3000H - 33FFH
  144. // UART1: +3400H - 37FFH
  145. // UART2: +3800H - 3BFFH
  146. // UART3: +3C00H - 3FFFH
  147. // SPI0: +4000H - 43FFH
  148. // SPI1: +4400H - 47FFH
  149. // PWMx: +5000H - 53FFH
  150. // LCD: +6000H - 63FFH
  151. // LED: +6400H - 67FFH
  152. // USB: +8000H - 83FFH
  153. // ETH: +9000H - 93FFH
  154. // BLE: +C000H - D3FFH
  155. // Register Bit Attribute / Bit Access Type
  156. // RF: Read only for Fixed value
  157. // RO: Read Only (internal change)
  158. // RZ: Read only with auto clear Zero
  159. // WO: Write Only (read zero or different)
  160. // WA: Write only under safe Accessing mode (read zero or different)
  161. // WZ: Write only with auto clear Zero
  162. // RW: Read / Write
  163. // RWA: Read / Write under safe Accessing mode
  164. // RW1: Read / Write 1 to Clear
  165. /* Register name rule:
  166. R32_* for 32 bits register (UINT32,ULONG)
  167. R16_* for 16 bits register (UINT16,USHORT)
  168. R8_* for 8 bits register (UINT8,UCHAR)
  169. RB_* for bit or bit mask of 8 bit register
  170. BA_* for base address point
  171. b* for GPIO bit mask
  172. Others for register address offset */
  173. /* ********************************************************************************************************************* */
  174. /* System: safe accessing register */
  175. #define R32_SAFE_ACCESS (*((PUINT32V)0x40001040)) // RW, safe accessing
  176. #define R8_SAFE_ACCESS_SIG (*((PUINT8V)0x40001040)) // WO, safe accessing sign register, must write SAFE_ACCESS_SIG1 then SAFE_ACCESS_SIG2 to enter safe accessing mode
  177. #define RB_SAFE_ACC_MODE 0x03 // RO, current safe accessing mode: 11=safe/unlocked (SAM), other=locked (00..01..10..11)
  178. #define RB_SAFE_ACC_ACT 0x08 // RO, indicate safe accessing status now: 0=locked, read only, 1=safe/unlocked (SAM), write enabled
  179. #define RB_SAFE_ACC_TIMER 0x70 // RO, safe accessing timer bit mask (16*clock number)
  180. #define SAFE_ACCESS_SIG1 0x57 // WO: safe accessing sign value step 1
  181. #define SAFE_ACCESS_SIG2 0xA8 // WO: safe accessing sign value step 2
  182. #define SAFE_ACCESS_SIG0 0x00 // WO: safe accessing sign value for disable
  183. #define R8_CHIP_ID (*((PUINT8V)0x40001041)) // RF, chip ID register, always is ID_CH57*
  184. #define R8_SAFE_ACCESS_ID (*((PUINT8V)0x40001042)) // RF, safe accessing ID register, always 0x04
  185. #define R8_WDOG_COUNT (*((PUINT8V)0x40001043)) // RW, watch-dog count, count by clock frequency Fsys/131072
  186. /* System: global configuration register */
  187. #define R32_GLOBAL_CONFIG (*((PUINT32V)0x40001044)) // RW, global configuration
  188. #define R8_RESET_STATUS (*((PUINT8V)0x40001044)) // RWA, reset status, SAM
  189. #define RB_RESET_FLAG 0x07 // RO: recent reset flag
  190. #define RST_FLAG_SW 0x00
  191. #define RST_FLAG_RPOR 0x01
  192. #define RST_FLAG_WTR 0x02
  193. #define RST_FLAG_MR 0x03
  194. //#define RST_FLAG_GPWSM 0x04 // RO, power on reset flag during sleep/shutdown: 0=no power on reset during sleep/shutdown, 1=power on reset occurred during sleep/shutdown
  195. #define RST_FLAG_GPWSM 0x05
  196. #define RB_ROM_CODE_OFS 0x10 // RWA, code offset address selection in Flash ROM: 0=start address 0x000000, 1=start address 0x008000
  197. // RB_RESET_FLAG: recent reset flag
  198. // 000 - SR, software reset, by RB_SOFTWARE_RESET=1 @RB_WDOG_RST_EN=0
  199. // 001 - RPOR, real power on reset
  200. // 010 - WTR, watch-dog timer-out reset
  201. // 011 - MR, external manual reset by RST pin input low
  202. // 101 - GRWSM, global reset by waking under shutdown mode
  203. // 1?? - LRW, power on reset occurred during sleep
  204. #define R8_GLOB_CFG_INFO (*((PUINT8V)0x40001045)) // RO, global configuration information and status
  205. #define RB_CFG_ROM_READ 0x01 // RO, indicate protected status of Flash ROM code and data: 0=reading protect, 1=enable read by external programmer
  206. #define RB_CFG_RESET_EN 0x04 // RO, manual reset input enable status
  207. #define RB_CFG_BOOT_EN 0x08 // RO, boot-loader enable status
  208. #define RB_CFG_DEBUG_EN 0x10 // RO, debug enable status
  209. #define RB_BOOT_LOADER 0x20 // RO, indicate boot loader status: 0=application status (by software reset), 1=boot loader status
  210. #define R8_RST_WDOG_CTRL (*((PUINT8V)0x40001046)) // RWA, reset and watch-dog control, SAM
  211. #define RB_SOFTWARE_RESET 0x01 // WA/WZ, global software reset, high action, auto clear
  212. #define RB_WDOG_RST_EN 0x02 // RWA, enable watch-dog reset if watch-dog timer overflow: 0=as timer only, 1=enable reset if timer overflow
  213. #define RB_WDOG_INT_EN 0x04 // RWA, watch-dog timer overflow interrupt enable: 0=disable, 1=enable
  214. #define RB_WDOG_INT_FLAG 0x10 // RW1, watch-dog timer overflow interrupt flag, cleared by RW1 or reload watch-dog count or __SEV(Send-Event)
  215. #define R8_GLOB_RESET_KEEP (*((PUINT8V)0x40001047)) // RW, value keeper during global reset
  216. /* System: clock configuration register */
  217. #define R32_CLOCK_CONFIG (*((PUINT32V)0x40001008)) // RWA, clock configuration, SAM
  218. #define R16_CLK_SYS_CFG (*((PUINT16V)0x40001008)) // RWA, system clock configuration, SAM
  219. #define RB_CLK_PLL_DIV 0x1F // RWA, output clock divider from PLL or CK32M
  220. #define RB_CLK_SYS_MOD 0xC0 // RWA, system clock source mode: 00=divided from 32MHz, 01=divided from PLL-480MHz, 10=directly from 32MHz, 11=directly from 32KHz
  221. #define RB_CLK_OSC32M_XT 0x0200 // RWA, 32MHz clock source selection: 0=internal 32MHz oscillator, 1=external 32MHz oscillator
  222. #define RB_XO_DI 0x8000 // RO, X32MO input status sample value
  223. #define R8_HFCK_PWR_CTRL (*((PUINT8V)0x4000100A)) // RWA, high frequency clock module power control, SAM
  224. #define RB_CLK_XT32M_PON 0x04 // RWA, external 32MHz oscillator power control: 0=power down, 1-power on
  225. #define RB_CLK_INT32M_PON 0x08 // RWA, internal 32MHz oscillator power control: 0=power down, 1-power on
  226. #define RB_CLK_PLL_PON 0x10 // RWA, PLL power control: 0=power down, 1-power on
  227. // Fck32m = RB_CLK_OSC32M_XT ? XT_32MHz : RC_32MHz
  228. // Fck32k = RB_CLK_OSC32K_XT ? XT_32KHz : RC_32KHz
  229. // Fpll = Fck32m * 15 = 480MHz
  230. // Fsys = RB_CLK_SYS_MOD[1] ? ( RB_CLK_SYS_MOD[0] ? Fck32k : Fck32m ) : ( ( RB_CLK_SYS_MOD[0] ? Fpll : Fck32m ) / RB_CLK_PLL_DIV )
  231. // default: Fsys = Fck32m / RB_CLK_PLL_DIV = 32MHz / 5 = 6.4MHz
  232. // range: 32KHz, 1MHz~16MHz, 32MHz, 15MHz~48MHz
  233. /* System: sleep control register */
  234. #define R32_SLEEP_CONTROL (*((PUINT32V)0x4000100C)) // RWA, sleep control, SAM
  235. #define R8_SLP_CLK_OFF0 (*((PUINT8V)0x4000100C)) // RWA, sleep clock off control byte 0, SAM
  236. #define RB_SLP_CLK_TMR0 0x01 // RWA, close TMR0 clock
  237. #define RB_SLP_CLK_TMR1 0x02 // RWA, close TMR1 clock
  238. #define RB_SLP_CLK_TMR2 0x04 // RWA, close TMR2 clock
  239. #define RB_SLP_CLK_TMR3 0x08 // RWA, close TMR3 clock
  240. #define RB_SLP_CLK_UART0 0x10 // RWA, close UART0 clock
  241. #define RB_SLP_CLK_UART1 0x20 // RWA, close UART1 clock
  242. #define RB_SLP_CLK_UART2 0x40 // RWA, close UART2 clock
  243. #define RB_SLP_CLK_UART3 0x80 // RWA, close UART3 clock
  244. #define R8_SLP_CLK_OFF1 (*((PUINT8V)0x4000100D)) // RWA, sleep clock off control byte 1, SAM
  245. #define RB_SLP_CLK_SPI0 0x01 // RWA, close SPI0 clock
  246. #define RB_SLP_CLK_SPI1 0x02 // RWA, close SPI1 clock
  247. #define RB_SLP_CLK_PWMX 0x04 // RWA, close PWMx clock
  248. #define RB_SLP_CLK_LCD 0x08 // RWA, close LCD clock
  249. #define RB_SLP_CLK_USB 0x10 // RWA, close USB clock
  250. #define RB_SLP_CLK_ETH 0x20 // RWA, close ETH clock
  251. #define RB_SLP_CLK_LED 0x40 // RWA, close LED clock
  252. #define RB_SLP_CLK_BLE 0x80 // RWA, close BLE clock
  253. #define R8_SLP_WAKE_CTRL (*((PUINT8V)0x4000100E)) // RWA, wake control, SAM
  254. #define RB_SLP_USB_WAKE 0x01 // RWA, enable USB waking
  255. #define RB_SLP_ETH_WAKE 0x02 // RWA, enable ETH waking
  256. //#define RB_SLP_BLE_WAKE 0x04 // RWA, enable BLE waking
  257. #define RB_SLP_RTC_WAKE 0x08 // RWA, enable RTC waking
  258. #define RB_SLP_GPIO_WAKE 0x10 // RWA, enable GPIO waking
  259. #define RB_SLP_BAT_WAKE 0x20 // RWA, enable BAT waking
  260. #define R8_SLP_POWER_CTRL (*((PUINT8V)0x4000100F)) // RWA, peripherals power down control, SAM
  261. //#define RB_SLP_USB_PWR_DN 0x01 // RWA, enable USB power down
  262. #define RB_SLP_ETH_PWR_DN 0x02 // RWA, enable ETH PHY power down
  263. //#define RB_SLP_BLE_PWR_DN 0x04 // RWA, enable BLE power down
  264. #define RB_SLP_ROM_PWR_DN 0x08 // RWA, enable Flash ROM power down during halt
  265. #define RB_SLP_CLK_RAMX 0x10 // RWA, close main SRAM clock
  266. #define RB_SLP_CLK_RAM2K 0x20 // RWA, close retention 2KB SRAM clock
  267. /* System: I/O pin configuration register */
  268. #define R32_PIN_CONFIG (*((PUINT32V)0x40001018)) // RW, I/O pin configuration
  269. #define R16_PIN_ALTERNATE (*((PUINT16V)0x40001018)) // RW, function pin alternate configuration
  270. #define RB_PIN_TMR0 0x01 // RW, TMR0 alternate pin enable: 0=TMR0/PWM0/CAP0 on PA[3], 1=TMR0_/PWM0_/CAP0_ on PB[19]
  271. #define RB_PIN_TMR1 0x02 // RW, TMR1 alternate pin enable: 0=TMR1/PWM1/CAP1 on PA[10], 1=TMR1_/PWM1_/CAP1_ on PB[10]
  272. #define RB_PIN_TMR2 0x04 // RW, TMR2 alternate pin enable: 0=TMR2/PWM2/CAP2 on PA[11], 1=TMR2_/PWM2_/CAP2_ on PB[11]
  273. #define RB_PIN_TMR3 0x08 // RW, TMR3 alternate pin enable: 0=TMR3/PWM3/CAP3 on PA[2], 1=TMR3_/PWM3_/CAP3_ on PB[18]
  274. #define RB_PIN_UART0 0x10 // RW, RXD0/TXD0 alternate pin enable: 0=RXD0/TXD0 on PB[4]/PB[7], 1=RXD0_/TXD0_ on PA[15]/PA[14]
  275. #define RB_PIN_UART1 0x20 // RW, RXD1/TXD1 alternate pin enable: 0=RXD1/TXD1 on PA[8]/PA[9], 1=RXD1_/TXD1_ on PB[8]/PB[9]
  276. #define RB_PIN_UART2 0x40 // RW, RXD2/TXD2 alternate pin enable: 0=RXD2/TXD2 on PA[6]/PA[7], 1=RXD2_/TXD2_ on PB[22]/PB[23]
  277. #define RB_PIN_UART3 0x80 // RW, RXD3/TXD3 alternate pin enable: 0=RXD3/TXD3 on PA[4]/PA[5], 1=RXD3_/TXD3_ on PB[20]/PB[21]
  278. #define RB_PIN_SPI0 0x100 // RW, SCS/SCK0/MOSI/MISO alternate pin enable: 0=SCS/SCK0/MOSI/MISO on PA[12]/PA[13]/PA[14]/PA[15], 1=SCS_/SCK0_/MOSI_/MISO_ on PB[12]/PB[13]/PB[14]/PB[15]
  279. #define R16_PIN_ANALOG_IE (*((PUINT16V)0x4000101A)) // RW, analog pin enable and digital input disable
  280. #define RB_PIN_SEG0_3_IE 0x01 // RW, LCD segment 0~3 digital input disable: 0=digital input enable, 1=digital input disable
  281. #define RB_PIN_SEG4_7_IE 0x02 // RW, LCD segment 4~7 digital input disable: 0=digital input enable, 1=digital input disable
  282. #define RB_PIN_SEG8_11_IE 0x04 // RW, LCD segment 8~11 digital input disable: 0=digital input enable, 1=digital input disable
  283. #define RB_PIN_SEG12_15_IE 0x08 // RW, LCD segment 12~15 digital input disable: 0=digital input enable, 1=digital input disable
  284. #define RB_PIN_SEG16_19_IE 0x10 // RW, LCD segment 16~19 digital input disable: 0=digital input enable, 1=digital input disable
  285. #define RB_PIN_SEG20_23_IE 0x20 // RW, LCD segment 20~23 digital input disable: 0=digital input enable, 1=digital input disable
  286. #define RB_PIN_ETH_IE 0x40 // RW, ETH analog I/O enable and digital input disable: 0=analog I/O disable and digital input enable, 1=analog I/O enable and digital input disable
  287. #define RB_PIN_USB_IE 0x80 // RW, USB analog I/O enable: 0=analog I/O disable, 1=analog I/O enable
  288. #define RB_PIN_ADC8_9_IE 0x0100 // RW, ADC/TouchKey channel 9/8 digital input disable: 0=digital input enable, 1=digital input disable
  289. #define RB_PIN_ADC6_7_IE 0x0200 // RW, ADC/TouchKey channel 7/6 digital input disable: 0=digital input enable, 1=digital input disable
  290. #define RB_PIN_ADC0_1_IE 0x0400 // RW, ADC/TouchKey channel 0/1 digital input disable: 0=digital input enable, 1=digital input disable
  291. #define RB_PIN_ADC10_11_IE 0x0800 // RW, ADC/TouchKey channel 10/11 digital input disable: 0=digital input enable, 1=digital input disable
  292. #define RB_PIN_ADC12_13_IE 0x1000 // RW, ADC/TouchKey channel 12/13 digital input disable: 0=digital input enable, 1=digital input disable
  293. #define RB_PIN_XT32K_IE 0x2000 // RW, external 32KHz oscillator digital input disable: 0=digital input enable, 1=digital input disable
  294. #define RB_PIN_ADC2_3_IE 0x4000 // RW, ADC/TouchKey channel 2/3 digital input disable: 0=digital input enable, 1=digital input disable
  295. #define RB_PIN_ADC4_5_IE 0x8000 // RW, ADC/TouchKey channel 4/5 digital input disable: 0=digital input enable, 1=digital input disable
  296. /* System: parallel slave configuration register */
  297. #define R32_PARA_SLV_CFG (*((PUINT32V)0x4000101C)) // RW, parallel slave configuration
  298. #define R8_SLV_CONFIG (*((PUINT8V)0x4000101C)) // RW, parallel slave configuration
  299. #define RB_SLV_ENABLE 0x01 // RW, parallel slave enable
  300. #define RB_SLV_IE_CMD 0x02 // RW, enable interrupt for slave writing command event
  301. #define RB_SLV_IE_WR 0x04 // RW, enable interrupt for slave writing event
  302. #define RB_SLV_IE_RD 0x08 // RW, enable interrupt for slave reading event
  303. #define RB_IF_SLV_CMD 0x20 // RO, parallel slave command synchronous flag
  304. #define RB_IF_SLV_WR 0x40 // RW1, interrupt flag of parallel slave writing event
  305. #define RB_IF_SLV_RD 0x80 // RW1, interrupt flag of parallel slave reading event
  306. #define R8_SLV_RD_DATA (*((PUINT8V)0x400010C8)) // RW, data for parallel slave read
  307. #define R8_SLV_RD_STAT (*((PUINT8V)0x40001096)) // RW, status for parallel slave read
  308. #define R8_SLV_WR_DATA (*((PUINT8V)0x40001097)) // RW, data or command from parallel slave write
  309. /* System: power management register */
  310. #define R32_POWER_MANAG (*((PUINT32V)0x40001020)) // RWA, power management register, SAM
  311. #define R16_POWER_PLAN (*((PUINT16V)0x40001020)) // RWA, power plan before sleep instruction, SAM
  312. #define RB_PWR_RAM2K 0x02 // RWA, power for retention 2KB SRAM
  313. #define RB_PWR_CORE 0x04 // RWA, power retention for core and base peripherals
  314. #define RB_PWR_EXTEND 0x08 // RWA, power retention for USB and BLE
  315. #define RB_PWR_RAM14K 0x10 // RWA, power for main SRAM
  316. #define RB_PWR_SYS_EN 0x80 // RWA, power for system
  317. #define RB_PWR_LDO_EN 0x0100 // RWA, LDO enable
  318. #define RB_PWR_DCDC_EN 0x0200 // RWA, DC/DC converter enable: 0=DC/DC disable and bypass, 1=DC/DC enable
  319. #define RB_PWR_DCDC_PRE 0x0400 // RWA, DC/DC converter pre-enable
  320. #define RB_PWR_PLAN_EN 0x8000 // RWA/WZ, power plan enable, auto clear after sleep executed
  321. #define RB_PWR_MUST_0010 0x1000 // RWA, must write 0010
  322. #define R8_AUX_POWER_ADJ (*((PUINT8V)0x40001022)) // RWA, aux power adjust control, SAM
  323. #define RB_ULPLDO_ADJ 0x0007 // RWA, Ultra-Low-Power LDO voltage adjust
  324. /* System: battery detector register */
  325. #define R32_BATTERY_CTRL (*((PUINT32V)0x40001024)) // RWA, battery voltage detector, SAM
  326. #define R8_BAT_DET_CTRL (*((PUINT8V)0x40001024)) // RWA, battery voltage detector control, SAM
  327. #define RB_BAT_DET_EN 0x01 // RWA, battery voltage detector enable
  328. #define RB_BAT_LOWER_IE 0x04 // RWA, interrupt enable for battery lower voltage
  329. #define RB_BAT_LOW_IE 0x08 // RWA, interrupt enable for battery low voltage
  330. // request NMI interrupt if both RB_BAT_LOWER_IE and RB_BAT_LOW_IE enabled
  331. #define R8_BAT_DET_CFG (*((PUINT8V)0x40001025)) // RWA, battery voltage detector configuration, SAM
  332. #define RB_BAT_LOW_VTH 0x03 // RWA, select threshold voltage of battery voltage low
  333. #define R8_BAT_STATUS (*((PUINT8V)0x40001026)) // RO, battery status
  334. #define RB_BAT_STAT_LOWER 0x01 // RO, battery lower voltage status, high action
  335. #define RB_BAT_STAT_LOW 0x02 // RO, battery low voltage status, high action
  336. /* System: 32KHz oscillator control register */
  337. #define R32_OSC32K_CTRL (*((PUINT32V)0x4000102C)) // RWA, 32KHz oscillator control, SAM
  338. #define R16_INT32K_TUNE (*((PUINT16V)0x4000102C)) // RWA, internal 32KHz oscillator tune control, SAM
  339. #define RB_INT32K_TUNE 0x03FF // RWA, internal 32KHz oscillator frequency tune
  340. #define R8_XT32K_TUNE (*((PUINT8V)0x4000102E)) // RWA, external 32KHz oscillator tune control, SAM
  341. #define RB_XT32K_I_TUNE 0x03 // RWA, external 32KHz oscillator current tune: 00=75% current, 01=standard current, 10=150% current, 11=200% current
  342. #define RB_XT32K_C_LOAD 0xF0 // RWA, external 32KHz oscillator load capacitor tune: Cap = RB_XT32K_C_LOAD + 12pF
  343. #define R8_CK32K_CONFIG (*((PUINT8V)0x4000102F)) // RWA, 32KHz oscillator configure
  344. #define RB_CLK_XT32K_PON 0x01 // RWA, external 32KHz oscillator power on
  345. #define RB_CLK_INT32K_PON 0x02 // RWA, internal 32KHz oscillator power on
  346. #define RB_CLK_OSC32K_XT 0x04 // RWA, 32KHz oscillator source selection: 0=RC, 1=XT
  347. #define RB_32K_CLK_PIN 0x80 // RO, 32KHz oscillator clock pin status
  348. /* System: real-time clock register */
  349. #define R32_RTC_CTRL (*((PUINT32V)0x40001030)) // RWA, RTC control, SAM
  350. #define R8_RTC_FLAG_CTRL (*((PUINT8V)0x40001030)) // RW, RTC flag and clear control
  351. #define RB_RTC_TMR_CLR 0x10 // RW, set 1 to clear RTC timer action flag, auto clear
  352. #define RB_RTC_TRIG_CLR 0x20 // RW, set 1 to clear RTC trigger action flag, auto clear
  353. #define RB_RTC_TMR_FLAG 0x40 // RO, RTC timer action flag
  354. #define RB_RTC_TRIG_FLAG 0x80 // RO, RTC trigger action flag
  355. #define R8_RTC_MODE_CTRL (*((PUINT8V)0x40001031)) // RWA, RTC mode control, SAM
  356. #define RB_RTC_TMR_MODE 0x07 // RWA, RTC timer mode: 000=0.125S, 001=0.25S, 010=0.5S, 011=1S, 100=2S, 101=4S, 110=8S, 111=16S
  357. #define RB_RTC_IGNORE_B0 0x08 // RWA, force ignore bit0 for trigger mode: 0=compare bit0, 1=ignore bit0
  358. #define RB_RTC_TMR_EN 0x10 // RWA, RTC timer mode enable
  359. #define RB_RTC_TRIG_EN 0x20 // RWA, RTC trigger mode enable
  360. #define RB_RTC_LOAD_LO 0x40 // RWA, set 1 to load RTC count low word R32_RTC_CNT_32K, auto clear after loaded
  361. #define RB_RTC_LOAD_HI 0x80 // RWA, set 1 to load RTC count high word R32_RTC_CNT_DAY, auto clear after loaded
  362. #define R32_RTC_TRIG (*((PUINT32V)0x40001034)) // RWA, RTC trigger value, SAM
  363. #define R32_RTC_CNT_32K (*((PUINT32V)0x40001038)) // RO, RTC count based 32KHz
  364. #define R16_RTC_CNT_32K (*((PUINT16V)0x40001038)) // RO, RTC count based 32KHz
  365. #define R16_RTC_CNT_2S (*((PUINT16V)0x4000103A)) // RO, RTC count based 2 second
  366. #define R32_RTC_CNT_DAY (*((PUINT32V)0x4000103C)) // RO, RTC count based one day, only low 14 bit
  367. /*System: Miscellaneous Control register */
  368. #define R32_MISC_CTRL (*((PUINT32V)0x40001048)) // RWA, miscellaneous control register
  369. #define R8_CFG_FLASH (*((PUINT8V)0x4000104A)) // RWA, Flash ROM configure register
  370. #define RB_CFG_FLASH_X 0x0F // RWA, Flash ROM configure data, keep the value unchanged if write
  371. #define RB_FLASH_BUSY_EN 0x80 // RWA, enable ROM busy if burst reading: 1-enable(suggest), 0-disable
  372. #define R8_PLL_CONFIG (*((PUINT8V)0x4000104B)) // RWA, PLL configuration control, SAM
  373. #define RB_PLL_CFG_DAT 0x03 // RWA, PLL configure data
  374. #define RB_PLL_LOCKED 0x80 // RO, indicate PLL locked
  375. /* System: 32MHz oscillator control register */
  376. #define R32_OSC32M_CTRL (*((PUINT32V)0x4000104C)) // RWA, 32MHz oscillator control, SAM
  377. #define R8_INT32M_CALIB (*((PUINT8V)0x4000104C)) // RWA, internal 32MHz oscillator tune control, SAM
  378. #define R8_XT32M_TUNE (*((PUINT8V)0x4000104E)) // RWA, external 32MHz oscillator tune control, SAM
  379. #define RB_XT32M_I_BIAS 0x03 // RWA, external 32MHz oscillator bias current tune: 00=75% current, 01=standard current, 10=125% current, 11=150% current
  380. #define RB_XT32M_C_LOAD 0x70 // RWA, external 32MHz oscillator load capacitor tune: Cap = RB_XT32M_C_LOAD * 2 + 10pF
  381. /* System: oscillator frequency calibration register */
  382. #define R32_OSC_CALIB (*((PUINT32V)0x40001050)) // RWA, oscillator frequency calibration, SAM
  383. #define R16_OSC_CAL_CNT (*((PUINT16V)0x40001050)) // RO, system clock count value for 32KHz 5 cycles
  384. #define RB_OSC_CAL_CNT 0x0FFF // RO, system clock count value for 32KHz 5 cycles
  385. #define R8_OSC_CAL_CTRL (*((PUINT8V)0x40001052)) // RWA, oscillator frequency calibration control, SAM
  386. #define RB_OSC_CNT_EN 0x01 // RWA, calibration counter enable
  387. #define RB_OSC_CNT_HALT 0x02 // RO, calibration counter halt status: 0=counting, 1=halt for reading count value
  388. /* System: ADC and Touch-key register */
  389. #define R32_ADC_CTRL (*((PUINT32V)0x40001058)) // RW, ADC control
  390. #define R8_ADC_CHANNEL (*((PUINT8V)0x40001058)) // RW, ADC input channel selection
  391. #define RB_ADC_CH_INX 0x0F // RW, ADC input channel index
  392. #define R8_ADC_CFG (*((PUINT8V)0x40001059)) // RW, ADC configure
  393. #define RB_ADC_POWER_ON 0x01 // RW, ADC power control: 0=power down, 1=power on
  394. #define RB_ADC_BUF_EN 0x02 // RW, ADC input buffer enable
  395. #define RB_ADC_DIFF_EN 0x04 // RW, ADC input channel mode: 0=single-end, 1=differnetial
  396. #define RB_ADC_OFS_TEST 0x08 // RW, enable ADC offset test mode: 0=normal mode, 1=short port4 to test offset
  397. #define RB_ADC_PGA_GAIN 0x30 // RW, set ADC input PGA gain: 00=-12dB, 01=-6dB, 10=0dB, 11=6dB
  398. #define RB_ADC_CLK_DIV 0xC0 // RW, select ADC clock frequency: 00=3.2MHz, 01=2.67MHz, 10=5.33MHz, 11=4MHz
  399. #define R8_ADC_CONVERT (*((PUINT8V)0x4000105A)) // RW, ADC convert control
  400. #define RB_ADC_START 0x01 // RW, ADC convert start control: 0=stop ADC convert, 1=start an ADC convert, auto clear
  401. #define RB_ADC_EOC_X 0x80 // RO, end of ADC conversion flag
  402. #define R8_TEM_SENSOR (*((PUINT8V)0x4000105B)) // RW, temperature sensor control
  403. #define RB_TEM_SEN_CALIB 0x07 // RW, temperature sensor calibration
  404. #define RB_TEM_SEN_PWR_ON 0x80 // RW, temperature sensor power control: 0=power down, 1=power on
  405. #define R32_ADC_DATA (*((PUINT32V)0x4000105C)) // RO, ADC data and status
  406. #define R16_ADC_DATA (*((PUINT16V)0x4000105C)) // RO, ADC data
  407. #define RB_ADC_DATA 0x0FFF // RO, ADC conversion data
  408. #define R8_ADC_INT_FLAG (*((PUINT8V)0x4000105E)) // RO, ADC interrupt flag register
  409. #define RB_ADC_IF_EOC 0x80 // RO, ADC conversion interrupt flag: 0=free or converting, 1=end of conversion, interrupt action, write R8_ADC_CONVERT to clear flag
  410. #define R8_TKEY_CTRL (*((PUINT8V)0x4000105A)) // RW, Touchkey capacity charge and discharge status
  411. #define RB_TKEY_PWR_ON 0x08 // RW, Touchkey power on: 0=power down, 1=power on
  412. #define RB_TKEY_ACTION 0x10 // RO, Touchkey action status: 0=free, 1=discharge or charge or ADC
  413. #define RB_TKEY_CHG_ACT 0x20 // RO, Touchkey capacity charge status: 0=free, 1=charge
  414. #define R8_TKEY_CNT (*((PUINT8V)0x4000105F)) // WO, Touch-key charge and discharge count
  415. /* System: Flash ROM control register */
  416. #define R32_FLASH_DATA (*((PUINT32V)0x40001800)) // RW, Flash ROM data
  417. #define R32_FLASH_ADDR (*((PUINT32V)0x40001804)) // RW, Flash ROM address
  418. #define R32_FLASH_CTRL (*((PUINT32V)0x40001808)) // RW, Flash ROM control and status
  419. #define R8_FLASH_COMMAND (*((PUINT8V)0x40001808)) // WO, Flash ROM operation command
  420. #define ROM_CMD_PROG 0x9A // WO: Flash ROM word program operation command, for changing some ROM bit of a word from 1 to 0
  421. #define ROM_CMD_ERASE 0xA6 // WO: Flash ROM sector erase operation command, for changing all ROM bit of 512Bytes from 0 to 1
  422. #define R8_FLASH_PROTECT (*((PUINT8V)0x40001809)) // RW, Flash ROM protect control
  423. #define RB_ROM_DATA_WE 0x04 // RW, enable Flash ROM data area being erase/write: 0=writing protect, 1=enable program and erase
  424. #define RB_ROM_CODE_WE 0x08 // RW, enable Flash ROM code area being erase/write: 0=writing protect, 1=enable program and erase
  425. #define RB_ROM_WE_MUST_10 0x80 // RW, must write 10
  426. #define R16_FLASH_STATUS (*((PUINT16V)0x4000180A)) // RO, Flash ROM operation status
  427. #define R8_FLASH_STATUS (*((PUINT8V)0x4000180A)) // RO, Flash ROM operation status
  428. #define RB_ROM_CMD_TOUT 0x01 // RO, Flash ROM operation result: 0=success, 1=operation time out
  429. #define RB_ROM_CMD_ERR 0x02 // RO, Flash ROM operation command error flag: 0=command accepted, 1=unknown command
  430. #define RB_ROM_ADDR_OK 0x40 // RO, Flash ROM erase/write operation address valid flag, can be reviewed before or after operation: 0=invalid parameter, 1=address valid
  431. #define RB_ROM_READ_FREE 0x100 // RO, indicate protected status of Flash ROM code and data: 0=reading protect, 1=enable read by external programmer
  432. /* System: GPIO interrupt control register */
  433. #define R32_GPIO_INT_EN (*((PUINT32V)0x40001090)) // RW, GPIO interrupt enable
  434. #define R16_PA_INT_EN (*((PUINT16V)0x40001090)) // RW, GPIO PA interrupt enable
  435. #define R16_PB_INT_EN (*((PUINT16V)0x40001092)) // RW, GPIO PB interrupt enable
  436. #define R32_GPIO_INT_MODE (*((PUINT32V)0x40001094)) // RW, GPIO interrupt mode: 0=level action, 1=edge action
  437. #define R16_PA_INT_MODE (*((PUINT16V)0x40001094)) // RW, GPIO PA interrupt mode: 0=level action, 1=edge action
  438. #define R16_PB_INT_MODE (*((PUINT16V)0x40001096)) // RW, GPIO PB interrupt mode: 0=level action, 1=edge action
  439. #define R32_GPIO_INT_IF (*((PUINT32V)0x4000109C)) // RW1, GPIO interrupt flag
  440. #define R16_PA_INT_IF (*((PUINT16V)0x4000109C)) // RW1, GPIO PA interrupt flag
  441. #define R16_PB_INT_IF (*((PUINT16V)0x4000109E)) // RW1, GPIO PB interrupt flag
  442. /* GPIO PA register */
  443. #define R32_PA_DIR (*((PUINT32V)0x400010A0)) // RW, GPIO PA I/O direction: 0=in, 1=out
  444. #define R8_PA_DIR_0 (*((PUINT8V)0x400010A0)) // RW, GPIO PA I/O direction byte 0
  445. #define R8_PA_DIR_1 (*((PUINT8V)0x400010A1)) // RW, GPIO PA I/O direction byte 1
  446. #define R32_PA_PIN (*((PUINT32V)0x400010A4)) // RO, GPIO PA input
  447. #define R8_PA_PIN_0 (*((PUINT8V)0x400010A4)) // RO, GPIO PA input byte 0
  448. #define R8_PA_PIN_1 (*((PUINT8V)0x400010A5)) // RO, GPIO PA input byte 1
  449. #define R32_PA_OUT (*((PUINT32V)0x400010A8)) // RW, GPIO PA output
  450. #define R8_PA_OUT_0 (*((PUINT8V)0x400010A8)) // RW, GPIO PA output byte 0
  451. #define R8_PA_OUT_1 (*((PUINT8V)0x400010A9)) // RW, GPIO PA output byte 1
  452. #define R32_PA_CLR (*((PUINT32V)0x400010AC)) // WZ, GPIO PA clear output: 0=keep, 1=clear
  453. #define R8_PA_CLR_0 (*((PUINT8V)0x400010AC)) // WZ, GPIO PA clear output byte 0
  454. #define R8_PA_CLR_1 (*((PUINT8V)0x400010AD)) // WZ, GPIO PA clear output byte 1
  455. #define R32_PA_PU (*((PUINT32V)0x400010B0)) // RW, GPIO PA pullup resistance enable
  456. #define R8_PA_PU_0 (*((PUINT8V)0x400010B0)) // RW, GPIO PA pullup resistance enable byte 0
  457. #define R8_PA_PU_1 (*((PUINT8V)0x400010B1)) // RW, GPIO PA pullup resistance enable byte 1
  458. #define R32_PA_PD_DRV (*((PUINT32V)0x400010B4)) // RW, PA pulldown for input or PA driving capability for output
  459. #define R8_PA_PD_DRV_0 (*((PUINT8V)0x400010B4)) // RW, PA pulldown for input or PA driving capability for output byte 0
  460. #define R8_PA_PD_DRV_1 (*((PUINT8V)0x400010B5)) // RW, PA pulldown for input or PA driving capability for output byte 1
  461. /* GPIO PB register */
  462. #define R32_PB_DIR (*((PUINT32V)0x400010C0)) // RW, GPIO PB I/O direction: 0=in, 1=out
  463. #define R8_PB_DIR_0 (*((PUINT8V)0x400010C0)) // RW, GPIO PB I/O direction byte 0
  464. #define R8_PB_DIR_1 (*((PUINT8V)0x400010C1)) // RW, GPIO PB I/O direction byte 1
  465. #define R8_PB_DIR_2 (*((PUINT8V)0x400010C2)) // RW, GPIO PB I/O direction byte 2
  466. #define R32_PB_PIN (*((PUINT32V)0x400010C4)) // RO, GPIO PB input
  467. #define R8_PB_PIN_0 (*((PUINT8V)0x400010C4)) // RO, GPIO PB input byte 0
  468. #define R8_PB_PIN_1 (*((PUINT8V)0x400010C5)) // RO, GPIO PB input byte 1
  469. #define R8_PB_PIN_2 (*((PUINT8V)0x400010C6)) // RO, GPIO PB input byte 2
  470. #define R32_PB_OUT (*((PUINT32V)0x400010C8)) // RW, GPIO PB output
  471. #define R8_PB_OUT_0 (*((PUINT8V)0x400010C8)) // RW, GPIO PB output byte 0
  472. #define R8_PB_OUT_1 (*((PUINT8V)0x400010C9)) // RW, GPIO PB output byte 1
  473. #define R8_PB_OUT_2 (*((PUINT8V)0x400010CA)) // RW, GPIO PB output byte 2
  474. #define R32_PB_CLR (*((PUINT32V)0x400010CC)) // WZ, GPIO PB clear output: 0=keep, 1=clear
  475. #define R8_PB_CLR_0 (*((PUINT8V)0x400010CC)) // WZ, GPIO PB clear output byte 0
  476. #define R8_PB_CLR_1 (*((PUINT8V)0x400010CD)) // WZ, GPIO PB clear output byte 1
  477. #define R8_PB_CLR_2 (*((PUINT8V)0x400010CE)) // WZ, GPIO PB clear output byte 2
  478. #define R32_PB_PU (*((PUINT32V)0x400010D0)) // RW, GPIO PB pullup resistance enable
  479. #define R8_PB_PU_0 (*((PUINT8V)0x400010D0)) // RW, GPIO PB pullup resistance enable byte 0
  480. #define R8_PB_PU_1 (*((PUINT8V)0x400010D1)) // RW, GPIO PB pullup resistance enable byte 1
  481. #define R8_PB_PU_2 (*((PUINT8V)0x400010D2)) // RW, GPIO PB pullup resistance enable byte 2
  482. #define R32_PB_PD_DRV (*((PUINT32V)0x400010D4)) // RW, PB pulldown for input or PB driving capability for output
  483. #define R8_PB_PD_DRV_0 (*((PUINT8V)0x400010D4)) // RW, PB pulldown for input or PB driving capability for output byte 0
  484. #define R8_PB_PD_DRV_1 (*((PUINT8V)0x400010D5)) // RW, PB pulldown for input or PB driving capability for output byte 1
  485. #define R8_PB_PD_DRV_2 (*((PUINT8V)0x400010D6)) // RW, PB pulldown for input or PB driving capability for output byte 2
  486. /* GPIO register address offset and bit define */
  487. #define BA_PA ((PUINT8V)0x400010A0) // point GPIO PA base address
  488. #define BA_PB ((PUINT8V)0x400010C0) // point GPIO PB base address
  489. #define GPIO_DIR 0x00
  490. #define GPIO_DIR_0 0x00
  491. #define GPIO_DIR_1 0x01
  492. #define GPIO_DIR_2 0x02
  493. #define GPIO_PIN 0x04
  494. #define GPIO_PIN_0 0x04
  495. #define GPIO_PIN_1 0x05
  496. #define GPIO_PIN_2 0x06
  497. #define GPIO_OUT 0x08
  498. #define GPIO_OUT_0 0x08
  499. #define GPIO_OUT_1 0x09
  500. #define GPIO_OUT_2 0x0A
  501. #define GPIO_CLR 0x0C
  502. #define GPIO_CLR_0 0x0C
  503. #define GPIO_CLR_1 0x0D
  504. #define GPIO_CLR_2 0x0E
  505. #define GPIO_PU 0x10
  506. #define GPIO_PU_0 0x10
  507. #define GPIO_PU_1 0x11
  508. #define GPIO_PU_2 0x12
  509. #define GPIO_PD_DRV 0x14
  510. #define GPIO_PD_DRV_0 0x14
  511. #define GPIO_PD_DRV_1 0x15
  512. #define GPIO_PD_DRV_2 0x16
  513. /* GPIO alias name */
  514. #define bSCK1 (1<<0) // PA0
  515. #define bPADDR (1<<0) // PA0
  516. #define bLED0 (1<<0) // PA0
  517. #define bCOM0 (1<<0) // PA0
  518. #define bSDO (1<<1) // PA1
  519. #define bMOSI1 bSDO
  520. #define bPCS (1<<1) // PA1
  521. #define bLED1 (1<<1) // PA1
  522. #define bCOM1 (1<<1) // PA1
  523. #define bTMR3 (1<<2) // PA2
  524. #define bCAP3 bTMR3
  525. #define bPWM3 bTMR3
  526. #define bSDI (1<<2) // PA2
  527. #define bMISO1 bSDI
  528. #define bLED2 (1<<2) // PA2
  529. #define bCOM2 (1<<2) // PA2
  530. #define bTMR0 (1<<3) // PA3
  531. #define bCAP0 bTMR0
  532. #define bPWM0 bTMR0
  533. #define bPINT (1<<3) // PA3
  534. #define bLED3 (1<<3) // PA3
  535. #define bCOM3 (1<<3) // PA3
  536. #define bUBUS1 (1<<4) // PA4
  537. #define bAIN0 (1<<4) // PA4
  538. #define bRXD3 (1<<4) // PA4
  539. #define bLEDC (1<<4) // PA4
  540. #define bUCC1 (1<<5) // PA5
  541. #define bAIN1 (1<<5) // PA5
  542. #define bTXD3 (1<<5) // PA5
  543. #define bUCC2 (1<<6) // PA6
  544. #define bAIN2 (1<<6) // PA6
  545. #define bRXD2 (1<<6) // PA6
  546. #define bPWM4 (1<<6) // PA6
  547. #define bTIN3 (1<<7) // PA7
  548. #define bTXD2 (1<<7) // PA7
  549. #define bPWM5 (1<<7) // PA7
  550. #define bTIN4 (1<<8) // PA8
  551. #define bRXD1 (1<<8) // PA8
  552. #define bTIN5 (1<<9) // PA9
  553. #define bTXD1 (1<<9) // PA9
  554. #define bX32KI (1<<10) // PA10
  555. #define bTMR1 (1<<10) // PA10
  556. #define bCAP1 bTMR1
  557. #define bPWM1 bTMR1
  558. #define bX32KO (1<<11) // PA11
  559. #define bTMR2 (1<<11) // PA11
  560. #define bCAP2 bTMR2
  561. #define bPWM2 bTMR2
  562. #define bTIN2 (1<<12) // PA12
  563. #define bSCS (1<<12) // PA12
  564. #define bTIN1 (1<<13) // PA13
  565. #define bSCK0 (1<<13) // PA13
  566. #define bUBUS2 (1<<14) // PA14
  567. #define bAIN3 (1<<14) // PA14
  568. #define bMOSI (1<<14) // PA14
  569. #define bTXD0_ (1<<14) // PA14
  570. #define bTIN0 (1<<15) // PA15
  571. #define bMISO (1<<15) // PA15
  572. #define bRXD0_ (1<<15) // PA15
  573. #define bCTS (1<<0) // PB0
  574. #define bPWM6 (1<<0) // PB0
  575. #define bSEG0 (1<<0) // PB0
  576. #define bDSR (1<<1) // PB1
  577. #define bPWM7 (1<<1) // PB1
  578. #define bSEG1 (1<<1) // PB1
  579. #define bRI (1<<2) // PB2
  580. #define bPWM8 (1<<2) // PB2
  581. #define bSEG2 (1<<2) // PB2
  582. #define bDCD (1<<3) // PB3
  583. #define bPWM9 (1<<3) // PB3
  584. #define bSEG3 (1<<3) // PB3
  585. #define bRXD0 (1<<4) // PB4
  586. #define bSEG4 (1<<4) // PB4
  587. #define bDTR (1<<5) // PB5
  588. #define bSEG5 (1<<5) // PB5
  589. #define bRTS (1<<6) // PB6
  590. #define bSEG6 (1<<6) // PB6
  591. #define bTXD0 (1<<7) // PB7
  592. #define bSEG7 (1<<7) // PB7
  593. #define bPBUS (0xFF<<0) // PB0~PB7
  594. #define bTIN8 (1<<8) // PB8
  595. #define bRXD1_ (1<<8) // PB8
  596. #define bPRD (1<<8) // PB8
  597. #define bSEG8 (1<<8) // PB8
  598. #define bTIN9 (1<<9) // PB9
  599. #define bTXD1_ (1<<9) // PB9
  600. #define bPWR (1<<9) // PB9
  601. #define bSEG9 (1<<9) // PB9
  602. #define bUDM (1<<10) // PB10
  603. #define bTMR1_ (1<<10) // PB10
  604. #define bCAP1_ bTMR1_
  605. #define bPWM1_ bTMR1_
  606. #define bSEG10 (1<<10) // PB10
  607. #define bUDP (1<<11) // PB11
  608. #define bTMR2_ (1<<11) // PB11
  609. #define bCAP2_ bTMR2_
  610. #define bPWM2_ bTMR2_
  611. #define bSEG11 (1<<11) // PB11
  612. #define bETM (1<<12) // PB12
  613. #define bSCS_ (1<<12) // PB12
  614. #define bSEG12 (1<<12) // PB12
  615. #define bETP (1<<13) // PB13
  616. #define bSCK0_ (1<<13) // PB13
  617. #define bSEG13 (1<<13) // PB13
  618. #define bERM (1<<14) // PB14
  619. #define bMOSI_ (1<<14) // PB14
  620. #define bPWM10 (1<<14) // PB14
  621. #define bSEG14 (1<<14) // PB14
  622. #define bERP (1<<15) // PB15
  623. #define bMISO_ (1<<15) // PB15
  624. #define bSEG15 (1<<15) // PB15
  625. #define bTIN6 (1<<16) // PB16
  626. #define bTIO (1<<16) // PB16
  627. #define bSEG16 (1<<16) // PB16
  628. #define bTIN7 (1<<17) // PB17
  629. #define bTCK (1<<17) // PB17
  630. #define bSEG17 (1<<17) // PB17
  631. #define bTMR3_ (1<<18) // PB18
  632. #define bCAP3_ bTMR3_
  633. #define bPWM3_ bTMR3_
  634. #define bSEG18 (1<<18) // PB18
  635. #define bTMR0_ (1<<19) // PB19
  636. #define bCAP0_ bTMR0_
  637. #define bPWM0_ bTMR0_
  638. #define bSEG19 (1<<19) // PB19
  639. #define bRXD3_ (1<<20) // PB20
  640. #define bSEG20 (1<<20) // PB20
  641. #define bTXD3_ (1<<21) // PB21
  642. #define bSEG21 (1<<21) // PB21
  643. #define bRXD2_ (1<<22) // PB22
  644. #define bSEG22 (1<<22) // PB22
  645. #define bRST (1<<23) // PB23
  646. #define bTXD2_ (1<<23) // PB23
  647. #define bPWM11 (1<<23) // PB23
  648. #define bSEG23 (1<<23) // PB23
  649. /* Timer0 register */
  650. #define R32_TMR0_CONTROL (*((PUINT32V)0x40002000)) // RW, TMR0 control
  651. #define R8_TMR0_CTRL_MOD (*((PUINT8V)0x40002000)) // RW, TMR0 mode control
  652. #define R8_TMR0_INTER_EN (*((PUINT8V)0x40002002)) // RW, TMR0 interrupt enable
  653. #define R32_TMR0_STATUS (*((PUINT32V)0x40002004)) // RW, TMR0 status
  654. #define R8_TMR0_INT_FLAG (*((PUINT8V)0x40002006)) // RW1, TMR0 interrupt flag
  655. #define R8_TMR0_FIFO_COUNT (*((PUINT8V)0x40002007)) // RO, TMR0 FIFO count status
  656. #define R32_TMR0_COUNT (*((PUINT32V)0x40002008)) // RO, TMR0 current count
  657. #define R16_TMR0_COUNT (*((PUINT16V)0x40002008)) // RO, TMR0 current count
  658. #define R8_TMR0_COUNT (*((PUINT8V)0x40002008)) // RO, TMR0 current count
  659. #define R32_TMR0_CNT_END (*((PUINT32V)0x4000200C)) // RW, TMR0 end count value, only low 26 bit
  660. #define R32_TMR0_FIFO (*((PUINT32V)0x40002010)) // RO/WO, TMR0 FIFO register, only low 26 bit
  661. #define R16_TMR0_FIFO (*((PUINT16V)0x40002010)) // RO/WO, TMR0 FIFO register
  662. #define R8_TMR0_FIFO (*((PUINT8V)0x40002010)) // RO/WO, TMR0 FIFO register
  663. /* Timer1 register */
  664. #define R32_TMR1_CONTROL (*((PUINT32V)0x40002400)) // RW, TMR1 control
  665. #define R8_TMR1_CTRL_MOD (*((PUINT8V)0x40002400)) // RW, TMR1 mode control
  666. #define R8_TMR1_CTRL_DMA (*((PUINT8V)0x40002401)) // RW, TMR1 DMA control
  667. #define R8_TMR1_INTER_EN (*((PUINT8V)0x40002402)) // RW, TMR1 interrupt enable
  668. #define R32_TMR1_STATUS (*((PUINT32V)0x40002404)) // RW, TMR1 status
  669. #define R8_TMR1_INT_FLAG (*((PUINT8V)0x40002406)) // RW1, TMR1 interrupt flag
  670. #define R8_TMR1_FIFO_COUNT (*((PUINT8V)0x40002407)) // RO, TMR1 FIFO count status
  671. #define R32_TMR1_COUNT (*((PUINT32V)0x40002408)) // RO, TMR1 current count
  672. #define R16_TMR1_COUNT (*((PUINT16V)0x40002408)) // RO, TMR1 current count
  673. #define R8_TMR1_COUNT (*((PUINT8V)0x40002408)) // RO, TMR1 current count
  674. #define R32_TMR1_CNT_END (*((PUINT32V)0x4000240C)) // RW, TMR1 end count value, only low 26 bit
  675. #define R32_TMR1_FIFO (*((PUINT32V)0x40002410)) // RO/WO, TMR1 FIFO register, only low 26 bit
  676. #define R16_TMR1_FIFO (*((PUINT16V)0x40002410)) // RO/WO, TMR1 FIFO register
  677. #define R8_TMR1_FIFO (*((PUINT8V)0x40002410)) // RO/WO, TMR1 FIFO register
  678. #define R32_TMR1_DMA_NOW (*((PUINT32V)0x40002414)) // RW, TMR1 DMA current address
  679. #define R16_TMR1_DMA_NOW (*((PUINT16V)0x40002414)) // RW, TMR1 DMA current address
  680. #define R32_TMR1_DMA_BEG (*((PUINT32V)0x40002418)) // RW, TMR1 DMA begin address
  681. #define R16_TMR1_DMA_BEG (*((PUINT16V)0x40002418)) // RW, TMR1 DMA begin address
  682. #define R32_TMR1_DMA_END (*((PUINT32V)0x4000241C)) // RW, TMR1 DMA end address
  683. #define R16_TMR1_DMA_END (*((PUINT16V)0x4000241C)) // RW, TMR1 DMA end address
  684. /* Timer2 register */
  685. #define R32_TMR2_CONTROL (*((PUINT32V)0x40002800)) // RW, TMR2 control
  686. #define R8_TMR2_CTRL_MOD (*((PUINT8V)0x40002800)) // RW, TMR2 mode control
  687. #define R8_TMR2_CTRL_DMA (*((PUINT8V)0x40002801)) // RW, TMR2 DMA control
  688. #define R8_TMR2_INTER_EN (*((PUINT8V)0x40002802)) // RW, TMR2 interrupt enable
  689. #define R32_TMR2_STATUS (*((PUINT32V)0x40002804)) // RW, TMR2 status
  690. #define R8_TMR2_INT_FLAG (*((PUINT8V)0x40002806)) // RW1, TMR2 interrupt flag
  691. #define R8_TMR2_FIFO_COUNT (*((PUINT8V)0x40002807)) // RO, TMR2 FIFO count status
  692. #define R32_TMR2_COUNT (*((PUINT32V)0x40002808)) // RO, TMR2 current count
  693. #define R16_TMR2_COUNT (*((PUINT16V)0x40002808)) // RO, TMR2 current count
  694. #define R8_TMR2_COUNT (*((PUINT8V)0x40002808)) // RO, TMR2 current count
  695. #define R32_TMR2_CNT_END (*((PUINT32V)0x4000280C)) // RW, TMR2 end count value, only low 26 bit
  696. #define R32_TMR2_FIFO (*((PUINT32V)0x40002810)) // RO/WO, TMR2 FIFO register, only low 26 bit
  697. #define R16_TMR2_FIFO (*((PUINT16V)0x40002810)) // RO/WO, TMR2 FIFO register
  698. #define R8_TMR2_FIFO (*((PUINT8V)0x40002810)) // RO/WO, TMR2 FIFO register
  699. #define R32_TMR2_DMA_NOW (*((PUINT32V)0x40002814)) // RW, TMR2 DMA current address
  700. #define R16_TMR2_DMA_NOW (*((PUINT16V)0x40002814)) // RW, TMR2 DMA current address
  701. #define R32_TMR2_DMA_BEG (*((PUINT32V)0x40002818)) // RW, TMR2 DMA begin address
  702. #define R16_TMR2_DMA_BEG (*((PUINT16V)0x40002818)) // RW, TMR2 DMA begin address
  703. #define R32_TMR2_DMA_END (*((PUINT32V)0x4000281C)) // RW, TMR2 DMA end address
  704. #define R16_TMR2_DMA_END (*((PUINT16V)0x4000281C)) // RW, TMR2 DMA end address
  705. /* Timer3 register */
  706. #define R32_TMR3_CONTROL (*((PUINT32V)0x40002C00)) // RW, TMR3 control
  707. #define R8_TMR3_CTRL_MOD (*((PUINT8V)0x40002C00)) // RW, TMR3 mode control
  708. #define R8_TMR3_INTER_EN (*((PUINT8V)0x40002C02)) // RW, TMR3 interrupt enable
  709. #define R32_TMR3_STATUS (*((PUINT32V)0x40002C04)) // RW, TMR3 status
  710. #define R8_TMR3_INT_FLAG (*((PUINT8V)0x40002C06)) // RW1, TMR3 interrupt flag
  711. #define R8_TMR3_FIFO_COUNT (*((PUINT8V)0x40002C07)) // RO, TMR3 FIFO count status
  712. #define R32_TMR3_COUNT (*((PUINT32V)0x40002C08)) // RO, TMR3 current count
  713. #define R16_TMR3_COUNT (*((PUINT16V)0x40002C08)) // RO, TMR3 current count
  714. #define R8_TMR3_COUNT (*((PUINT8V)0x40002C08)) // RO, TMR3 current count
  715. #define R32_TMR3_CNT_END (*((PUINT32V)0x40002C0C)) // RW, TMR3 end count value, only low 26 bit
  716. #define R32_TMR3_FIFO (*((PUINT32V)0x40002C10)) // RO/WO, TMR3 FIFO register, only low 26 bit
  717. #define R16_TMR3_FIFO (*((PUINT16V)0x40002C10)) // RO/WO, TMR3 FIFO register
  718. #define R8_TMR3_FIFO (*((PUINT8V)0x40002C10)) // RO/WO, TMR3 FIFO register
  719. /* Timer register address offset and bit define */
  720. #define TMR_FIFO_SIZE 8 // timer FIFO size (depth)
  721. #define BA_TMR0 ((PUINT8V)0x40002000) // point TMR0 base address
  722. #define BA_TMR1 ((PUINT8V)0x40002400) // point TMR1 base address
  723. #define BA_TMR2 ((PUINT8V)0x40002800) // point TMR2 base address
  724. #define BA_TMR3 ((PUINT8V)0x40002C00) // point TMR3 base address
  725. #define TMR_CTRL_MOD 0
  726. #define RB_TMR_MODE_IN 0x01 // RW, timer in mode: 0=timer/PWM, 1=capture/count
  727. #define RB_TMR_ALL_CLEAR 0x02 // RW, force clear timer FIFO and count
  728. #define RB_TMR_COUNT_EN 0x04 // RW, timer count enable
  729. #define RB_TMR_OUT_EN 0x08 // RW, timer output enable
  730. #define RB_TMR_OUT_POLAR 0x10 // RW, timer PWM output polarity: 0=default low and high action, 1=default high and low action
  731. #define RB_TMR_CAP_COUNT 0x10 // RW, count sub-mode if RB_TMR_MODE_IN=1: 0=capture, 1=count
  732. #define RB_TMR_PWM_REPEAT 0xC0 // RW, timer PWM repeat mode: 00=1, 01=4, 10=8, 11-16
  733. #define RB_TMR_CAP_EDGE 0xC0 // RW, timer capture edge mode: 00=disable, 01=edge change, 10=fall to fall, 11-rise to rise
  734. #define TMR_CTRL_DMA 1
  735. #define RB_TMR_DMA_ENABLE 0x01 // RW, timer1/2 DMA enable
  736. #define RB_TMR_DMA_LOOP 0x04 // RW, timer1/2 DMA address loop enable
  737. #define TMR_INTER_EN 2
  738. #define RB_TMR_IE_CYC_END 0x01 // RW, enable interrupt for timer capture count timeout or PWM cycle end
  739. #define RB_TMR_IE_DATA_ACT 0x02 // RW, enable interrupt for timer capture input action or PWM trigger
  740. #define RB_TMR_IE_FIFO_HF 0x04 // RW, enable interrupt for timer FIFO half (capture fifo >=4 or PWM fifo <=3)
  741. #define RB_TMR_IE_DMA_END 0x08 // RW, enable interrupt for timer1/2 DMA completion
  742. #define RB_TMR_IE_FIFO_OV 0x10 // RW, enable interrupt for timer FIFO overflow
  743. #define TMR_INT_FLAG 6
  744. #define RB_TMR_IF_CYC_END 0x01 // RW1, interrupt flag for timer capture count timeout or PWM cycle end
  745. #define RB_TMR_IF_DATA_ACT 0x02 // RW1, interrupt flag for timer capture input action or PWM trigger
  746. #define RB_TMR_IF_FIFO_HF 0x04 // RW1, interrupt flag for timer FIFO half (capture fifo >=4 or PWM fifo <=3)
  747. #define RB_TMR_IF_DMA_END 0x08 // RW1, interrupt flag for timer1/2 DMA completion
  748. #define RB_TMR_IF_FIFO_OV 0x10 // RW1, interrupt flag for timer FIFO overflow
  749. #define TMR_FIFO_COUNT 7
  750. #define TMR_COUNT 0x08
  751. #define TMR_CNT_END 0x0C
  752. #define TMR_FIFO 0x10
  753. #define TMR_DMA_NOW 0x14
  754. #define TMR_DMA_BEG 0x18
  755. #define TMR_DMA_END 0x1C
  756. /* UART0 register */
  757. #define R32_UART0_CTRL (*((PUINT32V)0x40003000)) // RW, UART0 control
  758. #define R8_UART0_MCR (*((PUINT8V)0x40003000)) // RW, UART0 modem control
  759. #define R8_UART0_IER (*((PUINT8V)0x40003001)) // RW, UART0 interrupt enable
  760. #define R8_UART0_FCR (*((PUINT8V)0x40003002)) // RW, UART0 FIFO control
  761. #define R8_UART0_LCR (*((PUINT8V)0x40003003)) // RW, UART0 line control
  762. #define R32_UART0_STAT (*((PUINT32V)0x40003004)) // RO, UART0 status
  763. #define R8_UART0_IIR (*((PUINT8V)0x40003004)) // RO, UART0 interrupt identification
  764. #define R8_UART0_LSR (*((PUINT8V)0x40003005)) // RO, UART0 line status
  765. #define R8_UART0_MSR (*((PUINT8V)0x40003006)) // RO, UART0 modem status
  766. #define R32_UART0_FIFO (*((PUINT32V)0x40003008)) // RW, UART0 data or FIFO port
  767. #define R8_UART0_RBR (*((PUINT8V)0x40003008)) // RO, UART0 receiver buffer, receiving byte
  768. #define R8_UART0_THR (*((PUINT8V)0x40003008)) // WO, UART0 transmitter holding, transmittal byte
  769. #define R8_UART0_RFC (*((PUINT8V)0x4000300A)) // RO, UART0 receiver FIFO count
  770. #define R8_UART0_TFC (*((PUINT8V)0x4000300B)) // RO, UART0 transmitter FIFO count
  771. #define R32_UART0_SETUP (*((PUINT32V)0x4000300C)) // RW, UART0 setup
  772. #define R16_UART0_DL (*((PUINT16V)0x4000300C)) // RW, UART0 divisor latch
  773. #define R8_UART0_DLL (*((PUINT8V)0x4000300C)) // RW, UART0 divisor latch LSB byte
  774. #define R8_UART0_DLM (*((PUINT8V)0x4000300D)) // RW, UART0 divisor latch MSB byte
  775. #define R8_UART0_DIV (*((PUINT8V)0x4000300E)) // RW, UART0 pre-divisor latch byte, only low 7 bit, from 1 to 0/128
  776. #define R8_UART0_ADR (*((PUINT8V)0x4000300F)) // RW, UART0 slave address: 0xFF=disable, other=enable
  777. /* UART1 register */
  778. #define R32_UART1_CTRL (*((PUINT32V)0x40003400)) // RW, UART1 control
  779. #define R8_UART1_MCR (*((PUINT8V)0x40003400)) // RW, UART1 modem control
  780. #define R8_UART1_IER (*((PUINT8V)0x40003401)) // RW, UART1 interrupt enable
  781. #define R8_UART1_FCR (*((PUINT8V)0x40003402)) // RW, UART1 FIFO control
  782. #define R8_UART1_LCR (*((PUINT8V)0x40003403)) // RW, UART1 line control
  783. #define R32_UART1_STAT (*((PUINT32V)0x40003404)) // RO, UART1 status
  784. #define R8_UART1_IIR (*((PUINT8V)0x40003404)) // RO, UART1 interrupt identification
  785. #define R8_UART1_LSR (*((PUINT8V)0x40003405)) // RO, UART1 line status
  786. #define R32_UART1_FIFO (*((PUINT32V)0x40003408)) // RW, UART1 data or FIFO port
  787. #define R8_UART1_RBR (*((PUINT8V)0x40003408)) // RO, UART1 receiver buffer, receiving byte
  788. #define R8_UART1_THR (*((PUINT8V)0x40003408)) // WO, UART1 transmitter holding, transmittal byte
  789. #define R8_UART1_RFC (*((PUINT8V)0x4000340A)) // RO, UART1 receiver FIFO count
  790. #define R8_UART1_TFC (*((PUINT8V)0x4000340B)) // RO, UART1 transmitter FIFO count
  791. #define R32_UART1_SETUP (*((PUINT32V)0x4000340C)) // RW, UART1 setup
  792. #define R16_UART1_DL (*((PUINT16V)0x4000340C)) // RW, UART1 divisor latch
  793. #define R8_UART1_DLL (*((PUINT8V)0x4000340C)) // RW, UART1 divisor latch LSB byte
  794. #define R8_UART1_DLM (*((PUINT8V)0x4000340D)) // RW, UART1 divisor latch MSB byte
  795. #define R8_UART1_DIV (*((PUINT8V)0x4000340E)) // RW, UART1 pre-divisor latch byte, only low 7 bit, from 1 to 0/128
  796. /* UART2 register */
  797. #define R32_UART2_CTRL (*((PUINT32V)0x40003800)) // RW, UART2 control
  798. #define R8_UART2_MCR (*((PUINT8V)0x40003800)) // RW, UART2 modem control
  799. #define R8_UART2_IER (*((PUINT8V)0x40003801)) // RW, UART2 interrupt enable
  800. #define R8_UART2_FCR (*((PUINT8V)0x40003802)) // RW, UART2 FIFO control
  801. #define R8_UART2_LCR (*((PUINT8V)0x40003803)) // RW, UART2 line control
  802. #define R32_UART2_STAT (*((PUINT32V)0x40003804)) // RO, UART2 status
  803. #define R8_UART2_IIR (*((PUINT8V)0x40003804)) // RO, UART2 interrupt identification
  804. #define R8_UART2_LSR (*((PUINT8V)0x40003805)) // RO, UART2 line status
  805. #define R32_UART2_FIFO (*((PUINT32V)0x40003808)) // RW, UART2 data or FIFO port
  806. #define R8_UART2_RBR (*((PUINT8V)0x40003808)) // RO, UART2 receiver buffer, receiving byte
  807. #define R8_UART2_THR (*((PUINT8V)0x40003808)) // WO, UART2 transmitter holding, transmittal byte
  808. #define R8_UART2_RFC (*((PUINT8V)0x4000380A)) // RO, UART2 receiver FIFO count
  809. #define R8_UART2_TFC (*((PUINT8V)0x4000380B)) // RO, UART2 transmitter FIFO count
  810. #define R32_UART2_SETUP (*((PUINT32V)0x4000380C)) // RW, UART2 setup
  811. #define R16_UART2_DL (*((PUINT16V)0x4000380C)) // RW, UART2 divisor latch
  812. #define R8_UART2_DLL (*((PUINT8V)0x4000380C)) // RW, UART2 divisor latch LSB byte
  813. #define R8_UART2_DLM (*((PUINT8V)0x4000380D)) // RW, UART2 divisor latch MSB byte
  814. #define R8_UART2_DIV (*((PUINT8V)0x4000380E)) // RW, UART2 pre-divisor latch byte, only low 7 bit, from 1 to 0/128
  815. /* UART3 register */
  816. #define R32_UART3_CTRL (*((PUINT32V)0x40003C00)) // RW, UART3 control
  817. #define R8_UART3_MCR (*((PUINT8V)0x40003C00)) // RW, UART3 modem control
  818. #define R8_UART3_IER (*((PUINT8V)0x40003C01)) // RW, UART3 interrupt enable
  819. #define R8_UART3_FCR (*((PUINT8V)0x40003C02)) // RW, UART3 FIFO control
  820. #define R8_UART3_LCR (*((PUINT8V)0x40003C03)) // RW, UART3 line control
  821. #define R32_UART3_STAT (*((PUINT32V)0x40003C04)) // RO, UART3 status
  822. #define R8_UART3_IIR (*((PUINT8V)0x40003C04)) // RO, UART3 interrupt identification
  823. #define R8_UART3_LSR (*((PUINT8V)0x40003C05)) // RO, UART3 line status
  824. #define R32_UART3_FIFO (*((PUINT32V)0x40003C08)) // RW, UART3 data or FIFO port
  825. #define R8_UART3_RBR (*((PUINT8V)0x40003C08)) // RO, UART3 receiver buffer, receiving byte
  826. #define R8_UART3_THR (*((PUINT8V)0x40003C08)) // WO, UART3 transmitter holding, transmittal byte
  827. #define R8_UART3_RFC (*((PUINT8V)0x40003C0A)) // RO, UART3 receiver FIFO count
  828. #define R8_UART3_TFC (*((PUINT8V)0x40003C0B)) // RO, UART3 transmitter FIFO count
  829. #define R32_UART3_SETUP (*((PUINT32V)0x40003C0C)) // RW, UART3 setup
  830. #define R16_UART3_DL (*((PUINT16V)0x40003C0C)) // RW, UART3 divisor latch
  831. #define R8_UART3_DLL (*((PUINT8V)0x40003C0C)) // RW, UART3 divisor latch LSB byte
  832. #define R8_UART3_DLM (*((PUINT8V)0x40003C0D)) // RW, UART3 divisor latch MSB byte
  833. #define R8_UART3_DIV (*((PUINT8V)0x40003C0E)) // RW, UART3 pre-divisor latch byte, only low 7 bit, from 1 to 0/128
  834. /* UART register address offset and bit define */
  835. #define UART_FIFO_SIZE 8 // UART FIFO size (depth)
  836. #define UART_RECV_RDY_SZ 7 // the max FIFO trigger level for UART receiver data available
  837. #define BA_UART0 ((PUINT8V)0x40003000) // point UART0 base address
  838. #define BA_UART1 ((PUINT8V)0x40003400) // point UART1 base address
  839. #define BA_UART2 ((PUINT8V)0x40003800) // point UART2 base address
  840. #define BA_UART3 ((PUINT8V)0x40003C00) // point UART3 base address
  841. #define UART_MCR 0
  842. #define RB_MCR_DTR 0x01 // RW, UART0 control DTR
  843. #define RB_MCR_RTS 0x02 // RW, UART0 control RTS
  844. #define RB_MCR_OUT1 0x04 // RW, UART0 control OUT1
  845. #define RB_MCR_OUT2 0x08 // RW, UART control OUT2
  846. #define RB_MCR_INT_OE 0x08 // RW, UART interrupt output enable
  847. #define RB_MCR_LOOP 0x10 // RW, UART0 enable local loop back
  848. #define RB_MCR_AU_FLOW_EN 0x20 // RW, UART0 enable autoflow control
  849. #define RB_MCR_TNOW 0x40 // RW, UART0 enable TNOW output on DTR pin
  850. #define RB_MCR_HALF 0x80 // RW, UART0 enable half-duplex
  851. #define UART_IER 1
  852. #define RB_IER_RECV_RDY 0x01 // RW, UART interrupt enable for receiver data ready
  853. #define RB_IER_THR_EMPTY 0x02 // RW, UART interrupt enable for THR empty
  854. #define RB_IER_LINE_STAT 0x04 // RW, UART interrupt enable for receiver line status
  855. #define RB_IER_MODEM_CHG 0x08 // RW, UART0 interrupt enable for modem status change
  856. #define RB_IER_DTR_EN 0x10 // RW, UART0 DTR/TNOW output pin enable
  857. #define RB_IER_RTS_EN 0x20 // RW, UART0 RTS output pin enable
  858. #define RB_IER_TXD_EN 0x40 // RW, UART TXD pin enable
  859. #define RB_IER_RESET 0x80 // WZ, UART software reset control, high action, auto clear
  860. #define UART_FCR 2
  861. #define RB_FCR_FIFO_EN 0x01 // RW, UART FIFO enable
  862. #define RB_FCR_RX_FIFO_CLR 0x02 // WZ, clear UART receiver FIFO, high action, auto clear
  863. #define RB_FCR_TX_FIFO_CLR 0x04 // WZ, clear UART transmitter FIFO, high action, auto clear
  864. #define RB_FCR_FIFO_TRIG 0xC0 // RW, UART receiver FIFO trigger level: 00-1byte, 01-2bytes, 10-4bytes, 11-7bytes
  865. #define UART_LCR 3
  866. #define RB_LCR_WORD_SZ 0x03 // RW, UART word bit length: 00-5bit, 01-6bit, 10-7bit, 11-8bit
  867. #define RB_LCR_STOP_BIT 0x04 // RW, UART stop bit length: 0-1bit, 1-2bit
  868. #define RB_LCR_PAR_EN 0x08 // RW, UART parity enable
  869. #define RB_LCR_PAR_MOD 0x30 // RW, UART parity mode: 00-odd, 01-even, 10-mark, 11-space
  870. #define RB_LCR_BREAK_EN 0x40 // RW, UART break control enable
  871. #define RB_LCR_DLAB 0x80 // RW, UART reserved bit
  872. #define RB_LCR_GP_BIT 0x80 // RW, UART general purpose bit
  873. #define UART_IIR 4
  874. #define RB_IIR_NO_INT 0x01 // RO, UART no interrupt flag: 0=interrupt action, 1=no interrupt
  875. #define RB_IIR_INT_MASK 0x0F // RO, UART interrupt flag bit mask
  876. #define RB_IIR_FIFO_ID 0xC0 // RO, UART FIFO enabled flag
  877. #define UART_LSR 5
  878. #define RB_LSR_DATA_RDY 0x01 // RO, UART receiver fifo data ready status
  879. #define RB_LSR_OVER_ERR 0x02 // RZ, UART receiver overrun error
  880. #define RB_LSR_PAR_ERR 0x04 // RZ, UART receiver parity error
  881. #define RB_LSR_FRAME_ERR 0x08 // RZ, UART receiver frame error
  882. #define RB_LSR_BREAK_ERR 0x10 // RZ, UART receiver break error
  883. #define RB_LSR_TX_FIFO_EMP 0x20 // RO, UART transmitter fifo empty status
  884. #define RB_LSR_TX_ALL_EMP 0x40 // RO, UART transmitter all empty status
  885. #define RB_LSR_ERR_RX_FIFO 0x80 // RO, indicate error in UART receiver fifo
  886. #define UART_MSR 6
  887. #define RB_MSR_CTS_CHG 0x01 // RZ, UART0 CTS changed status, high action
  888. #define RB_MSR_DSR_CHG 0x02 // RZ, UART0 DSR changed status, high action
  889. #define RB_MSR_RI_CHG 0x04 // RZ, UART0 RI changed status, high action
  890. #define RB_MSR_DCD_CHG 0x08 // RZ, UART0 DCD changed status, high action
  891. #define RB_MSR_CTS 0x10 // RO, UART0 CTS action status
  892. #define RB_MSR_DSR 0x20 // RO, UART0 DSR action status
  893. #define RB_MSR_RI 0x40 // RO, UART0 RI action status
  894. #define RB_MSR_DCD 0x80 // RO, UART0 DCD action status
  895. #define UART_RBR 8
  896. #define UART_THR 8
  897. #define UART_RFC 0x0A
  898. #define UART_TFC 0x0B
  899. #define UART_DLL 0x0C
  900. #define UART_DLM 0x0D
  901. #define UART_DIV 0x0E
  902. #define UART_ADR 0x0F
  903. /* UART interrupt identification values for IIR bits 3:0 */
  904. #define UART_II_SLV_ADDR 0x0E // RO, UART0 slave address match
  905. #define UART_II_LINE_STAT 0x06 // RO, UART interrupt by receiver line status
  906. #define UART_II_RECV_RDY 0x04 // RO, UART interrupt by receiver data available
  907. #define UART_II_RECV_TOUT 0x0C // RO, UART interrupt by receiver fifo timeout
  908. #define UART_II_THR_EMPTY 0x02 // RO, UART interrupt by THR empty
  909. #define UART_II_MODEM_CHG 0x00 // RO, UART0 interrupt by modem status change
  910. #define UART_II_NO_INTER 0x01 // RO, no UART interrupt is pending
  911. /* SPI0 register */
  912. #define R32_SPI0_CONTROL (*((PUINT32V)0x40004000)) // RW, SPI0 control
  913. #define R8_SPI0_CTRL_MOD (*((PUINT8V)0x40004000)) // RW, SPI0 mode control
  914. #define R8_SPI0_CTRL_CFG (*((PUINT8V)0x40004001)) // RW, SPI0 configuration control
  915. #define R8_SPI0_INTER_EN (*((PUINT8V)0x40004002)) // RW, SPI0 interrupt enable
  916. #define R8_SPI0_CLOCK_DIV (*((PUINT8V)0x40004003)) // RW, SPI0 master clock divisor
  917. #define R8_SPI0_SLAVE_PRE (*((PUINT8V)0x40004003)) // RW, SPI0 slave preset value
  918. #define R32_SPI0_STATUS (*((PUINT32V)0x40004004)) // RW, SPI0 status
  919. #define R8_SPI0_BUFFER (*((PUINT8V)0x40004004)) // RO, SPI0 data buffer
  920. #define R8_SPI0_RUN_FLAG (*((PUINT8V)0x40004005)) // RO, SPI0 work flag
  921. #define R8_SPI0_INT_FLAG (*((PUINT8V)0x40004006)) // RW1, SPI0 interrupt flag
  922. #define R8_SPI0_FIFO_COUNT (*((PUINT8V)0x40004007)) // RO, SPI0 FIFO count status
  923. #define R32_SPI0_TOTAL_CNT (*((PUINT32V)0x4000400C)) // RW, SPI0 total byte count, only low 12 bit
  924. #define R16_SPI0_TOTAL_CNT (*((PUINT16V)0x4000400C)) // RW, SPI0 total byte count, only low 12 bit
  925. #define R32_SPI0_FIFO (*((PUINT32V)0x40004010)) // RW, SPI0 FIFO register
  926. #define R8_SPI0_FIFO (*((PUINT8V)0x40004010)) // RO/WO, SPI0 FIFO register
  927. #define R8_SPI0_FIFO_COUNT1 (*((PUINT8V)0x40004013)) // RO, SPI0 FIFO count status
  928. #define R32_SPI0_DMA_NOW (*((PUINT32V)0x40004014)) // RW, SPI0 DMA current address
  929. #define R16_SPI0_DMA_NOW (*((PUINT16V)0x40004014)) // RW, SPI0 DMA current address
  930. #define R32_SPI0_DMA_BEG (*((PUINT32V)0x40004018)) // RW, SPI0 DMA begin address
  931. #define R16_SPI0_DMA_BEG (*((PUINT16V)0x40004018)) // RW, SPI0 DMA begin address
  932. #define R32_SPI0_DMA_END (*((PUINT32V)0x4000401C)) // RW, SPI0 DMA end address
  933. #define R16_SPI0_DMA_END (*((PUINT16V)0x4000401C)) // RW, SPI0 DMA end address
  934. /* SPI1 register */
  935. #define R32_SPI1_CONTROL (*((PUINT32V)0x40004400)) // RW, SPI1 control
  936. #define R8_SPI1_CTRL_MOD (*((PUINT8V)0x40004400)) // RW, SPI1 mode control
  937. #define R8_SPI1_CTRL_CFG (*((PUINT8V)0x40004401)) // RW, SPI1 configuration control
  938. #define R8_SPI1_INTER_EN (*((PUINT8V)0x40004402)) // RW, SPI1 interrupt enable
  939. #define R8_SPI1_CLOCK_DIV (*((PUINT8V)0x40004403)) // RW, SPI1 master clock divisor
  940. #define R32_SPI1_STATUS (*((PUINT32V)0x40004404)) // RW, SPI1 status
  941. #define R8_SPI1_BUFFER (*((PUINT8V)0x40004404)) // RO, SPI1 data buffer
  942. #define R8_SPI1_RUN_FLAG (*((PUINT8V)0x40004405)) // RO, SPI1 work flag
  943. #define R8_SPI1_INT_FLAG (*((PUINT8V)0x40004406)) // RW1, SPI1 interrupt flag
  944. #define R8_SPI1_FIFO_COUNT (*((PUINT8V)0x40004407)) // RO, SPI1 FIFO count status
  945. #define R32_SPI1_TOTAL_CNT (*((PUINT32V)0x4000440C)) // RW, SPI1 total byte count, only low 12 bit
  946. #define R16_SPI1_TOTAL_CNT (*((PUINT16V)0x4000440C)) // RW, SPI1 total byte count, only low 12 bit
  947. #define R32_SPI1_FIFO (*((PUINT32V)0x40004410)) // RW, SPI1 FIFO register
  948. #define R8_SPI1_FIFO (*((PUINT8V)0x40004410)) // RO/WO, SPI1 FIFO register
  949. #define R8_SPI1_FIFO_COUNT1 (*((PUINT8V)0x40004413)) // RO, SPI1 FIFO count status
  950. /* SPI register address offset and bit define */
  951. #define SPI_FIFO_SIZE 8 // SPI FIFO size (depth)
  952. #define BA_SPI0 ((PUINT8V)0x40004000) // point SPI0 base address
  953. #define BA_SPI1 ((PUINT8V)0x40004400) // point SPI1 base address
  954. #define SPI_CTRL_MOD 0
  955. #define RB_SPI_MODE_SLAVE 0x01 // RW, SPI0 slave mode: 0=master/host, 1=slave/device
  956. #define RB_SPI_ALL_CLEAR 0x02 // RW, force clear SPI FIFO and count
  957. #define RB_SPI_2WIRE_MOD 0x04 // RW, SPI0 enable 2 wire mode for slave: 0=3wire(SCK0,MOSI,MISO), 1=2wire(SCK0,MISO=MXSX)
  958. #define RB_SPI_MST_SCK_MOD 0x08 // RW, SPI master clock mode: 0=mode 0, 1=mode 3
  959. #define RB_SPI_SLV_CMD_MOD 0x08 // RW, SPI0 slave command mode: 0=byte stream, 1=first byte command
  960. #define RB_SPI_FIFO_DIR 0x10 // RW, SPI FIFO direction: 0=out(write @master mode), 1=in(read @master mode)
  961. #define RB_SPI_SCK_OE 0x20 // RW, SPI SCK output enable
  962. #define RB_SPI_MOSI_OE 0x40 // RW, SPI MOSI output enable
  963. #define RB_SPI1_SDO_OE 0x40 // RW, SPI1 SDO output enable
  964. #define RB_SPI_MISO_OE 0x80 // RW, SPI MISO output enable
  965. #define RB_SPI1_SDI_OE 0x80 // RW, SPI1 SDI output enable, SPI1 enable 2 wire mode: 0=3wire(SCK1,SDO,SDI), 1=2wire(SCK1,SDI=SDX)
  966. #define SPI_CTRL_CFG 1
  967. #define RB_SPI_DMA_ENABLE 0x01 // RW, SPI0 DMA enable
  968. #define RB_SPI_DMA_LOOP 0x04 // RW, SPI0 DMA address loop enable
  969. #define RB_SPI_AUTO_IF 0x10 // RW, enable buffer/FIFO accessing to auto clear RB_SPI_IF_BYTE_END interrupt flag
  970. #define RB_SPI_BIT_ORDER 0x20 // RW, SPI bit data order: 0=MSB first, 1=LSB first
  971. #define RB_SPI_MST_DLY_EN 0x40 // RW, SPI master input delay enable
  972. #define SPI_INTER_EN 2
  973. #define RB_SPI_IE_CNT_END 0x01 // RW, enable interrupt for SPI total byte count end
  974. #define RB_SPI_IE_BYTE_END 0x02 // RW, enable interrupt for SPI byte exchanged
  975. #define RB_SPI_IE_FIFO_HF 0x04 // RW, enable interrupt for SPI FIFO half
  976. #define RB_SPI_IE_DMA_END 0x08 // RW, enable interrupt for SPI0 DMA completion
  977. #define RB_SPI_IE_FIFO_OV 0x10 // RW, enable interrupt for SPI0 FIFO overflow
  978. #define RB_SPI_IE_FST_BYTE 0x80 // RW, enable interrupt for SPI0 slave mode first byte received
  979. #define SPI_CLOCK_DIV 3
  980. #define SPI_SLAVE_PRESET 3
  981. #define SPI_BUFFER 4
  982. #define SPI_RUN_FLAG 5
  983. #define RB_SPI_SLV_CMD_ACT 0x10 // RO, SPI0 slave first byte / command flag
  984. #define RB_SPI_FIFO_READY 0x20 // RO, SPI FIFO ready status
  985. #define RB_SPI_SLV_CS_LOAD 0x40 // RO, SPI0 slave chip-select loading status
  986. #define RB_SPI_SLV_SELECT 0x80 // RO, SPI0 slave selection status
  987. #define SPI_INT_FLAG 6
  988. #define RB_SPI_IF_CNT_END 0x01 // RW1, interrupt flag for SPI total byte count end
  989. #define RB_SPI_IF_BYTE_END 0x02 // RW1, interrupt flag for SPI byte exchanged
  990. #define RB_SPI_IF_FIFO_HF 0x04 // RW1, interrupt flag for SPI FIFO half (RB_SPI_FIFO_DIR ? >=4bytes : <4bytes)
  991. #define RB_SPI_IF_DMA_END 0x08 // RW1, interrupt flag for SPI0 DMA completion
  992. #define RB_SPI_IF_FIFO_OV 0x10 // RW1, interrupt flag for SPI0 FIFO overflow
  993. #define RB_SPI_FREE 0x40 // RO, current SPI free status
  994. #define RB_SPI_IF_FST_BYTE 0x80 // RW1, interrupt flag for SPI0 slave mode first byte received
  995. #define SPI_FIFO_COUNT 7
  996. #define SPI_TOTAL_CNT 0x0C
  997. #define SPI_FIFO 0x10
  998. #define SPI_DMA_NOW 0x14
  999. #define SPI_DMA_BEG 0x18
  1000. #define SPI_DMA_END 0x1C
  1001. /* PWM4/5/6/7/8/9/10/11 register */
  1002. #define R32_PWM_CONTROL (*((PUINT32V)0x40005000)) // RW, PWM control
  1003. #define R8_PWM_OUT_EN (*((PUINT8V)0x40005000)) // RW, PWM output enable control
  1004. #define R8_PWM_POLAR (*((PUINT8V)0x40005001)) // RW, PWM output polarity control
  1005. #define R8_PWM_CONFIG (*((PUINT8V)0x40005002)) // RW, PWM configuration
  1006. #define R8_PWM_CLOCK_DIV (*((PUINT8V)0x40005003)) // RW, PWM clock divisor
  1007. #define R32_PWM4_7_DATA (*((PUINT32V)0x40005004)) // RW, PWM4-7 data holding
  1008. #define R8_PWM4_DATA (*((PUINT8V)0x40005004)) // RW, PWM4 data holding
  1009. #define R8_PWM5_DATA (*((PUINT8V)0x40005005)) // RW, PWM5 data holding
  1010. #define R8_PWM6_DATA (*((PUINT8V)0x40005006)) // RW, PWM6 data holding
  1011. #define R8_PWM7_DATA (*((PUINT8V)0x40005007)) // RW, PWM7 data holding
  1012. #define R32_PWM8_11_DATA (*((PUINT32V)0x40005008)) // RW, PWM8-11 data holding
  1013. #define R8_PWM8_DATA (*((PUINT8V)0x40005008)) // RW, PWM8 data holding
  1014. #define R8_PWM9_DATA (*((PUINT8V)0x40005009)) // RW, PWM9 data holding
  1015. #define R8_PWM10_DATA (*((PUINT8V)0x4000500A)) // RW, PWM10 data holding
  1016. #define R8_PWM11_DATA (*((PUINT8V)0x4000500B)) // RW, PWM11 data holding
  1017. /* PWM4/5/6/7/8/9/10/11 register address offset and bit define */
  1018. #define BA_PWMX ((PUINT8V)0x40005000) // point PWM4/5/6/7/8/9/10/11 base address
  1019. #define PWM_OUT_EN 0
  1020. #define RB_PWM4_OUT_EN 0x01 // RW, PWM4 output enable
  1021. #define RB_PWM5_OUT_EN 0x02 // RW, PWM5 output enable
  1022. #define RB_PWM6_OUT_EN 0x04 // RW, PWM6 output enable
  1023. #define RB_PWM7_OUT_EN 0x08 // RW, PWM7 output enable
  1024. #define RB_PWM8_OUT_EN 0x10 // RW, PWM8 output enable
  1025. #define RB_PWM9_OUT_EN 0x20 // RW, PWM9 output enable
  1026. #define RB_PWM10_OUT_EN 0x40 // RW, PWM10 output enable
  1027. #define RB_PWM11_OUT_EN 0x80 // RW, PWM11 output enable
  1028. #define PWM_POLAR 1
  1029. #define RB_PWM4_POLAR 0x01 // RW, PWM4 output polarity: 0=default low and high action, 1=default high and low action
  1030. #define RB_PWM5_POLAR 0x02 // RW, PWM5 output polarity: 0=default low and high action, 1=default high and low action
  1031. #define RB_PWM6_POLAR 0x04 // RW, PWM6 output polarity: 0=default low and high action, 1=default high and low action
  1032. #define RB_PWM7_POLAR 0x08 // RW, PWM7 output polarity: 0=default low and high action, 1=default high and low action
  1033. #define RB_PWM8_POLAR 0x10 // RW, PWM8 output polarity: 0=default low and high action, 1=default high and low action
  1034. #define RB_PWM9_POLAR 0x20 // RW, PWM9 output polarity: 0=default low and high action, 1=default high and low action
  1035. #define RB_PWM10_POLAR 0x40 // RW, PWM10 output polarity: 0=default low and high action, 1=default high and low action
  1036. #define RB_PWM11_POLAR 0x80 // RW, PWM11 output polarity: 0=default low and high action, 1=default high and low action
  1037. #define PWM_CONFIG 2
  1038. #define RB_PWM_CYCLE_SEL 0x01 // RW, PWM cycle selection: 0=256/128/64/32 clocks, 1=255/127/63/31 clocks
  1039. #define RB_PWM_STAG_ST 0x02 // RO, PWM stagger cycle status
  1040. #define RB_PWM_CYC_MOD 0x0c // RW, PWM data width mode: 00=8 bits data, 01=7 bits data, 10=6 bits data, 11=5 bits data
  1041. #define RB_PWM4_5_STAG_EN 0x10 // RW, PWM4/5 stagger output enable: 0=independent output, 1=stagger output
  1042. #define RB_PWM6_7_STAG_EN 0x20 // RW, PWM6/7 stagger output enable: 0=independent output, 1=stagger output
  1043. #define RB_PWM8_9_STAG_EN 0x40 // RW, PWM8/9 stagger output enable: 0=independent output, 1=stagger output
  1044. #define RB_PWM10_11_STAG_EN 0x80 // RW, PWM10/11 stagger output enable: 0=independent output, 1=stagger output
  1045. #define PWM_CLOCK_DIV 3
  1046. #define PWM4_DATA_HOLD 4
  1047. #define PWM5_DATA_HOLD 5
  1048. #define PWM6_DATA_HOLD 6
  1049. #define PWM7_DATA_HOLD 7
  1050. #define PWM8_DATA_HOLD 8
  1051. #define PWM9_DATA_HOLD 9
  1052. #define PWM10_DATA_HOLD 10
  1053. #define PWM11_DATA_HOLD 11
  1054. /* LED register */
  1055. #define R32_LED_CONTROL (*((PUINT32V)0x40006400)) // RW, LED control
  1056. #define R8_LED_CTRL_MOD (*((PUINT8V)0x40006400)) // RW, LED mode control
  1057. #define R8_LED_CLOCK_DIV (*((PUINT8V)0x40006401)) // RW, LED serial clock divisor
  1058. #define R8_LED_STATUS (*((PUINT8V)0x40006404)) // RO, LED status
  1059. #define R32_LED_FIFO (*((PUINT32V)0x40006408)) // WO, LED FIFO register, width is half-word, only low 16 bit
  1060. #define R16_LED_FIFO (*((PUINT16V)0x40006408)) // WO, LED FIFO register, width is half-word
  1061. #define R32_LED_DMA_CNT (*((PUINT32V)0x40006410)) // RW, LED DMA main buffer remainder half-word count, exclude auxiliary buffer, automatic decreasing after DMA, only low 12 bit
  1062. #define R16_LED_DMA_CNT (*((PUINT16V)0x40006410)) // RW, LED DMA main buffer remainder half-word count, exclude auxiliary buffer, automatic decreasing after DMA, only low 12 bit
  1063. #define R32_LED_DMA_MAIN (*((PUINT32V)0x40006414)) // RW, LED main buffer DMA begin & current address, automatic increasing after DMA
  1064. #define R16_LED_DMA_MAIN (*((PUINT16V)0x40006414)) // RW, LED main buffer DMA begin & current address, automatic increasing after DMA
  1065. #define R32_LED_DMA_AUX (*((PUINT32V)0x40006418)) // RW, LED auxiliary buffer DMA begin & current address, automatic increasing after DMA
  1066. #define R16_LED_DMA_AUX (*((PUINT16V)0x40006418)) // RW, LED auxiliary buffer DMA begin & current address, automatic increasing after DMA
  1067. /* LED register address offset and bit define */
  1068. #define LED_FIFO_SIZE 2 // LED FIFO size (depth), width is half-word
  1069. #define BA_LED ((PUINT8V)0x40006400) // point LED base address
  1070. #define LED_CTRL_MOD 0
  1071. #define RB_LED_BIT_ORDER 0x01 // RW, LED bit data order: 0=LSB first, 1=MSB first
  1072. #define RB_LED_ALL_CLEAR 0x02 // RW, force clear LED FIFO and count
  1073. #define RB_LED_OUT_POLAR 0x04 // RW, LED output polarity: 0=pass, 1=invert
  1074. #define RB_LED_OUT_EN 0x08 // RW, LED output enable
  1075. #define RB_LED_DMA_EN 0x10 // RW, LED DMA enable and DMA interrupt enable
  1076. #define RB_LED_IE_FIFO 0x20 // RW, enable interrupt for LED FIFO <=2
  1077. #define RB_LED_CHAN_MOD 0xC0 // RW, LED channel mode: 00=LED0, 01=LED0/1, 10=LED0~3, 11=LED0~3 and LED2/3 from auxiliary buffer
  1078. // RB_LED_CHAN_MOD: LED channel mode
  1079. // 00: single channel output, LED0
  1080. // 01: dual channels output, LED0/1
  1081. // 10: 4 channels output, LED0~3
  1082. // 11: 4 channels output and LED2/3 from aux buffer, LED0~3
  1083. #define LED_CLOCK_DIV 1
  1084. #define LED_STATUS 4
  1085. #define RB_LED_FIFO_COUNT 0x07 // RO, LED FIFO byte count status, must divided by 2 for width half-word
  1086. #define RB_LED_CLOCK 0x10 // RO, current LED clock level
  1087. #define RB_LED_IF_FIFO 0x20 // RW1, interrupt flag for LED FIFO <=2, cleared by RW1 or write R32/R16_LED_FIFO
  1088. #define RB_LED_FIFO_EMPTY 0x40 // RO: indicate FIFO empty status
  1089. #define RB_LED_IF_DMA_END 0x80 // RW1, interrupt flag for LED DMA completion, cleared by RW1 or write R32/R16_LED_DMA_CNT
  1090. #define LED_FIFO 8
  1091. #define LED_DMA_CNT 0x10
  1092. #define LED_DMA_BEG 0x14
  1093. #define LED_DMA_END 0x18
  1094. /* LCD register */
  1095. #define R32_LCD_CONTROL (*((PUINT32V)(0x40006000)))
  1096. #define R8_LCD_CTRL_MOD (*((PUINT8V)(0x40006000)))
  1097. #define RB_SYS_POWER_ON 0x01 // RW, LCD digital system enable
  1098. #define RB_LCD_POWER_ON 0x02 // RW, LCD analog system enable
  1099. #define RB_LCD_BIAS 0x04 // RW, LCD bias select: 0=1/2 bias, 1=1/3 bias
  1100. #define RB_LCD_DUTY 0x18 // RW, LCD duty select: 00=1/2 duty, 01=1/3 duty, 10=1/4 duty
  1101. #define RB_LCD_SCAN_CLK 0x60 // RW, LCD scan clock select: 00=256Hz, 01=512Hz, 10=1KHz, 11=128Hz
  1102. #define RB_LCD_V_SEL 0x80 // RW, LCD drive voltage:0=VIO33*100%(3.3V),1=VIO33*76%(2.5V)
  1103. #define R32_LCD_RAM0 (*((PUINT32V)(0x40006004))) // RW, LCD driver data0, address 0-3
  1104. #define R32_LCD_RAM1 (*((PUINT32V)(0x40006008))) // RW, LCD driver data1, address 4-7
  1105. #define R32_LCD_RAM2 (*((PUINT32V)(0x4000600C))) // RW, LCD driver data2, address 8-12
  1106. /* Address space define */
  1107. #define BA_CODE ((PUINT32)0x00000000) // point code base address
  1108. #define SZ_CODE 0x00040000 // code size
  1109. #define BA_SFR ((PUINT32)0x40000000) // point SFR base address
  1110. #define SZ_SFR 0x00010000 // SFR size
  1111. #define BA_RAM ((PUINT32)0x20000000) // point RAM base address
  1112. #define SZ_RAM 0x00008000 // RAM size
  1113. #define BA_PPB ((PUINT32)0xE0000000) // point PPB base address
  1114. #define SZ_PPB 0x00010000 // PPB size
  1115. /* Special Program Space */
  1116. #define DATA_FLASH_ADDR 0x3E800 // start address of Data-Flash
  1117. #define DATA_FLASH_SIZE 0x0800 // size of Data-Flash
  1118. #define BOOT_LOAD_ADDR 0x3F000 // start address of boot loader program
  1119. #define BOOT_LOAD_SIZE 0x1000 // size of boot loader program
  1120. #define BOOT_LOAD_CFG 0x40000 // start address of configuration information for boot loader program
  1121. #define ROM_CFG_ADDR 0x40010 // chip configuration information address
  1122. /*----- Reference Information --------------------------------------------*/
  1123. #define ID_CH579 0x79 // chip ID
  1124. /* Interrupt routine address and interrupt number */
  1125. #define INT_ID_TMR0 0 // interrupt number for Timer0
  1126. #define INT_ID_GPIO 1 // interrupt number for GPIO
  1127. #define INT_ID_SLAVE 2 // interrupt number for Slave
  1128. #define INT_ID_SPI0 3 // interrupt number for SPI0
  1129. #define INT_ID_BLEB 4 // interrupt number for BLEBB
  1130. #define INT_ID_BLEL 5 // interrupt number for BLELLE
  1131. #define INT_ID_USB 6 // interrupt number for USB
  1132. #define INT_ID_ETH 7 // interrupt number for ETH
  1133. #define INT_ID_TMR1 8 // interrupt number for Timer1
  1134. #define INT_ID_TMR2 9 // interrupt number for Timer2
  1135. #define INT_ID_UART0 10 // interrupt number for UART0
  1136. #define INT_ID_UART1 11 // interrupt number for UART1
  1137. #define INT_ID_RTC 12 // interrupt number for RTC
  1138. #define INT_ID_ADC 13 // interrupt number for ADC and TouchKey
  1139. #define INT_ID_SPI1 14 // interrupt number for SPI1
  1140. #define INT_ID_LED 15 // interrupt number for LED
  1141. #define INT_ID_TMR3 16 // interrupt number for Timer3
  1142. #define INT_ID_UART2 17 // interrupt number for UART2
  1143. #define INT_ID_UART3 18 // interrupt number for UART3
  1144. #define INT_ID_WDOG_BAT 19 // interrupt number for Watch-Dog timer and Battery low voltage
  1145. #define INT_VEC_ENTRY_SZ 4 // size of each interrupt vector entry
  1146. #define INT_ADDR_TMR0 (INT_ID_TMR0*INT_VEC_ENTRY_SZ+64) // interrupt vector address for Timer0
  1147. #define INT_ADDR_GPIO (INT_ID_GPIO*INT_VEC_ENTRY_SZ+64) // interrupt vector address for GPIO
  1148. #define INT_ADDR_SLAVE (INT_ID_SLAVE*INT_VEC_ENTRY_SZ+64) // interrupt vector address for Slave
  1149. #define INT_ADDR_SPI0 (INT_ID_SPI0*INT_VEC_ENTRY_SZ+64) // interrupt vector address for SPI0
  1150. #define INT_ADDR_BLEB (INT_ID_BLEB*INT_VEC_ENTRY_SZ+64) // interrupt vector address for BLEBB
  1151. #define INT_ADDR_BLEL (INT_ID_BLEL*INT_VEC_ENTRY_SZ+64) // interrupt vector address for BLELLE
  1152. #define INT_ADDR_USB (INT_ID_USB*INT_VEC_ENTRY_SZ+64) // interrupt vector address for USB
  1153. #define INT_ADDR_ETH (INT_ID_ETH*INT_VEC_ENTRY_SZ+64) // interrupt vector address for ETH
  1154. #define INT_ADDR_TMR1 (INT_ID_TMR1*INT_VEC_ENTRY_SZ+64) // interrupt vector address for Timer1
  1155. #define INT_ADDR_TMR2 (INT_ID_TMR2*INT_VEC_ENTRY_SZ+64) // interrupt vector address for Timer2
  1156. #define INT_ADDR_UART0 (INT_ID_UART0*INT_VEC_ENTRY_SZ+64) // interrupt vector address for UART0
  1157. #define INT_ADDR_UART1 (INT_ID_UART1*INT_VEC_ENTRY_SZ+64) // interrupt vector address for UART1
  1158. #define INT_ADDR_RTC (INT_ID_RTC*INT_VEC_ENTRY_SZ+64) // interrupt vector address for RTC
  1159. #define INT_ADDR_AD (INT_ID_ADC*INT_VEC_ENTRY_SZ+64) // interrupt vector address for ADC and TouchKey
  1160. #define INT_ADDR_SPI1 (INT_ID_SPI1*INT_VEC_ENTRY_SZ+64) // interrupt vector address for SPI1
  1161. #define INT_ADDR_LED (INT_ID_LED*INT_VEC_ENTRY_SZ+64) // interrupt vector address for LED
  1162. #define INT_ADDR_Timer3 (INT_ID_Timer3*INT_VEC_ENTRY_SZ+64) // interrupt vector address for Timer3
  1163. #define INT_ADDR_UART2 (INT_ID_UART2*INT_VEC_ENTRY_SZ+64) // interrupt vector address for UART2
  1164. #define INT_ADDR_UART3 (INT_ID_UART3*INT_VEC_ENTRY_SZ+64) // interrupt vector address for UART3
  1165. #define INT_ADDR_WDOG_BAT (INT_ID_WDOG_BAT*INT_VEC_ENTRY_SZ+64) // interrupt vector address for Watch-Dog timer and Battery low voltage
  1166. #ifndef TABLE_IRQN
  1167. #define __NVIC_PRIO_BITS 2 /*!< uses 2 Bits for the Priority Levels */
  1168. #define __Vendor_SysTickConfig 0 /*!< Set to 1 if different SysTick Config is used */
  1169. typedef enum IRQn
  1170. {
  1171. /* ------------------- Cortex-M0 Processor Exceptions Numbers ------------------- */
  1172. NonMaskableInt_IRQn = -14, /*!< 2 Non Maskable Interrupt */
  1173. HardFault_IRQn = -13, /*!< 3 HardFault Interrupt */
  1174. SVCall_IRQn = -5, /*!< 11 SV Call Interrupt */
  1175. PendSV_IRQn = -2, /*!< 14 Pend SV Interrupt */
  1176. SysTick_IRQn = -1, /*!< 15 System Tick Interrupt */
  1177. /* ---------------------- ARMCM0 Specific Interrupt Numbers --------------------- */
  1178. TMR0_IRQn = 0, /*!< Timer0 Interrupt */
  1179. GPIO_IRQn = 1, /*!< GPIO A/B Interrupt */
  1180. SLAVE_IRQn = 2, /*!< Slave parallel port Interrupt */
  1181. SPI0_IRQn = 3, /*!< SPI0 Interrupt */
  1182. BLEB_IRQn = 4, /*!< BB Interrupt */
  1183. BLEL_IRQn = 5, /*!< LLE Interrupt */
  1184. USB_IRQn = 6, /*!< USB Interrupt */
  1185. ETH_IRQn = 7, /*!< Ethernet Interrupt */
  1186. TMR1_IRQn = 8, /*!< Timer1 Interrupt */
  1187. TMR2_IRQn = 9, /*!< Timer2 Interrupt */
  1188. UART0_IRQn = 10, /*!< UART0 Interrupt */
  1189. UART1_IRQn = 11, /*!< UART1 Interrupt */
  1190. RTC_IRQn = 12, /*!< Real Time Clock Interrupt */
  1191. ADC_IRQn = 13, /*!< ADC Interrupt */
  1192. SPI1_IRQn = 14, /*!< SPI1 Interrupt */
  1193. LED_IRQn = 15, /*!< LED control Interrupt */
  1194. TMR3_IRQn = 16, /*!< Timer3 Interrupt */
  1195. UART2_IRQn = 17, /*!< UART2 Interrupt */
  1196. UART3_IRQn = 18, /*!< UART3 Interrupt */
  1197. WDOG_BAT_IRQn = 19, /*!< Watch Dog Interrupt */
  1198. } IRQn_Type;
  1199. #endif
  1200. #ifdef __cplusplus
  1201. }
  1202. #endif
  1203. #endif // __CH579SFR_H__
  1204. #ifndef __CH579ETHSFR_H__
  1205. #define __CH579ETHSFR_H__
  1206. #ifdef __cplusplus
  1207. extern "C" {
  1208. #endif
  1209. /******************************************************************************/
  1210. /* ETH Peripheral memory map */
  1211. /******************************************************************************/
  1212. /* ETH addresses
  1213. // ETH: +9000H - 93FFH */
  1214. #define ETH_BASE_ADDR (0x40009000)
  1215. /* ETH register */
  1216. #define R8_ETH_EIE (*((PUINT8V)(0x40009003))) /* 中断使能寄存器 */
  1217. #define RB_ETH_EIE_INTIE 0x80 /* RW 中断使能 */
  1218. #define RB_ETH_EIE_RXIE 0x40 /* RW 接收完成中断使能 */
  1219. #define RB_ETH_EIE_LINKIE 0x10 /* RW Link 变化中断使能 */
  1220. #define RB_ETH_EIE_TXIE 0x08 /* RW 发送完成中断使能 */
  1221. #define RB_ETH_EIE_R_EN50 0x04 /* RW TX 50Ω电阻调节。1:片内 50Ω连接 0:片内 50Ω断开 */
  1222. #define RB_ETH_EIE_TXERIE 0x02 /* RW 发送错误中断使能 */
  1223. #define RB_ETH_EIE_RXERIE 0x01 /* RW1 接收错误标志 */
  1224. #define R32_ETH_CON (*((PUINT32V)(0x40009004)))
  1225. #define R8_ETH_EIR (*((PUINT8V)(0x40009004))) /* 中断标志寄存器 */
  1226. #define RB_ETH_EIR_RXIF 0x40 /* RW1 接收完成标志 */
  1227. #define RB_ETH_EIR_LINKIF 0x10 /* RW1 Link 变化标志 */
  1228. #define RB_ETH_EIR_TXIF 0x08 /* RW1 发送完成标志 */
  1229. #define RB_ETH_EIR_TXERIF 0x02 /* RW1 发送错误标志 */
  1230. #define RB_ETH_EIR_RXERIF 0x01
  1231. #define R8_ETH_ESTAT (*((PUINT8V)(0x40009005))) /* 状态寄存器 */
  1232. #define RB_ETH_ESTAT_INT 0x80 /* RW1 中断 */
  1233. #define RB_ETH_ESTAT_BUFER 0x40 /* RW1 Buffer 错误,理论上 mcu 主频太低才会发生 */
  1234. #define RB_ETH_ESTAT_RXCRCER 0x20 /* RO 接收 crc 出错 */
  1235. #define RB_ETH_ESTAT_RXNIBBLE 0x10 /* RO 接收 nibble 错误 */
  1236. #define RB_ETH_ESTAT_RXMORE 0x08 /* RO 接收超过最大数据包 */
  1237. #define RB_ETH_ESTAT_RXBUSY 0x04 /* RO 接收进行中 */
  1238. #define RB_ETH_ESTAT_TXABRT 0x02 /* RO 发送被 mcu 打断 */
  1239. #define R8_ETH_ECON2 (*((PUINT8V)(0x40009006))) /* ETH PHY模拟模块控制寄存器 */
  1240. #define RB_ETH_ECON2_RX 0x0E /* 必须写入011 */
  1241. #define RB_ETH_ECON2_TX 0x01
  1242. #define RB_ETH_ECON2_MUST 0x06 /* 必须写入011 */
  1243. #define R8_ETH_ECON1 (*((PUINT8V)(0x40009007))) /* 收发控制寄存器 */
  1244. #define RB_ETH_ECON1_TXRST 0x80 /* RW 发送模块复位 */
  1245. #define RB_ETH_ECON1_RXRST 0x40 /* RW 接收模块复位 */
  1246. #define RB_ETH_ECON1_TXRTS 0x08 /* RW 发送开始,发送完成后自动清零,如主动清零会使发送错误标志TXERIF和TXABRT变1 */
  1247. #define RB_ETH_ECON1_RXEN 0x04 /* RW 接收使能,清零时如正在接受则错误标志RXERIF变1 */
  1248. #define R32_ETH_TX (*((PUINT32V)(0x40009008))) /* 发送控制 */
  1249. #define R16_ETH_ETXST (*((PUINT16V)(0x40009008))) /* RW 发送 DMA 缓冲区起始地址 */
  1250. #define R16_ETH_ETXLN (*((PUINT16V)(0x4000900A))) /* RW 发送长度 */
  1251. #define R32_ETH_RX (*((PUINT32V)(0x4000900C))) /* 接收控制 */
  1252. #define R16_ETH_ERXST (*((PUINT16V)(0x4000900C))) /* RW 接收 DMA 缓冲区起始地址 */
  1253. #define R16_ETH_ERXLN (*((PUINT16V)(0x4000900E))) /* RO 接收长度 */
  1254. #define R32_ETH_HTL (*((PUINT32V)(0x40009010)))
  1255. #define R8_ETH_EHT0 (*((PUINT8V)(0x40009010))) /* RW Hash Table Byte0 */
  1256. #define R8_ETH_EHT1 (*((PUINT8V)(0x40009011))) /* RW Hash Table Byte1 */
  1257. #define R8_ETH_EHT2 (*((PUINT8V)(0x40009012))) /* RW Hash Table Byte2 */
  1258. #define R8_ETH_EHT3 (*((PUINT8V)(0x40009013))) /* RW Hash Table Byte3 */
  1259. #define R32_ETH_HTH (*((PUINT32V)(0x40009014)))
  1260. #define R8_ETH_EHT4 (*((PUINT8V)(0x40009014))) /* RW Hash Table Byte4 */
  1261. #define R8_ETH_EHT5 (*((PUINT8V)(0x40009015))) /* RW Hash Table Byte5 */
  1262. #define R8_ETH_EHT6 (*((PUINT8V)(0x40009016))) /* RW Hash Table Byte6 */
  1263. #define R8_ETH_EHT7 (*((PUINT8V)(0x40009017))) /* RW Hash Table Byte7 */
  1264. #define R32_ETH_MACON (*((PUINT32V)(0x40009018)))
  1265. #define R8_ETH_ERXFCON (*((PUINT8V)(0x40009018))) /* 接收包过滤控制寄存器 */
  1266. #define RB_ETH_ERXFCON_UCEN 0x80 /* RW 0=不启用该过滤条件,1=当ANDOR=1,目标地址不匹配将被过滤,当ANDOR=0,目标地址匹配将被接收 */
  1267. #define RB_ETH_ERXFCON_ANDOR 0x40 /* RW 1=AND,所有过滤条件都满足包才被接收 0=OR,任一过滤条件满足包均被接收 */
  1268. #define RB_ETH_ERXFCON_CRCEN 0x20 /* RW 0=不启用该过滤条件,1=当ANDOR=1,CRC校验错将被过滤,当ANDOR=0,CRC校验正确将被接收 */
  1269. #define RB_ETH_ERXFCON_MPEN 0x08 /* RW 0=不启用该过滤条件,1=当ANDOR=1,非魔法包将被过滤,当ANDOR=0,魔法包将被接收 */
  1270. #define RB_ETH_ERXFCON_HTEN 0x04 /* RW 0=不启用该过滤条件,1=当ANDOR=1,hash table不匹配将被过滤,当ANDOR=0,hash table匹配将被接收 */
  1271. #define RB_ETH_ERXFCON_MCEN 0x02 /* RW 0=不启用该过滤条件,1=当ANDOR=1,组播包不匹配将被过滤,当ANDOR=0,组播包匹配将被接收 */
  1272. #define RB_ETH_ERXFCON_BCEN 0x01 /* RW 0=不启用该过滤条件,1=当ANDOR=1,非广播包将被过滤,当ANDOR=0,广播包将被接收 */
  1273. #define R8_ETH_MACON1 (*((PUINT8V)(0x40009019))) /* Mac 层流控制寄存器 */
  1274. #define RB_ETH_MACON1_FCEN 0x30 /* RW 当FULDPX=0均无效,当FULDPX=1,11=发送0 timer暂停帧,然后停止发送,10=周期性发送暂停帧,01=发送一次暂停帧,然后停止发送,00=停止发送暂停帧 */
  1275. #define RB_ETH_MACON1_TXPAUS 0x08 /* RW 发送pause帧使能 */
  1276. #define RB_ETH_MACON1_RXPAUS 0x04 /* RW 接收pause帧使能 */
  1277. #define RB_ETH_MACON1_PASSALL 0x02 /* RW 1=没被过滤的控制帧将写入缓存,0=控制帧将被过滤 */
  1278. #define RB_ETH_MACON1_MARXEN 0x01 /* RW MAC层接收使能 */
  1279. #define R8_ETH_MACON2 (*((PUINT8V)(0x4000901A))) /* Mac 层封包控制寄存器 */
  1280. #define RB_ETH_MACON2_PADCFG 0xE0 /* RW 短包填充设置 */
  1281. #define RB_ETH_MACON2_TXCRCEN 0x10 /* RW 发送添加crc,PADCFG中如需要添加crc,该位置1 */
  1282. #define RB_ETH_MACON2_PHDREN 0x08 /* RW 特殊4字节不参与crc校验 */
  1283. #define RB_ETH_MACON2_HFRMEN 0x04 /* RW 允许接收巨型帧 */
  1284. #define RB_ETH_MACON2_FULDPX 0x01 /* RW 全双工 */
  1285. #define R8_ETH_MABBIPG (*((PUINT8V)(0x4000901B))) /* 最小包间间隔寄存器 */
  1286. #define RB_ETH_MABBIPG_MABBIPG 0x7F /* RW 最小包间间隔字节数 */
  1287. #define R32_ETH_TIM (*((PUINT32V)(0x4000901C)))
  1288. #define R16_ETH_EPAUS (*((PUINT16V)(0x4000901C))) /* RW 流控制暂停帧时间寄存器 */
  1289. #define R16_ETH_MAMXFL (*((PUINT16V)(0x4000901E))) /* RW 最大接收包长度寄存器 */
  1290. #define R16_ETH_MIRD (*((PUINT16V)(0x40009020))) /* RW MII 读数据寄存器 */
  1291. #define R32_ETH_MIWR (*((PUINT32V)(0x40009024)))
  1292. #define R8_ETH_MIREGADR (*((PUINT8V)(0x40009024))) /* MII 地址寄存器 */
  1293. #define RB_ETH_MIREGADR_MASK 0x1F /* RW PHY 寄存器地址掩码 */
  1294. #define R8_ETH_MISTAT (*((PUINT8V)(0x40009025))) /* MII 状态寄存器 */
  1295. //#define RB_ETH_MIREGADR_MIIWR 0x20 /* WO MII 写命令 */
  1296. #define R16_ETH_MIWR (*((PUINT16V)(0x40009026))) /* WO MII 写数据寄存器 */
  1297. #define R32_ETH_MAADRL (*((PUINT32V)(0x40009028))) /* RW MAC 1-4 */
  1298. #define R16_ETH_MAADRH (*((PUINT16V)(0x4000902C))) /* RW MAC 5-6 */
  1299. #ifdef __cplusplus
  1300. }
  1301. #endif
  1302. #endif // __CH579ETHSFR_H__
  1303. #ifndef __CH579USBSFR_H__
  1304. #define __CH579USBSFR_H__
  1305. #ifdef __cplusplus
  1306. extern "C" {
  1307. #endif
  1308. /******************************************************************************/
  1309. /* Peripheral memory map */
  1310. /******************************************************************************/
  1311. /* usb addresses
  1312. // USB: +8000H - 83FFH */
  1313. #define USB_BASE_ADDR (0x40008000)
  1314. /* USB */
  1315. #define R32_USB_CONTROL (*((PUINT32V)(0x40008000))) // USB control & interrupt enable & device address
  1316. #define R8_USB_CTRL (*((PUINT8V)(0x40008000))) // USB base control
  1317. #define RB_UC_HOST_MODE 0x80 // enable USB host mode: 0=device mode, 1=host mode
  1318. #define RB_UC_LOW_SPEED 0x40 // enable USB low speed: 0=12Mbps, 1=1.5Mbps
  1319. #define RB_UC_DEV_PU_EN 0x20 // USB device enable and internal pullup resistance enable
  1320. #define RB_UC_SYS_CTRL1 0x20 // USB system control high bit
  1321. #define RB_UC_SYS_CTRL0 0x10 // USB system control low bit
  1322. #define MASK_UC_SYS_CTRL 0x30 // bit mask of USB system control
  1323. // bUC_HOST_MODE & bUC_SYS_CTRL1 & bUC_SYS_CTRL0: USB system control
  1324. // 0 00: disable USB device and disable internal pullup resistance
  1325. // 0 01: enable USB device and disable internal pullup resistance, need external pullup resistance
  1326. // 0 1x: enable USB device and enable internal pullup resistance
  1327. // 1 00: enable USB host and normal status
  1328. // 1 01: enable USB host and force UDP/UDM output SE0 state
  1329. // 1 10: enable USB host and force UDP/UDM output J state
  1330. // 1 11: enable USB host and force UDP/UDM output resume or K state
  1331. #define RB_UC_INT_BUSY 0x08 // enable automatic responding busy for device mode or automatic pause for host mode during interrupt flag UIF_TRANSFER valid
  1332. #define RB_UC_RESET_SIE 0x04 // force reset USB SIE, need software clear
  1333. #define RB_UC_CLR_ALL 0x02 // force clear FIFO and count of USB
  1334. #define RB_UC_DMA_EN 0x01 // DMA enable and DMA interrupt enable for USB
  1335. #define R8_UDEV_CTRL (*((PUINT8V)(0x40008001))) // USB device physical prot control
  1336. #define RB_UD_PD_DIS 0x80 // disable USB UDP/UDM pulldown resistance: 0=enable pulldown, 1=disable
  1337. #define RB_UD_DP_PIN 0x20 // ReadOnly: indicate current UDP pin level
  1338. #define RB_UD_DM_PIN 0x10 // ReadOnly: indicate current UDM pin level
  1339. #define RB_UD_LOW_SPEED 0x04 // enable USB physical port low speed: 0=full speed, 1=low speed
  1340. #define RB_UD_GP_BIT 0x02 // general purpose bit
  1341. #define RB_UD_PORT_EN 0x01 // enable USB physical port I/O: 0=disable, 1=enable
  1342. #define R8_UHOST_CTRL R8_UDEV_CTRL // USB host physical prot control
  1343. #define RB_UH_PD_DIS 0x80 // disable USB UDP/UDM pulldown resistance: 0=enable pulldown, 1=disable
  1344. #define RB_UH_DP_PIN 0x20 // ReadOnly: indicate current UDP pin level
  1345. #define RB_UH_DM_PIN 0x10 // ReadOnly: indicate current UDM pin level
  1346. #define RB_UH_LOW_SPEED 0x04 // enable USB port low speed: 0=full speed, 1=low speed
  1347. #define RB_UH_BUS_RESET 0x02 // control USB bus reset: 0=normal, 1=force bus reset
  1348. #define RB_UH_PORT_EN 0x01 // enable USB port: 0=disable, 1=enable port, automatic disabled if USB device detached
  1349. #define R8_USB_INT_EN (*((PUINT8V)(0x40008002))) // USB interrupt enable
  1350. #define RB_UIE_DEV_SOF 0x80 // enable interrupt for SOF received for USB device mode
  1351. #define RB_UIE_DEV_NAK 0x40 // enable interrupt for NAK responded for USB device mode
  1352. #define RB_UIE_FIFO_OV 0x10 // enable interrupt for FIFO overflow
  1353. #define RB_UIE_HST_SOF 0x08 // enable interrupt for host SOF timer action for USB host mode
  1354. #define RB_UIE_SUSPEND 0x04 // enable interrupt for USB suspend or resume event
  1355. #define RB_UIE_TRANSFER 0x02 // enable interrupt for USB transfer completion
  1356. #define RB_UIE_DETECT 0x01 // enable interrupt for USB device detected event for USB host mode
  1357. #define RB_UIE_BUS_RST 0x01 // enable interrupt for USB bus reset event for USB device mode
  1358. #define R8_USB_DEV_AD (*((PUINT8V)(0x40008003))) // USB device address
  1359. #define RB_UDA_GP_BIT 0x80 // general purpose bit
  1360. #define MASK_USB_ADDR 0x7F // bit mask for USB device address
  1361. #define R32_USB_STATUS (*((PUINT32V)(0x40008004))) // USB miscellaneous status & interrupt flag & interrupt status
  1362. #define R8_USB_MIS_ST (*((PUINT8V)(0x40008005))) // USB miscellaneous status
  1363. #define RB_UMS_SOF_PRES 0x80 // RO, indicate host SOF timer presage status
  1364. #define RB_UMS_SOF_ACT 0x40 // RO, indicate host SOF timer action status for USB host
  1365. #define RB_UMS_SIE_FREE 0x20 // RO, indicate USB SIE free status
  1366. #define RB_UMS_R_FIFO_RDY 0x10 // RO, indicate USB receiving FIFO ready status (not empty)
  1367. #define RB_UMS_BUS_RESET 0x08 // RO, indicate USB bus reset status
  1368. #define RB_UMS_SUSPEND 0x04 // RO, indicate USB suspend status
  1369. #define RB_UMS_DM_LEVEL 0x02 // RO, indicate UDM level saved at device attached to USB host
  1370. #define RB_UMS_DEV_ATTACH 0x01 // RO, indicate device attached status on USB host
  1371. #define R8_USB_INT_FG (*((PUINT8V)(0x40008006))) // USB interrupt flag
  1372. #define RB_U_IS_NAK 0x80 // RO, indicate current USB transfer is NAK received
  1373. #define RB_U_TOG_OK 0x40 // RO, indicate current USB transfer toggle is OK
  1374. #define RB_U_SIE_FREE 0x20 // RO, indicate USB SIE free status
  1375. #define RB_UIF_FIFO_OV 0x10 // FIFO overflow interrupt flag for USB, direct bit address clear or write 1 to clear
  1376. #define RB_UIF_HST_SOF 0x08 // host SOF timer interrupt flag for USB host, direct bit address clear or write 1 to clear
  1377. #define RB_UIF_SUSPEND 0x04 // USB suspend or resume event interrupt flag, direct bit address clear or write 1 to clear
  1378. #define RB_UIF_TRANSFER 0x02 // USB transfer completion interrupt flag, direct bit address clear or write 1 to clear
  1379. #define RB_UIF_DETECT 0x01 // device detected event interrupt flag for USB host mode, direct bit address clear or write 1 to clear
  1380. #define RB_UIF_BUS_RST 0x01 // bus reset event interrupt flag for USB device mode, direct bit address clear or write 1 to clear
  1381. #define R8_USB_INT_ST (*((PUINT8V)(0x40008007))) // USB interrupt status
  1382. #define RB_UIS_IS_NAK 0x80 // RO, indicate current USB transfer is NAK received for USB device mode
  1383. #define RB_UIS_TOG_OK 0x40 // RO, indicate current USB transfer toggle is OK
  1384. #define RB_UIS_TOKEN1 0x20 // RO, current token PID code bit 1 received for USB device mode
  1385. #define RB_UIS_TOKEN0 0x10 // RO, current token PID code bit 0 received for USB device mode
  1386. #define MASK_UIS_TOKEN 0x30 // RO, bit mask of current token PID code received for USB device mode
  1387. #define UIS_TOKEN_OUT 0x00
  1388. #define UIS_TOKEN_SOF 0x10
  1389. #define UIS_TOKEN_IN 0x20
  1390. #define UIS_TOKEN_SETUP 0x30
  1391. // bUIS_TOKEN1 & bUIS_TOKEN0: current token PID code received for USB device mode
  1392. // 00: OUT token PID received
  1393. // 01: SOF token PID received
  1394. // 10: IN token PID received
  1395. // 11: SETUP token PID received
  1396. #define MASK_UIS_ENDP 0x0F // RO, bit mask of current transfer endpoint number for USB device mode
  1397. #define MASK_UIS_H_RES 0x0F // RO, bit mask of current transfer handshake response for USB host mode: 0000=no response, time out from device, others=handshake response PID received
  1398. #define R8_USB_RX_LEN (*((PUINT8V)(0x40008008))) // USB receiving length
  1399. #define R32_USB_BUF_MODE (*((PUINT32V)(0x4000800c))) // USB endpoint buffer mode
  1400. #define R8_UEP4_1_MOD (*((PUINT8V)(0x4000800c))) // endpoint 4/1 mode
  1401. #define RB_UEP1_RX_EN 0x80 // enable USB endpoint 1 receiving (OUT)
  1402. #define RB_UEP1_TX_EN 0x40 // enable USB endpoint 1 transmittal (IN)
  1403. #define RB_UEP1_BUF_MOD 0x10 // buffer mode of USB endpoint 1
  1404. // bUEPn_RX_EN & bUEPn_TX_EN & bUEPn_BUF_MOD: USB endpoint 1/2/3 buffer mode, buffer start address is UEPn_DMA
  1405. // 0 0 x: disable endpoint and disable buffer
  1406. // 1 0 0: 64 bytes buffer for receiving (OUT endpoint)
  1407. // 1 0 1: dual 64 bytes buffer by toggle bit bUEP_R_TOG selection for receiving (OUT endpoint), total=128bytes
  1408. // 0 1 0: 64 bytes buffer for transmittal (IN endpoint)
  1409. // 0 1 1: dual 64 bytes buffer by toggle bit bUEP_T_TOG selection for transmittal (IN endpoint), total=128bytes
  1410. // 1 1 0: 64 bytes buffer for receiving (OUT endpoint) + 64 bytes buffer for transmittal (IN endpoint), total=128bytes
  1411. // 1 1 1: dual 64 bytes buffer by bUEP_R_TOG selection for receiving (OUT endpoint) + dual 64 bytes buffer by bUEP_T_TOG selection for transmittal (IN endpoint), total=256bytes
  1412. #define RB_UEP4_RX_EN 0x08 // enable USB endpoint 4 receiving (OUT)
  1413. #define RB_UEP4_TX_EN 0x04 // enable USB endpoint 4 transmittal (IN)
  1414. // bUEP4_RX_EN & bUEP4_TX_EN: USB endpoint 4 buffer mode, buffer start address is UEP0_DMA
  1415. // 0 0: single 64 bytes buffer for endpoint 0 receiving & transmittal (OUT & IN endpoint)
  1416. // 1 0: single 64 bytes buffer for endpoint 0 receiving & transmittal (OUT & IN endpoint) + 64 bytes buffer for endpoint 4 receiving (OUT endpoint), total=128bytes
  1417. // 0 1: single 64 bytes buffer for endpoint 0 receiving & transmittal (OUT & IN endpoint) + 64 bytes buffer for endpoint 4 transmittal (IN endpoint), total=128bytes
  1418. // 1 1: single 64 bytes buffer for endpoint 0 receiving & transmittal (OUT & IN endpoint)
  1419. // + 64 bytes buffer for endpoint 4 receiving (OUT endpoint) + 64 bytes buffer for endpoint 4 transmittal (IN endpoint), total=192bytes
  1420. #define R8_UEP2_3_MOD (*((PUINT8V)(0x4000800d))) // endpoint 2/3 mode
  1421. #define RB_UEP3_RX_EN 0x80 // enable USB endpoint 3 receiving (OUT)
  1422. #define RB_UEP3_TX_EN 0x40 // enable USB endpoint 3 transmittal (IN)
  1423. #define RB_UEP3_BUF_MOD 0x10 // buffer mode of USB endpoint 3
  1424. #define RB_UEP2_RX_EN 0x08 // enable USB endpoint 2 receiving (OUT)
  1425. #define RB_UEP2_TX_EN 0x04 // enable USB endpoint 2 transmittal (IN)
  1426. #define RB_UEP2_BUF_MOD 0x01 // buffer mode of USB endpoint 2
  1427. #define R8_UH_EP_MOD R8_UEP2_3_MOD //host endpoint mode
  1428. #define RB_UH_EP_TX_EN 0x40 // enable USB host OUT endpoint transmittal
  1429. #define RB_UH_EP_TBUF_MOD 0x10 // buffer mode of USB host OUT endpoint
  1430. // bUH_EP_TX_EN & bUH_EP_TBUF_MOD: USB host OUT endpoint buffer mode, buffer start address is UH_TX_DMA
  1431. // 0 x: disable endpoint and disable buffer
  1432. // 1 0: 64 bytes buffer for transmittal (OUT endpoint)
  1433. // 1 1: dual 64 bytes buffer by toggle bit bUH_T_TOG selection for transmittal (OUT endpoint), total=128bytes
  1434. #define RB_UH_EP_RX_EN 0x08 // enable USB host IN endpoint receiving
  1435. #define RB_UH_EP_RBUF_MOD 0x01 // buffer mode of USB host IN endpoint
  1436. // bUH_EP_RX_EN & bUH_EP_RBUF_MOD: USB host IN endpoint buffer mode, buffer start address is UH_RX_DMA
  1437. // 0 x: disable endpoint and disable buffer
  1438. // 1 0: 64 bytes buffer for receiving (IN endpoint)
  1439. // 1 1: dual 64 bytes buffer by toggle bit bUH_R_TOG selection for receiving (IN endpoint), total=128bytes
  1440. #define R16_UEP0_DMA (*((PUINT16V)(0x40008010))) // endpoint 0 DMA buffer address
  1441. #define R16_UEP1_DMA (*((PUINT16V)(0x40008014))) // endpoint 1 DMA buffer address
  1442. #define R16_UEP2_DMA (*((PUINT16V)(0x40008018))) // endpoint 2 DMA buffer address
  1443. #define R16_UH_RX_DMA R16_UEP2_DMA // host rx endpoint buffer high address
  1444. #define R16_UEP3_DMA (*((PUINT16V)(0x4000801C))) // endpoint 3 DMA buffer address
  1445. #define R16_UH_TX_DMA R16_UEP3_DMA // host tx endpoint buffer high address
  1446. #define R32_USB_EP0_CTRL (*((PUINT32V)(0x40008020))) // endpoint 0 control & transmittal length
  1447. #define R8_UEP0_T_LEN (*((PUINT8V)(0x40008020))) // endpoint 0 transmittal length
  1448. #define R8_UEP0_CTRL (*((PUINT8V)(0x40008022))) // endpoint 0 control
  1449. #define R32_USB_EP1_CTRL (*((PUINT32V)(0x40008024))) // endpoint 1 control & transmittal length
  1450. #define R8_UEP1_T_LEN (*((PUINT8V)(0x40008024))) // endpoint 1 transmittal length
  1451. #define R8_UEP1_CTRL (*((PUINT8V)(0x40008026))) // endpoint 1 control
  1452. #define RB_UEP_R_TOG 0x80 // expected data toggle flag of USB endpoint X receiving (OUT): 0=DATA0, 1=DATA1
  1453. #define RB_UEP_T_TOG 0x40 // prepared data toggle flag of USB endpoint X transmittal (IN): 0=DATA0, 1=DATA1
  1454. #define RB_UEP_AUTO_TOG 0x10 // enable automatic toggle after successful transfer completion on endpoint 1/2/3: 0=manual toggle, 1=automatic toggle
  1455. #define RB_UEP_R_RES1 0x08 // handshake response type high bit for USB endpoint X receiving (OUT)
  1456. #define RB_UEP_R_RES0 0x04 // handshake response type low bit for USB endpoint X receiving (OUT)
  1457. #define MASK_UEP_R_RES 0x0C // bit mask of handshake response type for USB endpoint X receiving (OUT)
  1458. #define UEP_R_RES_ACK 0x00
  1459. #define UEP_R_RES_TOUT 0x04
  1460. #define UEP_R_RES_NAK 0x08
  1461. #define UEP_R_RES_STALL 0x0C
  1462. // RB_UEP_R_RES1 & RB_UEP_R_RES0: handshake response type for USB endpoint X receiving (OUT)
  1463. // 00: ACK (ready)
  1464. // 01: no response, time out to host, for non-zero endpoint isochronous transactions
  1465. // 10: NAK (busy)
  1466. // 11: STALL (error)
  1467. #define RB_UEP_T_RES1 0x02 // handshake response type high bit for USB endpoint X transmittal (IN)
  1468. #define RB_UEP_T_RES0 0x01 // handshake response type low bit for USB endpoint X transmittal (IN)
  1469. #define MASK_UEP_T_RES 0x03 // bit mask of handshake response type for USB endpoint X transmittal (IN)
  1470. #define UEP_T_RES_ACK 0x00
  1471. #define UEP_T_RES_TOUT 0x01
  1472. #define UEP_T_RES_NAK 0x02
  1473. #define UEP_T_RES_STALL 0x03
  1474. // bUEP_T_RES1 & bUEP_T_RES0: handshake response type for USB endpoint X transmittal (IN)
  1475. // 00: DATA0 or DATA1 then expecting ACK (ready)
  1476. // 01: DATA0 or DATA1 then expecting no response, time out from host, for non-zero endpoint isochronous transactions
  1477. // 10: NAK (busy)
  1478. // 11: STALL (error)
  1479. #define R8_UH_SETUP R8_UEP1_CTRL // host aux setup
  1480. #define RB_UH_PRE_PID_EN 0x80 // USB host PRE PID enable for low speed device via hub
  1481. #define RB_UH_SOF_EN 0x40 // USB host automatic SOF enable
  1482. #define R32_USB_EP2_CTRL (*((PUINT32V)(0x40008028))) // endpoint 2 control & transmittal length
  1483. #define R8_UEP2_T_LEN (*((PUINT8V)(0x40008028))) // endpoint 2 transmittal length
  1484. #define R8_UEP2_CTRL (*((PUINT8V)(0x4000802a))) // endpoint 2 control
  1485. #define R8_UH_EP_PID R8_UEP2_T_LEN // host endpoint and PID
  1486. #define MASK_UH_TOKEN 0xF0 // bit mask of token PID for USB host transfer
  1487. #define MASK_UH_ENDP 0x0F // bit mask of endpoint number for USB host transfer
  1488. #define R8_UH_RX_CTRL R8_UEP2_CTRL // host receiver endpoint control
  1489. #define RB_UH_R_TOG 0x80 // expected data toggle flag of host receiving (IN): 0=DATA0, 1=DATA1
  1490. #define RB_UH_R_AUTO_TOG 0x10 // enable automatic toggle after successful transfer completion: 0=manual toggle, 1=automatic toggle
  1491. #define RB_UH_R_RES 0x04 // prepared handshake response type for host receiving (IN): 0=ACK (ready), 1=no response, time out to device, for isochronous transactions
  1492. #define R32_USB_EP3_CTRL (*((PUINT32V)(0x4000802c))) // endpoint 3 control & transmittal length
  1493. #define R8_UEP3_T_LEN (*((PUINT8V)(0x4000802c))) // endpoint 3 transmittal length
  1494. #define R8_UEP3_CTRL (*((PUINT8V)(0x4000802e))) // endpoint 3 control
  1495. #define R8_UH_TX_LEN R8_UEP3_T_LEN // host transmittal endpoint transmittal length
  1496. #define R8_UH_TX_CTRL R8_UEP3_CTRL // host transmittal endpoint control
  1497. #define RB_UH_T_TOG 0x40 // prepared data toggle flag of host transmittal (SETUP/OUT): 0=DATA0, 1=DATA1
  1498. #define RB_UH_T_AUTO_TOG 0x10 // enable automatic toggle after successful transfer completion: 0=manual toggle, 1=automatic toggle
  1499. #define RB_UH_T_RES 0x01 // expected handshake response type for host transmittal (SETUP/OUT): 0=ACK (ready), 1=no response, time out from device, for isochronous transactions
  1500. #define R32_USB_EP4_CTRL (*((PUINT32V)(0x40008030))) // endpoint 4 control & transmittal length
  1501. #define R8_UEP4_T_LEN (*((PUINT8V)(0x40008030))) // endpoint 4 transmittal length
  1502. #define R8_UEP4_CTRL (*((PUINT8V)(0x40008032))) // endpoint 4 control
  1503. #define R8_USB_TYPE_C_CTRL (*((PUINT8V)(0x40008038))) // USB type-C control
  1504. #define RB_UTCC_GP_BIT 0x80 // USB general purpose bit
  1505. #define RB_UCC2_PD_EN 0x40 // USB CC2 5.1K pulldown resistance: 0=disable, 1=enable pulldown
  1506. #define RB_UCC2_PU1_EN 0x20 // USB CC2 pullup resistance control high bit
  1507. #define RB_UCC2_PU0_EN 0x10 // USB CC2 pullup resistance control low bit
  1508. #define RB_VBUS_PD_EN 0x08 // USB VBUS 10K pulldown resistance: 0=disable, 1=enable pullup
  1509. #define RB_UCC1_PD_EN 0x04 // USB CC1 5.1K pulldown resistance: 0=disable, 1=enable pulldown
  1510. #define RB_UCC1_PU1_EN 0x02 // USB CC1 pullup resistance control high bit
  1511. #define RB_UCC1_PU0_EN 0x01 // USB CC1 pullup resistance control low bit
  1512. // RB_UCC?_PU1_EN & RB_UCC?_PU0_EN: USB CC pullup resistance selection
  1513. // 00: disable pullup resistance
  1514. // 01: enable 36K pullup resistance for default USB power
  1515. // 10: enable 12K pullup resistance for 1.5A USB power
  1516. // 11: enable 4.7K pullup resistance for 3A USB power
  1517. #ifdef __cplusplus
  1518. }
  1519. #endif
  1520. #endif //__CH579USBSFR_H__
  1521. #ifndef __USB_TYPE__
  1522. #define __USB_TYPE__
  1523. #ifdef __cplusplus
  1524. extern "C" {
  1525. #endif
  1526. /*----- USB constant and structure define --------------------------------*/
  1527. /* USB PID */
  1528. #ifndef USB_PID_SETUP
  1529. #define USB_PID_NULL 0x00 /* reserved PID */
  1530. #define USB_PID_SOF 0x05
  1531. #define USB_PID_SETUP 0x0D
  1532. #define USB_PID_IN 0x09
  1533. #define USB_PID_OUT 0x01
  1534. #define USB_PID_ACK 0x02
  1535. #define USB_PID_NAK 0x0A
  1536. #define USB_PID_STALL 0x0E
  1537. #define USB_PID_DATA0 0x03
  1538. #define USB_PID_DATA1 0x0B
  1539. #define USB_PID_PRE 0x0C
  1540. #endif
  1541. /* USB standard device request code */
  1542. #ifndef USB_GET_DESCRIPTOR
  1543. #define USB_GET_STATUS 0x00
  1544. #define USB_CLEAR_FEATURE 0x01
  1545. #define USB_SET_FEATURE 0x03
  1546. #define USB_SET_ADDRESS 0x05
  1547. #define USB_GET_DESCRIPTOR 0x06
  1548. #define USB_SET_DESCRIPTOR 0x07
  1549. #define USB_GET_CONFIGURATION 0x08
  1550. #define USB_SET_CONFIGURATION 0x09
  1551. #define USB_GET_INTERFACE 0x0A
  1552. #define USB_SET_INTERFACE 0x0B
  1553. #define USB_SYNCH_FRAME 0x0C
  1554. #endif
  1555. /* USB hub class request code */
  1556. #ifndef HUB_GET_DESCRIPTOR
  1557. #define HUB_GET_STATUS 0x00
  1558. #define HUB_CLEAR_FEATURE 0x01
  1559. #define HUB_GET_STATE 0x02
  1560. #define HUB_SET_FEATURE 0x03
  1561. #define HUB_GET_DESCRIPTOR 0x06
  1562. #define HUB_SET_DESCRIPTOR 0x07
  1563. #endif
  1564. /* USB HID class request code */
  1565. #ifndef HID_GET_REPORT
  1566. #define HID_GET_REPORT 0x01
  1567. #define HID_GET_IDLE 0x02
  1568. #define HID_GET_PROTOCOL 0x03
  1569. #define HID_SET_REPORT 0x09
  1570. #define HID_SET_IDLE 0x0A
  1571. #define HID_SET_PROTOCOL 0x0B
  1572. #endif
  1573. /* Bit define for USB request type */
  1574. #ifndef USB_REQ_TYP_MASK
  1575. #define USB_REQ_TYP_IN 0x80 /* control IN, device to host */
  1576. #define USB_REQ_TYP_OUT 0x00 /* control OUT, host to device */
  1577. #define USB_REQ_TYP_READ 0x80 /* control read, device to host */
  1578. #define USB_REQ_TYP_WRITE 0x00 /* control write, host to device */
  1579. #define USB_REQ_TYP_MASK 0x60 /* bit mask of request type */
  1580. #define USB_REQ_TYP_STANDARD 0x00
  1581. #define USB_REQ_TYP_CLASS 0x20
  1582. #define USB_REQ_TYP_VENDOR 0x40
  1583. #define USB_REQ_TYP_RESERVED 0x60
  1584. #define USB_REQ_RECIP_MASK 0x1F /* bit mask of request recipient */
  1585. #define USB_REQ_RECIP_DEVICE 0x00
  1586. #define USB_REQ_RECIP_INTERF 0x01
  1587. #define USB_REQ_RECIP_ENDP 0x02
  1588. #define USB_REQ_RECIP_OTHER 0x03
  1589. #endif
  1590. /* USB request type for hub class request */
  1591. #ifndef HUB_GET_HUB_DESCRIPTOR
  1592. #define HUB_CLEAR_HUB_FEATURE 0x20
  1593. #define HUB_CLEAR_PORT_FEATURE 0x23
  1594. #define HUB_GET_BUS_STATE 0xA3
  1595. #define HUB_GET_HUB_DESCRIPTOR 0xA0
  1596. #define HUB_GET_HUB_STATUS 0xA0
  1597. #define HUB_GET_PORT_STATUS 0xA3
  1598. #define HUB_SET_HUB_DESCRIPTOR 0x20
  1599. #define HUB_SET_HUB_FEATURE 0x20
  1600. #define HUB_SET_PORT_FEATURE 0x23
  1601. #endif
  1602. /* Hub class feature selectors */
  1603. #ifndef HUB_PORT_RESET
  1604. #define HUB_C_HUB_LOCAL_POWER 0
  1605. #define HUB_C_HUB_OVER_CURRENT 1
  1606. #define HUB_PORT_CONNECTION 0
  1607. #define HUB_PORT_ENABLE 1
  1608. #define HUB_PORT_SUSPEND 2
  1609. #define HUB_PORT_OVER_CURRENT 3
  1610. #define HUB_PORT_RESET 4
  1611. #define HUB_PORT_POWER 8
  1612. #define HUB_PORT_LOW_SPEED 9
  1613. #define HUB_C_PORT_CONNECTION 16
  1614. #define HUB_C_PORT_ENABLE 17
  1615. #define HUB_C_PORT_SUSPEND 18
  1616. #define HUB_C_PORT_OVER_CURRENT 19
  1617. #define HUB_C_PORT_RESET 20
  1618. #endif
  1619. /* USB descriptor type */
  1620. #ifndef USB_DESCR_TYP_DEVICE
  1621. #define USB_DESCR_TYP_DEVICE 0x01
  1622. #define USB_DESCR_TYP_CONFIG 0x02
  1623. #define USB_DESCR_TYP_STRING 0x03
  1624. #define USB_DESCR_TYP_INTERF 0x04
  1625. #define USB_DESCR_TYP_ENDP 0x05
  1626. #define USB_DESCR_TYP_QUALIF 0x06
  1627. #define USB_DESCR_TYP_SPEED 0x07
  1628. #define USB_DESCR_TYP_OTG 0x09
  1629. #define USB_DESCR_TYP_HID 0x21
  1630. #define USB_DESCR_TYP_REPORT 0x22
  1631. #define USB_DESCR_TYP_PHYSIC 0x23
  1632. #define USB_DESCR_TYP_CS_INTF 0x24
  1633. #define USB_DESCR_TYP_CS_ENDP 0x25
  1634. #define USB_DESCR_TYP_HUB 0x29
  1635. #endif
  1636. /* USB device class */
  1637. #ifndef USB_DEV_CLASS_HUB
  1638. #define USB_DEV_CLASS_RESERVED 0x00
  1639. #define USB_DEV_CLASS_AUDIO 0x01
  1640. #define USB_DEV_CLASS_COMMUNIC 0x02
  1641. #define USB_DEV_CLASS_HID 0x03
  1642. #define USB_DEV_CLASS_MONITOR 0x04
  1643. #define USB_DEV_CLASS_PHYSIC_IF 0x05
  1644. #define USB_DEV_CLASS_POWER 0x06
  1645. #define USB_DEV_CLASS_PRINTER 0x07
  1646. #define USB_DEV_CLASS_STORAGE 0x08
  1647. #define USB_DEV_CLASS_HUB 0x09
  1648. #define USB_DEV_CLASS_VEN_SPEC 0xFF
  1649. #endif
  1650. /* USB endpoint type and attributes */
  1651. #ifndef USB_ENDP_TYPE_MASK
  1652. #define USB_ENDP_DIR_MASK 0x80
  1653. #define USB_ENDP_ADDR_MASK 0x0F
  1654. #define USB_ENDP_TYPE_MASK 0x03
  1655. #define USB_ENDP_TYPE_CTRL 0x00
  1656. #define USB_ENDP_TYPE_ISOCH 0x01
  1657. #define USB_ENDP_TYPE_BULK 0x02
  1658. #define USB_ENDP_TYPE_INTER 0x03
  1659. #endif
  1660. #ifndef USB_DEVICE_ADDR
  1661. #define USB_DEVICE_ADDR 0x02 /* 默认的USB设备地址 */
  1662. #endif
  1663. #ifndef DEFAULT_ENDP0_SIZE
  1664. #define DEFAULT_ENDP0_SIZE 8 /* default maximum packet size for endpoint 0 */
  1665. #endif
  1666. #ifndef MAX_PACKET_SIZE
  1667. #define MAX_PACKET_SIZE 64 /* maximum packet size */
  1668. #endif
  1669. #ifndef USB_BO_CBW_SIZE
  1670. #define USB_BO_CBW_SIZE 0x1F /* 命令块CBW的总长度 */
  1671. #define USB_BO_CSW_SIZE 0x0D /* 命令状态块CSW的总长度 */
  1672. #endif
  1673. #ifndef USB_BO_CBW_SIG
  1674. #define USB_BO_CBW_SIG 0x43425355 /* 命令块CBW识别标志'USBC' */
  1675. #define USB_BO_CSW_SIG 0x53425355 /* 命令状态块CSW识别标志'USBS' */
  1676. #endif
  1677. //#define __PACKED
  1678. #ifndef __PACKED
  1679. #define __PACKED __packed
  1680. #endif
  1681. __PACKED typedef struct _USB_SETUP_REQ {
  1682. UINT8 bRequestType;
  1683. UINT8 bRequest;
  1684. UINT16 wValue;
  1685. UINT16 wIndex;
  1686. UINT16 wLength;
  1687. } USB_SETUP_REQ, *PUSB_SETUP_REQ;
  1688. __PACKED typedef struct _USB_DEVICE_DESCR {
  1689. UINT8 bLength;
  1690. UINT8 bDescriptorType;
  1691. UINT16 bcdUSB;
  1692. UINT8 bDeviceClass;
  1693. UINT8 bDeviceSubClass;
  1694. UINT8 bDeviceProtocol;
  1695. UINT8 bMaxPacketSize0;
  1696. UINT16 idVendor;
  1697. UINT16 idProduct;
  1698. UINT16 bcdDevice;
  1699. UINT8 iManufacturer;
  1700. UINT8 iProduct;
  1701. UINT8 iSerialNumber;
  1702. UINT8 bNumConfigurations;
  1703. } USB_DEV_DESCR, *PUSB_DEV_DESCR;
  1704. __PACKED typedef struct _USB_CONFIG_DESCR {
  1705. UINT8 bLength;
  1706. UINT8 bDescriptorType;
  1707. UINT16 wTotalLength;
  1708. UINT8 bNumInterfaces;
  1709. UINT8 bConfigurationValue;
  1710. UINT8 iConfiguration;
  1711. UINT8 bmAttributes;
  1712. UINT8 MaxPower;
  1713. } USB_CFG_DESCR, *PUSB_CFG_DESCR;
  1714. __PACKED typedef struct _USB_INTERF_DESCR {
  1715. UINT8 bLength;
  1716. UINT8 bDescriptorType;
  1717. UINT8 bInterfaceNumber;
  1718. UINT8 bAlternateSetting;
  1719. UINT8 bNumEndpoints;
  1720. UINT8 bInterfaceClass;
  1721. UINT8 bInterfaceSubClass;
  1722. UINT8 bInterfaceProtocol;
  1723. UINT8 iInterface;
  1724. } USB_ITF_DESCR, *PUSB_ITF_DESCR;
  1725. __PACKED typedef struct _USB_ENDPOINT_DESCR {
  1726. UINT8 bLength;
  1727. UINT8 bDescriptorType;
  1728. UINT8 bEndpointAddress;
  1729. UINT8 bmAttributes;
  1730. UINT16 wMaxPacketSize;
  1731. UINT8 bInterval;
  1732. } USB_ENDP_DESCR, *PUSB_ENDP_DESCR;
  1733. __PACKED typedef struct _USB_CONFIG_DESCR_LONG {
  1734. USB_CFG_DESCR cfg_descr;
  1735. USB_ITF_DESCR itf_descr;
  1736. USB_ENDP_DESCR endp_descr[1];
  1737. } USB_CFG_DESCR_LONG, *PUSB_CFG_DESCR_LONG;
  1738. typedef USB_CFG_DESCR_LONG *PXUSB_CFG_DESCR_LONG;
  1739. __PACKED typedef struct _USB_HUB_DESCR {
  1740. UINT8 bDescLength;
  1741. UINT8 bDescriptorType;
  1742. UINT8 bNbrPorts;
  1743. UINT8 wHubCharacteristicsL;
  1744. UINT8 wHubCharacteristicsH;
  1745. UINT8 bPwrOn2PwrGood;
  1746. UINT8 bHubContrCurrent;
  1747. UINT8 DeviceRemovable;
  1748. UINT8 PortPwrCtrlMask;
  1749. } USB_HUB_DESCR, *PUSB_HUB_DESCR;
  1750. typedef USB_HUB_DESCR *PXUSB_HUB_DESCR;
  1751. __PACKED typedef struct _USB_HID_DESCR {
  1752. UINT8 bLength;
  1753. UINT8 bDescriptorType;
  1754. UINT16 bcdHID;
  1755. UINT8 bCountryCode;
  1756. UINT8 bNumDescriptors;
  1757. UINT8 bDescriptorTypeX;
  1758. UINT8 wDescriptorLengthL;
  1759. UINT8 wDescriptorLengthH;
  1760. } USB_HID_DESCR, *PUSB_HID_DESCR;
  1761. typedef USB_HID_DESCR *PXUSB_HID_DESCR;
  1762. __PACKED typedef struct _UDISK_BOC_CBW { /* command of BulkOnly USB-FlashDisk */
  1763. UINT32 mCBW_Sig;
  1764. UINT32 mCBW_Tag;
  1765. UINT32 mCBW_DataLen; /* uppest byte of data length, always is 0 */
  1766. UINT8 mCBW_Flag; /* transfer direction and etc. */
  1767. UINT8 mCBW_LUN;
  1768. UINT8 mCBW_CB_Len; /* length of command block */
  1769. UINT8 mCBW_CB_Buf[16]; /* command block buffer */
  1770. } UDISK_BOC_CBW, *PUDISK_BOC_CBW;
  1771. typedef UDISK_BOC_CBW *PXUDISK_BOC_CBW;
  1772. __PACKED typedef struct _UDISK_BOC_CSW { /* status of BulkOnly USB-FlashDisk */
  1773. UINT32 mCSW_Sig;
  1774. UINT32 mCSW_Tag;
  1775. UINT32 mCSW_Residue; /* return: remainder bytes */ /* uppest byte of remainder length, always is 0 */
  1776. UINT8 mCSW_Status; /* return: result status */
  1777. } UDISK_BOC_CSW, *PUDISK_BOC_CSW;
  1778. typedef UDISK_BOC_CSW *PXUDISK_BOC_CSW;
  1779. #ifdef __cplusplus
  1780. }
  1781. #endif
  1782. #endif // __USB_TYPE__