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