| Line No. | Rev | Author | Line | 
|---|---|---|---|
| 1 | 32 | kaklik | /********************************************************************* | 
| 2 |   File Information: | ||
| 3 |     FileName:        usb_function_msd.h | ||
| 4 |     Dependencies:    See INCLUDES section below | ||
| 5 |     Processor:       PIC18, PIC24, or PIC32 | ||
| 6 |     Compiler:        C18, C30, or C32 | ||
| 7 |     Company:         Microchip Technology, Inc. | ||
| 8 | |||
| 9 |     Software License Agreement | ||
| 10 | |||
| 11 |     The software supplied herewith by Microchip Technology Incorporated | ||
| 12 |     (the Company) for its PICmicro® Microcontroller is intended and | ||
| 13 |     supplied to you, the Companys customer, for use solely and | ||
| 14 |     exclusively on Microchip PICmicro Microcontroller products. The | ||
| 15 |     software is owned by the Company and/or its supplier, and is | ||
| 16 |     protected under applicable copyright laws. All rights are reserved. | ||
| 17 |     Any use in violation of the foregoing restrictions may subject the | ||
| 18 |     user to criminal sanctions under applicable laws, as well as to | ||
| 19 |     civil liability for the breach of the terms and conditions of this | ||
| 20 |     license. | ||
| 21 | |||
| 22 |     THIS SOFTWARE IS PROVIDED IN AN AS IS CONDITION. NO WARRANTIES, | ||
| 23 |     WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED | ||
| 24 |     TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | ||
| 25 |     PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, | ||
| 26 |     IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR | ||
| 27 |     CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. | ||
| 28 | |||
| 29 |   Summary: | ||
| 30 |     This file contains functions, macros, definitions, variables, | ||
| 31 |     datatypes, etc. that are required for use of the MSD function | ||
| 32 |     driver. This file should be included in projects that use the MSD | ||
| 33 |     \function driver. | ||
| 34 | |||
| 35 | |||
| 36 | |||
| 37 |     This file is located in the "\<Install Directory\>\\Microchip\\USB\\MSD | ||
| 38 |     Device Driver" directory. | ||
| 39 | |||
| 40 |   Description: | ||
| 41 |     USB MSD Function Driver File | ||
| 42 | |||
| 43 |     This file contains functions, macros, definitions, variables, | ||
| 44 |     datatypes, etc. that are required for use of the MSD function | ||
| 45 |     driver. This file should be included in projects that use the MSD | ||
| 46 |     \function driver. | ||
| 47 | |||
| 48 |     This file is located in the "\<Install Directory\>\\Microchip\\USB\\MSD | ||
| 49 |     Device Driver" directory. | ||
| 50 | |||
| 51 |     When including this file in a new project, this file can either be | ||
| 52 |     referenced from the directory in which it was installed or copied | ||
| 53 |     directly into the user application folder. If the first method is | ||
| 54 |     chosen to keep the file located in the folder in which it is installed | ||
| 55 |     then include paths need to be added so that the library and the | ||
| 56 |     application both know where to reference each others files. If the | ||
| 57 |     application folder is located in the same folder as the Microchip | ||
| 58 |     folder (like the current demo folders), then the following include | ||
| 59 |     paths need to be added to the application's project: | ||
| 60 | |||
| 61 |     . | ||
| 62 | |||
| 63 |     ..\\..\\Microchip\\Include | ||
| 64 | |||
| 65 |     If a different directory structure is used, modify the paths as | ||
| 66 |     required. An example using absolute paths instead of relative paths | ||
| 67 |     would be the following: | ||
| 68 | |||
| 69 |     C:\\Microchip Solutions\\Microchip\\Include | ||
| 70 | |||
| 71 |     C:\\Microchip Solutions\\My Demo Application | ||
| 72 | |||
| 73 |  Change History: | ||
| 74 |    Rev    Description | ||
| 75 |    ----   ------------------------------------------ | ||
| 76 |    2.6-   No Change | ||
| 77 |    2.7a | ||
| 78 | |||
| 79 |  ********************************************************************/ | ||
| 80 | #ifndef MSD_H | ||
| 81 | #define MSD_H | ||
| 82 | |||
| 83 | /** I N C L U D E S **********************************************************/ | ||
| 84 | #include "Compiler.h" | ||
| 85 | #include "GenericTypeDefs.h" | ||
| 86 | #include "MDD File System\FSDefs.h" | ||
| 87 | //#include "SD Card/sdcard.h" | ||
| 88 | |||
| 89 | /** D E F I N I T I O N S ****************************************************/ | ||
| 90 | |||
| 91 | /* MSD Interface Class Code */ | ||
| 92 | #define MSD_INTF                    0x08 | ||
| 93 | |||
| 94 | /* MSD Interface Class SubClass Codes */ | ||
| 95 | //Options - from usb_msc_overview_1[1].2.pdf | ||
| 96 | //  Supported | ||
| 97 | #define SCSI_TRANSPARENT    0x06 | ||
| 98 | //  Not-Supported | ||
| 99 | #define RBC                 0x01    // Reduced Block Commands (RBC) T10 Project 1240-D | ||
| 100 | #define SSF_8020i           0x02    // C/DVD devices typically use SSF-8020i or MMC-2 | ||
| 101 | #define MMC_2               0x02 | ||
| 102 | #define QIC_157             0x03    // Tape drives typically use QIC-157 command blocks | ||
| 103 | #define UFI                 0x04    // Typically a floppy disk drive (FDD) device | ||
| 104 | #define SSF_8070i           0x05    // Typically a floppy disk drive uses SSF-8070i commands | ||
| 105 | |||
| 106 | #define MSD_INTF_SUBCLASS          SCSI_TRANSPARENT | ||
| 107 | //#define MSD_INTF_SUBCLASS          RBC | ||
| 108 | |||
| 109 | /* MSD Interface Class Protocol Codes */ | ||
| 110 | #define MSD_PROTOCOL           0x50 | ||
| 111 | |||
| 112 | /* Class Commands */ | ||
| 113 | #define MSD_RESET 0xff | ||
| 114 | #define GET_MAX_LUN 0xfe | ||
| 115 | |||
| 116 | #define BLOCKLEN_512                0x0200 | ||
| 117 | |||
| 118 | #define STMSDTRIS TRISD0 | ||
| 119 | #define STRUNTRIS TRISD1 | ||
| 120 | #define STMSDLED LATDbits.LATD0 | ||
| 121 | #define STRUNLED LATDbits.LATD1 | ||
| 122 | #define ToggleRUNLED() STRUNLED = !STRUNLED; | ||
| 123 | |||
| 124 |     //**********************************************************DOM-IGNORE-BEGIN | ||
| 125 |     //Various States of Mass Storage Firmware (MSDTasks) | ||
| 126 |     //**********************************************************DOM-IGNORE-END | ||
| 127 | |||
| 128 |     //MSD_WAIT is when the MSD state machine is idle (returned by MSDTasks()) | ||
| 129 |     #define MSD_WAIT                            0x00 | ||
| 130 |     //MSD_DATA_IN is when the device is sending data (returned by MSDTasks()) | ||
| 131 |     #define MSD_DATA_IN                         0x01 | ||
| 132 |     //MSD_DATA_OUT is when the device is receiving data (returned by MSDTasks()) | ||
| 133 |     #define MSD_DATA_OUT                        0x02 | ||
| 134 |     //MSD_SEND_CSW is when the device is waiting to send the CSW (returned by MSDTasks()) | ||
| 135 |     #define MSD_SEND_CSW                        0x03 | ||
| 136 | |||
| 137 |     //States of the MSDProcessCommand state machine | ||
| 138 |     #define MSD_COMMAND_WAIT                    0xFF | ||
| 139 |     #define MSD_COMMAND_ERROR                   0xFE | ||
| 140 |     #define MSD_COMMAND_RESPONSE                0xFD | ||
| 141 |     #define MSD_COMMAND_RESPONSE_SEND           0xFC | ||
| 142 |     #define MSD_COMMAND_STALL                   0xFB | ||
| 143 | |||
| 144 |     /* SCSI Transparent Command Set Sub-class code */ | ||
| 145 |     #define MSD_INQUIRY 						0x12 | ||
| 146 |     #define MSD_READ_FORMAT_CAPACITY 			0x23			  | ||
| 147 |     #define MSD_READ_CAPACITY 					0x25 | ||
| 148 |     #define MSD_READ_10 						0x28 | ||
| 149 |     #define MSD_WRITE_10 						0x2a | ||
| 150 |     #define MSD_REQUEST_SENSE 					0x03 | ||
| 151 |     #define MSD_MODE_SENSE 						0x1a | ||
| 152 |     #define MSD_PREVENT_ALLOW_MEDIUM_REMOVAL 	0x1e | ||
| 153 |     #define MSD_TEST_UNIT_READY 				0x00 | ||
| 154 |     #define MSD_VERIFY 							0x2f | ||
| 155 |     #define MSD_STOP_START 						0x1b | ||
| 156 | |||
| 157 |     #define MSD_READ10_WAIT                     0x00 | ||
| 158 |     #define MSD_READ10_BLOCK                    0x01 | ||
| 159 |     #define MSD_READ10_SECTOR                   0x02 | ||
| 160 |     #define MSD_READ10_TX_SECTOR                0x03 | ||
| 161 |     #define MSD_READ10_TX_PACKET                0x04 | ||
| 162 | |||
| 163 |     #define MSD_WRITE10_WAIT                    0x00 | ||
| 164 |     #define MSD_WRITE10_BLOCK                   0x01 | ||
| 165 |     #define MSD_WRITE10_SECTOR                  0x02 | ||
| 166 |     #define MSD_WRITE10_RX_SECTOR               0x03 | ||
| 167 |     #define MSD_WRITE10_RX_PACKET               0x04 | ||
| 168 | |||
| 169 | //Define MSD_USE_BLOCKING in order to block the code in an  | ||
| 170 | //attempt to get better throughput. | ||
| 171 | //#define MSD_USE_BLOCKING | ||
| 172 | |||
| 173 | #define MSD_CSW_SIZE 0x0d	// 10 bytes CSW data | ||
| 174 | #define MSD_CBW_SIZE 0x1f	// 31 bytes CBW data | ||
| 175 | |||
| 176 | #define INVALID_CBW 1 | ||
| 177 | #define VALID_CBW !INVALID_CBW | ||
| 178 | |||
| 179 | /* Sense Key Error Codes */ | ||
| 180 | |||
| 181 | #define S_NO_SENSE 0x0 | ||
| 182 | #define S_RECOVERED_ERROR 0x1 | ||
| 183 | #define S_NOT_READY 0x2 | ||
| 184 | #define S_MEDIUM_ERROR 0x3 | ||
| 185 | #define S_HARDWARE_ERROR 0X4 | ||
| 186 | #define S_ILLEGAL_REQUEST 0x5 | ||
| 187 | #define S_UNIT_ATTENTION 0x6 | ||
| 188 | #define S_DATA_PROTECT 0x7 | ||
| 189 | #define S_BLANK_CHECK 0x8 | ||
| 190 | #define S_VENDOR_SPECIFIC 0x9 | ||
| 191 | #define S_COPY_ABORTED 0xa | ||
| 192 | #define S_ABORTED_COMMAND 0xb | ||
| 193 | #define S_OBSOLETE 0xc | ||
| 194 | #define S_VOLUME_OVERFLOW 0xd | ||
| 195 | #define S_MISCOMPARE 0xe | ||
| 196 | |||
| 197 | #define S_CURRENT 0x70 | ||
| 198 | #define S_DEFERRED 0x71 | ||
| 199 | |||
| 200 | /* ASC ASCQ Codes for Sense Data (only those that we plan to use) */ | ||
| 201 | // with sense key Illegal request for a command not supported | ||
| 202 | #define ASC_INVALID_COMMAND_OPCODE 0x20 | ||
| 203 | #define ASCQ_INVALID_COMMAND_OPCODE 0x00 | ||
| 204 | |||
| 205 | // from SPC-3 Table 185 | ||
| 206 | // with sense key Illegal Request for test unit ready | ||
| 207 | #define ASC_LOGICAL_UNIT_NOT_SUPPORTED 0x25 | ||
| 208 | #define ASCQ_LOGICAL_UNIT_NOT_SUPPORTED 0x00 | ||
| 209 | |||
| 210 | // with sense key Not ready | ||
| 211 | #define ASC_LOGICAL_UNIT_DOES_NOT_RESPOND 0x05 | ||
| 212 | #define ASCQ_LOGICAL_UNIT_DOES_NOT_RESPOND 0x00 | ||
| 213 | |||
| 214 | #define ASC_MEDIUM_NOT_PRESENT 0x3a | ||
| 215 | #define ASCQ_MEDIUM_NOT_PRESENT 0x00 | ||
| 216 | |||
| 217 | #define ASC_LOGICAL_UNIT_NOT_READY_CAUSE_NOT_REPORTABLE 0x04 | ||
| 218 | #define ASCQ_LOGICAL_UNIT_NOT_READY_CAUSE_NOT_REPORTABLE 0x00 | ||
| 219 | |||
| 220 | #define ASC_LOGICAL_UNIT_IN_PROCESS 0x04 | ||
| 221 | #define ASCQ_LOGICAL_UNIT_IN_PROCESS 0x01 | ||
| 222 | |||
| 223 | #define ASC_LOGICAL_UNIT_NOT_READY_INIT_REQD 0x04 | ||
| 224 | #define ASCQ_LOGICAL_UNIT_NOT_READY_INIT_REQD 0x02 | ||
| 225 | |||
| 226 | #define ASC_LOGICAL_UNIT_NOT_READY_INTERVENTION_REQD 0x04 | ||
| 227 | #define ASCQ_LOGICAL_UNIT_NOT_READY_INTERVENTION_REQD 0x03 | ||
| 228 | |||
| 229 | #define ASC_LOGICAL_UNIT_NOT_READY_FORMATTING 0x04 | ||
| 230 | #define ASCQ_LOGICAL_UNIT_NOT_READY_FORMATTING 0x04 | ||
| 231 | |||
| 232 | #define ASC_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE 0x21 | ||
| 233 | #define ASCQ_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE 0x00 | ||
| 234 | |||
| 235 | #define ASC_WRITE_PROTECTED 0x27 | ||
| 236 | #define ASCQ_WRITE_PROTECTED 0x00 | ||
| 237 | |||
| 238 | /** S T R U C T U R E S ******************************************************/ | ||
| 239 | /********************** ******************************************************/ | ||
| 240 | |||
| 241 | typedef struct _USB_MSD_CBW 		//31 bytes total Command Block Wrapper | ||
| 242 | { | ||
| 243 |     DWORD dCBWSignature;			// 55 53 42 43h | ||
| 244 |     DWORD dCBWTag;					// sent by host, device echos this value in CSW (associated a CSW with a CBW) | ||
| 245 |     DWORD dCBWDataTransferLength; 	// number of bytes of data host expects to transfer | ||
| 246 |     BYTE bCBWFlags; 				// CBW flags, bit 7 = 0-data out from host to device,  | ||
| 247 |     								//					= 1-device to host, rest bits 0 | ||
| 248 |     BYTE bCBWLUN;					// Most Significant 4bits are always zero, 0 in our case as only one logical unit | ||
| 249 |     BYTE bCBWCBLength;				// Here most significant 3bits are zero | ||
| 250 | 	BYTE CBWCB[16];		            // Command block to be executed by the device | ||
| 251 | } USB_MSD_CBW; | ||
| 252 | |||
| 253 | typedef struct { 					// Command Block for Read 10 (0x28)& Write 10 (0x2a)commands | ||
| 254 | 			BYTE Opcode;				 | ||
| 255 | 			BYTE Flags;						// b7-b5 RDProtect, b4 DPO, b3 FUA, b2 Reserved, b1 FUA_NV, b0 Obsolete | ||
| 256 | 			DWORD_VAL LBA;						//  | ||
| 257 | 			BYTE GroupNumber;				// b4-b0 is Group Number rest are reserved | ||
| 258 | 			WORD_VAL TransferLength; | ||
| 259 | 			BYTE Control; | ||
| 260 | } ReadWriteCB; | ||
| 261 | |||
| 262 | typedef struct {					// Inquiry command format | ||
| 263 | 	BYTE Opcode; | ||
| 264 | 	BYTE EVPD;				// only b0 is enable vital product data | ||
| 265 | 	BYTE PageCode; | ||
| 266 | 	WORD AllocationLength; | ||
| 267 | 	BYTE Control; | ||
| 268 | } InquiryCB; | ||
| 269 | |||
| 270 | typedef struct {					// Read Capacity 10 | ||
| 271 | 	BYTE Opcode; | ||
| 272 | 	BYTE Reserved1; | ||
| 273 | 	DWORD LBA;				// Logical Block Address | ||
| 274 | 	WORD Reserved2; | ||
| 275 | 	BYTE PMI;				// Partial medium Indicator b0 only | ||
| 276 | 	BYTE Control;  | ||
| 277 | } ReadCapacityCB; | ||
| 278 | |||
| 279 | typedef struct {					// Request Sense 0x03		 | ||
| 280 | 	BYTE Opcode; | ||
| 281 | 	BYTE Desc; | ||
| 282 | 	WORD Reserved; | ||
| 283 | 	BYTE AllocationLength; | ||
| 284 | 	BYTE Control; | ||
| 285 | } RequestSenseCB;	 | ||
| 286 | |||
| 287 | typedef struct {					// Mode Sense 0x1a | ||
| 288 | 	BYTE Opcode; | ||
| 289 | 	BYTE DBD;				// actually only b3 is used as disable block descriptor | ||
| 290 | 	BYTE PageCode;			// b7,b6 PC=Page Control, b5-b0 PageCode | ||
| 291 | 									// Page Control bits 00=> CurrentValue, 01=>Changeable Values,10=>Default Value, 11=>Saved Values | ||
| 292 | 	BYTE SubPageCode; | ||
| 293 | 	BYTE AllocationLength; | ||
| 294 | 	BYTE Control;		 | ||
| 295 | } ModeSenseCB; | ||
| 296 | |||
| 297 | typedef struct {					// PREVENT_ALLOW_MEDIUM_REMOVAL 0x1e | ||
| 298 | 	BYTE Opcode; | ||
| 299 | 	BYTE Reserved[3]; | ||
| 300 | 	BYTE Prevent;			// only b1-b0 is prevent, rest reserved | ||
| 301 | 	BYTE Control; | ||
| 302 | } PreventAllowMediumRemovalCB; | ||
| 303 | |||
| 304 | typedef struct {					// TEST_UNIT_READY 0x00 | ||
| 305 | 	BYTE Opcode; | ||
| 306 | 	DWORD Reserved; | ||
| 307 | 	BYTE Control;			 | ||
| 308 | } TestUnitReadyCB; | ||
| 309 | |||
| 310 | typedef struct {					// VERIFY 10 Command 0x2f | ||
| 311 | 	BYTE Opcode; | ||
| 312 | 	BYTE VRProtect;			// b7-b5 VRProtect, b4 DPO, b3-b2,Reserved, b1 BYTCHK, b0 Obsolete | ||
| 313 | 	DWORD LBA; | ||
| 314 | 	BYTE GroupNumber;		// b4-b0 Group Number, rest reserved | ||
| 315 | 	WORD VerificationLength;	 | ||
| 316 | 	BYTE Control; | ||
| 317 | } VerifyCB; | ||
| 318 | |||
| 319 | typedef struct {					// STOP_START 0x1b | ||
| 320 | 	BYTE Opcode; | ||
| 321 | 	BYTE Immed; | ||
| 322 | 	WORD Reserved; | ||
| 323 | 	BYTE Start;				// b7-b4 PowerCondition, b3-b2reserved, b1 LOEJ, b0 Start | ||
| 324 | 	BYTE Control; 	 | ||
| 325 | } StopStartCB;	 | ||
| 326 | |||
| 327 | |||
| 328 | typedef struct _USB_MSD_CSW			// Command Status Wrapper | ||
| 329 | { | ||
| 330 | 	DWORD dCSWSignature;			// 55 53 42 53h Signature of a CSW packet | ||
| 331 | 	DWORD dCSWTag;					// echo the dCBWTag of the CBW packet | ||
| 332 | 	DWORD dCSWDataResidue;			// difference in data expected (dCBWDataTransferLength) and actual amount processed/sent | ||
| 333 | 	BYTE bCSWStatus;				// 00h Command Passed, 01h Command Failed, 02h Phase Error, rest obsolete/reserved | ||
| 334 | } USB_MSD_CSW; | ||
| 335 | |||
| 336 | typedef struct  | ||
| 337 | { | ||
| 338 |  	BYTE Peripheral; 					// Peripheral_Qualifier:3; Peripheral_DevType:5; | ||
| 339 | 	BYTE Removble;						// removable medium bit7 = 0 means non removable, rest reserved | ||
| 340 | 	BYTE Version;						// version | ||
| 341 | 	BYTE Response_Data_Format;		// b7,b6 Obsolete, b5 Access control co-ordinator, b4 hierarchical addressing support  | ||
| 342 | 										// b3:0 response data format 2 indicates response is in format defined by spec | ||
| 343 | 	BYTE AdditionalLength;				// length in bytes of remaining in standard inquiry data | ||
| 344 | 	BYTE Sccstp; 						// b7 SCCS, b6 ACC, b5-b4 TGPS, b3 3PC, b2-b1 Reserved, b0 Protected  | ||
| 345 | 	BYTE bqueetc;						// b7 bque, b6- EncServ, b5-VS, b4-MultiP, b3-MChngr, b2-b1 Obsolete, b0-Addr16	 | ||
| 346 |     BYTE CmdQue;                        // b7-b6 Obsolete, b5-WBUS, b4-Sync, b3-Linked, b2 Obsolete,b1 Cmdque, b0-VS | ||
| 347 | 	char vendorID[8];	 | ||
| 348 | 	char productID[16]; | ||
| 349 | 	char productRev[4]; | ||
| 350 | } InquiryResponse; | ||
| 351 | |||
| 352 | typedef struct { | ||
| 353 | 	BYTE ModeDataLen; | ||
| 354 | 	BYTE MediumType; | ||
| 355 | 	unsigned Resv:4; | ||
| 356 | 	unsigned DPOFUA:1;					// 0 indicates DPO and FUA bits not supported | ||
| 357 | 	unsigned notused:2; | ||
| 358 | 	unsigned WP:1;						// 0 indicates not write protected		 | ||
| 359 | 	BYTE BlockDscLen;					// Block Descriptor Length | ||
| 360 | } tModeParamHdr; | ||
| 361 | |||
| 362 | /* Short LBA mode block descriptor (see Page 1009, SBC-2) */ | ||
| 363 | typedef struct { | ||
| 364 | 	BYTE NumBlocks[4]; | ||
| 365 | 	BYTE Resv;							// reserved | ||
| 366 | 	BYTE BlockLen[3]; | ||
| 367 | } tBlockDescriptor; | ||
| 368 | |||
| 369 | /* Page_0 mode page format */ | ||
| 370 | typedef struct { | ||
| 371 | |||
| 372 | 	unsigned PageCode:6;				// SPC-3 7.4.5 | ||
| 373 | 	unsigned SPF:1;						// SubPageFormat=0 means Page_0 format | ||
| 374 | 	unsigned PS:1;						// Parameters Saveable | ||
| 375 | |||
| 376 | 	BYTE PageLength;					// if 2..n bytes of mode parameters PageLength = n-1 | ||
| 377 | 	BYTE ModeParam[];					// mode parameters | ||
| 378 | } tModePage;	 | ||
| 379 | |||
| 380 | typedef struct { | ||
| 381 | 	tModeParamHdr Header; | ||
| 382 | 	tBlockDescriptor BlockDsc; | ||
| 383 | 	tModePage modePage; | ||
| 384 | } ModeSenseResponse; | ||
| 385 | |||
| 386 | |||
| 387 | /* Fixed format if Desc bit of request sense cbw is 0 */ | ||
| 388 | typedef union __attribute__((packed)){ | ||
| 389 | 	struct | ||
| 390 |     { | ||
| 391 |         BYTE _byte[18]; | ||
| 392 |     }; | ||
| 393 | 	struct __attribute__((packed)){ | ||
| 394 | 		unsigned ResponseCode:7;			// b6-b0 is Response Code Fixed or descriptor format | ||
| 395 | 		unsigned VALID:1;					// Set to 1 to indicate information field is a valid value | ||
| 396 | |||
| 397 | 		BYTE Obsolete; | ||
| 398 | |||
| 399 | 		unsigned SenseKey:4;				// Refer SPC-3 Section 4.5.6 | ||
| 400 | 		unsigned Resv:1;					 | ||
| 401 | 		unsigned ILI:1;						// Incorrect Length Indicator | ||
| 402 | 		unsigned EOM:1;						// End of Medium | ||
| 403 | 		unsigned FILEMARK:1; 				// for READ and SPACE commands | ||
| 404 | |||
| 405 | 		BYTE InformationB0;					// device type or command specific (SPC-33.1.18) | ||
| 406 |         BYTE InformationB1;					// device type or command specific (SPC-33.1.18) | ||
| 407 |         BYTE InformationB2;					// device type or command specific (SPC-33.1.18) | ||
| 408 |         BYTE InformationB3;					// device type or command specific (SPC-33.1.18) | ||
| 409 | 		BYTE AddSenseLen;					// number of additional sense bytes that follow <=244 | ||
| 410 | 		DWORD_VAL CmdSpecificInfo;				// depends on command on which exception occured | ||
| 411 | 		BYTE ASC;							// additional sense code  | ||
| 412 | 		BYTE ASCQ;							// additional sense code qualifier Section 4.5.2.1 SPC-3 | ||
| 413 | 		BYTE FRUC;							// Field Replaceable Unit Code 4.5.2.5 SPC-3 | ||
| 414 | |||
| 415 | 		BYTE SenseKeySpecific[3];			// msb is SKSV sense-key specific valied field set=> valid SKS | ||
| 416 | 											// 18-n additional sense bytes can be defined later | ||
| 417 | 											// 18 Bytes Request Sense Fixed Format | ||
| 418 | 	}; | ||
| 419 | } RequestSenseResponse; | ||
| 420 | |||
| 421 | /************************************************************************** | ||
| 422 |   Summary: | ||
| 423 |     LUN_FUNCTIONS is a structure of function pointers that tells the stack | ||
| 424 |     where to find each of the physical layer functions it is looking for. | ||
| 425 |     This structure needs to be defined for any project for PIC24F or PIC32. | ||
| 426 |   Description: | ||
| 427 |     LUN_FUNCTIONS is a structure of function pointers that tells the stack | ||
| 428 |     where to find each of the physical layer functions it is looking for. | ||
| 429 |     This structure needs to be defined for any project for PIC24F or PIC32. | ||
| 430 | |||
| 431 |     Typical Usage: | ||
| 432 |     <code> | ||
| 433 |         LUN_FUNCTIONS LUN[MAX_LUN + 1] = | ||
| 434 |         { | ||
| 435 |             { | ||
| 436 |                 &MDD_SDSPI_MediaInitialize, | ||
| 437 |                 &MDD_SDSPI_ReadCapacity, | ||
| 438 |                 &MDD_SDSPI_ReadSectorSize, | ||
| 439 |                 &MDD_SDSPI_MediaDetect, | ||
| 440 |                 &MDD_SDSPI_SectorRead, | ||
| 441 |                 &MDD_SDSPI_WriteProtectState, | ||
| 442 |                 &MDD_SDSPI_SectorWrite | ||
| 443 |             } | ||
| 444 |         }; | ||
| 445 |     </code> | ||
| 446 | |||
| 447 |     In the above code we are passing the address of the SDSPI functions to | ||
| 448 |     the corresponding member of the LUN_FUNCTIONS structure. In the above | ||
| 449 |     case we have created an array of LUN_FUNCTIONS structures so that it is | ||
| 450 |     possible to have multiple physical layers by merely increasing the | ||
| 451 |     MAX_LUN variable and by adding one more set of entries in the array. | ||
| 452 |     Please take caution to insure that each function is in the the correct | ||
| 453 |     location in the structure. Incorrect alignment will cause the USB stack | ||
| 454 |     to call the incorrect function for a given command. | ||
| 455 | |||
| 456 |     See the MDD File System Library for additional information about the | ||
| 457 |     available physical media, their requirements, and how to use their | ||
| 458 |     associated functions.                                                   | ||
| 459 |   **************************************************************************/ | ||
| 460 | typedef struct | ||
| 461 | { | ||
| 462 |     //Function pointer to the MediaInitialize() function of the physical media  | ||
| 463 |     //  being used.  | ||
| 464 |     MEDIA_INFORMATION* (*MediaInitialize)(); | ||
| 465 |     //Function pointer to the ReadCapacity() function of the physical media  | ||
| 466 |     //  being used. | ||
| 467 |     DWORD (*ReadCapacity)(); | ||
| 468 |     //Function pointer to the ReadSectorSize() function of the physical media  | ||
| 469 |     //  being used. | ||
| 470 |     WORD  (*ReadSectorSize)(); | ||
| 471 |     //Function pointer to the MediaDetect() function of the physical media  | ||
| 472 |     //  being used. | ||
| 473 |     BYTE  (*MediaDetect)(); | ||
| 474 |     //Function pointer to the SectorRead() function of the physical media being  | ||
| 475 |     //  used. | ||
| 476 |     BYTE  (*SectorRead)(DWORD sector_addr, BYTE* buffer); | ||
| 477 |     //Function pointer to the WriteProtectState() function of the physical  | ||
| 478 |     //  media being used. | ||
| 479 |     BYTE  (*WriteProtectState)(); | ||
| 480 |     //Function pointer to the SectorWrite() function of the physical media  | ||
| 481 |     //  being used. | ||
| 482 |     BYTE  (*SectorWrite)(DWORD sector_addr, BYTE* buffer, BYTE allowWriteToZero); | ||
| 483 | } LUN_FUNCTIONS; | ||
| 484 | |||
| 485 | /** Section: Externs *********************************************************/ | ||
| 486 | extern volatile USB_MSD_CBW msd_cbw; | ||
| 487 | extern volatile USB_MSD_CSW msd_csw; | ||
| 488 | extern volatile char msd_buffer[512]; | ||
| 489 | extern BOOL SoftDetach[MAX_LUN + 1]; | ||
| 490 | extern volatile CTRL_TRF_SETUP SetupPkt; | ||
| 491 | extern volatile BYTE CtrlTrfData[USB_EP0_BUFF_SIZE]; | ||
| 492 | |||
| 493 | |||
| 494 | /** Section: Public Prototypes ***********************************************/ | ||
| 495 | void USBCheckMSDRequest(void); | ||
| 496 | BYTE MSDTasks(void); | ||
| 497 | void USBMSDInit(void); | ||
| 498 | |||
| 499 | /************************************************************************** | ||
| 500 |     Function: | ||
| 501 |     void LUNSoftDetach(BYTE LUN) | ||
| 502 | |||
| 503 |     Summary: | ||
| 504 | |||
| 505 |     Description: | ||
| 506 | |||
| 507 |     Parameters: | ||
| 508 |         LUN - logical unit number to detach | ||
| 509 | |||
| 510 |     Return Values: | ||
| 511 |         None | ||
| 512 | |||
| 513 |     Remarks: | ||
| 514 |         Once a soft detached is initiated a soft attached, LUNSoftAttach(), | ||
| 515 |         on the same LUN must be performed before the device will re-attach | ||
| 516 | |||
| 517 |   **************************************************************************/ | ||
| 518 | #define LUNSoftDetach(LUN) SoftDetach[LUN]=TRUE; | ||
| 519 | |||
| 520 | /************************************************************************** | ||
| 521 |     Function: | ||
| 522 |     void LUNSoftAttach(BYTE LUN) | ||
| 523 | |||
| 524 |     Summary: | ||
| 525 | |||
| 526 |     Description: | ||
| 527 | |||
| 528 |     Parameters: | ||
| 529 |         LUN - logical unit number to detach | ||
| 530 | |||
| 531 |     Return Values: | ||
| 532 |         None | ||
| 533 | |||
| 534 |     Remarks: | ||
| 535 |         Once a soft detached is initiated a soft attached, LUNSoftAttach(), | ||
| 536 |         on the same LUN must be performed before the device will re-attach | ||
| 537 | |||
| 538 |   **************************************************************************/ | ||
| 539 | #define LUNSoftAttach(LUN) SoftDetach[LUN]=FALSE; | ||
| 540 | |||
| 541 | |||
| 542 | #endif | 
Powered by WebSVN v2.8.3