sdd_sd.c 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662
  1. /*****************************************************************************
  2. *
  3. * Copyright Andes Technology Corporation 2007-2008
  4. * All Rights Reserved.
  5. *
  6. * Revision History:
  7. *
  8. * Sep.26.2007 Created.
  9. ****************************************************************************/
  10. /*****************************************************************************
  11. *
  12. * FILE NAME VERSION
  13. *
  14. * sdd_sd.c
  15. *
  16. * DESCRIPTION
  17. *
  18. * Secure digital card specification 2.0 definition.
  19. *
  20. * Currently only Secure Digital Memory standards are well-defined.
  21. * Remaining spec mostly are left for future developers.
  22. *
  23. * DATA STRUCTURES
  24. *
  25. * None
  26. *
  27. * DEPENDENCIES
  28. *
  29. * None
  30. *
  31. ****************************************************************************/
  32. #include "sdd.h"
  33. #include "sdd_sd.h"
  34. /*
  35. * If SDD_SMALL_FOOTPRINT is defined, SD command routines are defined as
  36. * macros which will be redirect to a general command issuing routine.
  37. *
  38. * If performance is required, set SDD_SMALL_FOOTPRINT to 0. The SD command
  39. * issuing routines are then a set of expanded code.
  40. */
  41. #if (SDD_SMALL_FOOTPRINT)
  42. #define SDC_INLINE static _inline
  43. #else /* SDD_SMALL_FOOTPRINT */
  44. #define SDC_INLINE static
  45. #endif /* SDD_SMALL_FOOTPRINT */
  46. /* Local Helper Routines */
  47. SDC_INLINE uint32_t _sd_cmd(uint32_t cmd)
  48. {
  49. uint32_t retry_cnt = 0;
  50. /* Make sure card exists */
  51. if (GETB32(SDC_STATUS, SDC_SR_CARD_DETECT_BIT))
  52. return SDD_CARD_REMOVED;
  53. /* Clear SDC status bits */
  54. OUT32(SDC_CLEAR, SDC_RSP_CRC_FAIL_MASK | SDC_RSP_TIMEOUT_MASK |
  55. SDC_RSP_CRC_OK_MASK | SDC_CMD_SENT_MASK);
  56. /*OUT32(SDC_CLEAR, SDC_CLEAR_ALL); */
  57. /* Send command */
  58. OUT32(SDC_CMD, cmd);
  59. /* Wait until the command is on the way to the card ... */
  60. while (retry_cnt++ < SD_CMD_MAX_RETRY_COUNT) {
  61. /* Make sure card exists */
  62. if (GETB32(SDC_STATUS, SDC_SR_CARD_DETECT_BIT))
  63. return SDD_CARD_REMOVED;
  64. /* Get new status of SDC */
  65. if (GETB32(SDC_STATUS, SDC_SR_CMD_SENT_BIT) != 0)
  66. return HAL_SUCCESS;
  67. }
  68. return SDD_CMD_TIMEOUT;
  69. }
  70. SDC_INLINE uint32_t _sd_cmd_arg(uint32_t cmd, uint32_t arg)
  71. {
  72. uint32_t retry_cnt = 0;
  73. /* Make sure card exists */
  74. if (GETB32(SDC_STATUS, SDC_SR_CARD_DETECT_BIT))
  75. return SDD_CARD_REMOVED;
  76. /* Clear SDC status bits */
  77. OUT32(SDC_CLEAR, SDC_RSP_CRC_FAIL_MASK | SDC_RSP_TIMEOUT_MASK |
  78. SDC_RSP_CRC_OK_MASK | SDC_CMD_SENT_MASK);
  79. /*OUT32(SDC_CLEAR, SDC_CLEAR_ALL); */
  80. /* Prepare Argument */
  81. OUT32(SDC_CMD_ARG, arg);
  82. /* Send command */
  83. OUT32(SDC_CMD, cmd);
  84. /* Wait until the command is on the way to the card ... */
  85. while (retry_cnt++ < SD_CMD_MAX_RETRY_COUNT) {
  86. /* Make sure card exists */
  87. if (GETB32(SDC_STATUS, SDC_SR_CARD_DETECT_BIT))
  88. return SDD_CARD_REMOVED;
  89. /* Get new status of SDC */
  90. if (GETB32(SDC_STATUS, SDC_SR_CMD_SENT_BIT) != 0)
  91. return HAL_SUCCESS;
  92. }
  93. return SDD_CMD_TIMEOUT;
  94. }
  95. SDC_INLINE uint32_t _sd_cmd_r32(uint32_t cmd, SD_R32 * rsp)
  96. {
  97. uint32_t retry_cnt = 0;
  98. uint32_t sdc_sr = 0;
  99. /* Make sure card exists */
  100. if (GETB32(SDC_STATUS, SDC_SR_CARD_DETECT_BIT))
  101. return SDD_CARD_REMOVED;
  102. /* Clear SDC status bits */
  103. OUT32(SDC_CLEAR, SDC_RSP_CRC_FAIL_MASK | SDC_RSP_TIMEOUT_MASK |
  104. SDC_RSP_CRC_OK_MASK | SDC_CMD_SENT_MASK);
  105. /*OUT32(SDC_CLEAR, SDC_CLEAR_ALL); */
  106. /* Send command */
  107. OUT32(SDC_CMD, cmd);
  108. /* Wait until the command is responsed ... */
  109. while (retry_cnt++ < SD_CMD_MAX_RETRY_COUNT) {
  110. sdc_sr = IN32(SDC_STATUS);
  111. /* Make sure card exists */
  112. if (sdc_sr & SDC_SR_CARD_DETECT_BIT)
  113. return SDD_CARD_REMOVED;
  114. /* Check error status */
  115. if (sdc_sr & SDC_SR_RSP_CRC_OK_MASK) {
  116. rsp->r[0] = IN32(SDC_R0);
  117. return HAL_SUCCESS;
  118. }
  119. else if (sdc_sr & SDC_SR_RSP_CRC_FAIL_MASK) {
  120. return SDD_RSP_CRC_ERROR;
  121. }
  122. else if (sdc_sr & SDC_SR_RSP_TIMEOUT_MASK) {
  123. return SDD_RSP_TIMEOUT;
  124. }
  125. }
  126. return SDD_CMD_TIMEOUT;
  127. }
  128. SDC_INLINE uint32_t _sd_cmd_arg_r32(uint32_t cmd, uint32_t arg, SD_R32 * rsp)
  129. {
  130. uint32_t sdc_sr = 0;
  131. /* Make sure card exists */
  132. if (GETB32(SDC_STATUS, SDC_SR_CARD_DETECT_BIT))
  133. return SDD_CARD_REMOVED;
  134. /* Clear SDC status bits */
  135. OUT32(SDC_CLEAR, SDC_RSP_CRC_FAIL_MASK | SDC_RSP_TIMEOUT_MASK |
  136. SDC_RSP_CRC_OK_MASK);
  137. /*OUT32(SDC_CLEAR, SDC_CLEAR_ALL); */
  138. /* Prepare Argument */
  139. OUT32(SDC_CMD_ARG, arg);
  140. /* Send command */
  141. OUT32(SDC_CMD, cmd);
  142. /* Wait until the command is responsed ... */
  143. while (1) {
  144. // _nds_kwait(0x1000); /* hw need delay ? */
  145. sdc_sr = IN32(SDC_STATUS);
  146. /* Make sure card exists */
  147. if (sdc_sr & SDC_SR_CARD_DETECT_BIT)
  148. return SDD_CARD_REMOVED;
  149. /* Check error status */
  150. if (sdc_sr & SDC_SR_RSP_CRC_OK_MASK) {
  151. rsp->r[0] = IN32(SDC_R0);
  152. return HAL_SUCCESS;
  153. }
  154. else if (sdc_sr & SDC_SR_RSP_CRC_FAIL_MASK) {
  155. return SDD_RSP_CRC_ERROR;
  156. }
  157. else if (sdc_sr & SDC_SR_RSP_TIMEOUT_MASK) {
  158. return SDD_RSP_TIMEOUT;
  159. }
  160. }
  161. return SDD_CMD_TIMEOUT;
  162. }
  163. SDC_INLINE uint32_t _sd_cmd_r128(uint32_t cmd, SD_R128 * rsp)
  164. {
  165. uint32_t retry_cnt = 0;
  166. uint32_t sdc_sr = 0;
  167. /* Make sure card exists */
  168. if (GETB32(SDC_STATUS, SDC_SR_CARD_DETECT_BIT))
  169. return SDD_CARD_REMOVED;
  170. /* Clear SDC status bits */
  171. OUT32(SDC_CLEAR, SDC_RSP_CRC_FAIL_MASK | SDC_RSP_TIMEOUT_MASK |
  172. SDC_RSP_CRC_OK_MASK | SDC_CMD_SENT_MASK);
  173. /*OUT32(SDC_CLEAR, SDC_CLEAR_ALL); */
  174. /* Send command */
  175. OUT32(SDC_CMD, cmd);
  176. /* Wait until the command is responsed ... */
  177. while (retry_cnt++ < SD_CMD_MAX_RETRY_COUNT) {
  178. sdc_sr = IN32(SDC_STATUS);
  179. /* Make sure card exists */
  180. if (sdc_sr & SDC_SR_CARD_DETECT_BIT)
  181. return SDD_CARD_REMOVED;
  182. /* Check error status */
  183. if (sdc_sr & SDC_SR_RSP_CRC_OK_MASK) {
  184. rsp->r[0] = IN32(SDC_R0);
  185. rsp->r[1] = IN32(SDC_R1);
  186. rsp->r[2] = IN32(SDC_R2);
  187. rsp->r[3] = IN32(SDC_R3);
  188. return HAL_SUCCESS;
  189. }
  190. else if (sdc_sr & SDC_SR_RSP_CRC_FAIL_MASK) {
  191. return SDD_RSP_CRC_ERROR;
  192. }
  193. else if (sdc_sr & SDC_SR_RSP_TIMEOUT_MASK) {
  194. return SDD_RSP_TIMEOUT;
  195. }
  196. }
  197. return SDD_CMD_TIMEOUT;
  198. }
  199. SDC_INLINE uint32_t _sd_cmd_arg_r128(uint32_t cmd, uint32_t arg, SD_R128 * rsp)
  200. {
  201. uint32_t retry_cnt = 0;
  202. uint32_t sdc_sr = 0;
  203. /* Make sure card exists */
  204. if (GETB32(SDC_STATUS, SDC_SR_CARD_DETECT_BIT))
  205. return SDD_CARD_REMOVED;
  206. /* Clear SDC status bits */
  207. OUT32(SDC_CLEAR, SDC_RSP_CRC_FAIL_MASK | SDC_RSP_TIMEOUT_MASK |
  208. SDC_RSP_CRC_OK_MASK | SDC_CMD_SENT_MASK);
  209. /*OUT32(SDC_CLEAR, SDC_CLEAR_ALL); */
  210. /* Prepare Argument */
  211. OUT32(SDC_CMD_ARG, arg);
  212. /* Send command */
  213. OUT32(SDC_CMD, cmd);
  214. /* Wait until the command is responsed ... */
  215. while (retry_cnt++ < SD_CMD_MAX_RETRY_COUNT) {
  216. sdc_sr = IN32(SDC_STATUS);
  217. /* Make sure card exists */
  218. if (sdc_sr & SDC_SR_CARD_DETECT_BIT)
  219. return SDD_CARD_REMOVED;
  220. /* Check error status */
  221. if (sdc_sr & SDC_SR_RSP_CRC_OK_MASK) {
  222. rsp->r[0] = IN32(SDC_R0);
  223. rsp->r[1] = IN32(SDC_R1);
  224. rsp->r[2] = IN32(SDC_R2);
  225. rsp->r[3] = IN32(SDC_R3);
  226. return HAL_SUCCESS;
  227. }
  228. else if (sdc_sr & SDC_SR_RSP_CRC_FAIL_MASK) {
  229. return SDD_RSP_CRC_ERROR;
  230. }
  231. else if (sdc_sr & SDC_SR_RSP_TIMEOUT_MASK) {
  232. return SDD_RSP_TIMEOUT;
  233. }
  234. }
  235. return SDD_CMD_TIMEOUT;
  236. }
  237. /*****************************************************************************
  238. * FUNCTION
  239. *
  240. * _sd_cmd0
  241. *
  242. * DESCRIPTION
  243. *
  244. * This function issues SD command GO_IDLE_STATE: Reset all cards to idle
  245. * state.
  246. *
  247. * Class: 0 (basic commands)
  248. *
  249. * State Transition:
  250. * idle -> idle
  251. *
  252. * Argument:
  253. * [31:0] stuff bits
  254. *
  255. * Response:
  256. * None
  257. *
  258. * INPUTS
  259. *
  260. * None.
  261. *
  262. * OUTPUTS
  263. *
  264. * uint32_t : Returns HAL_SUCCESS if successful,
  265. * else positive value is SDD-specific error code,
  266. * else negative value is NU system error code.
  267. *
  268. ****************************************************************************/
  269. #if (SDD_SMALL_SD_FOOTPRINT == 0)
  270. uint32_t _sd_cmd0(void)
  271. {
  272. return _sd_cmd(SDC_CMD0_GO_IDLE_STATE);
  273. }
  274. #endif /* (SDD_SMALL_SD_FOOTPRINT == 0) */
  275. /*****************************************************************************
  276. * FUNCTION
  277. *
  278. * _sd_cmd2
  279. *
  280. * DESCRIPTION
  281. *
  282. * This function issues SD command ALL_SEND_CID: Ask any card to send the
  283. * CID numbers
  284. *
  285. * Class: 0 (basic commands)
  286. *
  287. * State Transition:
  288. * ready -> identification
  289. *
  290. * Argument:
  291. * [31:0] stuff bits
  292. *
  293. * Response:
  294. * R2 [127:1] CID
  295. *
  296. * INPUTS
  297. *
  298. * cid : Pointer to SD_CID struct.
  299. *
  300. * OUTPUTS
  301. *
  302. * cid : SD_CID struct which holds the card's CID register value.
  303. *
  304. * uint32_t : Returns HAL_SUCCESS if successful,
  305. * else positive value is SDD-specific error code,
  306. * else negative value is NU system error code.
  307. *
  308. ****************************************************************************/
  309. uint32_t _sd_cmd2(SD_CID * cid)
  310. {
  311. return _sd_cmd_r128(SDC_CMD2_ALL_SEND_CID, cid);
  312. }
  313. /*****************************************************************************
  314. * FUNCTION
  315. *
  316. * _sd_cmd3
  317. *
  318. * DESCRIPTION
  319. *
  320. * This function issues SD command SEND_RELATIVE_ADDR: Ask the card to
  321. * publish a new RCA.
  322. *
  323. * Class: 0 (basic commands)
  324. *
  325. * State Transition:
  326. * identification -> standby
  327. * standy -> standby
  328. *
  329. * Argument:
  330. * [31:0] stuff bits
  331. *
  332. * Response:
  333. * R6 [23:08] card status bits: 23, 22, 19, 12:0
  334. * [39:24] New publishded RCA
  335. *
  336. * INPUTS
  337. *
  338. * rca : Pointer to SD_R32 struct to receive RCA.
  339. *
  340. * OUTPUTS
  341. *
  342. * rca : SD_R32 struct where RCA will be placed at [31:16].
  343. * uint32_t : Returns HAL_SUCCESS if successful,
  344. * else positive value is SDD-specific error code,
  345. * else negative value is NU system error code.
  346. *
  347. ****************************************************************************/
  348. uint32_t _sd_cmd3(SD_R32 * rca)
  349. {
  350. return _sd_cmd_r32(SDC_CMD3_SEND_RELATIVE_ADDR, rca);
  351. }
  352. /*****************************************************************************
  353. * FUNCTION
  354. *
  355. * _sd_cmd4
  356. *
  357. * DESCRIPTION
  358. *
  359. * This function issues SD command SET_DSR: Program DSR of all cards.
  360. *
  361. * Class: 0 (basic commands)
  362. *
  363. * State Transition:
  364. * standy -> standby
  365. *
  366. * Argument:
  367. * [31:16] DSR
  368. *
  369. * Response:
  370. * None
  371. *
  372. * INPUTS
  373. *
  374. * dsr : uint32_t value where DSR is at [31:16].
  375. *
  376. * OUTPUTS
  377. *
  378. * uint32_t : Returns HAL_SUCCESS if successful,
  379. * else positive value is SDD-specific error code,
  380. * else negative value is NU system error code.
  381. *
  382. ****************************************************************************/
  383. #if (SDD_SMALL_SD_FOOTPRINT == 0)
  384. uint32_t _sd_cmd4(uint32_t dsr)
  385. {
  386. return _sd_cmd_arg(SDC_CMD4_SET_DSR, dsr);
  387. }
  388. #endif /* (SDD_SMALL_SD_FOOTPRINT == 0) */
  389. /*****************************************************************************
  390. * FUNCTION
  391. *
  392. * _sd_cmd7
  393. *
  394. * DESCRIPTION
  395. *
  396. * This function issues SD command SELECT/DESELECT_CARD: Toggles between
  397. * standby and transfer states or between programming and disconnect
  398. * states. Cards with matching RCA is selected, otherwise deselected.
  399. *
  400. * Class: 0 (basic commands)
  401. *
  402. * State Transition:
  403. * selected card:
  404. * standby -> transfer
  405. * disconnected -> programming
  406. * deselected card
  407. * standby -> standby
  408. * transfer -> standby
  409. * sending-data -> standby
  410. * programming -> disconnected
  411. *
  412. * Argument:
  413. * [31:16] RCA
  414. *
  415. * Response:
  416. * R1b [39:8] card status
  417. * DAT0 busy signal
  418. *
  419. * INPUTS
  420. *
  421. * rca : SD_R32 struct where RCA is at [31:16].
  422. * csr : Pointer to SD_R32 struct.
  423. *
  424. * OUTPUTS
  425. *
  426. * csr : SD_R32 struct which holds the R1 response.
  427. * uint32_t : Returns HAL_SUCCESS if successful,
  428. * else positive value is SDD-specific error code,
  429. * else negative value is NU system error code.
  430. *
  431. ****************************************************************************/
  432. uint32_t _sd_cmd7(uint32_t rca, SD_R32 * csr)
  433. {
  434. uint32_t status = _sd_cmd_arg_r32(SDC_CMD7_SELECT_DESELECT_CARD, rca, csr);
  435. if (status != HAL_SUCCESS)
  436. return status;
  437. if (SD_CSR_CHECK_ERROR_BITS(*csr))
  438. return SDD_CSR_ERROR;
  439. return HAL_SUCCESS;
  440. }
  441. /*****************************************************************************
  442. * FUNCTION
  443. *
  444. * _sd_cmd8
  445. *
  446. * DESCRIPTION
  447. *
  448. * This function issues SD command SEND_IF_COND: Send VHS to SD card before
  449. * issuing ACMD41 during initialization and identification process.
  450. *
  451. * Class: 0 (basic commands)
  452. *
  453. * State Transition:
  454. * idle -> idle
  455. *
  456. * Argument:
  457. * [11:8] VHS (see R7 bellow)
  458. * [ 7:0] Arbitrary Check Pattern (10101010b(0xaa) is suggested)
  459. *
  460. * Response:
  461. * R7 [19:16] voltage accepted (VHS)
  462. * 0001b (0x01) -> 2.7-3.6v
  463. * others are reserved or undefined
  464. *
  465. * INPUTS
  466. *
  467. * vhs_arg: uint32_t value with VHS at [11:8] and check-ptn at [7:0].
  468. * vhs_rsp: Pointer to SD_R32 struct to hold the response.
  469. *
  470. * OUTPUTS
  471. *
  472. * vhs_rsp: SD_R32 struct with VHS at [11:8] and check-ptn at [7:0].
  473. * uint32_t : Returns HAL_SUCCESS if successful,
  474. * else positive value is SDD-specific error code,
  475. * else negative value is NU system error code.
  476. *
  477. ****************************************************************************/
  478. uint32_t _sd_cmd8(uint32_t vhs_arg, SD_R32 * vhs_rsp)
  479. {
  480. return _sd_cmd_arg_r32(SDC_CMD8_SEND_IF_COND, vhs_arg, vhs_rsp);
  481. }
  482. /*****************************************************************************
  483. * FUNCTION
  484. *
  485. * _sd_cmd9
  486. *
  487. * DESCRIPTION
  488. *
  489. * This function issues SD command SEND_CSD: Ask addressed card to send its
  490. * CSD on the command line.
  491. *
  492. * Class: 0 (basic commands)
  493. *
  494. * State Transition:
  495. * standby -> standby
  496. *
  497. * Argument:
  498. * [31:16] RCA
  499. *
  500. * Response:
  501. * R2 [127:1] CSD
  502. *
  503. * INPUTS
  504. *
  505. * rca : uint32_t value where RCA is at [31:16].
  506. * csd : Pointer to SD_CSD struct.
  507. *
  508. * OUTPUTS
  509. *
  510. * csd : SD_CSD struct which contains CSD response.
  511. * uint32_t : Returns HAL_SUCCESS if successful,
  512. * else positive value is SDD-specific error code,
  513. * else negative value is NU system error code.
  514. *
  515. ****************************************************************************/
  516. uint32_t _sd_cmd9(uint32_t rca, SD_CSD * csd)
  517. {
  518. return _sd_cmd_arg_r128(SDC_CMD9_SEND_CSD, rca, csd);
  519. }
  520. /*****************************************************************************
  521. * FUNCTION
  522. *
  523. * _sd_cmd10
  524. *
  525. * DESCRIPTION
  526. *
  527. * This function issues SD command SEND_CID: Ask addressed card to send its
  528. * CID on the command line.
  529. *
  530. * Class: 0 (basic commands)
  531. *
  532. * State Transition:
  533. * standby -> standby
  534. *
  535. * Argument:
  536. * [31:16] RCA
  537. *
  538. * Response:
  539. * R2 [127:1] CID
  540. *
  541. * INPUTS
  542. *
  543. * rca : uint32_t value where RCA is at [31:16].
  544. * cid : Pointer to SD_CID struct.
  545. *
  546. * OUTPUTS
  547. *
  548. * cid : SD_CID struct which contains CID response.
  549. * uint32_t : Returns HAL_SUCCESS if successful,
  550. * else positive value is SDD-specific error code,
  551. * else negative value is NU system error code.
  552. *
  553. ****************************************************************************/
  554. #if (SDD_SMALL_SD_FOOTPRINT == 0)
  555. uint32_t _sd_cmd10(uint32_t rca, SD_CID * cid)
  556. {
  557. return _sd_cmd_arg_r128(SDC_CMD10_SEND_CID, rca, cid);
  558. }
  559. #endif /* (SDD_SMALL_SD_FOOTPRINT == 0) */
  560. /*****************************************************************************
  561. * FUNCTION
  562. *
  563. * _sd_cmd12
  564. *
  565. * DESCRIPTION
  566. *
  567. * This function issues SD command STOP_TRANSMISSION: Forces the card to
  568. * stop transmission.
  569. *
  570. * Class: 0 (basic commands)
  571. *
  572. * State Transition:
  573. * snedning-data -> transfer
  574. * receiving-data -> programming
  575. *
  576. * Argument:
  577. * [31:0] stuff bits
  578. *
  579. * Response:
  580. * R1b [39:8] card status
  581. * DAT0 busy signal
  582. *
  583. * INPUTS
  584. *
  585. * csr : Pointer to SD_R32 value.
  586. *
  587. * OUTPUTS
  588. *
  589. * csr : SD_R32 struct which holds the R1 response.
  590. * uint32_t : Returns HAL_SUCCESS if successful,
  591. * else positive value is SDD-specific error code,
  592. * else negative value is NU system error code.
  593. *
  594. ****************************************************************************/
  595. uint32_t _sd_cmd12(SD_R32 * csr)
  596. {
  597. uint32_t status = _sd_cmd_r32(SDC_CMD12_STOP_TRANSMISSION, csr);
  598. if (status != HAL_SUCCESS)
  599. return status;
  600. if (SD_CSR_CHECK_ERROR_BITS(*csr)) /* todo: ok to check all error bits */
  601. return SDD_CSR_ERROR;
  602. return HAL_SUCCESS;
  603. }
  604. /*****************************************************************************
  605. * FUNCTION
  606. *
  607. * _sd_cmd13
  608. *
  609. * DESCRIPTION
  610. *
  611. * This function issues SD command SEND_STATUS: Ask the card to send its
  612. * card status.
  613. *
  614. * Class: 0 (basic commands)
  615. *
  616. * State Transition:
  617. * standby -> standby
  618. * transfer -> transfer
  619. * sending-data -> sending-data
  620. * receiving-data -> receieving-data
  621. * programming -> programming
  622. * disconnect -> disconnect
  623. *
  624. * Argument:
  625. * [31:16] RCA
  626. *
  627. * Response:
  628. * R1 [39:8] card status
  629. *
  630. * INPUTS
  631. *
  632. * rca : uint32_t value where RCA is at [31:16].
  633. * csr : Pointer to SD_R32 to receive CSR.
  634. *
  635. * OUTPUTS
  636. *
  637. * csr : SD_R32 which holds the received CSR.
  638. * uint32_t : Returns HAL_SUCCESS if successful,
  639. * else positive value is SDD-specific error code,
  640. * else negative value is NU system error code.
  641. *
  642. ****************************************************************************/
  643. uint32_t _sd_cmd13(uint32_t rca, SD_R32 * csr)
  644. {
  645. uint32_t status = _sd_cmd_arg_r32(SDC_CMD13_SEND_STATUS, rca, csr);
  646. if (status != HAL_SUCCESS)
  647. return status;
  648. if (SD_CSR_CHECK_ERROR_BITS(*csr))
  649. return SDD_CSR_ERROR;
  650. return HAL_SUCCESS;
  651. }
  652. /*****************************************************************************
  653. * FUNCTION
  654. *
  655. * _sd_cmd15
  656. *
  657. * DESCRIPTION
  658. *
  659. * This function issues SD command GO_INACTIVE_STATE: Inactivate the
  660. * addressed card to inactive state.
  661. *
  662. * Class: 0 (basic commands)
  663. *
  664. * State Transition:
  665. * standby -> inactive
  666. * transfer -> inactive
  667. * sending-data -> inactive
  668. * receiving-data -> inactive
  669. * programming -> inactive
  670. * disconnect -> inactive
  671. *
  672. * Argument:
  673. * [31:16] RCA
  674. * [15: 0] Should be 0!
  675. *
  676. * Response:
  677. * None
  678. *
  679. * INPUTS
  680. *
  681. * rca : uint32_t value with RCA at [31:16], 0 at [15:0].
  682. *
  683. * OUTPUTS
  684. *
  685. * uint32_t : Returns HAL_SUCCESS if successful,
  686. * else positive value is SDD-specific error code,
  687. * else negative value is NU system error code.
  688. *
  689. ****************************************************************************/
  690. #if (SDD_SMALL_SD_FOOTPRINT == 0)
  691. uint32_t _sd_cmd15(uint32_t rca)
  692. {
  693. return _sd_cmd_arg(SDC_CMD15_GO_INACTIVE_STATE, rca);
  694. }
  695. #endif /* (SDD_SMALL_SD_FOOTPRINT == 0) */
  696. /*****************************************************************************
  697. * FUNCTION
  698. *
  699. * _sd_cmd16
  700. *
  701. * DESCRIPTION
  702. *
  703. * This function issues SD command SET_BLOCKLEN: Set block length (bytes)
  704. * for standard capacity SD cards. SDHC is fixed to 512 bytes and ignores
  705. * this field except the LOCK_UNLOCK command.
  706. *
  707. * Class: 2/4/7 (block-oriented read/write/lock_unlock commands)
  708. *
  709. * State Transition:
  710. * transfer -> transfer
  711. *
  712. * Argument:
  713. * [31:0] block length
  714. *
  715. * Response:
  716. * R1 [39:8] card status
  717. *
  718. * INPUTS
  719. *
  720. * blk_len: uint32_t block length value.
  721. * csr : Pointer to SD_R32 struct.
  722. *
  723. * OUTPUTS
  724. *
  725. * csr : SD_R32 struct which holds the R1 response.
  726. * uint32_t : Returns HAL_SUCCESS if successful,
  727. * else positive value is SDD-specific error code,
  728. * else negative value is NU system error code.
  729. *
  730. ****************************************************************************/
  731. uint32_t _sd_cmd16(uint32_t blk_len, SD_R32 * csr)
  732. {
  733. uint32_t status = _sd_cmd_arg_r32(SDC_CMD16_SET_BLOCKLEN, blk_len, csr);
  734. if (status != HAL_SUCCESS)
  735. return status;
  736. if (SD_CSR_CHECK_ERROR_BITS(*csr))
  737. return SDD_CSR_ERROR;
  738. return HAL_SUCCESS;
  739. }
  740. /*****************************************************************************
  741. * FUNCTION
  742. *
  743. * _sd_cmd17
  744. *
  745. * DESCRIPTION
  746. *
  747. * This function issues SD command READ_SINGLE_BLOCK: Reads a single block
  748. * size of data.
  749. *
  750. * Class: 2 (block-oriented read commands)
  751. *
  752. * State Transition:
  753. * transfer -> sending-data
  754. *
  755. * Argument:
  756. * [31:0] data address (byte-unit for SD, block unit for SDHC)
  757. *
  758. * Response:
  759. * R1 [39:8] card status
  760. *
  761. * INPUTS
  762. *
  763. * addr : uint32_t address value.
  764. * csr : Pointer to SD_R32 struct.
  765. *
  766. * OUTPUTS
  767. *
  768. * csr : SD_R32 struct which holds the R1 response.
  769. * uint32_t : Returns HAL_SUCCESS if successful,
  770. * else positive value is SDD-specific error code,
  771. * else negative value is NU system error code.
  772. *
  773. ****************************************************************************/
  774. #if (SDD_SMALL_SD_FOOTPRINT == 0)
  775. uint32_t _sd_cmd17(uint32_t addr, SD_R32 * csr)
  776. {
  777. #if 0
  778. uint32_t retry = 0;
  779. while (retry++ < SD_STATE_MAX_RETRY_COUNT) {
  780. #endif
  781. /* Send SD command */
  782. uint32_t status =
  783. _sd_cmd_arg_r32(SDC_CMD17_READ_SINGLE_BLOCK, addr, csr);
  784. if (status != HAL_SUCCESS) {
  785. return status;
  786. }
  787. /* Check error status */
  788. if (SD_CSR_CHECK_ERROR_BITS(*csr))
  789. return SDD_CSR_ERROR;
  790. #if 0
  791. /* Check whether make transition to sending-data state */
  792. switch (SD_CSR_GET_CURRENT_STATE(*csr)) {
  793. case SD_STATE_DATA:
  794. /* The card is ready to send out data */
  795. return HAL_SUCCESS;
  796. case SD_STATE_TRAN:
  797. /* Repeat previous command until the card get to the state */
  798. break;
  799. case SD_STATE_STBY:
  800. case SD_STATE_RCV:
  801. case SD_STATE_PRG:
  802. case SD_STATE_IDLE:
  803. case SD_STATE_READY:
  804. case SD_STATE_IDENT:
  805. case SD_STATE_DIS:
  806. default:
  807. /* Invalid current state before deselecting the card. */
  808. return SDD_INVALID_STATE;
  809. }
  810. }
  811. return SDD_WAIT_TIMEOUT;
  812. #else
  813. return HAL_SUCCESS;
  814. #endif
  815. }
  816. #endif /* (SDD_SMALL_SD_FOOTPRINT == 0) */
  817. /*****************************************************************************
  818. * FUNCTION
  819. *
  820. * _sd_cmd18
  821. *
  822. * DESCRIPTION
  823. *
  824. * This function issues SD command READ_MULTIPLE_BLOCK: Reads blocks of data
  825. * from card continuously until a STOP_TRANSMISSION command.
  826. *
  827. * Class: 2 (block-oriented read commands)
  828. *
  829. * State Transition:
  830. * transfer -> sending-data
  831. *
  832. * Argument:
  833. * [31:0] data address (byte-unit for SD, block unit for SDHC)
  834. *
  835. * Response:
  836. * R1 [39:8] card status
  837. *
  838. * INPUTS
  839. *
  840. * addr : uint32_t address value.
  841. * csr : Pointer to SD_R32 struct.
  842. *
  843. * OUTPUTS
  844. *
  845. * csr : SD_R32 struct which holds the R1 response.
  846. * uint32_t : Returns HAL_SUCCESS if successful,
  847. * else positive value is SDD-specific error code,
  848. * else negative value is NU system error code.
  849. *
  850. ****************************************************************************/
  851. uint32_t _sd_cmd18(uint32_t addr, SD_R32 * csr) {
  852. #if 0
  853. uint32_t retry = 0;
  854. while (retry++ < SD_STATE_MAX_RETRY_COUNT) {
  855. #endif
  856. /* Send SD command */
  857. uint32_t status =
  858. _sd_cmd_arg_r32(SDC_CMD18_READ_MULTIPLE_BLOCK, addr,
  859. csr);
  860. if (status != HAL_SUCCESS) {
  861. return status;
  862. }
  863. /* Check error status */
  864. if (SD_CSR_CHECK_ERROR_BITS(*csr))
  865. return SDD_CSR_ERROR;
  866. #if 0
  867. /* Check whether make transition to sending-data state */
  868. switch (SD_CSR_GET_CURRENT_STATE(*csr)) {
  869. case SD_STATE_DATA:
  870. /* The card is ready to send out data */
  871. return HAL_SUCCESS;
  872. case SD_STATE_TRAN:
  873. /* Repeat previous command until the card get to the state */
  874. break;
  875. case SD_STATE_STBY:
  876. case SD_STATE_RCV:
  877. case SD_STATE_PRG:
  878. case SD_STATE_IDLE:
  879. case SD_STATE_READY:
  880. case SD_STATE_IDENT:
  881. case SD_STATE_DIS:
  882. default:
  883. /* Invalid current state before deselecting the card. */
  884. return SDD_INVALID_STATE;
  885. }
  886. }
  887. return SDD_WAIT_TIMEOUT;
  888. #else
  889. return HAL_SUCCESS;
  890. #endif
  891. }
  892. /*****************************************************************************
  893. * FUNCTION
  894. *
  895. * _sd_cmd24
  896. *
  897. * DESCRIPTION
  898. *
  899. * This function issues SD command WRITE_SINGLE_BLOCK: Writes a single
  900. * block size of data.
  901. *
  902. * Class: 2 (block-oriented write commands)
  903. *
  904. * State Transition:
  905. * transfer -> receiving-data
  906. *
  907. * Argument:
  908. * [31:0] data address (byte-unit for SD, block unit for SDHC)
  909. *
  910. * Response:
  911. * R1 [39:8] card status
  912. *
  913. * INPUTS
  914. *
  915. * addr : uint32_t address value.
  916. * csr : Pointer to SD_R32 struct.
  917. *
  918. * OUTPUTS
  919. *
  920. * csr : SD_R32 struct which holds the R1 response.
  921. * uint32_t : Returns HAL_SUCCESS if successful,
  922. * else positive value is SDD-specific error code,
  923. * else negative value is NU system error code.
  924. *
  925. ****************************************************************************/
  926. #if (SDD_SMALL_SD_FOOTPRINT == 0)
  927. uint32_t _sd_cmd24(uint32_t addr, SD_R32 * csr) {
  928. #if 0
  929. uint32_t retry = 0;
  930. while (retry++ < SD_STATE_MAX_RETRY_COUNT) {
  931. #endif
  932. /* Send SD command */
  933. uint32_t status = _sd_cmd_arg_r32(SDC_CMD24_WRITE_BLOCK, addr, csr);
  934. if (status != HAL_SUCCESS)
  935. return status;
  936. /* Check error status */
  937. if (SD_CSR_CHECK_ERROR_BITS(*csr))
  938. return SDD_CSR_ERROR;
  939. #if 0
  940. /* Check whether make transition to sending-data state */
  941. switch (SD_CSR_GET_CURRENT_STATE(*csr)) {
  942. case SD_STATE_RCV:
  943. /* The card is ready to send out data */
  944. return HAL_SUCCESS;
  945. case SD_STATE_TRAN:
  946. /* Repeat previous command until the card get to the state */
  947. break;
  948. case SD_STATE_STBY:
  949. case SD_STATE_DATA:
  950. case SD_STATE_PRG:
  951. case SD_STATE_IDLE:
  952. case SD_STATE_READY:
  953. case SD_STATE_IDENT:
  954. case SD_STATE_DIS:
  955. default:
  956. /* Invalid current state before deselecting the card. */
  957. return SDD_INVALID_STATE;
  958. }
  959. }
  960. return SDD_WAIT_TIMEOUT;
  961. #else
  962. return HAL_SUCCESS;
  963. #endif
  964. }
  965. #endif /* (SDD_SMALL_SD_FOOTPRINT == 0) */
  966. /*****************************************************************************
  967. * FUNCTION
  968. *
  969. * _sd_cmd25
  970. *
  971. * DESCRIPTION
  972. *
  973. * This function issues SD command WRITE_MULTIPLE_BLOCK: Writes blocks of
  974. * data to the card continuously until a STOP_TRANSMISSION command.
  975. *
  976. * Class: 2 (block-oriented write commands)
  977. *
  978. * State Transition:
  979. * transfer -> receiving-data
  980. *
  981. * Argument:
  982. * [31:0] data address (byte-unit for SD, block unit for SDHC)
  983. *
  984. * Response:
  985. * R1 [39:8] card status
  986. *
  987. * INPUTS
  988. *
  989. * addr : uint32_t address value.
  990. * csr : Pointer to SD_R32 struct.
  991. *
  992. * OUTPUTS
  993. *
  994. * csr : SD_R32 struct which holds the R1 response.
  995. * uint32_t : Returns HAL_SUCCESS if successful,
  996. * else positive value is SDD-specific error code,
  997. * else negative value is NU system error code.
  998. *
  999. ****************************************************************************/
  1000. uint32_t _sd_cmd25(uint32_t addr, SD_R32 * csr) {
  1001. #if 0
  1002. uint32_t retry = 0;
  1003. while (retry++ < SD_STATE_MAX_RETRY_COUNT) {
  1004. #endif
  1005. /* Send SD command */
  1006. uint32_t status = _sd_cmd_arg_r32 (SDC_CMD25_WRITE_MULTIPLE_BLOCK, addr, csr);
  1007. if (status != HAL_SUCCESS)
  1008. return status;
  1009. /* Check error status */
  1010. if (SD_CSR_CHECK_ERROR_BITS(*csr))
  1011. return SDD_CSR_ERROR;
  1012. #if 0
  1013. /* Check whether make transition to sending-data state */
  1014. switch (SD_CSR_GET_CURRENT_STATE(*csr)) {
  1015. case SD_STATE_RCV:
  1016. /* The card is ready to send out data */
  1017. return HAL_SUCCESS;
  1018. case SD_STATE_TRAN:
  1019. /* Repeat previous command until the card get to the state */
  1020. break;
  1021. case SD_STATE_STBY:
  1022. case SD_STATE_DATA:
  1023. case SD_STATE_PRG:
  1024. case SD_STATE_IDLE:
  1025. case SD_STATE_READY:
  1026. case SD_STATE_IDENT:
  1027. case SD_STATE_DIS:
  1028. default:
  1029. /* Invalid current state before deselecting the card. */
  1030. return SDD_INVALID_STATE;
  1031. }
  1032. }
  1033. return SDD_WAIT_TIMEOUT;
  1034. #else
  1035. return HAL_SUCCESS;
  1036. #endif
  1037. }
  1038. /*****************************************************************************
  1039. * FUNCTION
  1040. *
  1041. * _sd_cmd27
  1042. *
  1043. * DESCRIPTION
  1044. *
  1045. * This function issues SD command PROGRAM_CSD: Programming the
  1046. * programmable bits of the CSD (using DATx lines).
  1047. *
  1048. * Class: 2 (block-oriented write commands)
  1049. *
  1050. * State Transition:
  1051. * transfer -> receiving-data
  1052. *
  1053. * Argument:
  1054. * [31:0] stufing bits
  1055. *
  1056. * Response:
  1057. * R1 [39:8] card status
  1058. *
  1059. * INPUTS
  1060. *
  1061. * csr : Pointer to SD_R32 struct.
  1062. *
  1063. * OUTPUTS
  1064. *
  1065. * csr : SD_R32 struct which holds the R1 response.
  1066. * uint32_t : Returns HAL_SUCCESS if successful,
  1067. * else positive value is SDD-specific error code,
  1068. * else negative value is NU system error code.
  1069. *
  1070. ****************************************************************************/
  1071. #if (SDD_SMALL_SD_FOOTPRINT == 0)
  1072. uint32_t _sd_cmd27(SD_R32 * csr) {
  1073. uint32_t status = _sd_cmd_r32(SDC_CMD27_PROGRAM_CSD, csr);
  1074. if (status != HAL_SUCCESS)
  1075. return status;
  1076. if (SD_CSR_CHECK_ERROR_BITS(*csr))
  1077. return SDD_CSR_ERROR;
  1078. return HAL_SUCCESS;
  1079. }
  1080. #endif /* (SDD_SMALL_SD_FOOTPRINT == 0) */
  1081. /*****************************************************************************
  1082. * FUNCTION
  1083. *
  1084. * _sd_cmd28
  1085. *
  1086. * DESCRIPTION
  1087. *
  1088. * This function issues SD command SET_WRITE_PROT: Sets the write protection
  1089. * bits of the addressed group, if supported. (Not supported in SDHC)
  1090. *
  1091. * Class: 6 (block-oriented write protection commands)
  1092. *
  1093. * State Transition:
  1094. * transfer -> programming
  1095. *
  1096. * Argument:
  1097. * [31:0] data address (byte unit)
  1098. *
  1099. * Response:
  1100. * R1b [39:8] card status
  1101. * DAT0 busy signal
  1102. *
  1103. * INPUTS
  1104. *
  1105. * addr : uint32_t address value.
  1106. * csr : Pointer to SD_R32 struct.
  1107. *
  1108. * OUTPUTS
  1109. *
  1110. * csr : SD_R32 struct which holds the R1 response.
  1111. * uint32_t : Returns HAL_SUCCESS if successful,
  1112. * else positive value is SDD-specific error code,
  1113. * else negative value is NU system error code.
  1114. *
  1115. ****************************************************************************/
  1116. #if (SDD_SMALL_SD_FOOTPRINT == 0)
  1117. uint32_t _sd_cmd28(uint32_t addr, SD_R32 * csr) {
  1118. uint32_t status = _sd_cmd_arg_r32 (SDC_CMD28_SET_WRITE_PROT, addr, csr);
  1119. if (status != HAL_SUCCESS)
  1120. return status;
  1121. if (SD_CSR_CHECK_ERROR_BITS(*csr))
  1122. return SDD_CSR_ERROR;
  1123. return HAL_SUCCESS;
  1124. }
  1125. #endif /* (SDD_SMALL_SD_FOOTPRINT == 0) */
  1126. /*****************************************************************************
  1127. * FUNCTION
  1128. *
  1129. * _sd_cmd29
  1130. *
  1131. * DESCRIPTION
  1132. *
  1133. * This function issues SD command CLR_WRITE_PROT: Clears the write
  1134. * protection bits of the addressed group, if supported.
  1135. * (Not supported in SDHC)
  1136. *
  1137. * Class: 6 (block-oriented write protection commands)
  1138. *
  1139. * State Transition:
  1140. * transfer -> programming
  1141. *
  1142. * Argument:
  1143. * [31:0] data address (byte unit)
  1144. *
  1145. * Response:
  1146. * R1b [39:8] card status
  1147. * DAT0 busy signal
  1148. *
  1149. * INPUTS
  1150. *
  1151. * addr : uint32_t address value.
  1152. * csr : Pointer to SD_R32 struct.
  1153. *
  1154. * OUTPUTS
  1155. *
  1156. * csr : SD_R32 struct which holds the R1 response.
  1157. * uint32_t : Returns HAL_SUCCESS if successful,
  1158. * else positive value is SDD-specific error code,
  1159. * else negative value is NU system error code.
  1160. *
  1161. ****************************************************************************/
  1162. #if (SDD_SMALL_SD_FOOTPRINT == 0)
  1163. uint32_t _sd_cmd29(uint32_t addr, SD_R32 * csr) {
  1164. uint32_t status = _sd_cmd_arg_r32 (SDC_CMD29_CLR_WRITE_PROT, addr, csr);
  1165. if (status != HAL_SUCCESS)
  1166. return status;
  1167. if (SD_CSR_CHECK_ERROR_BITS(*csr))
  1168. return SDD_CSR_ERROR;
  1169. return HAL_SUCCESS;
  1170. }
  1171. #endif /* (SDD_SMALL_SD_FOOTPRINT == 0) */
  1172. /*****************************************************************************
  1173. * FUNCTION
  1174. *
  1175. * _sd_cmd30
  1176. *
  1177. * DESCRIPTION
  1178. *
  1179. * This function issues SD command SEND_WRITE_PROT: Ask the card to send
  1180. * the status of the protection bits of the addressed group, if supported.
  1181. * (Not supported in SDHC)
  1182. *
  1183. * Class: 6 (block-oriented write protection commands)
  1184. *
  1185. * State Transition:
  1186. * transfer -> receiving-data
  1187. *
  1188. * Argument:
  1189. * [31:0] data address (byte unit)
  1190. *
  1191. * Response:
  1192. * R1 [39:8] card status
  1193. *
  1194. * INPUTS
  1195. *
  1196. * addr : uint32_t address value.
  1197. * csr : Pointer to SD_R32 struct.
  1198. *
  1199. * OUTPUTS
  1200. *
  1201. * csr : SD_R32 struct which holds the R1 response.
  1202. * uint32_t : Returns HAL_SUCCESS if successful,
  1203. * else positive value is SDD-specific error code,
  1204. * else negative value is NU system error code.
  1205. *
  1206. ****************************************************************************/
  1207. #if (SDD_SMALL_SD_FOOTPRINT == 0)
  1208. uint32_t _sd_cmd30(uint32_t addr, SD_R32 * csr) {
  1209. uint32_t status = _sd_cmd_arg_r32 (SDC_CMD30_SEND_WRITE_PROT, addr, csr);
  1210. if (status != HAL_SUCCESS)
  1211. return status;
  1212. if (SD_CSR_CHECK_ERROR_BITS(*csr))
  1213. return SDD_CSR_ERROR;
  1214. return HAL_SUCCESS;
  1215. }
  1216. #endif /* (SDD_SMALL_SD_FOOTPRINT == 0) */
  1217. /*****************************************************************************
  1218. * FUNCTION
  1219. *
  1220. * _sd_cmd32
  1221. *
  1222. * DESCRIPTION
  1223. *
  1224. * This function issues SD command ERASE_WR_BLK_START: Sets the address of
  1225. * the first write block to be erased.
  1226. *
  1227. * Class: 5 (erase commands)
  1228. *
  1229. * State Transition:
  1230. * transfer -> transfer
  1231. *
  1232. * Argument:
  1233. * [31:0] data address (SD: byte unit, SDHC: block unit)
  1234. *
  1235. * Response:
  1236. * R1 [39:8] card status
  1237. *
  1238. * INPUTS
  1239. *
  1240. * addr : uint32_t address value.
  1241. * csr : Pointer to SD_R32 struct.
  1242. *
  1243. * OUTPUTS
  1244. *
  1245. * csr : SD_R32 struct which holds the R1 response.
  1246. * uint32_t : Returns HAL_SUCCESS if successful,
  1247. * else positive value is SDD-specific error code,
  1248. * else negative value is NU system error code.
  1249. *
  1250. ****************************************************************************/
  1251. #if (SDD_SMALL_SD_FOOTPRINT == 0)
  1252. uint32_t _sd_cmd32(uint32_t addr, SD_R32 * csr) {
  1253. uint32_t status = _sd_cmd_arg_r32 (SDC_CMD32_ERASE_WR_BLK_START, addr, csr);
  1254. if (status != HAL_SUCCESS)
  1255. return status;
  1256. if (SD_CSR_CHECK_ERROR_BITS(*csr))
  1257. return SDD_CSR_ERROR;
  1258. return HAL_SUCCESS;
  1259. }
  1260. #endif /* (SDD_SMALL_SD_FOOTPRINT == 0) */
  1261. /*****************************************************************************
  1262. * FUNCTION
  1263. *
  1264. * _sd_cmd33
  1265. *
  1266. * DESCRIPTION
  1267. *
  1268. * This function issues SD command ERASE_WR_BLK_END: Sets the address of
  1269. * the last write block of a continuous range to be erased.
  1270. *
  1271. * Class: 5 (erase commands)
  1272. *
  1273. * State Transition:
  1274. * transfer -> transfer
  1275. *
  1276. * Argument:
  1277. * [31:0] data address (SD: byte unit, SDHC: block unit)
  1278. *
  1279. * Response:
  1280. * R1 [39:8] card status
  1281. *
  1282. * INPUTS
  1283. *
  1284. * addr : uint32_t address value.
  1285. * csr : Pointer to SD_R32 struct.
  1286. *
  1287. * OUTPUTS
  1288. *
  1289. * csr : SD_R32 struct which holds the R1 response.
  1290. * uint32_t : Returns HAL_SUCCESS if successful,
  1291. * else positive value is SDD-specific error code,
  1292. * else negative value is NU system error code.
  1293. *
  1294. ****************************************************************************/
  1295. #if (SDD_SMALL_SD_FOOTPRINT == 0)
  1296. uint32_t _sd_cmd33(uint32_t addr, SD_R32 * csr) {
  1297. uint32_t status = _sd_cmd_arg_r32 (SDC_CMD33_ERASE_WR_BLK_END, addr, csr);
  1298. if (status != HAL_SUCCESS)
  1299. return status;
  1300. if (SD_CSR_CHECK_ERROR_BITS(*csr))
  1301. return SDD_CSR_ERROR;
  1302. return HAL_SUCCESS;
  1303. }
  1304. #endif /* (SDD_SMALL_SD_FOOTPRINT == 0) */
  1305. /*****************************************************************************
  1306. * FUNCTION
  1307. *
  1308. * _sd_cmd38
  1309. *
  1310. * DESCRIPTION
  1311. *
  1312. * This function issues SD command ERASE: Erase all previously selected
  1313. * write blocks.
  1314. *
  1315. * Class: 5 (erase commands)
  1316. *
  1317. * State Transition:
  1318. * transfer -> programming
  1319. *
  1320. * Argument:
  1321. * [31:0] stuff bits
  1322. *
  1323. * Response:
  1324. * R1 [39:8] card status
  1325. * DAT0 busy signal
  1326. *
  1327. * INPUTS
  1328. *
  1329. * addr : uint32_t address value.
  1330. * csr : Pointer to SD_R32 struct.
  1331. *
  1332. * OUTPUTS
  1333. *
  1334. * csr : SD_R32 struct which holds the R1 response.
  1335. * uint32_t : Returns HAL_SUCCESS if successful,
  1336. * else positive value is SDD-specific error code,
  1337. * else negative value is NU system error code.
  1338. *
  1339. ****************************************************************************/
  1340. #if (SDD_SMALL_SD_FOOTPRINT == 0)
  1341. uint32_t _sd_cmd38(SD_R32 * csr) {
  1342. uint32_t status = _sd_cmd_r32(SDC_CMD38_ERASE, csr);
  1343. if (status != HAL_SUCCESS)
  1344. return status;
  1345. if (SD_CSR_CHECK_ERROR_BITS(*csr))
  1346. return SDD_CSR_ERROR;
  1347. return HAL_SUCCESS;
  1348. }
  1349. #endif /* (SDD_SMALL_SD_FOOTPRINT == 0) */
  1350. /*****************************************************************************
  1351. * FUNCTION
  1352. *
  1353. * _sd_cmd42
  1354. *
  1355. * DESCRIPTION
  1356. *
  1357. * This function issues SD command LOCK_UNLOCK: Set/reset the password or
  1358. * lock/unlock the card.
  1359. *
  1360. * Class: 7 (lock card)
  1361. *
  1362. * State Transition:
  1363. * transfer -> receiving-data
  1364. *
  1365. * Argument:
  1366. * [31:0] should be all 0!
  1367. *
  1368. * Response:
  1369. * R1 [39:8] card status
  1370. *
  1371. * INPUTS
  1372. *
  1373. * csr : Pointer to SD_R32 struct.
  1374. *
  1375. * OUTPUTS
  1376. *
  1377. * csr : SD_R32 struct which holds the R1 response.
  1378. * uint32_t : Returns HAL_SUCCESS if successful,
  1379. * else positive value is SDD-specific error code,
  1380. * else negative value is NU system error code.
  1381. *
  1382. ****************************************************************************/
  1383. #if (SDD_SMALL_SD_FOOTPRINT == 0)
  1384. uint32_t _sd_cmd42(SD_R32 * csr) {
  1385. uint32_t status = _sd_cmd_arg_r32 (SDC_CMD42_LOCK_UNLOCK, 0, csr);
  1386. if (status != HAL_SUCCESS)
  1387. return status;
  1388. if (SD_CSR_CHECK_ERROR_BITS(*csr))
  1389. return SDD_CSR_ERROR;
  1390. return HAL_SUCCESS;
  1391. }
  1392. #endif /* (SDD_SMALL_SD_FOOTPRINT == 0) */
  1393. /*****************************************************************************
  1394. * FUNCTION
  1395. *
  1396. * _sd_cmd55
  1397. *
  1398. * DESCRIPTION
  1399. *
  1400. * This function issues SD command APP_CMD: Indicates the next command is
  1401. * an application specific command.
  1402. *
  1403. * Class: 8 (application-specific commands)
  1404. *
  1405. * State Transition:
  1406. * idle -> idle
  1407. * standby -> standby
  1408. * transfer -> transfer
  1409. * sending-data -> sending-data
  1410. * receiving-data -> receiving-data
  1411. * programming -> programming
  1412. * disconnected -> disconnected
  1413. *
  1414. * Argument:
  1415. * [31:16] RCA
  1416. *
  1417. * Response:
  1418. * R1 [39:8] card status
  1419. *
  1420. * INPUTS
  1421. *
  1422. * rca : uint32_t value where RCA is at [31:16].
  1423. * csr : Pointer to SD_R32 struct.
  1424. *
  1425. * OUTPUTS
  1426. *
  1427. * csr : SD_R32 struct which holds the R1 response.
  1428. * uint32_t : Returns HAL_SUCCESS if successful,
  1429. * else positive value is SDD-specific error code,
  1430. * else negative value is NU system error code.
  1431. *
  1432. ****************************************************************************/
  1433. uint32_t _sd_cmd55(uint32_t rca, SD_R32 * csr) {
  1434. uint32_t status = _sd_cmd_arg_r32(SDC_CMD55_APP_CMD, rca, csr);
  1435. if (status != HAL_SUCCESS)
  1436. return status;
  1437. if (SD_CSR_CHECK_ERROR_BITS(*csr))
  1438. return SDD_CSR_ERROR;
  1439. return HAL_SUCCESS;
  1440. }
  1441. /*****************************************************************************
  1442. * FUNCTION
  1443. *
  1444. * _sd_cmd56
  1445. *
  1446. * DESCRIPTION
  1447. *
  1448. * This function issues SD command GEN_CMD: To transfer data block from/to
  1449. * the card for general-purpose/application-specific commands.
  1450. *
  1451. * Class: 8 (application-specific commands)
  1452. *
  1453. * State Transition:
  1454. * RD/WR = 0 (write)
  1455. * transfer -> receiving-data
  1456. * RD/WR = 1 (read)
  1457. * transfer -> sending-data
  1458. *
  1459. * Argument:
  1460. * [31: 1] stuff bits
  1461. * [0] RD/WR
  1462. *
  1463. * Response:
  1464. * R1 [39:8] card status
  1465. *
  1466. * INPUTS
  1467. *
  1468. * rdwr : uint32_t value where bit [0] is RD/WR.
  1469. * csr : Pointer to SD_R32 struct.
  1470. *
  1471. * OUTPUTS
  1472. *
  1473. * csr : SD_R32 struct which holds the R1 response.
  1474. * uint32_t : Returns HAL_SUCCESS if successful,
  1475. * else positive value is SDD-specific error code,
  1476. * else negative value is NU system error code.
  1477. *
  1478. ****************************************************************************/
  1479. #if (SDD_SMALL_SD_FOOTPRINT == 0)
  1480. uint32_t _sd_cmd56(uint32_t rdwr, SD_R32 * csr) {
  1481. uint32_t status = _sd_cmd_arg_r32(SDC_CMD56_GEN_CMD, rdwr, csr);
  1482. if (status != HAL_SUCCESS)
  1483. return status;
  1484. if (SD_CSR_CHECK_ERROR_BITS(*csr))
  1485. return SDD_CSR_ERROR;
  1486. return HAL_SUCCESS;
  1487. }
  1488. #endif /* (SDD_SMALL_SD_FOOTPRINT == 0) */
  1489. /*****************************************************************************
  1490. * FUNCTION
  1491. *
  1492. * _sd_acmd6
  1493. *
  1494. * DESCRIPTION
  1495. *
  1496. * This function issues SD command SET_BUS_WIDTH: Defines the data bus
  1497. * width to be used for data transfer. The allowed bus widths are given
  1498. * in the SCR register.
  1499. *
  1500. * Class: 8 (application-specific commands)
  1501. *
  1502. * State Transition:
  1503. * transfer -> transfer
  1504. *
  1505. * Argument:
  1506. * [31:2] stuff bits
  1507. * [ 1:0] bus width (00b -> 1bit, 10b -> 4bits)
  1508. *
  1509. * Response:
  1510. * R1 [39:8] card status
  1511. *
  1512. * INPUTS
  1513. *
  1514. * bw : uint32_t value where bit [1:0] is bus width.
  1515. * csr : Pointer to SD_R32 struct.
  1516. *
  1517. * OUTPUTS
  1518. *
  1519. * csr : SD_R32 struct which holds the R1 response.
  1520. * uint32_t : Returns HAL_SUCCESS if successful,
  1521. * else positive value is SDD-specific error code,
  1522. * else negative value is NU system error code.
  1523. *
  1524. ****************************************************************************/
  1525. uint32_t _sd_acmd6(uint32_t bw, SD_R32 * csr) {
  1526. uint32_t status = _sd_cmd_arg_r32 (SDC_ACMD6_SET_BUS_WIDTH, bw, csr);
  1527. if (status != HAL_SUCCESS)
  1528. return status;
  1529. if (SD_CSR_CHECK_ERROR_BITS(*csr))
  1530. return SDD_CSR_ERROR;
  1531. return HAL_SUCCESS;
  1532. }
  1533. /*****************************************************************************
  1534. * FUNCTION
  1535. *
  1536. * _sd_acmd13
  1537. *
  1538. * DESCRIPTION
  1539. *
  1540. * This function issues SD command SD_STATUS: Send the SD status.
  1541. *
  1542. * Class: 8 (application-specific commands)
  1543. *
  1544. * State Transition:
  1545. * transfer -> sending-data
  1546. *
  1547. * Argument:
  1548. * [31:0] stuff bits
  1549. *
  1550. * Response:
  1551. * R1 [39:8] card status
  1552. *
  1553. * INPUTS
  1554. *
  1555. * csr : Pointer to SD_R32 struct.
  1556. *
  1557. * OUTPUTS
  1558. *
  1559. * csr : SD_R32 struct which holds the R1 response.
  1560. * uint32_t : Returns HAL_SUCCESS if successful,
  1561. * else positive value is SDD-specific error code,
  1562. * else negative value is NU system error code.
  1563. *
  1564. ****************************************************************************/
  1565. uint32_t _sd_acmd13(SD_R32 * csr) {
  1566. uint32_t status = _sd_cmd_r32(SDC_ACMD13_SD_STATUS, csr);
  1567. if (status != HAL_SUCCESS)
  1568. return status;
  1569. if (SD_CSR_CHECK_ERROR_BITS(*csr))
  1570. return SDD_CSR_ERROR;
  1571. return HAL_SUCCESS;
  1572. }
  1573. /*****************************************************************************
  1574. * FUNCTION
  1575. *
  1576. * _sd_acmd22
  1577. *
  1578. * DESCRIPTION
  1579. *
  1580. * This function issues SD command SEND_NUM_WR_BLOCKS: Send the number of
  1581. * non-error write blocks.
  1582. *
  1583. * If (WRITE_BL_PARTIAL == 0)
  1584. * unit of ACMD22 is 512 bytes
  1585. * else
  1586. * unit of ACMD22 is a block length of write command
  1587. *
  1588. * Class: 8 (application-specific commands)
  1589. *
  1590. * State Transition:
  1591. * transfer -> sending-data
  1592. *
  1593. * Argument:
  1594. * [31:0] stuff bits
  1595. *
  1596. * Response:
  1597. * R1 [39:8] card status
  1598. *
  1599. * INPUTS
  1600. *
  1601. * csr : Pointer to SD_R32 struct.
  1602. *
  1603. * OUTPUTS
  1604. *
  1605. * csr : SD_R32 struct which holds the R1 response.
  1606. * uint32_t : Returns HAL_SUCCESS if successful,
  1607. * else positive value is SDD-specific error code,
  1608. * else negative value is NU system error code.
  1609. *
  1610. ****************************************************************************/
  1611. #if (SDD_SMALL_SD_FOOTPRINT == 0)
  1612. uint32_t _sd_acmd22(SD_R32 * csr) {
  1613. uint32_t status = _sd_cmd_r32 (SDC_ACMD22_SEND_NUM_WR_BLOCKS, csr);
  1614. if (status != HAL_SUCCESS)
  1615. return status;
  1616. if (SD_CSR_CHECK_ERROR_BITS(*csr))
  1617. return SDD_CSR_ERROR;
  1618. return HAL_SUCCESS;
  1619. }
  1620. #endif /* (SDD_SMALL_SD_FOOTPRINT == 0) */
  1621. /*****************************************************************************
  1622. * FUNCTION
  1623. *
  1624. * _sd_acmd23
  1625. *
  1626. * DESCRIPTION
  1627. *
  1628. * This function issues SD command SET_WR_BLK_ERASE_COUNT: Send the number
  1629. * of write blocks to be pre-erased before writing (for faster multiple-
  1630. * block-WR command). Default is 1.
  1631. *
  1632. * Class: 8 (application-specific commands)
  1633. *
  1634. * State Transition:
  1635. * transfer -> transfer
  1636. *
  1637. * Argument:
  1638. * [31:23] stuff bits
  1639. * [22: 0] number of blocks
  1640. *
  1641. * Response:
  1642. * R1 [39:8] card status
  1643. *
  1644. * INPUTS
  1645. *
  1646. * blocks : uint32_t value represents the number of blocks.
  1647. * csr : Pointer to SD_R32 struct.
  1648. *
  1649. * OUTPUTS
  1650. *
  1651. * csr : SD_R32 struct which holds the R1 response.
  1652. * uint32_t : Returns HAL_SUCCESS if successful,
  1653. * else positive value is SDD-specific error code,
  1654. * else negative value is NU system error code.
  1655. *
  1656. ****************************************************************************/
  1657. #if (SDD_SMALL_SD_FOOTPRINT == 0)
  1658. uint32_t _sd_acmd23(uint32_t blocks, SD_R32 * csr) {
  1659. uint32_t status = _sd_cmd_arg_r32 (SDC_ACMD23_SET_WR_BLK_ERASE_COUNT, blocks, csr);
  1660. if (status != HAL_SUCCESS)
  1661. return status;
  1662. if (SD_CSR_CHECK_ERROR_BITS(*csr))
  1663. return SDD_CSR_ERROR;
  1664. return HAL_SUCCESS;
  1665. }
  1666. #endif /* (SDD_SMALL_SD_FOOTPRINT == 0) */
  1667. /*****************************************************************************
  1668. * FUNCTION
  1669. *
  1670. * _sd_acmd41
  1671. *
  1672. * DESCRIPTION
  1673. *
  1674. * This function issues SD command SD_SEND_OP_COND: Send HCS and get OCR
  1675. * during the initialization and identification process.
  1676. *
  1677. * Class: 8 (application-specific commands)
  1678. *
  1679. * State Transition:
  1680. * idle -> ready (OCR check OK and card is not busy)
  1681. * idle -> idle (OCR check OK and card is busy)
  1682. * idle -> inactive (OCR check fails)
  1683. * idle -> idle (query mode)
  1684. *
  1685. * Argument:
  1686. * [30] HCS (OCR[32])
  1687. * [23:0] Vdd voltage window (OCR[23:0])
  1688. *
  1689. * Response:
  1690. * R3 [39:8] OCR
  1691. *
  1692. * INPUTS
  1693. *
  1694. * hcs : uint32_t value represents the host capacity support information.
  1695. * ocr : Pointer to SD_OCR struct.
  1696. *
  1697. * OUTPUTS
  1698. *
  1699. * ocr : SD_OCR struct which holds the R3/OCR response.
  1700. * uint32_t : Returns HAL_SUCCESS if successful,
  1701. * else positive value is SDD-specific error code,
  1702. * else negative value is NU system error code.
  1703. *
  1704. ****************************************************************************/
  1705. uint32_t _sd_acmd41(uint32_t hcs, SD_OCR * ocr) {
  1706. return _sd_cmd_arg_r32 (SDC_ACMD41_SD_SEND_OP_COND, hcs, ocr);
  1707. }
  1708. /*****************************************************************************
  1709. * FUNCTION
  1710. *
  1711. * _sd_acmd42
  1712. *
  1713. * DESCRIPTION
  1714. *
  1715. * This function issues SD command SET_CLR_CARD_DETECT: Connect/Disconnect
  1716. * the 50 KOmh pull-up resister on CD/DAT3 (pin1) of the card.
  1717. *
  1718. * Class: 8 (application-specific commands)
  1719. *
  1720. * State Transition:
  1721. * transfer -> transfer
  1722. *
  1723. * Argument:
  1724. * [0] set_cd (1: connect, 0: disconnect)
  1725. *
  1726. * Response:
  1727. * R1 [39:8] card status
  1728. *
  1729. * INPUTS
  1730. *
  1731. * conn : uint32_t value where [0] denotes set_cd.
  1732. * csr : Pointer to SD_R32 struct.
  1733. *
  1734. * OUTPUTS
  1735. *
  1736. * csr : SD_R32 struct which holds the R1 response.
  1737. * uint32_t : Returns HAL_SUCCESS if successful,
  1738. * else positive value is SDD-specific error code,
  1739. * else negative value is NU system error code.
  1740. *
  1741. ****************************************************************************/
  1742. #if (SDD_SMALL_SD_FOOTPRINT == 0)
  1743. uint32_t _sd_acmd42(uint32_t conn, SD_R32 * csr) {
  1744. uint32_t status = _sd_cmd_arg_r32 (SDC_ACMD42_SET_CLR_CARD_DETECT, conn, csr);
  1745. if (status != HAL_SUCCESS)
  1746. return status;
  1747. if (SD_CSR_CHECK_ERROR_BITS(*csr))
  1748. return SDD_CSR_ERROR;
  1749. return HAL_SUCCESS;
  1750. }
  1751. #endif /* (SDD_SMALL_SD_FOOTPRINT == 0) */
  1752. /*****************************************************************************
  1753. * FUNCTION
  1754. *
  1755. * _sd_acmd51
  1756. *
  1757. * DESCRIPTION
  1758. *
  1759. * This function issues SD command SEND_SCR: Reads the SD configuration
  1760. * register (SCR).
  1761. *
  1762. * Class: 8 (application-specific commands)
  1763. *
  1764. * State Transition:
  1765. * transfer -> sending-data
  1766. *
  1767. * Argument:
  1768. * [31:0] stuff bits
  1769. *
  1770. * Response:
  1771. * R1 [39:8] card status
  1772. *
  1773. * INPUTS
  1774. *
  1775. * csr : Pointer to SD_R32 struct.
  1776. *
  1777. * OUTPUTS
  1778. *
  1779. * csr : SD_R32 struct which holds the R1 response.
  1780. * uint32_t : Returns HAL_SUCCESS if successful,
  1781. * else positive value is SDD-specific error code,
  1782. * else negative value is NU system error code.
  1783. *
  1784. ****************************************************************************/
  1785. uint32_t _sd_acmd51(SD_R32 * csr) {
  1786. uint32_t status = _sd_cmd_r32(SDC_ACMD51_SEND_SCR, csr);
  1787. if (status != HAL_SUCCESS)
  1788. return status;
  1789. if (SD_CSR_CHECK_ERROR_BITS(*csr))
  1790. return SDD_CSR_ERROR;
  1791. return HAL_SUCCESS;
  1792. }
  1793. /*****************************************************************************
  1794. * FUNCTION
  1795. *
  1796. * _sd_cmd6
  1797. *
  1798. * DESCRIPTION
  1799. *
  1800. * This function issues SD command SWITCH_FUNC: Check switchable function
  1801. * or switch card function.
  1802. *
  1803. * Class: 8 (application-specific commands)
  1804. *
  1805. * State Transition:
  1806. * transfer -> sending-data
  1807. *
  1808. * Argument:
  1809. * [31] mode (0: check, 1: switch)
  1810. * [30:24] should be 0
  1811. * [23:20] 00h or 0fh (reserved for function group 6)
  1812. * [19:16] 00h or 0fh (reserved for function group 5)
  1813. * [15:12] 00h or 0fh (reserved for function group 4)
  1814. * [11: 8] 00h or 0fh (reserved for function group 3)
  1815. * [ 7: 4] function group 2 for command system
  1816. * [ 3: 0] function group 1 for access mode
  1817. *
  1818. * Response:
  1819. * R1 [39:8] card status
  1820. *
  1821. * INPUTS
  1822. *
  1823. * mode : uint32_t value which holds the function mode.
  1824. * csr : Pointer to SD_R32 struct.
  1825. *
  1826. * OUTPUTS
  1827. *
  1828. * csr : SD_R32 struct which holds the R1 response.
  1829. * uint32_t : Returns HAL_SUCCESS if successful,
  1830. * else positive value is SDD-specific error code,
  1831. * else negative value is NU system error code.
  1832. *
  1833. ****************************************************************************/
  1834. #if (SDD_SMALL_SD_FOOTPRINT == 0)
  1835. uint32_t _sd_cmd6(uint32_t mode, SD_R32 * csr) {
  1836. uint32_t status = _sd_cmd_arg_r32 (SDC_CMD6_SWITCH_FUNC, mode, csr);
  1837. if (status != HAL_SUCCESS)
  1838. return status;
  1839. if (SD_CSR_CHECK_ERROR_BITS(*csr))
  1840. return SDD_CSR_ERROR;
  1841. return HAL_SUCCESS;
  1842. }
  1843. #endif /* (SDD_SMALL_SD_FOOTPRINT == 0) */
  1844. #if 0
  1845. /*****************************************************************************
  1846. * FUNCTION
  1847. *
  1848. * _sd_wait_sending_state
  1849. *
  1850. * DESCRIPTION
  1851. *
  1852. * This function waits the transfer state make transition to the sending-
  1853. * data state. This is equivalent to waiting for the card start to send
  1854. * out data after cmd17 or cmd18.
  1855. *
  1856. * INPUTS
  1857. *
  1858. * rca : uint32_t value where RCA is at [31:16].
  1859. *
  1860. * OUTPUTS
  1861. *
  1862. * uint32_t : Returns HAL_SUCCESS if successful,
  1863. * else positive value is SDD-specific error code,
  1864. * else negative value is NU system error code.
  1865. *
  1866. ****************************************************************************/
  1867. uint32_t _sd_wait_sending_state(uint32_t rca) {
  1868. uint32_t status;
  1869. SD_R32 sd_rsp32;
  1870. uint32_t retry = 0;
  1871. while (retry++ <
  1872. SD_TRANSFER_MAX_RETRY_COUNT) {
  1873. /* Get current state */
  1874. status =
  1875. _sd_cmd13(rca, &sd_rsp32);
  1876. if (status != HAL_SUCCESS)
  1877. return status;
  1878. switch (SD_CSR_GET_CURRENT_STATE
  1879. (sd_rsp32)) {
  1880. case SD_STATE_DATA:
  1881. return HAL_SUCCESS;
  1882. case SD_STATE_TRAN:
  1883. break;
  1884. case SD_STATE_IDLE:
  1885. case SD_STATE_READY:
  1886. case SD_STATE_IDENT:
  1887. case SD_STATE_STBY:
  1888. case SD_STATE_RCV:
  1889. case SD_STATE_DIS:
  1890. case SD_STATE_PRG:
  1891. default:
  1892. return
  1893. SDD_INVALID_STATE;
  1894. }
  1895. }
  1896. return SDD_WAIT_TIMEOUT;
  1897. }
  1898. /*****************************************************************************
  1899. * FUNCTION
  1900. *
  1901. * _sd_wait_receiving_state
  1902. *
  1903. * DESCRIPTION
  1904. *
  1905. * This function waits the transfer state make transition to the receiving-
  1906. * data state. This is equivalent to waiting for the card start to receive
  1907. * data after cmd24/25/27/42/56.
  1908. *
  1909. * INPUTS
  1910. *
  1911. * rca : uint32_t value where RCA is at [31:16].
  1912. *
  1913. * OUTPUTS
  1914. *
  1915. * uint32_t : Returns HAL_SUCCESS if successful,
  1916. * else positive value is SDD-specific error code,
  1917. * else negative value is NU system error code.
  1918. *
  1919. ****************************************************************************/
  1920. uint32_t _sd_wait_receiving_state(uint32_t rca) {
  1921. uint32_t status;
  1922. SD_R32 sd_rsp32;
  1923. uint32_t retry = 0;
  1924. while (retry++ <
  1925. SD_TRANSFER_MAX_RETRY_COUNT) {
  1926. /* Get current state */
  1927. status =
  1928. _sd_cmd13(rca, &sd_rsp32);
  1929. if (status != HAL_SUCCESS)
  1930. return status;
  1931. switch (SD_CSR_GET_CURRENT_STATE
  1932. (sd_rsp32)) {
  1933. case SD_STATE_RCV:
  1934. if (SD_CSR_GET_READY_FOR_DATA(sd_rsp32))
  1935. return
  1936. HAL_SUCCESS;
  1937. break;
  1938. case SD_STATE_TRAN:
  1939. break;
  1940. case SD_STATE_IDLE:
  1941. case SD_STATE_READY:
  1942. case SD_STATE_IDENT:
  1943. case SD_STATE_STBY:
  1944. case SD_STATE_DATA:
  1945. case SD_STATE_DIS:
  1946. case SD_STATE_PRG:
  1947. default:
  1948. return
  1949. SDD_INVALID_STATE;
  1950. }
  1951. }
  1952. return SDD_WAIT_TIMEOUT;
  1953. }
  1954. #endif /* 0 */
  1955. /*****************************************************************************
  1956. * FUNCTION
  1957. *
  1958. * _sd_wait_programmed
  1959. *
  1960. * DESCRIPTION
  1961. *
  1962. * This function waits the disconnected state make transition to the
  1963. * standby state or the transfer state. This is equivalent to waiting for
  1964. * the completion of programming.
  1965. *
  1966. * INPUTS
  1967. *
  1968. * rca : uint32_t value where RCA is at [31:16].
  1969. *
  1970. * OUTPUTS
  1971. *
  1972. * uint32_t : Returns HAL_SUCCESS if successful,
  1973. * else positive value is SDD-specific error code,
  1974. * else negative value is NU system error code.
  1975. *
  1976. ****************************************************************************/
  1977. uint32_t _sd_wait_programmed(uint32_t rca) {
  1978. uint32_t status;
  1979. SD_R32 sd_rsp32;
  1980. uint32_t retry = 0;
  1981. while (retry++ < SD_TRANSFER_MAX_RETRY_COUNT) {
  1982. /* Get current state */
  1983. status = _sd_cmd13(rca, &sd_rsp32);
  1984. if (status != HAL_SUCCESS)
  1985. return status;
  1986. switch (SD_CSR_GET_CURRENT_STATE
  1987. (sd_rsp32)) {
  1988. case SD_STATE_STBY:
  1989. case SD_STATE_TRAN:
  1990. return HAL_SUCCESS;
  1991. case SD_STATE_DIS:
  1992. case SD_STATE_PRG:
  1993. break;
  1994. case SD_STATE_IDLE:
  1995. case SD_STATE_READY:
  1996. case SD_STATE_IDENT:
  1997. case SD_STATE_DATA:
  1998. case SD_STATE_RCV:
  1999. default:
  2000. return
  2001. SDD_INVALID_STATE;
  2002. }
  2003. }
  2004. return SDD_WAIT_TIMEOUT;
  2005. }
  2006. /*****************************************************************************
  2007. * FUNCTION
  2008. *
  2009. * _sd_wait_transferred
  2010. *
  2011. * DESCRIPTION
  2012. *
  2013. * This function waits the data/rcv/prog state make transition to the
  2014. * transfer state. This is equivalent to waiting for the
  2015. * completion of all current data transfer traffic.
  2016. *
  2017. * INPUTS
  2018. *
  2019. * rca : uint32_t value where RCA is at [31:16].
  2020. *
  2021. * OUTPUTS
  2022. *
  2023. * uint32_t : Returns HAL_SUCCESS if successful,
  2024. * else positive value is SDD-specific error code,
  2025. * else negative value is NU system error code.
  2026. *
  2027. ****************************************************************************/
  2028. uint32_t _sd_wait_transferred(uint32_t rca) {
  2029. uint32_t status;
  2030. SD_R32 sd_rsp32;
  2031. uint32_t retry = 0;
  2032. while (retry++ < SD_TRANSFER_MAX_RETRY_COUNT) {
  2033. /* Get current state */
  2034. status = _sd_cmd13(rca, &sd_rsp32);
  2035. if (status != HAL_SUCCESS)
  2036. return status;
  2037. switch (SD_CSR_GET_CURRENT_STATE (sd_rsp32)) {
  2038. case SD_STATE_TRAN:
  2039. return HAL_SUCCESS;
  2040. case SD_STATE_DATA:
  2041. case SD_STATE_RCV:
  2042. case SD_STATE_PRG:
  2043. break;
  2044. case SD_STATE_IDLE:
  2045. case SD_STATE_READY:
  2046. case SD_STATE_IDENT:
  2047. case SD_STATE_STBY:
  2048. case SD_STATE_DIS:
  2049. default:
  2050. return
  2051. SDD_INVALID_STATE;
  2052. }
  2053. }
  2054. return SDD_WAIT_TIMEOUT;
  2055. }
  2056. /*****************************************************************************
  2057. * FUNCTION
  2058. *
  2059. * _sd_disconnect
  2060. *
  2061. * DESCRIPTION
  2062. *
  2063. * This function forces the prog state make transition to the
  2064. * disconnect state.
  2065. *
  2066. * INPUTS
  2067. *
  2068. * rca : uint32_t value where RCA is at [31:16].
  2069. *
  2070. * OUTPUTS
  2071. *
  2072. * uint32_t : Returns HAL_SUCCESS if successful,
  2073. * else positive value is SDD-specific error code,
  2074. * else negative value is NU system error code.
  2075. *
  2076. ****************************************************************************/
  2077. uint32_t _sd_disconnect(uint32_t rca) {
  2078. uint32_t status;
  2079. SD_R32 sd_rsp32;
  2080. uint32_t retry = 0;
  2081. while (retry++ < SD_STATE_MAX_RETRY_COUNT) {
  2082. /* Get current state */
  2083. status = _sd_cmd13(rca, &sd_rsp32);
  2084. if (status != HAL_SUCCESS)
  2085. return status;
  2086. /* Perform state transition according to spec 2.0 fig 4-3. */
  2087. switch (SD_CSR_GET_CURRENT_STATE (sd_rsp32)) {
  2088. case SD_STATE_STBY:
  2089. case SD_STATE_DIS:
  2090. /* The card with the target rca is already disconnected. Just */
  2091. /* return that the card is disconnected successfully. */
  2092. return HAL_SUCCESS;
  2093. case SD_STATE_PRG:
  2094. /* Try to enter disconnected state ... */
  2095. status = _sd_cmd7(rca, &sd_rsp32); /* disconnect the card */
  2096. if (status != HAL_SUCCESS)
  2097. return status;
  2098. break;
  2099. case SD_STATE_TRAN:
  2100. case SD_STATE_DATA:
  2101. case SD_STATE_RCV:
  2102. case SD_STATE_IDLE:
  2103. case SD_STATE_READY:
  2104. case SD_STATE_IDENT:
  2105. default:
  2106. /* Invalid current state before disconnect the card. */
  2107. return
  2108. SDD_INVALID_STATE;
  2109. }
  2110. }
  2111. return SDD_WAIT_TIMEOUT;
  2112. }
  2113. /*****************************************************************************
  2114. * FUNCTION
  2115. *
  2116. * _sd_connect
  2117. *
  2118. * DESCRIPTION
  2119. *
  2120. * This function forces the disconnect state make transition to the
  2121. * programming state.
  2122. *
  2123. * INPUTS
  2124. *
  2125. * rca : uint32_t value where RCA is at [31:16].
  2126. *
  2127. * OUTPUTS
  2128. *
  2129. * uint32_t : Returns HAL_SUCCESS if successful,
  2130. * else positive value is SDD-specific error code,
  2131. * else negative value is NU system error code.
  2132. *
  2133. ****************************************************************************/
  2134. uint32_t _sd_connect(uint32_t rca) {
  2135. uint32_t status;
  2136. SD_R32 sd_rsp32;
  2137. uint32_t retry = 0;
  2138. while (retry++ < SD_STATE_MAX_RETRY_COUNT) {
  2139. /* Get current state */
  2140. status = _sd_cmd13(rca, &sd_rsp32);
  2141. if (status != HAL_SUCCESS)
  2142. return status;
  2143. /* Perform state transition according to spec 2.0 fig 4-3. */
  2144. switch (SD_CSR_GET_CURRENT_STATE (sd_rsp32)) {
  2145. case SD_STATE_PRG:
  2146. case SD_STATE_TRAN:
  2147. /*
  2148. * The card with the target rca is already connected. Just
  2149. * return that the card is connected successfully.
  2150. */
  2151. return HAL_SUCCESS;
  2152. case SD_STATE_DIS:
  2153. /* Try to enter programming state ... */
  2154. status = _sd_cmd7(rca, &sd_rsp32); /* connect the card */
  2155. if (status != HAL_SUCCESS)
  2156. return status;
  2157. break;
  2158. case SD_STATE_STBY:
  2159. case SD_STATE_DATA:
  2160. case SD_STATE_RCV:
  2161. case SD_STATE_IDLE:
  2162. case SD_STATE_READY:
  2163. case SD_STATE_IDENT:
  2164. default:
  2165. /* Invalid current state before connect the card. */
  2166. return
  2167. SDD_INVALID_STATE;
  2168. }
  2169. }
  2170. return SDD_WAIT_TIMEOUT;
  2171. }
  2172. /*****************************************************************************
  2173. * FUNCTION
  2174. *
  2175. * _sd_deselect_card
  2176. *
  2177. * DESCRIPTION
  2178. *
  2179. * This function forces the transfer state make transition to the
  2180. * standby state.
  2181. *
  2182. * If the card is currently in data or transfer state, the function will
  2183. * issue trnasition command and continue loop until the card enters standby
  2184. * state.
  2185. *
  2186. * INPUTS
  2187. *
  2188. * rca : uint32_t value where RCA is at [31:16].
  2189. *
  2190. * OUTPUTS
  2191. *
  2192. * uint32_t : Returns HAL_SUCCESS if successful,
  2193. * else positive value is SDD-specific error code,
  2194. * else negative value is NU system error code.
  2195. *
  2196. ****************************************************************************/
  2197. uint32_t _sd_deselect_card(uint32_t rca) {
  2198. uint32_t status;
  2199. SD_R32 sd_rsp32;
  2200. uint32_t retry = 0;
  2201. while (retry++ < SD_STATE_MAX_RETRY_COUNT) {
  2202. /* Get current state */
  2203. status = _sd_cmd13(rca, &sd_rsp32);
  2204. if (status != HAL_SUCCESS)
  2205. return status;
  2206. /* Perform state transition according to spec 2.0 fig 4-3. */
  2207. switch (SD_CSR_GET_CURRENT_STATE (sd_rsp32)) {
  2208. case SD_STATE_STBY:
  2209. /*
  2210. * The card with the target rca is already deselected. Just
  2211. * return that the card is deselected successfully.
  2212. */
  2213. return HAL_SUCCESS;
  2214. case SD_STATE_TRAN:
  2215. case SD_STATE_DATA:
  2216. /* Try to enter standby state ... */
  2217. status = _sd_cmd7(rca, &sd_rsp32); /* deselect the card */
  2218. if (status != HAL_SUCCESS)
  2219. return status;
  2220. break;
  2221. case SD_STATE_RCV:
  2222. case SD_STATE_PRG:
  2223. case SD_STATE_IDLE:
  2224. case SD_STATE_READY:
  2225. case SD_STATE_IDENT:
  2226. case SD_STATE_DIS:
  2227. default:
  2228. /* Invalid current state before deselecting the card. */
  2229. return
  2230. SDD_INVALID_STATE;
  2231. }
  2232. }
  2233. return SDD_WAIT_TIMEOUT;
  2234. }
  2235. /*****************************************************************************
  2236. * FUNCTION
  2237. *
  2238. * _sd_select_card
  2239. *
  2240. * DESCRIPTION
  2241. *
  2242. * This function forces the standby state make transition to the
  2243. * transfer state.
  2244. *
  2245. * If the card is currently in data/rcv state, the function will wait for
  2246. * a limitted time. After timeout, it forces to stop the current
  2247. * operation and try to make transition back to standby state.
  2248. *
  2249. * If the card is currently in the prog state, the function will wait for
  2250. * a limitted time. If timeout then it will return that failed to make
  2251. * the desired state transition.
  2252. *
  2253. * INPUTS
  2254. *
  2255. * rca : uint32_t value where RCA is at [31:16].
  2256. *
  2257. * OUTPUTS
  2258. *
  2259. * uint32_t : Returns HAL_SUCCESS if successful,
  2260. * else positive value is SDD-specific error code,
  2261. * else negative value is NU system error code.
  2262. *
  2263. ****************************************************************************/
  2264. uint32_t _sd_select_card(uint32_t rca) {
  2265. uint32_t status;
  2266. SD_R32 sd_rsp32;
  2267. uint32_t retry = 0;
  2268. while (retry++ < SD_STATE_MAX_RETRY_COUNT) {
  2269. /* Get current state */
  2270. status = _sd_cmd13(rca, &sd_rsp32);
  2271. if (status != HAL_SUCCESS)
  2272. return status;
  2273. /* Perform state transition according to spec 2.0 fig 4-3. */
  2274. switch (SD_CSR_GET_CURRENT_STATE (sd_rsp32)) {
  2275. case SD_STATE_TRAN:
  2276. /*
  2277. * The card with the target rca is already selected. Just
  2278. * return that the card is selected successfully.
  2279. */
  2280. return HAL_SUCCESS;
  2281. case SD_STATE_STBY:
  2282. /* Try to enter transfer state ... */
  2283. status = _sd_cmd7(rca, &sd_rsp32); /* select the card */
  2284. if (status != HAL_SUCCESS)
  2285. return status;
  2286. break;
  2287. case SD_STATE_DATA:
  2288. case SD_STATE_RCV:
  2289. /*
  2290. * The card is still transferring data or programming.
  2291. * Wait a short period for transfer completion. The
  2292. * card will back to transfer state after operation
  2293. * completion.
  2294. */
  2295. status = _sd_wait_transferred (rca);
  2296. if (status == HAL_SUCCESS) {
  2297. return HAL_SUCCESS;
  2298. }
  2299. else if (status == SDD_WAIT_TIMEOUT)
  2300. {
  2301. /*
  2302. * Stop the current transmission after waiting timeout. Then
  2303. * continue status check loop to fall back to transfer state.
  2304. */
  2305. status = _sd_cmd12(&sd_rsp32); /* stop transmission */
  2306. if (status != HAL_SUCCESS)
  2307. return status;
  2308. }
  2309. else {
  2310. return status;
  2311. }
  2312. break;
  2313. case SD_STATE_PRG:
  2314. status = _sd_wait_transferred (rca);
  2315. if (status != HAL_SUCCESS)
  2316. return status;
  2317. break;
  2318. case SD_STATE_DIS:
  2319. /* Continue status check loop to fall back to standby state. */
  2320. break;
  2321. case SD_STATE_IDLE:
  2322. case SD_STATE_READY:
  2323. case SD_STATE_IDENT:
  2324. default:
  2325. /* Invalid current state before selecting the card. */
  2326. return SDD_INVALID_STATE;
  2327. }
  2328. }
  2329. return SDD_WAIT_TIMEOUT;
  2330. }
  2331. /*****************************************************************************
  2332. * FUNCTION
  2333. *
  2334. * _sd_stop_transmission
  2335. *
  2336. * DESCRIPTION
  2337. *
  2338. * This function forces the data/rcv/prog state make transition to the
  2339. * transfer state.
  2340. *
  2341. * If the card is currently in data/rcv state, the function will issue
  2342. * stop command directly. Then continue check loop to wait for back to
  2343. * the transfer or standby state.
  2344. *
  2345. * If the card is currently in the prog state, the function will wait for
  2346. * a limitted time. If timeout then it will return that failed to make
  2347. * the desired state transition.
  2348. *
  2349. * INPUTS
  2350. *
  2351. * rca : uint32_t value where RCA is at [31:16].
  2352. *
  2353. * OUTPUTS
  2354. *
  2355. * uint32_t : Returns HAL_SUCCESS if successful,
  2356. * else positive value is SDD-specific error code,
  2357. * else negative value is NU system error code.
  2358. *
  2359. ****************************************************************************/
  2360. uint32_t _sd_stop_transmission(uint32_t rca) {
  2361. uint32_t status;
  2362. SD_R32 sd_rsp32;
  2363. while (1) {
  2364. // _nds_kwait(0x1000);
  2365. /* Get current state */
  2366. status = _sd_cmd13(rca, &sd_rsp32);
  2367. if (status != HAL_SUCCESS)
  2368. return status;
  2369. /* Perform state transition according to spec 2.0 fig 4-3. */
  2370. switch (SD_CSR_GET_CURRENT_STATE (sd_rsp32)) {
  2371. case SD_STATE_STBY:
  2372. case SD_STATE_TRAN:
  2373. /* The card with the target rca is already stopped. Just */
  2374. /* return that the card is stopped successfully. */
  2375. return HAL_SUCCESS;
  2376. case SD_STATE_DATA:
  2377. case SD_STATE_RCV:
  2378. /* Try to back to transfer state ... */
  2379. status = _sd_cmd12(&sd_rsp32); /* stop transmission */
  2380. if (status != HAL_SUCCESS)
  2381. return status;
  2382. break;
  2383. case SD_STATE_PRG:
  2384. /* The card is still transferring data or programming. */
  2385. /* Wait a short period for transfer completion. The */
  2386. /* card will back to transfer state after operation */
  2387. /* completion. */
  2388. status = _sd_wait_transferred (rca);
  2389. if (status != HAL_SUCCESS)
  2390. return status;
  2391. break;
  2392. case SD_STATE_IDLE:
  2393. case SD_STATE_READY:
  2394. case SD_STATE_IDENT:
  2395. case SD_STATE_DIS:
  2396. default:
  2397. /* Invalid current state before selecting the card. */
  2398. return SDD_INVALID_STATE;
  2399. }
  2400. }
  2401. return SDD_WAIT_TIMEOUT;
  2402. }