nu_sdh.h 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  1. /**************************************************************************//**
  2. * @file sdh.h
  3. * @brief N9H30 SDH driver header file
  4. *
  5. * @note
  6. * SPDX-License-Identifier: Apache-2.0
  7. * Copyright (C) 2018 Nuvoton Technology Corp. All rights reserved.
  8. *****************************************************************************/
  9. #include <stdio.h>
  10. #ifndef __NU_SDH_H__
  11. #define __NU_SDH_H__
  12. #ifdef __cplusplus
  13. #define __I volatile /*!< Defines 'read only' permissions */
  14. #else
  15. #define __I volatile const /*!< Defines 'read only' permissions */
  16. #endif
  17. #define __O volatile /*!< Defines 'write only' permissions */
  18. #define __IO volatile /*!< Defines 'read / write' permissions */
  19. #define TIMER0 0
  20. /**
  21. @addtogroup REGISTER Control Register
  22. @{
  23. */
  24. /**
  25. @addtogroup SDH SD/SDIO Host Controller(SDH)
  26. Memory Mapped Structure for SDH Controller
  27. @{ */
  28. typedef struct
  29. {
  30. /**
  31. * @var SDH_T::FB
  32. * Offset: 0x00~0x7C Shared Buffer (FIFO)
  33. * ---------------------------------------------------------------------------------------------------
  34. * |Bits |Field |Descriptions
  35. * | :----: | :----: | :---- |
  36. * |[31:0] |BUFFER |Shared Buffer
  37. * | | |Buffer for DMA transfer
  38. * @var SDH_T::DMACTL
  39. * Offset: 0x400 DMA Control and Status Register
  40. * ---------------------------------------------------------------------------------------------------
  41. * |Bits |Field |Descriptions
  42. * | :----: | :----: | :---- |
  43. * |[0] |DMAEN |DMA Engine Enable Bit
  44. * | | |0 = DMA Disabled.
  45. * | | |1 = DMA Enabled.
  46. * | | |If this bit is cleared, DMA will ignore all requests from SD host and force bus master into IDLE state.
  47. * | | |Note: If target abort is occurred, DMAEN will be cleared.
  48. * |[1] |DMARST |Software Engine Reset
  49. * | | |0 = No effect.
  50. * | | |1 = Reset internal state machine and pointers
  51. * | | |The contents of control register will not be cleared
  52. * | | |This bit will auto be cleared after few clock cycles.
  53. * | | |Note: The software reset DMA related registers.
  54. * |[3] |SGEN |Scatter-gather Function Enable Bit
  55. * | | |0 = Scatter-gather function Disabled (DMA will treat the starting address in DMASAR as starting pointer of a single block memory).
  56. * | | |1 = Scatter-gather function Enabled (DMA will treat the starting address in DMASAR as a starting address of Physical Address Descriptor (PAD) table
  57. * | | |The format of these Pads' will be described later).
  58. * |[9] |DMABUSY |DMA Transfer Is in Progress
  59. * | | |This bit indicates if SD Host is granted and doing DMA transfer or not.
  60. * | | |0 = DMA transfer is not in progress.
  61. * | | |1 = DMA transfer is in progress.
  62. * @var SDH_T::DMASA
  63. * Offset: 0x408 DMA Transfer Starting Address Register
  64. * ---------------------------------------------------------------------------------------------------
  65. * |Bits |Field |Descriptions
  66. * | :----: | :----: | :---- |
  67. * |[0] |ORDER |Determined to the PAD Table Fetching Is in Order or Out of Order
  68. * | | |0 = PAD table is fetched in order.
  69. * | | |1 = PAD table is fetched out of order.
  70. * | | |Note: the bit0 is valid in scatter-gather mode when SGEN = 1.
  71. * |[31:1] |DMASA |DMA Transfer Starting Address
  72. * | | |This field pads 0 as least significant bit indicates a 32-bit starting address of system memory (SRAM) for DMA to retrieve or fill in data.
  73. * | | |If DMA is not in normal mode, this field will be interpreted as a starting address of Physical Address Descriptor (PAD) table.
  74. * | | |Note: Starting address of the SRAM must be word aligned, for example, 0x0000_0000, 0x0000_0004.
  75. * @var SDH_T::DMABCNT
  76. * Offset: 0x40C DMA Transfer Byte Count Register
  77. * ---------------------------------------------------------------------------------------------------
  78. * |Bits |Field |Descriptions
  79. * | :----: | :----: | :---- |
  80. * |[25:0] |BCNT |DMA Transfer Byte Count (Read Only)
  81. * | | |This field indicates the remained byte count of DMA transfer
  82. * | | |The value of this field is valid only when DMA is busy; otherwise, it is 0.
  83. * @var SDH_T::DMAINTEN
  84. * Offset: 0x410 DMA Interrupt Enable Control Register
  85. * ---------------------------------------------------------------------------------------------------
  86. * |Bits |Field |Descriptions
  87. * | :----: | :----: | :---- |
  88. * |[0] |ABORTIEN |DMA Read/Write Target Abort Interrupt Enable Bit
  89. * | | |0 = Target abort interrupt generation Disabled during DMA transfer.
  90. * | | |1 = Target abort interrupt generation Enabled during DMA transfer.
  91. * |[1] |WEOTIEN |Wrong EOT Encountered Interrupt Enable Bit
  92. * | | |0 = Interrupt generation Disabled when wrong EOT is encountered.
  93. * | | |1 = Interrupt generation Enabled when wrong EOT is encountered.
  94. * @var SDH_T::DMAINTSTS
  95. * Offset: 0x414 DMA Interrupt Status Register
  96. * ---------------------------------------------------------------------------------------------------
  97. * |Bits |Field |Descriptions
  98. * | :----: | :----: | :---- |
  99. * |[0] |ABORTIF |DMA Read/Write Target Abort Interrupt Flag
  100. * | | |0 = No bus ERROR response received.
  101. * | | |1 = Bus ERROR response received.
  102. * | | |Note1: This bit is read only, but can be cleared by writing '1' to it.
  103. * | | |Note2: When DMA's bus master received ERROR response, it means that target abort is happened
  104. * | | |DMA will stop transfer and respond this event and then go to IDLE state
  105. * | | |When target abort occurred or WEOTIF is set, software must reset DMA and SD host, and then transfer those data again.
  106. * |[1] |WEOTIF |Wrong EOT Encountered Interrupt Flag
  107. * | | |When DMA Scatter-Gather function is enabled, and EOT of the descriptor is encountered before DMA transfer finished (that means the total sector count of all PAD is less than the sector count of SD host), this bit will be set.
  108. * | | |0 = No EOT encountered before DMA transfer finished.
  109. * | | |1 = EOT encountered before DMA transfer finished.
  110. * | | |Note: This bit is read only, but can be cleared by writing '1' to it.
  111. * @var SDH_T::GCTL
  112. * Offset: 0x800 Global Control and Status Register
  113. * ---------------------------------------------------------------------------------------------------
  114. * |Bits |Field |Descriptions
  115. * | :----: | :----: | :---- |
  116. * |[0] |GCTLRST |Software Engine Reset
  117. * | | |0 = No effect.
  118. * | | |1 = Reset SD host
  119. * | | |The contents of control register will not be cleared
  120. * | | |This bit will auto cleared after reset complete.
  121. * |[1] |SDEN |Secure Digital Functionality Enable Bit
  122. * | | |0 = SD functionality disabled.
  123. * | | |1 = SD functionality enabled.
  124. * @var SDH_T::GINTEN
  125. * Offset: 0x804 Global Interrupt Control Register
  126. * ---------------------------------------------------------------------------------------------------
  127. * |Bits |Field |Descriptions
  128. * | :----: | :----: | :---- |
  129. * |[0] |DTAIEN |DMA READ/WRITE Target Abort Interrupt Enable Bit
  130. * | | |0 = DMA READ/WRITE target abort interrupt generation disabled.
  131. * | | |1 = DMA READ/WRITE target abort interrupt generation enabled.
  132. * @var SDH_T::GINTSTS
  133. * Offset: 0x808 Global Interrupt Status Register
  134. * ---------------------------------------------------------------------------------------------------
  135. * |Bits |Field |Descriptions
  136. * | :----: | :----: | :---- |
  137. * |[0] |DTAIF |DMA READ/WRITE Target Abort Interrupt Flag (Read Only)
  138. * | | |This bit indicates DMA received an ERROR response from internal AHB bus during DMA read/write operation
  139. * | | |When Target Abort is occurred, please reset all engine.
  140. * | | |0 = No bus ERROR response received.
  141. * | | |1 = Bus ERROR response received.
  142. * | | |Note: This bit is read only, but can be cleared by writing '1' to it.
  143. * @var SDH_T::CTL
  144. * Offset: 0x820 SD Control and Status Register
  145. * ---------------------------------------------------------------------------------------------------
  146. * |Bits |Field |Descriptions
  147. * | :----: | :----: | :---- |
  148. * |[0] |COEN |Command Output Enable Bit
  149. * | | |0 = No effect. (Please use DMARST (SDH_CTL [0]) to clear this bit.)
  150. * | | |1 = Enabled, SD host will output a command to SD card.
  151. * | | |Note: When operation is finished, this bit will be cleared automatically, so don't write 0 to this bit (the controller will be abnormal).
  152. * |[1] |RIEN |Response Input Enable Bit
  153. * | | |0 = No effect. (Please use DMARST (SDH_CTL [0]) to clear this bit.)
  154. * | | |1 = Enabled, SD host will wait to receive a response from SD card.
  155. * | | |Note: When operation is finished, this bit will be cleared automatically, so don't write 0 to this bit (the controller will be abnormal).
  156. * |[2] |DIEN |Data Input Enable Bit
  157. * | | |0 = No effect. (Please use DMARST (SDH_CTL [0]) to clear this bit.)
  158. * | | |1 = Enabled, SD host will wait to receive block data and the CRC16 value from SD card.
  159. * | | |Note: When operation is finished, this bit will be cleared automatically, so don't write 0 to this bit (the controller will be abnormal).
  160. * |[3] |DOEN |Data Output Enable Bit
  161. * | | |0 = No effect. (Please use DMARST (SDH_CTL [0]) to clear this bit.)
  162. * | | |1 = Enabled, SD host will transfer block data and the CRC16 value to SD card.
  163. * | | |Note: When operation is finished, this bit will be cleared automatically, so don't write 0 to this bit (the controller will be abnormal).
  164. * |[4] |R2EN |Response R2 Input Enable Bit
  165. * | | |0 = No effect. (Please use DMARST (SDH_CTL [0]) to clear this bit.)
  166. * | | |1 = Enabled, SD host will wait to receive a response R2 from SD card and store the response data into DMC's flash buffer (exclude CRC7).
  167. * | | |Note: When operation is finished, this bit will be cleared automatically, so don't write 0 to this bit (the controller will be abnormal).
  168. * |[5] |CLK74OEN |Initial 74 Clock Cycles Output Enable Bit
  169. * | | |0 = No effect. (Please use DMARST (SDH_CTL [0]) to clear this bit.)
  170. * | | |1 = Enabled, SD host will output 74 clock cycles to SD card.
  171. * | | |Note: When operation is finished, this bit will be cleared automatically, so don't write 0 to this bit (the controller will be abnormal).
  172. * |[6] |CLK8OEN |Generating 8 Clock Cycles Output Enable Bit
  173. * | | |0 = No effect. (Please use DMARST (SDH_CTL [0]) to clear this bit.)
  174. * | | |1 = Enabled, SD host will output 8 clock cycles.
  175. * | | |Note: When operation is finished, this bit will be cleared automatically, so don't write 0 to this bit (the controller will be abnormal).
  176. * |[7] |CLKKEEP |SD Clock Enable Control
  177. * | | |0 = SD host decided when to output clock and when to disable clock output automatically.
  178. * | | |1 = SD clock always keeps free running.
  179. * |[13:8] |CMDCODE |SD Command Code
  180. * | | |This register contains the SD command code (0x00 - 0x3F).
  181. * |[14] |CTLRST |Software Engine Reset
  182. * | | |0 = No effect.
  183. * | | |1 = Reset the internal state machine and counters
  184. * | | |The contents of control register will not be cleared (but RIEN, DIEN, DOEN and R2_EN will be cleared)
  185. * | | |This bit will be auto cleared after few clock cycles.
  186. * |[15] |DBW |SD Data Bus Width (for 1-bit / 4-bit Selection)
  187. * | | |0 = Data bus width is 1-bit.
  188. * | | |1 = Data bus width is 4-bit.
  189. * |[23:16] |BLKCNT |Block Counts to Be Transferred or Received
  190. * | | |This field contains the block counts for data-in and data-out transfer
  191. * | | |For READ_MULTIPLE_BLOCK and WRITE_MULTIPLE_BLOCK command, software can use this function to accelerate data transfer and improve performance
  192. * | | |Don't fill 0x0 to this field.
  193. * | | |Note: For READ_MULTIPLE_BLOCK and WRITE_MULTIPLE_BLOCK command, the actual total length is BLKCNT * (BLKLEN +1).
  194. * |[27:24] |SDNWR |NWR Parameter for Block Write Operation
  195. * | | |This value indicates the NWR parameter for data block write operation in SD clock counts
  196. * | | |The actual clock cycle will be SDNWR+1.
  197. * @var SDH_T::CMDARG
  198. * Offset: 0x824 SD Command Argument Register
  199. * ---------------------------------------------------------------------------------------------------
  200. * |Bits |Field |Descriptions
  201. * | :----: | :----: | :---- |
  202. * |[31:0] |ARGUMENT |SD Command Argument
  203. * | | |This register contains a 32-bit value specifies the argument of SD command from host controller to SD card
  204. * | | |Before trigger COEN (SDH_CTL [0]), software should fill argument in this field.
  205. * @var SDH_T::INTEN
  206. * Offset: 0x828 SD Interrupt Control Register
  207. * ---------------------------------------------------------------------------------------------------
  208. * |Bits |Field |Descriptions
  209. * | :----: | :----: | :---- |
  210. * |[0] |BLKDIEN |Block Transfer Done Interrupt Enable Bit
  211. * | | |0 = BLKDIF (SDH_INTEN[0]) trigger interrupt Disable.
  212. * | | |1 = BLKDIF (SDH_INTEN[0]) trigger interrupt Enabled.
  213. * |[1] |CRCIEN |CRC7, CRC16 and CRC Status Error Interrupt Enable Bit
  214. * | | |0 = CRCIF (SDH_INTEN[1]) trigger interrupt Disable.
  215. * | | |1 = CRCIF (SDH_INTEN[1]) trigger interrupt Enabled.
  216. * |[8] |CDIEN |SD Card Detection Interrupt Enable Bit
  217. * | | |Enable/Disable interrupts generation of SD controller when card is inserted or removed.
  218. * | | |0 = CDIF (SDH_INTEN[8]) trigger interrupt Disable.
  219. * | | |1 = CDIF (SDH_INTEN[8]) trigger interrupt Enabled.
  220. * |[12] |RTOIEN |Response Time-out Interrupt Enable Bit
  221. * | | |Enable/Disable interrupts generation of SD controller when receiving response or R2 time-out
  222. * | | |Time-out value is specified at TOUT register.
  223. * | | |0 = RTOIF (SDH_INTEN[12]) trigger interrupt Disabled.
  224. * | | |1 = RTOIF (SDH_INTEN[12]) trigger interrupt Enabled.
  225. * |[13] |DITOIEN |Data Input Time-out Interrupt Enable Bit
  226. * | | |Enable/Disable interrupts generation of SD controller when data input time-out
  227. * | | |Time-out value is specified at TOUT register.
  228. * | | |0 = DITOIF (SDH_INTEN[13]) trigger interrupt Disabled.
  229. * | | |1 = DITOIF (SDH_INTEN[13]) trigger interrupt Enabled.
  230. * |[14] |WKIEN |Wake-up Signal Generating Enable Bit
  231. * | | |Enable/Disable wake-up signal generating of SD host when current using SD card issues an interrupt (wake-up) via DAT [1] to host.
  232. * | | |0 = SD Card interrupt to wake-up chip Disabled.
  233. * | | |1 = SD Card interrupt to wake-up chip Enabled.
  234. * |[30] |CDSRC |SD Card Detect Source Selection
  235. * | | |0 = From SD card's DAT3 pin.
  236. * | | |Host need clock to got data on pin DAT3
  237. * | | |Please make sure CLKKEEP (SDH_CTL[7]) is 1 in order to generate free running clock for DAT3 pin.
  238. * | | |1 = From GPIO pin.
  239. * @var SDH_T::INTSTS
  240. * Offset: 0x82C SD Interrupt Status Register
  241. * ---------------------------------------------------------------------------------------------------
  242. * |Bits |Field |Descriptions
  243. * | :----: | :----: | :---- |
  244. * |[0] |BLKDIF |Block Transfer Done Interrupt Flag (Read Only)
  245. * | | |This bit indicates that SD host has finished all data-in or data-out block transfer
  246. * | | |If there is a CRC16 error or incorrect CRC status during multiple block data transfer, the transfer will be broken and this bit will also be set.
  247. * | | |0 = Not finished yet.
  248. * | | |1 = Done.
  249. * | | |Note: This bit is read only, but can be cleared by writing '1' to it.
  250. * |[1] |CRCIF |CRC7, CRC16 and CRC Status Error Interrupt Flag (Read Only)
  251. * | | |This bit indicates that SD host has occurred CRC error during response in, data-in or data-out (CRC status error) transfer
  252. * | | |When CRC error is occurred, software should reset SD engine
  253. * | | |Some response (ex
  254. * | | |R3) doesn't have CRC7 information with it; SD host will still calculate CRC7, get CRC error and set this flag
  255. * | | |In this condition, software should ignore CRC error and clears this bit manually.
  256. * | | |0 = No CRC error is occurred.
  257. * | | |1 = CRC error is occurred.
  258. * | | |Note: This bit is read only, but can be cleared by writing '1' to it.
  259. * |[2] |CRC7 |CRC7 Check Status (Read Only)
  260. * | | |SD host will check CRC7 correctness during each response in
  261. * | | |If that response does not contain CRC7 information (ex
  262. * | | |R3), then software should turn off CRCIEN (SDH_INTEN[1]) and ignore this bit.
  263. * | | |0 = Fault.
  264. * | | |1 = OK.
  265. * |[3] |CRC16 |CRC16 Check Status of Data-in Transfer (Read Only)
  266. * | | |SD host will check CRC16 correctness after data-in transfer.
  267. * | | |0 = Fault.
  268. * | | |1 = OK.
  269. * |[6:4] |CRCSTS |CRC Status Value of Data-out Transfer (Read Only)
  270. * | | |SD host will record CRC status of data-out transfer
  271. * | | |Software could use this value to identify what type of error is during data-out transfer.
  272. * | | |010 = Positive CRC status.
  273. * | | |101 = Negative CRC status.
  274. * | | |111 = SD card programming error occurs.
  275. * |[7] |DAT0STS |DAT0 Pin Status of Current Selected SD Port (Read Only)
  276. * | | |This bit is the DAT0 pin status of current selected SD port.
  277. * |[8] |CDIF |SD Card Detection Interrupt Flag (Read Only)
  278. * | | |This bit indicates that SD card is inserted or removed
  279. * | | |Only when CDIEN (SDH_INTEN[8]) is set to 1, this bit is active.
  280. * | | |0 = No card is inserted or removed.
  281. * | | |1 = There is a card inserted in or removed from SD.
  282. * | | |Note: This bit is read only, but can be cleared by writing '1' to it.
  283. * |[12] |RTOIF |Response Time-out Interrupt Flag (Read Only)
  284. * | | |This bit indicates that SD host counts to time-out value when receiving response or R2 (waiting start bit).
  285. * | | |0 = Not time-out.
  286. * | | |1 = Response time-out.
  287. * | | |Note: This bit is read only, but can be cleared by writing '1' to it.
  288. * |[13] |DITOIF |Data Input Time-out Interrupt Flag (Read Only)
  289. * | | |This bit indicates that SD host counts to time-out value when receiving data (waiting start bit).
  290. * | | |0 = Not time-out.
  291. * | | |1 = Data input time-out.
  292. * | | |Note: This bit is read only, but can be cleared by writing '1' to it.
  293. * |[16] |CDSTS |Card Detect Status of SD (Read Only)
  294. * | | |This bit indicates the card detect pin status of SD, and is used for card detection
  295. * | | |When there is a card inserted in or removed from SD, software should check this bit to confirm if there is really a card insertion or removal.
  296. * | | |If CDSRC (SDH_INTEN[30]) = 0, to select DAT3 for card detection:.
  297. * | | |0 = Card removed.
  298. * | | |1 = Card inserted.
  299. * | | |If CDSRC (SDH_INTEN[30]) = 1, to select GPIO for card detection:.
  300. * | | |0 = Card inserted.
  301. * | | |1 = Card removed.
  302. * |[18] |DAT1STS |DAT1 Pin Status of SD Port (Read Only)
  303. * | | |This bit indicates the DAT1 pin status of SD port.
  304. * @var SDH_T::RESP0
  305. * Offset: 0x830 SD Receiving Response Token Register 0
  306. * ---------------------------------------------------------------------------------------------------
  307. * |Bits |Field |Descriptions
  308. * | :----: | :----: | :---- |
  309. * |[31:0] |RESPTK0 |SD Receiving Response Token 0
  310. * | | |SD host controller will receive a response token for getting a reply from SD card when RIEN (SDH_CTL[1]) is set
  311. * | | |This field contains response bit 47-16 of the response token.
  312. * @var SDH_T::RESP1
  313. * Offset: 0x834 SD Receiving Response Token Register 1
  314. * ---------------------------------------------------------------------------------------------------
  315. * |Bits |Field |Descriptions
  316. * | :----: | :----: | :---- |
  317. * |[7:0] |RESPTK1 |SD Receiving Response Token 1
  318. * | | |SD host controller will receive a response token for getting a reply from SD card when RIEN (SDH_CTL[1]) is set
  319. * | | |This register contains the bit 15-8 of the response token.
  320. * @var SDH_T::BLEN
  321. * Offset: 0x838 SD Block Length Register
  322. * ---------------------------------------------------------------------------------------------------
  323. * |Bits |Field |Descriptions
  324. * | :----: | :----: | :---- |
  325. * |[10:0] |BLKLEN |SD BLOCK LENGTH in Byte Unit
  326. * | | |An 11-bit value specifies the SD transfer byte count of a block
  327. * | | |The actual byte count is equal to BLKLEN+1.
  328. * | | |Note: The default SD block length is 512 bytes
  329. * @var SDH_T::TOUT
  330. * Offset: 0x83C SD Response/Data-in Time-out Register
  331. * ---------------------------------------------------------------------------------------------------
  332. * |Bits |Field |Descriptions
  333. * | :----: | :----: | :---- |
  334. * |[23:0] |TOUT |SD Response/Data-in Time-out Value
  335. * | | |A 24-bit value specifies the time-out counts of response and data input
  336. * | | |SD host controller will wait start bit of response or data-in until this value reached
  337. * | | |The time period depends on SD engine clock frequency
  338. * | | |Do not write a small number into this field, or you may never get response or data due to time-out.
  339. * | | |Note: Filling 0x0 into this field will disable hardware time-out function.
  340. */
  341. __IO uint32_t FB[32]; /*!< Shared Buffer (FIFO) */
  342. /// @cond HIDDEN_SYMBOLS
  343. __I uint32_t RESERVE0[224];
  344. /// @endcond //HIDDEN_SYMBOLS
  345. __IO uint32_t DMACTL; /*!< [0x0400] DMA Control and Status Register */
  346. /// @cond HIDDEN_SYMBOLS
  347. __I uint32_t RESERVE1[1];
  348. /// @endcond //HIDDEN_SYMBOLS
  349. __IO uint32_t DMASA; /*!< [0x0408] DMA Transfer Starting Address Register */
  350. __I uint32_t DMABCNT; /*!< [0x040c] DMA Transfer Byte Count Register */
  351. __IO uint32_t DMAINTEN; /*!< [0x0410] DMA Interrupt Enable Control Register */
  352. __IO uint32_t DMAINTSTS; /*!< [0x0414] DMA Interrupt Status Register */
  353. /// @cond HIDDEN_SYMBOLS
  354. __I uint32_t RESERVE2[250];
  355. /// @endcond //HIDDEN_SYMBOLS
  356. __IO uint32_t GCTL; /*!< [0x0800] Global Control and Status Register */
  357. __IO uint32_t GINTEN; /*!< [0x0804] Global Interrupt Control Register */
  358. __I uint32_t GINTSTS; /*!< [0x0808] Global Interrupt Status Register */
  359. /// @cond HIDDEN_SYMBOLS
  360. __I uint32_t RESERVE3[5];
  361. /// @endcond //HIDDEN_SYMBOLS
  362. __IO uint32_t CTL; /*!< [0x0820] SD Control and Status Register */
  363. __IO uint32_t CMDARG; /*!< [0x0824] SD Command Argument Register */
  364. __IO uint32_t INTEN; /*!< [0x0828] SD Interrupt Control Register */
  365. __IO uint32_t INTSTS; /*!< [0x082c] SD Interrupt Status Register */
  366. __I uint32_t RESP0; /*!< [0x0830] SD Receiving Response Token Register 0 */
  367. __I uint32_t RESP1; /*!< [0x0834] SD Receiving Response Token Register 1 */
  368. __IO uint32_t BLEN; /*!< [0x0838] SD Block Length Register */
  369. __IO uint32_t TOUT; /*!< [0x083c] SD Response/Data-in Time-out Register */
  370. __IO uint32_t ECTL; /*!< [0x0840] SD Host Extend Control Register */
  371. } SDH_T;
  372. /**
  373. @addtogroup SDH_CONST SDH Bit Field Definition
  374. Constant Definitions for SDH Controller
  375. @{ */
  376. #define SDH_DMACTL_DMAEN_Pos (0) /*!< SDH_T::DMACTL: DMAEN Position */
  377. #define SDH_DMACTL_DMAEN_Msk (0x1ul << SDH_DMACTL_DMAEN_Pos) /*!< SDH_T::DMACTL: DMAEN Mask */
  378. #define SDH_DMACTL_DMARST_Pos (1) /*!< SDH_T::DMACTL: DMARST Position */
  379. #define SDH_DMACTL_DMARST_Msk (0x1ul << SDH_DMACTL_DMARST_Pos) /*!< SDH_T::DMACTL: DMARST Mask */
  380. #define SDH_DMACTL_SGEN_Pos (3) /*!< SDH_T::DMACTL: SGEN Position */
  381. #define SDH_DMACTL_SGEN_Msk (0x1ul << SDH_DMACTL_SGEN_Pos) /*!< SDH_T::DMACTL: SGEN Mask */
  382. #define SDH_DMACTL_DMABUSY_Pos (9) /*!< SDH_T::DMACTL: DMABUSY Position */
  383. #define SDH_DMACTL_DMABUSY_Msk (0x1ul << SDH_DMACTL_DMABUSY_Pos) /*!< SDH_T::DMACTL: DMABUSY Mask */
  384. #define SDH_DMASA_ORDER_Pos (0) /*!< SDH_T::DMASA: ORDER Position */
  385. #define SDH_DMASA_ORDER_Msk (0x1ul << SDH_DMASA_ORDER_Pos) /*!< SDH_T::DMASA: ORDER Mask */
  386. #define SDH_DMASA_DMASA_Pos (1) /*!< SDH_T::DMASA: DMASA Position */
  387. #define SDH_DMASA_DMASA_Msk (0x7ffffffful << SDH_DMASA_DMASA_Pos) /*!< SDH_T::DMASA: DMASA Mask */
  388. #define SDH_DMABCNT_BCNT_Pos (0) /*!< SDH_T::DMABCNT: BCNT Position */
  389. #define SDH_DMABCNT_BCNT_Msk (0x3fffffful << SDH_DMABCNT_BCNT_Pos) /*!< SDH_T::DMABCNT: BCNT Mask */
  390. #define SDH_DMAINTEN_ABORTIEN_Pos (0) /*!< SDH_T::DMAINTEN: ABORTIEN Position */
  391. #define SDH_DMAINTEN_ABORTIEN_Msk (0x1ul << SDH_DMAINTEN_ABORTIEN_Pos) /*!< SDH_T::DMAINTEN: ABORTIEN Mask */
  392. #define SDH_DMAINTEN_WEOTIEN_Pos (1) /*!< SDH_T::DMAINTEN: WEOTIEN Position */
  393. #define SDH_DMAINTEN_WEOTIEN_Msk (0x1ul << SDH_DMAINTEN_WEOTIEN_Pos) /*!< SDH_T::DMAINTEN: WEOTIEN Mask */
  394. #define SDH_DMAINTSTS_ABORTIF_Pos (0) /*!< SDH_T::DMAINTSTS: ABORTIF Position */
  395. #define SDH_DMAINTSTS_ABORTIF_Msk (0x1ul << SDH_DMAINTSTS_ABORTIF_Pos) /*!< SDH_T::DMAINTSTS: ABORTIF Mask */
  396. #define SDH_DMAINTSTS_WEOTIF_Pos (1) /*!< SDH_T::DMAINTSTS: WEOTIF Position */
  397. #define SDH_DMAINTSTS_WEOTIF_Msk (0x1ul << SDH_DMAINTSTS_WEOTIF_Pos) /*!< SDH_T::DMAINTSTS: WEOTIF Mask */
  398. #define SDH_GCTL_GCTLRST_Pos (0) /*!< SDH_T::GCTL: GCTLRST Position */
  399. #define SDH_GCTL_GCTLRST_Msk (0x1ul << SDH_GCTL_GCTLRST_Pos) /*!< SDH_T::GCTL: GCTLRST Mask */
  400. #define SDH_GCTL_SDEN_Pos (1) /*!< SDH_T::GCTL: SDEN Position */
  401. #define SDH_GCTL_SDEN_Msk (0x1ul << SDH_GCTL_SDEN_Pos) /*!< SDH_T::GCTL: SDEN Mask */
  402. #define SDH_GINTEN_DTAIEN_Pos (0) /*!< SDH_T::GINTEN: DTAIEN Position */
  403. #define SDH_GINTEN_DTAIEN_Msk (0x1ul << SDH_GINTEN_DTAIEN_Pos) /*!< SDH_T::GINTEN: DTAIEN Mask */
  404. #define SDH_GINTSTS_DTAIF_Pos (0) /*!< SDH_T::GINTSTS: DTAIF Position */
  405. #define SDH_GINTSTS_DTAIF_Msk (0x1ul << SDH_GINTSTS_DTAIF_Pos) /*!< SDH_T::GINTSTS: DTAIF Mask */
  406. #define SDH_CTL_COEN_Pos (0) /*!< SDH_T::CTL: COEN Position */
  407. #define SDH_CTL_COEN_Msk (0x1ul << SDH_CTL_COEN_Pos) /*!< SDH_T::CTL: COEN Mask */
  408. #define SDH_CTL_RIEN_Pos (1) /*!< SDH_T::CTL: RIEN Position */
  409. #define SDH_CTL_RIEN_Msk (0x1ul << SDH_CTL_RIEN_Pos) /*!< SDH_T::CTL: RIEN Mask */
  410. #define SDH_CTL_DIEN_Pos (2) /*!< SDH_T::CTL: DIEN Position */
  411. #define SDH_CTL_DIEN_Msk (0x1ul << SDH_CTL_DIEN_Pos) /*!< SDH_T::CTL: DIEN Mask */
  412. #define SDH_CTL_DOEN_Pos (3) /*!< SDH_T::CTL: DOEN Position */
  413. #define SDH_CTL_DOEN_Msk (0x1ul << SDH_CTL_DOEN_Pos) /*!< SDH_T::CTL: DOEN Mask */
  414. #define SDH_CTL_R2EN_Pos (4) /*!< SDH_T::CTL: R2EN Position */
  415. #define SDH_CTL_R2EN_Msk (0x1ul << SDH_CTL_R2EN_Pos) /*!< SDH_T::CTL: R2EN Mask */
  416. #define SDH_CTL_CLK74OEN_Pos (5) /*!< SDH_T::CTL: CLK74OEN Position */
  417. #define SDH_CTL_CLK74OEN_Msk (0x1ul << SDH_CTL_CLK74OEN_Pos) /*!< SDH_T::CTL: CLK74OEN Mask */
  418. #define SDH_CTL_CLK8OEN_Pos (6) /*!< SDH_T::CTL: CLK8OEN Position */
  419. #define SDH_CTL_CLK8OEN_Msk (0x1ul << SDH_CTL_CLK8OEN_Pos) /*!< SDH_T::CTL: CLK8OEN Mask */
  420. #define SDH_CTL_CLKKEEP0_Pos (7) /*!< SDH_T::CTL: CLKKEEP Position */
  421. #define SDH_CTL_CLKKEEP0_Msk (0x1ul << SDH_CTL_CLKKEEP0_Pos) /*!< SDH_T::CTL: CLKKEEP Mask */
  422. #define SDH_CTL_CMDCODE_Pos (8) /*!< SDH_T::CTL: CMDCODE Position */
  423. #define SDH_CTL_CMDCODE_Msk (0x3ful << SDH_CTL_CMDCODE_Pos) /*!< SDH_T::CTL: CMDCODE Mask */
  424. #define SDH_CTL_CTLRST_Pos (14) /*!< SDH_T::CTL: CTLRST Position */
  425. #define SDH_CTL_CTLRST_Msk (0x1ul << SDH_CTL_CTLRST_Pos) /*!< SDH_T::CTL: CTLRST Mask */
  426. #define SDH_CTL_DBW_Pos (15) /*!< SDH_T::CTL: DBW Position */
  427. #define SDH_CTL_DBW_Msk (0x1ul << SDH_CTL_DBW_Pos) /*!< SDH_T::CTL: DBW Mask */
  428. #define SDH_CTL_BLKCNT_Pos (16) /*!< SDH_T::CTL: BLKCNT Position */
  429. #define SDH_CTL_BLKCNT_Msk (0xfful << SDH_CTL_BLKCNT_Pos) /*!< SDH_T::CTL: BLKCNT Mask */
  430. #define SDH_CTL_SDNWR_Pos (24) /*!< SDH_T::CTL: SDNWR Position */
  431. #define SDH_CTL_SDNWR_Msk (0xful << SDH_CTL_SDNWR_Pos) /*!< SDH_T::CTL: SDNWR Mask */
  432. #define SDH_CTL_SDPORT_Pos (29) /*!< SDH CTL: SDPORT Position */
  433. #define SDH_CTL_SDPORT_Msk (0x3ul << SDH_CTL_SDPORT_Pos) /*!< SDH CTL: SDPORT Mask */
  434. #define SDH_CTL_CLKKEEP1_Pos (31) /*!< SDH CTL: CLKKEEP1 Position */
  435. #define SDH_CTL_CLKKEEP1_Msk (0x1ul << SDH_CTL_CLKKEEP1_Pos) /*!< SDH CTL: CLKKEEP1 Mask */
  436. #define SDH_CMDARG_ARGUMENT_Pos (0) /*!< SDH_T::CMDARG: ARGUMENT Position */
  437. #define SDH_CMDARG_ARGUMENT_Msk (0xfffffffful << SDH_CMDARG_ARGUMENT_Pos) /*!< SDH_T::CMDARG: ARGUMENT Mask */
  438. #define SDH_INTEN_BLKDIEN_Pos (0) /*!< SDH_T::INTEN: BLKDIEN Position */
  439. #define SDH_INTEN_BLKDIEN_Msk (0x1ul << SDH_INTEN_BLKDIEN_Pos) /*!< SDH_T::INTEN: BLKDIEN Mask */
  440. #define SDH_INTEN_CRCIEN_Pos (1) /*!< SDH_T::INTEN: CRCIEN Position */
  441. #define SDH_INTEN_CRCIEN_Msk (0x1ul << SDH_INTEN_CRCIEN_Pos) /*!< SDH_T::INTEN: CRCIEN Mask */
  442. #define SDH_INTEN_CDIEN_Pos (8) /*!< SDH_T::INTEN: CDIEN Position */
  443. #define SDH_INTEN_CDIEN_Msk (0x1ul << SDH_INTEN_CDIEN_Pos) /*!< SDH_T::INTEN: CDIEN Mask */
  444. #define SDH_INTEN_CDIEN1_Pos (9) /*!< SDH INTEN: CDIEN1 Position */
  445. #define SDH_INTEN_CDIEN1_Msk (0x1ul << SDH_INTEN_CDIEN1_Pos) /*!< SDH INTEN: CDIEN1 Mask */
  446. #define SDH_INTEN_SDHOST0IEN_Pos (10) /*!< SDH INTSTS: SDHOST0IEN Position */
  447. #define SDH_INTEN_SDHOST0IEN_Msk (0x1ul << SDH_INTEN_SDHOST0IEN_Pos) /*!< SDH INTSTS: SDHOST0IEN Mask */
  448. #define SDH_INTEN_SDHOST1IEN_Pos (11) /*!< SDH INTSTS: SDHOST1IEN Position */
  449. #define SDH_INTEN_SDHOST1IEN_Msk (0x1ul << SDH_INTEN_SDHOST1IEN_Pos) /*!< SDH INTSTS: SDHOST1IEN Mask */
  450. #define SDH_INTEN_RTOIEN_Pos (12) /*!< SDH INTEN: RTOIEN Position */
  451. #define SDH_INTEN_RTOIEN_Msk (0x1ul << SDH_INTEN_RTOIEN_Pos) /*!< SDH INTEN: RTOIEN Mask */
  452. #define SDH_INTEN_DITOIEN_Pos (13) /*!< SDH_T::INTEN: DITOIEN Position */
  453. #define SDH_INTEN_DITOIEN_Msk (0x1ul << SDH_INTEN_DITOIEN_Pos) /*!< SDH_T::INTEN: DITOIEN Mask */
  454. #define SDH_INTEN_WKIEN_Pos (14) /*!< SDH_T::INTEN: WKIEN Position */
  455. #define SDH_INTEN_WKIEN_Msk (0x1ul << SDH_INTEN_WKIEN_Pos) /*!< SDH_T::INTEN: WKIEN Mask */
  456. #define SDH_INTEN_CDSRC_Pos (30) /*!< SDH_T::INTEN: CDSRC Position */
  457. #define SDH_INTEN_CDSRC_Msk (0x1ul << SDH_INTEN_CDSRC_Pos) /*!< SDH_T::INTEN: CDSRC Mask */
  458. #define SDH_INTEN_CDSRC1_Pos (31) /*!< SDH INTEN: CDSRC1 Position */
  459. #define SDH_INTEN_CDSRC1_Msk (0x1ul << SDH_INTEN_CDSRC1_Pos) /*!< SDH INTEN: CDSRC1 Mask */
  460. #define SDH_INTSTS_BLKDIF_Pos (0) /*!< SDH_T::INTSTS: BLKDIF Position */
  461. #define SDH_INTSTS_BLKDIF_Msk (0x1ul << SDH_INTSTS_BLKDIF_Pos) /*!< SDH_T::INTSTS: BLKDIF Mask */
  462. #define SDH_INTSTS_CRCIF_Pos (1) /*!< SDH_T::INTSTS: CRCIF Position */
  463. #define SDH_INTSTS_CRCIF_Msk (0x1ul << SDH_INTSTS_CRCIF_Pos) /*!< SDH_T::INTSTS: CRCIF Mask */
  464. #define SDH_INTSTS_CRC7_Pos (2) /*!< SDH_T::INTSTS: CRC7 Position */
  465. #define SDH_INTSTS_CRC7_Msk (0x1ul << SDH_INTSTS_CRC7_Pos) /*!< SDH_T::INTSTS: CRC7 Mask */
  466. #define SDH_INTSTS_CRC16_Pos (3) /*!< SDH_T::INTSTS: CRC16 Position */
  467. #define SDH_INTSTS_CRC16_Msk (0x1ul << SDH_INTSTS_CRC16_Pos) /*!< SDH_T::INTSTS: CRC16 Mask */
  468. #define SDH_INTSTS_CRCSTS_Pos (4) /*!< SDH_T::INTSTS: CRCSTS Position */
  469. #define SDH_INTSTS_CRCSTS_Msk (0x7ul << SDH_INTSTS_CRCSTS_Pos) /*!< SDH_T::INTSTS: CRCSTS Mask */
  470. #define SDH_INTSTS_DAT0STS_Pos (7) /*!< SDH_T::INTSTS: DAT0STS Position */
  471. #define SDH_INTSTS_DAT0STS_Msk (0x1ul << SDH_INTSTS_DAT0STS_Pos) /*!< SDH_T::INTSTS: DAT0STS Mask */
  472. #define SDH_INTSTS_CDIF_Pos (8) /*!< SDH_T::INTSTS: CDIF Position */
  473. #define SDH_INTSTS_CDIF_Msk (0x1ul << SDH_INTSTS_CDIF_Pos) /*!< SDH_T::INTSTS: CDIF Mask */
  474. #define SDH_INTSTS_CDIF1_Pos (9) /*!< SDH INTSTS: CDIF1 Position */
  475. #define SDH_INTSTS_CDIF1_Msk (0x1ul << SDH_INTSTS_CDIF1_Pos) /*!< SDH INTSTS: CDIF1 Mask */
  476. #define SDH_INTSTS_SDHOST0IF_Pos (10) /*!< SDH INTSTS: SDHOST0IF Position */
  477. #define SDH_INTSTS_SDHOST0IF_Msk (0x1ul << SDH_INTSTS_SDHOST0IF_Pos) /*!< SDH INTSTS: SDHOST0IF Mask */
  478. #define SDH_INTSTS_SDHOST1IF_Pos (11) /*!< SDH INTSTS: SDHOST1IF Position */
  479. #define SDH_INTSTS_SDHOST1IF_Msk (0x1ul << SDH_INTSTS_SDHOST1IF_Pos) /*!< SDH INTSTS: SDHOST1IF Mask */
  480. #define SDH_INTSTS_RTOIF_Pos (12) /*!< SDH_T::INTSTS: RTOIF Position */
  481. #define SDH_INTSTS_RTOIF_Msk (0x1ul << SDH_INTSTS_RTOIF_Pos) /*!< SDH_T::INTSTS: RTOIF Mask */
  482. #define SDH_INTSTS_DITOIF_Pos (13) /*!< SDH_T::INTSTS: DITOIF Position */
  483. #define SDH_INTSTS_DITOIF_Msk (0x1ul << SDH_INTSTS_DITOIF_Pos) /*!< SDH_T::INTSTS: DITOIF Mask */
  484. #define SDH_INTSTS_CDSTS_Pos (16) /*!< SDH_T::INTSTS: CDSTS Position */
  485. #define SDH_INTSTS_CDSTS_Msk (0x1ul << SDH_INTSTS_CDSTS_Pos) /*!< SDH_T::INTSTS: CDSTS Mask */
  486. #define SDH_INTSTS_CDSTS1_Pos (17) /*!< SDH INTSTS: CDSTS1 Position */
  487. #define SDH_INTSTS_CDSTS1_Msk (0x1ul << SDH_INTSTS_CDSTS1_Pos) /*!< SDH INTSTS: CDSTS1 Mask */
  488. #define SDH_INTSTS_DAT1STS_Pos (18) /*!< SDH_T::INTSTS: DAT1STS Position */
  489. #define SDH_INTSTS_DAT1STS_Msk (0x1ul << SDH_INTSTS_DAT1STS_Pos) /*!< SDH_T::INTSTS: DAT1STS Mask */
  490. #define SDH_RESP0_RESPTK0_Pos (0) /*!< SDH_T::RESP0: RESPTK0 Position */
  491. #define SDH_RESP0_RESPTK0_Msk (0xfffffffful << SDH_RESP0_RESPTK0_Pos) /*!< SDH_T::RESP0: RESPTK0 Mask */
  492. #define SDH_RESP1_RESPTK1_Pos (0) /*!< SDH_T::RESP1: RESPTK1 Position */
  493. #define SDH_RESP1_RESPTK1_Msk (0xfful << SDH_RESP1_RESPTK1_Pos) /*!< SDH_T::RESP1: RESPTK1 Mask */
  494. #define SDH_BLEN_BLKLEN_Pos (0) /*!< SDH_T::BLEN: BLKLEN Position */
  495. #define SDH_BLEN_BLKLEN_Msk (0x7fful << SDH_BLEN_BLKLEN_Pos) /*!< SDH_T::BLEN: BLKLEN Mask */
  496. #define SDH_TOUT_TOUT_Pos (0) /*!< SDH_T::TOUT: TOUT Position */
  497. #define SDH_TOUT_TOUT_Msk (0xfffffful << SDH_TOUT_TOUT_Pos) /*!< SDH_T::TOUT: TOUT Mask */
  498. #define SDH_ECTL_POWEROFF0_Pos (0) /*!< SDH_T::ECTL: POWEROFF0 Position */
  499. #define SDH_ECTL_POWEROFF0_Msk (0x1ul << SDH_ECTL_POWEROFF0_Pos) /*!< SDH_T::ECTL: POWEROFF0 Mask */
  500. #define SDH_ECTL_POWEROFF1_Pos (1) /*!< SDH_T::ECTL: POWEROFF1 Position */
  501. #define SDH_ECTL_POWEROFF1_Msk (0x1ul << SDH_ECTL_POWEROFF1_Pos) /*!< SDH_T::ECTL: POWEROFF1 Mask */
  502. /**@}*/ /* SDH_CONST */
  503. /**@}*/ /* end of SDH register group */
  504. /**@}*/ /* end of REGISTER group */
  505. #define SDH0 ((SDH_T *) FMI_BA)
  506. #define SDH1 ((SDH_T *) SDH_BA)
  507. /** @addtogroup Standard_Driver Standard Driver
  508. @{
  509. */
  510. /** @addtogroup SDH_Driver SDH Driver
  511. @{
  512. */
  513. /** @addtogroup SDH_EXPORTED_CONSTANTS SDH Exported Constants
  514. @{
  515. */
  516. #define SDH_ERR_ID 0xFFFF0100ul /*!< SDH error ID \hideinitializer */
  517. #define SDH_TIMEOUT (SDH_ERR_ID|0x01ul) /*!< Timeout \hideinitializer */
  518. #define SDH_NO_MEMORY (SDH_ERR_ID|0x02ul) /*!< OOM \hideinitializer */
  519. /*--- define type of SD card or MMC */
  520. #define SDH_TYPE_UNKNOWN 0ul /*!< Unknown card type \hideinitializer */
  521. #define SDH_TYPE_SD_HIGH 1ul /*!< SDHC card \hideinitializer */
  522. #define SDH_TYPE_SD_LOW 2ul /*!< SD card \hideinitializer */
  523. #define SDH_TYPE_MMC 3ul /*!< MMC card \hideinitializer */
  524. #define SDH_TYPE_EMMC 4ul /*!< eMMC card \hideinitializer */
  525. /* SD error */
  526. #define SDH_NO_SD_CARD (SDH_ERR_ID|0x10ul) /*!< Card removed \hideinitializer */
  527. #define SDH_ERR_DEVICE (SDH_ERR_ID|0x11ul) /*!< Device error \hideinitializer */
  528. #define SDH_INIT_TIMEOUT (SDH_ERR_ID|0x12ul) /*!< Card init timeout \hideinitializer */
  529. #define SDH_SELECT_ERROR (SDH_ERR_ID|0x13ul) /*!< Card select error \hideinitializer */
  530. #define SDH_WRITE_PROTECT (SDH_ERR_ID|0x14ul) /*!< Card write protect \hideinitializer */
  531. #define SDH_INIT_ERROR (SDH_ERR_ID|0x15ul) /*!< Card init error \hideinitializer */
  532. #define SDH_CRC7_ERROR (SDH_ERR_ID|0x16ul) /*!< CRC 7 error \hideinitializer */
  533. #define SDH_CRC16_ERROR (SDH_ERR_ID|0x17ul) /*!< CRC 16 error \hideinitializer */
  534. #define SDH_CRC_ERROR (SDH_ERR_ID|0x18ul) /*!< CRC error \hideinitializer */
  535. #define SDH_CMD8_ERROR (SDH_ERR_ID|0x19ul) /*!< Command 8 error \hideinitializer */
  536. #define MMC_FREQ 20000ul /*!< output 20MHz to MMC \hideinitializer */
  537. #define SD_FREQ 25000ul /*!< output 25MHz to SD \hideinitializer */
  538. #define SDHC_FREQ 50000ul /*!< output 50MHz to SDH \hideinitializer */
  539. #define SD_PORT0 (1 << 0) /*!< Card select SD0 \hideinitializer */
  540. #define SD_PORT1 (1 << 2) /*!< Card select SD1 \hideinitializer */
  541. #define CardDetect_From_GPIO (1ul << 8) /*!< Card detection pin is GPIO \hideinitializer */
  542. #define CardDetect_From_DAT3 (1ul << 9) /*!< Card detection pin is DAT3 \hideinitializer */
  543. /*@}*/ /* end of group N9H30_SDH_EXPORTED_CONSTANTS */
  544. /** @addtogroup N9H30_SDH_EXPORTED_TYPEDEF SDH Exported Type Defines
  545. @{
  546. */
  547. /** \brief Structure type of inserted Card information.
  548. */
  549. typedef struct SDH_info_t
  550. {
  551. unsigned char IsCardInsert; /*!< Card insert state */
  552. unsigned char R3Flag;
  553. unsigned char R7Flag;
  554. unsigned char volatile DataReadyFlag;
  555. unsigned int CardType; /*!< SDHC, SD, or MMC */
  556. unsigned int RCA; /*!< Relative card address */
  557. unsigned int totalSectorN; /*!< Total sector number */
  558. unsigned int diskSize; /*!< Disk size in K bytes */
  559. int sectorSize; /*!< Sector size in bytes */
  560. unsigned char *dmabuf;
  561. } SDH_INFO_T; /*!< Structure holds SD card info */
  562. /*@}*/ /* end of group N9H30_SDH_EXPORTED_TYPEDEF */
  563. /// @cond HIDDEN_SYMBOLS
  564. /// @endcond HIDDEN_SYMBOLS
  565. /** @addtogroup N9H30_SDH_EXPORTED_FUNCTIONS SDH Exported Functions
  566. @{
  567. */
  568. /**
  569. * @brief Enable specified interrupt.
  570. *
  571. * @param[in] u32IntMask Interrupt type mask:
  572. * \ref SDH_INTEN_BLKDIEN_Msk / \ref SDH_INTEN_CRCIEN_Msk / \ref SDH_INTEN_CDIEN0_Msk / \ref SDH_INTEN_CDIEN1_Msk /
  573. * \ref SDH_INTEN_CDSRC0_Msk / \ref SDH_INTEN_CDSRC1_Msk / \ref SDH_INTEN_RTOIEN_Msk / \ref SDH_INTEN_DITOIEN_Msk /
  574. * \ref SDH_INTEN_WKIEN_Msk
  575. *
  576. * @return None.
  577. * \hideinitializer
  578. */
  579. #define SDH_ENABLE_INT(sdh, u32IntMask) ((sdh)->INTEN |= (u32IntMask))
  580. /**
  581. * @brief Disable specified interrupt.
  582. *
  583. * @param[in] sdh Select SDH0 or SDH1.
  584. * @param[in] u32IntMask Interrupt type mask:
  585. * \ref SDH_INTEN_BLKDIEN_Msk / \ref SDH_INTEN_CRCIEN_Msk / \ref SDH_INTEN_CDIEN0_Msk / \ref SDH_INTEN_CDIEN1_Msk /
  586. * \ref SDH_INTEN_SDHOST0IEN_Msk / \ref SDH_INTEN_SDHOST1IEN_Msk / \ref SDH_INTEN_RTOIEN_Msk / \ref SDH_INTEN_DITOIEN_Msk /
  587. * \ref SDH_INTEN_WKIEN_Msk / \ref SDH_INTEN_CDSRC0_Msk / \ref SDH_INTEN_CDSRC1_Msk
  588. *
  589. * @return None.
  590. * \hideinitializer
  591. */
  592. #define SDH_DISABLE_INT(sdh, u32IntMask) ((sdh)->INTEN &= ~(u32IntMask))
  593. /**
  594. * @brief Get specified interrupt flag/status.
  595. *
  596. * @param[in] sdh Select SDH0 or SDH1.
  597. * @param[in] u32IntMask Interrupt type mask:
  598. * \ref SDH_INTSTS_BLKDIF_Msk / \ref SDH_INTSTS_CRCIF_Msk / \ref SDH_INTSTS_CRC7_Msk /
  599. * \ref SDH_INTSTS_CRC16_Msk / \ref SDH_INTSTS_CRCSTS_Msk / \ref SDH_INTSTS_DAT0STS_Msk / \ref SDH_INTSTS_CDIF0_Msk /
  600. * \ref SDH_INTSTS_CDIF1_Msk / \ref SDH_INTSTS_SDHOST0IF_Msk / \ref SDH_INTSTS_SDHOST1IF_Msk / \ref SDH_INTSTS_RTOIF_Msk /
  601. * \ref SDH_INTSTS_DINTOIF_Msk / \ref SDH_INTSTS_CDSTS0_Msk / \ref SDH_INTSTS_CDSTS1_Msk / \ref SDH_INTSTS_DAT1STS_Msk
  602. *
  603. *
  604. * @return 0 = The specified interrupt is not happened.
  605. * 1 = The specified interrupt is happened.
  606. * \hideinitializer
  607. */
  608. #define SDH_GET_INT_FLAG(sdh, u32IntMask) (((sdh)->INTSTS & (u32IntMask))?1:0)
  609. /**
  610. * @brief Clear specified interrupt flag/status.
  611. *
  612. * @param[in] sdh Select SDH0 or SDH1.
  613. * @param[in] u32IntMask Interrupt type mask:
  614. * \ref SDH_INTSTS_BLKDIF_Msk / \ref SDH_INTSTS_CRCIF_Msk / \ref SDH_INTSTS_CDIF0_Msk /
  615. * \ref SDH_INTSTS_CDIF1_Msk / \ref SDH_INTSTS_SDHOST0IF_Msk / \ref SDH_INTSTS_SDHOST1IF_Msk /
  616. * \ref SDH_INTSTS_RTOIF_Msk / \ref SDH_INTSTS_DINTOIF_Msk
  617. *
  618. *
  619. * @return None.
  620. * \hideinitializer
  621. */
  622. #define SDH_CLR_INT_FLAG(sdh, u32IntMask) ((sdh)->INTSTS = (u32IntMask))
  623. /**
  624. * @brief Check SD Card inserted or removed.
  625. *
  626. * @param[in] sdh Select SDH0 or SDH1.
  627. *
  628. * @return 1: Card inserted.
  629. * 0: Card removed.
  630. * \hideinitializer
  631. */
  632. //#define SDH_IS_CARD_PRESENT(sdh) (((sdh) == SDH0)? SD0.IsCardInsert : SD1.IsCardInsert)
  633. /**
  634. * @brief Get SD Card capacity.
  635. *
  636. * @param[in] sdh Select SDH0 or SDH1.
  637. *
  638. * @return SD Card capacity. (unit: KByte)
  639. * \hideinitializer
  640. */
  641. //#define SDH_GET_CARD_CAPACITY(sdh) (((sdh) == SDH0)? SD0.diskSize : SD1.diskSize)
  642. void SDH_Open(SDH_T *sdh, SDH_INFO_T *pSD, uint32_t u32CardDetSrc);
  643. uint32_t SDH_Probe(SDH_T *sdh, SDH_INFO_T *pSD, uint32_t card_num);
  644. uint32_t SDH_Read(SDH_T *sdh, SDH_INFO_T *pSD, uint8_t *pu8BufAddr, uint32_t u32StartSec, uint32_t u32SecCount);
  645. uint32_t SDH_Write(SDH_T *sdh, SDH_INFO_T *pSD, uint8_t *pu8BufAddr, uint32_t u32StartSec, uint32_t u32SecCount);
  646. void SDH_CardSelect(SDH_T *sdh, SDH_INFO_T *pSD, uint32_t u32CardSrc);
  647. uint32_t SDH_CardDetection(SDH_T *sdh, SDH_INFO_T *pSD, uint32_t card_num);
  648. void SDH_Open_Disk(SDH_T *sdh, SDH_INFO_T *pSD, uint32_t u32CardDetSrc);
  649. void SDH_Close_Disk(SDH_T *sdh, SDH_INFO_T *pSD);
  650. uint32_t SDH_WhichCardIsSelected(SDH_T *sdh);
  651. /*@}*/ /* end of group N9H30_SDH_EXPORTED_FUNCTIONS */
  652. /*@}*/ /* end of group N9H30_SDH_Driver */
  653. /*@}*/ /* end of group N9H30_Device_Driver */
  654. #endif //end of __NU_SDH_H__
  655. /*** (C) COPYRIGHT 2018 Nuvoton Technology Corp. ***/