ssi.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  1. //*****************************************************************************
  2. //
  3. // ssi.c - Driver for Synchronous Serial Interface.
  4. //
  5. // Copyright (c) 2005-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 8049 of the Stellaris Peripheral Driver Library.
  22. //
  23. //*****************************************************************************
  24. //*****************************************************************************
  25. //
  26. //! \addtogroup ssi_api
  27. //! @{
  28. //
  29. //*****************************************************************************
  30. #include "inc/hw_ints.h"
  31. #include "inc/hw_memmap.h"
  32. #include "inc/hw_ssi.h"
  33. #include "inc/hw_types.h"
  34. #include "driverlib/debug.h"
  35. #include "driverlib/interrupt.h"
  36. #include "driverlib/ssi.h"
  37. //*****************************************************************************
  38. //
  39. // A mapping of timer base address to interupt number.
  40. //
  41. //*****************************************************************************
  42. static const unsigned long g_ppulSSIIntMap[][2] =
  43. {
  44. { SSI0_BASE, INT_SSI0 },
  45. { SSI1_BASE, INT_SSI1 },
  46. { SSI2_BASE, INT_SSI2 },
  47. { SSI3_BASE, INT_SSI3 },
  48. };
  49. //*****************************************************************************
  50. //
  51. //! \internal
  52. //! Checks a SSI base address.
  53. //!
  54. //! \param ulBase specifies the SSI module base address.
  55. //!
  56. //! This function determines if a SSI module base address is valid.
  57. //!
  58. //! \return Returns \b true if the base address is valid and \b false
  59. //! otherwise.
  60. //
  61. //*****************************************************************************
  62. #ifdef DEBUG
  63. static tBoolean
  64. SSIBaseValid(unsigned long ulBase)
  65. {
  66. return((ulBase == SSI0_BASE) || (ulBase == SSI1_BASE) ||
  67. (ulBase == SSI2_BASE) || (ulBase == SSI3_BASE));
  68. }
  69. #endif
  70. //*****************************************************************************
  71. //
  72. //! \internal
  73. //! Gets the SSI interrupt number.
  74. //!
  75. //! \param ulBase specifies the SSI module base address.
  76. //!
  77. //! Given a SSI base address, returns the corresponding interrupt number.
  78. //!
  79. //! \return Returns a SSI interrupt number, or -1 if \e ulBase is invalid.
  80. //
  81. //*****************************************************************************
  82. static long
  83. SSIIntNumberGet(unsigned long ulBase)
  84. {
  85. unsigned long ulIdx;
  86. //
  87. // Loop through the table that maps SSI base addresses to interrupt
  88. // numbers.
  89. //
  90. for(ulIdx = 0; ulIdx < (sizeof(g_ppulSSIIntMap) /
  91. sizeof(g_ppulSSIIntMap[0])); ulIdx++)
  92. {
  93. //
  94. // See if this base address matches.
  95. //
  96. if(g_ppulSSIIntMap[ulIdx][0] == ulBase)
  97. {
  98. //
  99. // Return the corresponding interrupt number.
  100. //
  101. return(g_ppulSSIIntMap[ulIdx][1]);
  102. }
  103. }
  104. //
  105. // The base address could not be found, so return an error.
  106. //
  107. return(-1);
  108. }
  109. //*****************************************************************************
  110. //
  111. //! Configures the synchronous serial interface.
  112. //!
  113. //! \param ulBase specifies the SSI module base address.
  114. //! \param ulSSIClk is the rate of the clock supplied to the SSI module.
  115. //! \param ulProtocol specifies the data transfer protocol.
  116. //! \param ulMode specifies the mode of operation.
  117. //! \param ulBitRate specifies the clock rate.
  118. //! \param ulDataWidth specifies number of bits transferred per frame.
  119. //!
  120. //! This function configures the synchronous serial interface. It sets
  121. //! the SSI protocol, mode of operation, bit rate, and data width.
  122. //!
  123. //! The \e ulProtocol parameter defines the data frame format. The
  124. //! \e ulProtocol parameter can be one of the following values:
  125. //! \b SSI_FRF_MOTO_MODE_0, \b SSI_FRF_MOTO_MODE_1, \b SSI_FRF_MOTO_MODE_2,
  126. //! \b SSI_FRF_MOTO_MODE_3, \b SSI_FRF_TI, or \b SSI_FRF_NMW. The Motorola
  127. //! frame formats imply the following polarity and phase configurations:
  128. //!
  129. //! <pre>
  130. //! Polarity Phase Mode
  131. //! 0 0 SSI_FRF_MOTO_MODE_0
  132. //! 0 1 SSI_FRF_MOTO_MODE_1
  133. //! 1 0 SSI_FRF_MOTO_MODE_2
  134. //! 1 1 SSI_FRF_MOTO_MODE_3
  135. //! </pre>
  136. //!
  137. //! The \e ulMode parameter defines the operating mode of the SSI module. The
  138. //! SSI module can operate as a master or slave; if a slave, the SSI can be
  139. //! configured to disable output on its serial output line. The \e ulMode
  140. //! parameter can be one of the following values: \b SSI_MODE_MASTER,
  141. //! \b SSI_MODE_SLAVE, or \b SSI_MODE_SLAVE_OD.
  142. //!
  143. //! The \e ulBitRate parameter defines the bit rate for the SSI. This bit rate
  144. //! must satisfy the following clock ratio criteria:
  145. //!
  146. //! - FSSI >= 2 * bit rate (master mode)
  147. //! - FSSI >= 12 * bit rate (slave modes)
  148. //!
  149. //! where FSSI is the frequency of the clock supplied to the SSI module.
  150. //!
  151. //! The \e ulDataWidth parameter defines the width of the data transfers, and
  152. //! can be a value between 4 and 16, inclusive.
  153. //!
  154. //! The peripheral clock is the same as the processor clock. This is the value
  155. //! returned by SysCtlClockGet(), or it can be explicitly hard coded if it is
  156. //! constant and known (to save the code/execution overhead of a call to
  157. //! SysCtlClockGet()).
  158. //!
  159. //! This function replaces the original SSIConfig() API and performs the same
  160. //! actions. A macro is provided in <tt>ssi.h</tt> to map the original API to
  161. //! this API.
  162. //!
  163. //! \return None.
  164. //
  165. //*****************************************************************************
  166. void
  167. SSIConfigSetExpClk(unsigned long ulBase, unsigned long ulSSIClk,
  168. unsigned long ulProtocol, unsigned long ulMode,
  169. unsigned long ulBitRate, unsigned long ulDataWidth)
  170. {
  171. unsigned long ulMaxBitRate;
  172. unsigned long ulRegVal;
  173. unsigned long ulPreDiv;
  174. unsigned long ulSCR;
  175. unsigned long ulSPH_SPO;
  176. //
  177. // Check the arguments.
  178. //
  179. ASSERT(SSIBaseValid(ulBase));
  180. ASSERT((ulProtocol == SSI_FRF_MOTO_MODE_0) ||
  181. (ulProtocol == SSI_FRF_MOTO_MODE_1) ||
  182. (ulProtocol == SSI_FRF_MOTO_MODE_2) ||
  183. (ulProtocol == SSI_FRF_MOTO_MODE_3) ||
  184. (ulProtocol == SSI_FRF_TI) ||
  185. (ulProtocol == SSI_FRF_NMW));
  186. ASSERT((ulMode == SSI_MODE_MASTER) ||
  187. (ulMode == SSI_MODE_SLAVE) ||
  188. (ulMode == SSI_MODE_SLAVE_OD));
  189. ASSERT(((ulMode == SSI_MODE_MASTER) && (ulBitRate <= (ulSSIClk / 2))) ||
  190. ((ulMode != SSI_MODE_MASTER) && (ulBitRate <= (ulSSIClk / 12))));
  191. ASSERT((ulSSIClk / ulBitRate) <= (254 * 256));
  192. ASSERT((ulDataWidth >= 4) && (ulDataWidth <= 16));
  193. //
  194. // Set the mode.
  195. //
  196. ulRegVal = (ulMode == SSI_MODE_SLAVE_OD) ? SSI_CR1_SOD : 0;
  197. ulRegVal |= (ulMode == SSI_MODE_MASTER) ? 0 : SSI_CR1_MS;
  198. HWREG(ulBase + SSI_O_CR1) = ulRegVal;
  199. //
  200. // Set the clock predivider.
  201. //
  202. ulMaxBitRate = ulSSIClk / ulBitRate;
  203. ulPreDiv = 0;
  204. do
  205. {
  206. ulPreDiv += 2;
  207. ulSCR = (ulMaxBitRate / ulPreDiv) - 1;
  208. }
  209. while(ulSCR > 255);
  210. HWREG(ulBase + SSI_O_CPSR) = ulPreDiv;
  211. //
  212. // Set protocol and clock rate.
  213. //
  214. ulSPH_SPO = (ulProtocol & 3) << 6;
  215. ulProtocol &= SSI_CR0_FRF_M;
  216. ulRegVal = (ulSCR << 8) | ulSPH_SPO | ulProtocol | (ulDataWidth - 1);
  217. HWREG(ulBase + SSI_O_CR0) = ulRegVal;
  218. }
  219. //*****************************************************************************
  220. //
  221. //! Enables the synchronous serial interface.
  222. //!
  223. //! \param ulBase specifies the SSI module base address.
  224. //!
  225. //! This function enables operation of the synchronous serial interface. The
  226. //! synchronous serial interface must be configured before it is enabled.
  227. //!
  228. //! \return None.
  229. //
  230. //*****************************************************************************
  231. void
  232. SSIEnable(unsigned long ulBase)
  233. {
  234. //
  235. // Check the arguments.
  236. //
  237. ASSERT(SSIBaseValid(ulBase));
  238. //
  239. // Read-modify-write the enable bit.
  240. //
  241. HWREG(ulBase + SSI_O_CR1) |= SSI_CR1_SSE;
  242. }
  243. //*****************************************************************************
  244. //
  245. //! Disables the synchronous serial interface.
  246. //!
  247. //! \param ulBase specifies the SSI module base address.
  248. //!
  249. //! This function disables operation of the synchronous serial interface.
  250. //!
  251. //! \return None.
  252. //
  253. //*****************************************************************************
  254. void
  255. SSIDisable(unsigned long ulBase)
  256. {
  257. //
  258. // Check the arguments.
  259. //
  260. ASSERT(SSIBaseValid(ulBase));
  261. //
  262. // Read-modify-write the enable bit.
  263. //
  264. HWREG(ulBase + SSI_O_CR1) &= ~(SSI_CR1_SSE);
  265. }
  266. //*****************************************************************************
  267. //
  268. //! Registers an interrupt handler for the synchronous serial interface.
  269. //!
  270. //! \param ulBase specifies the SSI module base address.
  271. //! \param pfnHandler is a pointer to the function to be called when the
  272. //! synchronous serial interface interrupt occurs.
  273. //!
  274. //! This sets the handler to be called when an SSI interrupt
  275. //! occurs. This will enable the global interrupt in the interrupt controller;
  276. //! specific SSI interrupts must be enabled via SSIIntEnable(). If necessary,
  277. //! it is the interrupt handler's responsibility to clear the interrupt source
  278. //! via SSIIntClear().
  279. //!
  280. //! \sa IntRegister() for important information about registering interrupt
  281. //! handlers.
  282. //!
  283. //! \return None.
  284. //
  285. //*****************************************************************************
  286. void
  287. SSIIntRegister(unsigned long ulBase, void (*pfnHandler)(void))
  288. {
  289. unsigned long ulInt;
  290. //
  291. // Check the arguments.
  292. //
  293. ASSERT(SSIBaseValid(ulBase));
  294. //
  295. // Determine the interrupt number based on the SSI port.
  296. //
  297. ulInt = SSIIntNumberGet(ulBase);
  298. //
  299. // Register the interrupt handler, returning an error if an error occurs.
  300. //
  301. IntRegister(ulInt, pfnHandler);
  302. //
  303. // Enable the synchronous serial interface interrupt.
  304. //
  305. IntEnable(ulInt);
  306. }
  307. //*****************************************************************************
  308. //
  309. //! Unregisters an interrupt handler for the synchronous serial interface.
  310. //!
  311. //! \param ulBase specifies the SSI module base address.
  312. //!
  313. //! This function will clear the handler to be called when a SSI
  314. //! interrupt occurs. This will also mask off the interrupt in the interrupt
  315. //! controller so that the interrupt handler no longer is called.
  316. //!
  317. //! \sa IntRegister() for important information about registering interrupt
  318. //! handlers.
  319. //!
  320. //! \return None.
  321. //
  322. //*****************************************************************************
  323. void
  324. SSIIntUnregister(unsigned long ulBase)
  325. {
  326. unsigned long ulInt;
  327. //
  328. // Check the arguments.
  329. //
  330. ASSERT(SSIBaseValid(ulBase));
  331. //
  332. // Determine the interrupt number based on the SSI port.
  333. //
  334. ulInt = SSIIntNumberGet(ulBase);
  335. //
  336. // Disable the interrupt.
  337. //
  338. IntDisable(ulInt);
  339. //
  340. // Unregister the interrupt handler.
  341. //
  342. IntUnregister(ulInt);
  343. }
  344. //*****************************************************************************
  345. //
  346. //! Enables individual SSI interrupt sources.
  347. //!
  348. //! \param ulBase specifies the SSI module base address.
  349. //! \param ulIntFlags is a bit mask of the interrupt sources to be enabled.
  350. //!
  351. //! Enables the indicated SSI interrupt sources. Only the sources that are
  352. //! enabled can be reflected to the processor interrupt; disabled sources have
  353. //! no effect on the processor. The \e ulIntFlags parameter can be any of the
  354. //! \b SSI_TXFF, \b SSI_RXFF, \b SSI_RXTO, or \b SSI_RXOR values.
  355. //!
  356. //! \return None.
  357. //
  358. //*****************************************************************************
  359. void
  360. SSIIntEnable(unsigned long ulBase, unsigned long ulIntFlags)
  361. {
  362. //
  363. // Check the arguments.
  364. //
  365. ASSERT(SSIBaseValid(ulBase));
  366. //
  367. // Enable the specified interrupts.
  368. //
  369. HWREG(ulBase + SSI_O_IM) |= ulIntFlags;
  370. }
  371. //*****************************************************************************
  372. //
  373. //! Disables individual SSI interrupt sources.
  374. //!
  375. //! \param ulBase specifies the SSI module base address.
  376. //! \param ulIntFlags is a bit mask of the interrupt sources to be disabled.
  377. //!
  378. //! Disables the indicated SSI interrupt sources. The \e ulIntFlags parameter
  379. //! can be any of the \b SSI_TXFF, \b SSI_RXFF, \b SSI_RXTO, or \b SSI_RXOR
  380. //! values.
  381. //!
  382. //! \return None.
  383. //
  384. //*****************************************************************************
  385. void
  386. SSIIntDisable(unsigned long ulBase, unsigned long ulIntFlags)
  387. {
  388. //
  389. // Check the arguments.
  390. //
  391. ASSERT(SSIBaseValid(ulBase));
  392. //
  393. // Disable the specified interrupts.
  394. //
  395. HWREG(ulBase + SSI_O_IM) &= ~(ulIntFlags);
  396. }
  397. //*****************************************************************************
  398. //
  399. //! Gets the current interrupt status.
  400. //!
  401. //! \param ulBase specifies the SSI module base address.
  402. //! \param bMasked is \b false if the raw interrupt status is required or
  403. //! \b true if the masked interrupt status is required.
  404. //!
  405. //! This function returns the interrupt status for the SSI module. Either the
  406. //! raw interrupt status or the status of interrupts that are allowed to
  407. //! reflect to the processor can be returned.
  408. //!
  409. //! \return The current interrupt status, enumerated as a bit field of
  410. //! \b SSI_TXFF, \b SSI_RXFF, \b SSI_RXTO, and \b SSI_RXOR.
  411. //
  412. //*****************************************************************************
  413. unsigned long
  414. SSIIntStatus(unsigned long ulBase, tBoolean bMasked)
  415. {
  416. //
  417. // Check the arguments.
  418. //
  419. ASSERT(SSIBaseValid(ulBase));
  420. //
  421. // Return either the interrupt status or the raw interrupt status as
  422. // requested.
  423. //
  424. if(bMasked)
  425. {
  426. return(HWREG(ulBase + SSI_O_MIS));
  427. }
  428. else
  429. {
  430. return(HWREG(ulBase + SSI_O_RIS));
  431. }
  432. }
  433. //*****************************************************************************
  434. //
  435. //! Clears SSI interrupt sources.
  436. //!
  437. //! \param ulBase specifies the SSI module base address.
  438. //! \param ulIntFlags is a bit mask of the interrupt sources to be cleared.
  439. //!
  440. //! The specified SSI interrupt sources are cleared so that they no longer
  441. //! assert. This function must be called in the interrupt handler to keep the
  442. //! interrupts from being recognized again immediately upon exit. The
  443. //! \e ulIntFlags parameter can consist of either or both the \b SSI_RXTO and
  444. //! \b SSI_RXOR values.
  445. //!
  446. //! \note Because there is a write buffer in the Cortex-M3 processor, it may
  447. //! take several clock cycles before the interrupt source is actually cleared.
  448. //! Therefore, it is recommended that the interrupt source be cleared early in
  449. //! the interrupt handler (as opposed to the very last action) to avoid
  450. //! returning from the interrupt handler before the interrupt source is
  451. //! actually cleared. Failure to do so may result in the interrupt handler
  452. //! being immediately reentered (because the interrupt controller still sees
  453. //! the interrupt source asserted).
  454. //!
  455. //! \return None.
  456. //
  457. //*****************************************************************************
  458. void
  459. SSIIntClear(unsigned long ulBase, unsigned long ulIntFlags)
  460. {
  461. //
  462. // Check the arguments.
  463. //
  464. ASSERT(SSIBaseValid(ulBase));
  465. //
  466. // Clear the requested interrupt sources.
  467. //
  468. HWREG(ulBase + SSI_O_ICR) = ulIntFlags;
  469. }
  470. //*****************************************************************************
  471. //
  472. //! Puts a data element into the SSI transmit FIFO.
  473. //!
  474. //! \param ulBase specifies the SSI module base address.
  475. //! \param ulData is the data to be transmitted over the SSI interface.
  476. //!
  477. //! This function places the supplied data into the transmit FIFO of the
  478. //! specified SSI module.
  479. //!
  480. //! \note The upper 32 - N bits of the \e ulData are discarded by the hardware,
  481. //! where N is the data width as configured by SSIConfigSetExpClk(). For
  482. //! example, if the interface is configured for 8-bit data width, the upper 24
  483. //! bits of \e ulData are discarded.
  484. //!
  485. //! \return None.
  486. //
  487. //*****************************************************************************
  488. void
  489. SSIDataPut(unsigned long ulBase, unsigned long ulData)
  490. {
  491. //
  492. // Check the arguments.
  493. //
  494. ASSERT(SSIBaseValid(ulBase));
  495. ASSERT((ulData & (0xfffffffe << (HWREG(ulBase + SSI_O_CR0) &
  496. SSI_CR0_DSS_M))) == 0);
  497. //
  498. // Wait until there is space.
  499. //
  500. while(!(HWREG(ulBase + SSI_O_SR) & SSI_SR_TNF))
  501. {
  502. }
  503. //
  504. // Write the data to the SSI.
  505. //
  506. HWREG(ulBase + SSI_O_DR) = ulData;
  507. }
  508. //*****************************************************************************
  509. //
  510. //! Puts a data element into the SSI transmit FIFO.
  511. //!
  512. //! \param ulBase specifies the SSI module base address.
  513. //! \param ulData is the data to be transmitted over the SSI interface.
  514. //!
  515. //! This function places the supplied data into the transmit FIFO of the
  516. //! specified SSI module. If there is no space in the FIFO, then this function
  517. //! returns a zero.
  518. //!
  519. //! This function replaces the original SSIDataNonBlockingPut() API and
  520. //! performs the same actions. A macro is provided in <tt>ssi.h</tt> to map
  521. //! the original API to this API.
  522. //!
  523. //! \note The upper 32 - N bits of the \e ulData are discarded by the hardware,
  524. //! where N is the data width as configured by SSIConfigSetExpClk(). For
  525. //! example, if the interface is configured for 8-bit data width, the upper 24
  526. //! bits of \e ulData are discarded.
  527. //!
  528. //! \return Returns the number of elements written to the SSI transmit FIFO.
  529. //
  530. //*****************************************************************************
  531. long
  532. SSIDataPutNonBlocking(unsigned long ulBase, unsigned long ulData)
  533. {
  534. //
  535. // Check the arguments.
  536. //
  537. ASSERT(SSIBaseValid(ulBase));
  538. ASSERT((ulData & (0xfffffffe << (HWREG(ulBase + SSI_O_CR0) &
  539. SSI_CR0_DSS_M))) == 0);
  540. //
  541. // Check for space to write.
  542. //
  543. if(HWREG(ulBase + SSI_O_SR) & SSI_SR_TNF)
  544. {
  545. HWREG(ulBase + SSI_O_DR) = ulData;
  546. return(1);
  547. }
  548. else
  549. {
  550. return(0);
  551. }
  552. }
  553. //*****************************************************************************
  554. //
  555. //! Gets a data element from the SSI receive FIFO.
  556. //!
  557. //! \param ulBase specifies the SSI module base address.
  558. //! \param pulData is a pointer to a storage location for data that was
  559. //! received over the SSI interface.
  560. //!
  561. //! This function gets received data from the receive FIFO of the specified
  562. //! SSI module and places that data into the location specified by the
  563. //! \e pulData parameter.
  564. //!
  565. //! \note Only the lower N bits of the value written to \e pulData contain
  566. //! valid data, where N is the data width as configured by
  567. //! SSIConfigSetExpClk(). For example, if the interface is configured for
  568. //! 8-bit data width, only the lower 8 bits of the value written to \e pulData
  569. //! contain valid data.
  570. //!
  571. //! \return None.
  572. //
  573. //*****************************************************************************
  574. void
  575. SSIDataGet(unsigned long ulBase, unsigned long *pulData)
  576. {
  577. //
  578. // Check the arguments.
  579. //
  580. ASSERT(SSIBaseValid(ulBase));
  581. //
  582. // Wait until there is data to be read.
  583. //
  584. while(!(HWREG(ulBase + SSI_O_SR) & SSI_SR_RNE))
  585. {
  586. }
  587. //
  588. // Read data from SSI.
  589. //
  590. *pulData = HWREG(ulBase + SSI_O_DR);
  591. }
  592. //*****************************************************************************
  593. //
  594. //! Gets a data element from the SSI receive FIFO.
  595. //!
  596. //! \param ulBase specifies the SSI module base address.
  597. //! \param pulData is a pointer to a storage location for data that was
  598. //! received over the SSI interface.
  599. //!
  600. //! This function gets received data from the receive FIFO of the specified SSI
  601. //! module and places that data into the location specified by the \e ulData
  602. //! parameter. If there is no data in the FIFO, then this function returns a
  603. //! zero.
  604. //!
  605. //! This function replaces the original SSIDataNonBlockingGet() API and
  606. //! performs the same actions. A macro is provided in <tt>ssi.h</tt> to map
  607. //! the original API to this API.
  608. //!
  609. //! \note Only the lower N bits of the value written to \e pulData contain
  610. //! valid data, where N is the data width as configured by
  611. //! SSIConfigSetExpClk(). For example, if the interface is configured for
  612. //! 8-bit data width, only the lower 8 bits of the value written to \e pulData
  613. //! contain valid data.
  614. //!
  615. //! \return Returns the number of elements read from the SSI receive FIFO.
  616. //
  617. //*****************************************************************************
  618. long
  619. SSIDataGetNonBlocking(unsigned long ulBase, unsigned long *pulData)
  620. {
  621. //
  622. // Check the arguments.
  623. //
  624. ASSERT(SSIBaseValid(ulBase));
  625. //
  626. // Check for data to read.
  627. //
  628. if(HWREG(ulBase + SSI_O_SR) & SSI_SR_RNE)
  629. {
  630. *pulData = HWREG(ulBase + SSI_O_DR);
  631. return(1);
  632. }
  633. else
  634. {
  635. return(0);
  636. }
  637. }
  638. //*****************************************************************************
  639. //
  640. //! Enable SSI DMA operation.
  641. //!
  642. //! \param ulBase is the base address of the SSI port.
  643. //! \param ulDMAFlags is a bit mask of the DMA features to enable.
  644. //!
  645. //! The specified SSI DMA features are enabled. The SSI can be
  646. //! configured to use DMA for transmit and/or receive data transfers.
  647. //! The \e ulDMAFlags parameter is the logical OR of any of the following
  648. //! values:
  649. //!
  650. //! - SSI_DMA_RX - enable DMA for receive
  651. //! - SSI_DMA_TX - enable DMA for transmit
  652. //!
  653. //! \note The uDMA controller must also be set up before DMA can be used
  654. //! with the SSI.
  655. //!
  656. //! \return None.
  657. //
  658. //*****************************************************************************
  659. void
  660. SSIDMAEnable(unsigned long ulBase, unsigned long ulDMAFlags)
  661. {
  662. //
  663. // Check the arguments.
  664. //
  665. ASSERT(SSIBaseValid(ulBase));
  666. //
  667. // Set the requested bits in the SSI DMA control register.
  668. //
  669. HWREG(ulBase + SSI_O_DMACTL) |= ulDMAFlags;
  670. }
  671. //*****************************************************************************
  672. //
  673. //! Disable SSI DMA operation.
  674. //!
  675. //! \param ulBase is the base address of the SSI port.
  676. //! \param ulDMAFlags is a bit mask of the DMA features to disable.
  677. //!
  678. //! This function is used to disable SSI DMA features that were enabled
  679. //! by SSIDMAEnable(). The specified SSI DMA features are disabled. The
  680. //! \e ulDMAFlags parameter is the logical OR of any of the following values:
  681. //!
  682. //! - SSI_DMA_RX - disable DMA for receive
  683. //! - SSI_DMA_TX - disable DMA for transmit
  684. //!
  685. //! \return None.
  686. //
  687. //*****************************************************************************
  688. void
  689. SSIDMADisable(unsigned long ulBase, unsigned long ulDMAFlags)
  690. {
  691. //
  692. // Check the arguments.
  693. //
  694. ASSERT(SSIBaseValid(ulBase));
  695. //
  696. // Clear the requested bits in the SSI DMA control register.
  697. //
  698. HWREG(ulBase + SSI_O_DMACTL) &= ~ulDMAFlags;
  699. }
  700. //*****************************************************************************
  701. //
  702. //! Determines whether the SSI transmitter is busy or not.
  703. //!
  704. //! \param ulBase is the base address of the SSI port.
  705. //!
  706. //! Allows the caller to determine whether all transmitted bytes have cleared
  707. //! the transmitter hardware. If \b false is returned, then the transmit FIFO
  708. //! is empty and all bits of the last transmitted word have left the hardware
  709. //! shift register.
  710. //!
  711. //! \return Returns \b true if the SSI is transmitting or \b false if all
  712. //! transmissions are complete.
  713. //
  714. //*****************************************************************************
  715. tBoolean
  716. SSIBusy(unsigned long ulBase)
  717. {
  718. //
  719. // Check the arguments.
  720. //
  721. ASSERT(SSIBaseValid(ulBase));
  722. //
  723. // Determine if the SSI is busy.
  724. //
  725. return((HWREG(ulBase + SSI_O_SR) & SSI_SR_BSY) ? true : false);
  726. }
  727. //*****************************************************************************
  728. //
  729. //! Sets the data clock source for the specified SSI peripheral.
  730. //!
  731. //! \param ulBase is the base address of the SSI port.
  732. //! \param ulSource is the baud clock source for the SSI.
  733. //!
  734. //! This function allows the baud clock source for the SSI to be selected.
  735. //! The possible clock source are the system clock (\b SSI_CLOCK_SYSTEM) or
  736. //! the precision internal oscillator (\b SSI_CLOCK_PIOSC).
  737. //!
  738. //! Changing the baud clock source will change the data rate generated by the
  739. //! SSI. Therefore, the data rate should be reconfigured after any change to
  740. //! the SSI clock source.
  741. //!
  742. //! \note The ability to specify the SSI baud clock source varies with the
  743. //! Stellaris part and SSI in use. Please consult the data sheet for the part
  744. //! you are using to determine whether this support is available.
  745. //!
  746. //! \return None.
  747. //
  748. //*****************************************************************************
  749. void
  750. SSIClockSourceSet(unsigned long ulBase, unsigned long ulSource)
  751. {
  752. //
  753. // Check the arguments.
  754. //
  755. ASSERT(SSIBaseValid(ulBase));
  756. ASSERT((ulSource == SSI_CLOCK_SYSTEM) || (ulSource == SSI_CLOCK_PIOSC));
  757. //
  758. // Set the SSI clock source.
  759. //
  760. HWREG(ulBase + SSI_O_CC) = ulSource;
  761. }
  762. //*****************************************************************************
  763. //
  764. //! Gets the data clock source for the specified SSI peripheral.
  765. //!
  766. //! \param ulBase is the base address of the SSI port.
  767. //!
  768. //! This function returns the data clock source for the specified SSI. The
  769. //! possible data clock source are the system clock (\b SSI_CLOCK_SYSTEM) or
  770. //! the precision internal oscillator (\b SSI_CLOCK_PIOSC).
  771. //!
  772. //! \note The ability to specify the SSI data clock source varies with the
  773. //! Stellaris part and SSI in use. Please consult the data sheet for the part
  774. //! you are using to determine whether this support is available.
  775. //!
  776. //! \return None.
  777. //
  778. //*****************************************************************************
  779. unsigned long
  780. SSIClockSourceGet(unsigned long ulBase)
  781. {
  782. //
  783. // Check the arguments.
  784. //
  785. ASSERT(SSIBaseValid(ulBase));
  786. //
  787. // Return the SSI clock source.
  788. //
  789. return(HWREG(ulBase + SSI_O_CC));
  790. }
  791. //*****************************************************************************
  792. //
  793. // Close the Doxygen group.
  794. //! @}
  795. //
  796. //*****************************************************************************