📄 avrfat16.c
字号:
if (attrib == FILE_TYPE_FILE || attrib== FILE_TYPE_DIR ){ // entry is normal 8.3 entry // construct short filename string for (i=0;i<12;i++){ FAT_scratch[i] = FAT_buffer[fat_entry+i]; } FAT_scratch[11] = '/'; if (attrib == FILE_TYPE_FILE ){ FAT_scratch[8] = '.'; FAT_scratch[9] = FAT_buffer[fat_entry+8]; FAT_scratch[10] = FAT_buffer[fat_entry+9]; FAT_scratch[11] = FAT_buffer[fat_entry+10]; } FAT_scratch[12] = 0x00; // accept only *.mp3 files if(attrib== FILE_TYPE_DIR || ( FAT_scratch[9] =='M' && FAT_scratch[10] =='P' && FAT_scratch[11] =='3')){ // get Cluster UART_Printfu08(FAT_scratch[13] = FAT_buffer[(fat_entry)+0x15]); UART_Printfu08(FAT_scratch[14] = FAT_buffer[(fat_entry)+0x14]); UART_Printfu08(FAT_scratch[15] = FAT_buffer[(fat_entry)+0x1B]); UART_Printfu08(FAT_scratch[16] = FAT_buffer[(fat_entry)+0x1A]); PRINT("\t"); //get fileSize UART_Printfu08(FAT_scratch[17] = FAT_buffer[(fat_entry)+0x1f]); UART_Printfu08(FAT_scratch[18] = FAT_buffer[(fat_entry)+0x1e]); UART_Printfu08(FAT_scratch[19] = FAT_buffer[(fat_entry)+0x1d]); UART_Printfu08(FAT_scratch[20] = FAT_buffer[(fat_entry)+0x1c]); // // Do Long Filename entries.... //checksum of name for long entries.. nmeChkSm=FAT_ChkSum(FAT_buffer+fat_entry); lfn_record = record; lfn_sector = sector; lfn_entry = lfn_record << 5; do{ // look at previous FAT entry if (lfn_record > 0){ lfn_record--; }else{ if (lfn_sector > 0) { lfn_sector--; // read in new sector result = FAT_read(FAT16_root_dir_first_cluster+lfn_sector); if (result){ // abort on non-zero reply PRINT("Can't Read sector"); break; } lfn_record = 0x0F;// 15 records per sector FAT16 }else{ // force exit if we run out of sectors PRINT("ERR: sctr 0");EOL(); break; } } lfn_entry = lfn_record << 5; // dump record for debugging //FAT_PrintRecord(FAT_buffer+lfn_entry);EOL(); // get the attrib byte attrib = FAT_buffer[lfn_entry+FAT16_LDIR_Attr]; //exit if no LFN entry found if (attrib != FILE_ATTR_LFN_TEXT){ PRINT("no LFN "); UART_Printfu08(attrib); EOL(); break; } //get the chksm lfnchksm = FAT_buffer[lfn_entry+FAT16_LDIR_Chksum]; // exit if ChkSum doesn't Match if (lfnchksm != nmeChkSm){ PRINT("CkSm err"); UART_Printfu08(nmeChkSm); UART_Printfu08(lfnchksm); EOL(); break; } //look at order, select lfn section lfn = ((FAT_buffer[lfn_entry+FAT16_LDIR_Ord] & FILE_ATTR_LFN_MASK)-1) *13; UART_Printfu08(FAT_buffer[lfn_entry]); if (lfn < LFN_BUFFER_LENGTH-13) // Only allow 208 byte max LFNs { // note: only look at lower byte of unicode text. FAT16_longfilename[13+lfn] = 0x00; FAT16_longfilename[12+lfn] = FAT_buffer[lfn_entry+0x1e]; FAT16_longfilename[11+lfn] = FAT_buffer[lfn_entry+0x1c]; FAT16_longfilename[10+lfn] = FAT_buffer[lfn_entry+0x18]; FAT16_longfilename[9+lfn] = FAT_buffer[lfn_entry+0x16]; FAT16_longfilename[8+lfn] = FAT_buffer[lfn_entry+0x14]; FAT16_longfilename[7+lfn] = FAT_buffer[lfn_entry+0x12]; FAT16_longfilename[6+lfn] = FAT_buffer[lfn_entry+0x10]; FAT16_longfilename[5+lfn] = FAT_buffer[lfn_entry+0x0e]; FAT16_longfilename[4+lfn] = FAT_buffer[lfn_entry+0x09]; FAT16_longfilename[3+lfn] = FAT_buffer[lfn_entry+0x07]; FAT16_longfilename[2+lfn] = FAT_buffer[lfn_entry+0x05]; FAT16_longfilename[1+lfn] = FAT_buffer[lfn_entry+0x03]; FAT16_longfilename[lfn] = FAT_buffer[lfn_entry+0x01]; } // test to see if we need to keep looking }while(FAT_buffer[lfn_entry] < FILE_ATTR_LFN_MASK); // not last entry // check if we made it through all entries if (FAT_buffer[lfn_entry] < FILE_ATTR_LFN_MASK){ // use short name for (i=0;i<13;i++){ FAT16_longfilename[i]=FAT_scratch[i]; } } /* if (lfn_sector != sector) {// re read original FAT sector if changed result = FAT_read(FAT16_root_dir_first_cluster+sector); if (result) return result; // abort on non-zero reply } */ PRINT("\t"); UART_Printfu32(record+(sector<<4));EOL(); UART_Puts(FAT16_longfilename);EOL(); // RA Sewell - for ID3 tags and scrolling name on NOKIA FAT16_LFNTitleLen = strLen(FAT16_longfilename); FAT16_longfilename[LFN_TYPE_INDEX] = LFN_TYPE_FILENAME; if (attrib==FILE_TYPE_DIR) FAT16_longfilename[FAT16_LFNTitleLen-1] = '/'; FAT16_filetype = attrib; return 0x00; } } } return 0x59;}/*** FAT_readRoot * @param filenumber 32bit uInt pointing to file of interst. * @return error code * * Read the root directory of the disk and obtain details * about FAT entry number <filenumber> **/uint8 FAT_readRoot(uint32 filenumber){ return FAT_readFile(filenumber,FAT16_root_dir_first_cluster);}/*** GetNextSong * @return new filenumber or 0=err * **/uint32 FAT_getNextSong(uint32 filenumber,uint32 directory){ uint16 i; uint8 result=0; //uint32 nextfile; if (filenumber < FAT16_entryMAX){ filenumber++; // find next valid FAT entry i=1023;// time out after 1023 entries while ( (i--) && (result= FAT_readFile(filenumber++,directory)) ); // read last FAT entry if valid if (i && (result==0) ){ filenumber--; PRINT("File #");UART_Printfu16(filenumber); EOL(); return filenumber; } } return 0; }/*** GetPrevSong * @return file number of next file or zero if none found. **/uint32 FAT_getPrevSong(uint32 filenumber,uint32 directory){ uint16 i; uint8 result=0; if (filenumber>FAT16_entryMIN){ filenumber--; // find previous valid FAT entry i=1023; while ( (filenumber>0) && (i--) && (result= FAT_readFile(filenumber--,directory)) ); //set if valid if ((result==0) && i && filenumber){ filenumber++; PRINT("File #");UART_Printfu16(filenumber); EOL(); return filenumber; } } // return 0 if no new file found. return 0;}//----------------------------------------------------------------------------- // FAT_ChkSum() // Returnsanunsignedbytechecksumcomputedonanunsignedbyte // array. Thearraymustbe11byteslongandisassumedtocontain // anamestoredintheformatofaMS-DOSdirectoryentry. // Passed: pFcbName Pointertoanunsignedbytearrayassumedtobe // 11byteslong. // Returns:Sum An8-bitunsignedchecksumofthearraypointed // tobypFcbName. //------------------------------------------------------------------------------ uint8 FAT_ChkSum(uint8 *pFcbName) { uint8 FcbNameLen; uint8 Sum; //PRINT(">> "); Sum=0; for(FcbNameLen=11;FcbNameLen!=0;FcbNameLen--){ //UART_SendByte(*pFcbName); //NOTE:The operation is an unsignedchar rotate right Sum=((Sum&1)?0x80:0)+(Sum>>1)+*pFcbName++; } //PRINT(" "); //UART_Printfu08(Sum); //EOL(); return(Sum); } /*void FAT_PrintRecord(uint8 *pRecord){ uint8 i; for (i=0;i<32;i++){ UART_Printfu08(*pRecord++); } EOL(); for (i=0;i<32;i++){ UART_SendByte(*pRecord++); } EOL();}*/ /*** FAT_scanDir * @param uint32 pointing to director start cluster * @return number of files found * * scan a directory for songs, set max, min and currentdir variables **/uint8 FAT_scanDir(uint32 directory){ uint8 files=0; uint32 file=-1,nextfile; // exit if already in this directory. //if (directory==FAT16_dir_first_cluster) return -1; // get first good file FAT16_entryMIN = FAT_getNextSong(0,directory); //scan root directory and get max File Entry. nextfile = FAT16_entryMIN; while ( nextfile ){ file = nextfile; files++; nextfile = FAT_getNextSong(file,directory); } FAT16_entryMAX =file; // set to last valid MP3 if (files){ // then set working directory FAT16_parent_dir_first_cluster = FAT16_dir_first_cluster; FAT16_dir_first_cluster = directory; } return files;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -