ssi.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. //*****************************************************************************
  2. //
  3. // ssi.c - Driver for Synchronous Serial Interface.
  4. //
  5. // Copyright (c) 2005-2009 Luminary Micro, Inc. All rights reserved.
  6. // Software License Agreement
  7. //
  8. // Luminary Micro, Inc. (LMI) is supplying this software for use solely and
  9. // exclusively on LMI's microcontroller products.
  10. //
  11. // The software is owned by LMI and/or its suppliers, and is protected under
  12. // applicable copyright laws. All rights are reserved. You may not combine
  13. // this software with "viral" open-source software in order to form a larger
  14. // program. Any use in violation of the foregoing restrictions may subject
  15. // the user to criminal sanctions under applicable laws, as well as to civil
  16. // liability for the breach of the terms and conditions of this license.
  17. //
  18. // THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
  19. // OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
  20. // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
  21. // LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
  22. // CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
  23. //
  24. // This is part of revision 4694 of the Stellaris Peripheral Driver Library.
  25. //
  26. //*****************************************************************************
  27. //*****************************************************************************
  28. //
  29. //! \addtogroup ssi_api
  30. //! @{
  31. //
  32. //*****************************************************************************
  33. #include "inc/hw_ints.h"
  34. #include "inc/hw_memmap.h"
  35. #include "inc/hw_ssi.h"
  36. #include "inc/hw_types.h"
  37. #include "driverlib/debug.h"
  38. #include "driverlib/interrupt.h"
  39. #include "driverlib/ssi.h"
  40. //*****************************************************************************
  41. //
  42. //! Configures the synchronous serial interface.
  43. //!
  44. //! \param ulBase specifies the SSI module base address.
  45. //! \param ulSSIClk is the rate of the clock supplied to the SSI module.
  46. //! \param ulProtocol specifies the data transfer protocol.
  47. //! \param ulMode specifies the mode of operation.
  48. //! \param ulBitRate specifies the clock rate.
  49. //! \param ulDataWidth specifies number of bits transferred per frame.
  50. //!
  51. //! This function configures the synchronous serial interface. It sets
  52. //! the SSI protocol, mode of operation, bit rate, and data width.
  53. //!
  54. //! The \e ulProtocol parameter defines the data frame format. The
  55. //! \e ulProtocol parameter can be one of the following values:
  56. //! \b SSI_FRF_MOTO_MODE_0, \b SSI_FRF_MOTO_MODE_1, \b SSI_FRF_MOTO_MODE_2,
  57. //! \b SSI_FRF_MOTO_MODE_3, \b SSI_FRF_TI, or \b SSI_FRF_NMW. The Motorola
  58. //! frame formats imply the following polarity and phase configurations:
  59. //!
  60. //! <pre>
  61. //! Polarity Phase Mode
  62. //! 0 0 SSI_FRF_MOTO_MODE_0
  63. //! 0 1 SSI_FRF_MOTO_MODE_1
  64. //! 1 0 SSI_FRF_MOTO_MODE_2
  65. //! 1 1 SSI_FRF_MOTO_MODE_3
  66. //! </pre>
  67. //!
  68. //! The \e ulMode parameter defines the operating mode of the SSI module. The
  69. //! SSI module can operate as a master or slave; if a slave, the SSI can be
  70. //! configured to disable output on its serial output line. The \e ulMode
  71. //! parameter can be one of the following values: \b SSI_MODE_MASTER,
  72. //! \b SSI_MODE_SLAVE, or \b SSI_MODE_SLAVE_OD.
  73. //!
  74. //! The \e ulBitRate parameter defines the bit rate for the SSI. This bit rate
  75. //! must satisfy the following clock ratio criteria:
  76. //!
  77. //! - FSSI >= 2 * bit rate (master mode)
  78. //! - FSSI >= 12 * bit rate (slave modes)
  79. //!
  80. //! where FSSI is the frequency of the clock supplied to the SSI module.
  81. //!
  82. //! The \e ulDataWidth parameter defines the width of the data transfers, and
  83. //! can be a value between 4 and 16, inclusive.
  84. //!
  85. //! The peripheral clock will be the same as the processor clock. This will be
  86. //! the value returned by SysCtlClockGet(), or it can be explicitly hard coded
  87. //! if it is constant and known (to save the code/execution overhead of a call
  88. //! to SysCtlClockGet()).
  89. //!
  90. //! This function replaces the original SSIConfig() API and performs the same
  91. //! actions. A macro is provided in <tt>ssi.h</tt> to map the original API to
  92. //! this API.
  93. //!
  94. //! \return None.
  95. //
  96. //*****************************************************************************
  97. void
  98. SSIConfigSetExpClk(unsigned long ulBase, unsigned long ulSSIClk,
  99. unsigned long ulProtocol, unsigned long ulMode,
  100. unsigned long ulBitRate, unsigned long ulDataWidth)
  101. {
  102. unsigned long ulMaxBitRate;
  103. unsigned long ulRegVal;
  104. unsigned long ulPreDiv;
  105. unsigned long ulSCR;
  106. unsigned long ulSPH_SPO;
  107. //
  108. // Check the arguments.
  109. //
  110. ASSERT((ulBase == SSI0_BASE) || (ulBase == SSI1_BASE));
  111. ASSERT((ulProtocol == SSI_FRF_MOTO_MODE_0) ||
  112. (ulProtocol == SSI_FRF_MOTO_MODE_1) ||
  113. (ulProtocol == SSI_FRF_MOTO_MODE_2) ||
  114. (ulProtocol == SSI_FRF_MOTO_MODE_3) ||
  115. (ulProtocol == SSI_FRF_TI) ||
  116. (ulProtocol == SSI_FRF_NMW));
  117. ASSERT((ulMode == SSI_MODE_MASTER) ||
  118. (ulMode == SSI_MODE_SLAVE) ||
  119. (ulMode == SSI_MODE_SLAVE_OD));
  120. ASSERT(((ulMode == SSI_MODE_MASTER) && (ulBitRate <= (ulSSIClk / 2))) ||
  121. ((ulMode != SSI_MODE_MASTER) && (ulBitRate <= (ulSSIClk / 12))));
  122. ASSERT((ulSSIClk / ulBitRate) <= (254 * 256));
  123. ASSERT((ulDataWidth >= 4) && (ulDataWidth <= 16));
  124. //
  125. // Set the mode.
  126. //
  127. ulRegVal = (ulMode == SSI_MODE_SLAVE_OD) ? SSI_CR1_SOD : 0;
  128. ulRegVal |= (ulMode == SSI_MODE_MASTER) ? 0 : SSI_CR1_MS;
  129. HWREG(ulBase + SSI_O_CR1) = ulRegVal;
  130. //
  131. // Set the clock predivider.
  132. //
  133. ulMaxBitRate = ulSSIClk / ulBitRate;
  134. ulPreDiv = 0;
  135. do
  136. {
  137. ulPreDiv += 2;
  138. ulSCR = (ulMaxBitRate / ulPreDiv) - 1;
  139. }
  140. while(ulSCR > 255);
  141. HWREG(ulBase + SSI_O_CPSR) = ulPreDiv;
  142. //
  143. // Set protocol and clock rate.
  144. //
  145. ulSPH_SPO = ulProtocol << 6;
  146. ulProtocol &= SSI_CR0_FRF_M;
  147. ulRegVal = (ulSCR << 8) | ulSPH_SPO | ulProtocol | (ulDataWidth - 1);
  148. HWREG(ulBase + SSI_O_CR0) = ulRegVal;
  149. }
  150. //*****************************************************************************
  151. //
  152. //! Enables the synchronous serial interface.
  153. //!
  154. //! \param ulBase specifies the SSI module base address.
  155. //!
  156. //! This will enable operation of the synchronous serial interface. It must be
  157. //! configured before it is enabled.
  158. //!
  159. //! \return None.
  160. //
  161. //*****************************************************************************
  162. void
  163. SSIEnable(unsigned long ulBase)
  164. {
  165. //
  166. // Check the arguments.
  167. //
  168. ASSERT((ulBase == SSI0_BASE) || (ulBase == SSI1_BASE));
  169. //
  170. // Read-modify-write the enable bit.
  171. //
  172. HWREG(ulBase + SSI_O_CR1) |= SSI_CR1_SSE;
  173. }
  174. //*****************************************************************************
  175. //
  176. //! Disables the synchronous serial interface.
  177. //!
  178. //! \param ulBase specifies the SSI module base address.
  179. //!
  180. //! This will disable operation of the synchronous serial interface.
  181. //!
  182. //! \return None.
  183. //
  184. //*****************************************************************************
  185. void
  186. SSIDisable(unsigned long ulBase)
  187. {
  188. //
  189. // Check the arguments.
  190. //
  191. ASSERT((ulBase == SSI0_BASE) || (ulBase == SSI1_BASE));
  192. //
  193. // Read-modify-write the enable bit.
  194. //
  195. HWREG(ulBase + SSI_O_CR1) &= ~(SSI_CR1_SSE);
  196. }
  197. //*****************************************************************************
  198. //
  199. //! Registers an interrupt handler for the synchronous serial interface.
  200. //!
  201. //! \param ulBase specifies the SSI module base address.
  202. //! \param pfnHandler is a pointer to the function to be called when the
  203. //! synchronous serial interface interrupt occurs.
  204. //!
  205. //! This sets the handler to be called when an SSI interrupt
  206. //! occurs. This will enable the global interrupt in the interrupt controller;
  207. //! specific SSI interrupts must be enabled via SSIIntEnable(). If necessary,
  208. //! it is the interrupt handler's responsibility to clear the interrupt source
  209. //! via SSIIntClear().
  210. //!
  211. //! \sa IntRegister() for important information about registering interrupt
  212. //! handlers.
  213. //!
  214. //! \return None.
  215. //
  216. //*****************************************************************************
  217. void
  218. SSIIntRegister(unsigned long ulBase, void (*pfnHandler)(void))
  219. {
  220. unsigned long ulInt;
  221. //
  222. // Check the arguments.
  223. //
  224. ASSERT((ulBase == SSI0_BASE) || (ulBase == SSI1_BASE));
  225. //
  226. // Determine the interrupt number based on the SSI port.
  227. //
  228. ulInt = (ulBase == SSI0_BASE) ? INT_SSI0 : INT_SSI1;
  229. //
  230. // Register the interrupt handler, returning an error if an error occurs.
  231. //
  232. IntRegister(ulInt, pfnHandler);
  233. //
  234. // Enable the synchronous serial interface interrupt.
  235. //
  236. IntEnable(ulInt);
  237. }
  238. //*****************************************************************************
  239. //
  240. //! Unregisters an interrupt handler for the synchronous serial interface.
  241. //!
  242. //! \param ulBase specifies the SSI module base address.
  243. //!
  244. //! This function will clear the handler to be called when a SSI
  245. //! interrupt occurs. This will also mask off the interrupt in the interrupt
  246. //! controller so that the interrupt handler no longer is called.
  247. //!
  248. //! \sa IntRegister() for important information about registering interrupt
  249. //! handlers.
  250. //!
  251. //! \return None.
  252. //
  253. //*****************************************************************************
  254. void
  255. SSIIntUnregister(unsigned long ulBase)
  256. {
  257. unsigned long ulInt;
  258. //
  259. // Check the arguments.
  260. //
  261. ASSERT((ulBase == SSI0_BASE) || (ulBase == SSI1_BASE));
  262. //
  263. // Determine the interrupt number based on the SSI port.
  264. //
  265. ulInt = (ulBase == SSI0_BASE) ? INT_SSI0 : INT_SSI1;
  266. //
  267. // Disable the interrupt.
  268. //
  269. IntDisable(ulInt);
  270. //
  271. // Unregister the interrupt handler.
  272. //
  273. IntUnregister(ulInt);
  274. }
  275. //*****************************************************************************
  276. //
  277. //! Enables individual SSI interrupt sources.
  278. //!
  279. //! \param ulBase specifies the SSI module base address.
  280. //! \param ulIntFlags is a bit mask of the interrupt sources to be enabled.
  281. //!
  282. //! Enables the indicated SSI interrupt sources. Only the sources that are
  283. //! enabled can be reflected to the processor interrupt; disabled sources have
  284. //! no effect on the processor. The \e ulIntFlags parameter can be any of the
  285. //! \b SSI_TXFF, \b SSI_RXFF, \b SSI_RXTO, or \b SSI_RXOR values.
  286. //!
  287. //! \return None.
  288. //
  289. //*****************************************************************************
  290. void
  291. SSIIntEnable(unsigned long ulBase, unsigned long ulIntFlags)
  292. {
  293. //
  294. // Check the arguments.
  295. //
  296. ASSERT((ulBase == SSI0_BASE) || (ulBase == SSI1_BASE));
  297. //
  298. // Enable the specified interrupts.
  299. //
  300. HWREG(ulBase + SSI_O_IM) |= ulIntFlags;
  301. }
  302. //*****************************************************************************
  303. //
  304. //! Disables individual SSI interrupt sources.
  305. //!
  306. //! \param ulBase specifies the SSI module base address.
  307. //! \param ulIntFlags is a bit mask of the interrupt sources to be disabled.
  308. //!
  309. //! Disables the indicated SSI interrupt sources. The \e ulIntFlags parameter
  310. //! can be any of the \b SSI_TXFF, \b SSI_RXFF, \b SSI_RXTO, or \b SSI_RXOR
  311. //! values.
  312. //!
  313. //! \return None.
  314. //
  315. //*****************************************************************************
  316. void
  317. SSIIntDisable(unsigned long ulBase, unsigned long ulIntFlags)
  318. {
  319. //
  320. // Check the arguments.
  321. //
  322. ASSERT((ulBase == SSI0_BASE) || (ulBase == SSI1_BASE));
  323. //
  324. // Disable the specified interrupts.
  325. //
  326. HWREG(ulBase + SSI_O_IM) &= ~(ulIntFlags);
  327. }
  328. //*****************************************************************************
  329. //
  330. //! Gets the current interrupt status.
  331. //!
  332. //! \param ulBase specifies the SSI module base address.
  333. //! \param bMasked is \b false if the raw interrupt status is required and
  334. //! \b true if the masked interrupt status is required.
  335. //!
  336. //! This returns the interrupt status for the SSI module. Either the raw
  337. //! interrupt status or the status of interrupts that are allowed to reflect to
  338. //! the processor can be returned.
  339. //!
  340. //! \return The current interrupt status, enumerated as a bit field of
  341. //! \b SSI_TXFF, \b SSI_RXFF, \b SSI_RXTO, and \b SSI_RXOR.
  342. //
  343. //*****************************************************************************
  344. unsigned long
  345. SSIIntStatus(unsigned long ulBase, tBoolean bMasked)
  346. {
  347. //
  348. // Check the arguments.
  349. //
  350. ASSERT((ulBase == SSI0_BASE) || (ulBase == SSI1_BASE));
  351. //
  352. // Return either the interrupt status or the raw interrupt status as
  353. // requested.
  354. //
  355. if(bMasked)
  356. {
  357. return(HWREG(ulBase + SSI_O_MIS));
  358. }
  359. else
  360. {
  361. return(HWREG(ulBase + SSI_O_RIS));
  362. }
  363. }
  364. //*****************************************************************************
  365. //
  366. //! Clears SSI interrupt sources.
  367. //!
  368. //! \param ulBase specifies the SSI module base address.
  369. //! \param ulIntFlags is a bit mask of the interrupt sources to be cleared.
  370. //!
  371. //! The specified SSI interrupt sources are cleared, so that
  372. //! they no longer assert. This must be done in the interrupt handler to
  373. //! keep it from being called again immediately upon exit.
  374. //! The \e ulIntFlags parameter can consist of either or both the \b SSI_RXTO
  375. //! and \b SSI_RXOR values.
  376. //!
  377. //! \note Since there is a write buffer in the Cortex-M3 processor, it may take
  378. //! several clock cycles before the interrupt source is actually cleared.
  379. //! Therefore, it is recommended that the interrupt source be cleared early in
  380. //! the interrupt handler (as opposed to the very last action) to avoid
  381. //! returning from the interrupt handler before the interrupt source is
  382. //! actually cleared. Failure to do so may result in the interrupt handler
  383. //! being immediately reentered (since NVIC still sees the interrupt source
  384. //! asserted).
  385. //!
  386. //! \return None.
  387. //
  388. //*****************************************************************************
  389. void
  390. SSIIntClear(unsigned long ulBase, unsigned long ulIntFlags)
  391. {
  392. //
  393. // Check the arguments.
  394. //
  395. ASSERT((ulBase == SSI0_BASE) || (ulBase == SSI1_BASE));
  396. //
  397. // Clear the requested interrupt sources.
  398. //
  399. HWREG(ulBase + SSI_O_ICR) = ulIntFlags;
  400. }
  401. //*****************************************************************************
  402. //
  403. //! Puts a data element into the SSI transmit FIFO.
  404. //!
  405. //! \param ulBase specifies the SSI module base address.
  406. //! \param ulData data to be transmitted over the SSI interface.
  407. //!
  408. //! This function will place the supplied data into the transmit FIFO of
  409. //! the specified SSI module.
  410. //!
  411. //! \note The upper 32 - N bits of the \e ulData will be discarded by the
  412. //! hardware, where N is the data width as configured by SSIConfigSetExpClk().
  413. //! For example, if the interface is configured for 8-bit data width, the upper
  414. //! 24 bits of \e ulData will be discarded.
  415. //!
  416. //! \return None.
  417. //
  418. //*****************************************************************************
  419. void
  420. SSIDataPut(unsigned long ulBase, unsigned long ulData)
  421. {
  422. //
  423. // Check the arguments.
  424. //
  425. ASSERT((ulBase == SSI0_BASE) || (ulBase == SSI1_BASE));
  426. ASSERT((ulData & (0xfffffffe << (HWREG(ulBase + SSI_O_CR0) &
  427. SSI_CR0_DSS_M))) == 0);
  428. //
  429. // Wait until there is space.
  430. //
  431. while(!(HWREG(ulBase + SSI_O_SR) & SSI_SR_TNF))
  432. {
  433. }
  434. //
  435. // Write the data to the SSI.
  436. //
  437. HWREG(ulBase + SSI_O_DR) = ulData;
  438. }
  439. //*****************************************************************************
  440. //
  441. //! Puts a data element into the SSI transmit FIFO.
  442. //!
  443. //! \param ulBase specifies the SSI module base address.
  444. //! \param ulData data to be transmitted over the SSI interface.
  445. //!
  446. //! This function will place the supplied data into the transmit FIFO of
  447. //! the specified SSI module. If there is no space in the FIFO, then this
  448. //! function will return a zero.
  449. //!
  450. //! This function replaces the original SSIDataNonBlockingPut() API and
  451. //! performs the same actions. A macro is provided in <tt>ssi.h</tt> to map
  452. //! the original API to this API.
  453. //!
  454. //! \note The upper 32 - N bits of the \e ulData will be discarded by the
  455. //! hardware, where N is the data width as configured by SSIConfigSetExpClk().
  456. //! For example, if the interface is configured for 8-bit data width, the upper
  457. //! 24 bits of \e ulData will be discarded.
  458. //!
  459. //! \return Returns the number of elements written to the SSI transmit FIFO.
  460. //
  461. //*****************************************************************************
  462. long
  463. SSIDataPutNonBlocking(unsigned long ulBase, unsigned long ulData)
  464. {
  465. //
  466. // Check the arguments.
  467. //
  468. ASSERT((ulBase == SSI0_BASE) || (ulBase == SSI1_BASE));
  469. ASSERT((ulData & (0xfffffffe << (HWREG(ulBase + SSI_O_CR0) &
  470. SSI_CR0_DSS_M))) == 0);
  471. //
  472. // Check for space to write.
  473. //
  474. if(HWREG(ulBase + SSI_O_SR) & SSI_SR_TNF)
  475. {
  476. HWREG(ulBase + SSI_O_DR) = ulData;
  477. return(1);
  478. }
  479. else
  480. {
  481. return(0);
  482. }
  483. }
  484. //*****************************************************************************
  485. //
  486. //! Gets a data element from the SSI receive FIFO.
  487. //!
  488. //! \param ulBase specifies the SSI module base address.
  489. //! \param pulData pointer to a storage location for data that was received
  490. //! over the SSI interface.
  491. //!
  492. //! This function will get received data from the receive FIFO of the specified
  493. //! SSI module, and place that data into the location specified by the
  494. //! \e pulData parameter.
  495. //!
  496. //! \note Only the lower N bits of the value written to \e pulData will contain
  497. //! valid data, where N is the data width as configured by
  498. //! SSIConfigSetExpClk(). For example, if the interface is configured for
  499. //! 8-bit data width, only the lower 8 bits of the value written to \e pulData
  500. //! will contain valid data.
  501. //!
  502. //! \return None.
  503. //
  504. //*****************************************************************************
  505. void
  506. SSIDataGet(unsigned long ulBase, unsigned long *pulData)
  507. {
  508. //
  509. // Check the arguments.
  510. //
  511. ASSERT((ulBase == SSI0_BASE) || (ulBase == SSI1_BASE));
  512. //
  513. // Wait until there is data to be read.
  514. //
  515. while(!(HWREG(ulBase + SSI_O_SR) & SSI_SR_RNE))
  516. {
  517. }
  518. //
  519. // Read data from SSI.
  520. //
  521. *pulData = HWREG(ulBase + SSI_O_DR);
  522. }
  523. //*****************************************************************************
  524. //
  525. //! Gets a data element from the SSI receive FIFO.
  526. //!
  527. //! \param ulBase specifies the SSI module base address.
  528. //! \param pulData pointer to a storage location for data that was received
  529. //! over the SSI interface.
  530. //!
  531. //! This function will get received data from the receive FIFO of
  532. //! the specified SSI module, and place that data into the location specified
  533. //! by the \e ulData parameter. If there is no data in the FIFO, then this
  534. //! function will return a zero.
  535. //!
  536. //! This function replaces the original SSIDataNonBlockingGet() API and
  537. //! performs the same actions. A macro is provided in <tt>ssi.h</tt> to map
  538. //! the original API to this API.
  539. //!
  540. //! \note Only the lower N bits of the value written to \e pulData will contain
  541. //! valid data, where N is the data width as configured by
  542. //! SSIConfigSetExpClk(). For example, if the interface is configured for
  543. //! 8-bit data width, only the lower 8 bits of the value written to \e pulData
  544. //! will contain valid data.
  545. //!
  546. //! \return Returns the number of elements read from the SSI receive FIFO.
  547. //
  548. //*****************************************************************************
  549. long
  550. SSIDataGetNonBlocking(unsigned long ulBase, unsigned long *pulData)
  551. {
  552. //
  553. // Check the arguments.
  554. //
  555. ASSERT((ulBase == SSI0_BASE) || (ulBase == SSI1_BASE));
  556. //
  557. // Check for data to read.
  558. //
  559. if(HWREG(ulBase + SSI_O_SR) & SSI_SR_RNE)
  560. {
  561. *pulData = HWREG(ulBase + SSI_O_DR);
  562. return(1);
  563. }
  564. else
  565. {
  566. return(0);
  567. }
  568. }
  569. //*****************************************************************************
  570. //
  571. //! Enable SSI DMA operation.
  572. //!
  573. //! \param ulBase is the base address of the SSI port.
  574. //! \param ulDMAFlags is a bit mask of the DMA features to enable.
  575. //!
  576. //! The specified SSI DMA features are enabled. The SSI can be
  577. //! configured to use DMA for transmit and/or receive data transfers.
  578. //! The \e ulDMAFlags parameter is the logical OR of any of the following
  579. //! values:
  580. //!
  581. //! - SSI_DMA_RX - enable DMA for receive
  582. //! - SSI_DMA_TX - enable DMA for transmit
  583. //!
  584. //! \note The uDMA controller must also be set up before DMA can be used
  585. //! with the SSI.
  586. //!
  587. //! \return None.
  588. //
  589. //*****************************************************************************
  590. void
  591. SSIDMAEnable(unsigned long ulBase, unsigned long ulDMAFlags)
  592. {
  593. //
  594. // Check the arguments.
  595. //
  596. ASSERT((ulBase == SSI0_BASE) || (ulBase == SSI1_BASE));
  597. //
  598. // Set the requested bits in the UART DMA control register.
  599. //
  600. HWREG(ulBase + SSI_O_DMACTL) |= ulDMAFlags;
  601. }
  602. //*****************************************************************************
  603. //
  604. //! Disable SSI DMA operation.
  605. //!
  606. //! \param ulBase is the base address of the SSI port.
  607. //! \param ulDMAFlags is a bit mask of the DMA features to disable.
  608. //!
  609. //! This function is used to disable SSI DMA features that were enabled
  610. //! by SSIDMAEnable(). The specified SSI DMA features are disabled. The
  611. //! \e ulDMAFlags parameter is the logical OR of any of the following values:
  612. //!
  613. //! - SSI_DMA_RX - disable DMA for receive
  614. //! - SSI_DMA_TX - disable DMA for transmit
  615. //!
  616. //! \return None.
  617. //
  618. //*****************************************************************************
  619. void
  620. SSIDMADisable(unsigned long ulBase, unsigned long ulDMAFlags)
  621. {
  622. //
  623. // Check the arguments.
  624. //
  625. ASSERT((ulBase == SSI0_BASE) || (ulBase == SSI1_BASE));
  626. //
  627. // Clear the requested bits in the UART DMA control register.
  628. //
  629. HWREG(ulBase + SSI_O_DMACTL) &= ~ulDMAFlags;
  630. }
  631. //*****************************************************************************
  632. //
  633. // Close the Doxygen group.
  634. //! @}
  635. //
  636. //*****************************************************************************