1 //(c)2010 by Texas Instruments Incorporated, All Rights Reserved. 2 /*----------------------------------------------------------------------------+ 3 | | 4 | Texas Instruments | 5 | | 6 | MSP430 USB-Example (MSC Driver) | 7 | | 8 +-----------------------------------------------------------------------------+ 9 | Source: Msc_Scsi.h, File Version 1.02 | 10 | Description: This file contains all the structure,function declarations | 11 | used by stack | 12 | Author: Biju,MSP | 13 | | 14 | WHO WHEN WHAT | 15 | --- ---------- ------------------------------------------------ | 16 | MSP 2010/02/16 Created | 17 | Biju,MSP 2010/07/15 CV bug fix | 18 +----------------------------------------------------------------------------*/ 19 #ifndef _UMSC_SCSI_H_ 20 #define _UMSC_SCSI_H_ 21 22 #include <descriptors.h> 23 24 #ifdef __cplusplus 25 extern "C" 26 { 27 #endif 28 29 /*Macros for CBW, CSW signatures */ 30 #define CBW_SIGNATURE 0x43425355u 31 #define CSW_SIGNATURE 0x53425355u 32 33 /*CBW, CSW length in bytes */ 34 #define CBW_LENGTH 31 35 #define CSW_LENGTH 13 36 37 /*SCSI Commands - Mandatory only implemented */ 38 #define SCSI_TEST_UNIT_READY 0x00 39 #define SCSI_REQUEST_SENSE 0x03 40 #define SCSI_INQUIRY 0x12 41 #define SCSI_MODE_SENSE_6 0x1A 42 #define SCSI_MODE_SENSE_10 0x5A 43 #define SCSI_READ_CAPACITY_10 0x25 44 #define SCSI_READ_10 0x28 45 #define SCSI_WRITE_10 0x2A 46 #define SCSI_READ_FORMAT_CAPACITIES 0x23 47 #define SCSI_MODE_SELECT_6 0x15 48 #define SCSI_MODE_SELECT_10 0x55 49 #define PREVENT_ALLW_MDM 0x1E 50 #define START_STOP_UNIT 0x1B 51 #define SCSI_REPORT_LUNS 0xA0 52 #define SCSI_VERIFY 0x2F 53 54 #define SCSI_READ_TOC_PMA_ATIP 0x43 55 #define Scsi_Read_TOC_PMA_ATIP_F1_LEN 20 56 #define Scsi_Read_TOC_PMA_ATIP_F2_LEN 48 57 #define SCSI_GET_CONFIGURATION 0x46 58 #define SCSI_GET_CONFIGURATION_LEN 4 59 #define SCSI_EVENT_STATUS 0x4A 60 #define SCSI_EVENT_STATUS_LEN 8 61 #define SCSI_READ_DISC_INFORMATION 0x51 62 #define SCSI_SET_CD_SPEED 0xBB 63 #define SCSI_READ_DISC_INFORMATION_LEN 36 64 65 /*SCSI Status codes. Used in CSW response */ 66 #define SCSI_PASSED 0 67 #define SCSI_FAILED 1 68 #define SCSI_PHASE_ERROR 2 69 #define SCSI_READWRITE_FAIL 2 70 71 #define kUSBMSC_RWSuccess 0 72 #define kUSBMSC_RWNotReady 1 73 #define kUSBMSC_RWIllegalReq 2 74 #define kUSBMSC_RWUnitAttn 3 75 #define kUSBMSC_RWLbaOutOfRange 4 76 #define kUSBMSC_RWMedNotPresent 5 77 #define kUSBMSC_RWDevWriteFault 6 78 #define kUSBMSC_RWUnrecoveredRead 7 79 #define kUSBMSC_RWWriteProtected 8 80 81 82 /* Macros to indicate READ or WRITE operation */ 83 #define kUSBMSC_READ 1 84 #define kUSBMSC_WRITE 2 85 86 #define kUSBMSC_MEDIA_PRESENT 0x81 87 #define kUSBMSC_MEDIA_NOT_PRESENT 0x82 88 89 #define kUSBMSC_WRITE_PROTECTED 0x00 90 91 /* Defines for MSC SCSI State-Machine */ 92 #define MSC_READY 0x00 93 #define MSC_COMMAND_TRANSPORT 0x01 94 #define MSC_DATA_IN 0x02 95 #define MSC_DATA_OUT 0x03 96 #define MSC_STATUS_TRANSPORT 0x04 97 #define MSC_DATA 0x05 98 #define MSC_WAIT4RESET 0x06 99 100 /*Lengths of SCSI commands(in bytes) */ 101 #define SCSI_SCSI_INQUIRY_CMD_LEN 36 102 #define SCSI_READ_CAPACITY_CMD_LEN 8 103 #define SCSI_MODE_SENSE_6_CMD_LEN 4 104 #define SCSI_MODE_SENSE_10_CMD_LEN 8 105 #define SCSI_REQ_SENSE_CMD_LEN 18 106 #define SCSI_READ_FORMAT_CAPACITY_CMD_LEN 12 107 #define SCSI_REPORT_LUNS_CMD_LEN 16 108 109 /*----------------------------------------------------------------------------+ 110 | Type defines and structures | 111 +----------------------------------------------------------------------------*/ 112 /*CBW Structure */ 113 typedef struct { 114 DWORD dCBWSignature; 115 DWORD dCBWTag; 116 DWORD dCBWDataTransferLength; 117 BYTE bmCBWFlags; 118 BYTE bCBWLUN; 119 BYTE bCBWCBLength; 120 BYTE CBWCB[16]; 121 } CBW, *pCBW; 122 123 /*CSW structure */ 124 typedef struct { 125 DWORD dCSWSignature; 126 DWORD dCSWTag; 127 DWORD dCSWDataResidue; 128 BYTE bCSWStatus; 129 } CSW, *pCSW; 130 131 /*Request Response union(Required for Request sense command) */ 132 typedef struct { 133 BYTE ResponseCode : 7; 134 BYTE VALID : 1; 135 BYTE Obsolete; 136 BYTE SenseKey : 4; 137 BYTE Resv : 1; 138 BYTE ILI : 1; 139 BYTE EOM : 1; 140 BYTE FILEMARK : 1; 141 BYTE Information[4]; 142 BYTE AddSenseLen; 143 BYTE CmdSpecificInfo[4]; 144 BYTE ASC; 145 BYTE ASCQ; 146 BYTE FRUC; 147 BYTE SenseKeySpecific[3]; 148 BYTE padding[14]; /* padding to cover case where host requests 24 bytes of sense data */ 149 } REQUEST_SENSE_RESPONSE; 150 151 /*Read capacity union(Required for READ CAPACITY command)*/ 152 typedef struct { 153 DWORD Last_LBA; 154 BYTE Resv; 155 BYTE Size_LBA[3]; 156 } SCSI_READ_CAPACITY; 157 158 /*Structure internal to stack for holding LBA,buffer addr etc information*/ 159 typedef struct { 160 //BYTE intfNum; 161 BYTE lun; 162 BYTE operation; 163 DWORD lba; 164 BYTE lbCount; 165 BYTE *bufferAddr; 166 BYTE returnCode; 167 BYTE XorY; 168 BYTE xBufFull; 169 WORD xWordCnt; 170 BYTE yBufFull; 171 WORD yWordCnt; 172 BYTE bufferProcessed; 173 BYTE firstFlag; 174 DWORD xlba; 175 BYTE xlbaCount; 176 DWORD ylba; 177 BYTE ylbaCount; 178 179 }USBMSC_RWbuf_Info; 180 181 /*Media info structure */ 182 struct USBMSC_mediaInfoStr { 183 DWORD lastBlockLba; 184 DWORD bytesPerBlock; 185 BYTE mediaPresent; 186 BYTE mediaChanged; 187 BYTE writeProtected; 188 }; 189 190 /*Lun entry Structures */ 191 struct _LUN_entry_struct { 192 BYTE number; 193 BYTE PDT; 194 BYTE removable; 195 char t10VID[8]; 196 char t10PID[16]; 197 char t10rev[4]; 198 }; 199 200 struct config_struct { 201 struct _LUN_entry_struct LUN[MSC_MAX_LUN_NUMBER]; 202 }; 203 204 struct _Report_Luns { 205 BYTE LunListLength[4]; 206 BYTE Reserved[4]; 207 BYTE LunList1[8]; 208 }; 209 210 struct _Scsi_Read_Capacity { 211 BYTE lLba[4]; //Last logical block address 212 BYTE bLength[4]; //Block length, in this case 0x200 = 512 bytes for each Logical Block 213 }; 214 215 //structure for controlling WRITE phase (HOST to MSP430) 216 struct _MscWriteControl { 217 DWORD dwBytesToReceiveLeft; //holds how many bytes is still requested by WRITE operation: 218 //Host to MSP430. 219 WORD wFreeBytesLeft; //free bytes left in UserBuffer 220 DWORD lba; //holds the current LBA number. This is the first LBA in the UserBuffer 221 BYTE *pUserBuffer; //holds the current position of user's receiving buffer. 222 //If NULL- no receiving operation started 223 WORD wCurrentByte; //how many bytes in current LBA are received 224 WORD lbaCount; //how many LBA we have received in current User Buffer 225 BYTE * pCT1; //holds current EPBCTxx register 226 BYTE * pCT2; //holds next EPBCTxx register 227 BYTE * pEP2; //holds addr of the next EP buffer 228 BYTE bCurrentBufferXY; //indicates which buffer is used by host to transmit data via OUT 229 BYTE bWriteProcessing; //indicated if the current state is DATA WRITE phase or CBW receiwing 230 BYTE XorY; 231 }; 232 233 //structure for controlling READ phase (MSP430 to HOST) 234 struct _MscReadControl { 235 DWORD dwBytesToSendLeft; //holds how many bytes is still requested by WRITE operation (Host to MSP430) 236 BYTE *pUserBuffer; //holds the current position of user's receiving buffer. 237 //If NULL- no receiving operation started 238 DWORD lba; //holds the current LBA number. This is the first LBA in the UserBuffer. 239 BYTE * pCT1; //holds current EPBCTxx register 240 BYTE * pCT2; //holds next EPBCTxx register 241 BYTE * pEP2; //holds addr of the next EP buffer 242 WORD lbaCount; //how many LBA we have to send to Host 243 BYTE bCurrentBufferXY; //indicates which buffer is used by host to transmit data via OUT 244 BYTE bReadProcessing; //indicated if the current state is DATA READ phase or CSW sending 245 //initiated by McsDataSend() 246 BYTE XorY; 247 }; 248 249 //structure for common control of MSC stack 250 struct _MscControl { 251 WORD wMscUserBufferSize; 252 WORD lbaSize; //limitid to WORD, but could be increased if required. 253 BYTE lbaBufCapacity; //how many LBAs (max) contains UserBuffer for read/write operation (>=1) 254 BYTE *xBufferAddr; 255 BYTE *yBufferAddr; 256 BYTE bMediaPresent; 257 BYTE bWriteProtected; 258 }; 259 260 struct _MscState { 261 volatile DWORD Scsi_Residue; 262 volatile BYTE Scsi_Status; /*Variable to track command status */ 263 BOOL bMcsCommandSupported; /*Flag to indicate read/write command is recieved from host */ 264 BOOL bMscCbwReceived; /*Flag to inidicate whether any CBW recieved from host*/ 265 BOOL bMscSendCsw; 266 BOOL isMSCConfigured; 267 BYTE bUnitAttention; 268 BYTE bMscCbwFailed; 269 BYTE bMscResetRequired; 270 BYTE stallEndpoint; 271 }; 272 273 extern struct _MscWriteControl MscWriteControl; 274 extern struct _MscReadControl MscReadControl; 275 extern struct _MscControl MscControl[]; 276 277 /*----------------------------------------------------------------------------+ 278 | Extern Variables | 279 +----------------------------------------------------------------------------*/ 280 281 extern CBW cbw; 282 extern CSW csw; 283 extern REQUEST_SENSE_RESPONSE RequestSenseResponse; 284 285 /*----------------------------------------------------------------------------+ 286 | Function Prototypes | 287 +----------------------------------------------------------------------------*/ 288 289 /*SCSI Wrapper functions */ 290 BYTE Scsi_Cmd_Parser (BYTE opcode); 291 BYTE Scsi_Send_CSW (BYTE intfNum); 292 293 /*Function to reset MSC SCSI state machine */ 294 VOID Msc_ResetStateMachine(VOID); 295 VOID Msc_ResetFlags(VOID); 296 VOID Msc_ResetStruct(VOID); 297 VOID SET_RequestsenseNotReady(VOID); 298 VOID SET_RequestsenseMediaNotPresent(VOID); 299 VOID MscResetCtrlLun(VOID); 300 301 USBMSC_RWbuf_Info* USBMSC_fetchInfoStruct(VOID); 302 #ifdef __cplusplus 303 } 304 #endif 305 #endif //_MSC_SCSI_H_ 306