/* * main.cpp * * Created on: 2025Äê7ÔÂ22ÈÕ * Author: 86189 */ #include #include #include #include #include #include #include #include #include "adi_initialize.h" #include "../drv/gpio.h" #include "../drv/spi.h" #include "config.h" #include "../drv/board.h" #include "../drv/sport.h" #include "../drv/linkport.h" #include "../drv/memory.h" #include "../drv/FIR_acc.h" #include "messageproc.h" #include "ModuleProAPI.h" #include "queue.h" #include "f2f.h" #include "var_state.h" #include "tob.h" #include "tg/module_def.h" #include "tg/tg_scene.h" //È«¾Ö±äÁ¿ #define MAX_INTR 100 static u32 DMACount[MAX_INTR]; static ufloat asyn_proc_secs; static ufloat proc_secs; ufloat cpu_utility() { ufloat total_secs ; total_secs = asyn_proc_secs + proc_secs*(SAMPLE_RATE*0.01f)/SAMPLE_NUM ;// return total_secs*1000*100/10; } inline uvoid blink_led(GPIO_Level level) { GPIO_SetOutPut(GPIOB, GPIO_Pin10, level); } /* * 128 · UpdateInput && UpdateOutput 7.37% ÔÙ¼Ó128 ·Dummy input ºÍoutput. ¹²12.370000% * */ extern "C" uvoid AudioProcCallBack (u32 iid) { ToB* tob = ToB::GetInstance(); ufloat clock_start,clock_stop; VarState& var = VarState::GetInstance(); if(var.master_intr == iid){ var.dsp_status = DSPStatus::dsp_running_ok; } if(tob == NULL) return ; if(var.TopoLoading){ MuteOutput(); } else if(var.master_intr == iid){ clock_start = clock(); UpdateInput(iid, DMACount[iid]&0x1); tob->toProc(); UpdateOutput(iid, DMACount[iid]&0x1); <<<<<<< HEAD // LP_transmit(); ModulesAsynSetInterval(proc_secs); fir_acc_startup(); ======= //LP_transmit(); // ModulesAsynSetInterval(proc_secs); // fir_acc_startup(); >>>>>>> 0d5b7df96a2ee186b7b085dca9cf9a33f791c430 clock_stop = clock(); proc_secs = ((ufloat) (clock_stop - clock_start))/ CLOCKS_PER_SEC; } else{ UpdateInput(iid, DMACount[iid]&0x1); UpdateOutput(iid, DMACount[iid]&0x1); } <<<<<<< HEAD ++DMACount[iid]; ======= DMACount[iid]++; >>>>>>> 0d5b7df96a2ee186b7b085dca9cf9a33f791c430 } int main(int argc, char *argv[]) { s32 result ; s32 total_mem = space_unused(); s16 cpu,mem; s32 request_topo_count =0 ; //if no preset after handshare 8's, request one time. s32 clock_check_count =0; s32 ledOn = 0; uint32_t ledCount = 0; uint32_t levelCount = 0; u32 loop_cnt =0; MSG msg; VarState& var = VarState::GetInstance(); adi_initComponents(); spu_config(); DDR_config(); pinmux_config(); sram_init(); DAI_config(); memset(DMACount, 0, sizeof(DMACount)); Message* spiMsg = new Message(8); SPI2_Init(); fir_acc_init(); //֪ͨarmÆô¶¯Íê³É. //dir: pin12, High level DSP can receive data, low level DSP has data toz send . //busy: pin13/PB5, low level DSP is in busy state and cannot receive and send data, high level is free. GPIO_SetOutPut(GPIOA, GPIO_Pin12, GPIO_HIGH); GPIO_SetOutPut(GPIOB, GPIO_Pin5, GPIO_HIGH); <<<<<<< HEAD //µÚÒ»´ÎÆô¶¯Éϱ¨ÌرðÊÇ·ÂÕæµÄʱºòÐèÒªarm'ÖØÐ·¢ÎÕÊÖ. spiMsg->DspStatusPush(DSP_EMULATE_DEBUG, 0, 0); spiMsg->ReportDspStatus(&msg); printf("free sram %d, L2 %d\n", sram_free_space(SRAM_DDR, mem_any), sram_free_space(SRAM_L2, mem_any)); ======= // u32 ddrspace = sram_free_space(SRAM_DDR, mem_any); // printf("ddrspace:%d\n", ddrspace); >>>>>>> 0d5b7df96a2ee186b7b085dca9cf9a33f791c430 while(1) { asyn_proc_secs = ModulesAsynProcess(); spiMsg->Proc(); if(DMACount[var.master_intr] - ledCount > (SAMPLE_RATE/SAMPLE_NUM)) { blink_led((GPIO_Level)ledOn); ledOn = 1-ledOn; ledCount = DMACount[var.master_intr]; cpu = cpu_utility()*100; //all modules execute time.; mem = (1.0f - (float)space_unused()/total_mem)*10000; spiMsg->DspStatusPush(DSP_MEM_UTILITY, &mem, 1); spiMsg->DspStatusPush(DSP_CPU_UTILITY, &cpu, 1); spiMsg->DspStatusPush(DSP_RUNNING_STATUS,&var.dsp_status ,1); spiMsg->ReportDspStatus(&msg); } //if no preset , 8s request re-send. if(var.clock_ok && DMACount[var.master_intr] - request_topo_count > (8*(SAMPLE_RATE/SAMPLE_NUM))){ if(var.TopoStatus == PRESET_STA::PRESET_NONE) { spiMsg->DspStatusPush(DSP_SCENE_REQUEST,0 ,0); } else if(var.TopoStatus == PRESET_STA::PRESET_DONE){ spiMsg->DspStatusPush(DSP_SCENE_DONE,0 ,0); var.TopoStatus = PRESET_STA::PRESET_NORMAL; } request_topo_count = DMACount[var.master_intr]; } //clock state will change after running,it need check always. //about 1s if(++loop_cnt > 5e+6){ if (var.clock_ok && clock_check_count == DMACount[var.master_intr]) { var.dsp_status = dsp_no_clock; <<<<<<< HEAD spiMsg->DspStatusPush(DSP_RUNNING_STATUS, &var.dsp_status ,1); ======= spiMsg->DspStatusPush(DSP_CLOCK_STATUS, &var.dsp_status ,1); >>>>>>> 0d5b7df96a2ee186b7b085dca9cf9a33f791c430 spiMsg->ReportDspStatus(&msg); printf("clk0 ok\n"); } loop_cnt =0; clock_check_count = DMACount[var.master_intr]; // printf("clk1 ok\n"); } if(!var.clock_ok && var.dsp_status == DSPStatus::dsp_running_ok && var.HandShakeSuccesful) { //notify arm to work normaly. spiMsg->DspStatusPush(DSP_CLOCK_STATUS, &var.dsp_status, 1); request_topo_count = DMACount[var.master_intr] ; var.clock_ok = utrue; <<<<<<< HEAD spiMsg->ReportDspStatus(&msg); printf("clk2 ok\n"); ======= // printf("clk2 ok\n"); >>>>>>> 0d5b7df96a2ee186b7b085dca9cf9a33f791c430 } } }