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

📄 cal_gen3.c

📁 Atheros AP Test with Agilent N4010A source code
💻 C
📖 第 1 页 / 共 4 页
字号:
#ifdef _WINDOWS
#include <windows.h>
#endif
#include <stdio.h>
#ifndef LINUX
#include <conio.h>
#endif
#include <assert.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
#include <stdarg.h>
#include "wlantype.h"   /* typedefs for A_UINT16 etc.. */
#include "wlanproto.h"
#include "athreg.h"
#include "manlib.h"     /* The Manufacturing Library */
#include "MLIBif.h"     /* Manufacturing Library low level driver support functions */
#ifdef JUNGO
#include "mld.h"        /* Low level driver information */
#endif
#include "common_hw.h"
#include "manlibInst.h" /* The Manufacturing Library Instrument Library extension */
#include "mEeprom.h"    /* Definitions for the data structure */
#include "dynamic_optimizations.h"
#include "maui_cal.h"   /* Definitions for the Calibration Library */
#include "rssi_power.h"
#include "test.h"
#include "parse.h"
#include "dk_cmds.h"
#include "dk_ver.h"

#ifdef LINUX
#include "linux_ansi.h"
#include "unistd.h"
#endif

#include "art_if.h"

#include "ar5212/mEEPROM_d.h"
#include "cal_gen3.h"

//** the following added by ccshiang
#define __module_cal_gen3__
#include "..\..\..\..\AgN4010WSODrv\AgN4010WSOAPI.h"
#include "..\..\..\..\ART.Common\AgiGlobalDefs.h"

extern long ticksTest;

char *toSeconds(unsigned long ticks);

#undef  DESC_ANT_A
#define DESC_ANT_A		((unsigned char) AgN4010.nAntennaX)

#undef  DESC_ANT_B
//** the above added by ccshiang
extern  A_UINT32	devlibModeFor[3];
extern  A_UINT32	calModeFor[3];

extern  char		modeName[3][122]  ;
extern  A_INT32		devPM, devSA, devATT;
extern  A_BOOL		REWIND_TEST;
extern  char		ackRecvStr[1024];

extern A_UINT16		RAW_CHAN_LIST_2p4[2][3];


static A_UCHAR  bssID[6]     = {0x50, 0x55, 0x5A, 0x50, 0x00, 0x00};
static A_UCHAR  rxStation[6] = {0x10, 0x11, 0x12, 0x13, 0x00, 0x00};	// DUT
static A_UCHAR  txStation[6] = {0x20, 0x22, 0x24, 0x26, 0x00, 0x00};	// Golden
static A_UCHAR  NullID[6]    = {0x66, 0x66, 0x66, 0x66, 0x66, 0x66};
static A_UCHAR  pattern[2] = {0xaa, 0x55};

static A_UINT16 rates[MAX_RATES] = {6,9,12,18,24,36,48,54};


 RAW_DATA_STRUCT_GEN3 RawDatasetGen3_11a ; // raw power measurements for 11a
 RAW_DATA_STRUCT_GEN3 RawDatasetGen3_11g ; // raw power measurements for 11g
 RAW_DATA_STRUCT_GEN3 RawDatasetGen3_11b ; // raw power measurements for 11b
 RAW_DATA_STRUCT_GEN3 *pRawDataset_gen3[3] = {&RawDatasetGen3_11g, &RawDatasetGen3_11b, &RawDatasetGen3_11a} ; // raw power measurements

 EEPROM_DATA_STRUCT_GEN3 CalDatasetGen3_11a ; // calibration dataset
 EEPROM_DATA_STRUCT_GEN3 CalDatasetGen3_11g ; // calibration dataset
 EEPROM_DATA_STRUCT_GEN3 CalDatasetGen3_11b ; // calibration dataset
 EEPROM_DATA_STRUCT_GEN3 *pCalDataset_gen3[3] = {&CalDatasetGen3_11g, &CalDatasetGen3_11b, &CalDatasetGen3_11a} ; // calibration dataset

 RAW_DATA_STRUCT_GEN3 RawGainDatasetGen3_11a ; // raw gainF measurements for 11a
 RAW_DATA_STRUCT_GEN3 RawGainDatasetGen3_11g ; // raw gainF measurements for 11g
 RAW_DATA_STRUCT_GEN3 RawGainDatasetGen3_11b ; // raw gainF measurements for 11b
 RAW_DATA_STRUCT_GEN3 *pRawGainDataset_gen3[3] = {&RawGainDatasetGen3_11g, &RawGainDatasetGen3_11b, &RawGainDatasetGen3_11a} ; // raw gainF measurements

 char calPowerLogFile_gen3[3][122] = {"cal_AR5212_Power_11g.log", "cal_AR5212_Power_11b.log", "cal_AR5212_Power_11a.log"};


void dutCalibration_gen3(A_UINT32 devNum, A_UINT32 mode)
{

	A_BOOL		read_from_file = CalSetup.readFromFile;
	char		*fileName = CalSetup.rawDataFilename;
//	A_UINT16	myNumRawChannels = numRAWChannels;

	if (mode != MODE_11a) {
		read_from_file = CalSetup.readFromFile_2p4[mode];
		fileName       = CalSetup.rawDataFilename_2p4[mode];
//		myNumRawChannels = numRAWChannels_2p4;
	}

	// power and gainf datasets setup and measurement
	if (!setup_datasets_for_cal_gen3(devNum, mode)) {
		uiPrintf("Could not setup gen3 raw datasets for mode %d. Exiting...\n", mode);
		closeEnvironment();
		exit(0);
	}

	if (read_from_file)
	{
		read_dataset_from_file_gen3(pRawDataset_gen3[mode], fileName);
	} else
	{
		if ((mode == MODE_11b) && (CalSetup.useOneCal)){
			uiPrintf("\nUsing 11g calibration data for 11b mode\n");
//			uiPrintf("Re-using 11g calibration data for 11b mode not supported for gen3 yet\n");
//			exit(0);
			copy_11g_cal_to_11b_gen3(pRawDataset_gen3[MODE_11g], pRawDataset_gen3[MODE_11b]);
		} else {
			getCalData(devNum, mode, CalSetup.customerDebug);
		}
		dump_raw_data_to_file_gen3(pRawDataset_gen3[mode], calPowerLogFile_gen3[mode]) ;
//		if (CalSetup.customerDebug)
//			dump_raw_data_to_file_gen3(pRawGainDataset_gen3[mode], calGainfLogFile_gen3[mode]) ;
	}
	raw_to_eeprom_dataset_gen3(pRawDataset_gen3[mode], pCalDataset_gen3[mode]);
}

void copy_11g_cal_to_11b_gen3(RAW_DATA_STRUCT_GEN3 *pRawDataSrc, RAW_DATA_STRUCT_GEN3 *pRawDataDest) {

	A_UINT32 ii, jj, kk, idxL, idxR;
	RAW_DATA_PER_CHANNEL_GEN3	*pChDest;
	RAW_DATA_PER_CHANNEL_GEN3	*pChSrcL;
	RAW_DATA_PER_CHANNEL_GEN3	*pChSrcR;
	RAW_DATA_PER_XPD_GEN3		*pXpdDest;
	RAW_DATA_PER_XPD_GEN3		*pXpdSrcL;
	RAW_DATA_PER_XPD_GEN3		*pXpdSrcR;

	assert(pRawDataDest != NULL);
	assert(pRawDataSrc  != NULL);

	// map the 11g data to 2412, 2472, 2484 for 11b to give 2484 its
	// dedicated data.
	pRawDataDest->numChannels = 3;
	CalSetup.TrgtPwrStartAddr += 5*pRawDataDest->numChannels;
	CalSetup.numForcedPiers_2p4[MODE_11b] = pRawDataDest->numChannels;

	pRawDataDest->xpd_mask    = pRawDataSrc->xpd_mask;

	idxL = 0;
	idxR = 0;
	for (ii = 0; ii < pRawDataDest->numChannels ; ii++) {
		CalSetup.piersList_2p4[MODE_11b][ii] = RAW_CHAN_LIST_2p4[MODE_11b][ii];
		pRawDataDest->pChannels[ii] = RAW_CHAN_LIST_2p4[MODE_11b][ii];
		mdk_GetLowerUpperIndex(pRawDataDest->pChannels[ii], pRawDataSrc->pChannels, pRawDataSrc->numChannels, &(idxL), &(idxR));
		pChDest = &(pRawDataDest->pDataPerChannel[ii]);
		pChSrcL  = &(pRawDataSrc->pDataPerChannel[idxL]);
		pChSrcR  = &(pRawDataSrc->pDataPerChannel[idxR]);

		pChDest->channelValue = pRawDataDest->pChannels[ii];
		pChDest->maxPower_t4  = mdk_GetInterpolatedValue_Signed16(
									pChDest->channelValue,
									pChSrcL->channelValue,
									pChSrcR->channelValue,
									pChSrcL->maxPower_t4,
									pChSrcR->maxPower_t4
								);
		pChDest->maxPower_t4  += (A_UINT16)(4*CalSetup.cck_ofdm_delta);

		if (pChDest->channelValue == 2484) {
			pChDest->maxPower_t4 -= (A_UINT16)(4*CalSetup.ch14_filter_cck_delta);
		}

		for (jj = 0; jj < NUM_XPD_PER_CHANNEL; jj++) {
			if ( ((1 << jj) & pRawDataDest->xpd_mask) == 0 ) {
				continue;
			}
			pXpdDest  = &(pChDest->pDataPerXPD[jj]);
			pXpdSrcL  = &(pChSrcL->pDataPerXPD[jj]);
			pXpdSrcR  = &(pChSrcR->pDataPerXPD[jj]);
			// following quantities expected to remain the same for idxL and idxR
			assert(pXpdSrcL->numPcdacs == pXpdSrcR->numPcdacs);
			assert(pXpdSrcL->xpd_gain  == pXpdSrcR->xpd_gain);
			pXpdDest->numPcdacs = pXpdSrcL->numPcdacs;
			pXpdDest->xpd_gain  = pXpdSrcL->xpd_gain;
			for (kk = 0; kk < pXpdDest->numPcdacs; kk++) {
				pXpdDest->pcdac[kk] = getInterpolatedValue(	pChDest->channelValue,
											pChSrcL->channelValue,
											pChSrcR->channelValue,
											pXpdSrcL->pcdac[kk],
											pXpdSrcR->pcdac[kk],
											FALSE // don't scale_up
										);

				pXpdDest->pwr_t4[kk] = mdk_GetInterpolatedValue_Signed16(
											pChDest->channelValue,
											pChSrcL->channelValue,
											pChSrcR->channelValue,
											pXpdSrcL->pwr_t4[kk],
											pXpdSrcR->pwr_t4[kk]
										);

				pXpdDest->pwr_t4[kk] += (A_UINT16)(4*CalSetup.cck_ofdm_delta);

				if (pChDest->channelValue == 2484) {
					pXpdDest->pwr_t4[kk] -= (A_UINT16)(4*CalSetup.ch14_filter_cck_delta);
				}
			}
		}
	}
} // copy_11g_cal_to_11b_gen3

A_BOOL setup_datasets_for_cal_gen3(A_UINT32 devNum, A_UINT32 mode) {

//	A_UINT16	myNumRawChannels = numRAWChannels; // needed to handle forced piers case.
	A_UINT16	myNumRawChannels ;
	A_UINT16	*pMyRawChanList ;
	A_BOOL		read_from_file = CalSetup.readFromFile;
	A_BOOL		force_piers = CalSetup.forcePiers;

//	pMyRawChanList	 = RAW_CHAN_LIST ;

	if (mode != MODE_11a) {
		read_from_file		= CalSetup.readFromFile_2p4[mode];
//		myNumRawChannels	= numRAWChannels_2p4;
		myNumRawChannels	= 3;

		force_piers			= CalSetup.forcePiers_2p4[mode];
//		pMyRawChanList = &(RAW_CHAN_LIST_2p4[mode][0]) ;
	}


	// handle forcePierList case here
	if(force_piers && !read_from_file) // 'cause read from file supercedes
	{
		myNumRawChannels = (A_UINT16) ((mode == MODE_11a) ? CalSetup.numForcedPiers : CalSetup.numForcedPiers_2p4[mode]);
		if ((mode == MODE_11b) && (CalSetup.useOneCal)) {
			myNumRawChannels = 3; // 2412, 2472, 2484
		}
		pMyRawChanList	 = ((mode == MODE_11a) ? CalSetup.piersList : CalSetup.piersList_2p4[mode]);
	} else {
		uiPrintf("Automatic pier computation for gen3 not supported yet. Please specify the forced_piers_list\n");
	}

	if (!setup_raw_dataset_gen3(devNum, pRawDataset_gen3[mode], myNumRawChannels, pMyRawChanList)) {
		uiPrintf("Could not setup raw dataset for gen3 cal for mode %d\n", mode);
		return(0);
	}

	if (!setup_raw_dataset_gen3(devNum, pRawGainDataset_gen3[mode], myNumRawChannels, pMyRawChanList)) {
		uiPrintf("Could not setup raw gainF dataset for gen3 cal for mode %d\n", mode);
		return(0);
	}

	if (!setup_EEPROM_dataset_gen3(devNum, pCalDataset_gen3[mode], myNumRawChannels, pMyRawChanList)) {
		uiPrintf("Could not setup cal dataset for gen3 cal for mode %d\n", mode);
		return(0);
	}

	return(1);
}


void measure_all_channels_gen3(A_UINT32 devNum, A_UINT32 debug, A_UINT32 mode) {

	A_UINT32	xpd_gain, xgain_list[2]; // handle upto two xpd_gains
	A_INT32		ii, jj, kk, ll;
	A_UINT16	turbo = 0;
	A_UINT16	channel;
	A_UINT16	pcdac ;
	A_UINT16	reset = 0;
	double		power;
	A_UCHAR		devlibMode ; // use setResetParams to communicate appropriate mode to devlib

	double		maxPower;
	double		myAtten;
	A_INT16		lo_pcd, max_pcdac;
	A_INT16		PCDL = 11;
	A_INT16		PCDH = 41;
	A_UINT16	curr_intercept_estimate ;
	A_UINT32	gainF;
	A_UINT32    mixvga_ovr, mixgain_ovr;
	A_UINT32    gain1, gain25, intp_gain, prev_gain;
	double		pwr1, pwr25 ;
	A_INT16     dirxn;
	A_UINT16    sleep_interval = 150;
	A_UINT16    pcd1, pcd2, pcd_interp;
	double      pwrL, pwrH;
//** the following added by ccshiang
	double      saved_myAtten;
//** the above added by ccshiang
	double      attemptPower = 0;
	A_UINT16    tempPcdac, copyPcdac;

	mixvga_ovr = art_getFieldForMode(devNum, "rf_mixvga_ovr", mode, turbo);
	mixgain_ovr = art_getFieldForMode(devNum, "rf_mixgain_ovr", mode, turbo);
	art_writeField(devNum, "rf_mixvga_ovr", 0);


	switch (mode) {
	case MODE_11a :
		devlibMode = MODE_11A;
		max_pcdac = CalSetup.max_pcdac_11a;
		xpd_gain   = CalSetup.xgain;
		myAtten	   = CalSetup.attenDutPM;
		curr_intercept_estimate = IDEAL_10dB_INTERCEPT_5G;
		CalSetup.TrgtPwrStartAddr += 5; // upto 10 piers
		attemptPower = CalSetup.attempt_pcdac_11a;
		break;
	case MODE_11g :
		devlibMode = MODE_11G;
		max_pcdac = CalSetup.max_pcdac_11g;
		xpd_gain   = CalSetup.xgain_2p4[mode];
		myAtten	   = CalSetup.attenDutPM_2p4[mode];
		curr_intercept_estimate = IDEAL_10dB_INTERCEPT_2G;
		attemptPower = CalSetup.attempt_pcdac_11g;
		break;
	case MODE_11b :
		devlibMode = MODE_11B;
		max_pcdac = CalSetup.max_pcdac_11b;
		xpd_gain   = CalSetup.xgain_2p4[mode];
		myAtten	   = CalSetup.attenDutPM_2p4[mode];
		curr_intercept_estimate = IDEAL_10dB_INTERCEPT_2G;
		attemptPower = CalSetup.attempt_pcdac_11b;
//		if (CalSetup.pmModel == PM_436A) {
		if (CalSetup.pmModel == NRP_Z11) {
			sleep_interval = 50;
		} else {
//		if (1) {
			sleep_interval = 250;
		}
		break;
	default:
		uiPrintf("Unknown mode supplied to measure_all_channels_gen3 : %d \n", mode);
		break;
	}
	CalSetup.TrgtPwrStartAddr += 5*pRawDataset_gen3[mode]->numChannels;
//** the following added by ccshiang
	saved_myAtten = myAtten;
//** the above added by ccshiang

	configSetup.eepromLoad = 0;
	art_setResetParams(devNum, configSetup.pCfgFile, (A_BOOL)configSetup.eepromLoad,
					(A_BOOL)configSetup.eepromHeaderLoad, (A_UCHAR)devlibMode, configSetup.use_init);

//** the following added by ccshiang
	ticksTest = GetTickCount();
	AgN4010_Log_LogIt("<<<*** %s -- Collecting raw data for the adapter ***>>>",modeName[mode]);
	agiDo_Cal_Setting();
//** the above added by ccshiang
	uiPrintf("\nL%d, Collecting raw data for the adapter for mode %s\n",_module_line(),modeName[mode]);

	art_changeField(devNum, "rf_ovr", 0);
	art_changeField(devNum, "rf_xpdsel", 1);

⌨️ 快捷键说明

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