fix netradio mass_storage

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@270 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
wuyangyong 2009-12-31 15:40:59 +00:00
parent aecf1601d8
commit 620cde72e3
5 changed files with 40 additions and 64 deletions

View File

@ -22,7 +22,6 @@
/* Exported constants --------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/
#define MAL_OK 0 #define MAL_OK 0
#define MAL_FAIL 1 #define MAL_FAIL 1
#define MAX_LUN 1
/* Exported macro ------------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */ /* Exported functions ------------------------------------------------------- */

View File

@ -15,13 +15,13 @@
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "platform_config.h" #include "platform_config.h"
#include "sdcard.h"
#include "mass_mal.h" #include "mass_mal.h"
#include "rtthread.h" #include "rtthread.h"
uint32_t Mass_Memory_Size[2]; uint32_t Mass_Memory_Size[3];
uint32_t Mass_Block_Size[2]; uint32_t Mass_Block_Size[3];
uint32_t Mass_Block_Count[2]; uint32_t Mass_Block_Count[3];
uint32_t Max_Lun = 0;
rt_device_t dev_sdio = RT_NULL; rt_device_t dev_sdio = RT_NULL;

View File

@ -36,31 +36,30 @@ uint8_t Standard_Inquiry_Data[] =
0x00, 0x00,
0x00, 0x00,
/* Vendor Identification */ /* Vendor Identification */
'S', 'T', 'M', ' ', 'C', 'M', '-', '3', 'S', 'T', 'M', '3', '2', ' ', ' ', ' ',
/* Product Identification */ /* Product Identification */
'S', 'D', ' ', 'F', 'l', 'a', 's', 'h', ' ', 'n', 'e', 't', 'r', 'a', 'd', 'i', 'o', ' ',
'D', 'i', 's', 'k', ' ', ' ', ' ', 'D', 'I', 'S', 'K', '1', ' ', ' ',
/* Product Revision Level */ /* Product Revision Level */
'1', '.', '0', ' ' '1', '.', '0', ' '
}; };
uint8_t Standard_Inquiry_Data2[] = uint8_t Standard_Inquiry_Data2[] =
{ {
0x00, /* Direct Access Device *///磁盘设备 0x00, /* Direct Access Device */
//其中最高位D7为RMB。RMB=0表示不可移除设备。如果RMB=1则为可移除设备。
0x80, /* RMB = 1: Removable Medium */ 0x80, /* RMB = 1: Removable Medium */
0x02, /* Version: No conformance claim to standard */ 0x02, /* Version: No conformance claim to standard */
0x02, //数据响应格式 0x02, /* 数据响应格式 */
36 - 4, //附加数据长度为31字节 36 - 4, /* 附加数据长度为31字节 */
0x00, /* SCCS = 1: Storage Controller Component */ 0x00, /* SCCS = 1: Storage Controller Component */
0x00, 0x00,
0x00, 0x00,
/* Vendor Identification */ /* Vendor Identification */
'S', 'T', 'M', ' ', ' ', ' ', ' ', ' ', 'S', 'T', 'M', '3', '2', ' ', ' ', ' ',
/* Product Identification */ /* Product Identification */
'N', 'A', 'N', 'D', ' ', 'F', 'l', 'a', 's', 'h', ' ', 'n', 'e', 't', 'r', 'a', 'd', 'i', 'o', ' ',
'D', 'i', 's', 'k', ' ', 'D', 'I', 'S', 'K', '2', ' ', ' ',
/* Product Revision Level */ /* Product Revision Level */
'1', '.', '0', ' ' '1', '.', '0', ' '
}; };

View File

@ -21,6 +21,7 @@
#include "usb_conf.h" #include "usb_conf.h"
#include "usb_bot.h" #include "usb_bot.h"
#include "memory.h" #include "memory.h"
/* Private typedef -----------------------------------------------------------*/ /* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/
@ -81,26 +82,21 @@ void Mass_Storage_In (void)
void Mass_Storage_Out (void) void Mass_Storage_Out (void)
{ {
uint8_t CMD; uint8_t CMD;
CMD = CBW.CB[0];//得到上一次的? CMD = CBW.CB[0];
//得到端点2接收到的数据长度
Data_Len = GetEPRxCount(ENDP2); Data_Len = GetEPRxCount(ENDP2);
//print(" MS_Out:");//print_dec(Data_Len);
//读出数据到 Bulk_Data_Buff /* read data to Bulk_Data_Buff */
PMAToUserBufferCopy(Bulk_Data_Buff, ENDP2_RXADDR, Data_Len); PMAToUserBufferCopy(Bulk_Data_Buff, ENDP2_RXADDR, Data_Len);
switch (Bot_State) switch (Bot_State)
{ {
case BOT_IDLE://空闲状态 进入CBW解码 case BOT_IDLE:
//print("BOT_IDLE");
CBW_Decode(); CBW_Decode();
break; break;
case BOT_DATA_OUT://数据输出状态 case BOT_DATA_OUT:
//print("BOT_DATA_OUT");
if (CMD == SCSI_WRITE10) if (CMD == SCSI_WRITE10)
{ {
//print(" CMD == SCSI_WRITE10");
SCSI_Write10_Cmd(CBW.bLUN , SCSI_LBA , SCSI_BlkLen); SCSI_Write10_Cmd(CBW.bLUN , SCSI_LBA , SCSI_BlkLen);
break; break;
} }
@ -128,18 +124,17 @@ void CBW_Decode(void)
{ {
uint32_t Counter; uint32_t Counter;
//从Bulk_Data_Buff复制数据到CBW /* read data from Bulk_Data_Buff to CBW */
for (Counter = 0; Counter < Data_Len; Counter++) for (Counter = 0; Counter < Data_Len; Counter++)
{ {
*((uint8_t *)&CBW + Counter) = Bulk_Data_Buff[Counter]; *((uint8_t *)&CBW + Counter) = Bulk_Data_Buff[Counter];
} }
//复制TAG用于返回 /* copy return TAG */
CSW.dTag = CBW.dTag; CSW.dTag = CBW.dTag;
CSW.dDataResidue = CBW.dDataLength; CSW.dDataResidue = CBW.dDataLength;
//如果数据长度不等于CBW的长度
if (Data_Len != BOT_CBW_PACKET_LENGTH) if (Data_Len != BOT_CBW_PACKET_LENGTH)
{ {
//print(" Data_Len != BOT_CBW_PACKET_LENGTH");
Bot_Abort(BOTH_DIR); Bot_Abort(BOTH_DIR);
/* reset the CBW.dSignature to desible the clear feature until receiving a Mass storage reset*/ /* reset the CBW.dSignature to desible the clear feature until receiving a Mass storage reset*/
CBW.dSignature = 0; CBW.dSignature = 0;
@ -148,22 +143,18 @@ void CBW_Decode(void)
return; return;
} }
//读写数据
if ((CBW.CB[0] == SCSI_READ10 ) || (CBW.CB[0] == SCSI_WRITE10 )) if ((CBW.CB[0] == SCSI_READ10 ) || (CBW.CB[0] == SCSI_WRITE10 ))
{ {
/* Calculate Logical Block Address */ /* Calculate Logical Block Address */
//计算逻辑块地址 每个扇区512字节
SCSI_LBA = (CBW.CB[2] << 24) | (CBW.CB[3] << 16) | (CBW.CB[4] << 8) | CBW.CB[5]; SCSI_LBA = (CBW.CB[2] << 24) | (CBW.CB[3] << 16) | (CBW.CB[4] << 8) | CBW.CB[5];
/* Calculate the Number of Blocks to transfer */ /* Calculate the Number of Blocks to transfer */
//计算传送的块大小 以扇区为单位?
SCSI_BlkLen = (CBW.CB[7] << 8) | CBW.CB[8]; SCSI_BlkLen = (CBW.CB[7] << 8) | CBW.CB[8];
} }
//USBC /* USBC */
if (CBW.dSignature == BOT_CBW_SIGNATURE) if (CBW.dSignature == BOT_CBW_SIGNATURE)
{ {
/* Valid CBW */ /* Valid CBW */
//有效但参数错误
if ((CBW.bLUN > Max_Lun) || (CBW.bCBLength < 1) || (CBW.bCBLength > 16)) if ((CBW.bLUN > Max_Lun) || (CBW.bCBLength < 1) || (CBW.bCBLength > 16))
{ {
Bot_Abort(BOTH_DIR); Bot_Abort(BOTH_DIR);
@ -202,11 +193,9 @@ void CBW_Decode(void)
SCSI_TestUnitReady_Cmd(CBW.bLUN); SCSI_TestUnitReady_Cmd(CBW.bLUN);
break; break;
case SCSI_READ10: case SCSI_READ10:
//读数据
SCSI_Read10_Cmd(CBW.bLUN, SCSI_LBA , SCSI_BlkLen); SCSI_Read10_Cmd(CBW.bLUN, SCSI_LBA , SCSI_BlkLen);
break; break;
case SCSI_WRITE10: case SCSI_WRITE10:
//写数据
SCSI_Write10_Cmd(CBW.bLUN, SCSI_LBA , SCSI_BlkLen); SCSI_Write10_Cmd(CBW.bLUN, SCSI_LBA , SCSI_BlkLen);
break; break;
case SCSI_VERIFY10: case SCSI_VERIFY10:
@ -266,7 +255,6 @@ void CBW_Decode(void)
} }
else else
{ {
//无效的CBW
/* Invalid CBW */ /* Invalid CBW */
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);

View File

@ -23,15 +23,7 @@
#include "mass_mal.h" #include "mass_mal.h"
#include "usb_prop.h" #include "usb_prop.h"
/* Private typedef -----------------------------------------------------------*/ extern uint32_t Max_Lun;
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
#ifdef USE_STM3210B_EVAL
uint32_t Max_Lun = 0;
#else //USE_STM3210E_EVAL
uint32_t Max_Lun = 1;
#endif
DEVICE Device_Table = DEVICE Device_Table =
{ {
@ -258,13 +250,11 @@ RESULT MASS_Data_Setup(uint8_t RequestNo)
{ {
uint8_t *(*CopyRoutine)(uint16_t); uint8_t *(*CopyRoutine)(uint16_t);
//print("MASS_Data_Setup");
CopyRoutine = NULL; CopyRoutine = NULL;
if ((Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) if ((Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT))
&& (RequestNo == GET_MAX_LUN) && (pInformation->USBwValue == 0) && (RequestNo == GET_MAX_LUN) && (pInformation->USBwValue == 0)
&& (pInformation->USBwIndex == 0) && (pInformation->USBwLength == 0x01)) && (pInformation->USBwIndex == 0) && (pInformation->USBwLength == 0x01))
{ {
//print(" Get_Max_Lun\r\n");
CopyRoutine = Get_Max_Lun; CopyRoutine = Get_Max_Lun;
} }
else else