Rev 151 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
151 | dimkam | 1 | |
2 | //#include "../my.h" |
||
3 | #include "../zxevo_io.h" |
||
4 | #include <stdio.h> |
||
5 | #include <Intrz80.h> |
||
6 | #include <string.h> |
||
7 | #include "sl811.h" |
||
8 | #include "tpbulk.h" |
||
9 | #include "hal.h" |
||
10 | |||
11 | //extern void EZUSB_Delay(unsigned char); |
||
12 | |||
13 | ////////////////////////////////// |
||
14 | extern unsigned char xdata DBUF[BUFFER_LENGTH]; |
||
15 | //SYS_INFO_BLOCK xdata DeviceInfo; |
||
16 | |||
17 | unsigned char idata out[0x20]; |
||
18 | /////////////////////////////////////////////////////////////////////////// |
||
19 | unsigned char EnumMassDev(void) |
||
20 | { |
||
21 | if(!SPC_Inquiry()) |
||
22 | return 0x81;//FALSE; |
||
23 | if(!SPC_TestUnit()) |
||
24 | return 0x82;//FALSE; |
||
25 | if(!SPC_LockMedia()) |
||
26 | return 0x83;//FALSE; |
||
27 | if(!SPC_RequestSense()) |
||
28 | return 0x84;//FALSE; |
||
29 | if(!SPC_TestUnit()) |
||
30 | return 0x85;//FALSE; |
||
31 | if(!RBC_ReadCapacity()) |
||
32 | return 0x86;//FALSE; |
||
33 | |||
34 | //////////////////////////////////////////////////// |
||
35 | //DeviceInfo.BPB_BytesPerSec=512; //SectorSize 512 |
||
36 | |||
37 | if(!SPC_RequestSense()) |
||
38 | return 0x87;//FALSE; |
||
39 | if(!SPC_TestUnit()) |
||
40 | return 0x88;//FALSE; |
||
41 | if(!RBC_ReadCapacity()) |
||
42 | return 0x89;//FALSE; |
||
43 | //////////////////////////////////////////////////// |
||
44 | if(!RBC_Read(0x0,1,DBUF)) |
||
45 | return 0x8a;//FALSE; |
||
46 | ////////////////////////////////// |
||
47 | |||
48 | return TRUE; |
||
49 | } |
||
50 | |||
51 | const unsigned char data0[25]={ |
||
52 | 0x55,0x53,0x42,0x43,0x60,0xa6,0x24,0xde, |
||
53 | 0x24,0x00,0x00,0x00,0x80,0x00,0x06,SPC_CMD_INQUIRY, |
||
54 | 0x00,0x00,0x00,0x24,}; |
||
55 | |||
56 | unsigned char SPC_Inquiry(void) |
||
57 | { |
||
58 | memcpy(out,data0,21); |
||
59 | if(!epBulkSend(out,0x1f)) |
||
60 | return FALSE; |
||
61 | DelayMs(150); |
||
62 | if(!epBulkRcv(DBUF,36)) |
||
63 | return FALSE; |
||
64 | if(!epBulkRcv(out,13)) |
||
65 | return FALSE; |
||
66 | //////////////////////////////// |
||
67 | return TRUE; |
||
68 | } |
||
69 | |||
70 | unsigned char SPC_RequestSense(void) |
||
71 | { |
||
72 | memcpy(out,data0,21); |
||
73 | out[8]=0x0e; |
||
74 | out[15]=SPC_CMD_REQUESTSENSE; |
||
75 | out[19]=0x0e; |
||
76 | ////////////////////////////////////// |
||
77 | if(!epBulkSend(out,0x1f)) |
||
78 | return FALSE; |
||
79 | DelayMs(5); |
||
80 | if(!epBulkRcv(out,18)) |
||
81 | return FALSE; |
||
82 | //delay_dsp |
||
83 | if(!epBulkRcv(out,13)) |
||
84 | return FALSE; |
||
85 | ///////////////////////////// |
||
86 | return TRUE; |
||
87 | } |
||
88 | |||
89 | unsigned char SPC_TestUnit(void) |
||
90 | { |
||
91 | memcpy(out,data0,21); |
||
92 | //////////////////////////////// |
||
93 | out[8]=0x00; |
||
94 | out[12]=0x00; |
||
95 | ///////////////////////////////////// |
||
96 | out[15]=SPC_CMD_TESTUNITREADY; |
||
97 | out[19]=0; |
||
98 | ////////////////////////////////////// |
||
99 | if(!epBulkSend(out,0x1f)) |
||
100 | return FALSE; |
||
101 | DelayMs(5); |
||
102 | if(!epBulkRcv(out,13)) |
||
103 | return FALSE; |
||
104 | return TRUE; |
||
105 | } |
||
106 | |||
107 | unsigned char SPC_LockMedia(void) |
||
108 | { |
||
109 | memcpy(out,data0,21); |
||
110 | out[8]=0x00; |
||
111 | out[12]=0x00; |
||
112 | out[14]=5; |
||
113 | /////////////////////////////////////////// |
||
114 | out[15]=SPC_CMD_PRVENTALLOWMEDIUMREMOVAL; |
||
115 | out[19]=1; |
||
116 | /////////////////////////////////////////// |
||
117 | if(!epBulkSend(out,0x1f)) |
||
118 | return FALSE; |
||
119 | DelayMs(5); |
||
120 | |||
121 | if(!epBulkRcv(out,13)) |
||
122 | return FALSE; |
||
123 | |||
124 | ///////////////////////////// |
||
125 | return TRUE; |
||
126 | } |
||
127 | |||
128 | unsigned char RBC_ReadCapacity(void) |
||
129 | { |
||
130 | memcpy(out,data0,25); |
||
131 | out[8]=0x08; |
||
132 | out[14]=10; |
||
133 | ///////////////////////////////////// |
||
134 | out[15]=RBC_CMD_READCAPACITY; |
||
135 | out[19]=0; |
||
136 | ///////////////////////////////////// |
||
137 | if(!epBulkSend(out,0x1f)) |
||
138 | return FALSE; |
||
139 | DelayMs(10); |
||
140 | if(!epBulkRcv(DBUF,8)) |
||
141 | return FALSE; |
||
142 | if(!epBulkRcv(out,13)) |
||
143 | return FALSE; |
||
144 | ///////////////////////////// |
||
145 | return TRUE; |
||
146 | } |
||
147 | |||
148 | unsigned char RBC_Read(unsigned long lba,unsigned char len,unsigned char *pBuffer) |
||
149 | { |
||
150 | //unsigned long lout; |
||
151 | memcpy(out,data0,8); |
||
152 | //lout=len*DeviceInfo.BPB_BytesPerSec; |
||
153 | *((unsigned long *) (out+8))=len*512; |
||
154 | out[12]=0x80; |
||
155 | out[13]=0x00; |
||
156 | out[14]=10; |
||
157 | ///////////////////////////////////// |
||
158 | out[15]=RBC_CMD_READ10; |
||
159 | out[16]=0x00; |
||
160 | out[17]=(unsigned char)((lba>>24)&0xff); |
||
161 | out[18]=(unsigned char)((lba>>16)&0xff); |
||
162 | out[19]=(unsigned char)((lba>>8)&0xff); |
||
163 | out[20]=(unsigned char)(lba&0xff); |
||
164 | out[21]=0x00; |
||
165 | out[22]=(unsigned char)((len>>8)&0xff); |
||
166 | out[23]=(unsigned char)(len&0xff); |
||
167 | out[24]=0x00; |
||
168 | ////////////////////////////////////// |
||
169 | if(!epBulkSend(out,0x1f)) |
||
170 | { puts("epBulkSend Error"); |
||
171 | return FALSE; |
||
172 | } |
||
173 | EZUSB_Delay(10); |
||
174 | if(!epBulkRcv(pBuffer,len*512)) |
||
175 | { puts("epBulkRcv Error 1"); |
||
176 | return FALSE; |
||
177 | } |
||
178 | if(!epBulkRcv(out,13)) |
||
179 | { puts("epBulkRcv Error 2"); |
||
180 | return FALSE; |
||
181 | } |
||
182 | ///////////////////////////// |
||
183 | return TRUE; |
||
184 | } |
||
185 | |||
186 | unsigned char RBC_Write(unsigned long lba,unsigned char len,unsigned char *pBuffer) |
||
187 | { |
||
188 | //unsigned long lout; |
||
189 | out[0]=0x55;out[1]=0x53;out[2]=0x42;out[3]=0x43; |
||
190 | out[4]=0xb4;out[5]=0xd9;out[6]=0x77;out[7]=0xc1; |
||
191 | //lout=len*DeviceInfo.BPB_BytesPerSec; |
||
192 | *((unsigned long *) (out+8))=len*512; |
||
193 | out[12]=0x00;out[13]=0x00;out[14]=10; |
||
194 | ///////////////////////////////////// |
||
195 | out[15]=RBC_CMD_WRITE10; |
||
196 | out[16]=0x00; |
||
197 | out[17]=(unsigned char)((lba>>24)&0xff); |
||
198 | out[18]=(unsigned char)((lba>>16)&0xff); |
||
199 | out[19]=(unsigned char)((lba>>8)&0xff); |
||
200 | out[20]=(unsigned char)(lba&0xff); |
||
201 | out[21]=0x00; |
||
202 | out[22]=(unsigned char)((len>>8)&0xff); |
||
203 | out[23]=(unsigned char)(len&0xff); |
||
204 | out[24]=0x00; |
||
205 | ////////////////////////////////////// |
||
206 | if(!epBulkSend(out,0x1f)) |
||
207 | return FALSE; |
||
208 | DelayMs(15); |
||
209 | if(!epBulkSend(pBuffer,len*512)) |
||
210 | return FALSE; |
||
211 | DelayMs(10); |
||
212 | if(!epBulkRcv(out,13)) |
||
213 | return FALSE; |
||
214 | return TRUE; |
||
215 | } |