📄 test.i
字号:
UINT32 l[2]; READ_CAPACITY_DATA CapData; } tmpVar; UINT8 Control; } READ_CAPACITY_RBC, *pREAD_CAPACITY_RBC; typedef struct _READ_CAPACITY_RSP { UINT32 LastLBA; UINT32 BlockSize; } READ_CAPACITY_RSP, *pREAD_CAPACITY_RSP; typedef struct _START_STOP_RBC { UINT8 OperationCode; UINT8 Immediate: 1; UINT8 Reserved1 : 7; UINT8 Reserved2[2]; union _START_STOP_FLAGS { struct { UINT8 Start : 1; UINT8 LoadEject : 1; UINT8 Reserved3 : 2; UINT8 PowerConditions: 4; } bits0; struct { UINT8 MediumState : 2; UINT8 Reserved3 : 2; UINT8 PowerConditions: 4; } bits1; } Flags; UINT8 Control; } START_STOP_RBC, *pSTART_STOP_RBC; typedef struct _SYNCHRONIZE_CACHE_RBC { UINT8 OperationCode; UINT8 Reserved[8]; UINT8 Control; } SYNCHRONIZE_CACHE_RBC, *pSYNCHRONIZE_CACHE_RBC; typedef struct _WRITE_RBC { UINT8 OperationCode; UINT8 VendorSpecific; union{ struct { UINT8 LBA_3; UINT8 LBA_2; UINT8 LBA_1; UINT8 LBA_0; } LBA_W8 ; UINT32 LBA_W32; } LBA; UINT8 Reserved2; UINT16 XferLength; UINT8 Control; } WRITE_RBC, *pWRITE_RBC; typedef struct _VERIFY_RBC { UINT8 OperationCode; UINT8 Reserved0; UINT8 LBA_3; UINT8 LBA_2; UINT8 LBA_1; UINT8 LBA_0; UINT8 Reserved1; UINT8 VerifyLength_1; UINT8 VerifyLength_0; UINT8 Control; } VERIFY_RBC, *pVERIFY_RBC; typedef struct _INQUIRY_SPC { UINT8 OperationCode; UINT8 EnableVPD:1 ; UINT8 CmdSupportData:1 ; UINT8 Reserved0:6 ; UINT8 PageCode; UINT8 Reserved1; UINT8 AllocationLen; UINT8 Control; } INQUIRY_SPC, *pINQUIRY_SPC; typedef struct _MODE_SELECT_SPC { UINT8 OperationCode; UINT8 SavePage : 1 ; UINT8 Reseved0 : 3 ; UINT8 PageFormat : 1 ; UINT8 Reserved1 : 3 ; UINT8 Reserved2[2]; UINT8 ParameterLen; UINT8 Control; } MODE_SELECT_SPC, *pMODE_SELECT_SPC; typedef struct _MBR_BLOCK { UINT8 Res[454]; unsigned long StartSector; unsigned long TotalSector; UINT8 Res1[50]; } MBR_BLOCK,*pMBR_BLOCK; typedef struct _BPB_BLOCK { UINT8 BS_jmpBoo[3]; UINT8 BS_OEMName[8]; UINT16 BPB_BytesPerSec; UINT8 BPB_SecPerClus; UINT16 BPB_RsvdSecCnt; UINT8 BPB_NumFATs; UINT16 BPB_RootEntCnt; UINT16 BPB_TotSec16; UINT8 BPB_Media; UINT16 BPB_FATSz16; UINT16 BPB_SecPerTrk; UINT16 BPB_NumHeads; unsigned long BPB_HiddSec; unsigned long BPB_TotSec32; UINT8 BS_DrvNum; UINT8 BS_Reserved1; UINT8 BS_BootSig; UINT8 BS_VolID[4]; UINT8 BS_VolLab[11]; UINT8 BS_FilSysType[8]; UINT8 ExecutableCode[448]; UINT8 Marker[2]; } BPB_BLOCK,*pBPB_BLOCK; typedef struct _BPB_BLOCK32 { UINT8 BS_jmpBoo[3]; UINT8 BS_OEMName[8]; UINT16 BPB_BytesPerSec; UINT8 BPB_SecPerClus; UINT16 BPB_RsvdSecCnt; UINT8 BPB_NumFATs; UINT16 BPB_RootEntCnt; UINT16 BPB_TotSec16; UINT8 BPB_Media; UINT16 BPB_FATSz16; UINT16 BPB_SecPerTrk; UINT16 BPB_NumHeads; unsigned long BPB_HiddSec; unsigned long BPB_TotSec32; UINT32 BPB_FATSz32; UINT16 BPB_ExtFlags; UINT16 BPB_FSVer; UINT32 BPB_RootClus; UINT16 BPB_FSInfo; UINT16 BPB_BkBootSec; UINT8 BPB_Reserved[12]; UINT8 BS_DrvNum; UINT8 BS_Reserved1; UINT8 BS_BootSig; UINT32 BS_VolID; UINT8 BS_VolLab[11]; UINT8 BS_FilSysType[8]; } BPB_BLOCK32,*pBPB_BLOCK32; typedef struct _SYS_INFO_BLOCK{ unsigned long StartSector; unsigned long TotalSector; UINT16 BPB_BytesPerSec; UINT8 BPB_SecPerClus; UINT8 BPB_NumFATs; UINT16 BPB_RootEntCnt; UINT16 BPB_TotSec16; UINT8 BPB_Media; UINT16 BPB_FATSz16; UINT32 BPB_FATSz32; UINT16 BPB_SecPerTrk; UINT16 BPB_NumHeads; unsigned long BPB_HiddSec; unsigned long BPB_TotSec32; UINT8 BS_DrvNum; UINT8 BS_BootSig; UINT8 BS_VolID[4]; UINT8 BS_VolLab[11]; UINT8 BS_FilSysType[8]; unsigned long FatStartSector; unsigned long RootStartSector; unsigned long FirstDataSector; unsigned long TotCluster; unsigned char bFatType; } SYS_INFO_BLOCK,*pSYS_INFO_BLOCK; typedef struct _FILE_INFO{ unsigned char bFileOpen; unsigned int StartCluster; unsigned long LengthInByte; unsigned int ClusterPointer; unsigned long SectorPointer; unsigned int OffsetofSector; unsigned char SectorofCluster; unsigned long pointer; } FILE_INFO, *pFILE_INFO; typedef struct _DIR_INFO{ unsigned char name[8]; unsigned char extension[3]; unsigned char attribute; unsigned char Reserved[10]; unsigned int lastUpdateDate; unsigned int lastUpdateTime; unsigned int startCluster; unsigned long length; } DIR_INFO, *pDIR_INFO; typedef struct _MODE_SENSE_SPC { UINT8 OperationCode; UINT8 Reseved0 : 3 ; UINT8 DisableBlockDescriptor : 1 ; UINT8 Reserved0 : 4 ; UINT8 PageCode:6 ; UINT8 PageControl : 2 ; UINT8 Reserved1; UINT8 ParameterLen; UINT8 Control; } MODE_SENSE_SPC, *pMODE_SENSE_SPC; typedef struct _MEDIA_REMOVAL_SPC { UINT8 OperationCode; UINT8 Reserved0[3]; UINT8 Prevent; } MEDIA_REMOVAL_SPC, *pMEDIA_REMOVAL_SPC; typedef struct _REQUEST_SENSE_SPC { UINT8 OperationCode; UINT8 Reserved[3]; UINT8 AllocationLen; UINT8 Control; } REQUEST_SENSE_SPC, *pREQUEST_SENSE_SPC; typedef struct _TEST_UNIT_SPC { UINT8 OperationCode; UINT8 Reserved[4]; UINT8 Control; } TEST_UNIT_SPC, *pTEST_UNIT_SPC; typedef struct _WRITE_BUFFER_SPC { UINT8 OperationCode; UINT8 Mod:4 ; UINT8 Reserved0:4 ; UINT8 BufferID; UINT8 BufferOff_2; UINT8 BufferOff_1; UINT8 BufferOff_0; UINT8 ParameterLen_2; UINT8 ParameterLen_1; UINT8 ParameterLen_0; UINT8 Control; } WRITE_BUFFER_SPC, *pWRITE_BUFFER_SPC; typedef union _CDB_RBC { GENERIC_CDB Cdb_Generic; GENERIC_RBC RbcCdb_Generic; FORMAT_RBC RbcCdb_Format; READ_RBC RbcCdb_Read; READ_CAPACITY_RBC RbcCdb_ReadCapacity; START_STOP_RBC RbcCdb_OnOffUnit; SYNCHRONIZE_CACHE_RBC RbcCdb_SyncCache; VERIFY_RBC RbcCdb_Verify; WRITE_RBC RbcCdb_Write; INQUIRY_SPC SpcCdb_Inquiry; MODE_SELECT_SPC SpcCdb_ModeSelect; MODE_SENSE_SPC SpcCdb_ModeSense; MEDIA_REMOVAL_SPC SpcCdb_Remove; REQUEST_SENSE_SPC SpcCdb_RequestSense; TEST_UNIT_SPC SpcCdb_TestUnit; WRITE_BUFFER_SPC SpcCdb_WriteBuffer; READ_10 CmdRead10; WRITE_10 CmdWrite10; MODE_SELECT_10 CmdModeSel10; MODE_SENSE_10 CmdModeSen10; READ_LONG_CMD SpcCdb_ReadLong; } CDB_RBC, *pCDB_RBC; #line 1 "tpbulk.h" /0 typedef struct _COMMAND_BLOCK_WRAPPER{ UINT32 dCBW_Signature; UINT32 dCBW_Tag; UINT32 dCBW_DataXferLen; UINT8 bCBW_Flag; UINT8 bCBW_LUN; UINT8 bCBW_CDBLen; CDB_RBC cdbRBC; } CBW, *pCBW; typedef struct _COMMAND_STATUS_WRAPPER{ UINT32 dCSW_Signature; UINT32 dCSW_Tag; UINT32 dCSW_DataResidue; UINT8 bCSW_Status; } CSW, *pCSW; typedef union _TPBULK_STRUC { CBW TPBulk_CommandBlock; CSW TPBulk_CommandStatus; }TPB_STRUC, *pTPB_STRUC; unsigned char EnumMassDev(void); unsigned char TPBulk_GetMaxLUN(void); unsigned char SPC_Inquiry(void); unsigned char SPC_READLONG(void); unsigned char SPC_RequestSense(void); unsigned char SPC_TestUnit(void); unsigned char SPC_LockMedia(void); unsigned char RBC_ReadCapacity(void); unsigned char RBC_ReadOneSec(unsigned long lba, unsigned char *pBuffer); unsigned char RBC_Write(unsigned long lba,unsigned char len,unsigned char *pBuffer); #line 4 "test.c" /0 #line 1 "fat.h" /0 unsigned long FirstSectorofCluster(unsigned int n); unsigned int ThisFatEntOffset(unsigned int clusterNum); unsigned int GetNextClusterNum(unsigned int clusterNum); unsigned int ThisFatSecNum(unsigned int clusterNum);#line 5 "test.c" /0 #line 1 "fat32.h" /0 unsigned long FirstSectorofCluster32(unsigned long clusterNum); unsigned long ThisFatSecNum32(unsigned long clusterNum); unsigned long ThisFatEntOffset32(unsigned long clusterNum); unsigned long GetNextClusterNum32(unsigned long clusterNum ); unsigned char GoToPointer32(unsigned long pointer); unsigned char DeleteClusterLink32(unsigned long clusterNum); unsigned long GetFreeCusterNum32(void); unsigned long CreateClusterLink32(unsigned long currentCluster);#line 6 "test.c" /0 void playMp3(); void sdPlayMp3(); XXGFLAGS bdata bXXGFlags; UINT8 xdata pUSERBUF[64]; UINT8 xdata DBUF[512] _at_ 0x0; UINT8 xdata RDIRBUF[512]; UINT8 xdata FATBUF[512]; UINT8 xdata respBuf[16]; DIR_IDX dirIdx; pDIR_INFO pDIR; unsigned char skipSong; extern SYS_INFO_BLOCK DeviceInfo; extern XXGPKG usbstack; extern TPB_STRUC data TPBulk_Block; void main(void) { UINT8 i; UINT16 j; UINT32 nSector; unsigned char temp; bXXGFlags.SLAVE_ONLINE = 0; bXXGFlags.SLAVE_FOUND = 0; bXXGFlags.SLAVE_REMOVED=0; bXXGFlags.SLAVE_ENUMERATED = 0; bXXGFlags.SLAVE_IS_ATTACHED = 0; bXXGFlags.bUartInDone=0; bXXGFlags.bToggle=0; bXXGFlags.bIN_ISR=0; SCON = 0x50; ((unsigned char volatile xdata *) 0)[0xF80B] = 0x03; SPI_CTL0 = 0x4E; SPI_CTL1 = 0x3; P1= 0x0; for(i=0;i<64;i++) { DBUF[i] = 0; } P3_DDR = 0xFA; temp = P3; if (!(temp & 0x4)) { SDIdentify(); GetDevInfo(); } else { usbInit(); usbReset(); if(!bXXGFlags.SLAVE_ENUMERATED) { EA = 0; if(enumUsbDev(1)) { bXXGFlags.SLAVE_ENUMERATED = 1; } else { bXXGFlags.SLAVE_ENUMERATED = 0; bXXGFlags.SLAVE_IS_ATTACHED = 0; } } if(bXXGFlags.SLAVE_ENUMERATED) { bXXGFlags.bMassDevice=0; if(EnumMassDev()) { bXXGFlags.SLAVE_IS_ATTACHED = 1; temp = 0xAA; } else { bXXGFlags.SLAVE_IS_ATTACHED = 0; } } } if (DeviceInfo.bFatType == 2) { dirIdx.sector = 0; dirIdx.offset = 0; if (bXXGFlags.SLAVE_IS_ATTACHED) RBC_ReadOneSec(DeviceInfo.RootStartSector, RDIRBUF); else SDReadRdir(DeviceInfo.RootStartSector); pDIR = (pDIR_INFO) RDIRBUF; for (j=0;j<DeviceInfo.BPB_RootEntCnt;j++) { if ((pDIR->name[0] != 0xe5) && (pDIR->name[0] != 0x0) && (pDIR->attribute & 0x20)) { if((pDIR->extension[0] == 0x4d) && (pDIR->extension[1] == 0x50) && (pDIR->extension[2] == 0x33)) { if (bXXGFlags.SLAVE_IS_ATTACHED) playMp3(); else sdPlayMp3(); } } if (dirIdx.offset == 15) { dirIdx.sector++; nSector = DeviceInfo.RootStartSector + (UINT32) dirIdx.sector; if (bXXGFlags.SLAVE_IS_ATTACHED) RBC_ReadOneSec(nSector, RDIRBUF); else SDReadRdir(nSector); dirIdx.offset = 0; pDIR = (pDIR_INFO) RDIRBUF; } else { dirIdx.offset++; pDIR++; } } } } void playMp3() { UINT8 k; UINT16 currCluster; UINT16 nextCluster; UINT32 file_len; UINT32 dSectorNum; UINT8 usTemp; file_len = SwapINT32( pDIR->length ); currCluster = WordSwap( pDIR->startCluster ); usTemp = ((unsigned char volatile xdata *) 0)[0xF401]; ((unsigned char volatile xdata *) 0)[0xF40A] = 0x10; ((unsigned char volatile xdata *) 0)[0xF40A] = 0x00; DelayUs ( 100 ); ((unsigned char volatile xdata *) 0)[0xF401] = 0x31; while (file_len) { dSectorNum = FirstSectorofCluster ( currCluster ); nextCluster = GetNextClusterNum ( currCluster ); for ( k=0; k<DeviceInfo.BPB_SecPerClus; ) { if(((unsigned char volatile xdata *) 0)[0xF407] & 0x02) { bXXGFlags.bIN_ISR=1; if(file_len < 32768) { file_len = 0; break; } else { if(!RBC_ReadOneSec(dSectorNum, DBUF)) { break; } file_len -= 512; dSectorNum++; } ((unsigned char volatile xdata *) 0)[0xF407] = 0x02; bXXGFlags.bIN_ISR=0; k++; } } currCluster = nextCluster; } DelayMs(500); ((unsigned char volatile xdata *) 0)[0xF401] = usTemp; } void sdPlayMp3() { unsigned char k; unsigned int currCluster; unsigned int nextCluster; unsigned long file_len; unsigned long dSectorNum; unsigned char usTemp; SPI_CTL1 = 0x0; file_len = SwapINT32( pDIR->length ); currCluster = WordSwap( pDIR->startCluster ); dSectorNum = FirstSectorofCluster ( currCluster ); usTemp = ((unsigned char volatile xdata *) 0)[0xF401]; ((unsigned char volatile xdata *) 0)[0xF40A] = 0x10; ((unsigned char volatile xdata *) 0)[0xF40A] = 0x40; ((unsigned char volatile xdata *) 0)[0xF401] = 0x31; while (file_len) { if(((unsigned char volatile xdata *) 0)[0xF407] & 0x02) { SDMp3Read(dSectorNum); file_len -= 512; if(file_len < 512) file_len = 0; dSectorNum++; ((unsigned char volatile xdata *) 0)[0xF407] = 0x02; } } ((unsigned char volatile xdata *) 0)[0xF401] = usTemp; SPI_CTL1 = 0x3; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -