lpc8xx.pp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. unit lpc8xx;
  2. {$goto on}
  3. {$define lpc8xx}
  4. interface
  5. {$PACKRECORDS 2}
  6. const
  7. //------------------------- Cortex-M0 Processor Exceptions Numbers -------------------------
  8. Reset_IRQn = -15; // 1 Reset Vector, invoked on Power up and warm reset
  9. NonMaskableInt_IRQn = -14; // 2 Non Maskable Interrupt
  10. HardFault_IRQn = -13; // 3 Cortex-M0 Hard Fault Interrupt
  11. SVCall_IRQn = -5; // 11 Cortex-M0 SV Call Interrupt
  12. PendSV_IRQn = -2; // 14 Cortex-M0 Pend SV Interrupt
  13. SysTick_IRQn = -1; // 15 Cortex-M0 System Tick Interrupt
  14. //------------------------- LPC8xx Specific Interrupt Numbers -------------------------
  15. SPI0_IRQn = 0; // SPI0
  16. SPI1_IRQn = 1; // SPI1
  17. UART0_IRQn = 3; // USART0
  18. UART1_IRQn = 4; // USART1
  19. UART2_IRQn = 5; // USART2
  20. I2C_IRQn = 8; // I2C
  21. SCT_IRQn = 9; // SCT
  22. MRT_IRQn = 10; // MRT
  23. CMP_IRQn = 11; // CMP
  24. WDT_IRQn = 12; // WDT
  25. BOD_IRQn = 13; // BOD
  26. WKT_IRQn = 15; // WKT Interrupt
  27. PININT0_IRQn = 24; // External Interrupt 0
  28. PININT1_IRQn = 25; // External Interrupt 1
  29. PININT2_IRQn = 26; // External Interrupt 2
  30. PININT3_IRQn = 27; // External Interrupt 3
  31. PININT4_IRQn = 28; // External Interrupt 4
  32. PININT5_IRQn = 29; // External Interrupt 5
  33. PININT6_IRQn = 30; // External Interrupt 6
  34. PININT7_IRQn = 31; // External Interrupt 7
  35. type
  36. { ------------- System Control (SYSCON) ------------- }
  37. TSYSCON_Registers = record
  38. SYSMEMREMAP : longword;
  39. PRESETCTRL : longword;
  40. SYSPLLCTRL : longword;
  41. SYSPLLSTAT : longword;
  42. RESERVED0 : array [0 .. 3] of longword;
  43. SYSOSCCTRL : longword;
  44. WDTOSCCTRL : longword;
  45. RESERVED1 : array [0 .. 1] of longword;
  46. SYSRSTSTAT : longword;
  47. RESERVED2 : array [0 .. 2] of longword;
  48. SYSPLLCLKSEL : longword;
  49. SYSPLLCLKUEN : longword;
  50. RESERVED3 : array [0 .. 9] of longword;
  51. MAINCLKSEL : longword;
  52. MAINCLKUEN : longword;
  53. SYSAHBCLKDIV : longword;
  54. RESERVED4 : longword;
  55. SYSAHBCLKCTRL: longword;
  56. RESERVED5 : array [0 .. 3] of longword;
  57. UARTCLKDIV : longword;
  58. RESERVED6 : array [0 .. 17] of longword;
  59. CLKOUTSEL : longword;
  60. CLKOUTUEN : longword;
  61. CLKOUTDIV : longword;
  62. RESERVED7 : longword;
  63. UARTFRGDIV : longword;
  64. UARTFRGMULT : longword;
  65. RESERVED8 : longword;
  66. EXTTRACECMD : longword;
  67. PIOPORCAP0 : longword;
  68. RESERVED9 : array [0 .. 11] of longword;
  69. IOCONCLKDIV : array [0 .. 6] of longword;
  70. BODCTRL : longword;
  71. SYSTCKCAL : longword;
  72. RESERVED10 : array [0 .. 5] of longword;
  73. IRQLATENCY : longword;
  74. NMISRC : longword;
  75. PINTSEL : array [0 .. 7] of longword;
  76. RESERVED11 : array [0 .. 26] of longword;
  77. STARTERP0 : longword;
  78. RESERVED12 : array [0 .. 2] of longword;
  79. STARTERP1 : longword;
  80. RESERVED13 : array [0 .. 5] of longword;
  81. PDSLEEPCFG : longword;
  82. PDAWAKECFG : longword;
  83. PDRUNCFG : longword;
  84. RESERVED14 : array [0 .. 109] of longword;
  85. DEVICE_ID : longword;
  86. end;
  87. { ------------- Pin Connect Block (IOCON) ------------- }
  88. TIOCON_Registers = record
  89. PIO0_17 : longword;
  90. PIO0_13 : longword;
  91. PIO0_12 : longword;
  92. PIO0_5 : longword;
  93. PIO0_4 : longword;
  94. PIO0_3 : longword;
  95. PIO0_2 : longword;
  96. PIO0_11 : longword;
  97. PIO0_10 : longword;
  98. PIO0_16 : longword;
  99. PIO0_15 : longword;
  100. PIO0_1 : longword;
  101. RESERVED0: longword;
  102. PIO0_9 : longword;
  103. PIO0_8 : longword;
  104. PIO0_7 : longword;
  105. PIO0_6 : longword;
  106. PIO0_0 : longword;
  107. PIO0_14 : longword;
  108. end;
  109. { ------------- Flash Controller (FLASHCTRL) ------------- }
  110. TFLASHCTRL_Registers = record
  111. RESERVED0: array [0 .. 3] of longword;
  112. FLASHCFG : longword;
  113. RESERVED1: array [0 .. 2] of longword;
  114. FMSSTART : longword;
  115. FMSSTOP : longword;
  116. RESERVED2: longword;
  117. FMSW0 : longword;
  118. end;
  119. { ------------- Power Management Unit (PMU) ------------- }
  120. TPMU_Registers = record
  121. PCON : longword;
  122. GPREG0 : longword;
  123. GPREG1 : longword;
  124. GPREG2 : longword;
  125. GPREG3 : longword;
  126. DPDCTRL: longword;
  127. end;
  128. { ------------- Switch Matrix Register (SWM) ------------- }
  129. TSWM_Registers = record
  130. PINASSIGN : array [0 .. 8] of longword;
  131. RESERVED0 : array [0 .. 102] of longword;
  132. PINENABLE0: longword;
  133. end;
  134. { ------------- General Purpose Input/Output (GPIO) ------------- }
  135. TGPIOPORT_Registers = record
  136. B0 : array [0 .. 17] of byte;
  137. RESERVED0: array [0 .. 2038] of word;
  138. W0 : array [0 .. 17] of longword;
  139. RESERVED1: array [0 .. 1005] of longword;
  140. DIR0 : longword;
  141. RESERVED2: array [0 .. 30] of longword;
  142. MASK0 : longword;
  143. RESERVED3: array [0 .. 30] of longword;
  144. PIN0 : longword;
  145. RESERVED4: array [0 .. 30] of longword;
  146. MPIN0 : longword;
  147. RESERVED5: array [0 .. 30] of longword;
  148. SET0 : longword;
  149. RESERVED6: array [0 .. 30] of longword;
  150. CLR0 : longword;
  151. RESERVED7: array [0 .. 30] of longword;
  152. NOT0 : longword;
  153. end;
  154. { ------------- Pin interrupts/pattern match engine (PIN_INT) ------------- }
  155. TPININT_Registers = record
  156. ISEL : longword;
  157. IENR : longword;
  158. SIENR : longword;
  159. CIENR : longword;
  160. IENF : longword;
  161. SIENF : longword;
  162. CIENF : longword;
  163. RISE : longword;
  164. FALL : longword;
  165. IST : longword;
  166. PMCTRL: longword;
  167. PMSRC : longword;
  168. PMCFG : longword;
  169. end;
  170. { ------------- CRC Engine (CRC) ------------- }
  171. TCRC_Registers = record
  172. MODE: longword;
  173. SEED: longword;
  174. SUM : longword;
  175. end;
  176. { ------------- Comparator (CMP) ------------- }
  177. TCMP_Registers = record
  178. CTRL: longword;
  179. LAD : longword;
  180. end;
  181. { ------------- Wakeup Timer (WKT) ------------- }
  182. TWKT_Registers = record
  183. CTRL : longword;
  184. RESERVED0: array [0 .. 1] of longword;
  185. COUNT : longword;
  186. end;
  187. { ------------- Multi-Rate Timer(MRT) ------------- }
  188. TMRTChannel = record
  189. INTVAL: longword;
  190. TIMER : longword;
  191. CTRL : longword;
  192. STAT : longword;
  193. end;
  194. TMRT_Registers = record
  195. CHANNEL : array [0 .. 3] of TMRTChannel;
  196. RESERVED0: array [0 .. 0] of longword;
  197. IDLE_CH : longword;
  198. IRQ_FLAG : longword;
  199. end;
  200. { ------------- Universal Asynchronous Receiver Transmitter (USART) ------------- }
  201. TUSART_Registers = record
  202. CFG : longword;
  203. CTRL : longword;
  204. STAT : longword;
  205. INTENSET : longword;
  206. INTENCLR : longword;
  207. RXDATA : longword;
  208. RXDATA_STAT: longword;
  209. TXDATA : longword;
  210. BRG : longword;
  211. INTSTAT : longword;
  212. end;
  213. { ------------- Synchronous Serial Interface Controller (SPI) ------------- }
  214. TSPI_Registers = record
  215. CFG : longword;
  216. DLY : longword;
  217. STAT : longword;
  218. INTENSET: longword;
  219. INTENCLR: longword;
  220. RXDAT : longword;
  221. TXDATCTL: longword;
  222. TXDAT : longword;
  223. TXCTRL : longword;
  224. _DIV : longword;
  225. INTSTAT : longword;
  226. end;
  227. { ------------- Inter-Integrated Circuit (I2C) ------------- }
  228. TI2C_Registers = record
  229. CFG : longword;
  230. STAT : longword;
  231. INTENSET : longword;
  232. INTENCLR : longword;
  233. TIMEOUT : longword;
  234. _DIV : longword;
  235. INTSTAT : longword;
  236. RESERVED0: longword;
  237. MSTCTL : longword;
  238. MSTTIME : longword;
  239. MSTDAT : longword;
  240. RESERVED1: array [0 .. 4] of longword;
  241. SLVCTL : longword;
  242. SLVDAT : longword;
  243. SLVADR0 : longword;
  244. SLVADR1 : longword;
  245. SLVADR2 : longword;
  246. SLVADR3 : longword;
  247. SLVQUAL0 : longword;
  248. RESERVED2: array [0 .. 8] of longword;
  249. MONRXDAT : longword;
  250. end;
  251. { ------------- State Configurable Timer (SCT) ------------- }
  252. const
  253. CONFIG_SCT_nEV = 6;
  254. { Number of match/compare registers }
  255. CONFIG_SCT_nRG = 5;
  256. { Number of outputs }
  257. CONFIG_SCT_nOU = 4;
  258. type
  259. TSCTState = record
  260. STATE : longword;
  261. CTRL : longword;
  262. end;
  263. TSCTSet = record
  264. _SET : longword;
  265. CLR : longword;
  266. end;
  267. type
  268. TSCT_Registers = record
  269. CONFIG : longword;
  270. CTRL : longword;
  271. LIMIT : longword;
  272. HALT : longword;
  273. STOP : longword;
  274. START : longword;
  275. RESERVED1 : array [0 .. 9] of longword;
  276. COUNT : longword;
  277. STATE : longword;
  278. INPUT : longword;
  279. REGMODE : longword;
  280. OUTPUT : longword;
  281. OUTPUTDIRCTRL : longword;
  282. RES : longword;
  283. RESERVED2 : array [0 .. 36] of longword;
  284. EVEN : longword;
  285. EVFLAG : longword;
  286. CONEN : longword;
  287. CONFLAG : longword;
  288. MATCH_CAP : array [0 .. (CONFIG_SCT_nRG) - 1] of longword;
  289. RESERVED3 : array [0 .. (32 - CONFIG_SCT_nRG) - 1] of longword;
  290. MATCHREL_CAPCTRL: array [0 .. (CONFIG_SCT_nRG) - 1] of longword;
  291. RESERVED6 : array [0 .. (32 - CONFIG_SCT_nRG) - 1] of longword;
  292. EVENT : array [0 .. (CONFIG_SCT_nEV) - 1] of TSCTState;
  293. RESERVED9 : array [0 .. (128 - (2 * CONFIG_SCT_nEV)) - 1] of longword;
  294. _OUT : array [0 .. (CONFIG_SCT_nOU) - 1] of TSCTSet;
  295. end;
  296. { ------------- Watchdog Timer (WDT) ------------- }
  297. TWDT_Registers = record
  298. _MOD : longword;
  299. TC : longword;
  300. FEED : longword;
  301. TV : longword;
  302. RESERVED0: longword;
  303. WARNINT : longword;
  304. WINDOW : longword;
  305. end;
  306. { **************************************************************************** }
  307. { Peripheral memory map }
  308. { **************************************************************************** }
  309. const
  310. { Base addresses }
  311. LPC_FLASH_BASE = $00000000;
  312. LPC_RAM_BASE = $10000000;
  313. LPC_ROM_BASE = $1FFF0000;
  314. LPC_APB0_BASE = $40000000;
  315. LPC_AHB_BASE = $50000000;
  316. { APB0 peripherals }
  317. LPC_WDT_BASE = LPC_APB0_BASE + $00000;
  318. LPC_MRT_BASE = LPC_APB0_BASE + $04000;
  319. LPC_WKT_BASE = LPC_APB0_BASE + $08000;
  320. LPC_SWM_BASE = LPC_APB0_BASE + $0C000;
  321. LPC_PMU_BASE = LPC_APB0_BASE + $20000;
  322. LPC_CMP_BASE = LPC_APB0_BASE + $24000;
  323. LPC_FLASHCTRL_BASE = LPC_APB0_BASE + $40000;
  324. LPC_IOCON_BASE = LPC_APB0_BASE + $44000;
  325. LPC_SYSCON_BASE = LPC_APB0_BASE + $48000;
  326. LPC_I2C_BASE = LPC_APB0_BASE + $50000;
  327. LPC_SPI0_BASE = LPC_APB0_BASE + $58000;
  328. LPC_SPI1_BASE = LPC_APB0_BASE + $5C000;
  329. LPC_USART0_BASE = LPC_APB0_BASE + $64000;
  330. LPC_USART1_BASE = LPC_APB0_BASE + $68000;
  331. LPC_USART2_BASE = LPC_APB0_BASE + $6C000;
  332. { AHB peripherals }
  333. LPC_CRC_BASE = LPC_AHB_BASE + $00000;
  334. LPC_SCT_BASE = LPC_AHB_BASE + $04000;
  335. LPC_GPIO_PORT_BASE = $A0000000;
  336. LPC_PIN_INT_BASE = LPC_GPIO_PORT_BASE + $4000;
  337. // ****************************************************************************
  338. // Peripheral declaration
  339. // ****************************************************************************
  340. {$ALIGN 2}
  341. var
  342. WDT : TWDT_Registers absolute LPC_WDT_BASE;
  343. MRT : TMRT_Registers absolute LPC_MRT_BASE;
  344. WKT : TWKT_Registers absolute LPC_WKT_BASE;
  345. SWM : TSWM_Registers absolute LPC_SWM_BASE;
  346. PMU : TPMU_Registers absolute LPC_PMU_BASE;
  347. CMP : TCMP_Registers absolute LPC_CMP_BASE;
  348. FLASHCTRL: TFLASHCTRL_Registers absolute LPC_FLASHCTRL_BASE;
  349. IOCON : TIOCON_Registers absolute LPC_IOCON_BASE;
  350. SYSCON : TSysCon_Registers absolute LPC_SYSCON_BASE;
  351. I2C : TI2C_Registers absolute LPC_I2C_BASE;
  352. SPI0 : TSPI_Registers absolute LPC_SPI0_BASE;
  353. SPI1 : TSPI_Registers absolute LPC_SPI1_BASE;
  354. USART0 : TUSART_Registers absolute LPC_USART0_BASE;
  355. USART1 : TUSART_Registers absolute LPC_USART0_BASE;
  356. USART2 : TUSART_Registers absolute LPC_USART0_BASE;
  357. CRC : TCRC_Registers absolute LPC_CRC_BASE;
  358. SCT : TSCT_Registers absolute LPC_SCT_BASE;
  359. GPIO_PORT: TGPIOPort_Registers absolute LPC_GPIO_PORT_BASE;
  360. PIN_INT : TPININT_Registers absolute LPC_PIN_INT_BASE;
  361. implementation
  362. procedure NonMaskableInt_interrupt; external name 'NonMaskableInt_interrupt';
  363. procedure Hardfault_interrupt; external name 'Hardfault_interrupt';
  364. procedure Startup_Checksum; external name 'Startup_Checksum';
  365. procedure SVCall_interrupt; external name 'SVCall_interrupt';
  366. procedure PendSV_interrupt; external name 'PendSV_interrupt';
  367. procedure SysTick_interrupt; external name 'SysTick_interrupt';
  368. procedure SPI0_Interrupt; external name 'SPI0_Interrupt';
  369. procedure SPI1_Interrupt; external name 'SPI1_Interrupt';
  370. procedure UART0_Interrupt; external name 'UART0_Interrupt';
  371. procedure UART1_Interrupt; external name 'UART1_Interrupt';
  372. procedure UART2_Interrupt; external name 'UART2_Interrupt';
  373. procedure I2C_Interrupt; external name 'I2C_Interrupt';
  374. procedure SCT_Interrupt; external name 'SCT_Interrupt';
  375. procedure MRT_Interrupt; external name 'MRT_Interrupt';
  376. procedure CMP_Interrupt; external name 'CMP_Interrupt';
  377. procedure WDT_Interrupt; external name 'WDT_Interrupt';
  378. procedure BOD_Interrupt; external name 'BOD_Interrupt';
  379. procedure WKT_Interrupt; external name 'WKT_Interrupt';
  380. procedure PINIT0_Interrupt; external name 'PINIT0_Interrupt';
  381. procedure PINIT1_Interrupt; external name 'PINIT1_Interrupt';
  382. procedure PINIT2_Interrupt; external name 'PINIT2_Interrupt';
  383. procedure PINIT3_Interrupt; external name 'PINIT3_Interrupt';
  384. procedure PINIT4_Interrupt; external name 'PINIT4_Interrupt';
  385. procedure PINIT5_Interrupt; external name 'PINIT5_Interrupt';
  386. procedure PINIT6_Interrupt; external name 'PINIT6_Interrupt';
  387. procedure PINIT7_Interrupt; external name 'PINIT7_Interrupt';
  388. {$I cortexm0_start.inc}
  389. procedure Vectors; assembler;
  390. nostackframe;
  391. label interrupt_vectors;
  392. asm
  393. .section ".init.interrupt_vectors"
  394. interrupt_vectors:
  395. .long _stack_top
  396. .long Startup
  397. .long NonMaskableInt_interrupt
  398. .long Hardfault_interrupt
  399. .long 0
  400. .long 0
  401. .long 0
  402. .long Startup_Checksum
  403. .long 0
  404. .long 0
  405. .long 0
  406. .long SVCall_interrupt
  407. .long 0
  408. .long 0
  409. .long PendSV_interrupt
  410. .long SysTick_interrupt
  411. .long SPI0_Interrupt
  412. .long SPI1_Interrupt
  413. .long 0
  414. .long UART0_Interrupt
  415. .long UART1_Interrupt
  416. .long UART2_Interrupt
  417. .long 0
  418. .long 0
  419. .long I2C_Interrupt
  420. .long SCT_Interrupt
  421. .long MRT_Interrupt
  422. .long CMP_Interrupt
  423. .long WDT_Interrupt
  424. .long BOD_Interrupt
  425. .long 0
  426. .long WKT_Interrupt
  427. .long 0
  428. .long 0
  429. .long 0
  430. .long 0
  431. .long 0
  432. .long 0
  433. .long 0
  434. .long 0
  435. .long PINIT0_Interrupt
  436. .long PINIT1_Interrupt
  437. .long PINIT2_Interrupt
  438. .long PINIT3_Interrupt
  439. .long PINIT4_Interrupt
  440. .long PINIT5_Interrupt
  441. .long PINIT6_Interrupt
  442. .long PINIT7_Interrupt
  443. .weak NonMaskableInt_interrupt
  444. .weak Hardfault_interrupt
  445. .weak Startup_Checksum
  446. .weak SVCall_interrupt
  447. .weak PendSV_interrupt
  448. .weak SysTick_interrupt
  449. .weak SPI0_Interrupt
  450. .weak SPI1_Interrupt
  451. .weak UART0_Interrupt
  452. .weak UART1_Interrupt
  453. .weak UART2_Interrupt
  454. .weak I2C_Interrupt
  455. .weak SCT_Interrupt
  456. .weak MRT_Interrupt
  457. .weak CMP_Interrupt
  458. .weak WDT_Interrupt
  459. .weak BOD_Interrupt
  460. .weak WKT_Interrupt
  461. .weak PINIT0_Interrupt
  462. .weak PINIT1_Interrupt
  463. .weak PINIT2_Interrupt
  464. .weak PINIT3_Interrupt
  465. .weak PINIT4_Interrupt
  466. .weak PINIT5_Interrupt
  467. .weak PINIT6_Interrupt
  468. .weak PINIT7_Interrupt
  469. .set NonMaskableInt_interrupt, Startup
  470. .set Hardfault_interrupt , Startup
  471. .set SVCall_interrupt , Startup
  472. .set PendSV_interrupt , Startup
  473. .set SysTick_interrupt , Startup
  474. .set SPI0_Interrupt , Startup
  475. .set SPI1_Interrupt , Startup
  476. .set UART0_Interrupt , Startup
  477. .set UART1_Interrupt , Startup
  478. .set UART2_Interrupt , Startup
  479. .set I2C_Interrupt , Startup
  480. .set SCT_Interrupt , Startup
  481. .set MRT_Interrupt , Startup
  482. .set CMP_Interrupt , Startup
  483. .set WDT_Interrupt , Startup
  484. .set BOD_Interrupt , Startup
  485. .set WKT_Interrupt , Startup
  486. .set PINIT0_Interrupt, Startup
  487. .set PINIT1_Interrupt, Startup
  488. .set PINIT2_Interrupt, Startup
  489. .set PINIT3_Interrupt, Startup
  490. .set PINIT4_Interrupt, Startup
  491. .set PINIT5_Interrupt, Startup
  492. .set PINIT6_Interrupt, Startup
  493. .set PINIT7_Interrupt, Startup
  494. .text
  495. end;
  496. end.