#include #include #include #include #include #include #include #include #include "drv/global.h" #include "drv/pll.h" #include "drv/board_sru.h" #include "drv/ad1939.h" #include "drv/sport.h" #include "drv/hmem.h" #include "drv/spi.h" #include "drv/fft.h" #include "f2f.h" #include "execute.h" #include "queue.h" #include "jitter.h" #include "report.h" extern double proc_secs;/////////////////////////////////////////////////////// extern void* hans,* haec, *hafc; double cpu_get_process_ulitity(void); #pragma section("scene_mem") static int mem_test = 0xefbcdda5; //jitter_mem* pusb_input_jitter =0; //jitter_mem* pusb_output_jitter =0; static short cpu_cal_ulitily(void) { double aec_secs = alg_aec_get_ulitily(haec); double ans_secs = alg_ans_get_ulitily(hans); double total_secs; total_secs = proc_secs*7.5+ (aec_secs+ans_secs); proc_secs = 0 ; return (total_secs*100000/10); } void main() { int i ; int led_on=0; int led_count=0; int loop_cnt=0; short value; short reply_status; unsigned short size;//////////////////////////////////////////////// extern int clock_ok ; extern int sp_flag ; extern int inputcnt; extern int dma_count[2]; extern int usb_dma_count; extern void* htx_que; extern int msg_process(void); extern int dsp_index ; extern int dsp_status; extern int handshake_successful; extern int topo_state; int request_topo_count =0 ; //if no preset after handshare 8's, request one time. int clock_check_count =0; int first_scene_done = 0; int no_clock = 0; memset(dma_count, 0, sizeof(int)*2); initPLL_SDRAM(); //Initialize the PLL and SDRAM controller InitDAI(); SRU(DPI_PB06_O, FLAG6_I); sysreg_bit_set(sysreg_FLAGS, FLG6); dsp_index = sysreg_bit_tst(sysreg_FLAGS , FLG6); //GPIO SRU(HIGH, DPI_PBEN11_I); //0-busy,1-idle SRU(HIGH, DPI_PBEN12_I); //0-send, 1-recv SRU(LOW,DPI_PB11_I); SRU(LOW,DPI_PB12_I); SRU(HIGH,DPI_PBEN13_I);//led SRU(HIGH,DPI_PBEN14_I); for(i=0;i<3;i++){ SRU(LOW,DPI_PB13_I); SRU(LOW,DPI_PB14_I); Delay(1000000); SRU(HIGH,DPI_PB13_I); SRU(HIGH,DPI_PB14_I); Delay(1000000); } hmem_init(); //test(); spi_init(DEVICE_DMA); htx_que = queue_create(SPI_PKT_SIZE*4); //sdram check help find problem if(mem_test != 0xefbcdda5){ dsp_status = dsp_mem_err; device_status_report(DSP_RUNNING_STATUS,(short*)&dsp_status ,1); msg_report_dsp_status(MSG_DSP_STATUS_REPORT); //֪ͨMCUÆô¶¯Íê³É SRU(HIGH,DPI_PB11_I); SRU(HIGH,DPI_PB12_I); while(1){ loop_cnt++; if(loop_cnt>=1000000){ if(led_on){ SRU(HIGH,DPI_PB13_I); } else{ SRU(LOW,DPI_PB13_I); } led_on = !led_on; loop_cnt =0; } msg_process(); } } alg_lib_init(); output_empty(); //InitSRC(); //InitSPORT(0x3,RATE_SAMPLES); //interruptcb(SIG_SP1, sport_isr); //interruptcb(SIG_SP3, sport3_isr); //interruptcb(SIG_SP5, sport_usb_isr); //debug״̬ÇëÇóMCUÖØÐ·¢ËÍÊý¾Ý device_status_report(DSP_EMULATE_DEBUG,0, 0); msg_report_dsp_status(MSG_DSP_STATUS_REPORT); //֪ͨMCUÆô¶¯Íê³É SRU(HIGH,DPI_PB11_I); SRU(HIGH,DPI_PB12_I); #define LED_PERIOD (1000*RATE_SAMPLES/(NUM_SAMPLES*1000)) //main loop while(1){ if(haec != NULL ){ alg_aec_process_asy(haec); } if(hans != NULL){ alg_ans_process_asy(hans); } msg_process(); if(dma_count[0] - led_count >LED_PERIOD){ if(led_on){ SRU(LOW,DPI_PB13_I); } else{ SRU(HIGH,DPI_PB13_I); } size = hmem_perused(SRAM_AUTO); device_status_report(DSP_MEM_UTILITY,(short*)&size, 1); value = cpu_cal_ulitily(); device_status_report(DSP_CPU_UTILITY,&value , 1); reply_status = no_clock ? dsp_clock_ok : dsp_status; device_status_report(DSP_RUNNING_STATUS,(short*)&reply_status ,1); //do not use this function to other place .only here. msg_report_dsp_status(MSG_DSP_STATUS_REPORT); no_clock = 0; led_on=!led_on; led_count = dma_count[0]; } //8s request if(clock_ok && dma_count[0] - request_topo_count > (8*(RATE_SAMPLES/NUM_SAMPLES))){ if(topo_state == PRESET_NONE) { device_status_report(DSP_SCENE_REQUEST,0 ,0); } else if(topo_state == PRESET_DONE && !first_scene_done){ device_status_report(DSP_SCENE_DONE,0 ,0); topo_state = PRESET_NORMAL; first_scene_done = 1; } else if(topo_state == PRESET_DONE){ //If the scene completion response is continuously reported, it will cause the ADC to keep resetting. //device_status_report(DSP_SCENE_DONE,0 ,0); topo_state = PRESET_NORMAL; } request_topo_count = dma_count[0]; } //clock state will change after running,it need check always. //about 2.5s if(++loop_cnt>10000000){ if(clock_ok && !no_clock && clock_check_count == dma_count[0]) { dsp_status = dsp_no_clock; device_status_report(DSP_RUNNING_STATUS,(short*)&dsp_status ,1); msg_report_dsp_status(MSG_DSP_STATUS_REPORT); no_clock = 1; } loop_cnt =0; clock_check_count = dma_count[0]; } if(clock_ok == 0 && dsp_status==dsp_running_ok && handshake_successful){ //DSP²úÉúʱÖÓÉϱ¨MCUÕý³£ÔË×÷ device_status_report(DSP_CLOCK_STATUS,0 ,0 ); request_topo_count = dma_count[0]; clock_ok = 1; } } }