?? mmaskphys.c
字號:
// ported from trimmed oahu.pm in perl -- P.Dua 11/02
// To Do list :
// set goldDevNum, dutDevNum way upfront
// fix mem_read calls
// fix mem_write calls
#ifdef _WINDOWS
#include <windows.h>
#endif
#include <stdio.h>
#ifdef WIN32
#include <memory.h>
#include <conio.h>
#endif
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
#include <stdarg.h>
#include "wlantype.h" /* typedefs for A_UINT16 etc.. */
#include "athreg.h"
#include "manlib.h" /* The Manufacturing Library */
#include "mConfig.h"
#ifdef ANWI
#include "mld_anwi.h"
#endif
#ifdef LINUX
#include "mld_linux.h"
#endif
#include "mMaskPhys.h"
#include "mMaskMath.h"
A_UINT32 CAP_DESC_PTR;
A_UINT32 CAP_DATA_PTR;
extern A_UINT32 goldDevNum; // Needs to be set up at the begining. obviates having to pass around devNum to every call
extern A_UINT32 dutDevNum; // Needs to be set up at the begining. probably never needed - DUT just transmits.
// Routine to determine the start and stop indices
// of an n-point array based on the +/- % values
void slice (A_UINT32 n, double plus_pct, double minus_pct, A_UINT32 *beg, A_UINT32 *end) {
minus_pct = (minus_pct > 50) ? 50 : minus_pct;
plus_pct = (plus_pct > 50) ? 50 : plus_pct;
*beg = (n/2) - (A_UINT32)(n*minus_pct/100);
*end = (n/2) + (A_UINT32)(n*plus_pct/100) - 1;
}
// Routine to reverse the least significant bits
A_INT32 bit_rev (A_INT32 val, A_INT32 bits) {
A_INT32 k,retval=0;
for (k=0; k<bits; k++) {
retval <<= 1;
retval |= (val >> k) & 1;
}
return(retval);
}
// Routine to create an n-bit mask
A_UINT32 mask (A_UINT32 n) {
return((((1 << (n-1)) - 1) << 1) + 1);
}
// Routine to truncate a signed 32-bit to signed n-bit word
A_INT32 sign_ext (A_INT32 field, A_UINT32 wid) {
if ((field >> (wid-1)) == 1) {
return(-1*((field ^ mask(wid)) + 1));
}
return(field);
}
// Routine to truncate a signed 32-bit to signed n-bit word
A_INT32 sign_trunc (A_INT32 signed_val, A_UINT32 wid) {
A_UINT32 neg = (signed_val < 0) ? 1 : 0;
A_UINT32 mask_wid = mask(wid);
A_UINT32 mantissa = mask(wid-1);
A_UINT32 mag = neg ? -signed_val : signed_val;
if (neg) { mantissa++; }
if (mag > mantissa) {
printf( "\nIn function sign_trunc, Magnitude mag (%d) is larger than mantissa (%d)!\n", mag, mantissa);
exit(0);
} else {
return(neg ? (mag ^ mask_wid)+1 : mag);
}
}
// Routine to extract a field
A_UINT32 field_read (A_UINT32 base, A_UINT32 reg, A_UINT32 ofs, A_UINT32 bits) {
A_UINT32 addr = base+(reg<<2);
A_UINT32 mask_bits = mask(bits);
return ((REGR(goldDevNum, addr) >> ofs) & mask_bits);
}
// Routine to modify a field
void field_write (A_UINT32 base, A_UINT32 reg, A_UINT32 ofs, A_UINT32 bits, A_UINT32 unsignd) {
A_UINT32 addr = base+(reg<<2);
A_UINT32 mask_bits = mask(bits);
if (unsignd > mask_bits) {
printf( "\nIn function field_write, value for the field %d is larger than the mask (%d)!\n", unsignd, mask_bits);
exit(0);
} else {
REGW(goldDevNum, addr,(REGR(goldDevNum, addr) & ~(mask_bits<<ofs) | (unsignd<<ofs)));
}
}
// Routine to read expected attenuation of tx-rx switch
A_UINT32 txrxatten () {
return (REGR(goldDevNum, 0x9848) >> 12) & 0x3f;
}
// Routine to read expected attenuation of beanie lna switch
A_UINT32 blnaatten_db_2ghz () {
return (REGR(goldDevNum, 0xa20c) >> 5) & 0x1f;
}
// Routine to read expected attenuation of beanie-sombrero switch
A_UINT32 bswatten_db_2ghz () {
return REGR(goldDevNum, 0xa20c) & 0x1f;
}
// Routine to configure most of the agc timing and level params
void adjust_agc (A_UINT32 switch_settling, A_UINT32 agc_settling, double coarse_high,
double coarsepwr_const, double relpwr, A_UINT32 min_num_gain_change,
double total_desired, double pga_desired_size, double adc_desired_size) {
A_UINT32 wrdata;
wrdata = REGR(goldDevNum, 0x9844) & ~((0x7f<<7) | 0x7f);
wrdata |= (switch_settling<<15) | agc_settling;
REGW(goldDevNum, 0x9844, wrdata);
wrdata = REGR(goldDevNum, 0x985c) & ~((0x7f<<15) | 0x7f);
wrdata |= (sign_trunc((A_UINT32)(coarse_high*2),7)<<15) | (sign_trunc((A_UINT32)(coarsepwr_const*2),7));
REGW(goldDevNum, 0x985c, wrdata);
wrdata = REGR(goldDevNum, 0x9858) & ~(0x3f<<6);
wrdata |= (sign_trunc((A_UINT32)(relpwr*2),6)<<6);
REGW(goldDevNum, 0x9858, wrdata);
wrdata = REGR(goldDevNum, 0x9860) & ~(0x7<<3);
wrdata |= (min_num_gain_change<<3);
REGW(goldDevNum, 0x9860, wrdata);
wrdata = REGR(goldDevNum, 0x9850) & ~((0xff<<20) | (0xff<<8) | 0xff);
wrdata |= ((sign_trunc((A_UINT32)(total_desired*2),8)<<20) |
(sign_trunc((A_UINT32)(pga_desired_size*2),8)<<8) |
(sign_trunc((A_UINT32)(adc_desired_size*2),8)));
REGW(goldDevNum, 0x9850, wrdata);
}
// Routine to force gain tables and switches (NOTE: values latch on rx_frame!!)
void force_gain (A_UINT32 rfgain, A_UINT32 bbgain, A_UINT32 blnaatten_db_2ghz,
A_UINT32 bswatten_db_2ghz, A_UINT32 txrxatten) {
A_UINT32 blna_switch_2ghz = (blnaatten_db_2ghz!=0)?0:1;
A_UINT32 bsw_switch_2ghz = (bswatten_db_2ghz!=0)?1:0;
A_UINT32 rxtx_flag = (txrxatten!=0)?1:0;
A_UINT32 wrdata;
wrdata = REGR(goldDevNum, 0x9848) | (1<<23); // enable force rfgain, bbgain, rxtx_flag etc...
REGW(goldDevNum, 0x9848,wrdata);
wrdata = REGR(goldDevNum, 0x984c) & ~((0x7f<<25) | (0x7f<<18) | (0x1<<17));
wrdata |= ((rfgain<<25) | (bbgain<<18) | (rxtx_flag<<17));
REGW(goldDevNum, 0x984c,wrdata);
wrdata = REGR(goldDevNum, 0xa20c) & ~((0x1<<25) | (0x1<<24));
wrdata |= ((blna_switch_2ghz<<25) | (bsw_switch_2ghz<<24));
REGW(goldDevNum, 0xa20c,wrdata);
printf("snoop: force_gain: reg 18 = 0x%x\n", REGR(goldDevNum, 0x9848));
}
// Routine to force gain tables and switches
void read_gain (A_UINT32 *rfgain,A_UINT32 *bbgain,A_UINT32 *blnaatten_db_2ghz,
A_UINT32 *bswatten_db_2ghz,A_UINT32 *txrxatten) {
A_UINT32 blna_switch_2ghz,bsw_switch_2ghz,rxtx_flag;
A_UINT32 rddata;
rddata = REGR(goldDevNum, 0x984c);
*rfgain = ((rddata >> 25) & 0x7f);
*bbgain = ((rddata >> 18) & 0x7f);
rxtx_flag = ((rddata >> 17) & 0x1);
if (rxtx_flag!=0) {
rddata = REGR(goldDevNum, 0x9848);
*txrxatten = ((rddata >> 12) & 0x3f);
} else {
*txrxatten = 0;
}
rddata = REGR(goldDevNum, 0xa20c);
blna_switch_2ghz = ((rddata >> 25) & 0x1);
bsw_switch_2ghz = ((rddata >> 24) & 0x1);
if (blna_switch_2ghz==0) {
*blnaatten_db_2ghz = ((rddata >> 5) & 0x1f);
} else {
*blnaatten_db_2ghz = 0;
}
if (bsw_switch_2ghz!=0) {
*bswatten_db_2ghz = (rddata & 0x1f);
} else {
*bswatten_db_2ghz = 0;
}
}
// Routine to calculate the total gain - takes a gain array and mode (dk::mode 11a/b/g) as input
double total_gain (A_UINT32 *gain, A_UINT32 mode) {
if (mode == 0) {
return (double)(gain[0]+ gain[1])/2.0 - gain[4];
} else {
return (double)( gain[0]+ gain[1])/2.0 - gain[2]- gain[3]- gain[4];
}
}
// Routine to pad the rx buffer length to an integer multiple of 4
A_UINT32 pad_rx_buffer (A_UINT32 buf_len) {
return ((A_UINT32)((buf_len+3)/4))*4;
}
// Routine to report the most likely gain settings during descriptor consumption
void report_gain (A_UINT32 rx_desc_ptr, A_UINT32 desc_cnt, A_UINT32 *gain) {
A_UINT32 desc5 = rx_desc_ptr+(desc_cnt-1)*DESC_LEN+0x14 ;
A_UINT32 k = 0;
A_UINT32 start_time = milliTime();
A_UINT32 *rfgain;
A_UINT32 *bbgain;
A_UINT32 *blna;
A_UINT32 *xatten1;
A_UINT32 *xatten2;
A_BOOL TIMED_OUT = FALSE;
char name[25];
//printf("snoop:report_gain: entered report_gain\n");
rfgain = (A_UINT32 *) malloc(20*sizeof(A_UINT32));
bbgain = (A_UINT32 *) malloc(20*sizeof(A_UINT32));
blna = (A_UINT32 *) malloc(20*sizeof(A_UINT32));
xatten1 = (A_UINT32 *) malloc(20*sizeof(A_UINT32));
xatten2 = (A_UINT32 *) malloc(20*sizeof(A_UINT32));
//printf("snoop:report_gain: done with mallocs\n");
while (((mem_read(desc5) & 0x1) != 0x1) && (!TIMED_OUT)) {
printf("snoop:report_gain: iteration %d : read_gain res", k);
read_gain(&(rfgain[k]),&(bbgain[k]),&(blna[k]),&(xatten1[k]),&(xatten2[k]));
printf("ults are: %d, %d, %d, %d, %d\n", rfgain[k],bbgain[k],blna[k],xatten1[k],xatten2[k]);
k++;
mSleep(10);
if (milliTime() >= start_time+10000) {
printf( "Timed out in report_gainf after 10s!\n");
TIMED_OUT = TRUE;
}
if (k>16) {
TIMED_OUT = TRUE;
}
}
printf("snoop:report_gain: out of the loop with k = %d\n", k);
mem_write(desc5, 0x0);
strcpy(name, "rfgain");
gain[0] = mode(&(rfgain[0]), k, name);
printf("snoop:report_gain: rfgain mode = %d\n", gain[0]);
strcpy(name, "bbgain");
gain[1] = mode(&(bbgain[0]), k, name);
printf("snoop:report_gain: bbgain mode = %d\n", gain[1]);
strcpy(name, "blna");
gain[2] = mode(&(blna[0]), k, name);
printf("snoop:report_gain: blna mode = %d\n", gain[2]);
strcpy(name, "xatten1");
gain[3] = mode(&(xatten1[0]), k, name);
printf("snoop:report_gain: xatten1 mode = %d\n", gain[3]);
strcpy(name, "xatten2");
gain[4] = mode(&(xatten2[0]), k, name);
printf("snoop:report_gain: xatten2 mode = %d\n", gain[4]);
free(rfgain); free(bbgain); free(blna); free(xatten1); free(xatten2);
}
// Routine to report the status information after descriptor consumption
double report_status (A_UINT32 rx_desc_ptr, A_UINT32 desc_cnt) {
A_UINT32 j = 0;
A_UINT32 k = 0;
A_UINT32 *retval;
A_UINT32 return_val;
A_UINT32 datalen = 0;
A_UINT32 tmp_ptr = 0;
A_UINT32 desc5 = 0;
A_UINT32 done = 0;
A_UINT32 frrxok = 0;
A_UINT32 crcerr = 0;
A_UINT32 fifooverrun = 0;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -