start_rvds.S 66 KB

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