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

📄 mcont.c

📁 Atheros AP Test with Agilent N4010A source code
💻 C
📖 第 1 页 / 共 3 页
字号:
/* mCont.c - contians continuous transmit functions */
/* Copyright (c) 2001 Atheros Communications, Inc., All Rights Reserved */

#ident  "ACI $Id: //depot/sw/branches/ART_V53_dragon/sw/src/dk/mdk/devlib/mCont.c#3 $, $Header: //depot/sw/branches/ART_V53_dragon/sw/src/dk/mdk/devlib/mCont.c#3 $"

/* 
Revsision history
--------------------
1.0       Created.
*/
// #include "vxdrv.h"

#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 "ar5210reg.h"
#include "athreg.h"
#include "manlib.h"
#include "mdata.h"
#include "mEeprom.h"
#include "mConfig.h"
#include "mDevtbl.h"
#include "mIds.h"
#include <assert.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <errno.h>
#include <stdio.h>

#if defined(COBRA_AP) && defined(PCI_INTERFACE)
#include "ar531xPlusreg.h"
#endif

#define SINE_BUFFER_SIZE 2000
#ifndef PI	
#define PI 3.14159265358979323846
#endif

void lclSineWave(A_UINT32 frequency, A_UINT32 amplitude, 
                 A_UCHAR  sine1[2000], A_UCHAR  sine2[2000], A_UINT32 turbo);
static A_UCHAR PN7Data[] = {0xfe, 0xa9, 0x9d, 0xd2, 0xc6, 0xf6, 0xb6, 0x48, 
                            0xe1, 0x7c, 0xae, 0x68, 0x9e, 0x28, 0x60, 0x80};
static A_UCHAR PN9Data[] = {0xff, 0x87, 0xb8, 0x59, 0xb7, 0xa1, 0xcc, 0x24, 
                            0x57, 0x5e, 0x4b, 0x9c, 0x0e, 0xe9, 0xea, 0x50, 
                            0x2a, 0xbe, 0xb4, 0x1b, 0xb6, 0xb0, 0x5d, 0xf1, 
                            0xe6, 0x9a, 0xe3, 0x45, 0xfd, 0x2c, 0x53, 0x18, 
                            0x0c, 0xca, 0xc9, 0xfb, 0x49, 0x37, 0xe5, 0xa8, 
                            0x51, 0x3b, 0x2f, 0x61, 0xaa, 0x72, 0x18, 0x84, 
                            0x02, 0x23, 0x23, 0xab, 0x63, 0x89, 0x51, 0xb3, 
                            0xe7, 0x8b, 0x72, 0x90, 0x4c, 0xe8, 0xfb, 0xc0};

static A_BOOL stabilizePower(A_UINT32 devNum, A_UCHAR  dataRate, A_UINT32 antenna, 
							 A_UINT32 type);

/**************************************************************************
* txContBegin - Place device in continuous transmit mode
*
*/
MANLIB_API void txContBegin
( 
 A_UINT32 devNum,  
 A_UINT32 type, 
 A_UINT32 typeOption1,
 A_UINT32 typeOption2, 
 A_UINT32 antenna
)
{
   	LIB_DEV_INFO *pLibDev;
    A_UCHAR      sineBuffer1[SINE_BUFFER_SIZE], sineBuffer2[SINE_BUFFER_SIZE];
    A_UINT32	 i, pktSize=0, dataPatLength;
    A_UCHAR      *pData, dataRate;
    MDK_ATHEROS_DESC localDesc;
    MDK_ATHEROS_DESC localDescRx;
	A_UINT16	queueIndex;
	A_UINT32    value;
	A_UINT32    xpaaHigh = 0;
	A_UINT32    xpabHigh = 0;
	A_UINT32    max_constant_i, max_constant_q;

	if (checkDevNum(devNum) == FALSE) {
		mError(devNum, EINVAL, "Device Number %d:txContBegin\n", devNum);
		return;
	}
	if (gLibInfo.pLibDevArray[devNum]->devState < RESET_STATE) {
		mError(devNum, EILSEQ, "Device Number %d:txContBegin: Device should be out of Reset before continuous transmit\n", devNum);
		return;
	}
    pLibDev = gLibInfo.pLibDevArray[devNum];

	pLibDev->selQueueIndex = 0;
	pLibDev->tx[0].dcuIndex = 0;

	queueIndex = pLibDev->selQueueIndex;

    dataRate = 0;

	switch(type) {
	case CONT_SINE:
        mError(devNum, EINVAL, "Device Number %d:txContBegin: The SINE function is being retooled to provide more accurate\n \
            data and is not available in this version of the library.\n", devNum);
        return;
#if 0  //quiet compiler warnings
		if((typeOption1 < 1) || (typeOption1 > 100)) {
			mError(EINVAL, 
                "txContBegin: SINE amplitude must be between 1 and 100 inclusively - not: %d\n", 
                typeOption1);
			return;
		}
		if((typeOption2 < 1000) || (typeOption2 > 10000)) {
			mError(EINVAL, 
                "txContBegin: SINE frequency must be between 1000 kHz and 10,000 kHz - not: %d\n", 
				typeOption2);
			return;
		}
		break;
#endif
	case CONT_DATA:
    case CONT_FRAMED_DATA:
		if(typeOption1 > RANDOM_PATTERN) {
			mError(devNum, EINVAL, 
                "Device Number %d:txContBegin: DATA pattern does not match a known value: %d\n", devNum, 
				typeOption1);
			return;
		}
		//decode the rate code
		for(dataRate = 0; dataRate < numRateCodes; dataRate++) {
			if(typeOption2 == rateCodes[dataRate]) {
				break;  //dataRate should be set to the correct index
			}
		}
		if(dataRate == numRateCodes) {
            mError(devNum, EINVAL, "Device Number %d:txContBegin: DATA rate does not match a known rate: %d\n", devNum, 
                typeOption2);
            return;
        }
        break;
	case CONT_SINGLE_CARRIER:
		//change xpa value
		xpaaHigh = getFieldForMode(devNum, "bb_xpaa_active_high", pLibDev->mode, pLibDev->turbo);
		xpabHigh = getFieldForMode(devNum, "bb_xpab_active_high", pLibDev->mode, pLibDev->turbo);
		if(pLibDev->mode == MODE_11A) {
			writeField(devNum, "bb_xpaa_active_high", !xpaaHigh);
		} 
		else {
			writeField(devNum, "bb_xpab_active_high", !xpabHigh);
		}

//		resetDevice(devNum, pLibDev->macAddr.octets, pLibDev->bssAddr.octets, pLibDev->freqForResetDevice, pLibDev->turbo);
        if (isDragon(devNum)) {
           max_constant_i = max_constant_q = DAC_11BIT_MAX_VALUE;
        }
        else {
           max_constant_i = max_constant_q = DAC_9BIT_MAX_VALUE;
        }

		if(typeOption1 > max_constant_i) {
			mError(devNum, EINVAL, "Device Number %d:txContBegin: SINGLE_CARRIER constant I value greater than 511: %d\n", devNum, typeOption1);
			return;
		}
		if(typeOption2 > max_constant_q) {
			mError(devNum, EINVAL, "Device Number %d:txContBegin: SINGLE_CARRIER constant Q value greater than 511: %d\n", devNum, typeOption2);
			return;
		}
		break;
	default:
		mError(devNum, EINVAL, "Device Number %d:txContBegin: type must be set to a valid pattern type\n", devNum);
		return;
	}
    pLibDev->tx[queueIndex].contType = type;

	//cleanup any stuff from previous transmit
	if (pLibDev->tx[queueIndex].pktAddress || pLibDev->tx[queueIndex].descAddress) {
		memFree(devNum, pLibDev->tx[queueIndex].pktAddress);
		pLibDev->tx[queueIndex].pktAddress = 0;
		memFree(devNum, pLibDev->tx[queueIndex].descAddress);
		pLibDev->tx[queueIndex].descAddress = 0;
   		pLibDev->tx[queueIndex].txEnable = 0;
	}
	//update antenna
	//IF using Single carrier, then need to switch the antenna to the opposite
	//to what is expected.  This is because the baseband is in "receive" mode in the
	//case of single carrier, and so uses the opposite antenna to what is set for
	//transmit mode
	if(type == CONT_SINGLE_CARRIER) {
		antenna = 
			(antenna==(USE_DESC_ANT|DESC_ANT_A)) ? (USE_DESC_ANT|DESC_ANT_B) : (USE_DESC_ANT|DESC_ANT_A);
	}
	if (!ar5kInitData[pLibDev->ar5kInitIndex].pMacAPI->setupAntenna(devNum, antenna, &antenna))
	{
		return;
	}

   	// send a few packets first to step-up the transmit power
    // Setup the data packet
    pData = sineBuffer1;
    switch (typeOption1 ) {
    case ONES_PATTERN:
        *((A_UINT32 *)pData) = 0xFFFFFFFF;
        dataPatLength = 4;
        break;
    case REPEATING_5A:
        *((A_UINT32 *)pData) = 0x5A5A5A5A;
        dataPatLength = 4;
        break;
    case COUNTING_PATTERN:
        for(i = 0; i < 256; i++) {
            pData[i] = (A_UCHAR)i;
        }
        dataPatLength = 256;
        break;
    case PN7_PATTERN:
        pData = PN7Data;
        dataPatLength = sizeof(PN7Data);
        break;
    case PN9_PATTERN:
        pData = PN9Data;
        dataPatLength = sizeof(PN9Data);
        break;
    case REPEATING_10:
        *((A_UINT32 *)pData) = 0xAAAAAAAA;
        dataPatLength = 4;
		break;
    case RANDOM_PATTERN:
        srand( (unsigned)time( NULL ) );
        for(i = 0; i < 256; i++) {
            pData[i] = (A_UCHAR)(rand() & 0xFF);
        }
        dataPatLength = 256;
        break;
    default:  // Use Zeroes Pattern
        *((A_UINT32 *)pData) = 0;
        dataPatLength = 4;
        break;
    }

//	if((type != CONT_SINGLE_CARRIER)&&(type != CONT_SINE)) {
	if(type != CONT_SINE) {
		// Add a local self-linked rx descriptor and buffer to stop receive overrun
		// cleanup descriptors created by the last begin
		if (pLibDev->rx.rxEnable || pLibDev->rx.bufferAddress) {
			memFree(devNum, pLibDev->rx.bufferAddress);
			pLibDev->rx.bufferAddress = 0;
			memFree(devNum, pLibDev->rx.descAddress);
			pLibDev->rx.descAddress = 0;
			pLibDev->rx.rxEnable = 0;
			pLibDev->rx.numDesc = 0;
			pLibDev->rx.bufferSize = 0;
		}

		pLibDev->rx.descAddress = memAlloc( devNum, sizeof(MDK_ATHEROS_DESC));
		if (0 == pLibDev->rx.descAddress) {
			mError(devNum, ENOMEM, "Device Number %d:txContBegin: unable to allocate memory for rx-descriptor to prevent overrun\n", devNum);
			return;
		}
		pLibDev->rx.bufferAddress = memAlloc(devNum, 512);
		if (0 == pLibDev->rx.bufferAddress) {
			mError(devNum, ENOMEM, "Device Number %d:txContBegin: unable to allocate memory for rx-buffer to prevent overrun\n", devNum);
			return;
		}

#if defined(COBRA_AP) && defined(PCI_INTERFACE)
	    if(isCobra(pLibDev->swDevID)) {
			localDescRx.bufferPhysPtr = pLibDev->rx.bufferAddress;
		    localDescRx.nextPhysPtr = pLibDev->rx.descAddress;
		}
	    else {
		    localDescRx.bufferPhysPtr = pLibDev->rx.bufferAddress | HOST_PCI_SDRAM_BASEADDR;
		    localDescRx.nextPhysPtr = pLibDev->rx.descAddress | HOST_PCI_SDRAM_BASEADDR;
		}
#else
		localDescRx.bufferPhysPtr = pLibDev->rx.bufferAddress;
		localDescRx.nextPhysPtr = pLibDev->rx.descAddress;
#endif
		localDescRx.hwControl[1] = pLibDev->rx.bufferSize;
		localDescRx.hwControl[0] = 0;
		writeDescriptor(devNum, pLibDev->rx.descAddress, &localDescRx);

		//go into AGC deaf mode
		ar5kInitData[pLibDev->ar5kInitIndex].pMacAPI->AGCDeaf(devNum);

		//write RXDP
#if defined(COBRA_AP) && defined(PCI_INTERFACE)
	    if(isCobra(pLibDev->swDevID)) {
			ar5kInitData[pLibDev->ar5kInitIndex].pMacAPI->writeRxDescriptor(devNum, pLibDev->rx.descAddress);
		}
		else {
			ar5kInitData[pLibDev->ar5kInitIndex].pMacAPI->writeRxDescriptor(devNum, pLibDev->rx.descAddress | HOST_PCI_SDRAM_BASEADDR);
		}
#else
		ar5kInitData[pLibDev->ar5kInitIndex].pMacAPI->writeRxDescriptor(devNum, pLibDev->rx.descAddress);
#endif

//printf("SNOOP:dataRate=%x:antenna=%x:type=%d\n", dataRate, antenna, type);
		//stabilize the power before going into continuous mode
		if(!stabilizePower(devNum, dataRate,antenna, type)) {
			return;
		}

		//allocate memory for cont packet and descriptor
		pLibDev->tx[queueIndex].descAddress = memAlloc( devNum, sizeof(MDK_ATHEROS_DESC) );
//printf("SNOOP:txContBegin:tx%d:descAddr=%x\n", queueIndex, pLibDev->tx[queueIndex].descAddress);
	//memDisplay(devNum, pLibDev->tx[queueIndex].descAddress, 8);
		if (0 == pLibDev->tx[queueIndex].descAddress) {
			mError(devNum, ENOMEM, "Device Number %d:stabilize: unable to allocate memory for descriptors\n", devNum);
			return;
		}

 		//setup the transmit packet
		if(type == CONT_DATA) {
			//set this flag so that the packet will be created without the header
			pLibDev->specialTx100Pkt = 1;
		}

		createTransmitPacket(devNum, MDK_NORMAL_PKT, NULL, 1, 2300, pData, 
			dataPatLength, 1, queueIndex, &(pktSize), &(pLibDev->tx[queueIndex].pktAddress));

		// Setup descriptor template - only the desc addresses change per descriptor
		// write buffer ptr to descriptor
#if defined(COBRA_AP) && defined(PCI_INTERFACE)
	    if(isCobra(pLibDev->swDevID)) {
			localDesc.bufferPhysPtr = pLibDev->tx[queueIndex].pktAddress;
		}
		else {
			localDesc.bufferPhysPtr = pLibDev->tx[queueIndex].pktAddress | HOST_PCI_SDRAM_BASEADDR;
		}
#else
		localDesc.bufferPhysPtr = pLibDev->tx[queueIndex].pktAddress;
#endif

		ar5kInitData[pLibDev->ar5kInitIndex].pMacAPI->setContDescriptor( devNum, &localDesc, pktSize, 
							antenna, dataRate );
		
		//set the next pointer to point to itself
#if defined(COBRA_AP) && defined(PCI_INTERFACE)
	    if(isCobra(pLibDev->swDevID)) {
			localDesc.nextPhysPtr = pLibDev->tx[queueIndex].descAddress;
		}
		else {
			localDesc.nextPhysPtr = pLibDev->tx[queueIndex].descAddress | HOST_PCI_SDRAM_BASEADDR;
		}
#else
		localDesc.nextPhysPtr = pLibDev->tx[queueIndex].descAddress;
#endif
		
		//descriptor will be written later
	}

⌨️ 快捷键说明

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