Line No. | Rev | Author | Line |
---|---|---|---|
1 | 32 | kaklik | /******************************************************************************* |
2 | |||
3 | USB Host Mass Storage Class SCSI Interface Driver (Header File) |
||
4 | |||
5 | Description: |
||
6 | This is the header file for a USB Embedded Host that is using a SCSI |
||
7 | interface to the Mass Storage Class. |
||
8 | |||
9 | This file provides the interface between the file system and the USB Host |
||
10 | Mass Storage class. It translates the file system funtionality requirements |
||
11 | to the appropriate SCSI commands, and sends the SCSI commands via the USB |
||
12 | Mass Storage class. This header file should be included with usb_host.h and |
||
13 | usb_host_msd.h to provide the USB Mass Storage Class interface. It must |
||
14 | be included after the application-specific usb_config.h file, the USB Host |
||
15 | header file usb_host.h, and the USB Host MSD header file usb_host_msd.h, |
||
16 | as definitions in those files are required for proper compilation. |
||
17 | |||
18 | The functions in this file are designed to interface the Microchip Memory |
||
19 | Disk Drive File System library (see Application Note AN1045) to the USB |
||
20 | Host Mass Storage Class, allowing a PIC application to utilize mass storage |
||
21 | devices such as USB flash drives. For ease of integration, this file |
||
22 | contains macros to allow the File System code to reference the functions in |
||
23 | this file. |
||
24 | |||
25 | Currently, the file system layer above this interface layer is limited to |
||
26 | one LUN (Logical Unit Number) on a single mass storage device. This layer |
||
27 | accepts and stores the max LUN from the USB MSD layer, but all sector reads |
||
28 | and writes are hard-coded to LUN 0, since the layer above does not specify |
||
29 | a LUN in the sector read and write commands. Also, to interface with the |
||
30 | existing file system code, only one attached device is allowed. |
||
31 | |||
32 | Summary: |
||
33 | This is the header file for a USB Embedded Host that is using a SCSI |
||
34 | interface to the Mass Storage Class. |
||
35 | |||
36 | *******************************************************************************/ |
||
37 | //DOM-IGNORE-BEGIN |
||
38 | /******************************************************************************* |
||
39 | |||
40 | * FileName: usb_host_msd_scsi.h |
||
41 | * Dependencies: None |
||
42 | * Processor: PIC24/dsPIC30/dsPIC33/PIC32MX |
||
43 | * Compiler: C30 v2.01/C32 v0.00.18 |
||
44 | * Company: Microchip Technology, Inc. |
||
45 | |||
46 | Software License Agreement |
||
47 | |||
48 | The software supplied herewith by Microchip Technology Incorporated |
||
49 | (the Company) for its PICmicro® Microcontroller is intended and |
||
50 | supplied to you, the Companys customer, for use solely and |
||
51 | exclusively on Microchip PICmicro Microcontroller products. The |
||
52 | software is owned by the Company and/or its supplier, and is |
||
53 | protected under applicable copyright laws. All rights are reserved. |
||
54 | Any use in violation of the foregoing restrictions may subject the |
||
55 | user to criminal sanctions under applicable laws, as well as to |
||
56 | civil liability for the breach of the terms and conditions of this |
||
57 | license. |
||
58 | |||
59 | THIS SOFTWARE IS PROVIDED IN AN AS IS CONDITION. NO WARRANTIES, |
||
60 | WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED |
||
61 | TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
||
62 | PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, |
||
63 | IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR |
||
64 | CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. |
||
65 | |||
66 | Change History: |
||
67 | Rev Description |
||
68 | ---- -------------------------------------- |
||
69 | 2.6a- No change |
||
70 | 2.7 |
||
71 | |||
72 | 2.7a Removed improper include of "usb_config.h" |
||
73 | *******************************************************************************/ |
||
74 | |||
75 | #ifndef __USBHOSTMSDSCSI_H__ |
||
76 | #define __USBHOSTMSDSCSI_H__ |
||
77 | //DOM-IGNORE-END |
||
78 | |||
79 | #include "USB\usb.h" |
||
80 | #include "FSConfig.h" |
||
81 | #include "MDD File System\FSDefs.h" |
||
82 | |||
83 | // ***************************************************************************** |
||
84 | // ***************************************************************************** |
||
85 | // Section: Constants |
||
86 | // ***************************************************************************** |
||
87 | // ***************************************************************************** |
||
88 | |||
89 | |||
90 | // ***************************************************************************** |
||
91 | // ***************************************************************************** |
||
92 | // Section: Function Prototypes |
||
93 | // ***************************************************************************** |
||
94 | // ***************************************************************************** |
||
95 | |||
96 | /**************************************************************************** |
||
97 | Function: |
||
98 | BYTE USBHostMSDSCSIMediaDetect( void ) |
||
99 | |||
100 | Description: |
||
101 | This function determines if a mass storage device is attached and ready |
||
102 | to use. |
||
103 | |||
104 | Precondition: |
||
105 | None |
||
106 | |||
107 | Parameters: |
||
108 | None - None |
||
109 | |||
110 | Return Values: |
||
111 | TRUE - MSD present and ready |
||
112 | FALSE - MSD not present or not ready |
||
113 | |||
114 | Remarks: |
||
115 | Since this will often be called in a loop while waiting for a device, |
||
116 | we need to make sure that USB tasks are executed. |
||
117 | ***************************************************************************/ |
||
118 | |||
119 | BYTE USBHostMSDSCSIMediaDetect( void ); |
||
120 | |||
121 | |||
122 | /**************************************************************************** |
||
123 | Function: |
||
124 | MEDIA_INFORMATION * USBHostMSDSCSIMediaInitialize( void ) |
||
125 | |||
126 | Description: |
||
127 | This function initializes the media. |
||
128 | |||
129 | Precondition: |
||
130 | None |
||
131 | |||
132 | Parameters: |
||
133 | None - None |
||
134 | |||
135 | Returns: |
||
136 | The function returns a pointer to the MEDIA_INFORMATION structure. The |
||
137 | errorCode member may contain the following values: |
||
138 | * MEDIA_NO_ERROR - The media initialized successfully, and the |
||
139 | sector size should be valid (confirm using the validityFlags |
||
140 | bit). |
||
141 | * MEDIA_DEVICE_NOT_PRESENT - The requested device is not attached. |
||
142 | * MEDIA_CANNOT_INITIALIZE - Cannot initialize the media. |
||
143 | |||
144 | Remarks: |
||
145 | This function performs the following SCSI commands: |
||
146 | * READ CAPACITY 10 |
||
147 | * REQUEST SENSE |
||
148 | |||
149 | The READ CAPACITY 10 command block is as follows: |
||
150 | |||
151 | <code> |
||
152 | Byte/Bit 7 6 5 4 3 2 1 0 |
||
153 | |||
154 | 1 [ Reserved ] |
||
155 | 2 [ (MSB) |
||
156 | 3 Logical Block Address |
||
157 | 4 |
||
158 | 5 (LSB) ] |
||
159 | 6 [ Reserved |
||
160 | 7 ] |
||
161 | 8 [ Reserved ] [ PMI ] |
||
162 | 9 [ Control ] |
||
163 | </code> |
||
164 | |||
165 | The REQUEST SENSE command block is as follows: |
||
166 | |||
167 | <code> |
||
168 | Byte/Bit 7 6 5 4 3 2 1 0 |
||
169 | |||
170 | 1 [ Reserved ] [ DESC] |
||
171 | 2 [ Reserved |
||
172 | 3 ] |
||
173 | 4 [ Allocation Length ] |
||
174 | 5 [ Control ] |
||
175 | </code> |
||
176 | ***************************************************************************/ |
||
177 | |||
178 | MEDIA_INFORMATION * USBHostMSDSCSIMediaInitialize( void ); |
||
179 | |||
180 | |||
181 | /**************************************************************************** |
||
182 | Function: |
||
183 | BOOL USBHostMSDSCSIMediaReset( void ) |
||
184 | |||
185 | Summary: |
||
186 | This function resets the media. |
||
187 | |||
188 | Description: |
||
189 | This function resets the media. It is called if an operation returns an |
||
190 | error. Or the application can call it. |
||
191 | |||
192 | Precondition: |
||
193 | None |
||
194 | |||
195 | Parameters: |
||
196 | None - None |
||
197 | |||
198 | Return Values: |
||
199 | USB_SUCCESS - Reset successful |
||
200 | USB_MSD_DEVICE_NOT_FOUND - No device with specified address |
||
201 | USB_ILLEGAL_REQUEST - Device is in an illegal USB state |
||
202 | for reset |
||
203 | |||
204 | Remarks: |
||
205 | None |
||
206 | ***************************************************************************/ |
||
207 | |||
208 | BYTE USBHostMSDSCSIMediaReset( void ); |
||
209 | |||
210 | |||
211 | /**************************************************************************** |
||
212 | Function: |
||
213 | BYTE USBHostMSDSCSISectorRead( DWORD sectorAddress, BYTE *dataBuffer) |
||
214 | |||
215 | Summary: |
||
216 | This function reads one sector. |
||
217 | |||
218 | Description: |
||
219 | This function uses the SCSI command READ10 to read one sector. The size |
||
220 | of the sector was determined in the USBHostMSDSCSIMediaInitialize() |
||
221 | function. The data is stored in the application buffer. |
||
222 | |||
223 | Precondition: |
||
224 | None |
||
225 | |||
226 | Parameters: |
||
227 | DWORD sectorAddress - address of sector to read |
||
228 | BYTE *dataBuffer - buffer to store data |
||
229 | |||
230 | Return Values: |
||
231 | TRUE - read performed successfully |
||
232 | FALSE - read was not successful |
||
233 | |||
234 | Remarks: |
||
235 | The READ10 command block is as follows: |
||
236 | |||
237 | <code> |
||
238 | Byte/Bit 7 6 5 4 3 2 1 0 |
||
239 | |||
240 | 1 [ RDPROTECT ] DPO FUA - FUA_NV - |
||
241 | 2 [ (MSB) |
||
242 | 3 Logical Block Address |
||
243 | 4 |
||
244 | 5 (LSB) ] |
||
245 | 6 [ - ][ Group Number ] |
||
246 | 7 [ (MSB) Transfer Length |
||
247 | 8 (LSB) ] |
||
248 | 9 [ Control ] |
||
249 | </code> |
||
250 | ***************************************************************************/ |
||
251 | |||
252 | BYTE USBHostMSDSCSISectorRead( DWORD sectorAddress, BYTE *dataBuffer ); |
||
253 | |||
254 | |||
255 | /**************************************************************************** |
||
256 | Function: |
||
257 | BYTE USBHostMSDSCSISectorWrite( DWORD sectorAddress, BYTE *dataBuffer, BYTE allowWriteToZero ) |
||
258 | |||
259 | Summary: |
||
260 | This function writes one sector. |
||
261 | |||
262 | Description: |
||
263 | This function uses the SCSI command WRITE10 to write one sector. The size |
||
264 | of the sector was determined in the USBHostMSDSCSIMediaInitialize() |
||
265 | function. The data is read from the application buffer. |
||
266 | |||
267 | Precondition: |
||
268 | None |
||
269 | |||
270 | Parameters: |
||
271 | DWORD sectorAddress - address of sector to write |
||
272 | BYTE *dataBuffer - buffer with application data |
||
273 | BYTE allowWriteToZero- If a write to sector 0 is allowed. |
||
274 | |||
275 | Return Values: |
||
276 | TRUE - write performed successfully |
||
277 | FALSE - write was not successful |
||
278 | |||
279 | Remarks: |
||
280 | To follow convention, this function blocks until the write is complete. |
||
281 | |||
282 | The WRITE10 command block is as follows: |
||
283 | |||
284 | <code> |
||
285 | Byte/Bit 7 6 5 4 3 2 1 0 |
||
286 | |||
287 | 1 [ WRPROTECT ] DPO FUA - FUA_NV - |
||
288 | 2 [ (MSB) |
||
289 | 3 Logical Block Address |
||
290 | 4 |
||
291 | 5 (LSB) ] |
||
292 | 6 [ - ][ Group Number ] |
||
293 | 7 [ (MSB) Transfer Length |
||
294 | 8 (LSB) ] |
||
295 | 9 [ Control ] |
||
296 | </code> |
||
297 | ***************************************************************************/ |
||
298 | |||
299 | BYTE USBHostMSDSCSISectorWrite( DWORD sectorAddress, BYTE *dataBuffer, BYTE allowWriteToZero); |
||
300 | |||
301 | |||
302 | /**************************************************************************** |
||
303 | Function: |
||
304 | BYTE USBHostMSDSCSIWriteProtectState( void ) |
||
305 | |||
306 | Description: |
||
307 | This function returns the write protect status of the device. |
||
308 | |||
309 | Precondition: |
||
310 | None |
||
311 | |||
312 | Parameters: |
||
313 | None - None |
||
314 | |||
315 | Return Values: |
||
316 | |||
317 | |||
318 | |||
319 | Remarks: |
||
320 | None |
||
321 | ***************************************************************************/ |
||
322 | |||
323 | BYTE USBHostMSDSCSIWriteProtectState( void ); |
||
324 | |||
325 | |||
326 | // ***************************************************************************** |
||
327 | // ***************************************************************************** |
||
328 | // Section: SCSI Interface Callback Functions |
||
329 | // ***************************************************************************** |
||
330 | // ***************************************************************************** |
||
331 | |||
332 | /**************************************************************************** |
||
333 | Function: |
||
334 | BOOL USBHostMSDSCSIInitialize( BYTE address, DWORD flags, BYTE clientDriverID ) |
||
335 | |||
336 | Description: |
||
337 | This function is called when a USB Mass Storage device is being |
||
338 | enumerated. |
||
339 | |||
340 | Precondition: |
||
341 | None |
||
342 | |||
343 | Parameters: |
||
344 | BYTE address - Address of the new device |
||
345 | DWORD flags - Initialization flags |
||
346 | BYTE clientDriverID - ID for this layer. Not used by the media interface layer. |
||
347 | |||
348 | Return Values: |
||
349 | TRUE - We can support the device. |
||
350 | FALSE - We cannot support the device. |
||
351 | |||
352 | Remarks: |
||
353 | None |
||
354 | ***************************************************************************/ |
||
355 | |||
356 | BOOL USBHostMSDSCSIInitialize( BYTE address, DWORD flags, BYTE clientDriverID ); |
||
357 | |||
358 | |||
359 | /**************************************************************************** |
||
360 | Function: |
||
361 | BOOL USBHostMSDSCSIEventHandler( BYTE address, USB_EVENT event, |
||
362 | void *data, DWORD size ) |
||
363 | |||
364 | Description: |
||
365 | This function is called when various events occur in the USB Host Mass |
||
366 | Storage client driver. |
||
367 | |||
368 | Precondition: |
||
369 | The device has been initialized. |
||
370 | |||
371 | Parameters: |
||
372 | BYTE address - Address of the device |
||
373 | USB_EVENT event - Event that has occurred |
||
374 | void *data - Pointer to data pertinent to the event |
||
375 | DWORD size - Size of the data |
||
376 | |||
377 | Return Values: |
||
378 | TRUE - Event was handled |
||
379 | FALSE - Event was not handled |
||
380 | |||
381 | Remarks: |
||
382 | None |
||
383 | ***************************************************************************/ |
||
384 | |||
385 | BOOL USBHostMSDSCSIEventHandler( BYTE address, USB_EVENT event, void *data, DWORD size ); |
||
386 | |||
387 | |||
388 | #endif |
Powered by WebSVN v2.8.3