LPC2300.s
上传用户:ssllxx2007
上传日期:2022-06-12
资源大小:784k
文件大小:36k
源码类别:

uCOS

开发平台:

C/C++

  1. ;/*****************************************************************************/
  2. ;/* LPC2300.S: Startup file for Philips LPC2300 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 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 LPC2300.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 initializes External 
  22. ; *  Memory Controller (used mostly when external memory is already initialized 
  23. ; *  and loaded from script .ini file).
  24. ; *
  25. ; *  RAM_INTVEC: when set the startup code copies exception vectors 
  26. ; *  from on-chip Flash to on-chip RAM.
  27. ; *
  28. ; *  REMAP: when set the startup code initializes the register MEMMAP 
  29. ; *  which overwrites the settings of the CPU configuration pins. The 
  30. ; *  startup and interrupt vectors are remapped from:
  31. ; *     0x00000000  default setting (not remapped)
  32. ; *     0x40000000  when RAM_MODE is used
  33. ; *     0x80000000  when EXTMEM_MODE is used
  34. ; *
  35. ; *  EXTMEM_MODE: when set the device is configured for code execution
  36. ; *  from external memory starting at address 0x80000000.
  37. ; *
  38. ; *  RAM_MODE: when set the device is configured for code execution
  39. ; *  from on-chip RAM starting at address 0x40000000. 
  40. ; */
  41. ; Standard definitions of Mode bits and Interrupt (I & F) flags in PSRs
  42. Mode_USR        EQU     0x10
  43. Mode_FIQ        EQU     0x11
  44. Mode_IRQ        EQU     0x12
  45. Mode_SVC        EQU     0x13
  46. Mode_ABT        EQU     0x17
  47. Mode_UND        EQU     0x1B
  48. Mode_SYS        EQU     0x1F
  49. I_Bit           EQU     0x80            ; when I bit is set, IRQ is disabled
  50. F_Bit           EQU     0x40            ; when F bit is set, FIQ is disabled
  51. ;----------------------- Memory Definitions ------------------------------------
  52. ; Internal Memory Base Addresses
  53. FLASH_BASE      EQU     0x00000000   
  54. RAM_BASE        EQU     0x40000000
  55. EXTMEM_BASE     EQU     0x80000000
  56. ; External Memory Base Addresses
  57. STA_MEM0_BASE   EQU     0x80000000
  58. STA_MEM1_BASE   EQU     0x81000000
  59. ;----------------------- Stack and Heap Definitions ----------------------------
  60. ;// <h> Stack Configuration (Stack Sizes in Bytes)
  61. ;//   <o0> Undefined Mode      <0x0-0xFFFFFFFF:8>
  62. ;//   <o1> Supervisor Mode     <0x0-0xFFFFFFFF:8>
  63. ;//   <o2> Abort Mode          <0x0-0xFFFFFFFF:8>
  64. ;//   <o3> Fast Interrupt Mode <0x0-0xFFFFFFFF:8>
  65. ;//   <o4> Interrupt Mode      <0x0-0xFFFFFFFF:8>
  66. ;//   <o5> User/System Mode    <0x0-0xFFFFFFFF:8>
  67. ;// </h>
  68. UND_Stack_Size  EQU     0x00000000
  69. SVC_Stack_Size  EQU     0x00000008
  70. ABT_Stack_Size  EQU     0x00000000
  71. FIQ_Stack_Size  EQU     0x00000000
  72. IRQ_Stack_Size  EQU     0x00000100
  73. USR_Stack_Size  EQU     0x00000400
  74. ISR_Stack_Size  EQU     (UND_Stack_Size + SVC_Stack_Size + ABT_Stack_Size + 
  75.                          FIQ_Stack_Size + IRQ_Stack_Size)
  76.                 AREA    STACK, NOINIT, READWRITE, ALIGN=3
  77. Stack_Mem       SPACE   USR_Stack_Size
  78. __initial_sp    SPACE   ISR_Stack_Size
  79. Stack_Top
  80. ;// <h> Heap Configuration
  81. ;//   <o>  Heap Size (in Bytes) <0x0-0xFFFFFFFF>
  82. ;// </h>
  83. Heap_Size       EQU     0x00000000
  84.                 AREA    HEAP, NOINIT, READWRITE, ALIGN=3
  85. __heap_base
  86. Heap_Mem        SPACE   Heap_Size
  87. __heap_limit
  88. ;----------------------- System Control Block (SCB) Module Definitions ---------
  89. SCB_BASE        EQU     0xE01FC000      ; SCB Base Address
  90. PLLCON_OFS      EQU     0x80            ; PLL Control Offset
  91. PLLCFG_OFS      EQU     0x84            ; PLL Configuration Offset
  92. PLLSTAT_OFS     EQU     0x88            ; PLL Status Offset
  93. PLLFEED_OFS     EQU     0x8C            ; PLL Feed Offset
  94. CCLKCFG_OFS     EQU     0x104           ; CPU Clock Divider Reg Offset
  95. USBCLKCFG_OFS   EQU     0x108           ; USB Clock Divider Reg Offset
  96. CLKSRCSEL_OFS   EQU     0x10C           ; Clock Source Select Reg Offset
  97. SCS_OFS         EQU     0x1A0           ; System Control and Status Reg Offset
  98. PCLKSEL0_OFS    EQU     0x1A8           ; Peripheral Clock Select Reg 0 Offset
  99. PCLKSEL1_OFS    EQU     0x1AC           ; Peripheral Clock Select Reg 1 Offset
  100. PCON_OFS        EQU     0x0C0           ; Power Mode Control Reg Offset
  101. PCONP_OFS       EQU     0x0C4           ; Power Control for Periphs Reg Offset
  102. ; Constants
  103. OSCRANGE        EQU     (1<<4)          ; Oscillator Range Select
  104. OSCEN           EQU     (1<<5)          ; Main oscillator Enable
  105. OSCSTAT         EQU     (1<<6)          ; Main Oscillator Status
  106. PLLCON_PLLE     EQU     (1<<0)          ; PLL Enable
  107. PLLCON_PLLC     EQU     (1<<1)          ; PLL Connect
  108. PLLSTAT_M       EQU     (0x7FFF<<0)     ; PLL M Value
  109. PLLSTAT_N       EQU     (0xFF<<16)      ; PLL N Value
  110. PLLSTAT_PLOCK   EQU     (1<<26)         ; PLL Lock Status
  111. ;// <e> Clock Setup
  112. ;//   <h> System Controls and Status Register (SCS)
  113. ;//     <o1.4>    OSCRANGE: Main Oscillator Range Select
  114. ;//                     <0=>  1 MHz to 20 MHz
  115. ;//                     <1=> 15 MHz to 24 MHz
  116. ;//     <e1.5>       OSCEN: Main Oscillator Enable
  117. ;//     </e>
  118. ;//   </h>
  119. ;//
  120. ;//   <h> Clock Source Select Register (CLKSRCSEL)
  121. ;//     <o2.0..1>   CLKSRC: PLL Clock Source Selection
  122. ;//                     <0=> Internal RC oscillator
  123. ;//                     <1=> Main oscillator
  124. ;//                     <1=> RTC oscillator
  125. ;//   </h>
  126. ;//
  127. ;//   <h> PLL Configuration Register (PLLCFG)
  128. ;//                     <i> PLL_clk = (2* M * PLL_clk_src) / N
  129. ;//     <o3.0..14>    MSEL: PLL Multiplier Selection
  130. ;//                     <1-32768><#-1>
  131. ;//                     <i> M Value
  132. ;//     <o3.16..23>   NSEL: PLL Divider Selection
  133. ;//                     <1-256><#-1>
  134. ;//                     <i> N Value
  135. ;//   </h>
  136. ;//
  137. ;//   <h> CPU Clock Configuration Register (CCLKCFG)
  138. ;//     <o4.0..7>  CCLKSEL: Divide Value for CPU Clock from PLL
  139. ;//                     <1-256><#-1>
  140. ;//   </h>
  141. ;//
  142. ;//   <h> USB Clock Configuration Register (USBCLKCFG)
  143. ;//     <o5.0..3>   USBSEL: Divide Value for USB Clock from PLL
  144. ;//                     <1-16><#-1>
  145. ;//   </h>
  146. ;//
  147. ;//   <h> Peripheral Clock Selection Register 0 (PCLKSEL0)
  148. ;//     <o6.0..1>      PCLK_WDT: Peripheral Clock Selection for WDT
  149. ;//                     <0=> Pclk = Cclk / 4
  150. ;//                     <1=> Pclk = Cclk
  151. ;//                     <2=> Pclk = Cclk / 2
  152. ;//                     <3=> Pclk = Hclk / 8
  153. ;//     <o6.2..3>   PCLK_TIMER0: Peripheral Clock Selection for TIMER0
  154. ;//                     <0=> Pclk = Cclk / 4
  155. ;//                     <1=> Pclk = Cclk
  156. ;//                     <2=> Pclk = Cclk / 2
  157. ;//                     <3=> Pclk = Hclk / 8
  158. ;//     <o6.4..5>   PCLK_TIMER1: Peripheral Clock Selection for TIMER1
  159. ;//                     <0=> Pclk = Cclk / 4
  160. ;//                     <1=> Pclk = Cclk
  161. ;//                     <2=> Pclk = Cclk / 2
  162. ;//                     <3=> Pclk = Hclk / 8
  163. ;//     <o6.6..7>    PCLK_UART0: Peripheral Clock Selection for UART0
  164. ;//                     <0=> Pclk = Cclk / 4
  165. ;//                     <1=> Pclk = Cclk
  166. ;//                     <2=> Pclk = Cclk / 2
  167. ;//                     <3=> Pclk = Hclk / 8
  168. ;//     <o6.8..9>    PCLK_UART1: Peripheral Clock Selection for UART1
  169. ;//                     <0=> Pclk = Cclk / 4
  170. ;//                     <1=> Pclk = Cclk
  171. ;//                     <2=> Pclk = Cclk / 2
  172. ;//                     <3=> Pclk = Hclk / 8
  173. ;//     <o6.10..11>   PCLK_PWM0: Peripheral Clock Selection for PWM0
  174. ;//                     <0=> Pclk = Cclk / 4
  175. ;//                     <1=> Pclk = Cclk
  176. ;//                     <2=> Pclk = Cclk / 2
  177. ;//                     <3=> Pclk = Hclk / 8
  178. ;//     <o6.12..13>   PCLK_PWM1: Peripheral Clock Selection for PWM1
  179. ;//                     <0=> Pclk = Cclk / 4
  180. ;//                     <1=> Pclk = Cclk
  181. ;//                     <2=> Pclk = Cclk / 2
  182. ;//                     <3=> Pclk = Hclk / 8
  183. ;//     <o6.14..15>   PCLK_I2C0: Peripheral Clock Selection for I2C0
  184. ;//                     <0=> Pclk = Cclk / 4
  185. ;//                     <1=> Pclk = Cclk
  186. ;//                     <2=> Pclk = Cclk / 2
  187. ;//                     <3=> Pclk = Hclk / 8
  188. ;//     <o6.16..17>    PCLK_SPI: Peripheral Clock Selection for SPI
  189. ;//                     <0=> Pclk = Cclk / 4
  190. ;//                     <1=> Pclk = Cclk
  191. ;//                     <2=> Pclk = Cclk / 2
  192. ;//                     <3=> Pclk = Hclk / 8
  193. ;//     <o6.18..19>    PCLK_RTC: Peripheral Clock Selection for RTC
  194. ;//                     <0=> Pclk = Cclk / 4
  195. ;//                     <1=> Pclk = Cclk
  196. ;//                     <2=> Pclk = Cclk / 2
  197. ;//                     <3=> Pclk = Hclk / 8
  198. ;//     <o6.20..21>   PCLK_SSP1: Peripheral Clock Selection for SSP1
  199. ;//                     <0=> Pclk = Cclk / 4
  200. ;//                     <1=> Pclk = Cclk
  201. ;//                     <2=> Pclk = Cclk / 2
  202. ;//                     <3=> Pclk = Hclk / 8
  203. ;//     <o6.22..23>    PCLK_DAC: Peripheral Clock Selection for DAC
  204. ;//                     <0=> Pclk = Cclk / 4
  205. ;//                     <1=> Pclk = Cclk
  206. ;//                     <2=> Pclk = Cclk / 2
  207. ;//                     <3=> Pclk = Hclk / 8
  208. ;//     <o6.24..25>    PCLK_ADC: Peripheral Clock Selection for ADC
  209. ;//                     <0=> Pclk = Cclk / 4
  210. ;//                     <1=> Pclk = Cclk
  211. ;//                     <2=> Pclk = Cclk / 2
  212. ;//                     <3=> Pclk = Hclk / 8
  213. ;//     <o6.26..27>   PCLK_CAN1: Peripheral Clock Selection for CAN1
  214. ;//                     <0=> Pclk = Cclk / 4
  215. ;//                     <1=> Pclk = Cclk
  216. ;//                     <2=> Pclk = Cclk / 2
  217. ;//                     <3=> Pclk = Hclk / 6
  218. ;//     <o6.28..29>   PCLK_CAN2: Peripheral Clock Selection for CAN2
  219. ;//                     <0=> Pclk = Cclk / 4
  220. ;//                     <1=> Pclk = Cclk
  221. ;//                     <2=> Pclk = Cclk / 2
  222. ;//                     <3=> Pclk = Hclk / 6
  223. ;//     <o6.30..31>    PCLK_ACF: Peripheral Clock Selection for ACF
  224. ;//                     <0=> Pclk = Cclk / 4
  225. ;//                     <1=> Pclk = Cclk
  226. ;//                     <2=> Pclk = Cclk / 2
  227. ;//                     <3=> Pclk = Hclk / 6
  228. ;//   </h>
  229. ;//
  230. ;//   <h> Peripheral Clock Selection Register 1 (PCLKSEL1)
  231. ;//     <o7.0..1>  PCLK_BAT_RAM: Peripheral Clock Selection for the Battery Supported RAM
  232. ;//                     <0=> Pclk = Cclk / 4
  233. ;//                     <1=> Pclk = Cclk
  234. ;//                     <2=> Pclk = Cclk / 2
  235. ;//                     <3=> Pclk = Hclk / 8
  236. ;//     <o7.2..3>     PCLK_GPIO: Peripheral Clock Selection for GPIOs
  237. ;//                     <0=> Pclk = Cclk / 4
  238. ;//                     <1=> Pclk = Cclk
  239. ;//                     <2=> Pclk = Cclk / 2
  240. ;//                     <3=> Pclk = Hclk / 8
  241. ;//     <o7.4..5>      PCLK_PCB: Peripheral Clock Selection for Pin Connect Block
  242. ;//                     <0=> Pclk = Cclk / 4
  243. ;//                     <1=> Pclk = Cclk
  244. ;//                     <2=> Pclk = Cclk / 2
  245. ;//                     <3=> Pclk = Hclk / 8
  246. ;//     <o7.6..7>     PCLK_I2C1: Peripheral Clock Selection for I2C1
  247. ;//                     <0=> Pclk = Cclk / 4
  248. ;//                     <1=> Pclk = Cclk
  249. ;//                     <2=> Pclk = Cclk / 2
  250. ;//                     <3=> Pclk = Hclk / 8
  251. ;//     <o7.10..11>   PCLK_SSP0: Peripheral Clock Selection for SSP0
  252. ;//                     <0=> Pclk = Cclk / 4
  253. ;//                     <1=> Pclk = Cclk
  254. ;//                     <2=> Pclk = Cclk / 2
  255. ;//                     <3=> Pclk = Hclk / 8
  256. ;//     <o7.12..13> PCLK_TIMER2: Peripheral Clock Selection for TIMER2
  257. ;//                     <0=> Pclk = Cclk / 4
  258. ;//                     <1=> Pclk = Cclk
  259. ;//                     <2=> Pclk = Cclk / 2
  260. ;//                     <3=> Pclk = Hclk / 8
  261. ;//     <o7.14..15> PCLK_TIMER3: Peripheral Clock Selection for TIMER3
  262. ;//                     <0=> Pclk = Cclk / 4
  263. ;//                     <1=> Pclk = Cclk
  264. ;//                     <2=> Pclk = Cclk / 2
  265. ;//                     <3=> Pclk = Hclk / 8
  266. ;//     <o7.16..17>  PCLK_UART2: Peripheral Clock Selection for UART2
  267. ;//                     <0=> Pclk = Cclk / 4
  268. ;//                     <1=> Pclk = Cclk
  269. ;//                     <2=> Pclk = Cclk / 2
  270. ;//                     <3=> Pclk = Hclk / 8
  271. ;//     <o7.18..19>  PCLK_UART3: Peripheral Clock Selection for UART3
  272. ;//                     <0=> Pclk = Cclk / 4
  273. ;//                     <1=> Pclk = Cclk
  274. ;//                     <2=> Pclk = Cclk / 2
  275. ;//                     <3=> Pclk = Hclk / 8
  276. ;//     <o7.20..21>   PCLK_I2C2: Peripheral Clock Selection for I2C2
  277. ;//                     <0=> Pclk = Cclk / 4
  278. ;//                     <1=> Pclk = Cclk
  279. ;//                     <2=> Pclk = Cclk / 2
  280. ;//                     <3=> Pclk = Hclk / 8
  281. ;//     <o7.22..23>    PCLK_I2S: Peripheral Clock Selection for I2S
  282. ;//                     <0=> Pclk = Cclk / 4
  283. ;//                     <1=> Pclk = Cclk
  284. ;//                     <2=> Pclk = Cclk / 2
  285. ;//                     <3=> Pclk = Hclk / 8
  286. ;//     <o7.24..25>    PCLK_MCI: Peripheral Clock Selection for MCI
  287. ;//                     <0=> Pclk = Cclk / 4
  288. ;//                     <1=> Pclk = Cclk
  289. ;//                     <2=> Pclk = Cclk / 2
  290. ;//                     <3=> Pclk = Hclk / 8
  291. ;//     <o7.28..29> PCLK_SYSCON: Peripheral Clock Selection for System Control Block
  292. ;//                     <0=> Pclk = Cclk / 4
  293. ;//                     <1=> Pclk = Cclk
  294. ;//                     <2=> Pclk = Cclk / 2
  295. ;//                     <3=> Pclk = Hclk / 8
  296. ;//   </h>
  297. ;//   <h> Power Control for Peripherals Register (PCONP)
  298. ;//     <o8.31>     PCUSB: USB interface power/clock enable
  299. ;//     <o8.30>     PCENET: Ethernet block power/clock enable
  300. ;//     <o8.29>     PCGPDMA: GP DMA function power/clock enable
  301. ;//     <o8.28>     PCSDC: SD card interface power/clock enable
  302. ;//     <o8.27>     PCI2S: I2S interface power/clock enable
  303. ;//     <o8.26>     PCI2C2: I2C interface 2 power/clock enable
  304. ;//     <o8.25>     PCUART3: UART 3 power/clock enable
  305. ;//     <o8.24>     PCUART2: UART 2 power/clock enable
  306. ;//     <o8.23>     PCTIM3: Timer 3 power/clock enable
  307. ;//     <o8.22>     PCTIM2: Timer 2 power/clock enable
  308. ;//     <o8.21>     PCSSP0: SSP interface 0 power/clock enable
  309. ;//     <o8.19>     PCI2C1: I2C interface 1 power/clock enable
  310. ;//     <o8.14>     PCAN2: CAN controller 2 power/clock enable
  311. ;//     <o8.13>     PCAN1: CAN controller 1 power/clock enable
  312. ;//     <o8.12>     PCAD: A/D converter power/clock enable
  313. ;//     <o8.11>     PCEMC: External memory controller power/clock enable
  314. ;//     <o8.10>     PCSSP1: SSP interface 1 power/clock enable
  315. ;//     <o8.9>      PCRTC: RTC power/clock enable
  316. ;//     <o8.8>      PCSPI: SPI interface power/clock enable
  317. ;//     <o8.7>      PCI2C0: I2C interface 0 power/clock enable
  318. ;//     <o8.6>      PCPWM1: PWM 1 power/clock enable
  319. ;//     <o8.4>      PCUART1: UART 1 power/clock enable
  320. ;//     <o8.3>      PCUART0: UART 0 power/clock enable
  321. ;//     <o8.2>      PCTIM1: Timer/Counter 1 power/clock enable
  322. ;//     <o8.1>      PCTIM0: Timer/Counter 0 power/clock enable
  323. ;//   </h>
  324. ;// </e>
  325. CLOCK_SETUP     EQU     1
  326. SCS_Val         EQU     0x00000020
  327. CLKSRCSEL_Val   EQU     0x00000001
  328. PLLCFG_Val      EQU     0x0000000B
  329. CCLKCFG_Val     EQU     0x00000005
  330. USBCLKCFG_Val   EQU     0x00000005
  331. PCLKSEL0_Val    EQU     0x00000000
  332. PCLKSEL1_Val    EQU     0x00000000
  333. PCONP_Val       EQU     0x04280FDE
  334. ;----------------------- Memory Accelerator Module (MAM) Definitions -----------
  335. MAM_BASE        EQU     0xE01FC000      ; MAM Base Address
  336. MAMCR_OFS       EQU     0x00            ; MAM Control Offset
  337. MAMTIM_OFS      EQU     0x04            ; MAM Timing Offset
  338. ;// <e> MAM Setup
  339. ;//   <o1.0..1>   MAM Control
  340. ;//               <0=> Disabled
  341. ;//               <1=> Partially Enabled
  342. ;//               <2=> Fully Enabled
  343. ;//               <i> Mode
  344. ;//   <o2.0..2>   MAM Timing
  345. ;//               <0=> Reserved  <1=> 1   <2=> 2   <3=> 3
  346. ;//               <4=> 4         <5=> 5   <6=> 6   <7=> 7
  347. ;//               <i> Fetch Cycles
  348. ;// </e>
  349. MAM_SETUP       EQU     1
  350. MAMCR_Val       EQU     0x00000002
  351. MAMTIM_Val      EQU     0x00000004
  352. ;----------------------- Pin Connect Block Definitions -------------------------
  353. PCB_BASE            EQU 0xE002C000      ; PCB Base Address
  354. PINSEL0_OFS         EQU 0x00            ; PINSEL0  Address Offset
  355. PINSEL1_OFS         EQU 0x04            ; PINSEL1  Address Offset
  356. PINSEL2_OFS         EQU 0x08            ; PINSEL2  Address Offset
  357. PINSEL3_OFS         EQU 0x0C            ; PINSEL3  Address Offset
  358. PINSEL4_OFS         EQU 0x10            ; PINSEL4  Address Offset
  359. PINSEL5_OFS         EQU 0x14            ; PINSEL5  Address Offset
  360. PINSEL6_OFS         EQU 0x18            ; PINSEL6  Address Offset
  361. PINSEL7_OFS         EQU 0x1C            ; PINSEL7  Address Offset
  362. PINSEL8_OFS         EQU 0x20            ; PINSEL8  Address Offset
  363. PINSEL9_OFS         EQU 0x24            ; PINSEL9  Address Offset
  364. PINSEL10_OFS        EQU 0x28            ; PINSEL10 Address Offset
  365. ;----------------------- External Memory Controller (EMC) Definitons -----------
  366. EMC_BASE            EQU 0xFFE08000      ; EMC Base Address
  367. EMC_CTRL_OFS        EQU 0x000           ; EMCControl
  368. EMC_STAT_OFS        EQU 0x004           ; EMCStatus
  369. EMC_CONFIG_OFS      EQU 0x008           ; EMCConfig
  370. EMC_STA_CFG0_OFS    EQU 0x200           ; EMCStaticConfig0
  371. EMC_STA_WWEN0_OFS   EQU 0x204           ; EMCStaticWaitWen0
  372. EMC_STA_WOEN0_OFS   EQU 0x208           ; EMCStaticWaitOen0
  373. EMC_STA_WRD0_OFS    EQU 0x20C           ; EMCStaticWaitRd0
  374. EMC_STA_WPAGE0_OFS  EQU 0x210           ; EMCStaticWaitPage0
  375. EMC_STA_WWR0_OFS    EQU 0x214           ; EMCStaticWaitWr0
  376. EMC_STA_WTURN0_OFS  EQU 0x218           ; EMCStaticWaitTurn0
  377. EMC_STA_CFG1_OFS    EQU 0x220           ; EMCStaticConfig1
  378. EMC_STA_WWEN1_OFS   EQU 0x224           ; EMCStaticWaitWen1
  379. EMC_STA_WOEN1_OFS   EQU 0x228           ; EMCStaticWaitOen1
  380. EMC_STA_WRD1_OFS    EQU 0x22C           ; EMCStaticWaitRd1
  381. EMC_STA_WPAGE1_OFS  EQU 0x230           ; EMCStaticWaitPage1
  382. EMC_STA_WWR1_OFS    EQU 0x234           ; EMCStaticWaitWr1
  383. EMC_STA_WTURN1_OFS  EQU 0x238           ; EMCStaticWaitTurn1
  384. EMC_STA_EXT_W_OFS   EQU 0x880           ; EMCStaticExtendedWait
  385. BUFEN_Const         EQU (1 << 19)       ; Buffer enable bit
  386. EMC_PCONP_Const     EQU (1 << 11)       ; PCONP val to enable power for EMC
  387. ; External Memory Pins definitions
  388. ; pin functions for external memory interfacing
  389. EMC_PINSEL6_Val     EQU 0x00005555      ; D0 .. D7
  390. EMC_PINSEL8_Val     EQU 0x55555555      ; A0 .. A15
  391. EMC_PINSEL9_Val     EQU 0x50090000;     ; !OE, !WE (BLS0 because of errata), !CS0, !CS1
  392. ;//     External Memory Controller Setup (EMC) ---------------------------------
  393. ;// <e> External Memory Controller Setup (EMC)
  394. EMC_SETUP           EQU 1
  395. ;//   <h> EMC Control Register (EMCControl)
  396. ;//     <i> Controls operation of the memory controller
  397. ;//     <o0.2> L: Low-power mode enable
  398. ;//     <o0.1> M: Address mirror enable
  399. ;//     <o0.0> E: EMC enable
  400. ;//   </h>
  401. EMC_CTRL_Val        EQU 0x00000001
  402. ;//   <h> EMC Configuration Register (EMCConfig)
  403. ;//     <o0.0> Endian mode
  404. ;//       <0=> Little-endian
  405. ;//       <1=> Big-endian
  406. ;//   </h>
  407. EMC_CONFIG_Val      EQU 0x00000000
  408. ;//       Configure External Bus Behaviour for Static CS0 Area -----------------
  409. ;//   <e> Configure External Bus Behaviour for Static CS0 Area
  410. EMC_STACS0_SETUP    EQU 1
  411. ;//     <h> Static Memory Configuration Register (EMCStaticConfig0)
  412. ;//       <i> Defines the configuration information for the static memory CS0
  413. ;//       <o0.20> WP: Write protect
  414. ;//       <o0.19> B: Write buffer enable
  415. ;//       <o0.8> EW: Extended wait enable
  416. ;//       <o0.6> PC: Chip select polarity
  417. ;//         <0=> Active LOW chip select
  418. ;//         <1=> Active HIGH chip select
  419. ;//       <o0.3> PM: Async page mode enable
  420. ;//       <o0.0..1> MW: Memory width
  421. ;//         <0=> 8 bit
  422. ;//         <1=> 16 bit
  423. ;//         <2=> 32 bit
  424. ;//     </h>
  425. EMC_STA_CFG0_Val    EQU 0x00000000
  426. ;//     <h> Static Memory Write Enable Delay Register (EMCStaticWaitWen0)
  427. ;//       <i> Selects the delay from CS0 to write enable
  428. ;//       <o.0..3> WAITWEN: Wait write enable <1-16> <#-1>
  429. ;//         <i> The delay is in CCLK cycles
  430. ;//     </h>
  431. EMC_STA_WWEN0_Val   EQU 0x00000002
  432. ;//     <h> Static Memory Output Enable Delay register (EMCStaticWaitOen0)
  433. ;//       <i> Selects the delay from CS0 or address change, whichever is later, to output enable
  434. ;//       <o.0..3> WAITOEN: Wait output enable <0-15>
  435. ;//         <i> The delay is in CCLK cycles
  436. ;//     </h>
  437. EMC_STA_WOEN0_Val   EQU 0x00000002
  438.                                       
  439. ;//     <h> Static Memory Read Delay Register (EMCStaticWaitRd0)
  440. ;//       <i> Selects the delay from CS0 to a read access
  441. ;//       <o.0..4> WAITRD: Non-page mode read wait states or asynchronous page mode read first access wait states <1-32> <#-1>
  442. ;//         <i> The delay is in CCLK cycles
  443. ;//     </h>
  444. EMC_STA_WRD0_Val    EQU 0x0000001F
  445. ;//     <h> Static Memory Page Mode Read Delay Register (EMCStaticWaitPage0)
  446. ;//       <i> Selects the delay for asynchronous page mode sequential accesses for CS0
  447. ;//       <o.0..4> WAITPAGE: Asynchronous page mode read after the first read wait states <1-32> <#-1>
  448. ;//         <i> The delay is in CCLK cycles
  449. ;//     </h>
  450. EMC_STA_WPAGE0_Val  EQU 0x0000001F
  451. ;//     <h> Static Memory Write Delay Register (EMCStaticWaitWr0)
  452. ;//       <i> Selects the delay from CS0 to a write access
  453. ;//       <o.0..4> WAITWR: Write wait states <2-33> <#-2>
  454. ;//         <i> The delay is in CCLK cycles
  455. ;//     </h>
  456. EMC_STA_WWR0_Val    EQU 0x0000001F
  457. ;//     <h> Static Memory Turn Round Delay Register (EMCStaticWaitTurn0)
  458. ;//       <i> Selects the number of bus turnaround cycles for CS0
  459. ;//       <o.0..4> WAITTURN: Bus turnaround cycles <1-16> <#-1>
  460. ;//         <i> The delay is in CCLK cycles
  461. ;//     </h>
  462. EMC_STA_WTURN0_Val  EQU 0x0000000F
  463. ;//   </e> End of Static Setup for Static CS0 Area
  464. ;//       Configure External Bus Behaviour for Static CS1 Area -----------------
  465. ;//   <e> Configure External Bus Behaviour for Static CS1 Area
  466. EMC_STACS1_SETUP    EQU 0
  467. ;//     <h> Static Memory Configuration Register (EMCStaticConfig1)
  468. ;//       <i> Defines the configuration information for the static memory CS1
  469. ;//       <o0.20> WP: Write protect
  470. ;//       <o0.19> B: Write buffer enable
  471. ;//       <o0.8> EW: Extended wait enable
  472. ;//       <o0.6> PC: Chip select polarity
  473. ;//         <0=> Active LOW chip select
  474. ;//         <1=> Active HIGH chip select
  475. ;//       <o0.3> PM: Async page mode enable
  476. ;//       <o0.0..1> MW: Memory width
  477. ;//         <0=> 8 bit
  478. ;//         <1=> 16 bit
  479. ;//         <2=> 32 bit
  480. ;//     </h>
  481. EMC_STA_CFG1_Val    EQU 0x00000000
  482. ;//     <h> Static Memory Write Enable Delay Register (EMCStaticWaitWen1)
  483. ;//       <i> Selects the delay from CS1 to write enable
  484. ;//       <o.0..3> WAITWEN: Wait write enable <1-16> <#-1>
  485. ;//         <i> The delay is in CCLK cycles
  486. ;//     </h>
  487. EMC_STA_WWEN1_Val   EQU 0x00000000
  488. ;//     <h> Static Memory Output Enable Delay register (EMCStaticWaitOen1)
  489. ;//       <i> Selects the delay from CS1 or address change, whichever is later, to output enable
  490. ;//       <o.0..3> WAITOEN: Wait output enable <0-15>
  491. ;//         <i> The delay is in CCLK cycles
  492. ;//     </h>
  493. EMC_STA_WOEN1_Val   EQU 0x00000000
  494.                                       
  495. ;//     <h> Static Memory Read Delay Register (EMCStaticWaitRd1)
  496. ;//       <i> Selects the delay from CS1 to a read access
  497. ;//       <o.0..4> WAITRD: Non-page mode read wait states or asynchronous page mode read first access wait states <1-32> <#-1>
  498. ;//         <i> The delay is in CCLK cycles
  499. ;//     </h>
  500. EMC_STA_WRD1_Val    EQU 0x0000001F
  501. ;//     <h> Static Memory Page Mode Read Delay Register (EMCStaticWaitPage0)
  502. ;//       <i> Selects the delay for asynchronous page mode sequential accesses for CS1
  503. ;//       <o.0..4> WAITPAGE: Asynchronous page mode read after the first read wait states <1-32> <#-1>
  504. ;//         <i> The delay is in CCLK cycles
  505. ;//     </h>
  506. EMC_STA_WPAGE1_Val  EQU 0x0000001F
  507. ;//     <h> Static Memory Write Delay Register (EMCStaticWaitWr1)
  508. ;//       <i> Selects the delay from CS1 to a write access
  509. ;//       <o.0..4> WAITWR: Write wait states <2-33> <#-2>
  510. ;//         <i> The delay is in CCLK cycles
  511. ;//     </h>
  512. EMC_STA_WWR1_Val    EQU  0x0000001F
  513. ;//     <h> Static Memory Turn Round Delay Register (EMCStaticWaitTurn1)
  514. ;//       <i> Selects the number of bus turnaround cycles for CS1
  515. ;//       <o.0..4> WAITTURN: Bus turnaround cycles <1-16> <#-1>
  516. ;//         <i> The delay is in CCLK cycles
  517. ;//     </h>
  518. EMC_STA_WTURN1_Val  EQU 0x0000000F
  519. ;//   </e> End of Static Setup for Static CS1 Area
  520. ;//   <h> Static Memory Extended Wait Register (EMCStaticExtendedWait)
  521. ;//     <i> Time long static memory read and write transfers
  522. ;//     <o.0..9> EXTENDEDWAIT: Extended wait time out <1-64><#-1>
  523. ;//       <i> The delay is in (16 * CCLK) cycles
  524. ;//   </h>
  525. EMC_STA_EXT_W_Val   EQU 0x00000000
  526. ;// </e> End of EMC Setup
  527. ; Area Definition and Entry Point
  528. ;  Startup Code must be linked first at Address at which it expects to run.
  529.                 AREA    RESET, CODE, READONLY
  530.                 ARM
  531. ; Exception Vectors
  532. ;  Mapped to Address 0.
  533. ;  Absolute addressing mode must be used.
  534. ;  Dummy Handlers are implemented as infinite loops which can be modified.
  535. Vectors         LDR     PC, Reset_Addr         
  536.                 LDR     PC, Undef_Addr
  537.                 LDR     PC, SWI_Addr
  538.                 LDR     PC, PAbt_Addr
  539.                 LDR     PC, DAbt_Addr
  540.                 NOP                            ; Reserved Vector 
  541. ;               LDR     PC, IRQ_Addr
  542.                 LDR     PC, [PC, #-0x0120]     ; Vector from VicVectAddr
  543.                 LDR     PC, FIQ_Addr
  544. Reset_Addr      DCD     Reset_Handler
  545. Undef_Addr      DCD     Undef_Handler
  546. SWI_Addr        DCD     SWI_Handler
  547. PAbt_Addr       DCD     PAbt_Handler
  548. DAbt_Addr       DCD     DAbt_Handler
  549.                 DCD     0                      ; Reserved Address 
  550. IRQ_Addr        DCD     IRQ_Handler
  551. FIQ_Addr        DCD     FIQ_Handler
  552. Undef_Handler   B       Undef_Handler
  553. SWI_Handler     B       SWI_Handler
  554. PAbt_Handler    B       PAbt_Handler
  555. DAbt_Handler    B       DAbt_Handler
  556. IRQ_Handler     B       IRQ_Handler
  557. FIQ_Handler     B       FIQ_Handler
  558. ; Reset Handler
  559.                 EXPORT  Reset_Handler
  560. Reset_Handler   
  561. ; Clock Setup ------------------------------------------------------------------
  562.                 IF      (:LNOT:(:DEF:NO_CLOCK_SETUP)):LAND:(CLOCK_SETUP != 0)
  563.                 LDR     R0, =SCB_BASE
  564.                 MOV     R1, #0xAA
  565.                 MOV     R2, #0x55
  566. ;  Configure and Enable PLL
  567.                 LDR     R3, =SCS_Val          ; Enable main oscillator
  568.                 STR     R3, [R0, #SCS_OFS] 
  569.                 IF      (SCS_Val:AND:OSCEN) != 0  
  570. OSC_Loop        LDR     R3, [R0, #SCS_OFS]    ; Wait for main osc stabilize
  571.                 ANDS    R3, R3, #OSCSTAT
  572.                 BEQ     OSC_Loop
  573.                 ENDIF
  574.                 LDR     R3, =CLKSRCSEL_Val    ; Select PLL source clock
  575.                 STR     R3, [R0, #CLKSRCSEL_OFS] 
  576.                 LDR     R3, =PLLCFG_Val
  577.                 STR     R3, [R0, #PLLCFG_OFS] 
  578.                 STR     R1, [R0, #PLLFEED_OFS]
  579.                 STR     R2, [R0, #PLLFEED_OFS]
  580.                 MOV     R3, #PLLCON_PLLE
  581.                 STR     R3, [R0, #PLLCON_OFS]
  582.                 STR     R1, [R0, #PLLFEED_OFS]
  583.                 STR     R2, [R0, #PLLFEED_OFS]
  584. ;  Wait until PLL Locked
  585. PLL_Loop        LDR     R3, [R0, #PLLSTAT_OFS]
  586.                 ANDS    R3, R3, #PLLSTAT_PLOCK
  587.                 BEQ     PLL_Loop
  588. M_N_Lock        LDR     R3, [R0, #PLLSTAT_OFS]
  589.                 LDR     R4, =(PLLSTAT_M:OR:PLLSTAT_N)
  590.                 AND     R3, R3, R4
  591.                 LDR     R4, =PLLCFG_Val
  592.                 EORS    R3, R3, R4
  593.                 BNE     M_N_Lock
  594. ;  Setup CPU clock divider
  595.                 MOV     R3, #CCLKCFG_Val
  596.                 STR     R3, [R0, #CCLKCFG_OFS]
  597. ;  Setup USB clock divider
  598.                 LDR     R3, =USBCLKCFG_Val
  599.                 STR     R3, [R0, #USBCLKCFG_OFS]
  600. ;  Setup Peripheral Clock
  601.                 LDR     R3, =PCLKSEL0_Val
  602.                 STR     R3, [R0, #PCLKSEL0_OFS]
  603.                 LDR     R3, =PCLKSEL1_Val
  604.                 STR     R3, [R0, #PCLKSEL1_OFS]
  605. ;  Switch to PLL Clock
  606.                 MOV     R3, #(PLLCON_PLLE:OR:PLLCON_PLLC)
  607.                 STR     R3, [R0, #PLLCON_OFS]
  608.                 STR     R1, [R0, #PLLFEED_OFS]
  609.                 STR     R2, [R0, #PLLFEED_OFS]
  610.                 LDR     R4, =PCONP_Val        ; Enable Peripheral Clocks
  611.                 STR     R4, [R0, #PCONP_OFS]
  612.                 ENDIF   ; CLOCK_SETUP
  613. ; Setup Memory Accelerator Module ----------------------------------------------
  614.                 IF      MAM_SETUP != 0
  615.                 LDR     R0, =MAM_BASE
  616.                 MOV     R1, #MAMTIM_Val
  617.                 STR     R1, [R0, #MAMTIM_OFS] 
  618.                 MOV     R1, #MAMCR_Val
  619.                 STR     R1, [R0, #MAMCR_OFS] 
  620.                 ENDIF   ; MAM_SETUP
  621. ; Setup External Memory Controller ---------------------------------------------
  622.                 IF      (:DEF:NO_EMC_SETUP):LOR:(EMC_SETUP != 0)
  623.                 LDR     R0, =EMC_BASE
  624.                 LDR     R1, =SCB_BASE
  625.                 LDR     R2, =PCB_BASE
  626.                 LDR     R4, [R1, #PCONP_OFS]
  627.                 ORR     R4, R4, #EMC_PCONP_Const  ; Enable EMC clock
  628.                 STR     R4, [R1, #PCONP_OFS]
  629.                 LDR     R4, =EMC_CTRL_Val
  630.                 STR     R4, [R0, #EMC_CTRL_OFS]
  631.                 LDR     R4, =EMC_CONFIG_Val
  632.                 STR     R4, [R0, #EMC_CONFIG_OFS]
  633. ;  Setup pin functions for External Bus functionality
  634.                 LDR     R4, =EMC_PINSEL6_Val
  635.                 STR     R4, [R2, #PINSEL6_OFS]
  636.                 LDR     R4, =EMC_PINSEL8_Val
  637.                 STR     R4, [R2, #PINSEL8_OFS]
  638.                 LDR     R4, =EMC_PINSEL9_Val
  639.                 STR     R4, [R2, #PINSEL9_OFS]
  640.                 LDR     R6, =1200000              ; Number of cycles to delay
  641. Wait_0          SUBS    R6, R6, #1                ; Delay ~100 ms @ proc clk 48 MHz
  642.                 BNE     Wait_0
  643.                 IF      (EMC_STACS0_SETUP != 0)
  644.                 LDR     R4, =EMC_STA_CFG0_Val
  645.                 STR     R4, [R0, #EMC_STA_CFG0_OFS]
  646.                 LDR     R4, =EMC_STA_WWEN0_Val
  647.                 STR     R4, [R0, #EMC_STA_WWEN0_OFS]
  648.                 LDR     R4, =EMC_STA_WOEN0_Val
  649.                 STR     R4, [R0, #EMC_STA_WOEN0_OFS]
  650.                 LDR     R4, =EMC_STA_WRD0_Val
  651.                 STR     R4, [R0, #EMC_STA_WRD0_OFS]
  652.                 LDR     R4, =EMC_STA_WPAGE0_Val
  653.                 STR     R4, [R0, #EMC_STA_WPAGE0_OFS]
  654.                 LDR     R4, =EMC_STA_WWR0_Val
  655.                 STR     R4, [R0, #EMC_STA_WWR0_OFS]
  656.                 LDR     R4, =EMC_STA_WTURN0_Val
  657.                 STR     R4, [R0, #EMC_STA_WTURN0_OFS]
  658.                 ENDIF
  659.                 IF      (EMC_STACS1_SETUP != 0)
  660.                 LDR     R4, =EMC_STA_CFG1_Val
  661.                 STR     R4, [R0, #EMC_STA_CFG1_OFS]
  662.                 LDR     R4, =EMC_STA_WWEN1_Val
  663.                 STR     R4, [R0, #EMC_STA_WWEN1_OFS]
  664.                 LDR     R4, =EMC_STA_WOEN1_Val
  665.                 STR     R4, [R0, #EMC_STA_WOEN1_OFS]
  666.                 LDR     R4, =EMC_STA_WRD1_Val
  667.                 STR     R4, [R0, #EMC_STA_WRD1_OFS]
  668.                 LDR     R4, =EMC_STA_WPAGE1_Val
  669.                 STR     R4, [R0, #EMC_STA_WPAGE1_OFS]
  670.                 LDR     R4, =EMC_STA_WWR1_Val
  671.                 STR     R4, [R0, #EMC_STA_WWR1_OFS]
  672.                 LDR     R4, =EMC_STA_WTURN1_Val
  673.                 STR     R4, [R0, #EMC_STA_WTURN1_OFS]
  674.                 ENDIF
  675.                 LDR     R6, =120000               ; Number of cycles to delay
  676. Wait_1          SUBS    R6, R6, #1                ; Delay ~10 ms @ proc clk 48 MHz
  677.                 BNE     Wait_1
  678.                 LDR     R4, =EMC_STA_EXT_W_Val
  679.                 LDR     R5, =EMC_STA_EXT_W_OFS
  680.                 ADD     R5, R5, R0
  681.                 STR     R4, [R5, #0]
  682.                 ENDIF   ; EMC_SETUP
  683. ; Copy Exception Vectors to Internal RAM ---------------------------------------
  684.                 IF      :DEF:RAM_INTVEC
  685.                 ADR     R8, Vectors         ; Source
  686.                 LDR     R9, =RAM_BASE       ; Destination
  687.                 LDMIA   R8!, {R0-R7}        ; Load Vectors 
  688.                 STMIA   R9!, {R0-R7}        ; Store Vectors 
  689.                 LDMIA   R8!, {R0-R7}        ; Load Handler Addresses 
  690.                 STMIA   R9!, {R0-R7}        ; Store Handler Addresses
  691.                 ENDIF
  692. ; Memory Mapping (when Interrupt Vectors are in RAM) ---------------------------
  693. MEMMAP          EQU     0xE01FC040          ; Memory Mapping Control
  694.                 IF      :DEF:REMAP
  695.                 LDR     R0, =MEMMAP
  696.                 IF      :DEF:EXTMEM_MODE
  697.                 MOV     R1, #3
  698.                 ELIF    :DEF:RAM_MODE
  699.                 MOV     R1, #2
  700.                 ELSE
  701.                 MOV     R1, #1
  702.                 ENDIF
  703.                 STR     R1, [R0]
  704.                 ENDIF
  705. ; Setup Stack for each mode ----------------------------------------------------
  706.                 LDR     R0, =Stack_Top
  707. ;  Enter Undefined Instruction Mode and set its Stack Pointer
  708.                 MSR     CPSR_c, #Mode_UND:OR:I_Bit:OR:F_Bit
  709.                 MOV     SP, R0
  710.                 SUB     R0, R0, #UND_Stack_Size
  711. ;  Enter Abort Mode and set its Stack Pointer
  712.                 MSR     CPSR_c, #Mode_ABT:OR:I_Bit:OR:F_Bit
  713.                 MOV     SP, R0
  714.                 SUB     R0, R0, #ABT_Stack_Size
  715. ;  Enter FIQ Mode and set its Stack Pointer
  716.                 MSR     CPSR_c, #Mode_FIQ:OR:I_Bit:OR:F_Bit
  717.                 MOV     SP, R0
  718.                 SUB     R0, R0, #FIQ_Stack_Size
  719. ;  Enter IRQ Mode and set its Stack Pointer
  720.                 MSR     CPSR_c, #Mode_IRQ:OR:I_Bit:OR:F_Bit
  721.                 MOV     SP, R0
  722.                 SUB     R0, R0, #IRQ_Stack_Size
  723. ;  Enter Supervisor Mode and set its Stack Pointer
  724.                 MSR     CPSR_c, #Mode_SVC:OR:I_Bit:OR:F_Bit
  725.                 MOV     SP, R0
  726.                 SUB     R0, R0, #SVC_Stack_Size
  727. ;  Enter User Mode and set its Stack Pointer
  728.                 MSR     CPSR_c, #Mode_USR
  729.                 IF      :DEF:__MICROLIB
  730.                 EXPORT __initial_sp
  731.                 ELSE
  732.                 MOV     SP, R0
  733.                 SUB     SL, SP, #USR_Stack_Size
  734.                 ENDIF
  735. ; Enter the C code -------------------------------------------------------------
  736.                 IMPORT  __main
  737.                 LDR     R0, =__main
  738.                 BX      R0
  739.                 IF      :DEF:__MICROLIB
  740.                 EXPORT  __heap_base
  741.                 EXPORT  __heap_limit
  742.                 ELSE
  743. ; User Initial Stack & Heap
  744.                 AREA    |.text|, CODE, READONLY
  745.                 IMPORT  __use_two_region_memory
  746.                 EXPORT  __user_initial_stackheap
  747. __user_initial_stackheap
  748.                 LDR     R0, =  Heap_Mem
  749.                 LDR     R1, =(Stack_Mem + USR_Stack_Size)
  750.                 LDR     R2, = (Heap_Mem +      Heap_Size)
  751.                 LDR     R3, = Stack_Mem
  752.                 BX      LR
  753.                 ENDIF
  754.                 END