dev_sdhc_spi.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #ifndef __DEV_SDHC_SPI_H__
  2. #define __DEV_SDHC_SPI_H__
  3. #define __SDHC_BLOCK_LEN__ (512)
  4. typedef struct
  5. {
  6. uint8_t Reserved1:2; /* Reserved */
  7. uint16_t DeviceSize:12; /* Device Size */
  8. uint8_t MaxRdCurrentVDDMin:3; /* Max. read current @ VDD min */
  9. uint8_t MaxRdCurrentVDDMax:3; /* Max. read current @ VDD max */
  10. uint8_t MaxWrCurrentVDDMin:3; /* Max. write current @ VDD min */
  11. uint8_t MaxWrCurrentVDDMax:3; /* Max. write current @ VDD max */
  12. uint8_t DeviceSizeMul:3; /* Device size multiplier */
  13. } struct_v1;
  14. typedef struct
  15. {
  16. uint8_t Reserved1:6; /* Reserved */
  17. uint32_t DeviceSize:22; /* Device Size */
  18. uint8_t Reserved2:1; /* Reserved */
  19. } struct_v2;
  20. /**
  21. * @brief Card Specific Data: CSD Register
  22. */
  23. typedef struct
  24. {
  25. /* Header part */
  26. uint8_t CSDStruct:2; /* CSD structure */
  27. uint8_t Reserved1:6; /* Reserved */
  28. uint8_t TAAC:8; /* Data read access-time 1 */
  29. uint8_t NSAC:8; /* Data read access-time 2 in CLK cycles */
  30. uint8_t MaxBusClkFrec:8; /* Max. bus clock frequency */
  31. uint16_t CardComdClasses:12; /* Card command classes */
  32. uint8_t RdBlockLen:4; /* Max. read data block length */
  33. uint8_t PartBlockRead:1; /* Partial blocks for read allowed */
  34. uint8_t WrBlockMisalign:1; /* Write block misalignment */
  35. uint8_t RdBlockMisalign:1; /* Read block misalignment */
  36. uint8_t DSRImpl:1; /* DSR implemented */
  37. /* v1 or v2 struct */
  38. union csd_version {
  39. struct_v1 v1;
  40. struct_v2 v2;
  41. } version;
  42. uint8_t EraseSingleBlockEnable:1; /* Erase single block enable */
  43. uint8_t EraseSectorSize:7; /* Erase group size multiplier */
  44. uint8_t WrProtectGrSize:7; /* Write protect group size */
  45. uint8_t WrProtectGrEnable:1; /* Write protect group enable */
  46. uint8_t Reserved2:2; /* Reserved */
  47. uint8_t WrSpeedFact:3; /* Write speed factor */
  48. uint8_t MaxWrBlockLen:4; /* Max. write data block length */
  49. uint8_t WriteBlockPartial:1; /* Partial blocks for write allowed */
  50. uint8_t Reserved3:5; /* Reserved */
  51. uint8_t FileFormatGrouop:1; /* File format group */
  52. uint8_t CopyFlag:1; /* Copy flag (OTP) */
  53. uint8_t PermWrProtect:1; /* Permanent write protection */
  54. uint8_t TempWrProtect:1; /* Temporary write protection */
  55. uint8_t FileFormat:2; /* File Format */
  56. uint8_t Reserved4:2; /* Reserved */
  57. uint8_t crc:7; /* Reserved */
  58. uint8_t Reserved5:1; /* always 1*/
  59. } SD_CSD;
  60. /**
  61. * @brief Card Identification Data: CID Register
  62. */
  63. typedef struct
  64. {
  65. __IO uint8_t ManufacturerID; /* ManufacturerID */
  66. __IO uint16_t OEM_AppliID; /* OEM/Application ID */
  67. __IO uint32_t ProdName1; /* Product Name part1 */
  68. __IO uint8_t ProdName2; /* Product Name part2*/
  69. __IO uint8_t ProdRev; /* Product Revision */
  70. __IO uint32_t ProdSN; /* Product Serial Number */
  71. __IO uint8_t Reserved1; /* Reserved1 */
  72. __IO uint16_t ManufactDate; /* Manufacturing Date */
  73. __IO uint8_t CID_CRC; /* CID CRC */
  74. __IO uint8_t Reserved2; /* always 1 */
  75. } SD_CID;
  76. /**
  77. * @brief SD Card information
  78. */
  79. typedef struct
  80. {
  81. SD_CSD Csd;
  82. SD_CID Cid;
  83. uint64_t CardCapacity; /*!< Card Capacity */
  84. uint32_t LogBlockNbr; /*!< Specifies the Card logical Capacity in blocks */
  85. uint32_t CardBlockSize; /*!< Card Block Size */
  86. uint32_t LogBlockSize; /*!< Specifies logical block size in bytes */
  87. } SD_CardInfo;
  88. typedef struct
  89. {
  90. SD_CardInfo Info;
  91. uint64_t SDHCReadBlockTo;
  92. uint64_t SDHCWriteBlockTo;
  93. Buffer_Struct DataBuf;
  94. Buffer_Struct CacheBuf;
  95. HANDLE NotifyTask; //设置了NotifyTask,则会在大量传输SPI数据时,休眠任务但是仍然能接收Event并在CB中处理
  96. CBFuncEx_t TaskCB;
  97. uint32_t Size; //flash的大小KB
  98. uint32_t OCR;
  99. DBuffer_Struct *SCSIDataBuf;
  100. uint32_t PreCurBlock;
  101. uint32_t PreEndBlock;
  102. uint32_t CurBlock;
  103. uint32_t EndBlock;
  104. uint32_t SpiSpeed;
  105. uint16_t WriteWaitCnt;
  106. uint8_t CSPin;
  107. uint8_t SpiID;
  108. uint8_t IsSpiDMAMode;
  109. uint8_t SDHCState;
  110. uint8_t IsInitDone;
  111. uint8_t IsCRCCheck;
  112. uint8_t SDHCError;
  113. uint8_t SPIError;
  114. uint8_t ExternResult[8];
  115. uint8_t ExternLen;
  116. uint8_t TempData[__SDHC_BLOCK_LEN__ + 8];
  117. uint8_t SDSC;
  118. uint8_t USBDelayTime;
  119. uint8_t WaitFree;
  120. }SDHC_SPICtrlStruct;
  121. void SDHC_SpiInitCard(void *pSDHC);
  122. void SDHC_SpiReadCardConfig(void *pSDHC);
  123. void SDHC_SpiReadCardInfo(void *pSDHC);
  124. void SDHC_SpiWriteBlocks(void *pSDHC, const uint8_t *Buf, uint32_t StartLBA, uint32_t BlockNums);
  125. void SDHC_SpiReadBlocks(void *pSDHC, uint8_t *Buf, uint32_t StartLBA, uint32_t BlockNums);
  126. void *SDHC_SpiCreate(uint8_t SpiID, uint8_t CSPin);
  127. void SDHC_SpiRelease(void *pSDHC);
  128. uint8_t SDHC_IsReady(void *pSDHC);
  129. uint32_t SDHC_GetLogBlockNbr(void *pSDHC);
  130. #endif