lpc8xx.pp 16 KB

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