change usb msc lun=2
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@324 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
736bd9fd66
commit
9b282bd925
@ -86,8 +86,9 @@
|
|||||||
#define BLKVFY 0x04
|
#define BLKVFY 0x04
|
||||||
|
|
||||||
extern uint8_t Page00_Inquiry_Data[];
|
extern uint8_t Page00_Inquiry_Data[];
|
||||||
extern uint8_t Standard_Inquiry_Data[];
|
extern uint8_t Standard_Inquiry_Data1[];
|
||||||
extern uint8_t Standard_Inquiry_Data2[];
|
extern uint8_t Standard_Inquiry_Data2[];
|
||||||
|
extern uint8_t Standard_Inquiry_Data3[];
|
||||||
extern uint8_t Mode_Sense6_data[];
|
extern uint8_t Mode_Sense6_data[];
|
||||||
extern uint8_t Mode_Sense10_data[];
|
extern uint8_t Mode_Sense10_data[];
|
||||||
extern uint8_t Scsi_Sense_Data[];
|
extern uint8_t Scsi_Sense_Data[];
|
||||||
|
@ -21,7 +21,9 @@
|
|||||||
uint32_t Mass_Memory_Size[3];
|
uint32_t Mass_Memory_Size[3];
|
||||||
uint32_t Mass_Block_Size[3];
|
uint32_t Mass_Block_Size[3];
|
||||||
uint32_t Mass_Block_Count[3];
|
uint32_t Mass_Block_Count[3];
|
||||||
uint32_t Max_Lun = 0;
|
|
||||||
|
/* logic unit count; the first is 0 */
|
||||||
|
uint32_t Max_Lun = 2;
|
||||||
|
|
||||||
rt_device_t dev_sdio = RT_NULL;
|
rt_device_t dev_sdio = RT_NULL;
|
||||||
|
|
||||||
@ -34,6 +36,12 @@ uint16_t MAL_Init(uint8_t lun)
|
|||||||
case 0:
|
case 0:
|
||||||
status = MAL_OK;
|
status = MAL_OK;
|
||||||
break;
|
break;
|
||||||
|
case 1:
|
||||||
|
status = MAL_FAIL;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
status = MAL_FAIL;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return MAL_FAIL;
|
return MAL_FAIL;
|
||||||
}
|
}
|
||||||
@ -74,11 +82,24 @@ uint16_t MAL_Read(uint8_t lun, uint32_t Memory_Offset, uint32_t *Readbuff, uint1
|
|||||||
|
|
||||||
uint16_t MAL_GetStatus (uint8_t lun)
|
uint16_t MAL_GetStatus (uint8_t lun)
|
||||||
{
|
{
|
||||||
|
switch(lun)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
return MAL_OK;
|
||||||
|
case 1:
|
||||||
|
return MAL_FAIL;
|
||||||
|
case 2:
|
||||||
|
return MAL_FAIL;
|
||||||
|
default:
|
||||||
|
return MAL_FAIL;
|
||||||
|
}
|
||||||
|
#if 0
|
||||||
if(lun == 0)
|
if(lun == 0)
|
||||||
{
|
{
|
||||||
return MAL_OK;
|
return MAL_OK;
|
||||||
}
|
}
|
||||||
return MAL_FAIL;
|
return MAL_FAIL;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
|
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
|
||||||
|
@ -24,7 +24,7 @@ uint8_t Page00_Inquiry_Data[] =
|
|||||||
0x00,
|
0x00,
|
||||||
0x00 /* Supported Pages 00*/
|
0x00 /* Supported Pages 00*/
|
||||||
};
|
};
|
||||||
uint8_t Standard_Inquiry_Data[] =
|
uint8_t Standard_Inquiry_Data1[] =
|
||||||
{
|
{
|
||||||
0x00, /* Direct Access Device */
|
0x00, /* Direct Access Device */
|
||||||
0x80, /* RMB = 1: Removable Medium */
|
0x80, /* RMB = 1: Removable Medium */
|
||||||
@ -63,6 +63,26 @@ uint8_t Standard_Inquiry_Data2[] =
|
|||||||
/* Product Revision Level */
|
/* Product Revision Level */
|
||||||
'1', '.', '0', ' '
|
'1', '.', '0', ' '
|
||||||
};
|
};
|
||||||
|
uint8_t Standard_Inquiry_Data3[] =
|
||||||
|
{
|
||||||
|
0x00, /* Direct Access Device */
|
||||||
|
0x80, /* RMB = 1: Removable Medium */
|
||||||
|
|
||||||
|
0x02, /* Version: No conformance claim to standard */
|
||||||
|
0x02, /* 数据响应格式 */
|
||||||
|
|
||||||
|
36 - 4, /* 附加数据长度,为31字节 */
|
||||||
|
0x00, /* SCCS = 1: Storage Controller Component */
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
/* Vendor Identification */
|
||||||
|
'S', 'T', 'M', '3', '2', ' ', ' ', ' ',
|
||||||
|
/* Product Identification */
|
||||||
|
'n', 'e', 't', 'r', 'a', 'd', 'i', 'o', ' ',
|
||||||
|
'D', 'I', 'S', 'K', '3', ' ', ' ',
|
||||||
|
/* Product Revision Level */
|
||||||
|
'1', '.', '0', ' '
|
||||||
|
};
|
||||||
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
|
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
|
||||||
uint8_t Mode_Sense6_data[] =
|
uint8_t Mode_Sense6_data[] =
|
||||||
{
|
{
|
||||||
|
@ -32,9 +32,11 @@ extern uint8_t Bulk_Data_Buff[BULK_MAX_PACKET_SIZE]; /* data buffer*/
|
|||||||
extern uint8_t Bot_State;
|
extern uint8_t Bot_State;
|
||||||
extern Bulk_Only_CBW CBW;
|
extern Bulk_Only_CBW CBW;
|
||||||
extern Bulk_Only_CSW CSW;
|
extern Bulk_Only_CSW CSW;
|
||||||
extern uint32_t Mass_Memory_Size[2];
|
|
||||||
extern uint32_t Mass_Block_Size[2];
|
/* lun=3 1:SPI_FLASH 2:SD card 3:NAND-FLASH */
|
||||||
extern uint32_t Mass_Block_Count[2];
|
extern uint32_t Mass_Memory_Size[3];
|
||||||
|
extern uint32_t Mass_Block_Size[3];
|
||||||
|
extern uint32_t Mass_Block_Count[3];
|
||||||
|
|
||||||
/* Private function prototypes -----------------------------------------------*/
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
/* Private functions ---------------------------------------------------------*/
|
/* Private functions ---------------------------------------------------------*/
|
||||||
@ -48,33 +50,36 @@ extern uint32_t Mass_Block_Count[2];
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
void SCSI_Inquiry_Cmd(uint8_t lun)
|
void SCSI_Inquiry_Cmd(uint8_t lun)
|
||||||
{
|
{
|
||||||
uint8_t* Inquiry_Data;
|
uint8_t* Inquiry_Data;
|
||||||
uint16_t Inquiry_Data_Length;
|
uint16_t Inquiry_Data_Length;
|
||||||
|
|
||||||
if (CBW.CB[1] & 0x01)/*Evpd is set*/
|
if (CBW.CB[1] & 0x01)/*Evpd is set*/
|
||||||
{
|
|
||||||
Inquiry_Data = Page00_Inquiry_Data;
|
|
||||||
Inquiry_Data_Length = 5;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
if ( lun == 0)
|
|
||||||
{
|
{
|
||||||
Inquiry_Data = Standard_Inquiry_Data;
|
Inquiry_Data = Page00_Inquiry_Data;
|
||||||
|
Inquiry_Data_Length = 5;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Inquiry_Data = Standard_Inquiry_Data2;
|
switch(lun)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
Inquiry_Data = Standard_Inquiry_Data1;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
Inquiry_Data = Standard_Inquiry_Data2;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
Inquiry_Data = Standard_Inquiry_Data3;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CBW.CB[4] <= STANDARD_INQUIRY_DATA_LEN)
|
||||||
|
Inquiry_Data_Length = CBW.CB[4];
|
||||||
|
else
|
||||||
|
Inquiry_Data_Length = STANDARD_INQUIRY_DATA_LEN;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Transfer_Data_Request(Inquiry_Data, Inquiry_Data_Length);
|
||||||
if (CBW.CB[4] <= STANDARD_INQUIRY_DATA_LEN)
|
|
||||||
Inquiry_Data_Length = CBW.CB[4];
|
|
||||||
else
|
|
||||||
Inquiry_Data_Length = STANDARD_INQUIRY_DATA_LEN;
|
|
||||||
|
|
||||||
}
|
|
||||||
Transfer_Data_Request(Inquiry_Data, Inquiry_Data_Length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -87,22 +92,22 @@ void SCSI_Inquiry_Cmd(uint8_t lun)
|
|||||||
void SCSI_ReadFormatCapacity_Cmd(uint8_t lun)
|
void SCSI_ReadFormatCapacity_Cmd(uint8_t lun)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (MAL_GetStatus(lun) != 0 )
|
if (MAL_GetStatus(lun) != 0 )
|
||||||
{
|
{
|
||||||
Set_Scsi_Sense_Data(CBW.bLUN, NOT_READY, MEDIUM_NOT_PRESENT);
|
Set_Scsi_Sense_Data(CBW.bLUN, NOT_READY, MEDIUM_NOT_PRESENT);
|
||||||
Set_CSW (CSW_CMD_FAILED, SEND_CSW_ENABLE);
|
Set_CSW (CSW_CMD_FAILED, SEND_CSW_ENABLE);
|
||||||
Bot_Abort(DIR_IN);
|
Bot_Abort(DIR_IN);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ReadFormatCapacity_Data[4] = (uint8_t)(Mass_Block_Count[lun] >> 24);
|
ReadFormatCapacity_Data[4] = (uint8_t)(Mass_Block_Count[lun] >> 24);
|
||||||
ReadFormatCapacity_Data[5] = (uint8_t)(Mass_Block_Count[lun] >> 16);
|
ReadFormatCapacity_Data[5] = (uint8_t)(Mass_Block_Count[lun] >> 16);
|
||||||
ReadFormatCapacity_Data[6] = (uint8_t)(Mass_Block_Count[lun] >> 8);
|
ReadFormatCapacity_Data[6] = (uint8_t)(Mass_Block_Count[lun] >> 8);
|
||||||
ReadFormatCapacity_Data[7] = (uint8_t)(Mass_Block_Count[lun]);
|
ReadFormatCapacity_Data[7] = (uint8_t)(Mass_Block_Count[lun]);
|
||||||
|
|
||||||
ReadFormatCapacity_Data[9] = (uint8_t)(Mass_Block_Size[lun] >> 16);
|
ReadFormatCapacity_Data[9] = (uint8_t)(Mass_Block_Size[lun] >> 16);
|
||||||
ReadFormatCapacity_Data[10] = (uint8_t)(Mass_Block_Size[lun] >> 8);
|
ReadFormatCapacity_Data[10] = (uint8_t)(Mass_Block_Size[lun] >> 8);
|
||||||
ReadFormatCapacity_Data[11] = (uint8_t)(Mass_Block_Size[lun]);
|
ReadFormatCapacity_Data[11] = (uint8_t)(Mass_Block_Size[lun]);
|
||||||
Transfer_Data_Request(ReadFormatCapacity_Data, READ_FORMAT_CAPACITY_DATA_LEN);
|
Transfer_Data_Request(ReadFormatCapacity_Data, READ_FORMAT_CAPACITY_DATA_LEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -115,24 +120,24 @@ void SCSI_ReadFormatCapacity_Cmd(uint8_t lun)
|
|||||||
void SCSI_ReadCapacity10_Cmd(uint8_t lun)
|
void SCSI_ReadCapacity10_Cmd(uint8_t lun)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (MAL_GetStatus(lun))
|
if (MAL_GetStatus(lun))
|
||||||
{
|
{
|
||||||
Set_Scsi_Sense_Data(CBW.bLUN, NOT_READY, MEDIUM_NOT_PRESENT);
|
Set_Scsi_Sense_Data(CBW.bLUN, NOT_READY, MEDIUM_NOT_PRESENT);
|
||||||
Set_CSW (CSW_CMD_FAILED, SEND_CSW_ENABLE);
|
Set_CSW (CSW_CMD_FAILED, SEND_CSW_ENABLE);
|
||||||
Bot_Abort(DIR_IN);
|
Bot_Abort(DIR_IN);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReadCapacity10_Data[0] = (uint8_t)(Mass_Block_Count[lun] - 1 >> 24);
|
ReadCapacity10_Data[0] = (uint8_t)(Mass_Block_Count[lun] - 1 >> 24);
|
||||||
ReadCapacity10_Data[1] = (uint8_t)(Mass_Block_Count[lun] - 1 >> 16);
|
ReadCapacity10_Data[1] = (uint8_t)(Mass_Block_Count[lun] - 1 >> 16);
|
||||||
ReadCapacity10_Data[2] = (uint8_t)(Mass_Block_Count[lun] - 1 >> 8);
|
ReadCapacity10_Data[2] = (uint8_t)(Mass_Block_Count[lun] - 1 >> 8);
|
||||||
ReadCapacity10_Data[3] = (uint8_t)(Mass_Block_Count[lun] - 1);
|
ReadCapacity10_Data[3] = (uint8_t)(Mass_Block_Count[lun] - 1);
|
||||||
|
|
||||||
ReadCapacity10_Data[4] = (uint8_t)(Mass_Block_Size[lun] >> 24);
|
ReadCapacity10_Data[4] = (uint8_t)(Mass_Block_Size[lun] >> 24);
|
||||||
ReadCapacity10_Data[5] = (uint8_t)(Mass_Block_Size[lun] >> 16);
|
ReadCapacity10_Data[5] = (uint8_t)(Mass_Block_Size[lun] >> 16);
|
||||||
ReadCapacity10_Data[6] = (uint8_t)(Mass_Block_Size[lun] >> 8);
|
ReadCapacity10_Data[6] = (uint8_t)(Mass_Block_Size[lun] >> 8);
|
||||||
ReadCapacity10_Data[7] = (uint8_t)(Mass_Block_Size[lun]);
|
ReadCapacity10_Data[7] = (uint8_t)(Mass_Block_Size[lun]);
|
||||||
Transfer_Data_Request(ReadCapacity10_Data, READ_CAPACITY10_DATA_LEN);
|
Transfer_Data_Request(ReadCapacity10_Data, READ_CAPACITY10_DATA_LEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -144,7 +149,7 @@ void SCSI_ReadCapacity10_Cmd(uint8_t lun)
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
void SCSI_ModeSense6_Cmd (uint8_t lun)
|
void SCSI_ModeSense6_Cmd (uint8_t lun)
|
||||||
{
|
{
|
||||||
Transfer_Data_Request(Mode_Sense6_data, MODE_SENSE6_DATA_LEN);
|
Transfer_Data_Request(Mode_Sense6_data, MODE_SENSE6_DATA_LEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -156,7 +161,7 @@ void SCSI_ModeSense6_Cmd (uint8_t lun)
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
void SCSI_ModeSense10_Cmd (uint8_t lun)
|
void SCSI_ModeSense10_Cmd (uint8_t lun)
|
||||||
{
|
{
|
||||||
Transfer_Data_Request(Mode_Sense10_data, MODE_SENSE10_DATA_LEN);
|
Transfer_Data_Request(Mode_Sense10_data, MODE_SENSE10_DATA_LEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -168,17 +173,17 @@ void SCSI_ModeSense10_Cmd (uint8_t lun)
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
void SCSI_RequestSense_Cmd (uint8_t lun)
|
void SCSI_RequestSense_Cmd (uint8_t lun)
|
||||||
{
|
{
|
||||||
uint8_t Request_Sense_data_Length;
|
uint8_t Request_Sense_data_Length;
|
||||||
|
|
||||||
if (CBW.CB[4] <= REQUEST_SENSE_DATA_LEN)
|
if (CBW.CB[4] <= REQUEST_SENSE_DATA_LEN)
|
||||||
{
|
{
|
||||||
Request_Sense_data_Length = CBW.CB[4];
|
Request_Sense_data_Length = CBW.CB[4];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Request_Sense_data_Length = REQUEST_SENSE_DATA_LEN;
|
Request_Sense_data_Length = REQUEST_SENSE_DATA_LEN;
|
||||||
}
|
}
|
||||||
Transfer_Data_Request(Scsi_Sense_Data, Request_Sense_data_Length);
|
Transfer_Data_Request(Scsi_Sense_Data, Request_Sense_data_Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -191,8 +196,8 @@ void SCSI_RequestSense_Cmd (uint8_t lun)
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
void Set_Scsi_Sense_Data(uint8_t lun, uint8_t Sens_Key, uint8_t Asc)
|
void Set_Scsi_Sense_Data(uint8_t lun, uint8_t Sens_Key, uint8_t Asc)
|
||||||
{
|
{
|
||||||
Scsi_Sense_Data[2] = Sens_Key;
|
Scsi_Sense_Data[2] = Sens_Key;
|
||||||
Scsi_Sense_Data[12] = Asc;
|
Scsi_Sense_Data[12] = Asc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -204,7 +209,7 @@ void Set_Scsi_Sense_Data(uint8_t lun, uint8_t Sens_Key, uint8_t Asc)
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
void SCSI_Start_Stop_Unit_Cmd(uint8_t lun)
|
void SCSI_Start_Stop_Unit_Cmd(uint8_t lun)
|
||||||
{
|
{
|
||||||
Set_CSW (CSW_CMD_PASSED, SEND_CSW_ENABLE);
|
Set_CSW (CSW_CMD_PASSED, SEND_CSW_ENABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -217,31 +222,31 @@ void SCSI_Start_Stop_Unit_Cmd(uint8_t lun)
|
|||||||
void SCSI_Read10_Cmd(uint8_t lun , uint32_t LBA , uint32_t BlockNbr)
|
void SCSI_Read10_Cmd(uint8_t lun , uint32_t LBA , uint32_t BlockNbr)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (Bot_State == BOT_IDLE)
|
if (Bot_State == BOT_IDLE)
|
||||||
{
|
|
||||||
/*address out of range*/
|
|
||||||
if (!(SCSI_Address_Management(CBW.bLUN, SCSI_READ10, LBA, BlockNbr)))
|
|
||||||
{
|
{
|
||||||
return;
|
/*address out of range*/
|
||||||
}
|
if (!(SCSI_Address_Management(CBW.bLUN, SCSI_READ10, LBA, BlockNbr)))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ((CBW.bmFlags & 0x80) != 0)
|
if ((CBW.bmFlags & 0x80) != 0)
|
||||||
{
|
{
|
||||||
Bot_State = BOT_DATA_IN;
|
Bot_State = BOT_DATA_IN;
|
||||||
Read_Memory(lun, LBA , BlockNbr);
|
Read_Memory(lun, LBA , BlockNbr);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Bot_Abort(BOTH_DIR);
|
||||||
|
Set_Scsi_Sense_Data(CBW.bLUN, ILLEGAL_REQUEST, INVALID_FIELED_IN_COMMAND);
|
||||||
|
Set_CSW (CSW_CMD_FAILED, SEND_CSW_ENABLE);
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
else if (Bot_State == BOT_DATA_IN)
|
||||||
{
|
{
|
||||||
Bot_Abort(BOTH_DIR);
|
Read_Memory(lun , LBA , BlockNbr);
|
||||||
Set_Scsi_Sense_Data(CBW.bLUN, ILLEGAL_REQUEST, INVALID_FIELED_IN_COMMAND);
|
|
||||||
Set_CSW (CSW_CMD_FAILED, SEND_CSW_ENABLE);
|
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if (Bot_State == BOT_DATA_IN)
|
|
||||||
{
|
|
||||||
Read_Memory(lun , LBA , BlockNbr);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -254,30 +259,30 @@ void SCSI_Read10_Cmd(uint8_t lun , uint32_t LBA , uint32_t BlockNbr)
|
|||||||
void SCSI_Write10_Cmd(uint8_t lun , uint32_t LBA , uint32_t BlockNbr)
|
void SCSI_Write10_Cmd(uint8_t lun , uint32_t LBA , uint32_t BlockNbr)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (Bot_State == BOT_IDLE)
|
if (Bot_State == BOT_IDLE)
|
||||||
{
|
|
||||||
if (!(SCSI_Address_Management(CBW.bLUN, SCSI_WRITE10 , LBA, BlockNbr)))/*address out of range*/
|
|
||||||
{
|
{
|
||||||
return;
|
if (!(SCSI_Address_Management(CBW.bLUN, SCSI_WRITE10 , LBA, BlockNbr)))/*address out of range*/
|
||||||
}
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ((CBW.bmFlags & 0x80) == 0)
|
if ((CBW.bmFlags & 0x80) == 0)
|
||||||
{
|
{
|
||||||
Bot_State = BOT_DATA_OUT;
|
Bot_State = BOT_DATA_OUT;
|
||||||
SetEPRxStatus(ENDP2, EP_RX_VALID);
|
SetEPRxStatus(ENDP2, EP_RX_VALID);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Bot_Abort(DIR_IN);
|
||||||
|
Set_Scsi_Sense_Data(CBW.bLUN, ILLEGAL_REQUEST, INVALID_FIELED_IN_COMMAND);
|
||||||
|
Set_CSW (CSW_CMD_FAILED, SEND_CSW_DISABLE);
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
else if (Bot_State == BOT_DATA_OUT)
|
||||||
{
|
{
|
||||||
Bot_Abort(DIR_IN);
|
Write_Memory(lun , LBA , BlockNbr);
|
||||||
Set_Scsi_Sense_Data(CBW.bLUN, ILLEGAL_REQUEST, INVALID_FIELED_IN_COMMAND);
|
|
||||||
Set_CSW (CSW_CMD_FAILED, SEND_CSW_DISABLE);
|
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if (Bot_State == BOT_DATA_OUT)
|
|
||||||
{
|
|
||||||
Write_Memory(lun , LBA , BlockNbr);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -289,16 +294,16 @@ void SCSI_Write10_Cmd(uint8_t lun , uint32_t LBA , uint32_t BlockNbr)
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
void SCSI_Verify10_Cmd(uint8_t lun)
|
void SCSI_Verify10_Cmd(uint8_t lun)
|
||||||
{
|
{
|
||||||
if ((CBW.dDataLength == 0) && !(CBW.CB[1] & BLKVFY))/* BLKVFY not set*/
|
if ((CBW.dDataLength == 0) && !(CBW.CB[1] & BLKVFY))/* BLKVFY not set*/
|
||||||
{
|
{
|
||||||
Set_CSW (CSW_CMD_PASSED, SEND_CSW_ENABLE);
|
Set_CSW (CSW_CMD_PASSED, SEND_CSW_ENABLE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Bot_Abort(BOTH_DIR);
|
Bot_Abort(BOTH_DIR);
|
||||||
Set_Scsi_Sense_Data(CBW.bLUN, ILLEGAL_REQUEST, INVALID_FIELED_IN_COMMAND);
|
Set_Scsi_Sense_Data(CBW.bLUN, ILLEGAL_REQUEST, INVALID_FIELED_IN_COMMAND);
|
||||||
Set_CSW (CSW_CMD_FAILED, SEND_CSW_DISABLE);
|
Set_CSW (CSW_CMD_FAILED, SEND_CSW_DISABLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Function Name : SCSI_Valid_Cmd
|
* Function Name : SCSI_Valid_Cmd
|
||||||
@ -309,14 +314,14 @@ void SCSI_Verify10_Cmd(uint8_t lun)
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
void SCSI_Valid_Cmd(uint8_t lun)
|
void SCSI_Valid_Cmd(uint8_t lun)
|
||||||
{
|
{
|
||||||
if (CBW.dDataLength != 0)
|
if (CBW.dDataLength != 0)
|
||||||
{
|
{
|
||||||
Bot_Abort(BOTH_DIR);
|
Bot_Abort(BOTH_DIR);
|
||||||
Set_Scsi_Sense_Data(CBW.bLUN, ILLEGAL_REQUEST, INVALID_COMMAND);
|
Set_Scsi_Sense_Data(CBW.bLUN, ILLEGAL_REQUEST, INVALID_COMMAND);
|
||||||
Set_CSW (CSW_CMD_FAILED, SEND_CSW_DISABLE);
|
Set_CSW (CSW_CMD_FAILED, SEND_CSW_DISABLE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Set_CSW (CSW_CMD_PASSED, SEND_CSW_ENABLE);
|
Set_CSW (CSW_CMD_PASSED, SEND_CSW_ENABLE);
|
||||||
}
|
}
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Function Name : SCSI_Valid_Cmd
|
* Function Name : SCSI_Valid_Cmd
|
||||||
@ -327,17 +332,17 @@ void SCSI_Valid_Cmd(uint8_t lun)
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
void SCSI_TestUnitReady_Cmd(uint8_t lun)
|
void SCSI_TestUnitReady_Cmd(uint8_t lun)
|
||||||
{
|
{
|
||||||
if (MAL_GetStatus(lun))
|
if (MAL_GetStatus(lun))
|
||||||
{
|
{
|
||||||
Set_Scsi_Sense_Data(CBW.bLUN, NOT_READY, MEDIUM_NOT_PRESENT);
|
Set_Scsi_Sense_Data(CBW.bLUN, NOT_READY, MEDIUM_NOT_PRESENT);
|
||||||
Set_CSW (CSW_CMD_FAILED, SEND_CSW_ENABLE);
|
Set_CSW (CSW_CMD_FAILED, SEND_CSW_ENABLE);
|
||||||
Bot_Abort(DIR_IN);
|
Bot_Abort(DIR_IN);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Set_CSW (CSW_CMD_PASSED, SEND_CSW_ENABLE);
|
Set_CSW (CSW_CMD_PASSED, SEND_CSW_ENABLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Function Name : SCSI_Format_Cmd
|
* Function Name : SCSI_Format_Cmd
|
||||||
@ -348,19 +353,19 @@ void SCSI_TestUnitReady_Cmd(uint8_t lun)
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
void SCSI_Format_Cmd(uint8_t lun)
|
void SCSI_Format_Cmd(uint8_t lun)
|
||||||
{
|
{
|
||||||
if (MAL_GetStatus(lun))
|
if (MAL_GetStatus(lun))
|
||||||
{
|
{
|
||||||
Set_Scsi_Sense_Data(CBW.bLUN, NOT_READY, MEDIUM_NOT_PRESENT);
|
Set_Scsi_Sense_Data(CBW.bLUN, NOT_READY, MEDIUM_NOT_PRESENT);
|
||||||
Set_CSW (CSW_CMD_FAILED, SEND_CSW_ENABLE);
|
Set_CSW (CSW_CMD_FAILED, SEND_CSW_ENABLE);
|
||||||
Bot_Abort(DIR_IN);
|
Bot_Abort(DIR_IN);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#ifdef USE_STM3210E_EVAL
|
#ifdef USE_STM3210E_EVAL
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//NAND_Format();
|
//NAND_Format();
|
||||||
Set_CSW (CSW_CMD_PASSED, SEND_CSW_ENABLE);
|
Set_CSW (CSW_CMD_PASSED, SEND_CSW_ENABLE);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -372,23 +377,23 @@ void SCSI_Format_Cmd(uint8_t lun)
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
void SCSI_Invalid_Cmd(uint8_t lun)
|
void SCSI_Invalid_Cmd(uint8_t lun)
|
||||||
{
|
{
|
||||||
if (CBW.dDataLength == 0)
|
if (CBW.dDataLength == 0)
|
||||||
{
|
|
||||||
Bot_Abort(DIR_IN);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ((CBW.bmFlags & 0x80) != 0)
|
|
||||||
{
|
{
|
||||||
Bot_Abort(DIR_IN);
|
Bot_Abort(DIR_IN);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Bot_Abort(BOTH_DIR);
|
if ((CBW.bmFlags & 0x80) != 0)
|
||||||
|
{
|
||||||
|
Bot_Abort(DIR_IN);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Bot_Abort(BOTH_DIR);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
Set_Scsi_Sense_Data(CBW.bLUN, ILLEGAL_REQUEST, INVALID_COMMAND);
|
||||||
Set_Scsi_Sense_Data(CBW.bLUN, ILLEGAL_REQUEST, INVALID_COMMAND);
|
Set_CSW (CSW_CMD_FAILED, SEND_CSW_DISABLE);
|
||||||
Set_CSW (CSW_CMD_FAILED, SEND_CSW_DISABLE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -401,33 +406,33 @@ void SCSI_Invalid_Cmd(uint8_t lun)
|
|||||||
bool SCSI_Address_Management(uint8_t lun , uint8_t Cmd , uint32_t LBA , uint32_t BlockNbr)
|
bool SCSI_Address_Management(uint8_t lun , uint8_t Cmd , uint32_t LBA , uint32_t BlockNbr)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ((LBA + BlockNbr) > Mass_Block_Count[lun] )
|
if ((LBA + BlockNbr) > Mass_Block_Count[lun] )
|
||||||
{
|
|
||||||
if (Cmd == SCSI_WRITE10)
|
|
||||||
{
|
{
|
||||||
Bot_Abort(BOTH_DIR);
|
if (Cmd == SCSI_WRITE10)
|
||||||
|
{
|
||||||
|
Bot_Abort(BOTH_DIR);
|
||||||
|
}
|
||||||
|
Bot_Abort(DIR_IN);
|
||||||
|
Set_Scsi_Sense_Data(lun, ILLEGAL_REQUEST, ADDRESS_OUT_OF_RANGE);
|
||||||
|
Set_CSW (CSW_CMD_FAILED, SEND_CSW_DISABLE);
|
||||||
|
return (FALSE);
|
||||||
}
|
}
|
||||||
Bot_Abort(DIR_IN);
|
|
||||||
Set_Scsi_Sense_Data(lun, ILLEGAL_REQUEST, ADDRESS_OUT_OF_RANGE);
|
|
||||||
Set_CSW (CSW_CMD_FAILED, SEND_CSW_DISABLE);
|
|
||||||
return (FALSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (CBW.dDataLength != BlockNbr * Mass_Block_Size[lun])
|
if (CBW.dDataLength != BlockNbr * Mass_Block_Size[lun])
|
||||||
{
|
|
||||||
if (Cmd == SCSI_WRITE10)
|
|
||||||
{
|
{
|
||||||
Bot_Abort(BOTH_DIR);
|
if (Cmd == SCSI_WRITE10)
|
||||||
|
{
|
||||||
|
Bot_Abort(BOTH_DIR);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Bot_Abort(DIR_IN);
|
||||||
|
}
|
||||||
|
Set_Scsi_Sense_Data(CBW.bLUN, ILLEGAL_REQUEST, INVALID_FIELED_IN_COMMAND);
|
||||||
|
Set_CSW (CSW_CMD_FAILED, SEND_CSW_DISABLE);
|
||||||
|
return (FALSE);
|
||||||
}
|
}
|
||||||
else
|
return (TRUE);
|
||||||
{
|
|
||||||
Bot_Abort(DIR_IN);
|
|
||||||
}
|
|
||||||
Set_Scsi_Sense_Data(CBW.bLUN, ILLEGAL_REQUEST, INVALID_FIELED_IN_COMMAND);
|
|
||||||
Set_CSW (CSW_CMD_FAILED, SEND_CSW_DISABLE);
|
|
||||||
return (FALSE);
|
|
||||||
}
|
|
||||||
return (TRUE);
|
|
||||||
}
|
}
|
||||||
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
|
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user