sd.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #ifndef __SD_H__
  2. #define __SD_H__
  3. #include <stdint.h>
  4. /* SD/MMC Commands */
  5. #define GO_IDLE_STATE (0x40 + 0) // CMD0
  6. #define SEND_OP_COND (0x40 + 1)
  7. #define CMD8 (0x40 + 8) // CMD8
  8. #define SEND_CSD (0x40 + 9)
  9. #define SEND_CID (0x40 + 10) // CMD10
  10. #define STOP_TRAN (0x40 + 12) // CMD12
  11. #define SET_BLOCKLEN (0x40 + 16) // CMD16
  12. #define READ_BLOCK (0x40 + 17)
  13. #define READ_MULT_BLOCK (0x40 + 18)
  14. #define WRITE_BLOCK (0x40 + 24)
  15. #define WRITE_MULT_BLOCK (0x40 + 25)
  16. #define APP_CMD (0x40 + 55) // CMD55
  17. #define READ_OCR (0x40 + 58) // CMD58
  18. #define CRC_ON_OFF (0x40 + 59)
  19. #define SD_SEND_OP_COND (0xC0 + 41) // ACMD41
  20. #define SD_STATUS (0xC0 + 13) // ACMD13, SD_STATUS (SDC)
  21. #define SET_WR_BLK_ERASE_COUNT (0xC0 + 23) // ACMD23 (SDC)
  22. /* Card type flags (CardType) */
  23. #define CT_NONE 0x00
  24. #define CT_MMC 0x01
  25. #define CT_SD1 0x02
  26. #define CT_SD2 0x04
  27. #define CT_SDC (CT_SD1|CT_SD2)
  28. #define CT_BLOCK 0x08
  29. /* MMC device configuration */
  30. typedef struct tagSDCFG
  31. {
  32. uint32_t sernum; // serial number
  33. uint32_t size; // size=sectorsize*sectorcnt
  34. uint32_t sectorcnt; //
  35. uint32_t sectorsize; // 512
  36. uint32_t blocksize; // erase block size
  37. uint8_t ocr[4]; // OCR
  38. uint8_t cid[16]; // CID
  39. uint8_t csd[16]; // CSD
  40. } SDCFG;
  41. void rt_hw_sdcard_init(void);
  42. #endif