ButterflyMP3

testing.c

Go to the documentation of this file.
00001 
00002 #include "testing.h"
00003 
00004 /***************************************************************************
00005 *   Name:       dump_buffer
00006 *       Description: Dumps the mmc_sbuf[] to the Uart
00007 *       Parameters: <lines> # of lines (16 Bytes) to send starting from 0x00
00008 *       Returns:        none
00009 ***************************************************************************/
00010 void dump_buffer(uint8 lines, uint8 buffer[])
00011 {
00012         uint8 c,i;
00013         for (c=0;c<lines;c++){
00014                 EOL();
00015                 UART_Printfu08(c);
00016                 PRINT(": ");
00017                 for (i=0;i<16;i++){
00018                         UART_Printfu08(buffer[i+c*16]);
00019                         PRINT(" ");
00020                 }
00021                 for (i=0;i<16;i++){
00022                         if ((buffer[i+c*16] > 31) && (buffer[i+c*16] <= 'z'))
00023                                 UART_SendByte(buffer[i+c*16]);  
00024                         else
00025                                 UART_SendByte('.');
00026                         //PRINT(" ");
00027                 }
00028         }
00029 }
00030 
00031 /***************************************************************************
00032 *   Name:                       MMC_tester
00033 *       Description:    Check out basic MMC functions
00034 *       Parameters:             none
00035 *       Returns:        Status byte, non-zero for failure.
00036 ***************************************************************************/
00037 uint8 MMC_tester(void)
00038 {
00039         uint8 c;
00040         uint16 status;
00041         uint32 cap;
00042         
00043         c =  MMC_Reset();                               // init mmc
00044         PRINT("MMC_RESET returned ");
00045         UART_Printfu08(c);
00046         EOL();
00047         if (c==0){
00048                 status = MMC_Check();                           // check status
00049                 PRINT("MMC_SEND_STATUS returned ");
00050                 UART_Printfu16(status);
00051                 c = (uint8) status;
00052                 EOL();
00053         }
00054         if (c==0){
00055                 c = MMC_Identify();
00056                 PRINT("MMC_SEND_CID returned ");
00057                 UART_Printfu08(c);
00058                 if (c==0){ // identity OK
00059                         dump_buffer(2,mmc_scratch);// dump 2 lines from the buffer
00060                 }
00061                 c=0;
00062                 EOL();
00063         }
00064         if (c==0){
00065                 c = MMC_CardType();
00066                 PRINT("MMC_SEND_CSD returned ");
00067                 UART_Printfu08(c);
00068                 if (c==0){ // CSD OK
00069                         dump_buffer(2,mmc_scratch);// dump 2 lines from the buffer
00070                 }
00071                 c=0;
00072                 EOL();
00073         }
00074         if (c==0){
00075                 cap = MMC_Capacity();
00076                 PRINT("MMC_Capacity returned ");
00077                 UART_Printfu32(cap);
00078                 EOL();
00079         }
00080         
00081         if (c==0){
00082                 c = MMC_Name();
00083                 PRINT("MMC_Name returned ");
00084                 UART_Printfu08(c);
00085                 PRINT(" ");
00086                 if (c==0){
00087                         UART_Puts(mmc_scratch);
00088                 }       
00089                 EOL();
00090         }
00091         
00092         if (c == 0) {
00093                 c =  MMC_Read(0x20);// read boot sector
00094                 PRINT("MMC_Read returned ");
00095                 UART_Printfu08(c);
00096                 EOL();
00097                 if (c==0){
00098                         PRINT("MMC Boot Sector: ");
00099                         dump_buffer(32,mmc_sbuf); // dump the sector
00100                 }
00101         }
00102                         
00103         EOL();
00104 
00105         
00106         
00107         return c;
00108 }
00109 
00110 
00111 /***************************************************************************
00112 *   Name:                       FAT_tester
00113 *       Description:    Routines to test filesystem functions to the mmc
00114 *       Parameters:             none
00115 *       Returns:                error code
00116 ***************************************************************************/
00117 uint8   FAT_tester(void)
00118 {
00119         uint8 result,i;
00120         uint8 record;
00121         uint8 attrib;
00122         uint16 sector=0;
00123 //      uint16 cluster;
00124 //      uint32 size;
00125         
00126         // set up the FAT variables
00127         FAT_buffer = mmc_sbuf; // 512 byte buffer for sector reads/writes
00128         FAT_read = MMC_Read; // pointer to read block function 
00129         FAT_write = MMC_Write;// pointer to write block function 
00130         
00131         result =  MMC_Reset();                          // init mmc
00132         if (result) return result;
00133         
00134         result = FAT_initFat16();
00135         if (result) return result; // abort on non-zero reply 
00136         
00137         // print Fat info
00138         PRINT("FAT boot Sector info");EOL();
00139         PRINT("FAT begins at sector ");
00140         UART_Printfu32(FAT16_fat_begin_lba);EOL();
00141         PRINT("Clusters begin at sector ");
00142         UART_Printfu32(FAT16_cluster_begin_lba);EOL();
00143         PRINT("Sectors per cluster = ");
00144         UART_Printfu08(FAT16_sectors_per_cluster);EOL();
00145         PRINT("Root dir starts at sector ");
00146         UART_Printfu32(FAT16_root_dir_first_sector);EOL();
00147         
00148         //show volume label
00149         result = FAT_get_label(mmc_scratch);
00150         if (!result){
00151                 PRINT("Volume Name is ");
00152                 UART_Puts(mmc_scratch);
00153                 EOL();
00154         }
00155         
00156         // read the root dir
00157         sector = FAT16_root_dir_first_sector;
00158         result = FAT_read(sector);
00159 
00160         record =0;
00161         while((result==0) && mmc_sbuf[record*32]!=0){
00162                  // check firstByte
00163                 if (mmc_sbuf[record*32] != 0xe5){ // not used (aka deleted)
00164                         
00165                         // get the attrib byte
00166                         attrib = mmc_sbuf[(record*32)+11];
00167                         
00168                         if (attrib == FILE_TYPE_FILE || attrib == FILE_TYPE_DIR ){ // entry is normal 8.3 entry
00169                                 
00170                                 if (attrib == FILE_TYPE_DIR) PRINT("[");
00171                                 
00172                                 // construct short filename string
00173                                 for (i=0;i<8;i++){ 
00174                                         mmc_scratch[i] = mmc_sbuf[(record*32)+i];
00175                                 }
00176                                 mmc_scratch[8] = '.';
00177                                 mmc_scratch[9] = mmc_sbuf[(record*32)+8];
00178                                 mmc_scratch[10] = mmc_sbuf[(record*32)+9];
00179                                 mmc_scratch[11] = mmc_sbuf[(record*32)+10];
00180                                 mmc_scratch[12] = 0x00;
00181                                 UART_Puts(mmc_scratch);         
00182                                 if (attrib == FILE_TYPE_DIR) PRINT("]");
00183                                 PRINT("\t");
00184                                 
00185                                 // get Cluster 
00186                                 UART_Printfu08(mmc_scratch[13] = mmc_sbuf[(record*32)+0x15]);
00187                                 UART_Printfu08(mmc_scratch[14] = mmc_sbuf[(record*32)+0x14]);
00188                                 UART_Printfu08(mmc_scratch[15] = mmc_sbuf[(record*32)+0x1B]);
00189                                 UART_Printfu08(mmc_scratch[16] = mmc_sbuf[(record*32)+0x1A]);
00190                                 PRINT("\t");
00191                                 
00192                                 
00193                                 //get fileSize
00194                                 UART_Printfu08(mmc_scratch[17] = mmc_sbuf[(record*32)+0x1f]);
00195                                 UART_Printfu08(mmc_scratch[18] = mmc_sbuf[(record*32)+0x1e]);
00196                                 UART_Printfu08(mmc_scratch[19] = mmc_sbuf[(record*32)+0x1d]);
00197                                 UART_Printfu08(mmc_scratch[20] = mmc_sbuf[(record*32)+0x1c]);
00198                                 PRINT("\t");
00199                                 
00200                                 //get filenumber
00201                                 UART_Printfu32(record+(sector<<4));
00202                                 EOL();
00203                                 
00204                         }
00205                         
00206                                 
00207                 }
00208                 
00209                 // next record or on to next sector
00210                 record++;
00211                 
00212                 if (record==16){
00213                         record = 0;
00214                         record = 0;
00215                         record = 0;
00216 
00217                         sector++;
00218                         result = FAT_read(sector);
00219                         
00220                 }
00221         }
00222          
00223          // print number of files in directory
00224         
00225         // get limits of file system.
00226         
00227         // play file "test.mp3"
00228         EOL();
00229         
00230         return result;
00231 }
00232 
00233 
00234 
 All Files Functions Variables Typedefs Enumerations Enumerator Defines