Subversion Repositories pentevo

Rev

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

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