lpc.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533
  1. //*****************************************************************************
  2. //
  3. // lpc.c - Driver for the Low Pin Count (LPC) module.
  4. //
  5. // Copyright (c) 2010-2011 Texas Instruments Incorporated. All rights reserved.
  6. // Software License Agreement
  7. //
  8. // Texas Instruments (TI) is supplying this software for use solely and
  9. // exclusively on TI's microcontroller products. The software is owned by
  10. // TI and/or its suppliers, and is protected under applicable copyright
  11. // laws. You may not combine this software with "viral" open-source
  12. // software in order to form a larger program.
  13. //
  14. // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
  15. // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
  16. // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  17. // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
  18. // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
  19. // DAMAGES, FOR ANY REASON WHATSOEVER.
  20. //
  21. // This is part of revision 8264 of the Stellaris Peripheral Driver Library.
  22. //
  23. //*****************************************************************************
  24. //*****************************************************************************
  25. //
  26. //! \addtogroup lpc_api
  27. //! @{
  28. //
  29. //*****************************************************************************
  30. #include "inc/hw_ints.h"
  31. #include "inc/hw_memmap.h"
  32. #include "inc/hw_lpc.h"
  33. #include "inc/hw_sysctl.h"
  34. #include "inc/hw_types.h"
  35. #include "driverlib/debug.h"
  36. #include "driverlib/interrupt.h"
  37. #include "driverlib/lpc.h"
  38. //*****************************************************************************
  39. //
  40. //! \internal
  41. //! Checks an LPC Channel.
  42. //!
  43. //! \param ulChannel is the LPC channel identifier.
  44. //!
  45. //! This function determines if a channel identifier is valid. This function
  46. //! does not check for Channel 7 (COMx).
  47. //!
  48. //! \return Returns \b true if the channel identifier is valid and \b false
  49. //! otherwise.
  50. //
  51. //*****************************************************************************
  52. #ifdef DEBUG
  53. static tBoolean
  54. LPCChannelValid(unsigned long ulChannel)
  55. {
  56. return((ulChannel == LPC_CHAN_CH0) ||
  57. (ulChannel == LPC_CHAN_CH1) ||
  58. (ulChannel == LPC_CHAN_CH2) ||
  59. (ulChannel == LPC_CHAN_CH3) ||
  60. (ulChannel == LPC_CHAN_CH4) ||
  61. (ulChannel == LPC_CHAN_CH5) ||
  62. (ulChannel == LPC_CHAN_CH6) ||
  63. (ulChannel == LPC_CHAN_CH7));
  64. }
  65. #endif // #ifdef DEBUG
  66. //*****************************************************************************
  67. //
  68. //! Sets the configuration of the LPC module.
  69. //!
  70. //! \param ulBase is the base address of the LPC module.
  71. //! \param ulConfig specifies the configuration of the LPC module.
  72. //!
  73. //! This function configures the LPC module for basic operation. The
  74. //! configuration of individual channels is handled in a separate function.
  75. //!
  76. //! The \e ulConfig parameter is the logical OR of the following values:
  77. //! - \b LPC_CFG_WAKE - Force assertion of the LPC0CLKRUN signal when the
  78. //! LPC bus is powered down (LPC0PD is asserted).
  79. //!
  80. //! \return None.
  81. //
  82. //*****************************************************************************
  83. void
  84. LPCConfigSet(unsigned long ulBase, unsigned long ulConfig)
  85. {
  86. unsigned long ulTemp;
  87. //
  88. // Check the arguments.
  89. //
  90. ASSERT(ulBase == LPC0_BASE);
  91. ASSERT((ulConfig & ~(LPC_CFG_WAKE)) == 0);
  92. //
  93. // Configure the appropriate LPC Control Register fields.
  94. //
  95. ulTemp = HWREG(ulBase + LPC_O_CTL);
  96. ulTemp &= ~LPC_CTL_WAKE;
  97. ulTemp |= (ulConfig & LPC_CTL_WAKE);
  98. HWREG(ulBase + LPC_O_CTL) = ulTemp;
  99. }
  100. //*****************************************************************************
  101. //
  102. //! Gets the current configuration of the LPC module.
  103. //!
  104. //! \param ulBase is the base address of the LPC module.
  105. //!
  106. //! This function queries the control register of the LPC module and returns
  107. //! a bit-mapped value.
  108. //!
  109. //! \sa The description of the LPCConfigSet() function provides detailed
  110. //! information for the bit-mapped configuration values that are returned.
  111. //!
  112. //! \return Returns the bit-mapped LPC module configration value.
  113. //
  114. //*****************************************************************************
  115. unsigned long
  116. LPCConfigGet(unsigned long ulBase)
  117. {
  118. //
  119. // Check the arguments.
  120. //
  121. ASSERT(ulBase == LPC0_BASE);
  122. //
  123. // Return the configuration value
  124. //
  125. return((HWREG(ulBase + LPC_O_CTL) & LPC_CTL_WAKE));
  126. }
  127. //*****************************************************************************
  128. //
  129. //! Sets the Status Block Address for the LPC peripheral.
  130. //!
  131. //! \param ulBase is the base address of the LPC module.
  132. //! \param ulAddress is the host address to use for the block status.
  133. //! \param bEnabled indicates whether the block address feature should
  134. //! be enabled.
  135. //!
  136. //! This function sets the LPC block address register and optionally enables
  137. //! it.
  138. //!
  139. //! \return None.
  140. //
  141. //*****************************************************************************
  142. void
  143. LPCStatusBlockAddressSet(unsigned long ulBase, unsigned long ulAddress,
  144. tBoolean bEnabled)
  145. {
  146. //
  147. // Check the arguments.
  148. //
  149. ASSERT(ulBase == LPC0_BASE);
  150. ASSERT((ulAddress & ~0xFFFFFFFE) == 0);
  151. //
  152. // Set (and optionally enable) the Status Block Address
  153. //
  154. HWREG(ulBase + LPC_O_STSADDR) = (ulAddress | (bEnabled ? 1 : 0));
  155. }
  156. //*****************************************************************************
  157. //
  158. //! Gets the Status Block Address for the LPC peripheral.
  159. //!
  160. //! \param ulBase is the base address of the LPC module.
  161. //!
  162. //! This function returns the LPC block address register. The LSB is used
  163. //! to indicate whether this feature has been enabled or not.
  164. //!
  165. //! \return None.
  166. //
  167. //*****************************************************************************
  168. unsigned
  169. LPCStatusBlockAddressGet(unsigned long ulBase)
  170. {
  171. //
  172. // Check the arguments.
  173. //
  174. ASSERT(ulBase == LPC0_BASE);
  175. //
  176. // Return the Status Block Address, including the enable bit.
  177. //
  178. return(HWREG(ulBase + LPC_O_STSADDR));
  179. }
  180. //*****************************************************************************
  181. //
  182. //! Returns the status of the LPC module.
  183. //!
  184. //! \param ulBase is the base address of the LPC module.
  185. //! \param pulCount is a pointer to storage for the channel count.
  186. //! \param pulPoolSize is a pointer to storage for the register pool size.
  187. //!
  188. //! This function reads the value of the LPC Status register, calculates the
  189. //! number of channels and buffer pool size, and then returns the raw status
  190. //! value.
  191. //!
  192. //! \return Returns the contents of the LPC Status register.
  193. //
  194. //*****************************************************************************
  195. unsigned long
  196. LPCStatusGet(unsigned long ulBase, unsigned long *pulCount,
  197. unsigned long *pulPoolSize)
  198. {
  199. unsigned long ulStatus;
  200. //
  201. // Check the arguments.
  202. //
  203. ASSERT(ulBase == LPC0_BASE);
  204. //
  205. // Get a snapshot of the status register.
  206. //
  207. ulStatus = HWREG(ulBase + LPC_O_STS);
  208. //
  209. // Extract the channel count from the status, including COMx channel.
  210. //
  211. if(pulCount)
  212. {
  213. *pulCount = (((ulStatus & LPC_STS_CHCNT_M) >> LPC_STS_CHCNT_S) + 1);
  214. }
  215. //
  216. // Extract/Calculate the register pool size.
  217. //
  218. if(pulPoolSize)
  219. {
  220. *pulPoolSize = (((ulStatus & LPC_STS_POOLSZ_M) >> 16) * 256);
  221. }
  222. //
  223. // Return the raw status.
  224. //
  225. return(ulStatus);
  226. }
  227. //*****************************************************************************
  228. //
  229. //! Generates a pulse on the SCIn signal.
  230. //!
  231. //! \param ulBase is the base address of the LPC module.
  232. //! \param ulCount is the number used to generate the pulse width value.
  233. //!
  234. //! This function generates a pulse on the SCIn interrupt pin. The width of
  235. //! the pulse is (2 << \e ulCount) LPC Clock Periods, where \e ulCount can take
  236. //! on the value of 0, 1, 2, or 3. So, the pulse width is 2, 4, 8, or 16 clock
  237. //! periods.
  238. //!
  239. //! \return None.
  240. //
  241. //*****************************************************************************
  242. void
  243. LPCSCIAssert(unsigned long ulBase, unsigned long ulCount)
  244. {
  245. //
  246. // Check the arguments.
  247. //
  248. ASSERT(ulBase == LPC0_BASE);
  249. ASSERT(ulCount <= 3);
  250. //
  251. // Wait for any previous pulse to be completed, by checking the SCI bit
  252. // (which is a self-clearing bit that is used to generate the pulse).
  253. //
  254. while(HWREG(ulBase + LPC_O_CTL) & LPC_CTL_SCI)
  255. {
  256. }
  257. //
  258. // Set the count value first, prior to enabling the pulse.
  259. //
  260. HWREG(ulBase + LPC_O_CTL) &= ~LPC_CTL_SCICNT_M;
  261. HWREG(ulBase + LPC_O_CTL) |= (ulCount << 10);
  262. //
  263. // Now, generate the pulse by setting the SCI bit.
  264. //
  265. HWREG(ulBase + LPC_O_CTL) |= LPC_CTL_SCI;
  266. }
  267. //*****************************************************************************
  268. //
  269. //! Configure the LPC IRQ operation.
  270. //!
  271. //! \param ulBase is the base address of the LPC module.
  272. //! \param bIRQPulse is a flag to indicate the manual IRQ bits should be
  273. //! cleared after they have been sent (in an SIRQ frame).
  274. //! \param bIRQOnChange is a flag to indicate that an SIRQ frame should be
  275. //! sent whenever any IRQ bits (manual/auto) change status.
  276. //!
  277. //! This function configures the LPC IRQs. If the \e bIRQPulse parameter is
  278. //! \b true, then manual IRQ values are cleared after they are sent. If the
  279. //! \e bIRQOnChange parameter is true, then IRQ values (manual and/or
  280. //! automatic) are sent when a change is detected.
  281. //!
  282. //! \return None.
  283. //
  284. //*****************************************************************************
  285. void
  286. LPCIRQConfig(unsigned long ulBase, tBoolean bIRQPulse, tBoolean bIRQOnChange)
  287. {
  288. //
  289. // Check the arguments.
  290. //
  291. ASSERT(ulBase == LPC0_BASE);
  292. //
  293. // Setup IRQ pulse configuration.
  294. //
  295. if(bIRQPulse)
  296. {
  297. HWREG(ulBase + LPC_O_IRQCTL) |= LPC_IRQCTL_PULSE;
  298. }
  299. else
  300. {
  301. HWREG(ulBase + LPC_O_IRQCTL) &= ~LPC_IRQCTL_PULSE;
  302. }
  303. //
  304. // Setup IRQ on-change configuration.
  305. //
  306. if(bIRQOnChange)
  307. {
  308. HWREG(ulBase + LPC_O_IRQCTL) |= LPC_IRQCTL_ONCHG;
  309. }
  310. else
  311. {
  312. HWREG(ulBase + LPC_O_IRQCTL) &= ~LPC_IRQCTL_ONCHG;
  313. }
  314. }
  315. //*****************************************************************************
  316. //
  317. //! Set the manual LPC IRQ bits.
  318. //!
  319. //! \param ulBase specifies the LPC module base address.
  320. //! \param ulIRQ specifies the IRQ bits that should be set.
  321. //!
  322. //! This function sets the IRQ bits that are sent in the SERIRQ frame. The
  323. //! value in the \e ulIRQ register is OR-ed into the existing manual IRQ
  324. //! setting. The value for the \e ulIRQ parameter can be any combination of
  325. //! the following values: \b LPC_IRQ15, \b LPC_IRQ14, \b LPC_IRQ13,
  326. //! \b LPC_IRQ12, \b LPC_IRQ11, \b LPC_IRQ10, \b LPC_IRQ9, \b LPC_IRQ8,
  327. //! \b LPC_IRQ7, \b LPC_IRQ6, \b LPC_IRQ5, \b LPC_IRQ4, \b LPC_IRQ3,
  328. //! \b LPC_IRQ2, \b LPC_IRQ1, or \b LPC_IRQ0.
  329. //!
  330. //! \return None.
  331. //
  332. //*****************************************************************************
  333. void
  334. LPCIRQSet(unsigned long ulBase, unsigned long ulIRQ)
  335. {
  336. unsigned long ulTemp;
  337. //
  338. // Check the arguments.
  339. //
  340. ASSERT(ulBase == LPC0_BASE);
  341. //
  342. // Get the current IRQ configuration, mask off the bits that we are to
  343. // be operating on, set/clear them as appropriate, then rewrite the
  344. // register.
  345. //
  346. ulTemp = HWREG(ulBase + LPC_O_IRQCTL);
  347. ulTemp |= (ulIRQ & 0xFFFF0000);
  348. HWREG(ulBase + LPC_O_IRQCTL) = ulTemp;
  349. }
  350. //*****************************************************************************
  351. //
  352. //! Clear the manual LPC IRQ bits.
  353. //!
  354. //! \param ulBase specifies the LPC module base address.
  355. //! \param ulIRQ specifies the IRQ bits that should be cleared.
  356. //!
  357. //! This function clears the IRQ bits that are sent in the SERIRQ frame. The
  358. //! value in the \e ulIRQ register is OR-ed into the existing manual IRQ
  359. //! setting. The value for the \e ulIRQ parameter can be any combination of
  360. //! the following values: \b LPC_IRQ15, \b LPC_IRQ14, \b LPC_IRQ13,
  361. //! \b LPC_IRQ12, \b LPC_IRQ11, \b LPC_IRQ10, \b LPC_IRQ9, \b LPC_IRQ8,
  362. //! \b LPC_IRQ7, \b LPC_IRQ6, \b LPC_IRQ5, \b LPC_IRQ4, \b LPC_IRQ3,
  363. //! \b LPC_IRQ2, \b LPC_IRQ1, or \b LPC_IRQ0.
  364. //!
  365. //! \return None.
  366. //
  367. //*****************************************************************************
  368. void
  369. LPCIRQClear(unsigned long ulBase, unsigned long ulIRQ)
  370. {
  371. unsigned long ulTemp;
  372. //
  373. // Check the arguments.
  374. //
  375. ASSERT(ulBase == LPC0_BASE);
  376. //
  377. // Get the current IRQ configuration, mask off the bits that we are to
  378. // be operating on, set/clear them as appropriate, then rewrite the
  379. // register.
  380. //
  381. ulTemp = HWREG(ulBase + LPC_O_IRQCTL);
  382. ulTemp &= ~(ulIRQ & 0xFFFF0000);
  383. HWREG(ulBase + LPC_O_IRQCTL) = ulTemp;
  384. }
  385. //*****************************************************************************
  386. //
  387. //! Get the configuration and status of the IRQ signals
  388. //!
  389. //! \param ulBase specifies the LPC module base address.
  390. //!
  391. //! This function returns the LPC module's SERIRQ status. The value returned
  392. //! is a combination of the following values: \b LPC_IRQ15, \b LPC_IRQ14,
  393. //! \b LPC_IRQ13, \b LPC_IRQ12, \b LPC_IRQ11, \b LPC_IRQ10, \b LPC_IRQ9,
  394. //! \b LPC_IRQ8, \b LPC_IRQ7, \b LPC_IRQ6, \b LPC_IRQ5, \b LPC_IRQ4,
  395. //! \b LPC_IRQ3, \b LPC_IRQ2, \b LPC_IRQ1, \b LPC_IRQ0, \b LPC_IRQ_BUSY, or
  396. //! \b LPC_IRQ_CONT.
  397. //!
  398. //! \return None.
  399. //
  400. //*****************************************************************************
  401. unsigned long
  402. LPCIRQGet(unsigned long ulBase)
  403. {
  404. //
  405. // Check the arguments.
  406. //
  407. ASSERT(ulBase == LPC0_BASE);
  408. //
  409. // Simply read the registers and return the values.
  410. //
  411. return(HWREG(ulBase + LPC_O_IRQST));
  412. }
  413. //*****************************************************************************
  414. //
  415. //! Trigger a manual SIRQ frame.
  416. //!
  417. //! \param ulBase specifies the LPC module base address.
  418. //!
  419. //! This function forces the sending of an SIRQ frame using whatever values are
  420. //! currently set (auto and/or manual).
  421. //!
  422. //! \return None.
  423. //
  424. //*****************************************************************************
  425. void
  426. LPCIRQSend(unsigned long ulBase)
  427. {
  428. //
  429. // Check the arguments.
  430. //
  431. ASSERT(ulBase == LPC0_BASE);
  432. //
  433. // Set the bit to force the sending of an SIRQ frame.
  434. //
  435. HWREG(ulBase + LPC_O_IRQCTL) |= LPC_IRQCTL_SND;
  436. }
  437. //*****************************************************************************
  438. //
  439. //! Registers an interrupt handler for the LPC module.
  440. //!
  441. //! \param ulBase specifies the LPC module base address.
  442. //! \param pfnHandler is a pointer to the function to be called when the
  443. //! LPC interrupt occurs.
  444. //!
  445. //! This function registers the handler to be called when an LPC interrupt
  446. //! occurs. This function enables the global interrupt in the interrupt
  447. //! controller; specific LPC interrupts must be enabled via LPCIntEnable(). If
  448. //! necessary, it is the interrupt handler's responsibility to clear the
  449. //! interrupt source via LPCIntClear().
  450. //!
  451. //! \sa IntRegister() for important information about registering interrupt
  452. //! handlers.
  453. //!
  454. //! \return None.
  455. //
  456. //*****************************************************************************
  457. void
  458. LPCIntRegister(unsigned long ulBase, void (*pfnHandler)(void))
  459. {
  460. //
  461. // Check the arguments.
  462. //
  463. ASSERT(ulBase == LPC0_BASE);
  464. ASSERT(pfnHandler != 0);
  465. //
  466. // Register the interrupt handler.
  467. //
  468. IntRegister(INT_LPC0, pfnHandler);
  469. //
  470. // Enable the LPC interrupt.
  471. //
  472. IntEnable(INT_LPC0);
  473. }
  474. //*****************************************************************************
  475. //
  476. //! Unregisters an interrupt handler for the LPC module.
  477. //!
  478. //! \param ulBase specifies the LPC module base address.
  479. //!
  480. //! This function unregisters the handler to be called when an LPC interrupt
  481. //! occurs. This fucntion also masks off the interrupt in the interrupt
  482. //! controller so that the interrupt handler is no longer called.
  483. //!
  484. //! \sa IntRegister() for important information about registering interrupt
  485. //! handlers.
  486. //!
  487. //! \return None.
  488. //
  489. //*****************************************************************************
  490. void
  491. LPCIntUnregister(unsigned long ulBase)
  492. {
  493. //
  494. // Check the arguments.
  495. //
  496. ASSERT(ulBase == LPC0_BASE);
  497. //
  498. // Disable the LPC interrupt.
  499. //
  500. IntDisable(INT_LPC0);
  501. //
  502. // Unregister the interrupt handler.
  503. //
  504. IntUnregister(INT_LPC0);
  505. }
  506. //*****************************************************************************
  507. //
  508. //! Enables individual LPC interrupt sources.
  509. //!
  510. //! \param ulBase specifies the LPC module base address.
  511. //! \param ulIntFlags is a bit mask of the interrupt sources to be enabled.
  512. //!
  513. //! This function enables the indicated LPC interrupt sources. Only the
  514. //! sources that are enabled can be reflected to the processor interrupt;
  515. //! disabled sources have no effect on the processor.
  516. //!
  517. //! The \e ulIntFlags parameter can be any of the following values:
  518. //! \b LPC_INT_RST, \b LPC_INT_SLEEP, \b LPC_INT_COMx, \b LPC_INT_SIRQ,
  519. //! \b LPC_INT_CHx_EP_TO_HOST, \b LPC_INT_CHx_EP_FROM_DATA,
  520. //! \b LPC_INT_CHx_EP_FROM_CMD, \b LPC_INT_CHx_MB_HOST_WON,
  521. //! \b LPC_INT_CHx_MB_HOST_WRITE, \b LPC_INT_CHx_MB_HOST_READ, or
  522. //! \b LPC_INT_CHx_MB_MCU_LOST, where \b CHx can be \b CH6, \b CH5, \b CH4,
  523. //! \b CH3, \b CH2, \b CH1, or \b CH0.
  524. //!
  525. //! \return None.
  526. //
  527. //*****************************************************************************
  528. void
  529. LPCIntEnable(unsigned long ulBase, unsigned long ulIntFlags)
  530. {
  531. //
  532. // Check the arguments.
  533. //
  534. ASSERT(ulBase == LPC0_BASE);
  535. //
  536. // Get the current mask value.
  537. //
  538. HWREG(ulBase + LPC_O_IM) |= ulIntFlags;
  539. }
  540. //*****************************************************************************
  541. //
  542. //! Disables individual LPC interrupt sources.
  543. //!
  544. //! \param ulBase specifies the LPC module base address.
  545. //! \param ulIntFlags is a bit mask of the interrupt sources to be disabled.
  546. //!
  547. //! This funciton disables the indicated LPC interrupt sources. Only the
  548. //! sources that are enabled can be reflected to the processor interrupt;
  549. //! disabled sources have no effect on the processor.
  550. //!
  551. //! \sa The description of the LPCIntEnable() function provides detailed
  552. //! information for the bit-mapped values in \e ulIntFlags.
  553. //!
  554. //! \return None.
  555. //
  556. //*****************************************************************************
  557. void
  558. LPCIntDisable(unsigned long ulBase, unsigned long ulIntFlags)
  559. {
  560. //
  561. // Check the arguments.
  562. //
  563. ASSERT(ulBase == LPC0_BASE);
  564. //
  565. // Disable the specified interrupts.
  566. //
  567. HWREG(ulBase + LPC_O_IM) &= ~ulIntFlags;
  568. }
  569. //*****************************************************************************
  570. //
  571. //! Gets the current interrupt status.
  572. //!
  573. //! \param ulBase specifies the LPC module base address.
  574. //! \param bMasked is \b false if the raw interrupt status is required or
  575. //! \b true if the masked interrupt status is required.
  576. //!
  577. //! This function returns the interrupt status for the LPC module. Either the
  578. //! raw interrupt status or the status of interrupts that are allowed to
  579. //! reflect to the processor can be returned.
  580. //!
  581. //! The interpretation of the LPC_INT_CHx fields varies based on the type
  582. //! value programed for the specific Channel.
  583. //!
  584. //! \sa The description of the LPCIntEnable() function provides detailed
  585. //! information for the bit-mapped values returned by this function.
  586. //!
  587. //! \return The current interrupt status.
  588. //
  589. //*****************************************************************************
  590. unsigned long
  591. LPCIntStatus(unsigned long ulBase, tBoolean bMasked)
  592. {
  593. //
  594. // Check the arguments.
  595. //
  596. ASSERT(ulBase == LPC0_BASE);
  597. //
  598. // Return either the interrupt status or the raw interrupt status as
  599. // requested.
  600. //
  601. if(bMasked)
  602. {
  603. return(HWREG(ulBase + LPC_O_MIS));
  604. }
  605. else
  606. {
  607. return(HWREG(ulBase + LPC_O_RIS));
  608. }
  609. }
  610. //*****************************************************************************
  611. //
  612. //! Clears LPC interrupt sources.
  613. //!
  614. //! \param ulBase specifies the LPC module base address.
  615. //! \param ulIntFlags is a bit mask of the interrupt sources to be cleared.
  616. //!
  617. //! The specified LPC interrupt sources are cleared so that they no longer
  618. //! assert. This function must be called in the interrupt handler to keep the
  619. //! interrupts from being recognized again immediately upon exit.
  620. //!
  621. //! \sa The description of the LPCIntEnable() function provides detailed
  622. //! information for the bit-mapped values in \e ulIntFlags.
  623. //!
  624. //! \note Because there is a write buffer in the Cortex-M processor, it may
  625. //! take several clock cycles before the interrupt source is actually cleared.
  626. //! Therefore, it is recommended that the interrupt source be cleared early in
  627. //! the interrupt handler (as opposed to the very last action) to avoid
  628. //! returning from the interrupt handler before the interrupt source is
  629. //! actually cleared. Failure to do so may result in the interrupt handler
  630. //! being immediately reentered (because the interrupt controller still sees
  631. //! the interrupt source asserted).
  632. //!
  633. //! \return None.
  634. //
  635. //*****************************************************************************
  636. void
  637. LPCIntClear(unsigned long ulBase, unsigned long ulIntFlags)
  638. {
  639. //
  640. // Check the arguments.
  641. //
  642. ASSERT(ulBase == LPC0_BASE);
  643. //
  644. // Clear the requested interrupt sources.
  645. //
  646. HWREG(ulBase + LPC_O_IC) = ulIntFlags;
  647. }
  648. //*****************************************************************************
  649. //
  650. //! Enables an LPC Channel.
  651. //!
  652. //! \param ulBase specifies the LPC module base address.
  653. //! \param ulChannel specifies the LPC channel to enable.
  654. //!
  655. //! The specified LPC Channel is enabled.
  656. //!
  657. //! The value for the \e ulChannel parameter can be any one of the following
  658. //! values: \b LPC_CHAN_CH0, \b LPC_CHAN_CH1, \b LPC_CHAN_CH2,
  659. //! \b LPC_CHAN_CH3, \b LPC_CHAN_CH4, \b LPC_CHAN_CH5, \b LPC_CHAN_CH6 or
  660. //! \b LPC_CHAN_CH7.
  661. //!
  662. //! \return None.
  663. //
  664. //*****************************************************************************
  665. void
  666. LPCChannelEnable(unsigned long ulBase, unsigned long ulChannel)
  667. {
  668. //
  669. // Check the arguments.
  670. //
  671. ASSERT(ulBase == LPC0_BASE);
  672. ASSERT(LPCChannelValid(ulChannel));
  673. //
  674. // Enable the specified channel.
  675. //
  676. HWREG(ulBase + LPC_O_CTL) |= (1 << ulChannel);
  677. }
  678. //*****************************************************************************
  679. //
  680. //! Disables an LPC Channel.
  681. //!
  682. //! \param ulBase specifies the LPC module base address.
  683. //! \param ulChannel specifies the LPC channel to disable.
  684. //!
  685. //! This function disables the specified LPC Channel.
  686. //!
  687. //! \sa The description of the LPCChannelEnable() function provides detailed
  688. //! information for the values that can be usd for the \e ulChannel parameter.
  689. //!
  690. //! \return None.
  691. //
  692. //*****************************************************************************
  693. void
  694. LPCChannelDisable(unsigned long ulBase, unsigned long ulChannel)
  695. {
  696. //
  697. // Check the arguments.
  698. //
  699. ASSERT(ulBase == LPC0_BASE);
  700. ASSERT(LPCChannelValid(ulChannel));
  701. //
  702. // Disable the specified channel.
  703. //
  704. HWREG(ulBase + LPC_O_CTL) &= ~(1 << ulChannel);
  705. }
  706. //*****************************************************************************
  707. //
  708. //! Sets the configuration of an LPC Channel as an endpoint.
  709. //!
  710. //! \param ulBase specifies the LPC module base address.
  711. //! \param ulChannel specifies the LPC channel to configure.
  712. //! \param ulConfig specifies configuration options required for the endpoint.
  713. //! \param ulOffset specifies the offset from the beginning of the buffer pool
  714. //! for this endpoint's data.
  715. //! \param ulAddress specifies the LPC bus address (IO and/or MEM) for this
  716. //! channel.
  717. //!
  718. //! This function enables the specified LPC Channel as an endpoint.
  719. //!
  720. //! \return None.
  721. //
  722. //*****************************************************************************
  723. void
  724. LPCChannelConfigEPSet(unsigned long ulBase, unsigned long ulChannel,
  725. unsigned long ulConfig, unsigned long ulAddress,
  726. unsigned long ulOffset)
  727. {
  728. //
  729. // Check the arguments.
  730. //
  731. ASSERT(ulBase == LPC0_BASE);
  732. ASSERT(LPCChannelValid(ulChannel));
  733. ASSERT((ulConfig & ~(LPC_CH0CTL_IRQSEL1_M | LPC_CH0CTL_IRQSEL0_M |
  734. LPC_CH0CTL_IRQEN1 | LPC_CH0CTL_IRQEN0_M)) == 0);
  735. ASSERT((ulOffset & 3) == 0);
  736. ASSERT(ulOffset < ((((HWREG(ulBase + LPC_O_STS) & LPC_STS_POOLSZ_M) >>
  737. 16) * 256) - 4));
  738. //
  739. // Convert the byte offset address into a half-word
  740. // offset address and add into the control word.
  741. //
  742. ulConfig |= (((ulOffset >> 1) << LPC_CH0CTL_OFFSET_S) &
  743. LPC_CH0CTL_OFFSET_M);
  744. //
  745. // Write the final control value into the control word for
  746. // the channel.
  747. //
  748. HWREG(ulBase + LPC_O_CH0CTL + (ulChannel * 0x10)) = ulConfig;
  749. //
  750. // Setup the IO and/or MEM address to match for this channel.
  751. //
  752. HWREG(ulBase + LPC_O_CH0ADR + (ulChannel * 0x10)) = ulAddress;
  753. }
  754. //*****************************************************************************
  755. //
  756. //! Sets the configuration of an LPC Channel as a mailbox.
  757. //!
  758. //! \param ulBase specifies the LPC module base address.
  759. //! \param ulChannel specifies the LPC channel to configure.
  760. //! \param ulConfig specifies configuration options required for the endpoint.
  761. //! \param ulOffset specifies the offset from the beginning of the buffer pool
  762. //! for this endpoint's data.
  763. //! \param ulAddress specifies the LPC bus address (IO and/or MEM) for this
  764. //! channel.
  765. //!
  766. //! This function enables the specified LPC Channel as a mailbox.
  767. //!
  768. //! \return None.
  769. //
  770. //*****************************************************************************
  771. void
  772. LPCChannelConfigMBSet(unsigned long ulBase, unsigned long ulChannel,
  773. unsigned long ulConfig, unsigned long ulAddress,
  774. unsigned long ulOffset)
  775. {
  776. //
  777. // Check the arguments.
  778. //
  779. ASSERT(ulBase == LPC0_BASE);
  780. ASSERT(LPCChannelValid(ulChannel));
  781. ASSERT((ulConfig & ~(LPC_CH0CTL_IRQSEL1_M | LPC_CH0CTL_IRQSEL1_M |
  782. LPC_CH0CTL_IRQSEL0_M |
  783. LPC_CH0CTL_IRQEN2 | LPC_CH0CTL_IRQEN1 |
  784. LPC_CH0CTL_IRQEN0_M |
  785. LPC_CH0CTL_ARBDIS | LPC_CH0CTL_AMASK_M)) == 0);
  786. ASSERT((ulOffset & 3) == 0);
  787. ASSERT(ulOffset < ((((HWREG(ulBase + LPC_O_STS) & LPC_STS_POOLSZ_M) >>
  788. 16) * 256) - 4));
  789. //
  790. // Convert the byte offset address into a half-word
  791. // offset address and add into the control word.
  792. //
  793. ulConfig |= (((ulOffset >> 1) << LPC_CH0CTL_OFFSET_S) &
  794. LPC_CH0CTL_OFFSET_M);
  795. //
  796. // Set the configuration bit that enables Mailbox mode.
  797. //
  798. ulConfig |= LPC_CH0CTL_TYPE;
  799. //
  800. // Write the final control value into the control word for
  801. // the channel.
  802. //
  803. HWREG(ulBase + LPC_O_CH0CTL + (ulChannel * 0x10)) = ulConfig;
  804. //
  805. // Setup the IO and/or MEM address to match for this channel.
  806. //
  807. HWREG(ulBase + LPC_O_CH0ADR + (ulChannel * 0x10)) = ulAddress;
  808. }
  809. //*****************************************************************************
  810. //
  811. //! Sets the configuration of an LPC Channel as a COMx.
  812. //!
  813. //! \param ulBase specifies the LPC module base address.
  814. //! \param ulChannel specifies the LPC channel to configure.
  815. //! \param ulConfig specifies configuration options required for the endpoint.
  816. //! \param ulOffset specifies the offset from the beginning of the buffer pool
  817. //! for this endpoint's data.
  818. //! \param ulAddress specifies the LPC bus address (IO and/or MEM) for this
  819. //! channel.
  820. //! \param ulCOMxMode specifies the COMx mode to be used.
  821. //!
  822. //! The specified LPC Channel is enabled as a COMx.
  823. //!
  824. //! \return None.
  825. //
  826. //*****************************************************************************
  827. void
  828. LPCChannelConfigCOMxSet(unsigned long ulBase, unsigned long ulChannel,
  829. unsigned long ulConfig, unsigned long ulAddress,
  830. unsigned long ulOffset, unsigned long ulCOMxMode)
  831. {
  832. unsigned long ulTemp;
  833. //
  834. // Check the arguments.
  835. //
  836. ASSERT(ulBase == LPC0_BASE);
  837. ASSERT(LPCChannelValid(ulChannel));
  838. ASSERT(ulChannel == LPC_CHAN_COMx);
  839. ASSERT((ulConfig & ~(LPC_CH7CTL_IRQSEL1_M | LPC_CH7CTL_IRQSEL0_M |
  840. LPC_CH7CTL_CX | LPC_CH7CTL_IRQEN1 |
  841. LPC_CH7CTL_IRQEN0_M)) == 0);
  842. ASSERT((ulOffset & 3) == 0);
  843. ASSERT(ulOffset < ((((HWREG(ulBase + LPC_O_STS) & LPC_STS_POOLSZ_M) >>
  844. 16) * 256) - 4));
  845. ASSERT((ulCOMxMode & ~LPC_DMACX_CXACT_M) == 0);
  846. //
  847. // Convert the byte offset address into a half-word
  848. // offset address and add into the control word.
  849. //
  850. ulConfig |= (((ulOffset >> 1) << LPC_CH0CTL_OFFSET_S) &
  851. LPC_CH0CTL_OFFSET_M);
  852. //
  853. // Write the final control value into the control word for
  854. // the channel.
  855. //
  856. HWREG(ulBase + LPC_O_CH0CTL + (ulChannel * 0x10)) = ulConfig;
  857. //
  858. // Setup the IO and/or MEM address to match for this channel.
  859. //
  860. HWREG(ulBase + LPC_O_CH0ADR + (ulChannel * 0x10)) = ulAddress;
  861. //
  862. // Configure the COMx Mode for this channel.
  863. //
  864. ulTemp = HWREG(ulBase + LPC_O_DMACX);
  865. ulTemp &= ~LPC_DMACX_CXACT_M;
  866. ulTemp |= ulCOMxMode;
  867. ulTemp |= LPC_DMACX_COMX;
  868. HWREG(ulBase + LPC_O_DMACX) = ulTemp;
  869. }
  870. //*****************************************************************************
  871. //
  872. //! Gets the configuration of an LPC Channel.
  873. //!
  874. //! \param ulBase specifies the LPC module base address.
  875. //! \param ulChannel specifies the LPC channel to configure.
  876. //! \param pulOffset is a pointer to storage for the channel pool offset.
  877. //! \param pulAddress is a pointer to storage for the channel bus address.
  878. //! \param pulCOMxMode is a pointer to storage for the channel COMx mode.
  879. //!
  880. //! This function determines and returns the configuration for the specified
  881. //! channel.
  882. //!
  883. //! \return Returns the bit-mapped channel control register value.
  884. //
  885. //*****************************************************************************
  886. unsigned long
  887. LPCChannelConfigGet(unsigned long ulBase, unsigned long ulChannel,
  888. unsigned long *pulAddress, unsigned long *pulOffset,
  889. unsigned long *pulCOMxMode)
  890. {
  891. unsigned long ulConfig;
  892. //
  893. // Check the arguments.
  894. //
  895. ASSERT(ulBase == LPC0_BASE);
  896. ASSERT(LPCChannelValid(ulChannel));
  897. //
  898. // Read the channel control register.
  899. //
  900. ulConfig = HWREG(ulBase + LPC_O_CH0CTL + (ulChannel * 0x10));
  901. //
  902. // Get the buffer pool offset value.
  903. //
  904. if(pulOffset)
  905. {
  906. *pulOffset = ((ulConfig & LPC_CH0CTL_OFFSET_M) >>
  907. (LPC_CH0CTL_OFFSET_S - 1));
  908. }
  909. //
  910. // Get the IO/Memory address that this endpoint responds to.
  911. //
  912. if(pulAddress)
  913. {
  914. *pulAddress = HWREG(ulBase + LPC_O_CH0ADR + (ulChannel * 0x10));
  915. }
  916. //
  917. // Configure the COMx Mode for this channel.
  918. //
  919. if(pulCOMxMode && (ulChannel == LPC_CHAN_COMx))
  920. {
  921. *pulCOMxMode = (HWREG(ulBase + LPC_O_DMACX) & 0x00070000);
  922. }
  923. //
  924. // Return the raw config value.
  925. //
  926. return(ulConfig);
  927. }
  928. //*****************************************************************************
  929. //
  930. //! Gets the absolute base address of the channel pool.
  931. //!
  932. //! \param ulBase specifies the LPC module base address.
  933. //! \param ulChannel specifies the LPC channel to configure.
  934. //!
  935. //! Thos function calculates the absolute address of the channel pool from the
  936. //! channel configuration setting and returns it.
  937. //!
  938. //! \return Returns the absolute base address of the channel pool.
  939. //
  940. //*****************************************************************************
  941. unsigned long
  942. LPCChannelPoolAddressGet(unsigned long ulBase, unsigned long ulChannel)
  943. {
  944. unsigned long ulAddress;
  945. //
  946. // Check the arguments.
  947. //
  948. ASSERT(ulBase == LPC0_BASE);
  949. ASSERT(LPCChannelValid(ulChannel));
  950. //
  951. // Read the channel control register.
  952. //
  953. ulAddress = HWREG(ulBase + LPC_O_CH0CTL + (ulChannel * 0x10));
  954. //
  955. // Mask off the channel offset portion and shift it into a byte
  956. // offset (stored as half-word offset).
  957. //
  958. ulAddress = ((ulAddress & LPC_CH0CTL_OFFSET_M) >>
  959. (LPC_CH0CTL_OFFSET_S - 1));
  960. //
  961. // Add the LPC and Buffer Pool base address to get the final
  962. // address to return.
  963. //
  964. ulAddress += (ulBase + LPC_O_POOL);
  965. //
  966. // Return the address to the calling routine.
  967. //
  968. return(ulAddress);
  969. }
  970. //*****************************************************************************
  971. //
  972. //! Reads the status word from an LPC Channel.
  973. //!
  974. //! \param ulBase specifies the LPC module base address.
  975. //! \param ulChannel specifies the LPC Channel.
  976. //!
  977. //! This function reads the status word from an LPC channel and returns it to
  978. //! the caller.
  979. //!
  980. //! \return content of the channel status register.
  981. //
  982. //*****************************************************************************
  983. unsigned long
  984. LPCChannelStatusGet(unsigned long ulBase, unsigned long ulChannel)
  985. {
  986. //
  987. // Check the arguments.
  988. //
  989. ASSERT(ulBase == LPC0_BASE);
  990. ASSERT(LPCChannelValid(ulChannel));
  991. //
  992. // Read the half-word status from the LPC Channel
  993. //
  994. return (HWREG(ulBase + LPC_O_CH0ST + (ulChannel * 0x10)));
  995. }
  996. //*****************************************************************************
  997. //
  998. //! Sets the user bits in the status word (16-bits) of an LPC Channel.
  999. //!
  1000. //! \param ulBase specifies the LPC module base address.
  1001. //! \param ulChannel specifies the LPC Channel.
  1002. //! \param ulStatus is the user bit values to set.
  1003. //!
  1004. //! This function sets the selected user bits of the status word for an LPC
  1005. //! channel.
  1006. //!
  1007. //! \return None
  1008. //
  1009. //*****************************************************************************
  1010. void
  1011. LPCChannelStatusSet(unsigned long ulBase, unsigned long ulChannel,
  1012. unsigned long ulStatus)
  1013. {
  1014. unsigned long ulTemp;
  1015. //
  1016. // Check the arguments.
  1017. //
  1018. ASSERT(ulBase == LPC0_BASE);
  1019. ASSERT(LPCChannelValid(ulChannel));
  1020. ASSERT((ulStatus & (~LPC_CH0ST_USER_M)) == 0);
  1021. //
  1022. // Read the status from the LPC Channel, and set new values for
  1023. // the user bits.
  1024. //
  1025. ulTemp = HWREG(ulBase + LPC_O_CH0ST + (ulChannel * 0x10));
  1026. ulTemp |= ulStatus;
  1027. HWREG(ulBase + LPC_O_CH0ST + (ulChannel * 0x10)) = ulTemp;
  1028. }
  1029. //*****************************************************************************
  1030. //
  1031. //! Clears the user bits in the status word (16-bits) of an LPC Channel.
  1032. //!
  1033. //! \param ulBase specifies the LPC module base address.
  1034. //! \param ulChannel specifies the LPC Channel.
  1035. //! \param ulStatus is the user bit values to clear.
  1036. //!
  1037. //! This function sets the selected user bits of the status word for an LPC
  1038. //! channel.
  1039. //!
  1040. //! \return None
  1041. //
  1042. //*****************************************************************************
  1043. void
  1044. LPCChannelStatusClear(unsigned long ulBase, unsigned long ulChannel,
  1045. unsigned long ulStatus)
  1046. {
  1047. unsigned long ulTemp;
  1048. //
  1049. // Check the arguments.
  1050. //
  1051. ASSERT(ulBase == LPC0_BASE);
  1052. ASSERT(LPCChannelValid(ulChannel));
  1053. ASSERT((ulStatus & (~LPC_CH0ST_USER_M)) == 0);
  1054. //
  1055. // Read the status from the LPC Channel, and set new values for
  1056. // the user bits.
  1057. //
  1058. ulTemp = HWREG(ulBase + LPC_O_CH0ST + (ulChannel * 0x10));
  1059. ulTemp &= ~ulStatus;
  1060. HWREG(ulBase + LPC_O_CH0ST + (ulChannel * 0x10)) = ulTemp;
  1061. }
  1062. //*****************************************************************************
  1063. //
  1064. //! Sets the configuration of DMA for LPC channels.
  1065. //!
  1066. //! \param ulBase specifies the LPC module base address.
  1067. //! \param ulConfig specifies the DMA channel configuration.
  1068. //! \param ulMask specifies the configuration mask to be used.
  1069. //!
  1070. //! This function sets the specified DMA channel operation based on the
  1071. //! \e ulConfig parameter.
  1072. //!
  1073. //! \return None.
  1074. //
  1075. //*****************************************************************************
  1076. void
  1077. LPCChannelDMAConfigSet(unsigned long ulBase, unsigned long ulConfig,
  1078. unsigned long ulMask)
  1079. {
  1080. unsigned long ulTemp;
  1081. //
  1082. // Check the arguments.
  1083. //
  1084. ASSERT(ulBase == LPC0_BASE);
  1085. ASSERT((ulConfig & ~0x000000FF) == 0);
  1086. ASSERT((ulConfig & 0x00000003) != 0x00000003);
  1087. ASSERT((ulConfig & 0x0000000C) != 0x0000000C);
  1088. ASSERT((ulConfig & 0x00000030) != 0x00000030);
  1089. ASSERT((ulConfig & 0x000000C0) != 0x000000C0);
  1090. ASSERT((ulMask & ~0x000000FF) == 0);
  1091. //
  1092. // Get the current mask value.
  1093. //
  1094. ulTemp = HWREG(ulBase + LPC_O_DMACX);
  1095. ulTemp &= ~ulMask;
  1096. ulTemp |= (ulConfig & ulMask);
  1097. HWREG(ulBase + LPC_O_DMACX) = ulTemp;
  1098. }
  1099. //*****************************************************************************
  1100. //
  1101. //! Gets the configuration of DMA for LPC channels.
  1102. //!
  1103. //! \param ulBase specifies the LPC module base address.
  1104. //!
  1105. //! This function returns the configuration of the LPC DMA channels.
  1106. //!
  1107. //! \return Returns the bit-mapped DMA channel configuration.
  1108. //
  1109. //*****************************************************************************
  1110. unsigned long
  1111. LPCChannelDMAConfigGet(unsigned long ulBase)
  1112. {
  1113. //
  1114. // Check the arguments.
  1115. //
  1116. ASSERT(ulBase == LPC0_BASE);
  1117. //
  1118. // Get the current mask value.
  1119. //
  1120. return(HWREG(ulBase + LPC_O_DMACX) & 0x000000FF);
  1121. }
  1122. //*****************************************************************************
  1123. //
  1124. //! Reads a byte from the LPC channel pool.
  1125. //!
  1126. //! \param ulBase specifies the LPC module base address.
  1127. //! \param ulOffset specifies the offset from the beginning of the LPC channel
  1128. //! pool.
  1129. //!
  1130. //! This function reads a byte from the channel pool.
  1131. //!
  1132. //! \return Returns the byte read from the pool memory.
  1133. //
  1134. //*****************************************************************************
  1135. unsigned char
  1136. LPCByteRead(unsigned long ulBase, unsigned long ulOffset)
  1137. {
  1138. //
  1139. // Check the arguments.
  1140. //
  1141. ASSERT(ulBase == LPC0_BASE);
  1142. ASSERT(ulOffset < (((HWREG(ulBase + LPC_O_STS) & LPC_STS_POOLSZ_M) >>
  1143. 16) * 256));
  1144. //
  1145. // Return the byte from the LPC Buffer Pool.
  1146. //
  1147. return(HWREGB(ulBase + LPC_O_POOL + ulOffset));
  1148. }
  1149. //*****************************************************************************
  1150. //
  1151. //! Writes a byte to the LPC channel pool.
  1152. //!
  1153. //! \param ulBase specifies the LPC module base address.
  1154. //! \param ulOffset specifies the offset from the beginning of the LPC channel
  1155. //! pool.
  1156. //! \param ucData specifies the byte to write.
  1157. //!
  1158. //! This function writes a byte to the channel pool.
  1159. //!
  1160. //! \return None
  1161. //
  1162. //*****************************************************************************
  1163. void
  1164. LPCByteWrite(unsigned long ulBase, unsigned long ulOffset,
  1165. unsigned char ucData)
  1166. {
  1167. //
  1168. // Check the arguments.
  1169. //
  1170. ASSERT(ulBase == LPC0_BASE);
  1171. ASSERT(ulOffset < (((HWREG(ulBase + LPC_O_STS) & LPC_STS_POOLSZ_M) >>
  1172. 16) * 256));
  1173. //
  1174. // Write the byte to the LPC Buffer Pool.
  1175. //
  1176. HWREGB(ulBase + LPC_O_POOL + ulOffset) = ucData;
  1177. }
  1178. //*****************************************************************************
  1179. //
  1180. //! Reads a half-word from the LPC channel pool.
  1181. //!
  1182. //! \param ulBase specifies the LPC module base address.
  1183. //! \param ulOffset specifies the offset from the beginning of the LPC channel
  1184. //! pool.
  1185. //!
  1186. //! This function reads a half-word from the channel pool. The \e ulOffset
  1187. //! specified must be half-word aligned.
  1188. //!
  1189. //! \return Returns the half-word read from the pool memory.
  1190. //
  1191. //*****************************************************************************
  1192. unsigned short
  1193. LPCHalfWordRead(unsigned long ulBase, unsigned long ulOffset)
  1194. {
  1195. //
  1196. // Check the arguments.
  1197. //
  1198. ASSERT(ulBase == LPC0_BASE);
  1199. ASSERT((ulOffset & 1) == 0);
  1200. ASSERT(ulOffset < (((HWREG(ulBase + LPC_O_STS) & LPC_STS_POOLSZ_M) >>
  1201. 16) * 256));
  1202. //
  1203. // Return the half-word from the LPC Buffer Pool.
  1204. //
  1205. return(HWREGH(ulBase + LPC_O_POOL + ulOffset));
  1206. }
  1207. //*****************************************************************************
  1208. //
  1209. //! Writes a half-word to the LPC channel pool.
  1210. //!
  1211. //! \param ulBase specifies the LPC module base address.
  1212. //! \param ulOffset specifies the offset from the beginning of the LPC channel
  1213. //! pool.
  1214. //! \param usData specifies the byte to write.
  1215. //!
  1216. //! This function writes a half-word to the channel pool. The \e ulOffset
  1217. //! specified must be half-word aligned.
  1218. //!
  1219. //! \return None
  1220. //
  1221. //*****************************************************************************
  1222. void
  1223. LPCHalfWordWrite(unsigned long ulBase, unsigned long ulOffset,
  1224. unsigned short usData)
  1225. {
  1226. //
  1227. // Check the arguments.
  1228. //
  1229. ASSERT(ulBase == LPC0_BASE);
  1230. ASSERT((ulOffset & 1) == 0);
  1231. ASSERT(ulOffset < (((HWREG(ulBase + LPC_O_STS) & LPC_STS_POOLSZ_M) >>
  1232. 16) * 256));
  1233. //
  1234. // Write the half-word to the LPC Buffer Pool.
  1235. //
  1236. HWREGH(ulBase + LPC_O_POOL + ulOffset) = usData;
  1237. }
  1238. //*****************************************************************************
  1239. //
  1240. //! Reads a word from the LPC channel pool.
  1241. //!
  1242. //! \param ulBase specifies the LPC module base address.
  1243. //! \param ulOffset specifies the offset from the beginning of the LPC channel
  1244. //! pool.
  1245. //!
  1246. //! This function reads a word from the channel pool. The \e ulOffset
  1247. //! specified must be word aligned.
  1248. //!
  1249. //! \return Returns the word read from the pool memory.
  1250. //
  1251. //*****************************************************************************
  1252. unsigned long
  1253. LPCWordRead(unsigned long ulBase, unsigned long ulOffset)
  1254. {
  1255. //
  1256. // Check the arguments.
  1257. //
  1258. ASSERT(ulBase == LPC0_BASE);
  1259. ASSERT((ulOffset & 3) == 0);
  1260. ASSERT(ulOffset < (((HWREG(ulBase + LPC_O_STS) & LPC_STS_POOLSZ_M) >>
  1261. 16) * 256));
  1262. //
  1263. // Return the word from the LPC Buffer Pool.
  1264. //
  1265. return(HWREG(ulBase + LPC_O_POOL + ulOffset));
  1266. }
  1267. //*****************************************************************************
  1268. //
  1269. //! Writes a word to the LPC channel pool.
  1270. //!
  1271. //! \param ulBase specifies the LPC module base address.
  1272. //! \param ulOffset specifies the offset from the beginning of the LPC channel
  1273. //! pool.
  1274. //! \param ulData specifies the word to write.
  1275. //!
  1276. //! This function writes a word to the channel pool. The \e ulOffset
  1277. //! specified must be word aligned.
  1278. //!
  1279. //! \return None
  1280. //
  1281. //*****************************************************************************
  1282. void
  1283. LPCWordWrite(unsigned long ulBase, unsigned long ulOffset,
  1284. unsigned long ulData)
  1285. {
  1286. //
  1287. // Check the arguments.
  1288. //
  1289. ASSERT(ulBase == LPC0_BASE);
  1290. ASSERT((ulOffset & 1) == 0);
  1291. ASSERT(ulOffset < (((HWREG(ulBase + LPC_O_STS) & LPC_STS_POOLSZ_M) >>
  1292. 16) * 256));
  1293. //
  1294. // Write the word to the LPC Buffer Pool.
  1295. //
  1296. HWREG(ulBase + LPC_O_POOL + ulOffset) = ulData;
  1297. }
  1298. //*****************************************************************************
  1299. //
  1300. //! Enables individual COMx interrupt sources.
  1301. //!
  1302. //! \param ulBase specifies the LPC module base address.
  1303. //! \param ulIntFlags is a bit mask of the interrupt sources to be enabled.
  1304. //!
  1305. //! This function enables the indicated COMx interrupt sources to trigger the
  1306. //! COMx interrupt in the primary LPC interrupt registers.
  1307. //!
  1308. //! \return None.
  1309. //
  1310. //*****************************************************************************
  1311. void
  1312. LPCCOMxIntEnable(unsigned long ulBase, unsigned long ulIntFlags)
  1313. {
  1314. //
  1315. // Check the arguments.
  1316. //
  1317. ASSERT(ulBase == LPC0_BASE);
  1318. ASSERT((ulIntFlags & ~(LPC_DMACX_CXEM | LPC_DMACX_CXTXEM |
  1319. LPC_DMACX_CXRXEM)) == 0);
  1320. //
  1321. // Get the current mask value.
  1322. //
  1323. HWREG(ulBase + LPC_O_DMACX) |= ulIntFlags;
  1324. }
  1325. //*****************************************************************************
  1326. //
  1327. //! Disables individual COMx interrupt sources.
  1328. //!
  1329. //! \param ulBase specifies the LPC module base address.
  1330. //! \param ulIntFlags is a bit mask of the interrupt sources to be disabled.
  1331. //!
  1332. //! This function disables the indicated COMx interrupt sources from triggering
  1333. //! the COMx interrupt in the primary LPC interrupt registers.
  1334. //!
  1335. //! \return None.
  1336. //
  1337. //*****************************************************************************
  1338. void
  1339. LPCCOMxIntDisable(unsigned long ulBase, unsigned long ulIntFlags)
  1340. {
  1341. //
  1342. // Check the arguments.
  1343. //
  1344. ASSERT(ulBase == LPC0_BASE);
  1345. ASSERT((ulIntFlags & ~(LPC_DMACX_CXEM | LPC_DMACX_CXTXEM |
  1346. LPC_DMACX_CXRXEM)) == 0);
  1347. //
  1348. // Disable the specified interrupts.
  1349. //
  1350. HWREG(ulBase + LPC_O_DMACX) &= ~ulIntFlags;
  1351. }
  1352. //*****************************************************************************
  1353. //
  1354. //! Gets the current COMx interrupt status.
  1355. //!
  1356. //! \param ulBase specifies the LPC module base address.
  1357. //! \param bMasked is \b false if the raw interrupt status is required or
  1358. //! \b true if the masked interrupt status is required.
  1359. //!
  1360. //! This function returns the interrupt status for the COMx module.
  1361. //!
  1362. //! \return The current interrupt status.
  1363. //
  1364. //*****************************************************************************
  1365. unsigned long
  1366. LPCCOMxIntStatus(unsigned long ulBase, tBoolean bMasked)
  1367. {
  1368. unsigned long ulStatus;
  1369. //
  1370. // Check the arguments.
  1371. //
  1372. ASSERT(ulBase == LPC0_BASE);
  1373. //
  1374. // Return either the interrupt status or the raw interrupt status as
  1375. // requested.
  1376. //
  1377. ulStatus = HWREG(ulBase + LPC_O_DMACX);
  1378. if(bMasked)
  1379. {
  1380. ulStatus = ulStatus & (ulStatus << 4);
  1381. }
  1382. return(ulStatus & (LPC_DMACX_CXRES | LPC_DMACX_CXTXRES |
  1383. LPC_DMACX_CXRXRES));
  1384. }
  1385. //*****************************************************************************
  1386. //
  1387. //! Clears COMx interrupt sources.
  1388. //!
  1389. //! \param ulBase specifies the LPC module base address.
  1390. //! \param ulIntFlags is a bit mask of the interrupt sources to be cleared.
  1391. //!
  1392. //! This function clears the specified COMx interrupt sources so that they no
  1393. //! longer assert.
  1394. //!
  1395. //! \return None.
  1396. //
  1397. //*****************************************************************************
  1398. void
  1399. LPCCOMxIntClear(unsigned long ulBase, unsigned long ulIntFlags)
  1400. {
  1401. //
  1402. // Check the arguments.
  1403. //
  1404. ASSERT(ulBase == LPC0_BASE);
  1405. ASSERT((ulIntFlags & ~(LPC_DMACX_CXRES | LPC_DMACX_CXTXRES |
  1406. LPC_DMACX_CXRXRES)) == 0);
  1407. //
  1408. // Clear the requested interrupt sources.
  1409. //
  1410. HWREG(ulBase + LPC_O_DMACX) |= ulIntFlags;
  1411. }
  1412. //*****************************************************************************
  1413. //
  1414. // Close the Doxygen group.
  1415. //! @}
  1416. //
  1417. //*****************************************************************************