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

📄 meeprom_g.c

📁 Atheros AP Test with Agilent N4010A source code
💻 C
📖 第 1 页 / 共 3 页
字号:
/* mEEPROM_g.c - contians functions for reading eeprom and getting            */
/*                 Vpd power settings for all channels for gen5 analog chips  */
/* Copyright (c) 2004 Atheros Communications, Inc., All Rights Reserved         */


/* 
Revsision history
--------------------
1.0       Created.
*/

#ifdef VXWORKS
#include "vxworks.h"
#endif

#ifdef __ATH_DJGPPDOS__
#include <unistd.h>
#ifndef EILSEQ  
    #define EILSEQ EIO
#endif	// EILSEQ

#define __int64	long long
typedef unsigned long DWORD;
#define Sleep	delay
#endif	// #ifdef __ATH_DJGPPDOS__

#include "wlantype.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#ifdef WIN32 
#include <memory.h>
#include <conio.h>
#endif
#include "../athreg.h"
#include "../manlib.h"
#include "../mEeprom.h"
#include "../mConfig.h"
#include "../mDevtbl.h"
#include <errno.h>

#include "mEEPROM_g.h"


MANLIB_API A_BOOL setup_raw_dataset_gen5(A_UINT32 devNum, RAW_DATA_STRUCT_GEN5 *pRawDataset_gen5, A_UINT16 myNumRawChannels, A_UINT16 *pMyRawChanList)
{
	A_UINT16	i, j, kk, channelValue;	
	A_UINT32   xpd_mask;
	A_UINT16   numPdGainsUsed = 0;

	if(!allocateRawDataStruct_gen5(devNum, pRawDataset_gen5, myNumRawChannels)) {
		mError(devNum, EIO,"unable to allocate raw dataset (gen5)\n");
		return(0);
	}

	xpd_mask = pRawDataset_gen5->xpd_mask;	
	for (i = 0; i < 4; i++) {
		if ( ((xpd_mask >> i) & 0x1) > 0) {
			numPdGainsUsed++;
		}
	}

	for (i = 0; i < myNumRawChannels; i++) {
		channelValue = pMyRawChanList[i];

		pRawDataset_gen5->pChannels[i] = channelValue;
		
		pRawDataset_gen5->pDataPerChannel[i].channelValue = channelValue;
		pRawDataset_gen5->pDataPerChannel[i].numPdGains = numPdGainsUsed;
		kk = 0;
		for (j = 0; j < MAX_NUM_PDGAINS_PER_CHANNEL; j++) {
			pRawDataset_gen5->pDataPerChannel[i].pDataPerPDGain[j].pd_gain = j;
			if ( ((xpd_mask >> j) & 0x1) > 0) {
				pRawDataset_gen5->pDataPerChannel[i].pDataPerPDGain[j].numVpd = NUM_POINTS_OTHER_PDGAINS;
				kk++;
				if (kk == 1) { 
					// lowest pd_gain corresponds to highest power and thus, has one more point 
					pRawDataset_gen5->pDataPerChannel[i].pDataPerPDGain[j].numVpd = NUM_POINTS_LAST_PDGAIN;
				}
//printf("SNOOP: i = %d, j=%d, xpd_mask = 0x%x, numVpd = %d [A]\n", i, j, xpd_mask, pRawDataset_gen5->pDataPerChannel[i].pDataPerPDGain[j].numVpd);
			} else {
				pRawDataset_gen5->pDataPerChannel[i].pDataPerPDGain[j].numVpd = 0;
//printf("SNOOP: i = %d, j=%d, xpd_mask = 0x%x, numVpd = %d [B]\n", i, j, xpd_mask, pRawDataset_gen5->pDataPerChannel[i].pDataPerPDGain[j].numVpd);			
			}
		}		
	}

	return(1);
}



A_BOOL	allocateRawDataStruct_gen5(A_UINT32 devNum, RAW_DATA_STRUCT_GEN5  *pRawDataset_gen5, A_UINT16 numChannels)
{
	A_UINT16	i, j, k;
	A_UINT16	numVpds = NUM_POINTS_LAST_PDGAIN;

	///allocate room for the channels
	pRawDataset_gen5->pChannels = (A_UINT16 *)malloc(sizeof(A_UINT16) * numChannels);
	if (NULL == pRawDataset_gen5->pChannels) {
		mError(devNum, EIO,"unable to allocate raw data struct (gen5)\n");
		return(0);
	}

	pRawDataset_gen5->pDataPerChannel = (RAW_DATA_PER_CHANNEL_GEN5 *)malloc(sizeof(RAW_DATA_PER_CHANNEL_GEN5) * numChannels);
	if (NULL == pRawDataset_gen5->pDataPerChannel) {
		mError(devNum, EIO,"unable to allocate raw data struct data per channel(gen5)\n");
		free(pRawDataset_gen5->pChannels);
		return(0);
	}
	
	pRawDataset_gen5->numChannels = numChannels;

	for(i = 0; i < numChannels; i ++) {
		pRawDataset_gen5->pDataPerChannel[i].pDataPerPDGain = NULL;
		
		pRawDataset_gen5->pDataPerChannel[i].pDataPerPDGain = (RAW_DATA_PER_PDGAIN_GEN5 *)malloc(sizeof(RAW_DATA_PER_PDGAIN_GEN5) * MAX_NUM_PDGAINS_PER_CHANNEL);
		if (NULL == pRawDataset_gen5->pDataPerChannel[i].pDataPerPDGain) {
			mError(devNum, EIO,"unable to allocate raw data struct pDataPerPDGain (gen5)\n");
			break; //will cleanup outside loop
		}
		for (j=0; j<MAX_NUM_PDGAINS_PER_CHANNEL ; j++) {
			pRawDataset_gen5->pDataPerChannel[i].pDataPerPDGain[j].Vpd = (A_UINT16 *)malloc(numVpds*sizeof(A_UINT16));
			if(pRawDataset_gen5->pDataPerChannel[i].pDataPerPDGain[j].Vpd == NULL) {
				mError(devNum, EIO,"unable to allocate Vpds for a pd_gain (gen5)\n");
				break;
			}
			pRawDataset_gen5->pDataPerChannel[i].pDataPerPDGain[j].pwr_t4 = (A_INT16 *)malloc(numVpds*sizeof(A_INT16));
			if(pRawDataset_gen5->pDataPerChannel[i].pDataPerPDGain[j].pwr_t4 == NULL) {
				mError(devNum, EIO,"unable to allocate pwr_t4 for a pd_gain (gen5)\n");
				if (pRawDataset_gen5->pDataPerChannel[i].pDataPerPDGain[j].Vpd != NULL) {
					free(pRawDataset_gen5->pDataPerChannel[i].pDataPerPDGain[j].Vpd);
				}
				break; // cleanup outside the j loop
			}
		}
		if (j != MAX_NUM_PDGAINS_PER_CHANNEL) { // malloc must've failed
			for (k=0; k<j; k++) {
				if (pRawDataset_gen5->pDataPerChannel[i].pDataPerPDGain[k].Vpd != NULL) {
					free(pRawDataset_gen5->pDataPerChannel[i].pDataPerPDGain[k].Vpd);
				}
				if (pRawDataset_gen5->pDataPerChannel[i].pDataPerPDGain[k].pwr_t4 != NULL) {
					free(pRawDataset_gen5->pDataPerChannel[i].pDataPerPDGain[k].pwr_t4);
				}
			}
			break; // cleanupo outside i loop
		}
	}

	if (i != numChannels) {
		//malloc must have failed, cleanup any allocs
		for (j = 0; j < i; j++) {
			for (k=0; k<MAX_NUM_PDGAINS_PER_CHANNEL; k++) {
				if (pRawDataset_gen5->pDataPerChannel[j].pDataPerPDGain[k].Vpd != NULL) {
					free(pRawDataset_gen5->pDataPerChannel[j].pDataPerPDGain[k].Vpd);
				}
				if (pRawDataset_gen5->pDataPerChannel[j].pDataPerPDGain[k].pwr_t4 != NULL) {
					free(pRawDataset_gen5->pDataPerChannel[j].pDataPerPDGain[k].pwr_t4);
				}
			}
			if (pRawDataset_gen5->pDataPerChannel[j].pDataPerPDGain != NULL) {
				free(pRawDataset_gen5->pDataPerChannel[j].pDataPerPDGain);
			}
		}

		mError(devNum, EIO,"Failed to allocate raw data struct (gen5), freeing anything already allocated\n");
		free(pRawDataset_gen5->pDataPerChannel);
		free(pRawDataset_gen5->pChannels);
		pRawDataset_gen5->numChannels = 0;
		return(0);
	}
	return(1);
}


MANLIB_API A_BOOL setup_EEPROM_dataset_gen5(A_UINT32 devNum, EEPROM_DATA_STRUCT_GEN5 *pEEPROMDataset_gen5, A_UINT16 myNumRawChannels, A_UINT16 *pMyRawChanList)
{
	A_UINT16   i, channelValue;
	A_UINT32   xpd_mask;
	A_UINT16   numPdGainsUsed = 0;

	if(!allocateEEPROMDataStruct_gen5(devNum, pEEPROMDataset_gen5, myNumRawChannels)) {
		mError(devNum, EIO,"unable to allocate EEPROM dataset (gen5)\n");
		return(0);
	}

	xpd_mask = pEEPROMDataset_gen5->xpd_mask;	
	for (i = 0; i < 4; i++) {
		if ( ((xpd_mask >> i) & 0x1) > 0) {
			numPdGainsUsed++;
		}
	}

	for (i = 0; i < myNumRawChannels; i++) {
		channelValue = pMyRawChanList[i];
		pEEPROMDataset_gen5->pChannels[i] = channelValue;
		pEEPROMDataset_gen5->pDataPerChannel[i].channelValue = channelValue;
		pEEPROMDataset_gen5->pDataPerChannel[i].numPdGains = numPdGainsUsed;
	}

	return(1);
}



A_BOOL	allocateEEPROMDataStruct_gen5(A_UINT32 devNum, EEPROM_DATA_STRUCT_GEN5  *pEEPROMDataset_gen5, A_UINT16 numChannels)
{

	//allocate room for the channels
	pEEPROMDataset_gen5->pChannels = (A_UINT16 *)malloc(sizeof(A_UINT16) * numChannels);
	if (NULL == pEEPROMDataset_gen5->pChannels) {
		mError(devNum, EIO,"unable to allocate EEPROM data struct (gen5)\n");
		return(0);
	}

	pEEPROMDataset_gen5->pDataPerChannel = (EEPROM_DATA_PER_CHANNEL_GEN5 *)malloc(sizeof(EEPROM_DATA_PER_CHANNEL_GEN5) * numChannels);
	if (NULL == pEEPROMDataset_gen5->pDataPerChannel) {
		mError(devNum, EIO,"unable to allocate EEPROM data struct data per channel(gen5)\n");
		if (pEEPROMDataset_gen5->pChannels != NULL) {
			free(pEEPROMDataset_gen5->pChannels);
		}
		return(0);
	}
	
	pEEPROMDataset_gen5->numChannels = numChannels;

	return(1);
}



A_BOOL read_Cal_Dataset_From_EEPROM_gen5(A_UINT32 devNum, EEPROM_DATA_STRUCT_GEN5 *pCalDataset, A_UINT32 start_offset, A_UINT32 maxPiers, A_UINT32 *words, A_UINT32 devlibMode) {

	A_UINT16	ii=0;
	A_UINT16	freqmask			= 0xff;
	A_UINT16	dbm_I_mask			= 0x1F; // 5-bits. 1dB step.
	A_UINT16	dbm_delta_mask		= 0xF;  // 4-bits. 0.5dB step.
	A_UINT16	Vpd_I_mask			= 0x7F; // 7-bits. 0-128
	A_UINT16	Vpd_delta_mask		= 0x3F; // 6-bits. 0-63
	A_UINT16	idx, numPiers;
	A_UINT16	freq[NUM_11A_EEPROM_CHANNELS];
//	LIB_DEV_INFO *pLibDev = gLibInfo.pLibDevArray[devNum];
//	MODE_HEADER_INFO	hdrInfo;
	EEPROM_DATA_PER_CHANNEL_GEN5  *currCh;

	idx = (A_UINT16)start_offset;
	ii = 0;
	// no 11a piers, but 11b and 11g piers added in eep_map = 2
	while (ii < maxPiers) {
		if ((words[idx] & freqmask) == 0) {
			idx++;
			break;
		} else {
			freq[ii] = fbin2freq_gen5((words[idx] & freqmask), devlibMode);
//printf ("this is nothing\n");
		}
		ii++;
		
		if (((words[idx] >> 8) & freqmask) == 0) {
			idx++;
			break;
		} else {
			freq[ii] = fbin2freq_gen5(((words[idx] >> 8) & freqmask), devlibMode);
		}
		ii++;
		idx++;
	}
	idx = (A_UINT16)(start_offset + (maxPiers / 2) );

//	hdrInfo = (devlibMode == MODE_11G) ? pLibDev->p16kEepHeader->info11g : pLibDev->p16kEepHeader->info11b;
//	ii = 0;
//	if (hdrInfo.calPier1 != 0xff) freq[ii++] = hdrInfo.calPier1;
//	if (hdrInfo.calPier2 != 0xff) freq[ii++] = hdrInfo.calPier2;
//	if (hdrInfo.calPier3 != 0xff) freq[ii++] = hdrInfo.calPier3;

	numPiers = ii;
	if (!setup_EEPROM_dataset_gen5(devNum, pCalDataset, numPiers, &(freq[0])) ) {
		mError(devNum, EIO,"unable to allocate cal dataset (gen5) in read_from_eeprom...\n");
		return(0);
	}

	for (ii=0; ii<pCalDataset->numChannels; ii++) {

		currCh = &(pCalDataset->pDataPerChannel[ii]);
		
		if (currCh->numPdGains > 0) {
			// read the first NUM_POINTS_OTHER_PDGAINS pwr and Vpd values for pdgain_0
			currCh->pwr_I[0] = (A_UINT16)(words[idx] & dbm_I_mask);
//printf("SNOOP: pwr_I_0 = %d[idx=%d]\n", currCh->pwr_I[0], idx);
			currCh->Vpd_I[0] = (A_UINT16)((words[idx] >> 5) & Vpd_I_mask);
//printf("SNOOP: Vpd_I_0 = %d\n", currCh->Vpd_I[0]);
			currCh->pwr_delta_t2[0][0] = (A_UINT16)((words[idx] >> 12) & dbm_delta_mask);
		
			idx++;
			currCh->Vpd_delta[0][0] = (A_UINT16)(words[idx] & Vpd_delta_mask);
			currCh->pwr_delta_t2[1][0] = (A_UINT16)((words[idx] >> 6) & dbm_delta_mask);
			currCh->Vpd_delta[1][0] = (A_UINT16)((words[idx] >> 10) & Vpd_delta_mask);

			idx++;
			currCh->pwr_delta_t2[2][0] = (A_UINT16)(words[idx] & dbm_delta_mask);
			currCh->Vpd_delta[2][0] = (A_UINT16)((words[idx] >> 4) & Vpd_delta_mask);
		}


		if (currCh->numPdGains > 1) {
			// read the first NUM_POINTS_OTHER_PDGAINS pwr and Vpd values for pdgain_1
			currCh->pwr_I[1] = (A_UINT16)((words[idx] >> 10) & dbm_I_mask);
//printf("SNOOP: pwr_I_1 = %d\n", currCh->pwr_I[1]);
			currCh->Vpd_I[1] = (A_UINT16)((words[idx] >> 15) & 0x1);

			idx++;
			currCh->Vpd_I[1] |= (A_UINT16)((words[idx] & 0x3F) << 1); // upper 6 bits
//printf("SNOOP: Vpd_I_1 = %d\n", currCh->Vpd_I[1]);
			currCh->pwr_delta_t2[0][1] = (A_UINT16)((words[idx] >> 6) & dbm_delta_mask);
			currCh->Vpd_delta[0][1] = (A_UINT16)((words[idx] >> 10) & Vpd_delta_mask);

			idx++;
			currCh->pwr_delta_t2[1][1] = (A_UINT16)(words[idx] & dbm_delta_mask);
			currCh->Vpd_delta[1][1] = (A_UINT16)((words[idx] >> 4) & Vpd_delta_mask);
			currCh->pwr_delta_t2[2][1] = (A_UINT16)((words[idx] >> 10) & dbm_delta_mask);			
			currCh->Vpd_delta[2][1] = (A_UINT16)((words[idx] >> 14) & 0x3);

			idx++;
			currCh->Vpd_delta[2][1] |= (A_UINT16)((words[idx] & 0xF) << 2); // upper 4 bits

		} else if (currCh->numPdGains == 1) {
			// read the last pwr and Vpd values for pdgain_0
			currCh->pwr_delta_t2[3][0] = (A_UINT16)((words[idx] >> 10) & dbm_delta_mask);
			currCh->Vpd_delta[3][0] = (A_UINT16)((words[idx] >> 14) & 0x3);

			idx++;
			currCh->Vpd_delta[3][0] |= (A_UINT16)((words[idx] & 0xF) << 2); // upper 4 bits
			
			idx++;
			// 4 words if numPdGains == 1
		}

		if (currCh->numPdGains > 2) {
			// read the first NUM_POINTS_OTHER_PDGAINS pwr and Vpd values for pdgain_2
			currCh->pwr_I[2] = (A_UINT16)((words[idx] >> 4) & dbm_I_mask);
			currCh->Vpd_I[2] = (A_UINT16)((words[idx] >> 9) & Vpd_I_mask);

			idx++;
			currCh->pwr_delta_t2[0][2] = (A_UINT16)((words[idx] >> 0) & dbm_delta_mask);
			currCh->Vpd_delta[0][2] = (A_UINT16)((words[idx] >> 4) & Vpd_delta_mask);
			currCh->pwr_delta_t2[1][2] = (A_UINT16)((words[idx] >> 10) & dbm_delta_mask);
			currCh->Vpd_delta[1][2] = (A_UINT16)((words[idx] >> 14) & 0x3);

			idx++;
			currCh->Vpd_delta[1][2] |= (A_UINT16)((words[idx] & 0xF) << 2); // upper 4 bits
			currCh->pwr_delta_t2[2][2] = (A_UINT16)((words[idx] >> 4) & dbm_delta_mask);
			currCh->Vpd_delta[2][2] = (A_UINT16)((words[idx] >> 8) & Vpd_delta_mask);


		} else  if (currCh->numPdGains == 2){
			// read the last pwr and Vpd values for pdgain_1
			currCh->pwr_delta_t2[3][1] = (A_UINT16)((words[idx] >> 4) & dbm_delta_mask);
			currCh->Vpd_delta[3][1] = (A_UINT16)((words[idx] >> 8) & Vpd_delta_mask);

			idx++;
			// 6 words if numPdGains == 2
		}

		if (currCh->numPdGains > 3) {
			// read the first NUM_POINTS_OTHER_PDGAINS pwr and Vpd values for pdgain_3
			currCh->pwr_I[3] = (A_UINT16)((words[idx] >> 14) & 0x3);

			idx++;
			currCh->pwr_I[3] |= (A_UINT16)(((words[idx] >> 0) & 0x7) << 2); // upper 3 bits
			currCh->Vpd_I[3] = (A_UINT16)((words[idx] >> 3) & Vpd_I_mask);
			currCh->pwr_delta_t2[0][3] = (A_UINT16)((words[idx] >> 10) & dbm_delta_mask);
			currCh->Vpd_delta[0][3] = (A_UINT16)((words[idx] >> 14) & 0x3);

			idx++;
			currCh->Vpd_delta[0][3] |= (A_UINT16)((words[idx] & 0xF) << 2); // upper 4 bits
			currCh->pwr_delta_t2[1][3] = (A_UINT16)((words[idx] >> 4) & dbm_delta_mask);
			currCh->Vpd_delta[1][3] = (A_UINT16)((words[idx] >> 8) & Vpd_delta_mask);
			currCh->pwr_delta_t2[2][3] = (A_UINT16)((words[idx] >> 14) & 0x3);

			idx++;
			currCh->pwr_delta_t2[2][3] |= (A_UINT16)(((words[idx] >> 0) & 0x3) << 2); // upper 2 bits
			currCh->Vpd_delta[2][3] = (A_UINT16)((words[idx] >> 2) & Vpd_delta_mask);
			currCh->pwr_delta_t2[3][3] = (A_UINT16)((words[idx] >> 8) & dbm_delta_mask); 
			currCh->Vpd_delta[3][3] = (A_UINT16)((words[idx] >> 12) & 0xF);

			idx++;
			currCh->Vpd_delta[3][3] |= (A_UINT16)(((words[idx] >> 0) & 0x3) << 4); // upper 2 bits

			idx++;
			// 12 words if numPdGains == 4

		} else  if (currCh->numPdGains == 3){
			// read the last pwr and Vpd values for pdgain_2
			currCh->pwr_delta_t2[3][2] = (A_UINT16)((words[idx] >> 14) & 0x3);

			idx++;
			currCh->pwr_delta_t2[3][2] |= (A_UINT16)(((words[idx] >> 0) & 0x3) << 2); // upper 2 bits
			currCh->Vpd_delta[3][2] = (A_UINT16)((words[idx] >> 2) & Vpd_delta_mask);

			idx++;
			// 9 words if numPdGains == 3
		}

⌨️ 快捷键说明

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