msdscsi.h

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