2022-03-26 20:51:40 +08:00

293 lines
14 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* 2014.09.09
*****************************************
** Copyright (C) W.ch 1999-2019 **
** Web: http://wch.cn **
*****************************************
** USB-flash File Interface for CH583 **
** KEIL423, gcc 8.20 **
*****************************************
*/
/* CHRV3 U<><55><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ϵͳ<CFB5>ӿ<EFBFBD>, ֧<><D6A7>: FAT12/FAT16/FAT32 */
//#define DISK_BASE_BUF_LEN 512 /* Ĭ<>ϵĴ<CFB5><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>СΪ512<31>ֽ<EFBFBD>(<28><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>Ϊ2048<34><38><EFBFBD><EFBFBD>4096<39><36>֧<EFBFBD><D6A7>ijЩ<C4B3><D0A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>U<EFBFBD><55>),Ϊ0<CEAA><30><EFBFBD><EFBFBD>ֹ<EFBFBD>ڱ<EFBFBD><DAB1>ļ<EFBFBD><C4BC>ж<EFBFBD><D0B6><EFBFBD><E5BBBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD>pDISK_BASE_BUF<55><46>ָ<EFBFBD><D6B8> */
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>ô<EFBFBD><C3B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Խ<EFBFBD>ԼRAM,<2C><>ô<EFBFBD>ɽ<EFBFBD>DISK_BASE_BUF_LEN<45><4E><EFBFBD><EFBFBD>Ϊ0<CEAA>Խ<EFBFBD>ֹ<EFBFBD>ڱ<EFBFBD><DAB1>ļ<EFBFBD><C4BC>ж<EFBFBD><D0B6><EFBFBD><E5BBBA><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>Ӧ<EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD>CHRV3LibInit֮ǰ<D6AE><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õĻ<C3B5><C4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>pDISK_BASE_BUF<55><46><EFBFBD><EFBFBD> */
//#define NO_DEFAULT_ACCESS_SECTOR 1 /* <20><>ֹĬ<D6B9>ϵĴ<CFB5><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>д<EFBFBD>ij<EFBFBD><C4B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
//#define NO_DEFAULT_DISK_CONNECT 1 /* <20><>ֹĬ<D6B9>ϵļ<CFB5><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>д<EFBFBD>ij<EFBFBD><C4B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
//#define NO_DEFAULT_FILE_ENUMER 1 /* <20><>ֹĬ<D6B9>ϵ<EFBFBD><CFB5>ļ<EFBFBD><C4BC><EFBFBD>ö<EFBFBD>ٻص<D9BB><D8B5><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>д<EFBFBD>ij<EFBFBD><C4B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
#include "CH58x_common.h"
#include "CHRV3UFI.h"
UINT8 CtrlGetConfigDescrTB(void) // <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>TxBuffer<65><72>
{
return (CtrlGetConfigDescr());
}
CMD_PARAM_I mCmdParam; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
#if DISK_BASE_BUF_LEN > 0
//UINT8 DISK_BASE_BUF[ DISK_BASE_BUF_LEN ] __attribute__((at(BA_RAM+SZ_RAM/2))); /* <20>ⲿRAM<41>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊһ<CEAA><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><C4B3><EFBFBD> */
UINT8 DISK_BASE_BUF[DISK_BASE_BUF_LEN] __attribute__((aligned(4))); /* <20>ⲿRAM<41>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊһ<CEAA><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><C4B3><EFBFBD> */
//UINT8 DISK_FAT_BUF[ DISK_BASE_BUF_LEN ] __attribute__((aligned (4))); /* <20>ⲿRAM<41>Ĵ<EFBFBD><C4B4><EFBFBD>FAT<41><54><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊһ<CEAA><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><C4B3><EFBFBD> */
#endif
/* <20><><EFBFBD>³<EFBFBD><C2B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ը<EFBFBD><D4B8><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>޸<EFBFBD> */
#ifndef NO_DEFAULT_ACCESS_SECTOR /* <20><>Ӧ<EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD>NO_DEFAULT_ACCESS_SECTOR<4F><52><EFBFBD>Խ<EFBFBD>ֹĬ<D6B9>ϵĴ<CFB5><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD><><C8BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>д<EFBFBD>ij<EFBFBD><C4B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
//if ( use_external_interface ) { // <20>滻U<E6BBBB><55><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ײ<EFBFBD><D7B2><EFBFBD>д<EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD>
// CHRV3vSectorSize=512; // <20><><EFBFBD><EFBFBD>ʵ<EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>512<31>ı<EFBFBD><C4B1><EFBFBD>,<2C><>ֵ<EFBFBD>Ǵ<EFBFBD><C7B4>̵<EFBFBD><CCB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
// CHRV3vSectorSizeB=9; // <20><><EFBFBD><EFBFBD>ʵ<EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>,512<31><32><EFBFBD><EFBFBD>Ӧ9,1024<32><34>Ӧ10,2048<34><38>Ӧ11
// CHRV3DiskStatus=DISK_MOUNTED; // ǿ<>ƿ<EFBFBD><C6BF><EFBFBD><E8B1B8><EFBFBD>ӳɹ<D3B3><><D6BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ϵͳ)
//}
UINT8 CHRV3ReadSector(UINT8 SectCount, PUINT8 DataBuf) /* <20>Ӵ<EFBFBD><D3B4>̶<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
{
UINT8 retry;
// if ( use_external_interface ) return( extReadSector( CHRV3vLbaCurrent, SectCount, DataBuf ) ); /* <20>ⲿ<EFBFBD>ӿ<EFBFBD> */
for(retry = 0; retry < 3; retry++)
{ /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
pCBW->mCBW_DataLen = (UINT32)SectCount << CHRV3vSectorSizeB; /* <20><><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><E4B3A4> */
pCBW->mCBW_Flag = 0x80;
pCBW->mCBW_LUN = CHRV3vCurrentLun;
pCBW->mCBW_CB_Len = 10;
pCBW->mCBW_CB_Buf[0] = SPC_CMD_READ10;
pCBW->mCBW_CB_Buf[1] = 0x00;
pCBW->mCBW_CB_Buf[2] = (UINT8)(CHRV3vLbaCurrent >> 24);
pCBW->mCBW_CB_Buf[3] = (UINT8)(CHRV3vLbaCurrent >> 16);
pCBW->mCBW_CB_Buf[4] = (UINT8)(CHRV3vLbaCurrent >> 8);
pCBW->mCBW_CB_Buf[5] = (UINT8)(CHRV3vLbaCurrent);
pCBW->mCBW_CB_Buf[6] = 0x00;
pCBW->mCBW_CB_Buf[7] = 0x00;
pCBW->mCBW_CB_Buf[8] = SectCount;
pCBW->mCBW_CB_Buf[9] = 0x00;
CHRV3BulkOnlyCmd(DataBuf); /* ִ<>л<EFBFBD><D0BB><EFBFBD>BulkOnlyЭ<79><D0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
if(CHRV3IntStatus == ERR_SUCCESS)
{
return (ERR_SUCCESS);
}
CHRV3IntStatus = CHRV3AnalyzeError(retry);
if(CHRV3IntStatus != ERR_SUCCESS)
{
return (CHRV3IntStatus);
}
}
return (CHRV3IntStatus = ERR_USB_DISK_ERR); /* <20><><EFBFBD>̲<EFBFBD><CCB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
}
#ifdef EN_DISK_WRITE
UINT8 CHRV3WriteSector(UINT8 SectCount, PUINT8 DataBuf) /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>еĶ<D0B5><C4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
{
UINT8 retry;
// if ( use_external_interface ) return( extWriteSector( CHRV3vLbaCurrent, SectCount, DataBuf ) ); /* <20>ⲿ<EFBFBD>ӿ<EFBFBD> */
for(retry = 0; retry < 3; retry++)
{ /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
pCBW->mCBW_DataLen = (UINT32)SectCount << CHRV3vSectorSizeB; /* <20><><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><E4B3A4> */
pCBW->mCBW_Flag = 0x00;
pCBW->mCBW_LUN = CHRV3vCurrentLun;
pCBW->mCBW_CB_Len = 10;
pCBW->mCBW_CB_Buf[0] = SPC_CMD_WRITE10;
pCBW->mCBW_CB_Buf[1] = 0x00;
pCBW->mCBW_CB_Buf[2] = (UINT8)(CHRV3vLbaCurrent >> 24);
pCBW->mCBW_CB_Buf[3] = (UINT8)(CHRV3vLbaCurrent >> 16);
pCBW->mCBW_CB_Buf[4] = (UINT8)(CHRV3vLbaCurrent >> 8);
pCBW->mCBW_CB_Buf[5] = (UINT8)(CHRV3vLbaCurrent);
pCBW->mCBW_CB_Buf[6] = 0x00;
pCBW->mCBW_CB_Buf[7] = 0x00;
pCBW->mCBW_CB_Buf[8] = SectCount;
pCBW->mCBW_CB_Buf[9] = 0x00;
CHRV3BulkOnlyCmd(DataBuf); /* ִ<>л<EFBFBD><D0BB><EFBFBD>BulkOnlyЭ<79><D0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
if(CHRV3IntStatus == ERR_SUCCESS)
{
mDelayuS(200); /* д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ */
return (ERR_SUCCESS);
}
CHRV3IntStatus = CHRV3AnalyzeError(retry);
if(CHRV3IntStatus != ERR_SUCCESS)
{
return (CHRV3IntStatus);
}
}
return (CHRV3IntStatus = ERR_USB_DISK_ERR); /* <20><><EFBFBD>̲<EFBFBD><CCB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
}
#endif
#endif // NO_DEFAULT_ACCESS_SECTOR
#ifndef NO_DEFAULT_DISK_CONNECT /* <20><>Ӧ<EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD>NO_DEFAULT_DISK_CONNECT<43><54><EFBFBD>Խ<EFBFBD>ֹĬ<D6B9>ϵļ<CFB5><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD><><C8BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>д<EFBFBD>ij<EFBFBD><C4B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
/*
Լ<EFBFBD><EFBFBD>: USB<53><EFBFBD><E8B1B8>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<28>ο<EFBFBD>USB_DEVICE_ADDR)
<EFBFBD><EFBFBD>ֵַ <20>豸λ<E8B1B8><CEBB>
0x02 <20><><EFBFBD><EFBFBD>Root-HUB0<42>µ<EFBFBD>USB<53><EFBFBD><E8B1B8><EFBFBD>ⲿHUB
0x03 <20><><EFBFBD><EFBFBD>Root-HUB1<42>µ<EFBFBD>USB<53><EFBFBD><E8B1B8><EFBFBD>ⲿHUB
0x1x <20><><EFBFBD><EFBFBD>Root-HUB0<42>µ<EFBFBD><C2B5>ⲿHUB<55>Ķ˿<C4B6>x<EFBFBD>µ<EFBFBD>USB<53>豸,xΪ1~n
0x2x <20><><EFBFBD><EFBFBD>Root-HUB1<42>µ<EFBFBD><C2B5>ⲿHUB<55>Ķ˿<C4B6>x<EFBFBD>µ<EFBFBD>USB<53>豸,xΪ1~n
*/
//#define UHUB_DEV_ADDR ( CHRV3vRootPort ? R8_USB1_DEV_AD : R8_USB0_DEV_AD )
//#define UHUB_MIS_STAT ( CHRV3vRootPort ? R8_USB1_MIS_ST : R8_USB0_MIS_ST )
//#define UHUB_HOST_CTRL ( CHRV3vRootPort ? R8_UHOST1_CTRL : R8_UHOST0_CTRL )
//#define UHUB_INT_FLAG ( CHRV3vRootPort ? R8_USB1_INT_FG : R8_USB0_INT_FG )
#define UHUB_DEV_ADDR R8_USB_DEV_AD
#define UHUB_MIS_STAT R8_USB_MIS_ST
#define UHUB_HOST_CTRL R8_UHOST_CTRL
#define UHUB_INT_FLAG R8_USB_INT_FG
#define bUMS_ATTACH RB_UMS_DEV_ATTACH
#define bUMS_SUSPEND RB_UMS_SUSPEND
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD> */
UINT8 CHRV3DiskConnect(void)
{
UINT8 ums, devaddr;
UHUB_DEV_ADDR = UHUB_DEV_ADDR & 0x7F;
ums = UHUB_MIS_STAT;
devaddr = UHUB_DEV_ADDR;
if(devaddr == USB_DEVICE_ADDR)
{ /* <20><><EFBFBD><EFBFBD>Root-HUB<55>µ<EFBFBD>USB<53>豸 */
// if ( UHUB_HOST_CTRL & RB_UH_PORT_EN ) { /* <20><><EFBFBD><EFBFBD>Root-HUB<55>µ<EFBFBD>USB<53><EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD> */
if(ums & bUMS_ATTACH)
{ /* <20><><EFBFBD><EFBFBD>Root-HUB<55>µ<EFBFBD>USB<53><EFBFBD><E8B1B8><EFBFBD><EFBFBD> */
// if ( ( UHUB_INT_FLAG & UIF_DETECT ) == 0 ) { /* <20><><EFBFBD><EFBFBD>Root-HUB<55>µ<EFBFBD>USB<53><EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD> */
if((ums & bUMS_SUSPEND) == 0)
{ /* <20><><EFBFBD><EFBFBD>Root-HUB<55>µ<EFBFBD>USB<53><EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD> */
return (ERR_SUCCESS); /* USB<53><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD> */
}
else
{ /* <20><><EFBFBD><EFBFBD>Root-HUB<55>µ<EFBFBD>USB<53><EFBFBD><E8B1B8><EFBFBD><EFBFBD> */
mDiskConnect:
CHRV3DiskStatus = DISK_CONNECT; /* <20><><EFBFBD><EFBFBD><EFBFBD>Ͽ<EFBFBD><CFBF><EFBFBD> */
return (ERR_SUCCESS); /* <20>ⲿHUB<55><42>USB<53><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD>ӻ<EFBFBD><D3BB>߶Ͽ<DFB6><CFBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
}
}
else
{ /* USB<53><EFBFBD>Ͽ<EFBFBD> */
mDiskDisconn:
CHRV3DiskStatus = DISK_DISCONNECT;
return (ERR_USB_DISCON);
}
}
#ifndef FOR_ROOT_UDISK_ONLY
else if(devaddr > 0x10 && devaddr <= 0x14)
{ /* <20>ⲿHUB<55>Ķ˿<C4B6><CBBF>µ<EFBFBD>USB<53>豸 */
// if ( UHUB_HOST_CTRL & RB_UH_PORT_EN ) { /* <20><><EFBFBD><EFBFBD>Root-HUB<55>µ<EFBFBD><C2B5>ⲿHUB<55><42><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD> */
if(ums & bUMS_ATTACH)
{ /* <20><><EFBFBD><EFBFBD>Root-HUB<55>µ<EFBFBD>USB<53><EFBFBD><E8B1B8><EFBFBD><EFBFBD> */
// if ( ( UHUB_INT_FLAG & UIF_DETECT ) == 0 ) { /* <20><><EFBFBD><EFBFBD>Root-HUB<55>µ<EFBFBD>USB<53><EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD> */
if((ums & bUMS_SUSPEND) == 0)
{ /* <20><><EFBFBD><EFBFBD>Root-HUB<55>µ<EFBFBD>USB<53><EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD> */
TxBuffer[MAX_PACKET_SIZE - 1] = devaddr; /* <20><><EFBFBD><EFBFBD> */
UHUB_DEV_ADDR = USB_DEVICE_ADDR - 1 + (UHUB_DEV_ADDR >> 4); /* <20><><EFBFBD><EFBFBD>USB<53><42><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>USB<53><42>ַָ<D6B7><D6B8>HUB */
CHRV3IntStatus = HubGetPortStatus(TxBuffer[MAX_PACKET_SIZE - 1] & 0x0F); /* <20><>ѯHUB<55>˿<EFBFBD>״̬,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>TxBuffer<65><72> */
if(CHRV3IntStatus == ERR_SUCCESS)
{
if(TxBuffer[2] & (1 << (HUB_C_PORT_CONNECTION - 0x10)))
{ /* <20><><EFBFBD>⵽HUB<55>˿<EFBFBD><CBBF>ϵIJ<CFB5><C4B2><EFBFBD><EFBFBD>¼<EFBFBD> */
CHRV3DiskStatus = DISK_DISCONNECT; /* <20>ٶ<EFBFBD>ΪHUB<55>˿<EFBFBD><CBBF>ϵ<EFBFBD>USB<53><EFBFBD>Ͽ<EFBFBD> */
HubClearPortFeature(TxBuffer[MAX_PACKET_SIZE - 1] & 0x0F, HUB_C_PORT_CONNECTION); /* <20><><EFBFBD><EFBFBD>HUB<55>˿<EFBFBD><CBBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>״̬ */
}
UHUB_DEV_ADDR = TxBuffer[MAX_PACKET_SIZE - 1]; /* <20><><EFBFBD><EFBFBD>USB<53><42><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>USB<53><42>ַָ<D6B7><D6B8>USB<53>豸 */
if(TxBuffer[0] & (1 << HUB_PORT_CONNECTION))
{ /* <20><><EFBFBD><EFBFBD>״̬ */
if(CHRV3DiskStatus < DISK_CONNECT)
{
CHRV3DiskStatus = DISK_CONNECT; /* <20><><EFBFBD><EFBFBD><EFBFBD>Ͽ<EFBFBD><CFBF><EFBFBD> */
}
return (ERR_SUCCESS); /* USB<53><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD>ӻ<EFBFBD><D3BB>߶Ͽ<DFB6><CFBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
}
else
{
// CHRV3DiskStatus = DISK_DISCONNECT;
// return( ERR_USB_DISCON );
CHRV3DiskStatus = DISK_CONNECT;
return (ERR_HUB_PORT_FREE); /* HUB<55>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD>HUB<55>˿<EFBFBD><CBBF><EFBFBD>δ<EFBFBD><CEB4><EFBFBD>Ӵ<EFBFBD><D3B4><EFBFBD> */
}
}
else
{
UHUB_DEV_ADDR = TxBuffer[MAX_PACKET_SIZE - 1]; /* <20><><EFBFBD><EFBFBD>USB<53><42><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>USB<53><42>ַָ<D6B7><D6B8>USB<53>豸 */
if(CHRV3IntStatus == ERR_USB_DISCON)
{
// CHRV3DiskStatus = DISK_DISCONNECT;
// return( ERR_USB_DISCON );
goto mDiskDisconn;
}
else
{
CHRV3DiskStatus = DISK_CONNECT; /* HUB<55><42><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7> */
return (CHRV3IntStatus);
}
}
}
else
{ /* <20><><EFBFBD><EFBFBD>Root-HUB<55>µ<EFBFBD>USB<53><EFBFBD><E8B1B8><EFBFBD><EFBFBD>,<2C>ⲿHUB<55><42>USB<53><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD>ӻ<EFBFBD><D3BB>߶Ͽ<DFB6><CFBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
// CHRV3DiskStatus = DISK_CONNECT; /* <20><><EFBFBD><EFBFBD><EFBFBD>Ͽ<EFBFBD><CFBF><EFBFBD> */
// return( ERR_SUCCESS ); /* <20>ⲿHUB<55><42>USB<53><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD>ӻ<EFBFBD><D3BB>߶Ͽ<DFB6><CFBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
goto mDiskConnect;
}
}
else
{ /* <20>ⲿHUB<55>Ͽ<EFBFBD> */
CHRV3DiskStatus = DISK_DISCONNECT;
}
}
#endif
else
{
// CHRV3DiskStatus = DISK_DISCONNECT;
// return( ERR_USB_DISCON );
goto mDiskDisconn;
}
}
#endif // NO_DEFAULT_DISK_CONNECT
#ifndef NO_DEFAULT_FILE_ENUMER /* <20><>Ӧ<EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD>NO_DEFAULT_FILE_ENUMER<45><52><EFBFBD>Խ<EFBFBD>ֹĬ<D6B9>ϵ<EFBFBD><CFB5>ļ<EFBFBD><C4BC><EFBFBD>ö<EFBFBD>ٻص<D9BB><D8B5><EFBFBD><EFBFBD><EFBFBD><><C8BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>д<EFBFBD>ij<EFBFBD><C4B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
void xFileNameEnumer(void) /* <20>ļ<EFBFBD><C4BC><EFBFBD>ö<EFBFBD>ٻص<D9BB><D8B5>ӳ<EFBFBD><D3B3><EFBFBD> */
{
/* <20><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>ö<EFBFBD><C3B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>CHRV3vFileSizeΪ0xFFFFFFFF<46><46><EFBFBD><EFBFBD><EFBFBD><EFBFBD>FileOpen<65><6E><EFBFBD><EFBFBD>ôÿ<C3B4><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ļ<EFBFBD>FileOpen<65><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ñ<EFBFBD><C3B1>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<20>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>xFileNameEnumer<65><72><EFBFBD>غ<EFBFBD><D8BA><EFBFBD>FileOpen<65>ݼ<EFBFBD>CHRV3vFileSize<7A><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ö<EFBFBD><C3B6>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>Ŀ¼<C4BF><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǣ<EFBFBD>
<20>ڵ<EFBFBD><DAB5><EFBFBD>FileOpen֮ǰ<D6AE><C7B0><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ȫ<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD>Ϊ0<CEAA><30><EFBFBD><EFBFBD>FileOpen<65>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>󣬱<EFBFBD><F3A3ACB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>CHRV3vFdtOffset<65>õ<EFBFBD><C3B5>ṹFAT_DIR_INFO<46><4F>
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>DIR_Attr<74>Լ<EFBFBD>DIR_Name<6D>ж<EFBFBD><D0B6>Ƿ<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ¼<C4BF><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȫ<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<20><>FileOpen<65><6E><EFBFBD>غ<EFBFBD><D8BA><EFBFBD><EFBFBD>жϷ<D0B6><CFB7><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ERR_MISS_FILE<4C><45>ERR_FOUND_NAME<4D><45><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD>ȫ<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
<20><><EFBFBD><EFBFBD><EFBFBD>ڱ<EFBFBD><DAB1>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>xFileNameEnumer<65>н<EFBFBD>CHRV3vFileSize<7A><65>Ϊ1<CEAA><31><EFBFBD><EFBFBD>ô<EFBFBD><C3B4><EFBFBD><EFBFBD>֪ͨFileOpen<65><6E>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǻص<C7BB><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
#if 0
UINT8 i;
UINT16 FileCount;
PX_FAT_DIR_INFO pFileDir;
PUINT8 NameBuf;
pFileDir = (PX_FAT_DIR_INFO)(pDISK_BASE_BUF + CHRV3vFdtOffset); /* <20><>ǰFDT<44><54><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ַ */
FileCount = (UINT16)(0xFFFFFFFF - CHRV3vFileSize); /* <20><>ǰ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,CHRV3vFileSize<7A><65>ֵ<EFBFBD><D6B5>0xFFFFFFFF,<2C>ҵ<EFBFBD><D2B5>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD> */
if(FileCount < sizeof(FILE_DATA_BUF) / 12)
{ /* <20><><EFBFBD><EFBFBD><E9BBBA><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><E3B9BB><EFBFBD><EFBFBD>,<2C>ٶ<EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD><D5BC>12<31><32><EFBFBD>ֽڴ<D6BD><DAB4><EFBFBD> */
NameBuf = &FILE_DATA_BUF[FileCount * 12]; /* <20><><EFBFBD><EFBFBD>浱ǰ<E6B5B1>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ */
for(i = 0; i < 11; i++)
NameBuf[i] = pFileDir->DIR_Name[i]; /* <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>,<2C><><EFBFBD><EFBFBD>Ϊ11<31><31><EFBFBD>ַ<EFBFBD><><CEB4><EFBFBD><EFBFBD><EFBFBD>ո<EFBFBD> */
// if ( pFileDir -> DIR_Attr & ATTR_DIRECTORY ) NameBuf[ i ] = 1; /* <20>ж<EFBFBD><D0B6><EFBFBD>Ŀ¼<C4BF><C2BC> */
NameBuf[i] = 0; /* <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
}
#endif
}
#endif // NO_DEFAULT_FILE_ENUMER
UINT8 CHRV3LibInit(void) /* <20><>ʼ<EFBFBD><CABC>CHRV3<56><33><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD>0 */
{
if(CHRV3GetVer() < CHRV3_LIB_VER)
return (0xFF); /* <20><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>İ汾<C4B0><E6B1BE>,<2C>汾̫<E6B1BE><CCAB><EFBFBD>򷵻ش<F2B7B5BB><D8B4><EFBFBD> */
#if DISK_BASE_BUF_LEN > 0
pDISK_BASE_BUF = &DISK_BASE_BUF[0]; /* ָ<><D6B8><EFBFBD>ⲿRAM<41>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD><EFBFBD><EFBFBD> */
pDISK_FAT_BUF = &DISK_BASE_BUF[0]; /* ָ<><D6B8><EFBFBD>ⲿRAM<41>Ĵ<EFBFBD><C4B4><EFBFBD>FAT<41><54><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>pDISK_BASE_BUF<55><46><EFBFBD><EFBFBD><EFBFBD>Խ<EFBFBD>ԼRAM */
// pDISK_FAT_BUF = & DISK_FAT_BUF[0]; /* ָ<><D6B8><EFBFBD>ⲿRAM<41>Ĵ<EFBFBD><C4B4><EFBFBD>FAT<41><54><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>pDISK_BASE_BUF<55><46><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD> */
/* <20><><EFBFBD><EFBFBD>ϣ<EFBFBD><CFA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>ȡ<EFBFBD>ٶ<EFBFBD>,<2C><>ô<EFBFBD><C3B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD>CHRV3LibInit֮<74><D6AE>,<2C><>pDISK_FAT_BUF<55><46><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>pDISK_BASE_BUFͬ<46><CDAC><EFBFBD><EFBFBD>С<EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD><EFBFBD> */
#endif
CHRV3DiskStatus = DISK_UNKNOWN; /* δ֪״̬ */
CHRV3vSectorSizeB = 9; /* Ĭ<>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̵<EFBFBD><CCB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>512B */
CHRV3vSectorSize = 512; // Ĭ<>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̵<EFBFBD><CCB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>512B,<2C><>ֵ<EFBFBD>Ǵ<EFBFBD><C7B4>̵<EFBFBD><CCB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
CHRV3vStartLba = 0; /* Ĭ<><C4AC>Ϊ<EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>FDD<44><44>HDD */
CHRV3vPacketSize = 64; /* USB<53><EFBFBD><E6B4A2><EFBFBD><EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:64@FS,512@HS/SS,<2C><>Ӧ<EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><><C3B6>U<EFBFBD>̺<EFBFBD><CCBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ǹ<EFBFBD><C7B8>ٻ<EFBFBD><D9BB>߳<EFBFBD><DFB3><EFBFBD><EFBFBD><EFBFBD>ô<EFBFBD><C3B4>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>Ϊ512 */
pTX_DMA_A_REG = (PUINT32)&R16_UH_TX_DMA; /* ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DMA<4D><41>ַ<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>,<2C><>Ӧ<EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC> */
pRX_DMA_A_REG = (PUINT32)&R16_UH_RX_DMA; /* ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DMA<4D><41>ַ<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>,<2C><>Ӧ<EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC> */
pTX_LEN_REG = (PUINT16)&R8_UH_TX_LEN; /* ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD>ͳ<EFBFBD><CDB3>ȼĴ<C8BC><C4B4><EFBFBD>,<2C><>Ӧ<EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC> */
pRX_LEN_REG = (PUINT16)&R8_USB_RX_LEN; /* ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD>ճ<EFBFBD><D5B3>ȼĴ<C8BC><C4B4><EFBFBD>,<2C><>Ӧ<EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC> */
//CHRV3vRootPort = 0; /* USB<53><42><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>(<28><><EFBFBD><EFBFBD>Root-hub<75><62><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD>˿<EFBFBD>) */
return (ERR_SUCCESS);
}