sdhost.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. //*****************************************************************************
  2. //
  3. // sdhost.c
  4. //
  5. // Driver for the SD Host (SDHost) Interface
  6. //
  7. // Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
  8. //
  9. //
  10. // Redistribution and use in source and binary forms, with or without
  11. // modification, are permitted provided that the following conditions
  12. // are met:
  13. //
  14. // Redistributions of source code must retain the above copyright
  15. // notice, this list of conditions and the following disclaimer.
  16. //
  17. // Redistributions in binary form must reproduce the above copyright
  18. // notice, this list of conditions and the following disclaimer in the
  19. // documentation and/or other materials provided with the
  20. // distribution.
  21. //
  22. // Neither the name of Texas Instruments Incorporated nor the names of
  23. // its contributors may be used to endorse or promote products derived
  24. // from this software without specific prior written permission.
  25. //
  26. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  27. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  28. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  29. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  30. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  31. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  32. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  33. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  34. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  35. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  36. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  37. //
  38. //*****************************************************************************
  39. //*****************************************************************************
  40. //
  41. //! \addtogroup Secure_Digital_Host_api
  42. //! @{
  43. //
  44. //*****************************************************************************
  45. #include "inc/hw_types.h"
  46. #include "inc/hw_memmap.h"
  47. #include "inc/hw_mmchs.h"
  48. #include "inc/hw_ints.h"
  49. #include "inc/hw_apps_config.h"
  50. #include "interrupt.h"
  51. #include "sdhost.h"
  52. //*****************************************************************************
  53. //
  54. //! Configures SDHost module.
  55. //!
  56. //! \param ulBase is the base address of SDHost module.
  57. //!
  58. //! This function configures the SDHost module, enabling internal sub-modules.
  59. //!
  60. //! \return None.
  61. //
  62. //*****************************************************************************
  63. void
  64. SDHostInit(unsigned long ulBase)
  65. {
  66. //
  67. // Assert module reset
  68. //
  69. HWREG(ulBase + MMCHS_O_SYSCONFIG) = 0x2;
  70. //
  71. // Wait for soft reset to complete
  72. //
  73. while( !(HWREG(ulBase + MMCHS_O_SYSCONFIG) & 0x1) )
  74. {
  75. }
  76. //
  77. // Assert internal reset
  78. //
  79. HWREG(ulBase + MMCHS_O_SYSCTL) |= (1 << 24);
  80. //
  81. // Wait for Reset to complete
  82. //
  83. while( (HWREG(ulBase + MMCHS_O_SYSCTL) & (0x1 << 24)) )
  84. {
  85. }
  86. //
  87. // Set capability register, 1.8 and 3.0 V
  88. //
  89. HWREG(ulBase + MMCHS_O_CAPA) = (0x7 <<24);
  90. //
  91. // Select bus voltage, 3.0 V
  92. //
  93. HWREG(ulBase + MMCHS_O_HCTL) |= 0x7 << 9;
  94. //
  95. // Power up the bus
  96. //
  97. HWREG(ulBase + MMCHS_O_HCTL) |= 1 << 8;
  98. //
  99. // Wait for power on
  100. //
  101. while( !(HWREG(ulBase + MMCHS_O_HCTL) & (1<<8)) )
  102. {
  103. }
  104. HWREG(ulBase + MMCHS_O_CON) |= 1 << 21;
  105. //
  106. // Un-mask all events
  107. //
  108. HWREG(ulBase + MMCHS_O_IE) = 0xFFFFFFFF;
  109. }
  110. //*****************************************************************************
  111. //
  112. //! Resets SDHost command line
  113. //!
  114. //! \param ulBase is the base address of SDHost module.
  115. //!
  116. //! This function assers a soft reset for the command line
  117. //!
  118. //! \return None.
  119. //
  120. //*****************************************************************************
  121. void
  122. SDHostCmdReset(unsigned long ulBase)
  123. {
  124. HWREG(ulBase + MMCHS_O_SYSCTL) |= 1 << 25;
  125. while( (HWREG(ulBase + MMCHS_O_SYSCTL) & (1 << 25)) )
  126. {
  127. }
  128. }
  129. //*****************************************************************************
  130. //
  131. //! Sends command over SDHost interface
  132. //!
  133. //! \param ulBase is the base address of SDHost module.
  134. //! \param ulCmd is the command to send.
  135. //! \param ulArg is the argument for the command.
  136. //!
  137. //! This function send command to the attached card over the SDHost interface.
  138. //!
  139. //! The \e ulCmd parameter can be one of \b SDHOST_CMD_0 to \b SDHOST_CMD_63.
  140. //! It can be logically ORed with one or more of the following:
  141. //! - \b SDHOST_MULTI_BLK for multi-block transfer
  142. //! - \b SDHOST_WR_CMD if command is followed by write data
  143. //! - \b SDHOST_RD_CMD if command is followed by read data
  144. //! - \b SDHOST_DMA_EN if SDHost need to generate DMA request.
  145. //! - \b SDHOST_RESP_LEN_136 if 136 bit response is expected
  146. //! - \b SDHOST_RESP_LEN_48 if 48 bit response is expected
  147. //! - \b SDHOST_RESP_LEN_48B if 48 bit response with busy bit is expected
  148. //!
  149. //! The parameter \e ulArg is the argument for the command
  150. //!
  151. //! \return Returns 0 on success, -1 otherwise.
  152. //
  153. //*****************************************************************************
  154. long
  155. SDHostCmdSend(unsigned long ulBase, unsigned long ulCmd, unsigned ulArg)
  156. {
  157. //
  158. // Set Data Timeout
  159. //
  160. HWREG(ulBase + MMCHS_O_SYSCTL) |= 0x000E0000;
  161. //
  162. // Check for cmd inhabit
  163. //
  164. if( (HWREG(ulBase + MMCHS_O_PSTATE) & 0x1))
  165. {
  166. return -1;
  167. }
  168. //
  169. // Set the argument
  170. //
  171. HWREG(ulBase + MMCHS_O_ARG) = ulArg;
  172. //
  173. // Send the command
  174. //
  175. HWREG(ulBase + MMCHS_O_CMD) = ulCmd;
  176. return 0;
  177. }
  178. //*****************************************************************************
  179. //
  180. //! Writes a data word into the SDHost write buffer.
  181. //!
  182. //! \param ulBase is the base address of SDHost module.
  183. //! \param ulData is data word to be transfered.
  184. //!
  185. //! This function writes a single data word into the SDHost write buffer. The
  186. //! function returns \b true if there was a space available in the buffer else
  187. //! returns \b false.
  188. //!
  189. //! \return Return \b true on success, \b false otherwise.
  190. //
  191. //*****************************************************************************
  192. tBoolean
  193. SDHostDataNonBlockingWrite(unsigned long ulBase, unsigned long ulData)
  194. {
  195. //
  196. // See if there is a space in the write buffer
  197. //
  198. if( (HWREG(ulBase + MMCHS_O_PSTATE) & (1<<10)) )
  199. {
  200. //
  201. // Write the data into the buffer
  202. //
  203. HWREG(ulBase + MMCHS_O_DATA) = ulData;
  204. //
  205. // Success.
  206. //
  207. return(true);
  208. }
  209. else
  210. {
  211. //
  212. // No free sapce, failure.
  213. //
  214. return(false);
  215. }
  216. }
  217. //*****************************************************************************
  218. //
  219. //! Waits to write a data word into the SDHost write buffer.
  220. //!
  221. //! \param ulBase is the base address of SDHost module.
  222. //! \param ulData is data word to be transfered.
  223. //!
  224. //! This function writes \e ulData into the SDHost write buffer. If there is no
  225. //! space in the write buffer this function waits until there is a space
  226. //! available before returning.
  227. //!
  228. //! \return None.
  229. //
  230. //*****************************************************************************
  231. void
  232. SDHostDataWrite(unsigned long ulBase, unsigned long ulData)
  233. {
  234. //
  235. // Wait until space is available
  236. //
  237. while( !(HWREG(ulBase + MMCHS_O_PSTATE) & (1<<10)) )
  238. {
  239. }
  240. //
  241. // Write the data
  242. //
  243. HWREG(ulBase + MMCHS_O_DATA) = ulData;
  244. }
  245. //*****************************************************************************
  246. //
  247. //! Waits for a data word from the SDHost read buffer
  248. //!
  249. //! \param ulBase is the base address of SDHost module.
  250. //! \param pulData is pointer to read data variable.
  251. //!
  252. //! This function reads a single data word from the SDHost read buffer. If there
  253. //! is no data available in the buffer the function will wait until a data
  254. //! word is received before returning.
  255. //!
  256. //! \return None.
  257. //
  258. //*****************************************************************************
  259. void
  260. SDHostDataRead(unsigned long ulBase, unsigned long *pulData)
  261. {
  262. //
  263. // Wait until data is available
  264. //
  265. while( !(HWREG(ulBase + MMCHS_O_PSTATE) & (1<<11)) )
  266. {
  267. }
  268. //
  269. // Read the data
  270. //
  271. *pulData = HWREG(ulBase + MMCHS_O_DATA);
  272. }
  273. //*****************************************************************************
  274. //
  275. //! Reads single data word from the SDHost read buffer
  276. //!
  277. //! \param ulBase is the base address of SDHost module.
  278. //! \param pulData is pointer to read data variable.
  279. //!
  280. //! This function reads a data word from the SDHost read buffer. The
  281. //! function returns \b true if there was data available in to buffer else
  282. //! returns \b false.
  283. //!
  284. //! \return Return \b true on success, \b false otherwise.
  285. //
  286. //*****************************************************************************
  287. tBoolean
  288. SDHostDataNonBlockingRead(unsigned long ulBase, unsigned long *pulData)
  289. {
  290. //
  291. // See if there is any data in the read buffer.
  292. //
  293. if( (HWREG(ulBase + MMCHS_O_PSTATE) & (1<11)) )
  294. {
  295. //
  296. // Read the data word.
  297. //
  298. *pulData = HWREG(ulBase + MMCHS_O_DATA);
  299. //
  300. // Success
  301. //
  302. return(true);
  303. }
  304. else
  305. {
  306. //
  307. // No data available, failure.
  308. //
  309. return(false);
  310. }
  311. }
  312. //*****************************************************************************
  313. //
  314. //! Registers the interrupt handler for SDHost interrupt
  315. //!
  316. //! \param ulBase is the base address of SDHost module
  317. //! \param pfnHandler is a pointer to the function to be called when the
  318. //! SDHost interrupt occurs.
  319. //!
  320. //! This function does the actual registering of the interrupt handler. This
  321. //! function enables the global interrupt in the interrupt controller; specific
  322. //! SDHost interrupts must be enabled via SDHostIntEnable(). It is the
  323. //! interrupt handler's responsibility to clear the interrupt source.
  324. //!
  325. //! \sa IntRegister() for important information about registering interrupt
  326. //! handlers.
  327. //!
  328. //! \return None.
  329. //
  330. //*****************************************************************************
  331. void
  332. SDHostIntRegister(unsigned long ulBase, void (*pfnHandler)(void))
  333. {
  334. //
  335. // Register the interrupt handler.
  336. //
  337. IntRegister(INT_MMCHS, pfnHandler);
  338. //
  339. // Enable the SDHost interrupt.
  340. //
  341. IntEnable(INT_MMCHS);
  342. }
  343. //*****************************************************************************
  344. //
  345. //! Unregisters the interrupt handler for SDHost interrupt
  346. //!
  347. //! \param ulBase is the base address of SDHost module
  348. //!
  349. //! This function does the actual unregistering of the interrupt handler. It
  350. //! clears the handler to be called when a SDHost interrupt occurs. This
  351. //! function also masks off the interrupt in the interrupt controller so that
  352. //! the interrupt handler no longer is called.
  353. //!
  354. //! \sa IntRegister() for important information about registering interrupt
  355. //! handlers.
  356. //!
  357. //! \return None.
  358. //
  359. //*****************************************************************************
  360. void
  361. SDHostIntUnregister(unsigned long ulBase)
  362. {
  363. //
  364. // Disable the SDHost interrupt.
  365. //
  366. IntDisable(INT_MMCHS);
  367. //
  368. // Unregister the interrupt handler.
  369. //
  370. IntUnregister(INT_MMCHS);
  371. }
  372. //*****************************************************************************
  373. //
  374. //! Enable individual interrupt source for the specified SDHost
  375. //!
  376. //! \param ulBase is the base address of SDHost module.
  377. //! \param ulIntFlags is a bit mask of the interrupt sources to be enabled.
  378. //!
  379. //! This function enables the indicated SDHost interrupt sources. Only the
  380. //! sources that are enabled can be reflected to the processor interrupt;
  381. //! disabled sources have no effect on the processor.
  382. //!
  383. //! The \e ulIntFlags parameter is the logical OR of any of the following:
  384. //! - \b SDHOST_INT_CC Command Complete interrupt
  385. //! - \b SDHOST_INT_TC Transfer Complete interrupt
  386. //! - \b SDHOST_INT_BWR Buffer Write Ready interrupt
  387. //! - \b SDHOST_INT_BRR Buffer Read Ready interrupt
  388. //! - \b SDHOST_INT_ERRI Error interrupt
  389. //! - \b SDHOST_INT_CTO Command Timeout error interrupt
  390. //! - \b SDHOST_INT_CEB Command End Bit error interrupt
  391. //! - \b SDHOST_INT_DTO Data Timeout error interrupt
  392. //! - \b SDHOST_INT_DCRC Data CRC error interrupt
  393. //! - \b SDHOST_INT_DEB Data End Bit error
  394. //! - \b SDHOST_INT_CERR Cart Status Error interrupt
  395. //! - \b SDHOST_INT_BADA Bad Data error interrupt
  396. //! - \b SDHOST_INT_DMARD Read DMA done interrupt
  397. //! - \b SDHOST_INT_DMAWR Write DMA done interrupt
  398. //!
  399. //! Note that SDHOST_INT_ERRI can only be used with \sa SDHostIntStatus()
  400. //! and is internally logical OR of all error status bits. Setting this bit
  401. //! alone as \e ulIntFlags doesn't generates any interrupt.
  402. //!
  403. //! \return None.
  404. //
  405. //*****************************************************************************
  406. void
  407. SDHostIntEnable(unsigned long ulBase,unsigned long ulIntFlags)
  408. {
  409. //
  410. // Enable DMA done interrupts
  411. //
  412. HWREG(APPS_CONFIG_BASE + APPS_CONFIG_O_DMA_DONE_INT_MASK_CLR) =
  413. (ulIntFlags >> 30);
  414. //
  415. // Enable the individual interrupt sources
  416. //
  417. HWREG(ulBase + MMCHS_O_ISE) |= (ulIntFlags & 0x3FFFFFFF);
  418. }
  419. //*****************************************************************************
  420. //
  421. //! Enable individual interrupt source for the specified SDHost
  422. //!
  423. //! \param ulBase is the base address of SDHost module.
  424. //! \param ulIntFlags is a bit mask of the interrupt sources to be enabled.
  425. //!
  426. //! This function disables the indicated SDHost interrupt sources. Only the
  427. //! sources that are enabled can be reflected to the processor interrupt;
  428. //! disabled sources have no effect on the processor.
  429. //!
  430. //! The \e ulIntFlags parameter has the same definition as the \e ulIntFlags
  431. //! parameter to SDHostIntEnable().
  432. //!
  433. //! \return None.
  434. //
  435. //*****************************************************************************
  436. void
  437. SDHostIntDisable(unsigned long ulBase,unsigned long ulIntFlags)
  438. {
  439. //
  440. // Disable DMA done interrupts
  441. //
  442. HWREG(APPS_CONFIG_BASE + APPS_CONFIG_O_DMA_DONE_INT_MASK_SET) =
  443. (ulIntFlags >> 30);
  444. //
  445. // Disable the individual interrupt sources
  446. //
  447. HWREG(ulBase + MMCHS_O_ISE) &= ~(ulIntFlags & 0x3FFFFFFF);
  448. }
  449. //*****************************************************************************
  450. //
  451. //! Gets the current interrupt status.
  452. //!
  453. //! \param ulBase is the base address of SDHost module.
  454. //!
  455. //! This function returns the interrupt status for the specified SDHost.
  456. //!
  457. //! \return Returns the current interrupt status, enumerated as a bit field of
  458. //! values described in SDHostIntEnable().
  459. //
  460. //*****************************************************************************
  461. unsigned long
  462. SDHostIntStatus(unsigned long ulBase)
  463. {
  464. unsigned long ulIntStatus;
  465. //
  466. // Get DMA done interrupt status
  467. //
  468. ulIntStatus = HWREG(APPS_CONFIG_BASE + APPS_CONFIG_O_DMA_DONE_INT_STS_RAW);
  469. ulIntStatus = (ulIntStatus << 30);
  470. //
  471. // Return the status of individual interrupt sources
  472. //
  473. ulIntStatus |= (HWREG(ulBase + MMCHS_O_STAT) & 0x3FFFFFFF);
  474. return(ulIntStatus);
  475. }
  476. //*****************************************************************************
  477. //
  478. //! Clears the individual interrupt sources.
  479. //!
  480. //! \param ulBase is the base address of SDHost module.
  481. //! \param ulIntFlags is a bit mask of the interrupt sources to be cleared.
  482. //!
  483. //! The specified SDHost interrupt sources are cleared, so that they no longer
  484. //! assert. This function must be called in the interrupt handler to keep the
  485. //! interrupt from being recognized again immediately upon exit.
  486. //!
  487. //! The \e ulIntFlags parameter has the same definition as the \e ulIntFlags
  488. //! parameter to SDHostIntEnable().
  489. //!
  490. //! \return None.
  491. //
  492. //*****************************************************************************
  493. void
  494. SDHostIntClear(unsigned long ulBase,unsigned long ulIntFlags)
  495. {
  496. //
  497. // Clear DMA done interrupts
  498. //
  499. HWREG(APPS_CONFIG_BASE + APPS_CONFIG_O_DMA_DONE_INT_ACK) =
  500. (ulIntFlags >> 30);
  501. //
  502. // Clear the individual interrupt sources
  503. //
  504. HWREG(ulBase + MMCHS_O_STAT) = (ulIntFlags & 0x3FFFFFFF);
  505. }
  506. //*****************************************************************************
  507. //
  508. //! Sets the card status error mask.
  509. //!
  510. //! \param ulBase is the base address of SDHost module
  511. //! \param ulErrMask is the bit mask of card status errors to be enabled
  512. //!
  513. //! This function sets the card status error mask for response type R1, R1b,
  514. //! R5, R5b and R6 response. The parameter \e ulErrMask is the bit mask of card
  515. //! status errors to be enabled, if the corresponding bits in the 'card status'
  516. //! field of a respose are set then the host controller indicates a card error
  517. //! interrupt status. Only bits referenced as type E (error) in status field in
  518. //! the response can set a card status error.
  519. //!
  520. //! \return None
  521. //
  522. //*****************************************************************************
  523. void
  524. SDHostCardErrorMaskSet(unsigned long ulBase, unsigned long ulErrMask)
  525. {
  526. //
  527. // Set the card status error mask
  528. //
  529. HWREG(ulBase + MMCHS_O_CSRE) = ulErrMask;
  530. }
  531. //*****************************************************************************
  532. //
  533. //! Gets the card status error mask.
  534. //!
  535. //! \param ulBase is the base address of SDHost module
  536. //!
  537. //! This function gets the card status error mask for response type R1, R1b,
  538. //! R5, R5b and R6 response.
  539. //!
  540. //! \return Returns the current card status error.
  541. //
  542. //*****************************************************************************
  543. unsigned long
  544. SDHostCardErrorMaskGet(unsigned long ulBase)
  545. {
  546. //
  547. // Return the card status error mask
  548. //
  549. return(HWREG(ulBase + MMCHS_O_CSRE));
  550. }
  551. //*****************************************************************************
  552. //
  553. //! Sets the SD Card clock.
  554. //!
  555. //! \param ulBase is the base address of SDHost module
  556. //! \param ulSDHostClk is the rate of clock supplied to SDHost module
  557. //! \param ulCardClk is the required SD interface clock
  558. //!
  559. //! This function configures the SDHost interface to supply the specified clock
  560. //! to the connected card.
  561. //!
  562. //! \return None.
  563. //
  564. //*****************************************************************************
  565. void
  566. SDHostSetExpClk(unsigned long ulBase, unsigned long ulSDHostClk,
  567. unsigned long ulCardClk)
  568. {
  569. unsigned long ulDiv;
  570. //
  571. // Disable card clock
  572. //
  573. HWREG(ulBase + MMCHS_O_SYSCTL) &= ~0x4;
  574. //
  575. // Enable internal clock
  576. //
  577. HWREG(ulBase + MMCHS_O_SYSCTL) |= 0x1;
  578. ulDiv = ((ulSDHostClk/ulCardClk) & 0x3FF);
  579. //
  580. // Set clock divider,
  581. //
  582. HWREG(ulBase + MMCHS_O_SYSCTL) = ((HWREG(ulBase + MMCHS_O_SYSCTL) &
  583. ~0x0000FFC0)| (ulDiv) << 6);
  584. //
  585. // Wait for clock to stablize
  586. //
  587. while( !(HWREG(ulBase + MMCHS_O_SYSCTL) & 0x2) )
  588. {
  589. }
  590. //
  591. // Enable card clock
  592. //
  593. HWREG(ulBase + MMCHS_O_SYSCTL) |= 0x4;
  594. }
  595. //*****************************************************************************
  596. //
  597. //! Get the response for the last command.
  598. //!
  599. //! \param ulBase is the base address of SDHost module
  600. //! \param ulRespnse is 128-bit response.
  601. //!
  602. //! This function gets the response from the SD card for the last command
  603. //! send.
  604. //!
  605. //! \return None.
  606. //
  607. //*****************************************************************************
  608. void
  609. SDHostRespGet(unsigned long ulBase, unsigned long ulRespnse[4])
  610. {
  611. //
  612. // Read the responses.
  613. //
  614. ulRespnse[0] = HWREG(ulBase + MMCHS_O_RSP10);
  615. ulRespnse[1] = HWREG(ulBase + MMCHS_O_RSP32);
  616. ulRespnse[2] = HWREG(ulBase + MMCHS_O_RSP54);
  617. ulRespnse[3] = HWREG(ulBase + MMCHS_O_RSP76);
  618. }
  619. //*****************************************************************************
  620. //
  621. //! Set the block size for data transfer
  622. //!
  623. //! \param ulBase is the base address of SDHost module
  624. //! \param ulBlkSize is the transfer block size in bytes
  625. //!
  626. //! This function sets the block size the data transfer.
  627. //!
  628. //! The parameter \e ulBlkSize is size of each data block in bytes.
  629. //! This should be in range 0 - 2^10.
  630. //!
  631. //! \return None.
  632. //
  633. //*****************************************************************************
  634. void
  635. SDHostBlockSizeSet(unsigned long ulBase, unsigned short ulBlkSize)
  636. {
  637. //
  638. // Set the block size
  639. //
  640. HWREG(ulBase + MMCHS_O_BLK) = ((HWREG(ulBase + MMCHS_O_BLK) & 0x00000FFF)|
  641. (ulBlkSize & 0xFFF));
  642. }
  643. //*****************************************************************************
  644. //
  645. //! Set the block size and count for data transfer
  646. //!
  647. //! \param ulBase is the base address of SDHost module
  648. //! \param ulBlkCount is the number of blocks
  649. //!
  650. //! This function sets block count for the data transfer. This needs to be set
  651. //! for each block transfer. \sa SDHostBlockSizeSet()
  652. //!
  653. //! \return None.
  654. //
  655. //*****************************************************************************
  656. void
  657. SDHostBlockCountSet(unsigned long ulBase, unsigned short ulBlkCount)
  658. {
  659. unsigned long ulRegVal;
  660. //
  661. // Read the current value
  662. //
  663. ulRegVal = HWREG(ulBase + MMCHS_O_BLK);
  664. //
  665. // Set the number of blocks
  666. //
  667. HWREG(ulBase + MMCHS_O_BLK) = ((ulRegVal & 0x0000FFFF)|
  668. (ulBlkCount << 16));
  669. }
  670. //*****************************************************************************
  671. //
  672. // Close the Doxygen group.
  673. //! @}
  674. //
  675. //*****************************************************************************