




已阅读5页,还剩24页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
/文件操作与WAV音频播放实验程序解析/头文件#include #include inc/hw_memmap.h#include inc/hw_types.h#include driverlib/fpu.h#include driverlib/gpio.h#include driverlib/interrupt.h#include driverlib/rom.h#include driverlib/sysctl.h#include driverlib/systick.h#include driverlib/pin_map.h#include driverlib/ssi.h#include grlib/grlib.h#include utils/cmdline.h#include utils/uartstdio.h#include fatfs/src/ff.h#include fatfs/src/diskio.h#include drivers/cfal96x64x16.h#include drivers/buttons.h/*/ Defines the size of the buffers that hold the path, or temporary data from/ the SD card. There are two buffers allocated of this size. The buffer size/ must be large enough to hold the longest expected full path name, including/ the file name, and a trailing null character./*#define PATH_BUF_SIZE 80/*/ Defines the size of the buffer that holds the command line./*#define CMD_BUF_SIZE 64/*/ This buffer holds the full path to the current working directory. Initially/ it is root (/)./*static char g_cCwdBufPATH_BUF_SIZE = /;/*/ A temporary data buffer used when manipulating file paths, or reading data/ from the SD card./*static char g_cTmpBufPATH_BUF_SIZE;/*/ A flag to indicate the select button was pressed./*static volatile unsigned char bSelectPressed = 0;static volatile unsigned char bUpPressed = 0;static volatile unsigned char bDownPressed = 0;static volatile unsigned char bLeftPressed = 0;static volatile unsigned char bRightPressed = 0;/*/ The buffer that holds the command line./*static char g_cCmdBufCMD_BUF_SIZE;/*/ The following are data structures used by FatFs./*static FATFS g_sFatFs;static DIR g_sDirObject;static FILINFO g_sFileInfo;static FIL g_sFileObject;tRectangle sRect;char tmp100;char cover20= ;/*/ A structure that holds a mapping between an FRESULT numerical code, and a/ string representation. FRESULT codes are returned from the FatFs FAT file/ system driver./*typedef struct FRESULT fresult; char *pcResultStr;tFresultString;/wav文件头数据类型typedef struct _tagMsWavPcmHeader44char ChunkID4; / RIFF; The RIFF the mainchunk;unsigned long ChunkSize; / FileSize - 8; The size following this datachar Format4; / WAVE; The WAVE format consists of two subchunks: fmt and data char SubChunk1ID4; / fmt unsigned long SubChunk1Size; / 16 for PCM. This is the size of the rest of the subchunk which follows this data.unsigned short AudioFormat; / 1 for PCM. Linear quantizationunsigned short NumChannels; / 1-Mono, 2-stereo, etc.unsigned long SampleRate; / 8000, 11025, 16000, 44100, 48000, etc.unsigned long ByteRate; / = SampleRate * NumChannels * BitsPerSample/8unsigned short BlockAlign; / = NumChannels * BitsPerSample / 8unsigned short BitsPerSample; / 8-8bits, 16-16bits, etc. char SubChunk2ID4; / dataunsigned long SubChun2Size; / = NumSamples * NumChannels * BitsPerSample / 8. The size of data wav_pcm_header44;/*/ A macro to make it easy to add result codes to the table./*#define FRESULT_ENTRY(f) (f), (#f) /*/ A table that holds a mapping between the numerical FRESULT code and its/ name as a string. This is used for looking up error codes for printing to/ the console./*tFresultString g_sFresultStrings = FRESULT_ENTRY(FR_OK), FRESULT_ENTRY(FR_NOT_READY), FRESULT_ENTRY(FR_NO_FILE), FRESULT_ENTRY(FR_NO_PATH), FRESULT_ENTRY(FR_INVALID_NAME), FRESULT_ENTRY(FR_INVALID_DRIVE), FRESULT_ENTRY(FR_DENIED), FRESULT_ENTRY(FR_EXIST), FRESULT_ENTRY(FR_RW_ERROR), FRESULT_ENTRY(FR_WRITE_PROTECTED), FRESULT_ENTRY(FR_NOT_ENABLED), FRESULT_ENTRY(FR_NO_FILESYSTEM), FRESULT_ENTRY(FR_INVALID_OBJECT), FRESULT_ENTRY(FR_MKFS_ABORTED);/*/ A macro that holds the number of result codes./*#define NUM_FRESULT_CODES (sizeof(g_sFresultStrings) / sizeof(tFresultString)/*/ Graphics context used to show text on the CSTN display./*tContext g_sContext;/*/ This function returns a string representation of an error code that was/ returned from a function call to FatFs. It can be used for printing human/ readable error messages./*const char *StringFromFresult(FRESULT fresult) unsigned int uIdx; / / Enter a loop to search the error code table for a matching error code. / for(uIdx = 0; uIdx 9) + 1980, (g_sFileInfo.fdate 5) & 15, g_sFileInfo.fdate & 31, (g_sFileInfo.ftime 11), (g_sFileInfo.ftime 5) & 63, g_sFileInfo.fsize, g_sFileInfo.fname); / Print summary lines showing the file, dir, and size totals. UARTprintf(n%4u File(s),%10u bytes totaln%4u Dir(s), ulFileCount, ulTotalSize, ulDirCount); / Get the free space. fresult = f_getfree(/, &ulTotalSize, &pFatFs); / Check for error and return if there is a problem. if(fresult != FR_OK) return(fresult); / Display the amount of free space that was calculated. UARTprintf(, %10uK bytes freen, ulTotalSize * pFatFs-sects_clust / 2); / Made it to here, return with no errors. return(0);/*/ This function implements the cd command. It takes an argument that/ specifies the directory to make the current working directory. Path/ separators must use a forward slash /. The argument to cd can be one of/ the following:/ * root (/)/ * a fully specified path (/my/path/to/mydir)/ * a single directory name that is in the current directory (mydir)/ * parent directory (.)/ It does not understand relative paths, so dont try something like this:/ (./my/new/path)/ Once the new directory is specified, it attempts to open the directory to/ make sure it exists. If the new path is opened successfully, then the/ current working directory (cwd) is changed to the new path./*intCmd_cd(int argc, char *argv) unsigned int uIdx; FRESULT fresult; / Copy the current working path into a temporary buffer so it can be / manipulated. strcpy(g_cTmpBuf, g_cCwdBuf); / If the first character is /, then this is a fully specified path, and it / should just be used as-is. if(argv10 = /) / Make sure the new path is not bigger than the cwd buffer. if(strlen(argv1) + 1 sizeof(g_cCwdBuf) UARTprintf(Resulting path name is too longn); return(0); / If the new path name (in argv1) is not too long, then copy it / into the temporary buffer so it can be checked. else strncpy(g_cTmpBuf, argv1, sizeof(g_cTmpBuf); / If the argument is . then attempt to remove the lowest level on the / CWD. else if(!strcmp(argv1, .) / Get the index to the last character in the current path. uIdx = strlen(g_cTmpBuf) - 1; / Back up from the end of the path name until a separator (/) is / found, or until we bump up to the start of the path. while(g_cTmpBufuIdx != /) & (uIdx 1) / / Back up one character. / uIdx-; / Now we are either at the lowest level separator in the current path, / or at the beginning of the string (root). So set the new end of / string here, effectively removing that last part of the path. g_cTmpBufuIdx = 0; / Otherwise this is just a normal path name from the current directory, / and it needs to be appended to the current path. else / Test to make sure that when the new additional path is added on to / the current path, there is room in the buffer for the full new path. / It needs to include a new separator, and a trailing null character. if(strlen(g_cTmpBuf) + strlen(argv1) + 1 + 1 sizeof(g_cCwdBuf) UARTprintf(Resulting path name is too longn); return(0); / The new path is okay, so add the separator and then append the new / directory to the path. else / If not already at the root level, then append a / if(strcmp(g_cTmpBuf, /) strcat(g_cTmpBuf, /); / Append the new directory to the path. strcat(g_cTmpBuf, argv1); / At this point, a candidate new directory path is in chTmpBuf. Try to / open it to make sure it is valid. fresult = f_opendir(&g_sDirObject, g_cTmpBuf); / If it cant be opened, then it is a bad path. Inform the user and / return. if(fresult != FR_OK) UARTprintf(cd: %sn, g_cTmpBuf); return(fresult); / Otherwise, it is a valid new path, so copy it into the CWD. else strncpy(g_cCwdBuf, g_cTmpBuf, sizeof(g_cCwdBuf); / Return success. return(0);/*/ This function implements the pwd command. It simply prints the current/ working directory./*intCmd_pwd(int argc, char *argv) / Print the CWD to the console. UARTprintf(%sn, g_cCwdBuf); / Return success. return(0);/*/ This function implements the cat command. It reads the contents of a file/ and prints it to the console. This should only be used on text files. If/ it is used on a binary file, then a bunch of garbage is likely to printed on/ the console./*intCmd_cat(int argc, char *argv) FRESULT fresult; unsigned short usBytesRead; / First, check to make sure that the current path (CWD), plus the file / name, plus a separator and trailing null, will all fit in the temporary / buffer that will be used to hold the file name. The file name must be / fully specified, with path, to FatFs. if(strlen(g_cCwdBuf) + strlen(argv1) + 1 + 1 sizeof(g_cTmpBuf) UARTprintf(Resulting path name is too longn); return(0); / Copy the current path to the temporary buffer so it can be manipulated. strcpy(g_cTmpBuf, g_cCwdBuf); / If not already at the root level, then append a separator. if(strcmp(/, g_cCwdBuf) strcat(g_cTmpBuf, /); / Now finally, append the file name to result in a fully specified file. strcat(g_cTmpBuf, argv1); / Open the file for reading. fresult = f_open(&g_sFileObject, g_cTmpBuf, FA_READ); / If there was some problem opening the file, then return an error. if(fresult != FR_OK) return(fresult); / Enter a loop to repeatedly read data from the file and display it, until / the end of the file is reached. do / Read a block of data from the file. Read as much as can fit in the / temporary
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 《比》(教学设计)-2024-2025学年六年级上册数学人教版
- 河北省衡水市景县黎阳学校初中体育 第一课《技巧 跳跃练习》说课稿
- 办公买卖合同(标准版)
- 学生军训毕营仪式流程操作手册
- 2024-2025年高中化学 专题2 第3单元 优化食物品质的添加剂说课稿 苏教版选修1
- 店面经营权承包合同书7篇
- 医院物业建筑服务合同5篇
- 计划考核岗位笔试题(附答案)
- 2025年专业婚礼策划婚礼车队租赁及现场布置服务合同
- 二零二五年事业单位专业技术人员聘用管理服务协议
- 高度近视并发症及其管理
- 排球整套教学课件
- 甲状腺癌根治术护理查房
- ttt培训课件 肯德基
- 新生儿呼吸暂停及处理
- 2025-2030中国综合能源服务行业发展状况与竞争格局分析报告
- 校园欺凌案件管理制度
- 2025至2030年中国消防工程行业发展动态及未来前景规划报告
- 2025至2030年中国民用采暖炉行业市场行情动态及发展前景研判报告
- 药品网络交易服务三方平台质量管理体系文件-B2B平台(完整版)
- 儿童心理发展课件
评论
0/150
提交评论