From faba6b022b86f066d95b1cfdf752573724d5fbcd Mon Sep 17 00:00:00 2001
From: chenlh <2008get@163.com>
Date: 星期五, 29 八月 2025 19:08:13 +0800
Subject: [PATCH] 常规提交

---
 src/tob.cpp           |   87 +++++++++++++++++----
 src/tg/tg_scene.cpp   |   23 ++---
 src/hw_adapter.h      |    4 +
 inc/ModuleProAPI.h    |    1 
 src/param_ctrl.h      |    2 
 src/messageproc.cpp   |   18 ++--
 src/main.cpp          |   10 +-
 src/tg/tg_adapter.cpp |   28 ++++---
 src/messageproc.h     |    2 
 src/ModuleExport.cpp  |    3 
 src/scene.cpp         |   18 +++-
 11 files changed, 133 insertions(+), 63 deletions(-)

diff --git a/inc/ModuleProAPI.h b/inc/ModuleProAPI.h
index 2fba2de..8a0437c 100644
--- a/inc/ModuleProAPI.h
+++ b/inc/ModuleProAPI.h
@@ -42,6 +42,7 @@
 __MODULE_EXPORT IModule* SignalGeneraterCreate(u32 n, ubool linkEnable , u32 sampleRate, u32 sampleNum, u16 inputNum, u16 outputNum);
 __MODULE_EXPORT IModule* ContinuousSPLCreate(u32 n, ubool linkEnable , u32 sampleRate, u32 sampleNum, u16 inputNum, u16 outputNum);
 __MODULE_EXPORT IModule* DummyCreate(u32 n, ubool linkEnable , u32 sampleRate, u32 sampleNum, u16 inputNum, u16 outputNum);
+__MODULE_EXPORT IModule* SignalSourceCreate(u32 n, ubool linkEnable , u32 sampleRate, u32 sampleNum, u16 inputNum, u16 outputNum);
 __MODULE_EXPORT IModule* InputCreate(u32 n,ubool linkEnable , u32 sampleRate, u32 sampleNum, u16 inputNum, u16 outputNum);
 __MODULE_EXPORT IModule* GainCreate(u32 n, ubool linkEnable , u32 sampleRate, u32 sampleNum, u16 inputNum, u16 outputNum);
 __MODULE_EXPORT IModule* OutputCreate(u32 n, ubool linkEnable , u32 sampleRate, u32 sampleNum, u16 inputNum, u16 outputNum);
diff --git a/src/ModuleExport.cpp b/src/ModuleExport.cpp
index 7b16d4f..2edf2ee 100644
--- a/src/ModuleExport.cpp
+++ b/src/ModuleExport.cpp
@@ -19,7 +19,8 @@
 	ModuleProcessLibInit();
 
 	if (modules.empty()) {
-		modules.push_back(ModuleEntry("Input",ModuleType::PROC_INPUT, InputCreate, ufalse));
+		modules.push_back(ModuleEntry("SignalSource", ModuleType::PROC_INPUT, SignalSourceCreate, ufalse));
+//		modules.push_back(ModuleEntry("Input",ModuleType::PROC_INPUT, InputCreate, ufalse));
 		modules.push_back(ModuleEntry("Output",ModuleType::PROC_OUTPUT, OutputCreate, ufalse));
 
 		modules.push_back(ModuleEntry("Meter",ModuleType::PROC_METER, MeterCreate, ufalse));
diff --git a/src/hw_adapter.h b/src/hw_adapter.h
index dfe31d2..a3c36f8 100644
--- a/src/hw_adapter.h
+++ b/src/hw_adapter.h
@@ -29,6 +29,8 @@
 
 	s8 ana_input_num ;
 	s8 ana_output_num ;
+	s8 usb_input_num;
+	s8 usb_output_num;
 	s8 dante_input_num ;
 	s8 dante_output_num ;
 public:
@@ -41,6 +43,8 @@
 		this->ana_output_num = ana_output_num;
 		this->dante_input_num = dante_input_num;
 		this->dante_output_num = dante_output_num;
+		this->usb_input_num = 2;
+		this->usb_output_num = 2;
 	}
 	uvoid get_channel_num(s8* ana_rx_num,s8* ana_tx_num,s8* dante_rx_num,s8* dante_tx_num)
 	{
diff --git a/src/main.cpp b/src/main.cpp
index f4a6f5c..7bcc2f7 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -128,13 +128,13 @@
 	fir_acc_init();
 
 	//通知arm启动完成.
-	//dir: pin12, High level DSP can receive data, low level DSP has data to send .
+	//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);
 
-	u32 ddrspace = sram_free_space(SRAM_DDR, mem_any);
-	printf("ddrspace:%d\n", ddrspace);
+//	u32 ddrspace = sram_free_space(SRAM_DDR, mem_any);
+//	printf("ddrspace:%d\n", ddrspace);
 
 	while(1) {
 		asyn_proc_secs = ModulesAsynProcess();
@@ -178,7 +178,7 @@
 			}
 			loop_cnt =0;
 			clock_check_count = DMACount[var.master_intr];
-			printf("clk1 ok\n");
+//			printf("clk1 ok\n");
 		}
 
 
@@ -187,7 +187,7 @@
 			spiMsg->DspStatusPush(DSP_CLOCK_STATUS, 0, 0);
 			request_topo_count = DMACount[var.master_intr] ;
 			var.clock_ok = utrue;
-			printf("clk2 ok\n");
+//			printf("clk2 ok\n");
 		}
 	}
 
diff --git a/src/messageproc.cpp b/src/messageproc.cpp
index bc6d6a6..652424f 100644
--- a/src/messageproc.cpp
+++ b/src/messageproc.cpp
@@ -47,16 +47,16 @@
 	int data_len;
 
 	ToB* tob = ToB::GetInstance();
-	u16 LevelCnt = tob->GetLevels(Levels);
+	u16 LevelCnt = tob->GetLevels(Levels);	//864 levels
 	u32 msgLen = LevelCnt * sizeof(*Levels);
-
-	int Packegs = (LevelCnt+MSG_DATA_LEN-1)/MSG_DATA_LEN;
+	int Packegs = (msgLen+MSG_DATA_LEN-1)/MSG_DATA_LEN;
 
 	pmsg->magic = 0x5aa5;
 //	pmsg->dataLen = LevelCnt;
 	pmsg->totalPkts = Packegs;
 //	pmsg->pktNo = 1;
 	pmsg->msgType = MSG_GET_LEVEL;
+	pmsg->msgID = LevelCnt;
 
 	// Split packeg
 	for(i=0; i<Packegs; i++){
@@ -67,11 +67,11 @@
 			data_len = MSG_DATA_LEN;
 		}
 
-		memcpy(pmsg->data, Levels + i * MSG_DATA_LEN, data_len);
-		pmsg->dataLen = LevelCnt;
+		memcpy(pmsg->data, Levels + i * MSG_DATA_LEN / sizeof(*Levels), data_len);
+		pmsg->dataLen = data_len;
 		pmsg->pktNo = i;
 
-		pmsg->Enc(MsgType::MSG_GET_LEVEL, 0, msgLen);
+		pmsg->Enc(MsgType::MSG_GET_LEVEL, 0, data_len);
 		txQueue->Push(*pmsg);
 	}
 }
@@ -97,8 +97,8 @@
 		s16* data = (s16*)(ptr + 1);
 
 		data_num = (data_num - sizeof(struct ParamCtrl))/sizeof(s16);
+//		ptr->mid = var.pscene->get_module_id(ptr->mid, type, ptr->cmd) ;
 
-		ptr->mid = var.pscene->get_module_id(ptr->mid, type, ptr->cmd) ;
 		tob->toCtrl(ptr->mid, ptr->cmd, data, data_num);
 	}
 
@@ -120,7 +120,7 @@
 		bin = (u8*)sram_malloc(SRAM_DDR, mem_any, pmsg->totalPkts*MSG_DATA_LEN);
 	}
 	if(bin == NULL) return -1;
-	printf("No:%d len %d\n", pmsg->pktNo,pmsg->dataLen);
+//	printf("No:%d len %d\n", pmsg->pktNo,pmsg->dataLen);
 	var.TopoLoading = utrue;
 	memcpy(bin+pmsg->pktNo*MSG_DATA_LEN, pmsg->data , pmsg->dataLen);
 
@@ -232,7 +232,7 @@
 		ParamCtrl(pmsg);
 		break;
 	case MsgType::MSG_GET_LEVEL:
-		//ReportLevel(pmsg);
+		ReportLevel(pmsg);
 		break;
 	case MsgType::MSG_PARAM_CONFIG:
 	case MsgType::MSG_PARAM_COMPLETED:
diff --git a/src/messageproc.h b/src/messageproc.h
index a3d1d14..fe862ad 100644
--- a/src/messageproc.h
+++ b/src/messageproc.h
@@ -37,7 +37,7 @@
 	Message(u32 num)
 	{
 		txQueue = new Queue<MSG>(num);
-		Levels = new(SRAM_DDR) s16[300];
+		Levels = new s16[868];
 	}
 	~Message()
 	{
diff --git a/src/param_ctrl.h b/src/param_ctrl.h
index 88aa16b..f94f880 100644
--- a/src/param_ctrl.h
+++ b/src/param_ctrl.h
@@ -55,7 +55,7 @@
 		if(mctrl_list.count(mtype))
 			return mctrl_list[mtype].GetCtrlEntry();
 		else
-		return NULL;
+			return NULL;
 	}
 };
 
diff --git a/src/scene.cpp b/src/scene.cpp
index 2e31c30..13a930b 100644
--- a/src/scene.cpp
+++ b/src/scene.cpp
@@ -58,6 +58,7 @@
 	u32 size =  sizeof(struct FlowChartHead);
 	s32 ninports,noutports;
 	u16 rxBufID[64],txBufID[64];
+	u32 dsp_index ;
 
 	u16 dsp_input_num[2] ={0,0};
 	u16 dsp_output_num[2] ={0,0};
@@ -99,20 +100,27 @@
 			mixer->mTxNum = 1;
 			memcpy(bin + size , &rxBufID[1], mixer->mTxNum*sizeof(u16)); size += mixer->mTxNum*sizeof(u16);
 		}
+		if(hw_adapter->get_system_is_dual_dsp()){
+			dsp_index = p->dsp_index ;
+		}
+		else {
+			dsp_index = 0;
+		}
+
 
 		m  = (struct Module *)(bin + size);
 		for(j = 0 ; j< ninports ;j ++) {
-			if(rxBufID[j] > dsp_input_num[p->dsp_index]) {
-				dsp_input_num[p->dsp_index] = rxBufID[j];
+			if(rxBufID[j] > dsp_input_num[dsp_index]) {
+				dsp_input_num[dsp_index] = rxBufID[j];
 			}
 		}
 		for(j = 0 ; j< noutports ;j ++) {
-			if(txBufID[j] > dsp_output_num[p->dsp_index]) {
-				dsp_output_num[p->dsp_index] = txBufID[j];
+			if(txBufID[j] > dsp_output_num[dsp_index]) {
+				dsp_output_num[dsp_index] = txBufID[j];
 			}
 		}
 
-		m->mDsp = hw_adapter->get_system_is_dual_dsp()?p->dsp_index:0;
+		m->mDsp = dsp_index;
 		m->mID = p->proc_id;
 		m->mType = p->proc_type;
 		m->mTag = p->tag;
diff --git a/src/tg/tg_adapter.cpp b/src/tg/tg_adapter.cpp
index 6b51fdb..6d90cec 100644
--- a/src/tg/tg_adapter.cpp
+++ b/src/tg/tg_adapter.cpp
@@ -6,31 +6,35 @@
 {
 	//s32 phy_channel[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,18,19};
 	if(input) {
-		s32 input_num = ana_input_num + dante_input_num ;
+//		s32 input_num = ana_input_num + dante_input_num ;
+		s32 local_ch = ana_input_num + usb_input_num;	// C H G 18
 		if(logic_channel < ana_input_num) {
 			//analog
 			return logic_channel + 1;
 		}
-		else if(logic_channel < input_num) {
-			//dante
-			return 19 + (logic_channel-ana_input_num);
+		else if(logic_channel < local_ch) {
+			//usb
+			return 17 + (logic_channel + 2 - local_ch);
 		}
 		else {
-			//usb
-			return 17 + (logic_channel-input_num);
+			//dante
+			return 19 + (logic_channel - local_ch);
 		}
 	}
-	else {
-		s32 output_num = ana_output_num + dante_output_num ;
-		//output
+	else {	//output
+//		s32 output_num = ana_output_num + dante_output_num ;
+		s32 local_ch = ana_output_num + usb_output_num;	// C H G 18
+		//analog
 		if(logic_channel < ana_output_num) {
 			return logic_channel +1;
 		}
-		else if(logic_channel < output_num) {
-			return 19 + (logic_channel-ana_output_num);
+		else if(logic_channel < local_ch) {
+			//usb
+			return 17 + (logic_channel + 2 - local_ch);
 		}
 		else {
-			return 17 + (logic_channel-output_num);
+			//dante
+			return 19 + (logic_channel - local_ch);
 		}
 	}
 }
diff --git a/src/tg/tg_scene.cpp b/src/tg/tg_scene.cpp
index 2b13629..613fd87 100644
--- a/src/tg/tg_scene.cpp
+++ b/src/tg/tg_scene.cpp
@@ -13,7 +13,7 @@
 
 tgScene::tgScene(hw_adapter_t* adapter):Scene(adapter)
 {
-	s8 inport_str[8],outport_str[8];
+	s8 inport_str[10],outport_str[10];
 	s8 ana_input_num, ana_output_num,dante_input_num,dante_output_num ;
 	s16 input_num, output_num ;
 	s32 n;
@@ -98,31 +98,32 @@
 
 	//mixer
 	sprintf(inport_str, "1-%d", input_num+ 4);
-	sprintf(outport_str, "1-%d", output_num+1);
+	sprintf(outport_str, "%d-%d",input_num+5, input_num+output_num+6);
 	__MADD(166,PROC_MIXER,inport_str,outport_str,1, 1 ,&parameters.mixer, 0, ModuleInterfaceType::SOFT_MODULE);	// .begin()+48
 
 	//crossover
 	for(s32 i =0 ;i < output_num ; i++) {
-		sprintf(outport_str, "%d|", i+1);
-		__MADD(167+i,PROC_CROSSOVER,outport_str, outport_str,1, 0, &parameters.out1[i],2, ModuleInterfaceType::SOFT_MODULE);
+		sprintf(inport_str, "%d|", i+input_num+5);
+		__MADD(167+i,PROC_CROSSOVER,inport_str,inport_str,1, 0, &parameters.out1[i],2, ModuleInterfaceType::SOFT_MODULE);
 	}
 
 	//eq
 	for(s32 i =0 ;i < output_num ; i++) {
-		sprintf(outport_str, "%d|", i+1);
-		__MADD(199+i,PROC_EQ,outport_str, outport_str,1, 0, &parameters.out2[i], 8, ModuleInterfaceType::SOFT_MODULE);
+		sprintf(inport_str, "%d|", i+input_num+5);
+		__MADD(199+i,PROC_EQ,inport_str, inport_str,1, 0, &parameters.out2[i], 8, ModuleInterfaceType::SOFT_MODULE);
 	}
 
 	//delay
 	for(s32 i =0 ;i < output_num ; i++) {
-		sprintf(outport_str, "%d|", i+1);
-		__MADD(231+i,PROC_DELAY,outport_str, outport_str,1, 0, &parameters.out3[i], 1200, ModuleInterfaceType::SOFT_MODULE);
+		sprintf(inport_str, "%d|", i+input_num+5);
+		__MADD(231+i,PROC_DELAY,inport_str, inport_str,1, 0, &parameters.out3[i], 1200, ModuleInterfaceType::SOFT_MODULE);
 	}
 
 	//limit
 	for(s32 i =0 ;i < output_num ; i++) {
+		sprintf(inport_str, "%d|", i+input_num+5);
 		sprintf(outport_str, "%d|", i+1);
-		__MADD(263+i,PROC_LIMIT,outport_str, outport_str,1, 0, &parameters.out4[i],0, ModuleInterfaceType::SOFT_MODULE);
+		__MADD(263+i,PROC_LIMIT,inport_str, outport_str,1, 0, &parameters.out4[i],0, ModuleInterfaceType::SOFT_MODULE);
 	}
 
 	//output
@@ -132,8 +133,6 @@
 	__MADD(296,PROC_SYSCTL,outport_str,outport_str,1, 1, &parameters.sysctl,0, ModuleInterfaceType::PHY_OUTPUT);
 	//meter
 	__MADD(297,PROC_METER,outport_str,"",1, 1, NULL, 0, ModuleInterfaceType::SOFT_MODULE);
-
-	printf("lst size=%d\n", proc_list.size());
 };
 
 
@@ -484,7 +483,7 @@
 		proc->tag =1200;
 		break;
 	case  ModuleType::PROC_CROSSOVER:
-		proc->tag =2;
+		proc->tag =1;
 		break;
 	case  ModuleType::PROC_FEEDBACK:{
 		ptag_module pmodule  = (ptag_module)proc->parameters;
diff --git a/src/tob.cpp b/src/tob.cpp
index e0eecab..0a3fce0 100644
--- a/src/tob.cpp
+++ b/src/tob.cpp
@@ -16,6 +16,7 @@
 #include "../drv/memory.h"
 
 
+
 //#define DEBUG
 #ifdef DEBUG
 #define dbg_printf printf
@@ -95,7 +96,6 @@
 
 	u32 size = sizeof(FlowChartHead);
 	u32 nPhyInput =0 ,nPhyOutput=0;
-
 	frames = new Frames(head->dsp_buffer_num[dsp_index]);
 
 	do {
@@ -187,18 +187,57 @@
 	if (size != nbytes) {
 		dbg_printf("check flowchart some error!\n");
 	}
-	dbg_printf("Phy InputNum %d, Output Num %d\n",nPhyInput,nPhyOutput);
+//	dbg_printf("Phy InputNum %d, Output Num %d\n",nPhyInput,nPhyOutput);
 	SetNumOfChannels(IntDataType::TDM , nPhyInput, nPhyOutput);
 
 	return 	ErrStatus::SUCCESS;
 }
+
+#if 1//DEBUG
+	const s8* type_string[ModuleType::PROC_COUNT] = {
+			"none"
+			,"input"
+			,"meter"
+			,"peq"
+			,"expander"
+			,"compresser"
+			,"limiter"
+			,"mixer"
+			,"delay"
+			,"crossover"
+			,"output"
+			,"gain"
+			,"nhs"
+			,"gain sharing am"
+			,"agc"
+			,"aec"
+			,"ans"
+			,"sysctrl"
+			,"shelf"
+			,"selector"
+			,"gating am"
+			,"spl"
+			,"gating"
+			,"ducker"
+			,"reverb"
+			,"echo"
+			,"geq"
+			,"fir"
+			,"afc"
+			,"signal gen"
+			,"pitch"
+			,"route"
+			,"dummuy input"
+			,"dummy output"
+	};
+#endif
 ErrStatus ToB::CreateModuleV1(const u8* bin, u32 nbytes)
 {
 	FlowChartHead* head = (FlowChartHead*)bin;
 	u32 size = sizeof(FlowChartHead);
 	u16 nPhyInput[IntDataType::COUNT] = { 0,0,0 }, nPhyOutput[IntDataType::COUNT] = { 0,0,0 };
 	s32 len =0;
-	frames = new Frames(head->dsp_buffer_num[dsp_index]); // C H G
+	frames = new Frames(head->dsp_buffer_num[dsp_index]);
 
 	do {
 		const Module* pmod = (Module*)(bin+ size);  size += sizeof(Module);
@@ -225,27 +264,33 @@
 		if (pmod->mDsp != dsp_index)  continue;
 
 #ifdef DEBUG
-		printf("Module ID %d type %d rxnum %d txnum %d tag %d. \n",pmod->mID ,pmod->mType, pmod->mRxNum,pmod->mTxNum,pmod->mTag);
+		printf("Module ID %d type %d %s rxnum %d txnum %d tag %d. \n",pmod->mID ,pmod->mType, type_string[pmod->mType], pmod->mRxNum,pmod->mTxNum,pmod->mTag);
 #endif
-		IModule* m = CreateBaseModule(pmod->mType,pmod->mTag, mRxNum,mTxNum);
+
+		IModule* m = CreateBaseModule(pmod->mType, pmod->mTag, mRxNum, mTxNum);
 		if(!m) {
 			dbg_printf("Module ID Create fail.\n", pmod->mID);
 			continue;
 		}
 
-		m->SetModuleInfo(pmod->mID ,pmod->mType,pmod->mTag);
+//		int ddr = sram_free_space(SRAM_DDR,mem_any);
+//		int ccm = sram_free_space(SRAM_L2,mem_any);
+//		int l1 = sram_free_space(SRAM_L1,mem_heap);
+//		printf("ddr %d ccm %d l1 %d.\n",ddr, ccm ,l1);
+
+		m->SetModuleInfo(pmod->mID ,pmod->mType, pmod->mTag);
 		mList.push_back(m);
 
 		if(pmod->mID >= mModuleIndex.size()) {
 			mModuleIndex.resize(pmod->mID + 1, 0);
 		}
-		mModuleIndex[pmod->mID] = ++mModuleNum  ;
+		mModuleIndex[pmod->mID] = ++mModuleNum;
 
 //		printf("Module id:%d, Tx buffer id:", pmod->mID);
 		for (size_t i = 0; i < mTxNum && !bOutput; i++){
-//			printf("bid %d", mTxbufID[i]);
+			printf("bid %d, ", mTxbufID[i]);
 			if (mTxbufID[i] > 0) {
-				Frame* pcm = frames->GetFrame(mTxbufID[i]-1 );
+				Frame* pcm = frames->GetFrame(mTxbufID[i]-1);
 				m->SetOutputChannelDataPtr(i, pcm);
 
 				if (bInput && mPhyID[i].mIntType < IntDataType::COUNT) {
@@ -253,7 +298,7 @@
 						nPhyInput[mPhyID[i].mIntType] = mPhyID[i].mPhyID;
 					m->SetInputChannelDataPtr(i, pcm);
 					SetRxChannelPtr(static_cast<IntDataType>(mPhyID[i].mIntType), mPhyID[i].mPhyID-1, pcm->Data());
-//					printf("phy_id %d", mPhyID[i].mPhyID);
+					printf("phy_id %d\n", mPhyID[i].mPhyID);
 				}
 			}
 			else {
@@ -284,7 +329,16 @@
 //		printf("\n");
 
 		m->Init();
-		//paramset->GetParamEntry(m->GetModuleType())(m, (uvoid*)pmod->mParamaddr, len);
+//		paramset->GetParamEntry(m->GetModuleType())(m, (uvoid*)pmod->mParamaddr, len);
+		// 获取模块类型
+		u32 moduleType = m->GetModuleType();
+		// 从 paramset 中获取对应的参数控制函数指针
+		ParamCtrl_fn paramEntry = paramset->GetParamEntry(moduleType);
+		// 获取模块参数地址
+		void* paramAddr = (uvoid*)pmod->mParamaddr;
+		// 调用参数控制函数
+		u32 result = paramEntry(m, paramAddr, len);
+
 	} while (size < nbytes);
 
 	if (size != nbytes) {
@@ -331,13 +385,10 @@
 {
 	if(processed) {
 		for (auto iter = mList.begin(); iter < mList.end(); iter++) {
-//			if ((*iter)->GetModuleID() == 166)
-//				continue;
-
-			if((*iter)->GetModuleType() <= 5) {
-				printf("%d ", (*iter)->GetModuleID());
+//			if(((*iter)->GetModuleType() >= 9) && ((*iter)->GetModuleType() <= 9)) {
+//				printf("%d ", (*iter)->GetModuleID());
 				(*iter)->Proc();
-			}
+//			}
 		}
 //		printf("\n");
 	}
@@ -417,8 +468,10 @@
 	for (std::vector<IModule*>::iterator iter = mList.begin();
 		iter != mList.end() ; iter++) {
 		size = (*iter)->GetLevel(buffer + n );
+//		printf("proc %s level num:%d\n",type_string[(*iter)->GetModuleType()],size);
 		n += size;
 	}
+
 	return n;
 }
 

--
Gitblit v1.9.3