📄 sd.lst
字号:
172 =1 #define SPI_1P5M 0x1
173 =1 #define SPI_750K 0x2
174 =1 #define SPI_375K 0x3
175 =1 #define SPI_188K 0x4
176 =1 #define SPI_94K 0x5
177 =1 #define SPI_47K 0x6
178 =1 #define SPI_23K 0x7
179 =1 // SPI status
180 =1 #define SPI_SPTEF 0x1
181 =1 #define SPI_RRDY 0x2
182 =1 #define SPI_WERR 0x4
183 =1 #define SPI_RERR 0x8
184 =1 // SD control
185 =1 #define SD_64B 0x0
186 =1 #define SD_128B 0x1
187 =1 #define SD_256B 0x2
188 =1 #define SD_512B 0x3
189 =1 #define SD_WR 0x40
190 =1 #define SD_EN 0x80
191 =1 // SD status 0
192 =1
193 =1 // SD status 1
194 =1 #define SD_SDERR 0x1
195 =1 #define SD_SDINT 0x2
196 =1 #define SD_CMDEND 0x4
197 =1
198 =1 #define SD_DETECT 0x4
199 =1
200 =1 // Buffer Control
201 =1 #ifdef OLD_CHIP
202 =1 #define MCU2MP3 0x03
203 =1 #define USB2MP3 0x13
204 =1 #else
=1 #define MCU2MP3 0x02
=1 #define USB2MP3 0x12
=1 #endif
208 =1 #define USB2MCU 0x10
209 =1 #define MCU2USB 0x01
210 =1 #define USBFLSH 0x14
211 =1
212 =1 // function prototypes
213 =1 unsigned short WordSwap(unsigned short input);
214 =1 void DelayMs(unsigned int nFactor);
215 =1 void DelayUs(unsigned char nFactor);
216 =1 unsigned long SwapINT32(unsigned long dData);
217 =1 unsigned char SendUart(unsigned char *pUsrBuf, unsigned int num);
218 =1
219 =1
220 =1
6 #include "sd.h"
1 =1 // sd.h
2 =1 // SD/MMC definitions for SPI protocol
3 =1 // modified from holger.klabunde from AVR to C8051
4 =1 //#########################################################################
5 =1
6 =1 #ifndef __SD_CARD_SPI_H
7 =1 #define __SD_CARD_SPI_H
8 =1
9 =1 #define SPI_WRITE(a) { SPI_DATA=(a); while(!(SPI_STA0&SPI_SPTEF)); }
10 =1
11 =1 // data structures
12 =1 typedef struct _CSD_BLOCK
C51 COMPILER V8.02 SD 09/19/2006 15:01:24 PAGE 7
13 =1 {
14 =1 unsigned char CSD_Struct:2;
15 =1 unsigned char CSD_StructResv:6;
16 =1 unsigned char CSD_RdAcsTime;
17 =1 unsigned char CSD_RdAcsCycl;
18 =1 unsigned char CSD_XferSpeed;
19 =1 unsigned int CSD_CCC:12;
20 =1 unsigned int CSD_RdBlkLen:4;
21 =1 unsigned int CSD_RdBlkPartial:1;
22 =1 unsigned int CSD_WrBlkMisAlign:1;
23 =1 unsigned int CSD_RdBlkMisAlign:1;
24 =1 unsigned int CSD_DSRImp:1;
25 =1 unsigned int CSD_DevResv:2;
26 =1 unsigned int CSD_DevSize:12;
27 =1 unsigned int CSD_MaxRdCurVmin:3;
28 =1 unsigned int CSD_MaxRdCurVmax:3;
29 =1 unsigned int CSD_MaxWrCurVmin:3;
30 =1 unsigned int CSD_MaxWrCurVmax:3;
31 =1 unsigned int CSD_DevSizeMult:3;
32 =1 unsigned int CSD_ErsSingBlk:1;
33 =1 unsigned int CSD_ErsSectSize:7;
34 =1 unsigned int CSD_WrProtGrpSize:7;
35 =1 unsigned char CSD_WrFmtGrpEn:1;
36 =1 unsigned char CSD_MMCResv:2;
37 =1 unsigned char CSD_WrSpeedFactor:3;
38 =1 unsigned char CSD_MaxWrLen:4;
39 =1 unsigned char CSD_PartBlkWr:1;
40 =1 unsigned char CSD_FileResv:5;
41 =1 unsigned char CSD_FileFmtGrp:1;
42 =1 unsigned char CSD_CopyFlag:1;
43 =1 unsigned char CSD_PermWrProt:1;
44 =1 unsigned char CSD_TempWrProt:1;
45 =1 unsigned char CSD_FileFmt:2;
46 =1 unsigned char CSD_Resv:2;
47 =1 unsigned char CSD_CRC:7;
48 =1 unsigned char CSD_EOB:1;
49 =1 } CSD_BLOCK, *pCSD_BLOCK;
50 =1
51 =1 // SD/MMC commands
52 =1 #define SD_RESET 0x40 + 0
53 =1 #define SD_INIT 0x40 + 1
54 =1 #define SD_READ_CSD 0x40 + 9
55 =1 #define SD_READ_CID 0x40 + 10
56 =1 //
57 =1 #define SD_STOP_TRANSMISSION 0x40 + 12
58 =1 #define SD_SEND_STATUS 0x40 + 13
59 =1 //
60 =1 #define SD_SET_BLOCKLEN 0x40 + 16
61 =1 #define SD_READ_BLOCK 0x40 + 17
62 =1 #define SD_READ_MULTI_BLOCK 0x40 + 18
63 =1 //
64 =1 #define SD_WRITE_BLOCK 0x40 + 24
65 =1 #define SD_WRITE_MULTI_BLOCK 0x40 + 25
66 =1
67 =1 //prototypes
68 =1 unsigned char GetDevInfo(void);
69 =1
70 =1 unsigned char SDCommand(unsigned char command, unsigned char *pAddr);
71 =1
72 =1 unsigned char SDReadSector(unsigned long sector);
73 =1
74 =1 unsigned char SDReadFat(unsigned long sector);
C51 COMPILER V8.02 SD 09/19/2006 15:01:24 PAGE 8
75 =1
76 =1 unsigned char SDReadRdir(unsigned long sector);
77 =1
78 =1 unsigned char SDWriteSector(unsigned long sector, unsigned char *pUsrBuf);
79 =1
80 =1 unsigned char SDIdentify(void);
81 =1
82 =1 unsigned char SDResp(unsigned char respLen);
83 =1
84 =1 unsigned char SDMp3Read(unsigned long sector);
85 =1
86 =1 unsigned char UartWaitCmd();
87 =1
88 =1 #endif
7 #include "fat.h"
1 =1 unsigned long FirstSectorofCluster(unsigned int n);
2 =1 unsigned int ThisFatEntOffset(unsigned int clusterNum);
3 =1 unsigned int GetNextClusterNum(unsigned int clusterNum);
4 =1 unsigned int ThisFatSecNum(unsigned int clusterNum);
8 #include "rbccmd.h"
1 =1 /*
2 =1 // RBC commands
3 =1 */
4 =1 #define RBC_CMD_FORMAT 0x04
5 =1 #define RBC_CMD_READ10 0x28
6 =1 #define RBC_CMD_READCAPACITY 0x25
7 =1 #define RBC_CMD_STARTSTOPUNIT 0x1B
8 =1 #define RBC_CMD_SYNCCACHE 0x35
9 =1 #define RBC_CMD_VERIFY10 0x2F
10 =1 #define RBC_CMD_WRITE10 0x2A
11 =1
12 =1 /*
13 =1 // SPC-2 commands
14 =1 */
15 =1 #define SPC_CMD_INQUIRY 0x12
16 =1 #define SPC_CMD_MODESELECT6 0x15
17 =1 #define SPC_CMD_MODESENSE6 0x1A
18 =1 #define SPC_CMD_PERSISTANTRESERVIN 0x5E
19 =1 #define SPC_CMD_PERSISTANTRESERVOUT 0x5F
20 =1 #define SPC_CMD_PRVENTALLOWMEDIUMREMOVAL 0x1E
21 =1 #define SPC_CMD_RELEASE6 0x17
22 =1 #define SPC_CMD_REQUESTSENSE 0x03
23 =1 #define SPC_CMD_RESERVE6 0x16
24 =1 #define SPC_CMD_TESTUNITREADY 0x00
25 =1 #define SPC_CMD_WRITEBUFFER 0x3B
26 =1 #define SPC_CMD_READLONG 0x23
27 =1
28 =1
29 =1 /*
30 =1 // ATAPI Command Descriptor Block - 13 Bytes
31 =1 */
32 =1
33 =1 typedef struct _READ_10 {
34 =1 UINT8 OperationCode;
35 =1 UINT8 Reserved1;
36 =1 UINT8 LBA_3;
37 =1 UINT8 LBA_2;
38 =1 UINT8 LBA_1;
39 =1 UINT8 LBA_0;
40 =1 UINT8 Reserved2;
41 =1 UINT8 XferLen_1;
42 =1 UINT8 XferLen_0;
C51 COMPILER V8.02 SD 09/19/2006 15:01:24 PAGE 9
43 =1 UINT8 Reserved3[3];
44 =1 } READ_10, *pREAD_10;
45 =1
46 =1 typedef struct _WRITE_10 {
47 =1 UINT8 OperationCode;
48 =1 UINT8 Reserved1;
49 =1 UINT8 LBA_3;
50 =1 UINT8 LBA_2;
51 =1 UINT8 LBA_1;
52 =1 UINT8 LBA_0;
53 =1 UINT8 Reserved2;
54 =1 UINT8 XferLen_1;
55 =1 UINT8 XferLen_0;
56 =1 UINT8 Reserved3[3];
57 =1 } WRITE_10, *pWRITE_10;
58 =1
59 =1 typedef struct _MODE_SENSE_10 {
60 =1 UINT8 OperationCode;
61 =1 UINT8 Reserved1;
62 =1 UINT8 PageCode : 6;
63 =1 UINT8 Pc : 2;
64 =1 UINT8 Reserved2[4];
65 =1 UINT8 ParameterListLengthMsb;
66 =1 UINT8 ParameterListLengthLsb;
67 =1 UINT8 Reserved3[3];
68 =1 } MODE_SENSE_10, *pMODE_SENSE_10;
69 =1
70 =1 typedef struct _MODE_SELECT_10 {
71 =1 UINT8 OperationCode;
72 =1 UINT8 Reserved1 : 4;
73 =1 UINT8 PFBit : 1;
74 =1 UINT8 Reserved2 : 3;
75 =1 UINT8 Reserved3[5];
76 =1 UINT8 ParameterListLengthMsb;
77 =1 UINT8 ParameterListLengthLsb;
78 =1 UINT8 Reserved4[3];
79 =1 } MODE_SELECT_10, *pMODE_SELECT_10;
80 =1 /*
81 =1 ////////////////////////////////////////////////////////////////////////////////////
82 =1 // Command Descriptor Block - max = 16 Bytes
83 =1 // _RBC : Reduced Block Command
84 =1 // _SPC : SPC-2 SCSI primary Command - 2
85 =1 ////////////////////////////////////////////////////////////////////////////////////
86 =1 */
87 =1
88 =1 /*
89 =1 // Generic
90 =1 */
91 =1 typedef struct _GENERIC_CDB {
92 =1 UINT8 OperationCode;
93 =1 UINT8 Reserved[15];
94 =1 } GENERIC_CDB,*pGENERIC_CDB;
95 =1
96 =1 typedef struct _GENERIC_RBC {
97 =1 UINT8 OperationCode;
98 =1 UINT8 Reserved[8];
99 =1 UINT8 Control;
100 =1 } GENERIC_RBC,*pGENERIC_RBC;
101 =1
102 =1 /*
103 =1 // format unit
104 =1 */
C51 COMPILER V8.02 SD 09/19/2006 15:01:24 PAGE 10
105 =1 typedef struct _FORMAT_RBC {
106 =1 UINT8 OperationCode; // 04H
107 =1 UINT8 VendorSpecific;
108 =1 UINT8 Increment : 1;
109 =1 UINT8 PercentorTime : 1;
110 =1 UINT8 Progress : 1;
111 =1 UINT8 Immediate : 1;
112 =1 UINT8 VendorSpecific1 : 4;
113 =1 UINT8 Reserved2[2];
114 =1 UINT8 Control;
115 =1 } FORMAT_RBC, *pFORMAT_RBC;
116 =1
117 =1
118 =1 /*
119 =1 // Read Command
120 =1 */
121 =1 typedef struct _READ_RBC {
122 =1 UINT8 OperationCode; // 10H
123 =1 UINT8 VendorSpecific;
124 =1 union{
125 =1 struct
126 =1 {
127 =1 UINT8 LBA_3;
128 =1 UINT8 LBA_2;
129 =1 UINT8 LBA_1;
130 =1 UINT8 LBA_0;
131 =1 } LBA_W8 ;
132 =1
133 =1 UINT32 LBA_W32;
134 =1 }LBA;
135 =1 UINT8 Reserved;
136 =1 //UINT8 XferLength_1;
137 =1 //UINT8 XferLength_0;
138 =1 UINT16 XferLength;
139 =1 UINT8 Control;
140 =1 //UINT8 Reserved1[3];
141 =1 } READ_RBC, *pREAD_RBC;
142 =1
143 =1
144 =1 /*
145 =1 // Read Capacity Data - returned in Big Endian format
146 =1 */
147 =1 typedef struct _READ_CAPACITY_DATA {
148 =1
149 =1 UINT8 LBA_3;
150 =1 UINT8 LBA_2;
151 =1 UINT8 LBA_1;
152 =1 UINT8 LBA_0;
153 =1
154 =1 UINT8 BlockLen_3;
155 =1 UINT8 BlockLen_2;
156 =1 UINT8 BlockLen_1;
157 =1 UINT8 BlockLen_0;
158 =1 } READ_CAPACITY_DATA, *pREAD_CAPACITY_DATA;
159 =1 //////////////////////////////////////////////////
160 =1 typedef struct _READ_LONG_CMD{
161 =1 UINT8 OperationCode;
162 =1 UINT8 LogicalUnitNum :3;
163 =1 UINT8 RES_1 :5;
164 =1 UINT8 RES_2;
165 =1 UINT8 RES_3;
166 =1 UINT8 RES_4;
C51 COMPILER V8.02 SD 09/19/2006 15:01:24 PAGE 11
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -