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

📄 maui_cal.c

📁 atheros ar5001 5002 driver
💻 C
📖 第 1 页 / 共 5 页
字号:
	{
		read_dataset_from_file(pRawDataset, CalSetup.rawDataFilename);
	} else if (CalSetup.forcePiers)
	{
		getCalData(devNum, MODE_11a, CalSetup.customerDebug);
		dump_rectangular_grid_to_file(pRawDataset, "force_piers_power.log") ;
		if (CalSetup.customerDebug)
			dump_rectangular_grid_to_file(pRawGainDataset, "force_piers_gainf.log") ;
	} else
	{
		getCalData(devNum, MODE_11a, CalSetup.customerDebug);
		dump_rectangular_grid_to_file(pRawDataset, "cal_AR5211_power.log") ;
		if (CalSetup.customerDebug)
			dump_rectangular_grid_to_file(pRawGainDataset, "cal_AR5211_gainf.log") ;
	}

	make_cal_dataset_from_raw_dataset() ;

	dMapGrid(pCalDataset, pFullDataset);

	if (CalSetup.customerDebug)
		dump_rectangular_grid_to_file(pFullDataset, "junkff.log");
}



void setupChannelLists()
{
	A_UINT16 lower_lab_channel, upper_lab_channel ;
	A_UINT16 ii,jj;

	lower_lab_channel = (A_UINT16) 20*(goldenParams.channelStart/20) ;
	if (lower_lab_channel < goldenParams.channelStart)
		lower_lab_channel += 20;

	upper_lab_channel = (A_UINT16) 20*(goldenParams.channelStop/20) ;


	jj=0;
	for(ii=goldenParams.channelStart; ii<=goldenParams.channelStop; ii+=goldenParams.measurementStep )
	{
		RAW_CHAN_LIST[jj] = ii;
		jj++;
	}

	if (ii < goldenParams.channelStop)
	{
		ii+=goldenParams.measurementStep ; 
		RAW_CHAN_LIST[jj] = ii;
		jj++;
	} // measurement channels need to include the channelStop

	numRAWChannels = jj;
}
		   

// Write Common Data to eeprom

A_BOOL setup_raw_datasets()
{

	A_UINT16  numPcdacs;
	A_UINT16 i, j, channelValue;
	dPCDACS_EEPROM *pEepromStruct;
	A_UINT16  myNumRawChannels; // needed to handle forced piers case.
	A_UINT16 *pMyRawChanList ;

	// handle forcePierList case here
	if(CalSetup.forcePiers && !CalSetup.readFromFile) // 'cause read from file supercedes
	{
		myNumRawChannels = (A_UINT16) CalSetup.numForcedPiers;
		pMyRawChanList = CalSetup.piersList ;
	} else
	{
		myNumRawChannels = numRAWChannels;
		pMyRawChanList = RAW_CHAN_LIST ;
	}

	numPcdacs = sizeOfRawPcdacs;

	if(!d_allocateEepromStruct( pRawDataset, myNumRawChannels, numPcdacs )) {
		uiPrintf("unable to allocate eeprom struct RawDataset for full struct\n");
		return(0);
	}

	if(!d_allocateEepromStruct( pRawGainDataset, myNumRawChannels, numPcdacs )) {
		uiPrintf("unable to allocate eeprom struct RawGainDataset for full struct\n");
		return(0);
	}

	//now fill in the channel list and pcdac lists
	for (j=0; j<2; j++) 
	{
		pEepromStruct = pRawDataset;
		if (j > 0) 
			pEepromStruct = pRawGainDataset;

		for (i = 0; i < myNumRawChannels; i++) {
			channelValue = pMyRawChanList[i];
	
			pEepromStruct->hadIdenticalPcdacs = TRUE;
			pEepromStruct->pChannels[i] = channelValue;
			
			pEepromStruct->pDataPerChannel[i].channelValue = channelValue;
			pEepromStruct->pDataPerChannel[i].numPcdacValues = numPcdacs ;
			memcpy(pEepromStruct->pDataPerChannel[i].pPcdacValues, RAW_PCDACS, numPcdacs*sizeof(A_UINT16));

			pEepromStruct->pDataPerChannel[i].pcdacMin = pEepromStruct->pDataPerChannel[i].pPcdacValues[0];
			pEepromStruct->pDataPerChannel[i].pcdacMax = pEepromStruct->pDataPerChannel[i].pPcdacValues[numPcdacs - 1];
	
		}
	}

	return(1);

}

A_BOOL	d_allocateEepromStruct(dPCDACS_EEPROM  *pEepromStruct, A_UINT16	numChannels, A_UINT16 numPcdacs )
{
	A_UINT16	i, j;

	///allocate room for the channels
	pEepromStruct->pChannels = (A_UINT16 *)malloc(sizeof(A_UINT16) * numChannels);
	if (NULL == pEepromStruct->pChannels) {
		uiPrintf("unable to allocate eeprom struct\n");
		return(0);
	}

	pEepromStruct->pDataPerChannel = (dDATA_PER_CHANNEL *)malloc(sizeof(dDATA_PER_CHANNEL) * numChannels);
	if (NULL == pEepromStruct->pDataPerChannel) {
		uiPrintf("unable to allocate eeprom struct\n");
		free(pEepromStruct->pChannels);
		return(0);
	}
	
	pEepromStruct->numChannels = numChannels;

	for(i = 0; i < numChannels; i ++) {
		pEepromStruct->pDataPerChannel[i].pPcdacValues = NULL;
		pEepromStruct->pDataPerChannel[i].pPwrValues = NULL;
		pEepromStruct->pDataPerChannel[i].numPcdacValues = numPcdacs;
		
		pEepromStruct->pDataPerChannel[i].pPcdacValues = (A_UINT16 *)malloc(sizeof(A_UINT16) * numPcdacs);
		if (NULL == pEepromStruct->pDataPerChannel[i].pPcdacValues) {
			uiPrintf("unable to allocate eeprom struct\n");
			break; //will cleanup outside loop
		}

		pEepromStruct->pDataPerChannel[i].pPwrValues = (double *)malloc(sizeof(double) * numPcdacs);
		if (NULL == pEepromStruct->pDataPerChannel[i].pPwrValues) {
			uiPrintf("unable to allocate eeprom struct\n");
			break; //will cleanup outside loop
		}

	}

	if (i != numChannels) {
		//malloc must have failed, cleanup any allocs
		for (j = 0; j < i; j++) {
			if (pEepromStruct->pDataPerChannel[j].pPcdacValues != NULL) {
				free(pEepromStruct->pDataPerChannel[j].pPcdacValues);
			}
			if (pEepromStruct->pDataPerChannel[j].pPwrValues != NULL) {
				free(pEepromStruct->pDataPerChannel[j].pPwrValues);
			}
		}

		uiPrintf("Failed to allocate eeprom struct, freeing anything already allocated\n");
		free(pEepromStruct->pDataPerChannel);
		free(pEepromStruct->pChannels);
		pEepromStruct->numChannels = 0;
		return(0);
	}
	return(1);
}

A_BOOL	d_freeEepromStruct(dPCDACS_EEPROM  *pEepromStruct)
{
	A_UINT16	j;
	A_UINT16	numChannels;

	
	numChannels = pEepromStruct->numChannels;


	for (j = 0; j < numChannels; j++) {
		if (pEepromStruct->pDataPerChannel[j].pPcdacValues != NULL) {
			free(pEepromStruct->pDataPerChannel[j].pPcdacValues);
		}
		if (pEepromStruct->pDataPerChannel[j].pPwrValues != NULL) {
			free(pEepromStruct->pDataPerChannel[j].pPwrValues);
		}
	}

	free(pEepromStruct->pDataPerChannel);
	free(pEepromStruct->pChannels);
//	free(pEepromStruct); 
	return(1);
}

void measure_all_channels(A_UINT32 devNum, A_UINT16 debug) 
{
	A_UINT16 fill_zero_pcdac = 40 ;
	A_BOOL fillZeros ;
	A_BOOL fillMaxPwr;
	A_UINT16 numPcdacs ;
	A_INT16 i;
	A_UINT16 *reordered_pcdacs_index ;
	A_UINT16 rr = 0; //reordered_pcdacs_index index
	A_UINT16 channel;
	A_UINT16  pcdac ;
	A_UINT16 reset = 0;
	double power;
	
	dDATA_PER_CHANNEL	*pRawChannelData;
	double				*pRawPwrValue;

	dDATA_PER_CHANNEL	*pGainfChannelData;
	double				*pGainfValue;

	uiPrintf("\nCollecting raw data for the adapter for mode 11a\n");
	numPcdacs = (A_UINT16) sizeOfRawPcdacs ;
	reordered_pcdacs_index = (A_UINT16 *)malloc(sizeof(A_UINT16) * numPcdacs) ;
	if (NULL == reordered_pcdacs_index) 
		uiPrintf("Could not allocate memory for the reordered_pcdacs_index array.\n");

	for (i=numPcdacs-1; i>=0; i--)
	{
		if (RAW_PCDACS[i] <= fill_zero_pcdac)
		{
			reordered_pcdacs_index[rr] = i;
			rr++;
		}
	}

	for (i=0; i<numPcdacs; i++)
	{
		if (RAW_PCDACS[i] > fill_zero_pcdac)
		{
			reordered_pcdacs_index[rr] = i;
			rr++;
		}
	}

	if (rr != numPcdacs)
	{
		uiPrintf("Couldn't reorder pcdacs.\n");
		exit(0);
	}


	if(debug)
	{
		uiPrintf("Reordered pcdacs are: ");
		for (i=0; i<numPcdacs; i++)
		{
			uiPrintf("%d, ", RAW_PCDACS[reordered_pcdacs_index[i]]);
		}
		uiPrintf("\n");
	}

	for (i=0; i<pRawDataset->numChannels; i++)
	{
		channel = pRawDataset->pDataPerChannel[i].channelValue;
		pRawChannelData = &(pRawDataset->pDataPerChannel[i]) ;
		pGainfChannelData = &(pRawGainDataset->pDataPerChannel[i]) ;
				
		//setCornerFixBits(devNum, channel);

		if (i == 0)
		{
			art_resetDevice(devNum, txStation, NullID, channel, 0);
		} else
		{
//			art_resetDevice(devNum, txStation, NullID, channel, 0); 
			art_changeChannel(devNum, channel); //SNOOP: get this in eventually for efficiency
		}

	
		art_txContBegin(devNum, CONT_FRAMED_DATA, RANDOM_PATTERN, 
					    rates[0], DESC_ANT_A | USE_DESC_ANT);

		reset = 0; //1;
		if(CalSetup.useInstruments) 
		{	
			power = pmMeasAvgPower(devPM, reset) ;
		} else
		{
			power = 0;
		}
		reset = 0;

//		Sleep(20); // sleep 20 ms
		Sleep(50); // sleep 150 ms - based on feedback b.
		fillZeros = FALSE ;
		fillMaxPwr = FALSE ;

		for(rr=0; rr<numPcdacs; rr++)
		{
			pcdac = RAW_PCDACS[reordered_pcdacs_index[rr]] ;
			pRawPwrValue = &(pRawChannelData->pPwrValues[reordered_pcdacs_index[rr]]) ;
			pGainfValue  = &(pGainfChannelData->pPwrValues[reordered_pcdacs_index[rr]]) ;
			
			if (CalSetup.xpd < 1)
			{
				art_txContEnd(devNum);
				art_resetDevice(devNum, txStation, NullID, channel, 0);
				art_ForceSinglePCDACTable(devNum, (A_UCHAR) pcdac);
				art_txContBegin(devNum, CONT_FRAMED_DATA, RANDOM_PATTERN, 
							    rates[0], DESC_ANT_A | USE_DESC_ANT);
			} else
			{
				art_ForceSinglePCDACTable(devNum, pcdac);
			}

			if (pcdac > fill_zero_pcdac) 
				fillZeros = FALSE ;

			if (pcdac < fill_zero_pcdac) 
				fillMaxPwr = FALSE ;

			if (fillZeros)
			{
				*pRawPwrValue = 0;
				*pGainfValue  = 0;
				continue ;
			}

			if (fillMaxPwr)
			{
				*pRawPwrValue = CalSetup.maxPowerCap[MODE_11a];
				*pGainfValue  = 110;
				continue ;
			}

			Sleep(50) ;

			if(CalSetup.useInstruments) 
			{	
				power = pmMeasAvgPower(devPM, reset) ;
			} else
			{
				power = 0;
			}

			*pRawPwrValue = (power + CalSetup.attenDutPM) ;
			if (CalSetup.customerDebug)
			{
				art_txContEnd(devNum);
				//Sleep(100);
				*pGainfValue  = (double) dump_a2_pc_out(devNum) ;
				art_txContBegin(devNum, CONT_FRAMED_DATA, RANDOM_PATTERN, 
								rates[0], DESC_ANT_A | USE_DESC_ANT);

			} else
			{
				*pGainfValue = (double) 0 ;
			}

			if ( *pRawPwrValue <= 0 )
				fillZeros = TRUE ;

			if ( *pRawPwrValue >= CalSetup.maxPowerCap[MODE_11a] )
				fillMaxPwr = TRUE ;

			if (debug)
			{
				uiPrintf("  power at pcdac=%d is %2.1f + %2.1f = %2.1f\n", pcdac, power, CalSetup.attenDutPM, *pRawPwrValue);
			}
		}

		uiPrintf("ch: %d  --> max pwr is %2.1f dBm\n", channel, *pRawPwrValue) ;

		art_txContEnd(devNum) ;
	}

	free(reordered_pcdacs_index);
}



void dump_rectangular_grid_to_file( dPCDACS_EEPROM  *pEepromData, char *filename )
{
	A_UINT16	i, j;
	dDATA_PER_CHANNEL	*pChannelData;
    FILE *fStream;
 
	if (CalSetup.customerDebug)
		uiPrintf("\nWriting to file %s\n", filename);
	
    if( (fStream = fopen( filename, "w")) == NULL ) {
        uiPrintf("Failed to open %s - using Defaults\n", filename);
        return;
    }

	//print the frequency values

⌨️ 快捷键说明

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