⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 CP detector (CPD) only reports the onset and removal of a tone. The analysis of timing (if required)
💻 C
字号:
#include "cpdi.h"
#include "tg.h"
#include "tg_miket.h"
#include <stdlib.h>
#include <string.h>

#define DBG_IT	(11)

#define _RUN_SZ (300)
S16 asReply[_RUN_SZ];


S16 asTx[ICPD_FR_SZ];
S16 asRxC[ICPD_FR_SZ];
S16 asRxA[ICPD_FR_SZ];
S16 aS[ICPD_FR_SZ*2];
S16 aC[ICPD_FR_SZ*2];

CPD_tStts	SttsC;
CPD_tStts	SttsA;

#pragma DATA_SECTION(CpdDbA, ".cpdba")
#pragma DATA_SECTION(CpdDbC, ".cpdbc")
#pragma DATA_SECTION(CpdScA, ".cpdsa")
#pragma DATA_SECTION(CpdScC, ".cpdsc")

CPD_tDb CpdDbA, CpdDbC;
CPD_tSc CpdScA, CpdScC;

TG_tDb TgDb;
TG_tSc TgSc;
ITG_Status TgCfg;

volatile S16 sErr = 0;
volatile S32 slA, slC;
volatile S16 sA, sC;
volatile S32 slCntr = 0;
volatile S16 k;

S16 asErrPosDb[8];
S16 asErrPosSc[32];
S16 sErrPos;

/*-------------------------------------------------------------------------*/
void                     tg_config_tone
/*-------------------------------------------------------------------------*/
(
)
{
    TG_MIKET_control(&TgDb,ITG_CMD_RESET, &TgCfg);

    TgCfg.Lo.sFreq = (S16)((32768./4000.)*(350.0)); 
    TgCfg.Lo.sAmp = 1300;
    TgCfg.Hi.sFreq = (S16)((32768./4000.)*(440.0));
    TgCfg.Hi.sAmp = 1300;
    TgCfg.sPreSilenceDuration =  (S16) (25/(ITG_FR_SZ/8));
    TgCfg.sSignalDuration =      (S16) (95/(ITG_FR_SZ/8));
    TgCfg.sPostSilenceDuration = (S16) (80/(ITG_FR_SZ/8));
    
    TG_MIKET_control(&TgDb, ITG_CMD_TONE,&TgCfg);
}
/*-------------------------------------------------------------------------*/
void 						fill_rand
/*-------------------------------------------------------------------------*/
(
S16 *pTo,
S16 sSz,
S16 sLevel
)
{
	S16 s;
	for (s = 0; s < sSz; s++)
	{
		S16 x = rand() - (RAND_MAX/2);
		x  = (S16)((x * (S32)sLevel)>>14); /* /RAND_MAX = 32767 */
		pTo[s] = x;
	}
}

/*-------------------------------------------------------------------------*/
void 						fill_cnt
/*-------------------------------------------------------------------------*/
(
S16 *pTo,
S16 sSz,
S16 sStart
)
{
	S16 s;
	S16 x = sStart;
	for (s = 0; s < sSz; s++)
	{
		pTo[s] = x;
		x += 0x100;
	}
}

/*-------------------------------------------------------------------------*/
S16 						compare
/*-------------------------------------------------------------------------*/
(
S16 *psIn,
S16 *psInC,
S16 sSz
)
{
	S16 s;     
	S16 err = 0;
	
	for (s = 0; s < sSz; s++)
	{
		if(psIn[s] != psInC[s]) {
			err++;
			sErrPos = s;
		}
	}      
	return err;
}
/*-------------------------------------------------------------------------*/
S16 						compare_db
/*-------------------------------------------------------------------------*/
(
)
{
	S16 *psC = (S16 *)&CpdDbC;
	S16 *psA = (S16 *)&CpdDbA;
	S16 s;     
	S16 err = 0;

	for (s = 0; s < 8; s++)asErrPosDb[s] = 0;
	
	for (s = 0; s < sizeof(CpdDbC); s++)
	{
		if(psA[s] != psC[s])
		{
			err++;
			if (err < 8)
			{
				asErrPosDb[err] = s;
			}
		}
	}
	asErrPosDb[0] = err;
	return err;
}
/*-------------------------------------------------------------------------*/
S16 						compare_sc
/*-------------------------------------------------------------------------*/
(
)
{
	S16 *psC = (S16 *)&CpdScC;
	S16 *psA = (S16 *)&CpdScA;
	S16 s;     
	S16 err = 0;
	
	for (s = 0; s < 32; s++)asErrPosSc[s] = 0;
	/* last is ptr, which is different */
	/* all structures are long-word aligned */
	for (s = 0; s < sizeof(CpdScC); s++)
	{
		if(psA[s] != psC[s])
		{
			err++;
			if (err < 32)
			{
				asErrPosSc[err] = s;
			}
		}
	}
	asErrPosSc[0] = err;
	return err;
}


void main ()
{
	memset(&CpdDbA, 0, sizeof(CpdDbA));	
	memset(&CpdDbC, 0, sizeof(CpdDbC));	
	memset(&CpdScA, 0, sizeof(CpdScA));	
	memset(&CpdScC, 0, sizeof(CpdScC));	
	CpdDbC.pCfg = &ICPD_MIKET_DefaultCfg;
	CpdDbA.pCfg = &ICPD_MIKET_DefaultCfg;
	sErr = 0;
#if (DBG_IT == 0)
	if (sizeof(CPD_tDb) != CPD_MIKET_DB_LSZ*2)
		sErr++;
	if (sizeof(CPD_tSc) != CPD_MIKET_SC_LSZ*2)
		sErr++;
#elif (DBG_IT == 1)
	for (k = 0; k < 100; k++)
	{
		slC = rand() * (S32) rand();
		sC = cpd_en2logC(slC, 2000);
		sA = cpd_en2log (slC, 2000);
		if (sC-sA)sErr++;
	}
#elif (DBG_IT == 2)
	for (k = 0; k < 100; k++)
	{
		extern void cpd_move_data_inC (CPD_tDb *pDb, CPD_tSc *pSc, S16 *psIn);	
		fill_rand(CpdDbC.asBpDataSav, CPD_BP_SSZ, 3333);
		fill_rand(CpdDbC.asPgIDataSav, CPD_PG_SSZ, 3333);
		fill_rand(CpdDbC.asPgQDataSav, CPD_PG_SSZ, 3333);
		fill_rand(asRxC, ICPD_FR_SZ, 4444);
		memcpy(&CpdDbA, &CpdDbC, sizeof(CPD_tDb));
		memcpy(asRxA, asRxC, ICPD_FR_SZ);
		cpd_move_data_inC(&CpdDbC, &CpdScC, asRxC);
		cpd_move_data_in (&CpdDbA, &CpdScA, asRxA);
		sErr += compare_db();
		sErr += compare_sc();
		sErr += compare(asRxC, asRxA, ICPD_FR_SZ);
	}
#elif (DBG_IT == 3)
	for (k = 0; k < 100; k++)
	{
		extern void cpd_move_data_inC (CPD_tDb *pDb, CPD_tSc *pSc, S16 *psIn);	
		extern void cpd_filter_bpC    (CPD_tSc *pSc);
		fill_rand(CpdDbC.asBpDataSav, CPD_BP_SSZ, 3333);
		fill_rand(CpdDbC.asPgIDataSav, CPD_PG_SSZ, 3333);
		fill_rand(CpdDbC.asPgQDataSav, CPD_PG_SSZ, 3333);
		fill_rand(asRxC, ICPD_FR_SZ, 4444);
		memcpy(&CpdDbA, &CpdDbC, sizeof(CPD_tDb));
		memcpy(asRxA, asRxC, ICPD_FR_SZ);
		cpd_move_data_in (&CpdDbC, &CpdScC, asRxC);
		cpd_move_data_in (&CpdDbA, &CpdScA, asRxA);

		cpd_filter_bpC(&CpdScC);
		cpd_filter_bp (&CpdScA);
		sErr += compare_sc();
	}	
#elif (DBG_IT == 4)
	for (k = 0; k < 100; k++)
	{
		extern void cpd_move_data_inC (CPD_tDb *pDb, CPD_tSc *pSc, S16 *psIn);	
		extern void cpd_filter_bpC    (CPD_tSc *pSc);
		extern void cpd_sum_subC      (CPD_tSc *pSc);
		fill_rand(CpdDbC.asBpDataSav, CPD_BP_SSZ, 3333);
		fill_rand(CpdDbC.asPgIDataSav, CPD_PG_SSZ, 3333);
		fill_rand(CpdDbC.asPgQDataSav, CPD_PG_SSZ, 3333);
		fill_rand(asRxC, ICPD_FR_SZ, 4444);
		memcpy(&CpdDbA, &CpdDbC, sizeof(CPD_tDb));
		memcpy(asRxA, asRxC, ICPD_FR_SZ);
		cpd_move_data_in (&CpdDbC, &CpdScC, asRxC);
		cpd_move_data_in (&CpdDbA, &CpdScA, asRxA);
		cpd_filter_bp (&CpdScC);
		cpd_filter_bp (&CpdScA);
		
		cpd_sum_subC(&CpdScC);
		cpd_sum_sub (&CpdScA);
		sErr += compare_sc();
	}	
#elif (DBG_IT == 5)
	for (k = 0; k < 100; k++)
	{
		extern void cpd_move_data_inC (CPD_tDb *pDb, CPD_tSc *pSc, S16 *psIn);	
		extern void cpd_filter_bpC    (CPD_tSc *pSc);
		extern void cpd_sum_subC      (CPD_tSc *pSc);
		extern void cpd_filter_pgC    (CPD_tSc *pSc);
		
		fill_rand(CpdDbC.asBpDataSav, CPD_BP_SSZ, 3333);
		fill_rand(CpdDbC.asPgIDataSav, CPD_PG_SSZ, 3333);
		fill_rand(CpdDbC.asPgQDataSav, CPD_PG_SSZ, 3333);
		fill_rand(asRxC, ICPD_FR_SZ, 4444);
		memcpy(&CpdDbA, &CpdDbC, sizeof(CPD_tDb));
		memcpy(asRxA, asRxC, ICPD_FR_SZ);
		
		cpd_move_data_in (&CpdDbC, &CpdScC, asRxC);
		cpd_move_data_in (&CpdDbA, &CpdScA, asRxA);
		cpd_filter_bp (&CpdScC);
		cpd_filter_bp (&CpdScA);
		cpd_sum_sub (&CpdScC);
		cpd_sum_sub (&CpdScA);
		
		cpd_filter_pgC(&CpdScC);
		cpd_filter_pg (&CpdScA);
		sErr += compare_sc();
	}	
#elif (DBG_IT == 6)
	for (k = 0; k < 100; k++)
	{
		extern void cpd_filter_pgC    (CPD_tSc *pSc);
		
		fill_rand(CpdDbC.asBpDataSav, CPD_BP_SSZ, 3333);
		fill_rand(CpdDbC.asPgIDataSav, CPD_PG_SSZ, 3333);
		fill_rand(CpdDbC.asPgQDataSav, CPD_PG_SSZ, 3333);
		fill_rand(asRxC, ICPD_FR_SZ, 4444);
		cpd_move_data_in(&CpdDbC, &CpdScC, asRxC);
		cpd_filter_bp   (&CpdScC);
		cpd_sum_sub     (&CpdScC);
		memcpy(&CpdScA, & CpdScC, sizeof(CPD_tSc));
		
		cpd_filter_pgC(&CpdScC);
		cpd_filter_pg (&CpdScA);
		sErr += compare_sc();
	}	
#elif (DBG_IT == 7)
	for (k = 0; k < 100; k++)
	{
		extern void cpd_sort_freqsC    (CPD_tSc *pSc);

		fill_rand(CpdDbC.asBpDataSav, CPD_BP_SSZ, 3333);
		fill_rand(CpdDbC.asPgIDataSav, CPD_PG_SSZ, 3333);
		fill_rand(CpdDbC.asPgQDataSav, CPD_PG_SSZ, 3333);
		fill_rand(asRxC, ICPD_FR_SZ, 4444);
		cpd_move_data_in(&CpdDbC, &CpdScC, asRxC);
		cpd_filter_bp   (&CpdScC);
		cpd_sum_sub     (&CpdScC);
		cpd_filter_pg   (&CpdScC);
		memcpy(&CpdScA, & CpdScC, sizeof(CPD_tSc));
		
		cpd_sort_freqsC(&CpdScC);
		cpd_sort_freqs (&CpdScA);
		sErr += compare_sc();
	}	
#elif (DBG_IT == 81)
	for (k = 0; k < 1000; k++)
	{
		extern S16 _get_errC  (S32 slEn,S32 slErr);
		extern S16 cpd_get_err(S32 slEn,S32 slErr);
		slA = rand();
		slA <<= 16;
		slA += rand();
		if (slA < 0) slA = -slA;
		sC = rand();
		if (sC > RAND_MAX/2) slA = -slA;

		slC = rand();
		slC <<= 16;
		slC += rand();
		if (slC < 0) slC = -slC;
		
		sC = _get_errC(slC, slA);
		sA = cpd_get_err(slC, slA);
		if (sA != sC) sErr++;
	}
#elif (DBG_IT == 8)
	for (k = 0; k < 1000; k++)
	{
		extern void cpd_get_elem_dataC(CPD_tDb *pDb, CPD_tSc *pSc, 
                              CPD_tElem *pElem,
                              S16 sIdx);
		S16 sNo = 0;
		fill_rand((S16*)&CpdDbC.aOutSav[0], CPD_FREQS*2, 3456);
		fill_rand(CpdDbC.asBpDataSav, CPD_BP_SSZ, 3333);
		fill_rand(CpdDbC.asPgIDataSav, CPD_PG_SSZ, 3333);
		fill_rand(CpdDbC.asPgQDataSav, CPD_PG_SSZ, 3333);
		fill_rand(asRxC, ICPD_FR_SZ, 4444);
		cpd_move_data_in(&CpdDbC, &CpdScC, asRxC);
		cpd_filter_bp   (&CpdScC);
		cpd_sum_sub     (&CpdScC);
		cpd_filter_pg   (&CpdScC);
		cpd_sort_freqs  (&CpdScC);
		cpd_get_lohi    (&CpdDbC, &CpdScC);
		memcpy(&CpdScA, & CpdScC, sizeof(CPD_tSc));
		memcpy(&CpdDbA, & CpdDbC, sizeof(CPD_tDb));
		
    	cpd_get_elem_dataC(&CpdDbC, &CpdScC, &CpdScC.Lo, CpdScC.sLoIdx);
    	cpd_get_elem_data (&CpdDbA, &CpdScA, &CpdScA.Lo, CpdScA.sLoIdx);
		sNo += compare_db();
		sNo += compare_sc();
		if (sNo)
		{
			sErr++;
			slCntr++;
		}
	}	
#elif (DBG_IT == 9)
	for (k = 0; k < 100; k++)
	{
		extern void cpd_move_data_outC(CPD_tDb *pDb, CPD_tSc *pSc);
		S16 sNo = 0;
		fill_rand((S16*)&CpdDbC.aOutSav[0], CPD_FREQS*2, 3456);
		fill_rand(CpdDbC.asBpDataSav, CPD_BP_SSZ, 3333);
		fill_rand(CpdDbC.asPgIDataSav, CPD_PG_SSZ, 3333);
		fill_rand(CpdDbC.asPgQDataSav, CPD_PG_SSZ, 3333);
		fill_rand(asRxC, ICPD_FR_SZ, 4444);
		cpd_move_data_in(&CpdDbC, &CpdScC, asRxC);
		cpd_filter_bp   (&CpdScC);
		cpd_sum_sub     (&CpdScC);
		cpd_filter_pg   (&CpdScC);
		cpd_sort_freqs  (&CpdScC);
		cpd_get_lohi    (&CpdDbC, &CpdScC);
    	cpd_get_elem_data(&CpdDbC, &CpdScC, &CpdScC.Lo, CpdScC.sLoIdx);
		memcpy(&CpdScA, &CpdScC, sizeof(CPD_tSc));
		memcpy(&CpdDbA, &CpdDbC, sizeof(CPD_tDb));
    	cpd_move_data_outC(&CpdDbC, &CpdScC);		
    	cpd_move_data_out (&CpdDbA, &CpdScA);		
		sNo += compare_db();
		sNo += compare_sc();
		if (sNo)
		{
			sErr++;
			slCntr++;
		}
	}	
#elif (DBG_IT == 10)
	{
		ICPD_Status Sts;
		CPD_MIKET_init_db(&CpdDbA, (ICPD_tCfg *)&ICPD_MIKET_DefaultCfg);
		CPD_MIKET_control(&CpdDbA, ICPD_CMD_RESET, &Sts);
		for (k = 0; k < 100; k++)
		{
			fill_rand(asRxA, ICPD_FR_SZ, 5000);
			
			CPD_MIKET_process(&CpdDbA, &CpdScA, asRxA);
		}
	}
#elif (DBG_IT == 11)
	{
		ICPD_Status Sts;
	    TG_MIKET_init_db(&TgDb);
		tg_config_tone();
		CPD_MIKET_init_db(&CpdDbA, (ICPD_tCfg *)&ICPD_MIKET_DefaultCfg);
		CPD_MIKET_control(&CpdDbA, ICPD_CMD_RESET, &Sts);
	
		memset(asReply, 0xfeed, _RUN_SZ);
		for (k = 0; k < _RUN_SZ; k++)
		{
			S16 sState;
			
			fill_rand(asRxA, ICPD_FR_SZ, 40);
			sState = TG_MIKET_process(&TgDb, &TgSc, asRxA); 
			if (sState == 0)
			{
				tg_config_tone();
			}
	//		memset(&CpdScA, 0, sizeof(CpdScA));
			asReply[k] = CPD_MIKET_process(&CpdDbA, &CpdScA, asRxA);
		}
	}
#elif (DBG_IT == 12)
	fill_rand((S16*)&CpdDbC.aOutSav[0], CPD_FREQS*2, 3456);
	fill_rand(CpdDbC.asBpDataSav, CPD_BP_SSZ, 3333);
	fill_rand(CpdDbC.asPgIDataSav, CPD_PG_SSZ, 3333);
	fill_rand(CpdDbC.asPgQDataSav, CPD_PG_SSZ, 3333);
	memcpy(&CpdDbA, &CpdDbC, sizeof(CpdDbC));
	for (k = 0; k < _RUN_SZ; k++)
	{
		fill_rand(asRxA, ICPD_FR_SZ, 4000);
		cpd_move_data_in 	(&CpdDbA, &CpdScA, asRxA);
		cpd_move_data_inC	(&CpdDbC, &CpdScC, asRxA);
		
		cpd_filter_bp 		(&CpdScA);
		cpd_filter_bpC		(&CpdScC);
		
		cpd_sum_sub  		(&CpdScA);
		cpd_sum_subC 		(&CpdScC);
		
		cpd_filter_pg 		(&CpdScA);
		cpd_filter_pgC		(&CpdScC);
		
		cpd_sort_freqs 		(&CpdScA);
		cpd_sort_freqsC		(&CpdScC);
		
		cpd_get_lohi 		(&CpdDbA, &CpdScA);
		cpd_get_lohi 		(&CpdDbC, &CpdScC);
		
		cpd_get_elem_data	(&CpdDbA, &CpdScA, &CpdScA.Lo, CpdScA.sLoIdx);
		cpd_get_elem_dataC	(&CpdDbC, &CpdScC, &CpdScC.Lo, CpdScC.sLoIdx);
		
		cpd_test	 		(&CpdDbA, &CpdScA);
		cpd_test	 		(&CpdDbC, &CpdScC);
		
		cpd_move_data_out	(&CpdDbA, &CpdScA);
		cpd_move_data_outC	(&CpdDbC, &CpdScC);
		
		if (compare_sc())sErr++;		
		if (compare_db())sErr++;		
	}	
#elif (DBG_IT == 13)
#elif (DBG_IT == 14)
#elif (DBG_IT == 15)
#elif (DBG_IT == 16)
#elif (DBG_IT == 17)
#elif (DBG_IT == 18)
#elif (DBG_IT == 19)
#elif (DBG_IT == 20)
#elif (DBG_IT == 21)
#elif (DBG_IT == 22)
#elif (DBG_IT == 23)
#elif (DBG_IT == 24)
#elif (DBG_IT == 25)
#elif (DBG_IT == 26)
#elif (DBG_IT == 27)
#elif (DBG_IT == 28)
#elif (DBG_IT == 29)
#elif (DBG_IT == 30)
#elif (DBG_IT == 31)
#elif (DBG_IT == 32)
#elif (DBG_IT == 33)
#elif (DBG_IT == 34)
#elif (DBG_IT == 35)
#elif (DBG_IT == 36)
#elif (DBG_IT == 37)
#elif (DBG_IT == 38)
#elif (DBG_IT == 39)
#endif
	{
		for(;;)
		{
			extern S16 cpd_en2log(S32 slEn, S16 sCorr);
			slCntr++;
			cpd_en2log(slCntr, 0);
		}
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -