lpc214x.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. /**
  14. * @file lpc214x.h
  15. * @brief LPC214x register definitions.
  16. */
  17. #ifndef LPC214X_H
  18. #define LPC214X_H
  19. typedef volatile uint8_t IOREG8;
  20. typedef volatile uint16_t IOREG16;
  21. typedef volatile uint32_t IOREG32;
  22. /*
  23. * System.
  24. */
  25. #define MEMMAP (*((IOREG32 *)0xE01FC040))
  26. #define PCON (*((IOREG32 *)0xE01FC0C0))
  27. #define PCONP (*((IOREG32 *)0xE01FC0C4))
  28. #define VPBDIV (*((IOREG32 *)0xE01FC100))
  29. #define EXTINT (*((IOREG32 *)0xE01FC140))
  30. #define INTWAKE (*((IOREG32 *)0xE01FC144))
  31. #define EXTMODE (*((IOREG32 *)0xE01FC148))
  32. #define EXTPOLAR (*((IOREG32 *)0xE01FC14C))
  33. #define RSID (*((IOREG32 *)0xE01FC180))
  34. #define CSPR (*((IOREG32 *)0xE01FC184))
  35. #define SCS (*((IOREG32 *)0xE01FC1A0))
  36. #define VPD_D4 0
  37. #define VPD_D1 1
  38. #define VPD_D2 2
  39. #define VPD_RESERVED 3
  40. #define PCTIM0 (1 << 1)
  41. #define PCTIM1 (1 << 2)
  42. #define PCUART0 (1 << 3)
  43. #define PCUART1 (1 << 4)
  44. #define PCPWM0 (1 << 5)
  45. #define PCI2C0 (1 << 7)
  46. #define PCSPI0 (1 << 8)
  47. #define PCRTC (1 << 9)
  48. #define PCSPI1 (1 << 10)
  49. #define PCAD0 (1 << 12)
  50. #define PCI2C1 (1 << 19)
  51. #define PCAD1 (1 << 20)
  52. #define PCUSB (1 << 31)
  53. #define PCALL (PCTIM0 | PCTIM1 | PCUART0 | PCUART1 | \
  54. PCPWM0 | PCI2C0 | PCSPI0 | PCRTC | PCSPI1 | \
  55. PCAD0 | PCI2C1 | PCAD1 | PCUSB)
  56. #define EINT0 1
  57. #define EINT1 2
  58. #define EINT2 4
  59. #define EINT3 8
  60. #define EXTWAKE0 1
  61. #define EXTWAKE1 2
  62. #define EXTWAKE2 4
  63. #define EXTWAKE3 8
  64. #define USBWAKE 0x20
  65. #define BODWAKE 0x4000
  66. #define RTCWAKE 0x8000
  67. #define EXTMODE0 1
  68. #define EXTMODE1 2
  69. #define EXTMODE2 4
  70. #define EXTMODE3 8
  71. #define EXTPOLAR0 1
  72. #define EXTPOLAR1 2
  73. #define EXTPOLAR2 4
  74. #define EXTPOLAR3 8
  75. typedef struct {
  76. IOREG32 PLL_CON;
  77. IOREG32 PLL_CFG;
  78. IOREG32 PLL_STAT;
  79. IOREG32 PLL_FEED;
  80. } PLL;
  81. #define PLL0Base ((PLL *)0xE01FC080)
  82. #define PLL1Base ((PLL *)0xE01FC0A0)
  83. #define PLL0CON (PLL0Base->PLL_CON)
  84. #define PLL0CFG (PLL0Base->PLL_CFG)
  85. #define PLL0STAT (PLL0Base->PLL_STAT)
  86. #define PLL0FEED (PLL0Base->PLL_FEED)
  87. #define PLL1CON (PLL1Base->PLL_CON)
  88. #define PLL1CFG (PLL1Base->PLL_CFG)
  89. #define PLL1STAT (PLL1Base->PLL_STAT)
  90. #define PLL1FEED (PLL1Base->PLL_FEED)
  91. /*
  92. * Pins.
  93. */
  94. typedef struct {
  95. IOREG32 PS_SEL0;
  96. IOREG32 PS_SEL1;
  97. IOREG32 _dummy[3];
  98. IOREG32 PS_SEL2;
  99. } PS;
  100. #define PSBase ((PS *)0xE002C000)
  101. #define PINSEL0 (PSBase->PS_SEL0)
  102. #define PINSEL1 (PSBase->PS_SEL1)
  103. #define PINSEL2 (PSBase->PS_SEL2)
  104. /*
  105. * VIC
  106. */
  107. #define SOURCE_WDT 0
  108. #define SOURCE_ARMCore0 2
  109. #define SOURCE_ARMCore1 3
  110. #define SOURCE_Timer0 4
  111. #define SOURCE_Timer1 5
  112. #define SOURCE_UART0 6
  113. #define SOURCE_UART1 7
  114. #define SOURCE_PWM0 8
  115. #define SOURCE_I2C0 9
  116. #define SOURCE_SPI0 10
  117. #define SOURCE_SPI1 11
  118. #define SOURCE_PLL 12
  119. #define SOURCE_RTC 13
  120. #define SOURCE_EINT0 14
  121. #define SOURCE_EINT1 15
  122. #define SOURCE_EINT2 16
  123. #define SOURCE_EINT3 17
  124. #define SOURCE_ADC0 18
  125. #define SOURCE_I2C1 19
  126. #define SOURCE_BOD 20
  127. #define SOURCE_ADC1 21
  128. #define SOURCE_USB 22
  129. #define INTMASK(n) (1 << (n))
  130. #define ALLINTMASK (INTMASK(SOURCE_WDT) | INTMASK(SOURCE_ARMCore0) | \
  131. INTMASK(SOURCE_ARMCore1) | INTMASK(SOURCE_Timer0) | \
  132. INTMASK(SOURCE_Timer1) | INTMASK(SOURCE_UART0) | \
  133. INTMASK(SOURCE_UART1) | INTMASK(SOURCE_PWM0) | \
  134. INTMASK(SOURCE_I2C0) | INTMASK(SOURCE_SPI0) | \
  135. INTMASK(SOURCE_SPI1) | INTMASK(SOURCE_PLL) | \
  136. INTMASK(SOURCE_RTC) | INTMASK(SOURCE_EINT0) | \
  137. INTMASK(SOURCE_EINT1) | INTMASK(SOURCE_EINT2) | \
  138. INTMASK(SOURCE_EINT3) | INTMASK(SOURCE_ADC0) | \
  139. INTMASK(SOURCE_I2C1) | INTMASK(SOURCE_BOD) | \
  140. INTMASK(SOURCE_ADC1) | INTMASK(SOURCE_USB))
  141. typedef struct {
  142. IOREG32 VIC_IRQStatus;
  143. IOREG32 VIC_FIQStatus;
  144. IOREG32 VIC_RawIntr;
  145. IOREG32 VIC_IntSelect;
  146. IOREG32 VIC_IntEnable;
  147. IOREG32 VIC_IntEnClear;
  148. IOREG32 VIC_SoftInt;
  149. IOREG32 VIC_SoftIntClear;
  150. IOREG32 VIC_Protection;
  151. IOREG32 unused1[3];
  152. IOREG32 VIC_VectAddr;
  153. IOREG32 VIC_DefVectAddr;
  154. IOREG32 unused2[50];
  155. IOREG32 VIC_VectAddrs[16];
  156. IOREG32 unused3[48];
  157. IOREG32 VIC_VectCntls[16];
  158. } VIC;
  159. #define VICBase ((VIC *)0xFFFFF000)
  160. #define VICVectorsBase ((IOREG32 *)0xFFFFF100)
  161. #define VICControlsBase ((IOREG32 *)0xFFFFF200)
  162. #define VICIRQStatus (VICBase->VIC_IRQStatus)
  163. #define VICFIQStatus (VICBase->VIC_FIQStatus)
  164. #define VICRawIntr (VICBase->VIC_RawIntr)
  165. #define VICIntSelect (VICBase->VIC_IntSelect)
  166. #define VICIntEnable (VICBase->VIC_IntEnable)
  167. #define VICIntEnClear (VICBase->VIC_IntEnClear)
  168. #define VICSoftInt (VICBase->VIC_SoftInt)
  169. #define VICSoftIntClear (VICBase->VIC_SoftIntClear)
  170. #define VICProtection (VICBase->VIC_Protection)
  171. #define VICVectAddr (VICBase->VIC_VectAddr)
  172. #define VICDefVectAddr (VICBase->VIC_DefVectAddr)
  173. #define VICVectAddrs(n) (VICBase->VIC_VectAddrs[n])
  174. #define VICVectCntls(n) (VICBase->VIC_VectCntls[n])
  175. /*
  176. * MAM.
  177. */
  178. typedef struct {
  179. IOREG32 MAM_Control;
  180. IOREG32 MAM_Timing;
  181. } MAM;
  182. #define MAMBase ((MAM *)0xE01FC000)
  183. #define MAMCR (MAMBase->MAM_Control)
  184. #define MAMTIM (MAMBase->MAM_Timing)
  185. /*
  186. * GPIO - FIO.
  187. */
  188. typedef struct {
  189. IOREG32 IO_PIN;
  190. IOREG32 IO_SET;
  191. IOREG32 IO_DIR;
  192. IOREG32 IO_CLR;
  193. } GPIO;
  194. #define GPIO0Base ((GPIO *)0xE0028000)
  195. #define IO0PIN (GPIO0Base->IO_PIN)
  196. #define IO0SET (GPIO0Base->IO_SET)
  197. #define IO0DIR (GPIO0Base->IO_DIR)
  198. #define IO0CLR (GPIO0Base->IO_CLR)
  199. #define GPIO1Base ((GPIO *)0xE0028010)
  200. #define IO1PIN (GPIO1Base->IO_PIN)
  201. #define IO1SET (GPIO1Base->IO_SET)
  202. #define IO1DIR (GPIO1Base->IO_DIR)
  203. #define IO1CLR (GPIO1Base->IO_CLR)
  204. typedef struct {
  205. IOREG32 FIO_DIR;
  206. IOREG32 unused1;
  207. IOREG32 unused2;
  208. IOREG32 unused3;
  209. IOREG32 FIO_MASK;
  210. IOREG32 FIO_PIN;
  211. IOREG32 FIO_SET;
  212. IOREG32 FIO_CLR;
  213. } FIO;
  214. #define FIO0Base ((FIO *)0x3FFFC000)
  215. #define FIO0DIR (FIO0Base->FIO_DIR)
  216. #define FIO0MASK (FIO0Base->FIO_MASK)
  217. #define FIO0PIN (FIO0Base->FIO_PIN)
  218. #define FIO0SET (FIO0Base->FIO_SET)
  219. #define FIO0CLR (FIO0Base->FIO_CLR)
  220. #define FIO1Base ((FIO *)0x3FFFC020)
  221. #define FIO1DIR (FIO1Base->FIO_DIR)
  222. #define FIO1MASK (FIO1Base->FIO_MASK)
  223. #define FIO1PIN (FIO1Base->FIO_PIN)
  224. #define FIO1SET (FIO1Base->FIO_SET)
  225. #define FIO1CLR (FIO1Base->FIO_CLR)
  226. /*
  227. * UART.
  228. */
  229. typedef struct {
  230. union {
  231. IOREG32 UART_RBR;
  232. IOREG32 UART_THR;
  233. IOREG32 UART_DLL;
  234. };
  235. union {
  236. IOREG32 UART_IER;
  237. IOREG32 UART_DLM;
  238. };
  239. union {
  240. IOREG32 UART_IIR;
  241. IOREG32 UART_FCR;
  242. };
  243. IOREG32 UART_LCR;
  244. IOREG32 UART_MCR;
  245. IOREG32 UART_LSR;
  246. IOREG32 unused18;
  247. IOREG32 UART_SCR;
  248. IOREG32 UART_ACR;
  249. IOREG32 unused24;
  250. IOREG32 UART_FDR;
  251. IOREG32 unused2C;
  252. IOREG32 UART_TER;
  253. } UART;
  254. #define U0Base ((UART *)0xE000C000)
  255. #define U0RBR (U0Base->UART_RBR)
  256. #define U0THR (U0Base->UART_THR)
  257. #define U0DLL (U0Base->UART_DLL)
  258. #define U0IER (U0Base->UART_IER)
  259. #define U0DLM (U0Base->UART_DLM)
  260. #define U0IIR (U0Base->UART_IIR)
  261. #define U0FCR (U0Base->UART_FCR)
  262. #define U0LCR (U0Base->UART_LCR)
  263. #define U0LSR (U0Base->UART_LSR)
  264. #define U0SCR (U0Base->UART_SCR)
  265. #define U0ACR (U0Base->UART_ACR)
  266. #define U0FDR (U0Base->UART_FDR)
  267. #define U0TER (U0Base->UART_TER)
  268. #define U1Base ((UART *)0xE0010000)
  269. #define U1RBR (U1Base->UART_RBR)
  270. #define U1THR (U1Base->UART_THR)
  271. #define U1DLL (U1Base->UART_DLL)
  272. #define U1IER (U1Base->UART_IER)
  273. #define U1DLM (U1Base->UART_DLM)
  274. #define U1IIR (U1Base->UART_IIR)
  275. #define U1FCR (U1Base->UART_FCR)
  276. #define U1MCR (U1Base->UART_MCR)
  277. #define U1LCR (U1Base->UART_LCR)
  278. #define U1LSR (U1Base->UART_LSR)
  279. #define U1SCR (U1Base->UART_SCR)
  280. #define U1ACR (U1Base->UART_ACR)
  281. #define U1FDR (U1Base->UART_FDR)
  282. #define U1TER (U1Base->UART_TER)
  283. #define IIR_SRC_MASK 0x0F
  284. #define IIR_SRC_NONE 0x01
  285. #define IIR_SRC_TX 0x02
  286. #define IIR_SRC_RX 0x04
  287. #define IIR_SRC_ERROR 0x06
  288. #define IIR_SRC_TIMEOUT 0x0C
  289. #define IER_RBR 1
  290. #define IER_THRE 2
  291. #define IER_STATUS 4
  292. #define IIR_INT_PENDING 1
  293. #define LCR_WL5 0
  294. #define LCR_WL6 1
  295. #define LCR_WL7 2
  296. #define LCR_WL8 3
  297. #define LCR_STOP1 0
  298. #define LCR_STOP2 4
  299. #define LCR_NOPARITY 0
  300. #define LCR_PARITYODD 0x08
  301. #define LCR_PARITYEVEN 0x18
  302. #define LCR_PARITYONE 0x28
  303. #define LCR_PARITYZERO 0x38
  304. #define LCR_BREAK_ON 0x40
  305. #define LCR_DLAB 0x80
  306. #define FCR_ENABLE 1
  307. #define FCR_RXRESET 2
  308. #define FCR_TXRESET 4
  309. #define FCR_TRIGGER0 0
  310. #define FCR_TRIGGER1 0x40
  311. #define FCR_TRIGGER2 0x80
  312. #define FCR_TRIGGER3 0xC0
  313. #define LSR_RBR_FULL 1
  314. #define LSR_OVERRUN 2
  315. #define LSR_PARITY 4
  316. #define LSR_FRAMING 8
  317. #define LSR_BREAK 0x10
  318. #define LSR_THRE 0x20
  319. #define LSR_TEMT 0x40
  320. #define LSR_RXFE 0x80
  321. #define TER_ENABLE 0x80
  322. /*
  323. * SSP.
  324. */
  325. typedef struct {
  326. IOREG32 SSP_CR0;
  327. IOREG32 SSP_CR1;
  328. IOREG32 SSP_DR;
  329. IOREG32 SSP_SR;
  330. IOREG32 SSP_CPSR;
  331. IOREG32 SSP_IMSC;
  332. IOREG32 SSP_RIS;
  333. IOREG32 SSP_MIS;
  334. IOREG32 SSP_ICR;
  335. } SSP;
  336. #define SSPBase ((SSP *)0xE0068000)
  337. #define SSPCR0 (SSPBase->SSP_CR0)
  338. #define SSPCR1 (SSPBase->SSP_CR1)
  339. #define SSPDR (SSPBase->SSP_DR)
  340. #define SSPSR (SSPBase->SSP_SR)
  341. #define SSPCPSR (SSPBase->SSP_CPSR)
  342. #define SSPIMSC (SSPBase->SSP_IMSC)
  343. #define SSPRIS (SSPBase->SSP_RIS)
  344. #define SSPMIS (SSPBase->SSP_MIS)
  345. #define SSPICR (SSPBase->SSP_ICR)
  346. #define CR0_DSSMASK 0x0F
  347. #define CR0_DSS4BIT 3
  348. #define CR0_DSS5BIT 4
  349. #define CR0_DSS6BIT 5
  350. #define CR0_DSS7BIT 6
  351. #define CR0_DSS8BIT 7
  352. #define CR0_DSS9BIT 8
  353. #define CR0_DSS10BIT 9
  354. #define CR0_DSS11BIT 0xA
  355. #define CR0_DSS12BIT 0xB
  356. #define CR0_DSS13BIT 0xC
  357. #define CR0_DSS14BIT 0xD
  358. #define CR0_DSS15BIT 0xE
  359. #define CR0_DSS16BIT 0xF
  360. #define CR0_FRFSPI 0
  361. #define CR0_FRFSSI 0x10
  362. #define CR0_FRFMW 0x20
  363. #define CR0_CPOL 0x40
  364. #define CR0_CPHA 0x80
  365. #define CR0_CLOCKRATE(n) ((n) << 8)
  366. #define CR1_LBM 1
  367. #define CR1_SSE 2
  368. #define CR1_MS 4
  369. #define CR1_SOD 8
  370. #define SR_TFE 1
  371. #define SR_TNF 2
  372. #define SR_RNE 4
  373. #define SR_RFF 8
  374. #define SR_BSY 0x10
  375. #define IMSC_ROR 1
  376. #define IMSC_RT 2
  377. #define IMSC_RX 4
  378. #define IMSC_TX 8
  379. #define RIS_ROR 1
  380. #define RIS_RT 2
  381. #define RIS_RX 4
  382. #define RIS_TX 8
  383. #define MIS_ROR 1
  384. #define MIS_RT 2
  385. #define MIS_RX 4
  386. #define MIS_TX 8
  387. #define ICR_ROR 1
  388. #define ICR_RT 2
  389. /*
  390. * Timers/Counters.
  391. */
  392. typedef struct {
  393. IOREG32 TC_IR;
  394. IOREG32 TC_TCR;
  395. IOREG32 TC_TC;
  396. IOREG32 TC_PR;
  397. IOREG32 TC_PC;
  398. IOREG32 TC_MCR;
  399. IOREG32 TC_MR0;
  400. IOREG32 TC_MR1;
  401. IOREG32 TC_MR2;
  402. IOREG32 TC_MR3;
  403. IOREG32 TC_CCR;
  404. IOREG32 TC_CR0;
  405. IOREG32 TC_CR1;
  406. IOREG32 TC_CR2;
  407. IOREG32 TC_CR3;
  408. IOREG32 TC_EMR;
  409. IOREG32 TC_CTCR;
  410. } TC;
  411. #define T0Base ((TC *)0xE0004000)
  412. #define T0IR (T0Base->TC_IR)
  413. #define T0TCR (T0Base->TC_TCR)
  414. #define T0TC (T0Base->TC_TC)
  415. #define T0PR (T0Base->TC_PR)
  416. #define T0PC (T0Base->TC_PC)
  417. #define T0MCR (T0Base->TC_MCR)
  418. #define T0MR0 (T0Base->TC_MR0)
  419. #define T0MR1 (T0Base->TC_MR1)
  420. #define T0MR2 (T0Base->TC_MR2)
  421. #define T0MR3 (T0Base->TC_MR3)
  422. #define T0CCR (T0Base->TC_CCR)
  423. #define T0CR0 (T0Base->TC_CR0)
  424. #define T0CR1 (T0Base->TC_CR1)
  425. #define T0CR2 (T0Base->TC_CR2)
  426. #define T0CR3 (T0Base->TC_CR3)
  427. #define T0EMR (T0Base->TC_EMR)
  428. #define T0CTCR (T0Base->TC_CTCR)
  429. #define T1Base ((TC *)0xE0008000)
  430. #define T1IR (T1Base->TC_IR)
  431. #define T1TCR (T1Base->TC_TCR)
  432. #define T1TC (T1Base->TC_TC)
  433. #define T1PR (T1Base->TC_PR)
  434. #define T1PC (T1Base->TC_PC)
  435. #define T1MCR (T1Base->TC_MCR)
  436. #define T1MR0 (T1Base->TC_MR0)
  437. #define T1MR1 (T1Base->TC_MR1)
  438. #define T1MR2 (T1Base->TC_MR2)
  439. #define T1MR3 (T1Base->TC_MR3)
  440. #define T1CCR (T1Base->TC_CCR)
  441. #define T1CR0 (T1Base->TC_CR0)
  442. #define T1CR1 (T1Base->TC_CR1)
  443. #define T1CR2 (T1Base->TC_CR2)
  444. #define T1CR3 (T1Base->TC_CR3)
  445. #define T1EMR (T1Base->TC_EMR)
  446. #define T1CTCR (T1Base->TC_CTCR)
  447. /*
  448. * Watchdog.
  449. */
  450. typedef struct {
  451. IOREG32 WD_MOD;
  452. IOREG32 WD_TC;
  453. IOREG32 WD_FEED;
  454. IOREG32 WD_TV;
  455. } WD;
  456. #define WDBase ((WD *)0xE0000000)
  457. #define WDMOD (WDBase->WD_MOD)
  458. #define WDTC (WDBase->WD_TC)
  459. #define WDFEED (WDBase->WD_FEED)
  460. #define WDTV (WDBase->WD_TV)
  461. /*
  462. * DAC.
  463. */
  464. #define DACR (*((IOREG32 *)0xE006C000))
  465. #endif /* LPC214X_H */