Subversion Repositories pentevo

Rev

Rev 796 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed | ?url?

  1. #ifndef SDCARD_H
  2. #define SDCARD_H
  3.  
  4. const u8 _SDNCS = 1;
  5. const u8 _SDDET = 2;
  6. const u8 _SDWP  = 4;
  7.  
  8. class TSdCard
  9. {
  10.     enum TCmd
  11.     {
  12.         CMD_INVALID = -1,
  13.         CMD0 = 0,
  14.         CMD_GO_IDLE_STATE = CMD0,
  15.         CMD1 = 1,
  16.         CMD_SEND_OP_COND = CMD1,
  17.         CMD8 = 8,
  18.         CMD_SEND_IF_COND = CMD8,
  19.         CMD9 = 9,
  20.         CMD_SEND_CSD = CMD9,
  21.         CMD10 = 10,
  22.         CMD_SEND_CID = CMD10,
  23.         CMD12 = 12,
  24.         CMD_STOP_TRANSMISSION = CMD12,
  25.         CMD16 = 16,
  26.         CMD_SET_BLOCKLEN = CMD16,
  27.         CMD17 = 17,
  28.         CMD_READ_SINGLE_BLOCK = CMD17,
  29.         CMD18 = 18,
  30.         CMD_READ_MULTIPLE_BLOCK = CMD18,
  31.         CMD24 = 24,
  32.         CMD_WRITE_BLOCK = CMD24,
  33.         CMD25 = 25,
  34.         CMD_WRITE_MULTIPLE_BLOCK = CMD25,
  35.         CMD55 = 55,
  36.         CMD_APP_CMD = CMD55,
  37.         CMD58 = 58,
  38.         CMD_READ_OCR = CMD58,
  39.         CMD59 = 59,
  40.         CMD_CRC_ON_OFF = CMD59,
  41.         ACMD23 = 23,
  42.         CMD_SET_WR_BLK_ERASE_COUNT = ACMD23,
  43.         ACMD41 = 41,
  44.         CMD_SD_SEND_OP_COND = ACMD41
  45.     };
  46.     enum TState
  47.     {
  48.         ST_IDLE, ST_RD_ARG, ST_RD_CRC, ST_R1, ST_R1b, ST_R2, ST_R3, ST_R7,
  49.         ST_WR_DATA_SIG, ST_WR_DATA, ST_WR_CRC16_1, ST_WR_CRC16_2,
  50.         ST_RD_DATA_SIG, ST_RD_DATA, ST_RD_DATA_MUL, ST_RD_CRC16_1, ST_RD_CRC16_2,
  51.         ST_WR_DATA_RESP, ST_RD_DATA_SIG_MUL
  52.     };
  53.     enum TDataStatus
  54.     {
  55.         STAT_DATA_ACCEPTED = 2, STAT_DATA_CRC_ERR = 5, STAT_DATA_WR_ERR = 6
  56.     };
  57.     TState CurrState;
  58.  
  59. #pragma pack(push, 1)
  60.     union
  61.     {
  62.         u8 ArgArr[4];
  63.         u32 Arg;
  64.     };
  65. #pragma pack(pop)
  66.  
  67.     u32 ArgCnt;
  68.  
  69. #pragma pack(push, 1)
  70.     union
  71.     {
  72.         u8 OcrArr[4];
  73.         u32 Ocr;
  74.     };
  75. #pragma pack(pop)
  76.  
  77.     u32 OcrCnt;
  78.  
  79.     u8 Cid[16];
  80.     u8 Csd[16];
  81.  
  82.     u32 CidCnt;
  83.     u32 CsdCnt;
  84.  
  85.     bool AppCmd;
  86.     TCmd Cmd;
  87.     u32 DataBlockLen;
  88.     u32 DataCnt;
  89.  
  90.     u8 Buf[512];
  91.  
  92.     FILE *Image;
  93.     u32 ImageSize; // ЁрчьхЁ SD ърЁЄ√ т 512╩с сыюърї - 1
  94. public:
  95.     TSdCard() { Image = nullptr; ImageSize = 0; Reset(); }
  96.     void Reset();
  97.     void Open(const char *Name);
  98.     void Close();
  99.     void Wr(u8 Val);
  100.     u8 Rd();
  101. private:
  102.     TState GetRespondType();
  103.     void UpdateCsdImageSize();
  104. };
  105. extern TSdCard SdCard;
  106. #endif
  107.