msdscsi.h

Go to the documentation of this file.
00001 /***************************************************************************/
00017 #ifndef __MSDSCSI_H
00018 #define __MSDSCSI_H
00019 
00020 /***************************************************************************/
00025 /***************************************************************************/
00030 #ifdef __cplusplus
00031 extern "C" {
00032 #endif
00033 
00034 #define SCSI_TESTUNIT_READY          0x00 
00035 #define SCSI_REQUESTSENSE            0x03 
00036 #define SCSI_INQUIRY                 0x12 
00037 #define SCSI_STARTSTOP_UNIT          0x1B 
00038 #define SCSI_READCAPACITY            0x25 
00039 #define SCSI_READ10                  0x28 
00040 #define SCSI_WRITE10                 0x2A 
00042 #define SCSI_READ10_LEN              10U  
00043 #define SCSI_WRITE10_LEN             10U  
00044 #define SCSI_INQUIRYDATA_LEN         36U  
00045 #define SCSI_REQUESTSENSE_LEN        6U   
00046 #define SCSI_REQUESTSENSEDATA_LEN    18U  
00047 #define SCSI_READCAPACITY_LEN        10U  
00048 #define SCSI_READCAPACITYDATA_LEN    8U   
00050 /**************************************************************************/
00053 EFM32_PACK_START(1)
00054 typedef struct
00055 {
00056   uint8_t  OpCode;                
00057   struct
00058   {
00059     uint8_t Evpd     : 1;         
00060     uint8_t Obsolete : 1;         
00061     uint8_t Reserved : 6;         
00062   };
00063   uint8_t  PageCode;              
00064   uint16_t AllocationLength;      
00065   uint8_t  Control;               
00066 } __attribute__ ((packed)) MSDSCSI_Inquiry_TypeDef;
00067 EFM32_PACK_END()
00068 
00069 /**************************************************************************/
00072 EFM32_PACK_START(1)
00073 typedef struct
00074 {
00075   struct
00076   {
00077     uint8_t PeripheralDeviceType : 5; 
00078     uint8_t PeripheralQualifier  : 3; 
00079   };
00080   struct
00081   {
00082     uint8_t Reserved1 : 7;        
00083     uint8_t Removable : 1;        
00084   };
00085   uint8_t Version;                
00086   struct
00087   {
00088     uint8_t ResponseDataFormat : 4; 
00089     uint8_t HiSup              : 1; 
00090     uint8_t NormACA            : 1; 
00091     uint8_t Obsolete1          : 2; 
00092   };
00093   uint8_t AdditionalLength;         
00094   struct
00095   {
00096     uint8_t Protect        : 1;     
00097     uint8_t Reserved2      : 2;     
00098     uint8_t ThirdPartyCode : 1;     
00099     uint8_t Tpgs           : 2;     
00100     uint8_t Acc            : 1;     
00101     uint8_t Sccs           : 1;     
00102   };
00103   struct
00104   {
00105     uint8_t Addr16    : 1;          
00106     uint8_t Obsolete2 : 2;          
00107     uint8_t MChngr    : 1;          
00108     uint8_t MultiP    : 1;          
00109     uint8_t Vs1       : 1;          
00110     uint8_t EncServ   : 1;          
00111     uint8_t BQue      : 1;          
00112   };
00113   struct
00114   {
00115     uint8_t Vs2       : 1;          
00116     uint8_t CmdQue    : 1;          
00117     uint8_t Obsolete3 : 1;          
00118     uint8_t Linked    : 1;          
00119     uint8_t Sync      : 1;          
00120     uint8_t Wbus16    : 1;          
00121     uint8_t Obsolete4 : 2;          
00122   };
00123   uint8_t T10VendorId[ 8 ];         
00124   uint8_t ProductId[ 16 ];          
00125   uint8_t ProductRevisionLevel[ 4 ]; 
00126 } __attribute__ ((packed)) MSDSCSI_InquiryData_TypeDef;
00127 EFM32_PACK_END()
00128 
00129 /**************************************************************************/
00132 EFM32_PACK_START(1)
00133 typedef struct
00134 {
00135   uint8_t OpCode;                 
00136   struct
00137   {
00138     uint8_t Desc      : 1;        
00139     uint8_t Reserved1 : 7;        
00140   };
00141   uint8_t Reserved2;              
00142   uint8_t Reserved3;              
00143   uint8_t AllocationLength;       
00144   uint8_t Control;                
00145 } __attribute__ ((packed)) MSDSCSI_RequestSense_TypeDef;
00146 EFM32_PACK_END()
00147 
00148 /**************************************************************************/
00151 EFM32_PACK_START(1)
00152 typedef struct
00153 {
00154   struct
00155   {
00156     uint8_t ResponseCode : 7;     
00157     uint8_t Valid        : 1;     
00158   };
00159   uint8_t  Obsolete;              
00160   struct
00161   {
00162     uint8_t SenseKey : 4;         
00163     uint8_t Reserved : 1;         
00164     uint8_t Ili      : 1;         
00165     uint8_t Eom      : 1;         
00166     uint8_t FileMark : 1;         
00167   };
00168   uint32_t Information;           
00169   uint8_t  AdditionalLength;      
00170   uint32_t CmdSpecificInfo;       
00171   uint8_t  Asc;                   
00172   uint8_t  Ascq;                  
00173   uint8_t  Fruc;                  
00174   struct
00175   {
00176     uint8_t SenseKeySpecific1 : 7;  
00177     uint8_t Sksv              : 1;  
00178   };
00179   uint8_t  SenseKeySpecific2;       
00180   uint8_t  SenseKeySpecific3;       
00181 } __attribute__ ((packed)) MSDSCSI_RequestSenseData_TypeDef;
00182 EFM32_PACK_END()
00183 
00184 /**************************************************************************/
00187 EFM32_PACK_START(1)
00188 typedef struct
00189 {
00190   uint8_t  OpCode;                
00191   struct
00192   {
00193     uint8_t Obsolete  : 1;        
00194     uint8_t Reserved1 : 7;        
00195   };
00196   uint32_t Lba;                   
00197   uint16_t Reserved2;             
00198   struct
00199   {
00200     uint8_t Pmi       : 1;        
00201     uint8_t Reserved3 : 7;        
00202   };
00203   uint8_t  Control;               
00204 } __attribute__ ((packed)) MSDSCSI_ReadCapacity_TypeDef;
00205 EFM32_PACK_END()
00206 
00207 /**************************************************************************/
00210 EFM32_PACK_START(1)
00211 typedef struct
00212 {
00213   uint32_t LogicalBlockAddress; 
00214   uint32_t LogicalBlockLength;  
00215 } __attribute__ ((packed)) MSDSCSI_ReadCapacityData_TypeDef;
00216 EFM32_PACK_END()
00217 
00218 /**************************************************************************/
00221 EFM32_PACK_START(1)
00222 typedef struct
00223 {
00224   uint8_t  OpCode;                
00225   struct
00226   {
00227     uint8_t Obsolete  : 1;        
00228     uint8_t FuaNv     : 1;        
00229     uint8_t Reserved1 : 1;        
00230     uint8_t Fua       : 1;        
00231     uint8_t Dpo       : 1;        
00232     uint8_t RdProtect : 3;        
00233   };
00234   uint32_t Lba;                   
00235   struct
00236   {
00237     uint8_t GroupNumber : 5;      
00238     uint8_t Reserved2   : 3;      
00239   };
00240   uint16_t TransferLength;        
00241   uint8_t  Control;               
00242 } __attribute__ ((packed)) MSDSCSI_Read10_TypeDef;
00243 EFM32_PACK_END()
00244 
00245 /**************************************************************************/
00248 EFM32_PACK_START(1)
00249 typedef struct
00250 {
00251   uint8_t  OpCode;                
00252   struct
00253   {
00254     uint8_t Obsolete  : 1;        
00255     uint8_t FuaNv     : 1;        
00256     uint8_t Reserved1 : 1;        
00257     uint8_t Fua       : 1;        
00258     uint8_t Dpo       : 1;        
00259     uint8_t WrProtect : 3;        
00260   };
00261   uint32_t Lba;                   
00262   struct
00263   {
00264     uint8_t GroupNumber : 5;      
00265     uint8_t Reserved2   : 3;      
00266   };
00267   uint16_t TransferLength;        
00268   uint8_t  Control;               
00269 } __attribute__ ((packed)) MSDSCSI_Write10_TypeDef;
00270 EFM32_PACK_END()
00271 
00272 /*** MSDSCSI Function prototypes ***/
00273 
00274 #if defined(USB_HOST)
00275 
00276 bool MSDSCSI_Init(USBH_Ep_TypeDef *out, USBH_Ep_TypeDef *in);
00277 bool MSDSCSI_Inquiry(MSDSCSI_InquiryData_TypeDef *data);
00278 bool MSDSCSI_Read10(uint32_t lba, uint16_t sectors, void *data);
00279 bool MSDSCSI_ReadCapacity(MSDSCSI_ReadCapacityData_TypeDef *data);
00280 bool MSDSCSI_RequestSense(MSDSCSI_RequestSenseData_TypeDef *data);
00281 bool MSDSCSI_TestUnitReady(void);
00282 bool MSDSCSI_Write10(uint32_t lba, uint16_t sectors, const void *data);
00283 
00284 #endif
00285 
00286 #ifdef __cplusplus
00287 }
00288 #endif
00289 
00293 #endif /* __MSDSCSI_H */