📄 main.c
字号:
#include "option.h"
#include "def.h"
#include "44b.h"
#include "44blib.h"
#include "iis.h"
#include "usb.h"
#define DOWNSIZE 7000000
/**********************************************************************
* 串口下载文件
* *addr返回文件起始地址,*size返回文件长度
* 成功返回0,失败返回-1
*/
int Com_DownloadFile(U32 *addr, U32 *size)
{
int i,tmp;
U16 checkSum=0,dnCS;
U32 fileSize=10;
U8 *downPt;
U32 downloadAddress;
downloadAddress=(unsigned)malloc(DOWNSIZE);//申请DOWNSIZE大小内存
if(downloadAddress==NULL)
return 0;
downPt=(U8 *)downloadAddress;
Uart_Printf("\nDownload file by COM");
Uart_Printf("\nSTATUS:\n");
rINTMSK=~BIT_GLOBAL;
tmp=RdURXH0(); //To remove overrun error state.
i=0;
while(i<fileSize)
{
while(!(rUTRSTAT0&0x1));
*(downPt+i)=RdURXH0();
if(i==3)
{
fileSize=*((U8 *)(downloadAddress+0))+
(*((U8 *)(downloadAddress+1))<<8)+
(*((U8 *)(downloadAddress+2))<<16)+
(*((U8 *)(downloadAddress+3))<<24);
}
if((i%1000)==0)WrUTXH0('.');
i++;
}
for(i=4;i<(fileSize-2);i++)
{
checkSum+=*((U8 *)(i+downloadAddress));
}
dnCS=*((U8 *)(downloadAddress+fileSize-2))+
(*( (U8 *)(downloadAddress+fileSize-1) )<<8);
free((void *)downloadAddress);//释放内存
if(checkSum!=dnCS)
{
Uart_Printf("\nChecksum Error!!! MEM:%x DN:%x",checkSum,dnCS);
return 0;
}
Uart_Printf("\nDownload O.K.");
*addr=(U32)(U8 *)(4+downPt);
*size=fileSize-6;
return 1;
}
/**********************************************************************
* USB下载文件
* size 指定接收文件长度
* *addr 返回文件起始地址
* 成功返回0,失败返回-1
*/
int Usb_DownloadFile(U32 *addr, U32 size)
{
int i;
U16 checkSum=0,dnCS;
U32 fileSize;
U8 *downPt;
U32 downloadAddress;
// static U8 UsbOn=0;
downloadAddress=(unsigned)malloc(DOWNSIZE);//申请DOWNSIZE大小内存
if(downloadAddress==NULL)
return 0;
downPt=(U8 *)downloadAddress;
Uart_Printf("\nDownload file by USB");
USBON();
/*
USBReceiveBulk(downPt,8);
while(!USBReceiveBulkDone());
fileSize=*((U8 *)(downloadAddress+4))+
(*((U8 *)(downloadAddress+5))<<8)+
(*((U8 *)(downloadAddress+6))<<16)+
(*((U8 *)(downloadAddress+7))<<24)-10;
downPt=(U8 *)(downloadAddress+8);
// Uart_Printf("\ndownPt=%x,filesize=%x",downPt,fileSize);////////
USBReceiveBulk(downPt,fileSize+2);
*/
USBReceiveBulk(downPt,size);
while(!USBReceiveBulkDone());
// Uart_Printf("\ndownPt=%x",downPt);////////
USBOFF();
*addr=(U32)(U8 *)(8+downPt);
free((void *)downloadAddress);//释放内存
return 1;
// free((void *)downloadAddress);//释放内存
//
// Uart_Printf("\nChecksum start!");
// for(i=8;i<fileSize+8;i++)
// {
// checkSum+=*((U8 *)(i+downloadAddress));
// }
//
// dnCS=*((U8 *)(downloadAddress+fileSize+8))+
// (*( (U8 *)(downloadAddress+fileSize+9) )<<8);
//
//
// if(checkSum!=dnCS)
// {
// Uart_Printf("Checksum Error!!! MEM:%x DN:%x\n",checkSum,dnCS);
// return 0;
// }
// Uart_Printf("\nDownload O.K.\n");
// *addr=(U32)(U8 *)(4+downPt);
// *size=fileSize;
// return 1;
}
/**********************************************************************
* main loop
*/
void Main(void)
{
int i,rt;
char key;
U32 addr,size;
rSYSCFG=CACHECFG; // Using 8KB Cache//
Port_Init();
Uart_Init(0,115200);
Delay(1000);
Uart_Select(0); //Select UART0
while(1)
{
Uart_Printf("\n\n========== FS44B0X IIS TEST ==========");
Uart_Printf("\nPlease Download the *.wav!");
Uart_Printf("\nPlease select C(COM) or U(USB):zhu li");
key= Uart_Getch();
switch(key)
{
case 'c':
case 'C':
rt=Com_DownloadFile(&addr,&size);
break;
case 'u':
case 'U':
Uart_Printf("\nPlease input file size:");
size=Uart_GetIntNum();
rt=Usb_DownloadFile(&addr,size);
break;
default:
continue;
}
if(!rt)
Uart_Printf("\nDownloadFile Error!");
else
{
if(size>MAX_WAVESIZE)
Play_BigWave(addr,size);
else
Play_SmallWave(addr,size);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -