start_rvds.S 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. */
  9. ;/*****************************************************************************/
  10. ;/* LPC2400.S: Startup file for Philips LPC2400 device series */
  11. ;/*****************************************************************************/
  12. ;/* <<< Use Configuration Wizard in Context Menu >>> */
  13. ;/*****************************************************************************/
  14. ;/* This file is part of the uVision/ARM development tools. */
  15. ;/* Copyright (c) 2007-2008 Keil - An ARM Company. All rights reserved. */
  16. ;/* This software may only be used under the terms of a valid, current, */
  17. ;/* end user licence from KEIL for a compatible version of KEIL software */
  18. ;/* development tools. Nothing else gives you the right to use this software. */
  19. ;/*****************************************************************************/
  20. ;/*
  21. ; * The LPC2400.S code is executed after CPU Reset. This file may be
  22. ; * translated with the following SET symbols. In uVision these SET
  23. ; * symbols are entered under Options - ASM - Define.
  24. ; *
  25. ; * NO_CLOCK_SETUP: when set the startup code will not initialize Clock
  26. ; * (used mostly when clock is already initialized from script .ini
  27. ; * file).
  28. ; *
  29. ; * NO_EMC_SETUP: when set the startup code will not initialize
  30. ; * External Bus Controller.
  31. ; *
  32. ; * RAM_INTVEC: when set the startup code copies exception vectors
  33. ; * from on-chip Flash to on-chip RAM.
  34. ; *
  35. ; * REMAP: when set the startup code initializes the register MEMMAP
  36. ; * which overwrites the settings of the CPU configuration pins. The
  37. ; * startup and interrupt vectors are remapped from:
  38. ; * 0x00000000 default setting (not remapped)
  39. ; * 0x40000000 when RAM_MODE is used
  40. ; * 0x80000000 when EXTMEM_MODE is used
  41. ; *
  42. ; * EXTMEM_MODE: when set the device is configured for code execution
  43. ; * from external memory starting at address 0x80000000.
  44. ; *
  45. ; * RAM_MODE: when set the device is configured for code execution
  46. ; * from on-chip RAM starting at address 0x40000000.
  47. ; */
  48. ; Standard definitions of Mode bits and Interrupt (I & F) flags in PSRs
  49. Mode_USR EQU 0x10
  50. Mode_FIQ EQU 0x11
  51. Mode_IRQ EQU 0x12
  52. Mode_SVC EQU 0x13
  53. Mode_ABT EQU 0x17
  54. Mode_UND EQU 0x1B
  55. Mode_SYS EQU 0x1F
  56. I_Bit EQU 0x80 ; when I bit is set, IRQ is disabled
  57. F_Bit EQU 0x40 ; when F bit is set, FIQ is disabled
  58. ;----------------------- Memory Definitions ------------------------------------
  59. ; Internal Memory Base Addresses
  60. FLASH_BASE EQU 0x00000000
  61. RAM_BASE EQU 0x40000000
  62. EXTMEM_BASE EQU 0x80000000
  63. ; External Memory Base Addresses
  64. STA_MEM0_BASE EQU 0x80000000
  65. STA_MEM1_BASE EQU 0x81000000
  66. STA_MEM2_BASE EQU 0x82000000
  67. STA_MEM3_BASE EQU 0x83000000
  68. DYN_MEM0_BASE EQU 0xA0000000
  69. DYN_MEM1_BASE EQU 0xB0000000
  70. DYN_MEM2_BASE EQU 0xC0000000
  71. DYN_MEM3_BASE EQU 0xD0000000
  72. ;----------------------- Stack and Heap Definitions ----------------------------
  73. ;// <h> Stack Configuration (Stack Sizes in Bytes)
  74. ;// <o0> Undefined Mode <0x0-0xFFFFFFFF:8>
  75. ;// <o1> Supervisor Mode <0x0-0xFFFFFFFF:8>
  76. ;// <o2> Abort Mode <0x0-0xFFFFFFFF:8>
  77. ;// <o3> Fast Interrupt Mode <0x0-0xFFFFFFFF:8>
  78. ;// <o4> Interrupt Mode <0x0-0xFFFFFFFF:8>
  79. ;// <o5> User/System Mode <0x0-0xFFFFFFFF:8>
  80. ;// </h>
  81. UND_Stack_Size EQU 0x00000000
  82. SVC_Stack_Size EQU 0x00000100
  83. ABT_Stack_Size EQU 0x00000000
  84. FIQ_Stack_Size EQU 0x00000000
  85. IRQ_Stack_Size EQU 0x00000100
  86. USR_Stack_Size EQU 0x00000100
  87. ISR_Stack_Size EQU (UND_Stack_Size + SVC_Stack_Size + ABT_Stack_Size + \
  88. FIQ_Stack_Size + IRQ_Stack_Size)
  89. AREA STACK, NOINIT, READWRITE, ALIGN=3
  90. Stack_Mem SPACE USR_Stack_Size
  91. __initial_sp SPACE ISR_Stack_Size
  92. Stack_Top
  93. ;// <h> Heap Configuration
  94. ;// <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF>
  95. ;// </h>
  96. Heap_Size EQU 0x00000000
  97. AREA HEAP, NOINIT, READWRITE, ALIGN=3
  98. __heap_base
  99. Heap_Mem SPACE Heap_Size
  100. __heap_limit
  101. ;----------------------- Clock Definitions -------------------------------------
  102. ; System Control Block (SCB) Module Definitions
  103. SCB_BASE EQU 0xE01FC000 ; SCB Base Address
  104. PLLCON_OFS EQU 0x80 ; PLL Control Offset
  105. PLLCFG_OFS EQU 0x84 ; PLL Configuration Offset
  106. PLLSTAT_OFS EQU 0x88 ; PLL Status Offset
  107. PLLFEED_OFS EQU 0x8C ; PLL Feed Offset
  108. CCLKCFG_OFS EQU 0x104 ; CPU Clock Divider Reg Offset
  109. USBCLKCFG_OFS EQU 0x108 ; USB Clock Divider Reg Offset
  110. CLKSRCSEL_OFS EQU 0x10C ; Clock Source Sel Reg Offset
  111. SCS_OFS EQU 0x1A0 ; Sys Control and Status Reg Offset
  112. PCLKSEL0_OFS EQU 0x1A8 ; Periph Clock Sel Reg 0 Offset
  113. PCLKSEL1_OFS EQU 0x1AC ; Periph Clock Sel Reg 0 Offset
  114. PCON_OFS EQU 0x0C0 ; Power Mode Control Reg Offset
  115. PCONP_OFS EQU 0x0C4 ; Power Control for Periphs Reg Offset
  116. ; Constants
  117. OSCRANGE EQU (1<<4) ; Oscillator Range Select
  118. OSCEN EQU (1<<5) ; Main oscillator Enable
  119. OSCSTAT EQU (1<<6) ; Main Oscillator Status
  120. PLLCON_PLLE EQU (1<<0) ; PLL Enable
  121. PLLCON_PLLC EQU (1<<1) ; PLL Connect
  122. PLLSTAT_M EQU (0x7FFF<<0) ; PLL M Value
  123. PLLSTAT_N EQU (0xFF<<16) ; PLL N Value
  124. PLLSTAT_PLOCK EQU (1<<26) ; PLL Lock Status
  125. ;// <e> Clock Setup
  126. ;// <h> System Controls and Status Register (SYS)
  127. ;// <o1.4> OSCRANGE: Main Oscillator Range Select
  128. ;// <0=> 1 MHz to 20 MHz
  129. ;// <1=> 15 MHz to 24 MHz
  130. ;// <e1.5> OSCEN: Main Oscillator Enable
  131. ;// </e>
  132. ;// </h>
  133. ;//
  134. ;// <h> PLL Clock Source Select Register (CLKSRCSEL)
  135. ;// <o2.0..1> CLKSRC: PLL Clock Source Selection
  136. ;// <0=> Internal RC oscillator
  137. ;// <1=> Main oscillator
  138. ;// <2=> RTC oscillator
  139. ;// </h>
  140. ;//
  141. ;// <h> PLL Configuration Register (PLLCFG)
  142. ;// <i> PLL_clk = (2* M * PLL_clk_src) / N
  143. ;// <o3.0..14> MSEL: PLL Multiplier Selection
  144. ;// <1-32768><#-1>
  145. ;// <i> M Value
  146. ;// <o3.16..23> NSEL: PLL Divider Selection
  147. ;// <1-256><#-1>
  148. ;// <i> N Value
  149. ;// </h>
  150. ;//
  151. ;// <h> CPU Clock Configuration Register (CCLKCFG)
  152. ;// <o4.0..7> CCLKSEL: Divide Value for CPU Clock from PLL
  153. ;// <1-256><#-1>
  154. ;// </h>
  155. ;//
  156. ;// <h> USB Clock Configuration Register (USBCLKCFG)
  157. ;// <o5.0..3> USBSEL: Divide Value for USB Clock from PLL
  158. ;// <1-16><#-1>
  159. ;// </h>
  160. ;//
  161. ;// <h> Peripheral Clock Selection Register 0 (PCLKSEL0)
  162. ;// <o6.0..1> PCLK_WDT: Peripheral Clock Selection for WDT
  163. ;// <0=> Pclk = Cclk / 4
  164. ;// <1=> Pclk = Cclk
  165. ;// <2=> Pclk = Cclk / 2
  166. ;// <3=> Pclk = Cclk / 8
  167. ;// <o6.2..3> PCLK_TIMER0: Peripheral Clock Selection for TIMER0
  168. ;// <0=> Pclk = Cclk / 4
  169. ;// <1=> Pclk = Cclk
  170. ;// <2=> Pclk = Cclk / 2
  171. ;// <3=> Pclk = Cclk / 8
  172. ;// <o6.4..5> PCLK_TIMER1: Peripheral Clock Selection for TIMER1
  173. ;// <0=> Pclk = Cclk / 4
  174. ;// <1=> Pclk = Cclk
  175. ;// <2=> Pclk = Cclk / 2
  176. ;// <3=> Pclk = Cclk / 8
  177. ;// <o6.6..7> PCLK_UART0: Peripheral Clock Selection for UART0
  178. ;// <0=> Pclk = Cclk / 4
  179. ;// <1=> Pclk = Cclk
  180. ;// <2=> Pclk = Cclk / 2
  181. ;// <3=> Pclk = Cclk / 8
  182. ;// <o6.8..9> PCLK_UART1: Peripheral Clock Selection for UART1
  183. ;// <0=> Pclk = Cclk / 4
  184. ;// <1=> Pclk = Cclk
  185. ;// <2=> Pclk = Cclk / 2
  186. ;// <3=> Pclk = Cclk / 8
  187. ;// <o6.10..11> PCLK_PWM0: Peripheral Clock Selection for PWM0
  188. ;// <0=> Pclk = Cclk / 4
  189. ;// <1=> Pclk = Cclk
  190. ;// <2=> Pclk = Cclk / 2
  191. ;// <3=> Pclk = Cclk / 8
  192. ;// <o6.12..13> PCLK_PWM1: Peripheral Clock Selection for PWM1
  193. ;// <0=> Pclk = Cclk / 4
  194. ;// <1=> Pclk = Cclk
  195. ;// <2=> Pclk = Cclk / 2
  196. ;// <3=> Pclk = Cclk / 8
  197. ;// <o6.14..15> PCLK_I2C0: Peripheral Clock Selection for I2C0
  198. ;// <0=> Pclk = Cclk / 4
  199. ;// <1=> Pclk = Cclk
  200. ;// <2=> Pclk = Cclk / 2
  201. ;// <3=> Pclk = Cclk / 8
  202. ;// <o6.16..17> PCLK_SPI: Peripheral Clock Selection for SPI
  203. ;// <0=> Pclk = Cclk / 4
  204. ;// <1=> Pclk = Cclk
  205. ;// <2=> Pclk = Cclk / 2
  206. ;// <3=> Pclk = Cclk / 8
  207. ;// <o6.18..19> PCLK_RTC: Peripheral Clock Selection for RTC
  208. ;// <0=> Pclk = Cclk / 4
  209. ;// <1=> Pclk = Cclk
  210. ;// <2=> Pclk = Cclk / 2
  211. ;// <3=> Pclk = Cclk / 8
  212. ;// <o6.20..21> PCLK_SSP1: Peripheral Clock Selection for SSP1
  213. ;// <0=> Pclk = Cclk / 4
  214. ;// <1=> Pclk = Cclk
  215. ;// <2=> Pclk = Cclk / 2
  216. ;// <3=> Pclk = Cclk / 8
  217. ;// <o6.22..23> PCLK_DAC: Peripheral Clock Selection for DAC
  218. ;// <0=> Pclk = Cclk / 4
  219. ;// <1=> Pclk = Cclk
  220. ;// <2=> Pclk = Cclk / 2
  221. ;// <3=> Pclk = Cclk / 8
  222. ;// <o6.24..25> PCLK_ADC: Peripheral Clock Selection for ADC
  223. ;// <0=> Pclk = Cclk / 4
  224. ;// <1=> Pclk = Cclk
  225. ;// <2=> Pclk = Cclk / 2
  226. ;// <3=> Pclk = Cclk / 8
  227. ;// <o6.26..27> PCLK_CAN1: Peripheral Clock Selection for CAN1
  228. ;// <0=> Pclk = Cclk / 4
  229. ;// <1=> Pclk = Cclk
  230. ;// <2=> Pclk = Cclk / 2
  231. ;// <3=> Pclk = Cclk / 6
  232. ;// <o6.28..29> PCLK_CAN2: Peripheral Clock Selection for CAN2
  233. ;// <0=> Pclk = Cclk / 4
  234. ;// <1=> Pclk = Cclk
  235. ;// <2=> Pclk = Cclk / 2
  236. ;// <3=> Pclk = Cclk / 6
  237. ;// <o6.30..31> PCLK_ACF: Peripheral Clock Selection for ACF
  238. ;// <0=> Pclk = Cclk / 4
  239. ;// <1=> Pclk = Cclk
  240. ;// <2=> Pclk = Cclk / 2
  241. ;// <3=> Pclk = Cclk / 6
  242. ;// </h>
  243. ;//
  244. ;// <h> Peripheral Clock Selection Register 1 (PCLKSEL1)
  245. ;// <o7.0..1> PCLK_BAT_RAM: Peripheral Clock Selection for the Battery Supported RAM
  246. ;// <0=> Pclk = Cclk / 4
  247. ;// <1=> Pclk = Cclk
  248. ;// <2=> Pclk = Cclk / 2
  249. ;// <3=> Pclk = Cclk / 8
  250. ;// <o7.2..3> PCLK_GPIO: Peripheral Clock Selection for GPIOs
  251. ;// <0=> Pclk = Cclk / 4
  252. ;// <1=> Pclk = Cclk
  253. ;// <2=> Pclk = Cclk / 2
  254. ;// <3=> Pclk = Cclk / 8
  255. ;// <o7.4..5> PCLK_PCB: Peripheral Clock Selection for Pin Connect Block
  256. ;// <0=> Pclk = Cclk / 4
  257. ;// <1=> Pclk = Cclk
  258. ;// <2=> Pclk = Cclk / 2
  259. ;// <3=> Pclk = Cclk / 8
  260. ;// <o7.6..7> PCLK_I2C1: Peripheral Clock Selection for I2C1
  261. ;// <0=> Pclk = Cclk / 4
  262. ;// <1=> Pclk = Cclk
  263. ;// <2=> Pclk = Cclk / 2
  264. ;// <3=> Pclk = Cclk / 8
  265. ;// <o7.10..11> PCLK_SSP0: Peripheral Clock Selection for SSP0
  266. ;// <0=> Pclk = Cclk / 4
  267. ;// <1=> Pclk = Cclk
  268. ;// <2=> Pclk = Cclk / 2
  269. ;// <3=> Pclk = Cclk / 8
  270. ;// <o7.12..13> PCLK_TIMER2: Peripheral Clock Selection for TIMER2
  271. ;// <0=> Pclk = Cclk / 4
  272. ;// <1=> Pclk = Cclk
  273. ;// <2=> Pclk = Cclk / 2
  274. ;// <3=> Pclk = Cclk / 8
  275. ;// <o7.14..15> PCLK_TIMER3: Peripheral Clock Selection for TIMER3
  276. ;// <0=> Pclk = Cclk / 4
  277. ;// <1=> Pclk = Cclk
  278. ;// <2=> Pclk = Cclk / 2
  279. ;// <3=> Pclk = Cclk / 8
  280. ;// <o7.16..17> PCLK_UART2: Peripheral Clock Selection for UART2
  281. ;// <0=> Pclk = Cclk / 4
  282. ;// <1=> Pclk = Cclk
  283. ;// <2=> Pclk = Cclk / 2
  284. ;// <3=> Pclk = Cclk / 8
  285. ;// <o7.18..19> PCLK_UART3: Peripheral Clock Selection for UART3
  286. ;// <0=> Pclk = Cclk / 4
  287. ;// <1=> Pclk = Cclk
  288. ;// <2=> Pclk = Cclk / 2
  289. ;// <3=> Pclk = Cclk / 8
  290. ;// <o7.20..21> PCLK_I2C2: Peripheral Clock Selection for I2C2
  291. ;// <0=> Pclk = Cclk / 4
  292. ;// <1=> Pclk = Cclk
  293. ;// <2=> Pclk = Cclk / 2
  294. ;// <3=> Pclk = Cclk / 8
  295. ;// <o7.22..23> PCLK_I2S: Peripheral Clock Selection for I2S
  296. ;// <0=> Pclk = Cclk / 4
  297. ;// <1=> Pclk = Cclk
  298. ;// <2=> Pclk = Cclk / 2
  299. ;// <3=> Pclk = Cclk / 8
  300. ;// <o7.24..25> PCLK_MCI: Peripheral Clock Selection for MCI
  301. ;// <0=> Pclk = Cclk / 4
  302. ;// <1=> Pclk = Cclk
  303. ;// <2=> Pclk = Cclk / 2
  304. ;// <3=> Pclk = Cclk / 8
  305. ;// <o7.28..29> PCLK_SYSCON: Peripheral Clock Selection for System Control Block
  306. ;// <0=> Pclk = Cclk / 4
  307. ;// <1=> Pclk = Cclk
  308. ;// <2=> Pclk = Cclk / 2
  309. ;// <3=> Pclk = Cclk / 8
  310. ;// </h>
  311. ;// </e>
  312. CLOCK_SETUP EQU 1
  313. SCS_Val EQU 0x00000020
  314. CLKSRCSEL_Val EQU 0x00000001
  315. PLLCFG_Val EQU 0x0000000B
  316. CCLKCFG_Val EQU 0x00000004
  317. USBCLKCFG_Val EQU 0x00000005
  318. PCLKSEL0_Val EQU 0x00000000
  319. PCLKSEL1_Val EQU 0x00000000
  320. ;----------------------- Memory Accelerator Module (MAM) Definitions -----------
  321. MAM_BASE EQU 0xE01FC000 ; MAM Base Address
  322. MAMCR_OFS EQU 0x00 ; MAM Control Offset
  323. MAMTIM_OFS EQU 0x04 ; MAM Timing Offset
  324. ;// <e> MAM Setup
  325. ;// <o1.0..1> MAM Control
  326. ;// <0=> Disabled
  327. ;// <1=> Partially Enabled
  328. ;// <2=> Fully Enabled
  329. ;// <i> Mode
  330. ;// <o2.0..2> MAM Timing
  331. ;// <0=> Reserved <1=> 1 <2=> 2 <3=> 3
  332. ;// <4=> 4 <5=> 5 <6=> 6 <7=> 7
  333. ;// <i> Fetch Cycles
  334. ;// </e>
  335. MAM_SETUP EQU 1
  336. MAMCR_Val EQU 0x00000002
  337. MAMTIM_Val EQU 0x00000004
  338. ;----------------------- Pin Connect Block Definitions -------------------------
  339. PCB_BASE EQU 0xE002C000 ; PCB Base Address
  340. PINSEL0_OFS EQU 0x00 ; PINSEL0 Address Offset
  341. PINSEL1_OFS EQU 0x04 ; PINSEL1 Address Offset
  342. PINSEL2_OFS EQU 0x08 ; PINSEL2 Address Offset
  343. PINSEL3_OFS EQU 0x0C ; PINSEL3 Address Offset
  344. PINSEL4_OFS EQU 0x10 ; PINSEL4 Address Offset
  345. PINSEL5_OFS EQU 0x14 ; PINSEL5 Address Offset
  346. PINSEL6_OFS EQU 0x18 ; PINSEL6 Address Offset
  347. PINSEL7_OFS EQU 0x1C ; PINSEL7 Address Offset
  348. PINSEL8_OFS EQU 0x20 ; PINSEL8 Address Offset
  349. PINSEL9_OFS EQU 0x24 ; PINSEL9 Address Offset
  350. PINSEL10_OFS EQU 0x28 ; PINSEL10 Address Offset
  351. ;----------------------- External Memory Controller (EMC) Definitons -----------
  352. EMC_BASE EQU 0xFFE08000 ; EMC Base Address
  353. EMC_CTRL_OFS EQU 0x000
  354. EMC_STAT_OFS EQU 0x004
  355. EMC_CONFIG_OFS EQU 0x008
  356. EMC_DYN_CTRL_OFS EQU 0x020
  357. EMC_DYN_RFSH_OFS EQU 0x024
  358. EMC_DYN_RD_CFG_OFS EQU 0x028
  359. EMC_DYN_RP_OFS EQU 0x030
  360. EMC_DYN_RAS_OFS EQU 0x034
  361. EMC_DYN_SREX_OFS EQU 0x038
  362. EMC_DYN_APR_OFS EQU 0x03C
  363. EMC_DYN_DAL_OFS EQU 0x040
  364. EMC_DYN_WR_OFS EQU 0x044
  365. EMC_DYN_RC_OFS EQU 0x048
  366. EMC_DYN_RFC_OFS EQU 0x04C
  367. EMC_DYN_XSR_OFS EQU 0x050
  368. EMC_DYN_RRD_OFS EQU 0x054
  369. EMC_DYN_MRD_OFS EQU 0x058
  370. EMC_DYN_CFG0_OFS EQU 0x100
  371. EMC_DYN_RASCAS0_OFS EQU 0x104
  372. EMC_DYN_CFG1_OFS EQU 0x140
  373. EMC_DYN_RASCAS1_OFS EQU 0x144
  374. EMC_DYN_CFG2_OFS EQU 0x160
  375. EMC_DYN_RASCAS2_OFS EQU 0x164
  376. EMC_DYN_CFG3_OFS EQU 0x180
  377. EMC_DYN_RASCAS3_OFS EQU 0x184
  378. EMC_STA_CFG0_OFS EQU 0x200
  379. EMC_STA_WWEN0_OFS EQU 0x204
  380. EMC_STA_WOEN0_OFS EQU 0x208
  381. EMC_STA_WRD0_OFS EQU 0x20C
  382. EMC_STA_WPAGE0_OFS EQU 0x210
  383. EMC_STA_WWR0_OFS EQU 0x214
  384. EMC_STA_WTURN0_OFS EQU 0x218
  385. EMC_STA_CFG1_OFS EQU 0x220
  386. EMC_STA_WWEN1_OFS EQU 0x224
  387. EMC_STA_WOEN1_OFS EQU 0x228
  388. EMC_STA_WRD1_OFS EQU 0x22C
  389. EMC_STA_WPAGE1_OFS EQU 0x230
  390. EMC_STA_WWR1_OFS EQU 0x234
  391. EMC_STA_WTURN1_OFS EQU 0x238
  392. EMC_STA_CFG2_OFS EQU 0x240
  393. EMC_STA_WWEN2_OFS EQU 0x244
  394. EMC_STA_WOEN2_OFS EQU 0x248
  395. EMC_STA_WRD2_OFS EQU 0x24C
  396. EMC_STA_WPAGE2_OFS EQU 0x250
  397. EMC_STA_WWR2_OFS EQU 0x254
  398. EMC_STA_WTURN2_OFS EQU 0x258
  399. EMC_STA_CFG3_OFS EQU 0x260
  400. EMC_STA_WWEN3_OFS EQU 0x264
  401. EMC_STA_WOEN3_OFS EQU 0x268
  402. EMC_STA_WRD3_OFS EQU 0x26C
  403. EMC_STA_WPAGE3_OFS EQU 0x270
  404. EMC_STA_WWR3_OFS EQU 0x274
  405. EMC_STA_WTURN3_OFS EQU 0x278
  406. EMC_STA_EXT_W_OFS EQU 0x880
  407. ; Constants
  408. NORMAL_CMD EQU (0x0 << 7) ; NORMAL Command
  409. MODE_CMD EQU (0x1 << 7) ; MODE Command
  410. PALL_CMD EQU (0x2 << 7) ; Precharge All Command
  411. NOP_CMD EQU (0x3 << 7) ; NOP Command
  412. BUFEN_Const EQU (1 << 19) ; Buffer enable bit
  413. EMC_PCONP_Const EQU (1 << 11) ; PCONP val to enable power for EMC
  414. ; External Memory Pins definitions
  415. ; pin functions for SDRAM, NOR and NAND flash interfacing
  416. EMC_PINSEL5_Val EQU 0x05010115 ; !CAS, !RAS, CLKOUT0, !DYCS0, DQMOUT0, DQMOUT1
  417. EMC_PINSEL6_Val EQU 0x55555555 ; D0 .. D15
  418. EMC_PINSEL8_Val EQU 0x55555555 ; A0 .. A15
  419. EMC_PINSEL9_Val EQU 0x50055555; ; A16 .. A23, !OE, !WE, !CS0, !CS1
  420. ;// External Memory Controller Setup (EMC) ---------------------------------
  421. ;// <e> External Memory Controller Setup (EMC)
  422. EMC_SETUP EQU 0
  423. ;// <h> EMC Control Register (EMCControl)
  424. ;// <i> Controls operation of the memory controller
  425. ;// <o0.2> L: Low-power mode enable
  426. ;// <o0.1> M: Address mirror enable
  427. ;// <o0.0> E: EMC enable
  428. ;// </h>
  429. EMC_CTRL_Val EQU 0x00000001
  430. ;// <h> EMC Configuration Register (EMCConfig)
  431. ;// <i> Configures operation of the memory controller
  432. ;// <o0.8> CCLK: CLKOUT ratio
  433. ;// <0=> 1:1
  434. ;// <1=> 1:2
  435. ;// <o0.0> Endian mode
  436. ;// <0=> Little-endian
  437. ;// <1=> Big-endian
  438. ;// </h>
  439. EMC_CONFIG_Val EQU 0x00000000
  440. ;// Dynamic Memory Interface Setup ---------------------------------------
  441. ;// <e> Dynamic Memory Interface Setup
  442. EMC_DYNAMIC_SETUP EQU 1
  443. ;// <h> Dynamic Memory Refresh Timer Register (EMCDynamicRefresh)
  444. ;// <i> Configures dynamic memory refresh operation
  445. ;// <o0.0..10> REFRESH: Refresh timer <0x000-0x7FF>
  446. ;// <i> 0 = refresh disabled, 0x01-0x7FF: value * 16 CCLKS
  447. ;// </h>
  448. EMC_DYN_RFSH_Val EQU 0x0000001C
  449. ;// <h> Dynamic Memory Read Configuration Register (EMCDynamicReadConfig)
  450. ;// <i> Configures the dynamic memory read strategy
  451. ;// <o0.0..1> RD: Read data strategy
  452. ;// <0=> Clock out delayed strategy
  453. ;// <1=> Command delayed strategy
  454. ;// <2=> Command delayed strategy plus one clock cycle
  455. ;// <3=> Command delayed strategy plus two clock cycles
  456. ;// </h>
  457. EMC_DYN_RD_CFG_Val EQU 0x00000001
  458. ;// <h> Dynamic Memory Timings
  459. ;// <h> Dynamic Memory Percentage Command Period Register (EMCDynamictRP)
  460. ;// <o0.0..3> tRP: Precharge command period <1-16> <#-1>
  461. ;// <i> The delay is in EMCCLK cycles
  462. ;// <i> This value is normally found in SDRAM data sheets as tRP
  463. ;// </h>
  464. ;// <h> Dynamic Memory Active to Precharge Command Period Register (EMCDynamictRAS)
  465. ;// <o1.0..3> tRAS: Active to precharge command period <1-16> <#-1>
  466. ;// <i> The delay is in EMCCLK cycles
  467. ;// <i> This value is normally found in SDRAM data sheets as tRAS
  468. ;// </h>
  469. ;// <h> Dynamic Memory Self-refresh Exit Time Register (EMCDynamictSREX)
  470. ;// <o2.0..3> tSREX: Self-refresh exit time <1-16> <#-1>
  471. ;// <i> The delay is in CCLK cycles
  472. ;// <i> This value is normally found in SDRAM data sheets as tSREX,
  473. ;// <i> for devices without this parameter you use the same value as tXSR
  474. ;// </h>
  475. ;// <h> Dynamic Memory Last Data Out to Active Time Register (EMCDynamictAPR)
  476. ;// <o3.0..3> tAPR: Last-data-out to active command time <1-16> <#-1>
  477. ;// <i> The delay is in CCLK cycles
  478. ;// <i> This value is normally found in SDRAM data sheets as tAPR
  479. ;// </h>
  480. ;// <h> Dynamic Memory Data-in to Active Command Time Register (EMCDynamictDAL)
  481. ;// <o4.0..3> tDAL: Data-in to active command time <1-16> <#-1>
  482. ;// <i> The delay is in CCLK cycles
  483. ;// <i> This value is normally found in SDRAM data sheets as tDAL or tAPW
  484. ;// </h>
  485. ;// <h> Dynamic Memory Write Recovery Time Register (EMCDynamictWR)
  486. ;// <o5.0..3> tWR: Write recovery time <1-16> <#-1>
  487. ;// <i> The delay is in CCLK cycles
  488. ;// <i> This value is normally found in SDRAM data sheets as tWR, tDPL, tRWL, or tRDL
  489. ;// </h>
  490. ;// <h> Dynamic Memory Active to Active Command Period Register (EMCDynamictRC)
  491. ;// <o6.0..4> tRC: Active to active command period <1-32> <#-1>
  492. ;// <i> The delay is in CCLK cycles
  493. ;// <i> This value is normally found in SDRAM data sheets as tRC
  494. ;// </h>
  495. ;// <h> Dynamic Memory Auto-refresh Period Register (EMCDynamictRFC)
  496. ;// <o7.0..4> tRFC: Auto-refresh period and auto-refresh to active command period <1-32> <#-1>
  497. ;// <i> The delay is in CCLK cycles
  498. ;// <i> This value is normally found in SDRAM data sheets as tRFC or tRC
  499. ;// </h>
  500. ;// <h> Dynamic Memory Exit Self-refresh Register (EMCDynamictXSR)
  501. ;// <o8.0..4> tXSR: Exit self-refresh to active command time <1-32> <#-1>
  502. ;// <i> The delay is in CCLK cycles
  503. ;// <i> This value is normally found in SDRAM data sheets as tXSR
  504. ;// </h>
  505. ;// <h> Dynamic Memory Active Bank A to Active Bank B Time Register (EMCDynamicRRD)
  506. ;// <o9.0..3> tRRD: Active bank A to active bank B latency <1-16> <#-1>
  507. ;// <i> The delay is in CCLK cycles
  508. ;// <i> This value is normally found in SDRAM data sheets as tRRD
  509. ;// </h>
  510. ;// <h> Dynamic Memory Load Mode Register to Active Command Time (EMCDynamictMRD)
  511. ;// <o10.0..3> tMRD: Load mode register to active command time <1-16> <#-1>
  512. ;// <i> The delay is in CCLK cycles
  513. ;// <i> This value is normally found in SDRAM data sheets as tMRD or tRSA
  514. ;// </h>
  515. ;// </h>
  516. EMC_DYN_RP_Val EQU 0x00000002
  517. EMC_DYN_RAS_Val EQU 0x00000003
  518. EMC_DYN_SREX_Val EQU 0x00000007
  519. EMC_DYN_APR_Val EQU 0x00000002
  520. EMC_DYN_DAL_Val EQU 0x00000005
  521. EMC_DYN_WR_Val EQU 0x00000001
  522. EMC_DYN_RC_Val EQU 0x00000005
  523. EMC_DYN_RFC_Val EQU 0x00000005
  524. EMC_DYN_XSR_Val EQU 0x00000007
  525. EMC_DYN_RRD_Val EQU 0x00000001
  526. EMC_DYN_MRD_Val EQU 0x00000002
  527. ;// <e> Configure External Bus Behaviour for Dynamic CS0 Area
  528. EMC_DYNCS0_SETUP EQU 1
  529. ;// <h> Dynamic Memory Configuration Register (EMCDynamicConfig0)
  530. ;// <i> Defines the configuration information for the dynamic memory CS0
  531. ;// <o0.20> P: Write protect
  532. ;// <o0.19> B: Buffer enable
  533. ;// <o0.14> AM 14: External bus data width
  534. ;// <0=> 16 bit
  535. ;// <1=> 32 bit
  536. ;// <o0.12> AM 12: External bus memory type
  537. ;// <0=> High-performance
  538. ;// <1=> Low-power SDRAM
  539. ;// <o0.7..11> AM 11..7: External bus address mapping (Row, Bank, Column)
  540. ;// <0x00=> 16 Mb = 2MB (2Mx8), 2 banks, row length = 11, column length = 9
  541. ;// <0x01=> 16 Mb = 2MB (1Mx16), 2 banks, row length = 11, column length = 8
  542. ;// <0x04=> 64 Mb = 8MB (8Mx8), 4 banks, row length = 12, column length = 9
  543. ;// <0x05=> 64 Mb = 8MB (4Mx16), 4 banks, row length = 12, column length = 8
  544. ;// <0x08=> 128 Mb = 16MB (16Mx8), 4 banks, row length = 12, column length = 10
  545. ;// <0x09=> 128 Mb = 16MB (8Mx16), 4 banks, row length = 12, column length = 9
  546. ;// <0x0C=> 256 Mb = 32MB (32Mx8), 4 banks, row length = 13, column length = 10
  547. ;// <0x0D=> 256 Mb = 32MB (16Mx16), 4 banks, row length = 13, column length = 9
  548. ;// <0x10=> 512 Mb = 64MB (64Mx8), 4 banks, row length = 13, column length = 11
  549. ;// <0x11=> 512 Mb = 64MB (32Mx16), 4 banks, row length = 13, column length = 10
  550. ;// <o0.3..4> MD: Memory device
  551. ;// <0=> SDRAM
  552. ;// <1=> Low-power SDRAM
  553. ;// <2=> Micron SyncFlash
  554. ;// </h>
  555. EMC_DYN_CFG0_Val EQU 0x00080680
  556. ;// <h> Dynamic Memory RAS & CAS Delay register (EMCDynamicRASCAS0)
  557. ;// <i> Controls the RAS and CAS latencies for the dynamic memory CS0
  558. ;// <o0.8..9> CAS: CAS latency
  559. ;// <1=> One CCLK cycle
  560. ;// <2=> Two CCLK cycles
  561. ;// <3=> Three CCLK cycles
  562. ;// <o0.0..1> RAS: RAS latency (active to read/write delay)
  563. ;// <1=> One CCLK cycle
  564. ;// <2=> Two CCLK cycles
  565. ;// <3=> Three CCLK cycles
  566. ;// </h>
  567. EMC_DYN_RASCAS0_Val EQU 0x00000303
  568. ;// </e> End of Dynamic Setup for CS0 Area
  569. ;// <e> Configure External Bus Behaviour for Dynamic CS1 Area
  570. EMC_DYNCS1_SETUP EQU 0
  571. ;// <h> Dynamic Memory Configuration Register (EMCDynamicConfig1)
  572. ;// <i> Defines the configuration information for the dynamic memory CS1
  573. ;// <o0.20> P: Write protect
  574. ;// <o0.19> B: Buffer enable
  575. ;// <o0.14> AM 14: External bus data width
  576. ;// <0=> 16 bit
  577. ;// <1=> 32 bit
  578. ;// <o0.12> AM 12: External bus memory type
  579. ;// <0=> High-performance
  580. ;// <1=> Low-power SDRAM
  581. ;// <o0.7..11> AM 11..7: External bus address mapping (Row, Bank, Column)
  582. ;// <0x00=> 16 Mb = 2MB (2Mx8), 2 banks, row length = 11, column length = 9
  583. ;// <0x01=> 16 Mb = 2MB (1Mx16), 2 banks, row length = 11, column length = 8
  584. ;// <0x04=> 64 Mb = 8MB (8Mx8), 4 banks, row length = 12, column length = 9
  585. ;// <0x05=> 64 Mb = 8MB (4Mx16), 4 banks, row length = 12, column length = 8
  586. ;// <0x08=> 128 Mb = 16MB (16Mx8), 4 banks, row length = 12, column length = 10
  587. ;// <0x09=> 128 Mb = 16MB (8Mx16), 4 banks, row length = 12, column length = 9
  588. ;// <0x0C=> 256 Mb = 32MB (32Mx8), 4 banks, row length = 13, column length = 10
  589. ;// <0x0D=> 256 Mb = 32MB (16Mx16), 4 banks, row length = 13, column length = 9
  590. ;// <0x10=> 512 Mb = 64MB (64Mx8), 4 banks, row length = 13, column length = 11
  591. ;// <0x11=> 512 Mb = 64MB (32Mx16), 4 banks, row length = 13, column length = 10
  592. ;// <o0.3..4> MD: Memory device
  593. ;// <0=> SDRAM
  594. ;// <1=> Low-power SDRAM
  595. ;// <2=> Micron SyncFlash
  596. ;// </h>
  597. EMC_DYN_CFG1_Val EQU 0x00000000
  598. ;// <h> Dynamic Memory RAS & CAS Delay register (EMCDynamicRASCAS1)
  599. ;// <i> Controls the RAS and CAS latencies for the dynamic memory CS1
  600. ;// <o0.8..9> CAS: CAS latency
  601. ;// <1=> One CCLK cycle
  602. ;// <2=> Two CCLK cycles
  603. ;// <3=> Three CCLK cycles
  604. ;// <o0.0..1> RAS: RAS latency (active to read/write delay)
  605. ;// <1=> One CCLK cycle
  606. ;// <2=> Two CCLK cycles
  607. ;// <3=> Three CCLK cycles
  608. ;// </h>
  609. EMC_DYN_RASCAS1_Val EQU 0x00000303
  610. ;// </e> End of Dynamic Setup for CS1 Area
  611. ;// <e> Configure External Bus Behaviour for Dynamic CS2 Area
  612. EMC_DYNCS2_SETUP EQU 0
  613. ;// <h> Dynamic Memory Configuration Register (EMCDynamicConfig2)
  614. ;// <i> Defines the configuration information for the dynamic memory CS2
  615. ;// <o0.20> P: Write protect
  616. ;// <o0.19> B: Buffer enable
  617. ;// <o0.14> AM 14: External bus data width
  618. ;// <0=> 16 bit
  619. ;// <1=> 32 bit
  620. ;// <o0.12> AM 12: External bus memory type
  621. ;// <0=> High-performance
  622. ;// <1=> Low-power SDRAM
  623. ;// <o0.7..11> AM 11..7: External bus address mapping (Row, Bank, Column)
  624. ;// <0x00=> 16 Mb = 2MB (2Mx8), 2 banks, row length = 11, column length = 9
  625. ;// <0x01=> 16 Mb = 2MB (1Mx16), 2 banks, row length = 11, column length = 8
  626. ;// <0x04=> 64 Mb = 8MB (8Mx8), 4 banks, row length = 12, column length = 9
  627. ;// <0x05=> 64 Mb = 8MB (4Mx16), 4 banks, row length = 12, column length = 8
  628. ;// <0x08=> 128 Mb = 16MB (16Mx8), 4 banks, row length = 12, column length = 10
  629. ;// <0x09=> 128 Mb = 16MB (8Mx16), 4 banks, row length = 12, column length = 9
  630. ;// <0x0C=> 256 Mb = 32MB (32Mx8), 4 banks, row length = 13, column length = 10
  631. ;// <0x0D=> 256 Mb = 32MB (16Mx16), 4 banks, row length = 13, column length = 9
  632. ;// <0x10=> 512 Mb = 64MB (64Mx8), 4 banks, row length = 13, column length = 11
  633. ;// <0x11=> 512 Mb = 64MB (32Mx16), 4 banks, row length = 13, column length = 10
  634. ;// <o0.3..4> MD: Memory device
  635. ;// <0=> SDRAM
  636. ;// <1=> Low-power SDRAM
  637. ;// <2=> Micron SyncFlash
  638. ;// </h>
  639. EMC_DYN_CFG2_Val EQU 0x00000000
  640. ;// <h> Dynamic Memory RAS & CAS Delay register (EMCDynamicRASCAS2)
  641. ;// <i> Controls the RAS and CAS latencies for the dynamic memory CS2
  642. ;// <o0.8..9> CAS: CAS latency
  643. ;// <1=> One CCLK cycle
  644. ;// <2=> Two CCLK cycles
  645. ;// <3=> Three CCLK cycles
  646. ;// <o0.0..1> RAS: RAS latency (active to read/write delay)
  647. ;// <1=> One CCLK cycle
  648. ;// <2=> Two CCLK cycles
  649. ;// <3=> Three CCLK cycles
  650. ;// </h>
  651. EMC_DYN_RASCAS2_Val EQU 0x00000303
  652. ;// </e> End of Dynamic Setup for CS2 Area
  653. ;// <e> Configure External Bus Behaviour for Dynamic CS3 Area
  654. EMC_DYNCS3_SETUP EQU 0
  655. ;// <h> Dynamic Memory Configuration Register (EMCDynamicConfig3)
  656. ;// <i> Defines the configuration information for the dynamic memory CS3
  657. ;// <o0.20> P: Write protect
  658. ;// <o0.19> B: Buffer enable
  659. ;// <o0.14> AM 14: External bus data width
  660. ;// <0=> 16 bit
  661. ;// <1=> 32 bit
  662. ;// <o0.12> AM 12: External bus memory type
  663. ;// <0=> High-performance
  664. ;// <1=> Low-power SDRAM
  665. ;// <o0.7..11> AM 11..7: External bus address mapping (Row, Bank, Column)
  666. ;// <0x00=> 16 Mb = 2MB (2Mx8), 2 banks, row length = 11, column length = 9
  667. ;// <0x01=> 16 Mb = 2MB (1Mx16), 2 banks, row length = 11, column length = 8
  668. ;// <0x04=> 64 Mb = 8MB (8Mx8), 4 banks, row length = 12, column length = 9
  669. ;// <0x05=> 64 Mb = 8MB (4Mx16), 4 banks, row length = 12, column length = 8
  670. ;// <0x08=> 128 Mb = 16MB (16Mx8), 4 banks, row length = 12, column length = 10
  671. ;// <0x09=> 128 Mb = 16MB (8Mx16), 4 banks, row length = 12, column length = 9
  672. ;// <0x0C=> 256 Mb = 32MB (32Mx8), 4 banks, row length = 13, column length = 10
  673. ;// <0x0D=> 256 Mb = 32MB (16Mx16), 4 banks, row length = 13, column length = 9
  674. ;// <0x10=> 512 Mb = 64MB (64Mx8), 4 banks, row length = 13, column length = 11
  675. ;// <0x11=> 512 Mb = 64MB (32Mx16), 4 banks, row length = 13, column length = 10
  676. ;// <o0.3..4> MD: Memory device
  677. ;// <0=> SDRAM
  678. ;// <1=> Low-power SDRAM
  679. ;// <2=> Micron SyncFlash
  680. ;// </h>
  681. EMC_DYN_CFG3_Val EQU 0x00000000
  682. ;// <h> Dynamic Memory RAS & CAS Delay register (EMCDynamicRASCAS3)
  683. ;// <i> Controls the RAS and CAS latencies for the dynamic memory CS3
  684. ;// <o0.8..9> CAS: CAS latency
  685. ;// <1=> One CCLK cycle
  686. ;// <2=> Two CCLK cycles
  687. ;// <3=> Three CCLK cycles
  688. ;// <o0.0..1> RAS: RAS latency (active to read/write delay)
  689. ;// <1=> One CCLK cycle
  690. ;// <2=> Two CCLK cycles
  691. ;// <3=> Three CCLK cycles
  692. ;// </h>
  693. EMC_DYN_RASCAS3_Val EQU 0x00000303
  694. ;// </e> End of Dynamic Setup for CS3 Area
  695. ;// </e> End of Dynamic Setup
  696. ;// Static Memory Interface Setup ----------------------------------------
  697. ;// <e> Static Memory Interface Setup
  698. EMC_STATIC_SETUP EQU 1
  699. ;// Configure External Bus Behaviour for Static CS0 Area ---------------
  700. ;// <e> Configure External Bus Behaviour for Static CS0 Area
  701. EMC_STACS0_SETUP EQU 1
  702. ;// <h> Static Memory Configuration Register (EMCStaticConfig0)
  703. ;// <i> Defines the configuration information for the static memory CS0
  704. ;// <o0.20> WP: Write protect
  705. ;// <o0.19> B: Buffer enable
  706. ;// <o0.8> EW: Extended wait enable
  707. ;// <o0.7> PB: Byte lane state
  708. ;// <0=> For reads BLSn are HIGH, for writes BLSn are LOW
  709. ;// <1=> For reads BLSn are LOW, for writes BLSn are LOW
  710. ;// <o0.6> PC: Chip select polarity
  711. ;// <0=> Active LOW chip select
  712. ;// <1=> Active HIGH chip select
  713. ;// <o0.3> PM: Page mode enable
  714. ;// <o0.0..1> MW: Memory width
  715. ;// <0=> 8 bit
  716. ;// <1=> 16 bit
  717. ;// <2=> 32 bit
  718. ;// </h>
  719. EMC_STA_CFG0_Val EQU 0x00000081
  720. ;// <h> Static Memory Write Enable Delay Register (EMCStaticWaitWen0)
  721. ;// <i> Selects the delay from CS0 to write enable
  722. ;// <o.0..3> WAITWEN: Wait write enable <1-16> <#-1>
  723. ;// <i> The delay is in CCLK cycles
  724. ;// </h>
  725. EMC_STA_WWEN0_Val EQU 0x00000002
  726. ;// <h> Static Memory Output Enable Delay register (EMCStaticWaitOen0)
  727. ;// <i> Selects the delay from CS0 or address change, whichever is later, to output enable
  728. ;// <o.0..3> WAITOEN: Wait output enable <0-15>
  729. ;// <i> The delay is in CCLK cycles
  730. ;// </h>
  731. EMC_STA_WOEN0_Val EQU 0x00000002
  732. ;// <h> Static Memory Read Delay Register (EMCStaticWaitRd0)
  733. ;// <i> Selects the delay from CS0 to a read access
  734. ;// <o.0..4> WAITRD: Non-page mode read wait states or asynchronous page mode read first access wait states <1-32> <#-1>
  735. ;// <i> The delay is in CCLK cycles
  736. ;// </h>
  737. EMC_STA_WRD0_Val EQU 0x0000001F
  738. ;// <h> Static Memory Page Mode Read Delay Register (EMCStaticWaitPage0)
  739. ;// <i> Selects the delay for asynchronous page mode sequential accesses for CS0
  740. ;// <o.0..4> WAITPAGE: Asynchronous page mode read after the first read wait states <1-32> <#-1>
  741. ;// <i> The delay is in CCLK cycles
  742. ;// </h>
  743. EMC_STA_WPAGE0_Val EQU 0x0000001F
  744. ;// <h> Static Memory Write Delay Register (EMCStaticWaitWr0)
  745. ;// <i> Selects the delay from CS0 to a write access
  746. ;// <o.0..4> WAITWR: Write wait states <2-33> <#-2>
  747. ;// <i> The delay is in CCLK cycles
  748. ;// </h>
  749. EMC_STA_WWR0_Val EQU 0x0000001F
  750. ;// <h> Static Memory Turn Round Delay Register (EMCStaticWaitTurn0)
  751. ;// <i> Selects the number of bus turnaround cycles for CS0
  752. ;// <o.0..4> WAITTURN: Bus turnaround cycles <1-16> <#-1>
  753. ;// <i> The delay is in CCLK cycles
  754. ;// </h>
  755. EMC_STA_WTURN0_Val EQU 0x0000000F
  756. ;// </e> End of Static Setup for Static CS0 Area
  757. ;// Configure External Bus Behaviour for Static CS1 Area ---------------
  758. ;// <e> Configure External Bus Behaviour for Static CS1 Area
  759. EMC_STACS1_SETUP EQU 0
  760. ;// <h> Static Memory Configuration Register (EMCStaticConfig1)
  761. ;// <i> Defines the configuration information for the static memory CS1
  762. ;// <o0.20> WP: Write protect
  763. ;// <o0.19> B: Buffer enable
  764. ;// <o0.8> EW: Extended wait enable
  765. ;// <o0.7> PB: Byte lane state
  766. ;// <0=> For reads BLSn are HIGH, for writes BLSn are LOW
  767. ;// <1=> For reads BLSn are LOW, for writes BLSn are LOW
  768. ;// <o0.6> PC: Chip select polarity
  769. ;// <0=> Active LOW chip select
  770. ;// <1=> Active HIGH chip select
  771. ;// <o0.3> PM: Page mode enable
  772. ;// <o0.0..1> MW: Memory width
  773. ;// <0=> 8 bit
  774. ;// <1=> 16 bit
  775. ;// <2=> 32 bit
  776. ;// </h>
  777. EMC_STA_CFG1_Val EQU 0x00000000
  778. ;// <h> Static Memory Write Enable Delay Register (EMCStaticWaitWen1)
  779. ;// <i> Selects the delay from CS1 to write enable
  780. ;// <o.0..3> WAITWEN: Wait write enable <1-16> <#-1>
  781. ;// <i> The delay is in CCLK cycles
  782. ;// </h>
  783. EMC_STA_WWEN1_Val EQU 0x00000000
  784. ;// <h> Static Memory Output Enable Delay register (EMCStaticWaitOen1)
  785. ;// <i> Selects the delay from CS1 or address change, whichever is later, to output enable
  786. ;// <o.0..3> WAITOEN: Wait output enable <0-15>
  787. ;// <i> The delay is in CCLK cycles
  788. ;// </h>
  789. EMC_STA_WOEN1_Val EQU 0x00000000
  790. ;// <h> Static Memory Read Delay Register (EMCStaticWaitRd1)
  791. ;// <i> Selects the delay from CS1 to a read access
  792. ;// <o.0..4> WAITRD: Non-page mode read wait states or asynchronous page mode read first access wait states <1-32> <#-1>
  793. ;// <i> The delay is in CCLK cycles
  794. ;// </h>
  795. EMC_STA_WRD1_Val EQU 0x0000001F
  796. ;// <h> Static Memory Page Mode Read Delay Register (EMCStaticWaitPage0)
  797. ;// <i> Selects the delay for asynchronous page mode sequential accesses for CS1
  798. ;// <o.0..4> WAITPAGE: Asynchronous page mode read after the first read wait states <1-32> <#-1>
  799. ;// <i> The delay is in CCLK cycles
  800. ;// </h>
  801. EMC_STA_WPAGE1_Val EQU 0x0000001F
  802. ;// <h> Static Memory Write Delay Register (EMCStaticWaitWr1)
  803. ;// <i> Selects the delay from CS1 to a write access
  804. ;// <o.0..4> WAITWR: Write wait states <2-33> <#-2>
  805. ;// <i> The delay is in CCLK cycles
  806. ;// </h>
  807. EMC_STA_WWR1_Val EQU 0x0000001F
  808. ;// <h> Static Memory Turn Round Delay Register (EMCStaticWaitTurn1)
  809. ;// <i> Selects the number of bus turnaround cycles for CS1
  810. ;// <o.0..4> WAITTURN: Bus turnaround cycles <1-16> <#-1>
  811. ;// <i> The delay is in CCLK cycles
  812. ;// </h>
  813. EMC_STA_WTURN1_Val EQU 0x0000000F
  814. ;// </e> End of Static Setup for Static CS1 Area
  815. ;// Configure External Bus Behaviour for Static CS2 Area ---------------
  816. ;// <e> Configure External Bus Behaviour for Static CS2 Area
  817. EMC_STACS2_SETUP EQU 0
  818. ;// <h> Static Memory Configuration Register (EMCStaticConfig2)
  819. ;// <i> Defines the configuration information for the static memory CS2
  820. ;// <o0.20> WP: Write protect
  821. ;// <o0.19> B: Buffer enable
  822. ;// <o0.8> EW: Extended wait enable
  823. ;// <o0.7> PB: Byte lane state
  824. ;// <0=> For reads BLSn are HIGH, for writes BLSn are LOW
  825. ;// <1=> For reads BLSn are LOW, for writes BLSn are LOW
  826. ;// <o0.6> PC: Chip select polarity
  827. ;// <0=> Active LOW chip select
  828. ;// <1=> Active HIGH chip select
  829. ;// <o0.3> PM: Page mode enable
  830. ;// <o0.0..1> MW: Memory width
  831. ;// <0=> 8 bit
  832. ;// <1=> 16 bit
  833. ;// <2=> 32 bit
  834. ;// </h>
  835. EMC_STA_CFG2_Val EQU 0x00000000
  836. ;// <h> Static Memory Write Enable Delay Register (EMCStaticWaitWen2)
  837. ;// <i> Selects the delay from CS2 to write enable
  838. ;// <o.0..3> WAITWEN: Wait write enable <1-16> <#-1>
  839. ;// <i> The delay is in CCLK cycles
  840. ;// </h>
  841. EMC_STA_WWEN2_Val EQU 0x00000000
  842. ;// <h> Static Memory Output Enable Delay register (EMCStaticWaitOen2)
  843. ;// <i> Selects the delay from CS2 or address change, whichever is later, to output enable
  844. ;// <o.0..3> WAITOEN: Wait output enable <0-15>
  845. ;// <i> The delay is in CCLK cycles
  846. ;// </h>
  847. EMC_STA_WOEN2_Val EQU 0x00000000
  848. ;// <h> Static Memory Read Delay Register (EMCStaticWaitRd2)
  849. ;// <i> Selects the delay from CS2 to a read access
  850. ;// <o.0..4> WAITRD: Non-page mode read wait states or asynchronous page mode read first access wait states <1-32> <#-1>
  851. ;// <i> The delay is in CCLK cycles
  852. ;// </h>
  853. EMC_STA_WRD2_Val EQU 0x0000001F
  854. ;// <h> Static Memory Page Mode Read Delay Register (EMCStaticWaitPage2)
  855. ;// <i> Selects the delay for asynchronous page mode sequential accesses for CS2
  856. ;// <o.0..4> WAITPAGE: Asynchronous page mode read after the first read wait states <1-32> <#-1>
  857. ;// <i> The delay is in CCLK cycles
  858. ;// </h>
  859. EMC_STA_WPAGE2_Val EQU 0x0000001F
  860. ;// <h> Static Memory Write Delay Register (EMCStaticWaitWr2)
  861. ;// <i> Selects the delay from CS2 to a write access
  862. ;// <o.0..4> WAITWR: Write wait states <2-33> <#-2>
  863. ;// <i> The delay is in CCLK cycles
  864. ;// </h>
  865. EMC_STA_WWR2_Val EQU 0x0000001F
  866. ;// <h> Static Memory Turn Round Delay Register (EMCStaticWaitTurn2)
  867. ;// <i> Selects the number of bus turnaround cycles for CS2
  868. ;// <o.0..4> WAITTURN: Bus turnaround cycles <1-16> <#-1>
  869. ;// <i> The delay is in CCLK cycles
  870. ;// </h>
  871. EMC_STA_WTURN2_Val EQU 0x0000000F
  872. ;// </e> End of Static Setup for Static CS2 Area
  873. ;// Configure External Bus Behaviour for Static CS3 Area ---------------
  874. ;// <e> Configure External Bus Behaviour for Static CS3 Area
  875. EMC_STACS3_SETUP EQU 0
  876. ;// <h> Static Memory Configuration Register (EMCStaticConfig3)
  877. ;// <i> Defines the configuration information for the static memory CS3
  878. ;// <o0.20> WP: Write protect
  879. ;// <o0.19> B: Buffer enable
  880. ;// <o0.8> EW: Extended wait enable
  881. ;// <o0.7> PB: Byte lane state
  882. ;// <0=> For reads BLSn are HIGH, for writes BLSn are LOW
  883. ;// <1=> For reads BLSn are LOW, for writes BLSn are LOW
  884. ;// <o0.6> PC: Chip select polarity
  885. ;// <0=> Active LOW chip select
  886. ;// <1=> Active HIGH chip select
  887. ;// <o0.3> PM: Page mode enable
  888. ;// <o0.0..1> MW: Memory width
  889. ;// <0=> 8 bit
  890. ;// <1=> 16 bit
  891. ;// <2=> 32 bit
  892. ;// </h>
  893. EMC_STA_CFG3_Val EQU 0x00000000
  894. ;// <h> Static Memory Write Enable Delay Register (EMCStaticWaitWen3)
  895. ;// <i> Selects the delay from CS3 to write enable
  896. ;// <o.0..3> WAITWEN: Wait write enable <1-16> <#-1>
  897. ;// <i> The delay is in CCLK cycles
  898. ;// </h>
  899. EMC_STA_WWEN3_Val EQU 0x00000000
  900. ;// <h> Static Memory Output Enable Delay register (EMCStaticWaitOen3)
  901. ;// <i> Selects the delay from CS3 or address change, whichever is later, to output enable
  902. ;// <o.0..3> WAITOEN: Wait output enable <0-15>
  903. ;// <i> The delay is in CCLK cycles
  904. ;// </h>
  905. EMC_STA_WOEN3_Val EQU 0x00000000
  906. ;// <h> Static Memory Read Delay Register (EMCStaticWaitRd3)
  907. ;// <i> Selects the delay from CS3 to a read access
  908. ;// <o.0..4> WAITRD: Non-page mode read wait states or asynchronous page mode read first access wait states <1-32> <#-1>
  909. ;// <i> The delay is in CCLK cycles
  910. ;// </h>
  911. EMC_STA_WRD3_Val EQU 0x0000001F
  912. ;// <h> Static Memory Page Mode Read Delay Register (EMCStaticWaitPage3)
  913. ;// <i> Selects the delay for asynchronous page mode sequential accesses for CS3
  914. ;// <o.0..4> WAITPAGE: Asynchronous page mode read after the first read wait states <1-32> <#-1>
  915. ;// <i> The delay is in CCLK cycles
  916. ;// </h>
  917. EMC_STA_WPAGE3_Val EQU 0x0000001F
  918. ;// <h> Static Memory Write Delay Register (EMCStaticWaitWr3)
  919. ;// <i> Selects the delay from CS3 to a write access
  920. ;// <o.0..4> WAITWR: Write wait states <2-33> <#-2>
  921. ;// <i> The delay is in CCLK cycles
  922. ;// </h>
  923. EMC_STA_WWR3_Val EQU 0x0000001F
  924. ;// <h> Static Memory Turn Round Delay Register (EMCStaticWaitTurn3)
  925. ;// <i> Selects the number of bus turnaround cycles for CS3
  926. ;// <o.0..4> WAITTURN: Bus turnaround cycles <1-16> <#-1>
  927. ;// <i> The delay is in CCLK cycles
  928. ;// </h>
  929. EMC_STA_WTURN3_Val EQU 0x0000000F
  930. ;// </e> End of Static Setup for Static CS3 Area
  931. ;// <h> Static Memory Extended Wait Register (EMCStaticExtendedWait)
  932. ;// <i> Time long static memory read and write transfers
  933. ;// <o.0..9> EXTENDEDWAIT: Extended wait time out <0-1023>
  934. ;// <i> The delay is in (16 * CCLK) cycles
  935. ;// </h>
  936. EMC_STA_EXT_W_Val EQU 0x00000000
  937. ;// </e> End of Static Setup
  938. ;// </e> End of EMC Setup
  939. PRESERVE8
  940. ; Area Definition and Entry Point
  941. ; Startup Code must be linked first at Address at which it expects to run.
  942. AREA RESET, CODE, READONLY
  943. ARM
  944. ; Exception Vectors
  945. ; Mapped to Address 0.
  946. ; Absolute addressing mode must be used.
  947. ; Dummy Handlers are implemented as infinite loops which can be modified.
  948. Vectors LDR PC, Reset_Addr
  949. LDR PC, Undef_Addr
  950. LDR PC, SWI_Addr
  951. LDR PC, PAbt_Addr
  952. LDR PC, DAbt_Addr
  953. NOP ; Reserved Vector
  954. LDR PC, IRQ_Addr
  955. LDR PC, FIQ_Addr
  956. Reset_Addr DCD Reset_Handler
  957. Undef_Addr DCD Undef_Handler
  958. SWI_Addr DCD SWI_Handler
  959. PAbt_Addr DCD PAbt_Handler
  960. DAbt_Addr DCD DAbt_Handler
  961. DCD 0 ; Reserved Address
  962. IRQ_Addr DCD IRQ_Handler
  963. FIQ_Addr DCD FIQ_Handler
  964. ; Exception Handler
  965. IMPORT rt_hw_trap_udef
  966. IMPORT rt_hw_trap_swi
  967. IMPORT rt_hw_trap_pabt
  968. IMPORT rt_hw_trap_dabt
  969. IMPORT rt_hw_trap_fiq
  970. ; Prepare Fatal Context
  971. MACRO
  972. prepare_fatal
  973. STMFD sp!, {r0-r3}
  974. MOV r1, sp
  975. ADD sp, sp, #16
  976. SUB r2, lr, #4
  977. MRS r3, spsr
  978. ; switch to SVC mode and no interrupt
  979. MSR cpsr_c, #I_Bit :OR: F_Bit :OR: Mode_SVC
  980. STMFD sp!, {r0} ; old r0
  981. ; get sp
  982. ADD r0, sp, #4
  983. STMFD sp!, {r3} ; cpsr
  984. STMFD sp!, {r2} ; pc
  985. STMFD sp!, {lr} ; lr
  986. STMFD sp!, {r0} ; sp
  987. STMFD sp!, {r4-r12}
  988. MOV r4, r1
  989. LDMFD r4!, {r0-r3}
  990. STMFD sp!, {r0-r3}
  991. MOV r0, sp
  992. MEND
  993. Undef_Handler
  994. prepare_fatal
  995. BL rt_hw_trap_irq
  996. B .
  997. SWI_Handler
  998. prepare_fatal
  999. BL rt_hw_trap_swi
  1000. B .
  1001. PAbt_Handler
  1002. prepare_fatal
  1003. BL rt_hw_trap_pabt
  1004. B .
  1005. DAbt_Handler
  1006. prepare_fatal
  1007. BL rt_hw_trap_dabt
  1008. B .
  1009. FIQ_Handler
  1010. prepare_fatal
  1011. BL rt_hw_trap_fiq
  1012. B .
  1013. ; Reset Handler
  1014. EXPORT Reset_Handler
  1015. Reset_Handler
  1016. ; Clock Setup ------------------------------------------------------------------
  1017. IF (:LNOT:(:DEF:NO_CLOCK_SETUP)):LAND:(CLOCK_SETUP != 0)
  1018. LDR R0, =SCB_BASE
  1019. MOV R1, #0xAA
  1020. MOV R2, #0x55
  1021. ; Configure and Enable PLL
  1022. LDR R3, =SCS_Val ; Enable main oscillator
  1023. STR R3, [R0, #SCS_OFS]
  1024. IF (SCS_Val:AND:OSCEN) != 0
  1025. OSC_Loop LDR R3, [R0, #SCS_OFS] ; Wait for main osc stabilize
  1026. ANDS R3, R3, #OSCSTAT
  1027. BEQ OSC_Loop
  1028. ENDIF
  1029. LDR R3, =CLKSRCSEL_Val ; Select PLL source clock
  1030. STR R3, [R0, #CLKSRCSEL_OFS]
  1031. LDR R3, =PLLCFG_Val
  1032. STR R3, [R0, #PLLCFG_OFS]
  1033. STR R1, [R0, #PLLFEED_OFS]
  1034. STR R2, [R0, #PLLFEED_OFS]
  1035. MOV R3, #PLLCON_PLLE
  1036. STR R3, [R0, #PLLCON_OFS]
  1037. STR R1, [R0, #PLLFEED_OFS]
  1038. STR R2, [R0, #PLLFEED_OFS]
  1039. IF (CLKSRCSEL_Val:AND:3) != 2
  1040. ; Wait until PLL Locked (if source is not RTC oscillator)
  1041. PLL_Loop LDR R3, [R0, #PLLSTAT_OFS]
  1042. ANDS R3, R3, #PLLSTAT_PLOCK
  1043. BEQ PLL_Loop
  1044. ELSE
  1045. ; Wait at least 200 cycles (if source is RTC oscillator)
  1046. MOV R3, #(200/4)
  1047. PLL_Loop SUBS R3, R3, #1
  1048. BNE PLL_Loop
  1049. ENDIF
  1050. M_N_Lock LDR R3, [R0, #PLLSTAT_OFS]
  1051. LDR R4, =(PLLSTAT_M:OR:PLLSTAT_N)
  1052. AND R3, R3, R4
  1053. LDR R4, =PLLCFG_Val
  1054. EORS R3, R3, R4
  1055. BNE M_N_Lock
  1056. ; Setup CPU clock divider
  1057. MOV R3, #CCLKCFG_Val
  1058. STR R3, [R0, #CCLKCFG_OFS]
  1059. ; Setup USB clock divider
  1060. LDR R3, =USBCLKCFG_Val
  1061. STR R3, [R0, #USBCLKCFG_OFS]
  1062. ; Setup Peripheral Clock
  1063. LDR R3, =PCLKSEL0_Val
  1064. STR R3, [R0, #PCLKSEL0_OFS]
  1065. LDR R3, =PCLKSEL1_Val
  1066. STR R3, [R0, #PCLKSEL1_OFS]
  1067. ; Switch to PLL Clock
  1068. MOV R3, #(PLLCON_PLLE:OR:PLLCON_PLLC)
  1069. STR R3, [R0, #PLLCON_OFS]
  1070. STR R1, [R0, #PLLFEED_OFS]
  1071. STR R2, [R0, #PLLFEED_OFS]
  1072. ENDIF ; CLOCK_SETUP
  1073. ; Setup Memory Accelerator Module ----------------------------------------------
  1074. IF MAM_SETUP != 0
  1075. LDR R0, =MAM_BASE
  1076. MOV R1, #MAMTIM_Val
  1077. STR R1, [R0, #MAMTIM_OFS]
  1078. MOV R1, #MAMCR_Val
  1079. STR R1, [R0, #MAMCR_OFS]
  1080. ENDIF ; MAM_SETUP
  1081. ; Setup External Memory Controller ---------------------------------------------
  1082. IF (:LNOT:(:DEF:NO_EMC_SETUP)):LAND:(EMC_SETUP != 0)
  1083. LDR R0, =EMC_BASE
  1084. LDR R1, =SCB_BASE
  1085. LDR R2, =PCB_BASE
  1086. LDR R4, =EMC_PCONP_Const ; Enable EMC
  1087. LDR R3, [R1, #PCONP_OFS]
  1088. ORR R4, R4, R3
  1089. STR R4, [R1, #PCONP_OFS]
  1090. LDR R4, =EMC_CTRL_Val
  1091. STR R4, [R0, #EMC_CTRL_OFS]
  1092. LDR R4, =EMC_CONFIG_Val
  1093. STR R4, [R0, #EMC_CONFIG_OFS]
  1094. ; Setup pin functions for External Bus functionality
  1095. LDR R4, =EMC_PINSEL5_Val
  1096. STR R4, [R2, #PINSEL5_OFS]
  1097. LDR R4, =EMC_PINSEL6_Val
  1098. STR R4, [R2, #PINSEL6_OFS]
  1099. LDR R4, =EMC_PINSEL8_Val
  1100. STR R4, [R2, #PINSEL8_OFS]
  1101. LDR R4, =EMC_PINSEL9_Val
  1102. STR R4, [R2, #PINSEL9_OFS]
  1103. ; Setup Dynamic Memory Interface
  1104. IF (EMC_DYNAMIC_SETUP != 0)
  1105. LDR R4, =EMC_DYN_RP_Val
  1106. STR R4, [R0, #EMC_DYN_RP_OFS]
  1107. LDR R4, =EMC_DYN_RAS_Val
  1108. STR R4, [R0, #EMC_DYN_RAS_OFS]
  1109. LDR R4, =EMC_DYN_SREX_Val
  1110. STR R4, [R0, #EMC_DYN_SREX_OFS]
  1111. LDR R4, =EMC_DYN_APR_Val
  1112. STR R4, [R0, #EMC_DYN_APR_OFS]
  1113. LDR R4, =EMC_DYN_DAL_Val
  1114. STR R4, [R0, #EMC_DYN_DAL_OFS]
  1115. LDR R4, =EMC_DYN_WR_Val
  1116. STR R4, [R0, #EMC_DYN_WR_OFS]
  1117. LDR R4, =EMC_DYN_RC_Val
  1118. STR R4, [R0, #EMC_DYN_RC_OFS]
  1119. LDR R4, =EMC_DYN_RFC_Val
  1120. STR R4, [R0, #EMC_DYN_RFC_OFS]
  1121. LDR R4, =EMC_DYN_XSR_Val
  1122. STR R4, [R0, #EMC_DYN_XSR_OFS]
  1123. LDR R4, =EMC_DYN_RRD_Val
  1124. STR R4, [R0, #EMC_DYN_RRD_OFS]
  1125. LDR R4, =EMC_DYN_MRD_Val
  1126. STR R4, [R0, #EMC_DYN_MRD_OFS]
  1127. LDR R4, =EMC_DYN_RD_CFG_Val
  1128. STR R4, [R0, #EMC_DYN_RD_CFG_OFS]
  1129. IF (EMC_DYNCS0_SETUP != 0)
  1130. LDR R4, =EMC_DYN_RASCAS0_Val
  1131. STR R4, [R0, #EMC_DYN_RASCAS0_OFS]
  1132. LDR R4, =EMC_DYN_CFG0_Val
  1133. MVN R5, #BUFEN_Const
  1134. AND R4, R4, R5
  1135. STR R4, [R0, #EMC_DYN_CFG0_OFS]
  1136. ENDIF
  1137. IF (EMC_DYNCS1_SETUP != 0)
  1138. LDR R4, =EMC_DYN_RASCAS1_Val
  1139. STR R4, [R0, #EMC_DYN_RASCAS1_OFS]
  1140. LDR R4, =EMC_DYN_CFG1_Val
  1141. MVN R5, =BUFEN_Const
  1142. AND R4, R4, R5
  1143. STR R4, [R0, #EMC_DYN_CFG1_OFS]
  1144. ENDIF
  1145. IF (EMC_DYNCS2_SETUP != 0)
  1146. LDR R4, =EMC_DYN_RASCAS2_Val
  1147. STR R4, [R0, #EMC_DYN_RASCAS2_OFS]
  1148. LDR R4, =EMC_DYN_CFG2_Val
  1149. MVN R5, =BUFEN_Const
  1150. AND R4, R4, R5
  1151. STR R4, [R0, #EMC_DYN_CFG2_OFS]
  1152. ENDIF
  1153. IF (EMC_DYNCS3_SETUP != 0)
  1154. LDR R4, =EMC_DYN_RASCAS3_Val
  1155. STR R4, [R0, #EMC_DYN_RASCAS3_OFS]
  1156. LDR R4, =EMC_DYN_CFG3_Val
  1157. MVN R5, =BUFEN_Const
  1158. AND R4, R4, R5
  1159. STR R4, [R0, #EMC_DYN_CFG3_OFS]
  1160. ENDIF
  1161. LDR R6, =1440000 ; Number of cycles to delay
  1162. Wait_0 SUBS R6, R6, #1 ; Delay ~100 ms proc clk 57.6 MHz
  1163. BNE Wait_0 ; BNE (3 cyc) + SUBS (1 cyc) = 4 cyc
  1164. LDR R4, =(NOP_CMD:OR:0x03) ; Write NOP Command
  1165. STR R4, [R0, #EMC_DYN_CTRL_OFS]
  1166. LDR R6, =2880000 ; Number of cycles to delay
  1167. Wait_1 SUBS R6, R6, #1 ; Delay ~200 ms proc clk 57.6 MHz
  1168. BNE Wait_1
  1169. LDR R4, =(PALL_CMD:OR:0x03) ; Write Precharge All Command
  1170. STR R4, [R0, #EMC_DYN_CTRL_OFS]
  1171. MOV R4, #2
  1172. STR R4, [R0, #EMC_DYN_RFSH_OFS]
  1173. MOV R6, #64 ; Number of cycles to delay
  1174. Wait_2 SUBS R6, R6, #1 ; Delay
  1175. BNE Wait_2
  1176. LDR R4, =EMC_DYN_RFSH_Val
  1177. STR R4, [R0, #EMC_DYN_RFSH_OFS]
  1178. LDR R4, =(MODE_CMD:OR:0x03) ; Write MODE Command
  1179. STR R4, [R0, #EMC_DYN_CTRL_OFS]
  1180. ; Dummy read
  1181. IF (EMC_DYNCS0_SETUP != 0)
  1182. LDR R4, =DYN_MEM0_BASE
  1183. MOV R5, #(0x33 << 12)
  1184. ADD R4, R4, R5
  1185. LDR R4, [R4, #0]
  1186. ENDIF
  1187. IF (EMC_DYNCS1_SETUP != 0)
  1188. LDR R4, =DYN_MEM1_BASE
  1189. MOV R5, #(0x33 << 12)
  1190. ADD R4, R4, R5
  1191. LDR R4, [R4, #0]
  1192. ENDIF
  1193. IF (EMC_DYNCS2_SETUP != 0)
  1194. LDR R4, =DYN_MEM2_BASE
  1195. MOV R5, #(0x33 << 12)
  1196. ADD R4, R4, R5
  1197. LDR R4, [R4, #0]
  1198. ENDIF
  1199. IF (EMC_DYNCS3_SETUP != 0)
  1200. LDR R4, =DYN_MEM3_BASE
  1201. MOV R5, #(0x33 << 12)
  1202. ADD R4, R4, R5
  1203. LDR R4, [R4, #0]
  1204. ENDIF
  1205. LDR R4, =NORMAL_CMD ; Write NORMAL Command
  1206. STR R4, [R0, #EMC_DYN_CTRL_OFS]
  1207. ; Enable buffer if requested by settings
  1208. IF (EMC_DYNCS0_SETUP != 0):LAND:((EMC_DYN_CFG0_Val:AND:BUFEN_Const) != 0)
  1209. LDR R4, =EMC_DYN_CFG0_Val
  1210. STR R4, [R0, #EMC_DYN_CFG0_OFS]
  1211. ENDIF
  1212. IF (EMC_DYNCS1_SETUP != 0):LAND:((EMC_DYN_CFG1_Val:AND:BUFEN_Const) != 0)
  1213. LDR R4, =EMC_DYN_CFG1_Val
  1214. STR R4, [R0, #EMC_DYN_CFG1_OFS]
  1215. ENDIF
  1216. IF (EMC_DYNCS2_SETUP != 0):LAND:((EMC_DYN_CFG2_Val:AND:BUFEN_Const) != 0)
  1217. LDR R4, =EMC_DYN_CFG2_Val
  1218. STR R4, [R0, #EMC_DYN_CFG2_OFS]
  1219. ENDIF
  1220. IF (EMC_DYNCS3_SETUP != 0):LAND:((EMC_DYN_CFG3_Val:AND:BUFEN_Const) != 0)
  1221. LDR R4, =EMC_DYN_CFG3_Val
  1222. STR R4, [R0, #EMC_DYN_CFG3_OFS]
  1223. ENDIF
  1224. LDR R6, =14400 ; Number of cycles to delay
  1225. Wait_3 SUBS R6, R6, #1 ; Delay ~1 ms @ proc clk 57.6 MHz
  1226. BNE Wait_3
  1227. ENDIF ; EMC_DYNAMIC_SETUP
  1228. ; Setup Static Memory Interface
  1229. IF (EMC_STATIC_SETUP != 0)
  1230. LDR R6, =1440000 ; Number of cycles to delay
  1231. Wait_4 SUBS R6, R6, #1 ; Delay ~100 ms @ proc clk 57.6 MHz
  1232. BNE Wait_4
  1233. IF (EMC_STACS0_SETUP != 0)
  1234. LDR R4, =EMC_STA_CFG0_Val
  1235. STR R4, [R0, #EMC_STA_CFG0_OFS]
  1236. LDR R4, =EMC_STA_WWEN0_Val
  1237. STR R4, [R0, #EMC_STA_WWEN0_OFS]
  1238. LDR R4, =EMC_STA_WOEN0_Val
  1239. STR R4, [R0, #EMC_STA_WOEN0_OFS]
  1240. LDR R4, =EMC_STA_WRD0_Val
  1241. STR R4, [R0, #EMC_STA_WRD0_OFS]
  1242. LDR R4, =EMC_STA_WPAGE0_Val
  1243. STR R4, [R0, #EMC_STA_WPAGE0_OFS]
  1244. LDR R4, =EMC_STA_WWR0_Val
  1245. STR R4, [R0, #EMC_STA_WWR0_OFS]
  1246. LDR R4, =EMC_STA_WTURN0_Val
  1247. STR R4, [R0, #EMC_STA_WTURN0_OFS]
  1248. ENDIF
  1249. IF (EMC_STACS1_SETUP != 0)
  1250. LDR R4, =EMC_STA_CFG1_Val
  1251. STR R4, [R0, #EMC_STA_CFG1_OFS]
  1252. LDR R4, =EMC_STA_WWEN1_Val
  1253. STR R4, [R0, #EMC_STA_WWEN1_OFS]
  1254. LDR R4, =EMC_STA_WOEN1_Val
  1255. STR R4, [R0, #EMC_STA_WOEN1_OFS]
  1256. LDR R4, =EMC_STA_WRD1_Val
  1257. STR R4, [R0, #EMC_STA_WRD1_OFS]
  1258. LDR R4, =EMC_STA_WPAGE1_Val
  1259. STR R4, [R0, #EMC_STA_WPAGE1_OFS]
  1260. LDR R4, =EMC_STA_WWR1_Val
  1261. STR R4, [R0, #EMC_STA_WWR1_OFS]
  1262. LDR R4, =EMC_STA_WTURN1_Val
  1263. STR R4, [R0, #EMC_STA_WTURN1_OFS]
  1264. ENDIF
  1265. IF (EMC_STACS2_SETUP != 0)
  1266. LDR R4, =EMC_STA_CFG2_Val
  1267. STR R4, [R0, #EMC_STA_CFG2_OFS]
  1268. LDR R4, =EMC_STA_WWEN2_Val
  1269. STR R4, [R0, #EMC_STA_WWEN2_OFS]
  1270. LDR R4, =EMC_STA_WOEN2_Val
  1271. STR R4, [R0, #EMC_STA_WOEN2_OFS]
  1272. LDR R4, =EMC_STA_WRD2_Val
  1273. STR R4, [R0, #EMC_STA_WRD2_OFS]
  1274. LDR R4, =EMC_STA_WPAGE2_Val
  1275. STR R4, [R0, #EMC_STA_WPAGE2_OFS]
  1276. LDR R4, =EMC_STA_WWR2_Val
  1277. STR R4, [R0, #EMC_STA_WWR2_OFS]
  1278. LDR R4, =EMC_STA_WTURN2_Val
  1279. STR R4, [R0, #EMC_STA_WTURN2_OFS]
  1280. ENDIF
  1281. IF (EMC_STACS3_SETUP != 0)
  1282. LDR R4, =EMC_STA_CFG3_Val
  1283. STR R4, [R0, #EMC_STA_CFG3_OFS]
  1284. LDR R4, =EMC_STA_WWEN3_Val
  1285. STR R4, [R0, #EMC_STA_WWEN3_OFS]
  1286. LDR R4, =EMC_STA_WOEN3_Val
  1287. STR R4, [R0, #EMC_STA_WOEN3_OFS]
  1288. LDR R4, =EMC_STA_WRD3_Val
  1289. STR R4, [R0, #EMC_STA_WRD3_OFS]
  1290. LDR R4, =EMC_STA_WPAGE3_Val
  1291. STR R4, [R0, #EMC_STA_WPAGE3_OFS]
  1292. LDR R4, =EMC_STA_WWR3_Val
  1293. STR R4, [R0, #EMC_STA_WWR3_OFS]
  1294. LDR R4, =EMC_STA_WTURN3_Val
  1295. STR R4, [R0, #EMC_STA_WTURN3_OFS]
  1296. ENDIF
  1297. LDR R6, =144000 ; Number of cycles to delay
  1298. Wait_5 SUBS R6, R6, #1 ; Delay ~10 ms @ proc clk 57.6 MHz
  1299. BNE Wait_5
  1300. LDR R4, =EMC_STA_EXT_W_Val
  1301. LDR R5, =EMC_STA_EXT_W_OFS
  1302. ADD R5, R5, R0
  1303. STR R4, [R5, #0]
  1304. ENDIF ; EMC_STATIC_SETUP
  1305. ENDIF ; EMC_SETUP
  1306. ; Copy Exception Vectors to Internal RAM ---------------------------------------
  1307. IF :DEF:RAM_INTVEC
  1308. ADR R8, Vectors ; Source
  1309. LDR R9, =RAM_BASE ; Destination
  1310. LDMIA R8!, {R0-R7} ; Load Vectors
  1311. STMIA R9!, {R0-R7} ; Store Vectors
  1312. LDMIA R8!, {R0-R7} ; Load Handler Addresses
  1313. STMIA R9!, {R0-R7} ; Store Handler Addresses
  1314. ENDIF
  1315. ; Memory Mapping (when Interrupt Vectors are in RAM) ---------------------------
  1316. MEMMAP EQU 0xE01FC040 ; Memory Mapping Control
  1317. IF :DEF:REMAP
  1318. LDR R0, =MEMMAP
  1319. IF :DEF:EXTMEM_MODE
  1320. MOV R1, #3
  1321. ELIF :DEF:RAM_MODE
  1322. MOV R1, #2
  1323. ELSE
  1324. MOV R1, #1
  1325. ENDIF
  1326. STR R1, [R0]
  1327. ENDIF
  1328. ; Setup Stack for each mode ----------------------------------------------------
  1329. LDR R0, =Stack_Top
  1330. ; Enter Undefined Instruction Mode and set its Stack Pointer
  1331. MSR CPSR_c, #Mode_UND:OR:I_Bit:OR:F_Bit
  1332. MOV SP, R0
  1333. SUB R0, R0, #UND_Stack_Size
  1334. ; Enter Abort Mode and set its Stack Pointer
  1335. MSR CPSR_c, #Mode_ABT:OR:I_Bit:OR:F_Bit
  1336. MOV SP, R0
  1337. SUB R0, R0, #ABT_Stack_Size
  1338. ; Enter FIQ Mode and set its Stack Pointer
  1339. MSR CPSR_c, #Mode_FIQ:OR:I_Bit:OR:F_Bit
  1340. MOV SP, R0
  1341. SUB R0, R0, #FIQ_Stack_Size
  1342. ; Enter IRQ Mode and set its Stack Pointer
  1343. MSR CPSR_c, #Mode_IRQ:OR:I_Bit:OR:F_Bit
  1344. MOV SP, R0
  1345. SUB R0, R0, #IRQ_Stack_Size
  1346. ; Enter Supervisor Mode and set its Stack Pointer
  1347. MSR CPSR_c, #Mode_SVC:OR:I_Bit:OR:F_Bit
  1348. MOV SP, R0
  1349. SUB R0, R0, #SVC_Stack_Size
  1350. IF :DEF:__MICROLIB
  1351. EXPORT __initial_sp
  1352. ELSE
  1353. ENDIF
  1354. ; Enter the C code -------------------------------------------------------------
  1355. IMPORT __main
  1356. LDR R0, =__main
  1357. BX R0
  1358. IMPORT rt_interrupt_enter
  1359. IMPORT rt_interrupt_leave
  1360. IMPORT rt_thread_switch_interrupt_flag
  1361. IMPORT rt_interrupt_from_thread
  1362. IMPORT rt_interrupt_to_thread
  1363. IMPORT rt_hw_trap_irq
  1364. IRQ_Handler PROC
  1365. EXPORT IRQ_Handler
  1366. STMFD sp!, {r0-r12,lr}
  1367. BL rt_interrupt_enter
  1368. BL rt_hw_trap_irq
  1369. BL rt_interrupt_leave
  1370. ; if rt_thread_switch_interrupt_flag set, jump to
  1371. ; rt_hw_context_switch_interrupt_do and don't return
  1372. LDR r0, =rt_thread_switch_interrupt_flag
  1373. LDR r1, [r0]
  1374. CMP r1, #1
  1375. BEQ rt_hw_context_switch_interrupt_do
  1376. LDMFD sp!, {r0-r12,lr}
  1377. SUBS pc, lr, #4
  1378. ENDP
  1379. ; /*
  1380. ; * void rt_hw_context_switch_interrupt_do(rt_base_t flag)
  1381. ; */
  1382. rt_hw_context_switch_interrupt_do PROC
  1383. EXPORT rt_hw_context_switch_interrupt_do
  1384. MOV r1, #0 ; clear flag
  1385. STR r1, [r0]
  1386. LDMFD sp!, {r0-r12,lr}; reload saved registers
  1387. STMFD sp!, {r0-r3} ; save r0-r3
  1388. MOV r1, sp
  1389. ADD sp, sp, #16 ; restore sp
  1390. SUB r2, lr, #4 ; save old task's pc to r2
  1391. MRS r3, spsr ; get cpsr of interrupt thread
  1392. ; switch to SVC mode and no interrupt
  1393. MSR cpsr_c, #I_Bit :OR: F_Bit :OR: Mode_SVC
  1394. STMFD sp!, {r2} ; push old task's pc
  1395. STMFD sp!, {r4-r12,lr}; push old task's lr,r12-r4
  1396. MOV r4, r1 ; Special optimised code below
  1397. MOV r5, r3
  1398. LDMFD r4!, {r0-r3}
  1399. STMFD sp!, {r0-r3} ; push old task's r3-r0
  1400. STMFD sp!, {r5} ; push old task's cpsr
  1401. LDR r4, =rt_interrupt_from_thread
  1402. LDR r5, [r4]
  1403. STR sp, [r5] ; store sp in preempted tasks's TCB
  1404. LDR r6, =rt_interrupt_to_thread
  1405. LDR r6, [r6]
  1406. LDR sp, [r6] ; get new task's stack pointer
  1407. LDMFD sp!, {r4} ; pop new task's cpsr to spsr
  1408. MSR spsr_cxsf, r4
  1409. BIC r4, r4, #0x20 ; must be ARM mode
  1410. MSR cpsr_cxsf, r4
  1411. LDMFD sp!, {r0-r12,lr,pc}^ ; pop new task's r0-r12,lr & pc, copy spsr to cpsr
  1412. ENDP
  1413. IF :DEF:__MICROLIB
  1414. EXPORT __heap_base
  1415. EXPORT __heap_limit
  1416. ELSE
  1417. ; User Initial Stack & Heap
  1418. AREA |.text|, CODE, READONLY
  1419. IMPORT __use_two_region_memory
  1420. EXPORT __user_initial_stackheap
  1421. __user_initial_stackheap
  1422. LDR R0, = Heap_Mem
  1423. LDR R1, =(Stack_Mem + USR_Stack_Size)
  1424. LDR R2, = (Heap_Mem + Heap_Size)
  1425. LDR R3, = Stack_Mem
  1426. BX LR
  1427. ENDIF
  1428. END