From 345edc823540089925b8ae60af34404d608fdfb4 Mon Sep 17 00:00:00 2001
From: chenlh <2008get@163.com>
Date: 星期四, 18 九月 2025 14:58:20 +0800
Subject: [PATCH] 首轮测试代码提交

---
 src/tob.cpp |  199 ++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 155 insertions(+), 44 deletions(-)

diff --git a/src/tob.cpp b/src/tob.cpp
index 3260cad..8d34e61 100644
--- a/src/tob.cpp
+++ b/src/tob.cpp
@@ -6,6 +6,7 @@
  */
 #include <stdlib.h>
 #include <stdio.h>
+#include <heapnew>
 #include "tob.h"
 #include "crc.h"
 #include "config.h"
@@ -15,6 +16,7 @@
 #include "../drv/memory.h"
 
 
+
 //#define DEBUG
 #ifdef DEBUG
 #define dbg_printf printf
@@ -22,31 +24,31 @@
 #define dbg_printf
 #endif
 
-static ToB* tob = NULL;
+//static ToB* tob = NULL;
 
-ToB* ToB::GetInstance()
-{
-	return tob;
-}
+//ToB* ToB::GetInstance()
+//{
+//	return tob;
+//}
 
 ToB::ToB(ubool dualDsp, u32 dspIndex )
-	: dual_dsp(dualDsp), dsp_index(dspIndex),mList(32)
+	: dual_dsp(dualDsp), dsp_index(dspIndex)
 {
-	if(tob != NULL) {
-		delete tob;
-	}
-	tob = this;
-	frames = NULL;
+//	if(tob != NULL) {
+//		delete tob;
+//	}
+//	tob = this;
+	frames = nullptr;
 	processed = ufalse;
 	mModuleNum =0;
 	mModuleIndex.resize(0);
-	paramset = new tg_param_ctrl_t();
+	paramset = new(SRAM_DDR) tg_param_ctrl_t();
 }
 
 ToB::~ToB()
 {
 	toClear();
-	tob = NULL;
+//	tob = NULL;
 	delete paramset;
 }
 
@@ -57,16 +59,23 @@
 ErrStatus ToB::toClear()
 {
 	processed = ufalse;
+	int i = 0;
 
-	for (std::vector<IModule*>::iterator iter = mList.begin();
-		iter != mList.end() ;iter++) {
-		delete *iter;
+//	for (std::vector<IModule*>::iterator iter = mList.begin(); iter != mList.end(); iter++, ++i) {
+//		delete *iter;
+//		*iter = nullptr;
+//	}
+	for (auto iter : mList) {
+		delete iter;
+		iter = nullptr;
 	}
+
 	mList.clear();
 	mModuleIndex.clear();
 
 	if(frames != NULL) {
 		delete frames;
+		frames = nullptr;
 	}
 	mModuleNum = 0;
 
@@ -94,7 +103,6 @@
 
 	u32 size = sizeof(FlowChartHead);
 	u32 nPhyInput =0 ,nPhyOutput=0;
-
 	frames = new Frames(head->dsp_buffer_num[dsp_index]);
 
 	do {
@@ -141,7 +149,7 @@
 		mList.push_back(m);
 
 		if(pmod->mID >= mModuleIndex.size()) {
-			mModuleIndex.resize(pmod->mID + 1,0);
+			mModuleIndex.resize(pmod->mID + 1, 0);
 		}
 		mModuleIndex[pmod->mID] = ++mModuleNum  ;
 
@@ -186,11 +194,50 @@
 	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;
 }
+#define DEBUG 0
+#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;
@@ -203,7 +250,7 @@
 		const Module* pmod = (Module*)(bin+ size);  size += sizeof(Module);
 		const u16* mRxbufID = (u16*)(bin + size);	size += pmod->mRxNum * sizeof(u16);
 		const u16* mTxbufID = (u16*)(bin + size);	size += pmod->mTxNum * sizeof(u16);
-		PhyPort* mPhyID ;
+		PhyPort* mPhyID;
 		ubool bInput=ufalse,bOutput=ufalse;
 		u16 mRxNum = pmod->mRxNum, mTxNum = pmod->mTxNum;
 
@@ -223,25 +270,30 @@
 
 		if (pmod->mDsp != dsp_index)  continue;
 
-#ifdef DEBUG
-		dbg_printf("Module ID %d type %d rxnum %d txnum %d. \n",pmod->mID ,pmod->mType, pmod->mRxNum,pmod->mTxNum);
+#if DEBUG
+		//if (PROC_FIR == pmod->mType)
+			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);
+
+		m->SetModuleInfo(pmod->mID ,pmod->mType, pmod->mTag);
 		mList.push_back(m);
 
 		if(pmod->mID >= mModuleIndex.size()) {
-			mModuleIndex.resize(pmod->mID + 1,0);
+			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]);
 			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) {
@@ -249,13 +301,16 @@
 						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\n", mPhyID[i].mPhyID);
 				}
 			}
 			else {
 				m->SetOutputChannelDataPtr(i, 0);
 			}
 		}
+//		printf(";Rx buffer id:");
 		for (size_t i = 0; i < mRxNum && !bInput; i++) {
+//			printf("mID %d,bid %d\n", pmod->mID, mRxbufID[i]);
 			if (mRxbufID[i] > 0) {
 				Frame* pcm = frames->GetFrame(mRxbufID[i]-1 );
 				m->SetInputChannelDataPtr(i, pcm);
@@ -264,19 +319,41 @@
 					if(nPhyOutput[mPhyID[i].mIntType] < mPhyID[i].mPhyID)
 						nPhyOutput[mPhyID[i].mIntType] = mPhyID[i].mPhyID;
 
-					pcm = frames->AllocFrame();
+					//pcm = frames->AllocFrame(); // It is not necessary to be compatible with the AXE1208 series here, because the TOP architecture is different.
 					m->SetOutputChannelDataPtr(i, pcm);
 					SetTxChannelPtr(static_cast<IntDataType>(mPhyID[i].mIntType), mPhyID[i].mPhyID-1, pcm->Data());
+//					printf("mID %d,bid %d\n", pmod->mID, mPhyID[i].mPhyID-1);
+//					printf("phy_type %d, _id %d\n", mPhyID[i].mIntType, mPhyID[i].mPhyID);
 				}
 			}
 			else {
 				m->SetInputChannelDataPtr(i, 0);
 			}
 		}
+//		printf("\n");
 
 		m->Init();
-		paramset->GetParamEntry(m->GetModuleType())(m, (uvoid*)pmod->mParamaddr, len);
+
+		// 从 paramset 中获取对应的参数控制函数指针
+		ParamCtrl_fn paramEntry = paramset->GetParamEntry( m->GetModuleType());
+		if(paramEntry == NULL) {
+			printf("paramEntry is NULL!\n");
+		}
+		// 调用参数控制函数
+		u32 result = paramEntry(m, (uvoid*)pmod->mParamaddr, len);
+
 	} while (size < nbytes);
+
+//	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("mListAdd:0x%x, ddr %d ccm %d l1 %d.\n", &mList, ddr, ccm ,l1);
+
+//for (auto pl : mList) {
+//	delete pl;
+//	int l2mem = sram_free_space(SRAM_L2, mem_any);
+//	printf("L2mem %d\n", l2mem);
+//}
 
 	if (size != nbytes) {
 		dbg_printf("check flowchart some error!\n");
@@ -286,6 +363,12 @@
 		SetNumOfChannels(static_cast<IntDataType>(i) , nPhyInput[i], nPhyOutput[i]);
 	}
 
+	/*for (auto pt = mList.begin(); pt < mList.end(); pt++) {
+		IModule *p =  *pt._Myptr;
+		static int i = 0;
+		printf("%d, id %d, type %d\n",i++, p->GetModuleID(), p->GetModuleType());
+	}*/
+
 	return 	ErrStatus::SUCCESS;
 }
 ErrStatus ToB::toAnalysis(const u8* bin, u32 nbytes)
@@ -293,14 +376,14 @@
 	FlowChartHead* head = (FlowChartHead*)bin;
 	ErrStatus ret = ErrStatus::ERR_METHOD;
 	//check crc
-	u32 tmp_crc ,crc = head->crcLsb|(head->crcMsb<<16);
-	head->crcLsb = head->crcMsb = 0;
+	s32 tmp_crc;
+	s32 crc = head->crc;
+	head->crc = 0;
 	tmp_crc = CRC::crc32(bin, nbytes);
 	if (tmp_crc != crc) {
-		//dbg_printf("flowchar crc check fail.\n");
+		printf("flowchar crc check fail.\n");
 		return ErrStatus::ERR_PARAM;
 	}
-
 	processed = ufalse;
 
 	if(head->version == 0) {
@@ -309,16 +392,19 @@
 	else if(head->version == 1) {
 		ret = CreateModuleV1(bin, nbytes);
 	}
-
+	processed = utrue;
 	return ret;
 }
 ErrStatus ToB::toProc()
 {
 	if(processed) {
-		for (auto iter = mList.begin();
-			iter != mList.end() ;iter++) {
-			(*iter)->Proc();
+		for (auto iter = mList.begin(); iter < mList.end(); iter++) {
+//			if(((*iter)->GetModuleType() >= 6) && ((*iter)->GetModuleType() <= 6)) {
+//				printf("%d ", (*iter)->GetModuleID());
+				(*iter)->Proc();
+//			}
 		}
+//		printf("\n");
 	}
 	else {
 		MuteOutput();
@@ -338,6 +424,28 @@
 	return 0;
 }
 
+/*ErrStatus ToB::toCtrl(u32 mID, u32 pID, const s16* val, u32 num)
+{
+    if(mID >= mModuleIndex.size() || mModuleIndex[mID] == 0) {
+    	printf("ToB::toCtrl mID Error!\n");
+        return ErrStatus::ERR_PARAM;
+    }
+
+    IModule* m = mList[mModuleIndex[mID]-1];
+    if(!m) {
+    	printf("ToB::toCtrl m Error!\n");
+        return ErrStatus::ERR_PARAM;
+    }
+
+    auto entries  = paramset->GetEntries(m->GetModuleType());
+    if(!entries.second) {
+    	printf("ToB::toCtrl entries Error!\n");
+        return ErrStatus::ERR_METHOD;
+    }
+
+    entries.second(m, pID, const_cast<s16*>(val), num);
+    return ErrStatus::SUCCESS;
+}*/
 ErrStatus ToB::toCtrl(u32 mID, u32 pID, const s16* val, u32 num)
 {
 	if(mID >= mModuleIndex.size() || mModuleIndex[mID] == 0) {
@@ -346,10 +454,10 @@
 
 	IModule* m = mList[mModuleIndex[mID]-1];
 	if( m != NULL) {
-		///m->Ctrl(pID, val, num);
-		paramset->GetCtrlEntry(m->GetModuleType())(m, pID, (s16*)val);
+//		m->Ctrl(pID, val, num);
+		paramset->GetCtrlEntry(m->GetModuleType())(m, pID, (s16*)val, num);
 	}
-
+//	printf("mID:%d pID:%d val[0]:%d val[1]:%d\n",mID, pID, val[0], val[1]);
 	return ErrStatus::SUCCESS;
 }
 
@@ -358,11 +466,11 @@
 	FlowChartHead* head = (FlowChartHead*)bin;
 
 	//check crc
-	u32 tmp_crc ,crc = head->crcLsb|(head->crcMsb<<16);
-	head->crcLsb = head->crcMsb = 0;
+	u32 tmp_crc ,crc = head->crc;
+	head->crc =0;
 	tmp_crc = CRC::crc32(bin, nbytes);
 	if (tmp_crc != crc) {
-		//dbg_printf("flowchar crc check fail.\n");
+		dbg_printf("flowchar crc check fail.\n");
 		return ErrStatus::ERR_PARAM;
 	}
 
@@ -378,12 +486,13 @@
 	}
 
 	if(size != nbytes) {
-		//dbg_printf("check preset has some error!\n");
+		dbg_printf("check preset has some error!\n");
 	}
 
 	processed = utrue;
 	return ErrStatus::SUCCESS;
 }
+
 
 u32 ToB::GetLevels(s16* buffer)
 {
@@ -395,8 +504,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