📄 main.c
字号:
/**********************************************************************
********* 主控程序 **********
**********************************************************************/
#include "VoiceProcess.h"
#include "math.h"
#include "config.h"
#define MMC_CARD 0
Bool int_flag;
int MikeOut[0x6010];
DATA souA[2];
unsigned long rev_cnt = 0,out_cnt = 0,rev_star = 1,out_star = 0;
interrupt void mcbsprev1(); //中断接收函数
MMC_Handle mmc0;
Uint16 cardtype;
MMC_CardObj *card, cardalloc;
MMC_CardIdObj *cid, cardid;
MMC_CardCsdObj *csd, cardcsd;
//SD_CardCsdObj *sdcsd, sdcardcsd;
int retVal;
Uint16 mybuf[256];
unsigned char youbuf[512];
MMC_SetupNative Init = {
0, /* disable DMA for data read/write */
0, /* Set level of edge detection for DAT3 pin */
0, /* Determines if MMC goes IDLE during IDLE instr */
0, /* Memory clk reflected on CLK Pin */
7, /* CPU CLK to MMC function clk divide down */
5, /* MMC function clk to memory clk divide down */
0, /* No. memory clks to wait before response timeout */
0, /* No. memory clks to wait before data timeout */
512, /* Block Length must be same as CSD */
};
MMC_Config myMMCCfg={
0x000f,/* MMCCTL */
0x0f00,/* MMCFCLK */
0x0001,/* MMCCLK */
0x0fa0,/* MMCIm */
0x00ff,/* MMCTOR */
0x0500,/* MMCTOD */
0x0200,/* MMCBLEN */
0x0001,/* MMCNBLK */
};
RTC_Config myConfig={
0x21,/*秒*/
0x10,/*秒报警*/
0x26,/*分*/
0x10,/*分报警*/
0x17,/*小时*/
0x16,/*小时报警*/
0x03,/*星期及星期报警*/
0x05,/*日期*/
0x03,/*月*/
0x08,/*年*/
0x10,/*周期中断选择寄存器*/
0x02,/*中断使能寄存器 (24小时制)*/
};
RTC_Date getDate;
RTC_Time getTime;
RTC_Date myDate={
0x08,//2008
0x03,//3月
0x05,//1日
0x03,//星期六
};
RTC_Time myTime={
0x10,//10时
0x30,//30分
0x58,//58秒
};
DATE_TIME Time;
extern void ReadFileWork(char *NAME);
extern void WriteFileWork(char *NAME);
uint8 GetDataTime(DATE_TIME *GetTime);
void SD_INIT(void);
unsigned char ReadSector(uint32 iLbaStart,unsigned char *buf);
/**********************************************************************/
// 主程序
/**********************************************************************/
void delay(Uint16 a)
{
Uint16 i,j;
for(j=0;j<a;j++){
for(i=0;i<1000;i++)asm(" NOP");
}
}
/////////////////////////////////////////////////////////////////////
void main(void)
{ DATE_TIME *T;
T=&Time;
IRQ_globalDisable(); //全局中断禁止
RTC_config(&myConfig);
// RTC_setDate(&myDate);
// RTC_setTime(&myTime);
RTC_start();
int_flag=FALSE;
sys_init(); //系统初始化函数
SET_AD73311(); //设置两个AD73311芯片,包括内部时钟,采样率,增益等
CSL_init();
GetDataTime(T);
SD_INIT();
// ReadSector(0,youbuf);
FileInit(); /* 初始化文件系统 */
DiskInit(); /* 初始化磁盘管理模块 */
AddFileDriver(USBCammand); /* 增加存储设备: */
IRQ_globalEnable(); //全局中断使能
LedYellow(LedOff); //LED2 OFF
LedRed(LedOn); //LED1 ON
while(1) //循环,等待中断,进行数据处理
{
if(int_flag==1)
{
//语音播放部分
if(out_star == 1)
{
while (!MCBSP_xrdy(hMcbsp1));
MCBSP_write16(hMcbsp1, MikeOut[out_cnt]);
out_cnt++;
if(out_cnt == 0x6000)
{
out_star = 0;
rev_star = 1;
rev_cnt = 0;
LedYellow(LedOff); //LED1 ON
delay(2500);
LedYellow(LedOn);
delay(2500);
LedYellow(LedOff);
delay(2500);
LedYellow(LedOn);
delay(2500);
LedYellow(LedOff); //LED2 OFF
LedRed(LedOn); //LED1 ON
}
}
//语音录音部分
if(rev_star == 1)
{
MikeOut[rev_cnt]=souA[0]-2200;
if(rev_cnt < 0x6000 )
rev_cnt++;
else
{
out_star = 1;
out_cnt = 0;
rev_star = 0;
LedRed( LedOff);
delay(2500);
LedRed(LedOn);
delay(2500);
LedRed(LedOff);
delay(2500);
LedRed(LedOn);
delay(2500);
LedYellow( LedOn); //LED1 ON
LedRed(LedOff); //LED2 OFF
}
}
int_flag = 0;
IRQ_globalEnable();
}
}
}
//////////////////////////////////////////////////////////////////////////////
// 读一个扇区
unsigned char ReadSector(uint32 iLbaStart,unsigned char *buf)
{ uint16 i;
int C;
C=MMC_read(mmc0,iLbaStart,mybuf,256);
for(i=0;i<256;i++){
buf[2*i]=mybuf[i] & 0x00ff;
buf[2*i+1]=(mybuf[i]>>8)& 0x00ff;
}
return C;
}
///////////////////////////////////////////////////////////////////////////////
//写一个扇区
unsigned char WriteSector(uint32 iLbaStart,unsigned char *buf)
{
int C;
C=MMC_write(mmc0, iLbaStart, buf,512);
return C;
}
//////////////////////////////////////////////////////////////////////////////
uint8 GetDataTime(DATE_TIME *GetTime)
{
RTC_getDate(&getDate);
RTC_getTime(&getTime);
GetTime->ti_sec =getTime.second/16*10 + getTime.second%16 ;
GetTime->ti_min = getTime.minute/16*10+ getTime.minute%16 ;
GetTime->ti_hour = getTime.hour%16 + getTime.hour/16*10;
GetTime->da_dow = getDate.dayw%16+getDate.dayw/16*10;
GetTime->da_day = getDate.daym%16+getDate.daym/16*10;
GetTime->da_mon = getDate.month%16+getDate.month/16*10;
GetTime->da_year = 2000+(Uint16)(getDate.year%16+getDate.year/16*10);
return RETURN_OK;
}
//////////////////////////////////////////////////////////////////////////////
interrupt void mcbsprev1() //语音数据接收中断服务子函数
{
IRQ_globalDisable(); //全局中断禁止
/*********** 取两路数据 ********************************/
souA[0]=MCBSP_read16(hMcbsp1); //A口作输入
//souA[1]=MCBSP_read16(hMcbsp2); //B口作参考
int_flag=TRUE;
IRQ_clear(rcvEventId1);
// IRQ_clear(rcvEventId2); //清除中断标志
}
///////////////////////////////////////////////////////////////////////////
void SD_INIT(void)
{
printf ("MMC Controller setup test...\n");
/* The MMC shares a event line with McBSP. In this function, we *
* - reserve the system event line for MMC *
* - initialize the handle with data about register locations, *
* event id and other device details *
* - initialize the dispatcher for the device to point to the *
* dispatcher for the MMC device instance */
/* Prototype: MMC_open(<device instance>); *
* We choose device 1 on the board */
mmc0 = MMC_open(MMC_DEV1);
/* In this function, we initialize the MMC registers with the *
* parameters passed in the Init structure *
* Prototype: MMC_setupNative(Handle, MMC_setupNative*); */
MMC_setupNative(mmc0,&Init); //initialize the MMC controller
MMC_config(mmc0,&myMMCCfg);
/* Ask all cards to go to idle state. This is equivalent to a *
* s/w reset. *
* Prototype: MMC_sendGoIdle(Handle); */
MMC_sendGoIdle(mmc0);
delay(1000);
/* Set the voltage window for the card. If the card does not *
* support this voltage range, it will return -1. *
* *
* Working: *
* We first send an APP_CMD. An SD card responds to this command *
* while an MMC does not. If the card responds, we now send the *
* ACMD41 to initialize the SD card with the desiered voltage *
* range. If there is no response, we send the CMD1 to initialize *
* the MMC card with the desired voltage range. *
* *
* Return Value: *
* If an MMC card is identified, it returns 0. *
* If an SD card is identified, it returns 1. *
* If the voltage range is not supported or the card does not *
* initialize correctly, it returns -1. */
cardtype = MMC_sendOpCond(mmc0,0x00100000);
if (cardtype == 0xFFFF){
printf ("Card not recognized\n");
exit(0);
}
if (cardtype == MMC_CARD){
printf ("SD card found\n");
cid = &cardid;
/* Instruct all cards to send their Card Identification Data */
MMC_sendAllCID(mmc0,cid);
printf ("The values in the CID of the SD card are:\n");
printf ("mgfId = %d\n",cid->mfgId);
printf ("hwRew = %d\n",cid->hwRev);
printf ("fwRev = %d\n",cid->fwRev);
printf ("serialNo = %d\n",cid->serialNumber);
printf ("month = %d\n",cid->monthCode);
printf ("year = %d\n",cid->yearCode);
/* NOTE: Year 0 = 2000 for MMC */
}
retVal = MMC_selectCard(mmc0,card);
printf ("Initialized card successfully\n");
}
/*************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -