sd.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright (C) 2013 Michael McMaster <michael@codesrc.com>
  2. //
  3. // This file is part of SCSI2SD.
  4. //
  5. // SCSI2SD is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // SCSI2SD is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with SCSI2SD. If not, see <http://www.gnu.org/licenses/>.
  17. #ifndef S2S_SD_H
  18. #define S2S_SD_H
  19. #include <stdint.h>
  20. #define SD_SECTOR_SIZE 512
  21. /*
  22. typedef enum
  23. {
  24. SD_GO_IDLE_STATE = 0,
  25. SD_SEND_OP_COND = 1,
  26. SD_SEND_IF_COND = 8, // SD V2
  27. SD_SEND_CSD = 9,
  28. SD_SEND_CID = 10,
  29. SD_STOP_TRANSMISSION = 12,
  30. SD_SEND_STATUS = 13,
  31. SD_SET_BLOCKLEN = 16,
  32. SD_READ_SINGLE_BLOCK = 17,
  33. SD_READ_MULTIPLE_BLOCK = 18,
  34. SD_APP_SET_WR_BLK_ERASE_COUNT = 23,
  35. SD_WRITE_MULTIPLE_BLOCK = 25,
  36. SD_APP_SEND_OP_COND = 41,
  37. SD_APP_CMD = 55,
  38. SD_READ_OCR = 58,
  39. SD_CRC_ON_OFF = 59
  40. } SD_CMD;
  41. typedef enum
  42. {
  43. SD_R1_IDLE = 1,
  44. SD_R1_ERASE_RESET = 2,
  45. SD_R1_ILLEGAL = 4,
  46. SD_R1_CRC = 8,
  47. SD_R1_ERASE_SEQ = 0x10,
  48. SD_R1_ADDRESS = 0x20,
  49. SD_R1_PARAMETER = 0x40
  50. } SD_R1;
  51. */
  52. typedef struct
  53. {
  54. int version; // SDHC = version 2.
  55. int ccs; // Card Capacity Status. 1 = SDHC or SDXC
  56. uint32_t capacity; // in 512 byte blocks
  57. uint8_t csd[16]; // Unparsed CSD
  58. uint8_t cid[16]; // Unparsed CID
  59. } SdDevice;
  60. extern SdDevice sdDev;
  61. extern volatile uint8_t sdRxDMAComplete;
  62. extern volatile uint8_t sdTxDMAComplete;
  63. int sdInit(void);
  64. #define sdDMABusy() (!(sdRxDMAComplete && sdTxDMAComplete))
  65. void sdWriteMultiSectorPrep(uint32_t sdLBA, uint32_t sdSectors);
  66. void sdWriteMultiSectorDMA(uint8_t* outputBuffer);
  67. int sdWriteSectorDMAPoll();
  68. void sdReadMultiSectorPrep(uint32_t sdLBA, uint32_t sdSectors);
  69. void sdReadMultiSectorDMA(uint8_t* outputBuffer);
  70. void sdReadSingleSectorDMA(uint32_t lba, uint8_t* outputBuffer);
  71. int sdReadSectorDMAPoll();
  72. void sdCompleteTransfer(void);
  73. void sdPoll();
  74. #endif