📄 mcont.c
字号:
pLibDev->devState = CONT_ACTIVE_STATE;
pLibDev->rx.rxEnable = 0;
// The rest of the code is broken into three sections for the three different data transmit types.
switch(type) {
case CONT_SINE:
// memFree(devNum, pLibDev->tx[queueIndex].descAddress);
// memFree(devNum, pLibDev->tx[queueIndex].pktAddress);
pLibDev->tx[queueIndex].descAddress = memAlloc(devNum, sizeof(MDK_ATHEROS_DESC));
if (0 == pLibDev->tx[queueIndex].descAddress) {
mError(devNum, ENOMEM, "Device Number %d:txContBegin: unable to allocate memory for descriptors\n", devNum);
return;
}
//allocate enough memory for the packet and write it down
pLibDev->tx[queueIndex].pktAddress = memAlloc(devNum, SINE_BUFFER_SIZE * 2);
if (0 == pLibDev->tx[queueIndex].pktAddress) {
mError(devNum, ENOMEM, "Device Number %d:txContBegin: unable to allocate memory for SINE packet\n", devNum);
return;
}
pktSize = SINE_BUFFER_SIZE * 2;
lclSineWave(typeOption1, typeOption2, sineBuffer1, sineBuffer2, pLibDev->turbo);
pLibDev->devMap.OSmemWrite(devNum, pLibDev->tx[queueIndex].pktAddress,
sineBuffer1, SINE_BUFFER_SIZE);
pLibDev->devMap.OSmemWrite(devNum, pLibDev->tx[queueIndex].pktAddress + SINE_BUFFER_SIZE,
sineBuffer2, SINE_BUFFER_SIZE);
// Setup the SINE descriptor
localDesc.nextPhysPtr = 0;
// write buffer ptr to descriptor
localDesc.bufferPhysPtr = pLibDev->tx[queueIndex].pktAddress;
//create and write the 2 control words
localDesc.hwControl[0] = ( (rateValues[0] << BITS_TO_TX_XMIT_RATE) |
(0x18 << BITS_TO_TX_HDR_LEN) |
(antenna << BITS_TO_TX_ANT_MODE) |
(pktSize + FCS_FIELD) );
localDesc.hwControl[1] = pktSize;
writeDescriptor(devNum, pLibDev->tx[queueIndex].descAddress, &localDesc);
// Disable AGC to A2 traffic
REGW(devNum, 0x9808, REGR(devNum, 0x9808) | 0x08000000);
mSleep(1);
// Turn on Tx
REGW(devNum, PHY_BASE+(50<<2),0x00060406);
mSleep(1);
// Set PA on
REGW(devNum, PHY_BASE+(50<<2),0x00060606);
mSleep(1);
// Re-enable AGC to A2 traffic
REGW(devNum, 0x9808, REGR(devNum, 0x9808) & (~0x08000000));
// Program the num of lines to loop on
REGW(devNum, 0x8074, (1 << 14) | (((pktSize/2)-1) << 3) | 0x3);
mSleep(1);
// Turn on DAC
REGW(devNum, PHY_BASE+(11<<2), 0x0ffc0ffc);
mSleep(1);
// Enable PCU tstDAC
REGW(devNum, (PHY_BASE+(2<<2)),(REGR(devNum, PHY_BASE+(2<<2)) | 0x80) & ~0x3);
mSleep(1);
// Start the hardware
REGW(devNum, F2_TXDP0, pLibDev->tx[queueIndex].descAddress);
mSleep(1);
REGW(devNum, F2_TXCFG, REGR(devNum, F2_TXCFG) | F2_TXCFG_CONT_EN);
REGW(devNum, F2_CR, F2_CR_TXE0);
// Wait for loop to load
mSleep(2);
// Enable looping
REGW(devNum, 0x8074, REGR(devNum, 0x8074) | 0x4);
mSleep(1);
break;
case CONT_SINGLE_CARRIER:
// --------- set constant values -----------
if (isDragon(devNum)) {
REGW(devNum, PHY_BASE+(15<<2), (typeOption2 << 11) | typeOption1);
// --------- Force TSTDAC with value in Reg 15 -----
REGW(devNum, PHY_BASE+(2<<2),
(REGR(devNum, PHY_BASE+(2<<2)) & 0xffffff7d) | (0x1 << 7) | (0x1 << 1)| 0x1);
// --------- Manually Turn on the DAC -----------
REGW(devNum, PHY_BASE+(11<<2), 0x80038ffc); // Turn on the DAC
if(pLibDev->mode == MODE_11A) {
writeField(devNum, "rf_xpa5bias_en", 0x0);
writeField(devNum, "rf_xpa5bias_mode", 0x1);
}
else {
writeField(devNum, "rf_xpa2bias_en", 0x0);
writeField(devNum, "rf_xpa2bias_mode", 0x1);
}
}
else {
REGW(devNum, PHY_BASE+(15<<2), (typeOption2 << 9) | typeOption1);
// --------- Force TSTDAC with value in Reg 15 -----
REGW(devNum, PHY_BASE+(2<<2),
(REGR(devNum, PHY_BASE+(2<<2)) & 0xffffff7d) | (0x1 << 7) | (0x1 << 1));
// --------- Manually Turn on the DAC -----------
REGW(devNum, PHY_BASE+(11<<2), 0x80038ffc); // Turn on the DAC
}
// --------- turn on rf -----------
if((pLibDev->swDevID & 0x00ff) <= 0x0013) {
REGW(devNum, PHY_BASE+(0x36<<2), 0x0604066);
mSleep(10);
REGW(devNum, PHY_BASE+(0x36<<2), 0x0606066);
}
else if ((pLibDev->swDevID & 0x00ff) >= 0x0014){
value = 0x10a098c2;
if(pLibDev->mode != MODE_11A) {
value |= 0x400000;
}
REGW(devNum, PHY_BASE+(0x37<<2), value);
mSleep(10);
value |= 0x4000;
REGW(devNum, PHY_BASE+(0x37<<2), value);
}
//printf("SNOOP: dumping pci writes:\n");
//displayPciRegWrites(devNum);
//getch();
//revert back to existing xpa value.
changeField(devNum, "bb_xpaa_active_high", xpaaHigh);
changeField(devNum, "bb_xpab_active_high", xpabHigh);
break;
case CONT_DATA:
//reset data create flag
pLibDev->specialTx100Pkt = 0;
// Resetup the first transmit descriptor with the More flag set.
localDesc.hwControl[1] = (pktSize & 0xfff) | DESC_MORE;
writeDescriptor(devNum, pLibDev->tx[queueIndex].descAddress, &localDesc);
// start hardware
ar5kInitData[pLibDev->ar5kInitIndex].pMacAPI->txBeginContData(devNum, queueIndex);
break;
case CONT_FRAMED_DATA:
writeDescriptor(devNum, pLibDev->tx[queueIndex].descAddress, &localDesc);
ar5kInitData[pLibDev->ar5kInitIndex].pMacAPI->txBeginContFramedData(devNum, queueIndex, 0, 1);
break;
}
}
/**************************************************************************
* txContEnd - Remove device from continuous transmit mode
*
*/
MANLIB_API void txContEnd
(
A_UINT32 devNum
)
{
LIB_DEV_INFO *pLibDev;
A_UINT16 queueIndex = 0;
if (checkDevNum(devNum) == FALSE) {
mError(devNum, EINVAL, "Device Number %d:txContEnd\n", devNum);
return;
}
if (gLibInfo.pLibDevArray[devNum]->devState != CONT_ACTIVE_STATE) {
mError(devNum, EILSEQ, "Device Number %d:txContEnd: This device is not running continuous transmit - bad function sequence\n", devNum);
return;
}
pLibDev = gLibInfo.pLibDevArray[devNum];
queueIndex = pLibDev->selQueueIndex;
if (pLibDev->tx[queueIndex].contType != CONT_FRAMED_DATA) {
mError(devNum, EINVAL, "Device Number %d:txContEnd: this function does not support stopping continuous transmit except for CONT_FRAMED_DATA (tx99)\n", devNum);
return;
}
//stop the transmit at mac level
ar5kInitData[pLibDev->ar5kInitIndex].pMacAPI->txEndContFramedData(devNum, queueIndex);
//cleanup descriptor/buffer usage
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;
}
pLibDev->devState = RESET_STATE;
}
/**************************************************************************
* stabilizePower - send out a few packets to get power up
*
*/
A_BOOL stabilizePower
(
A_UINT32 devNum,
A_UCHAR dataRate,
A_UINT32 antenna,
A_UINT32 type
)
{
LIB_DEV_INFO *pLibDev;
A_UINT32 numDesc;
A_UINT32 pktSize;
A_UINT16 queueIndex = 0;
A_UINT32 descAddress;
MDK_ATHEROS_DESC localDesc;
A_UINT32 i; //ch;
A_UINT32 timeout = 4000;
A_UINT32 txComplete;
pLibDev = gLibInfo.pLibDevArray[devNum];
if (pLibDev->mode == MODE_11B)
{
numDesc = 10;
} else
{
numDesc = 20;
}
pLibDev->tx[queueIndex].descAddress = memAlloc( devNum, numDesc * sizeof(MDK_ATHEROS_DESC) );
//printf("SNOOP::stabilizePower::Allocate %x descs at %x\n", numDesc, pLibDev->tx[queueIndex].descAddress);
//memDisplay(devNum, pLibDev->tx[queueIndex].descAddress, 16);
if (0 == pLibDev->tx[queueIndex].descAddress) {
mError(devNum, ENOMEM, "Device Number %d:stabilize: unable to allocate memory for descriptors\n", devNum);
return FALSE;
}
//setup the transmit packet
createTransmitPacket(devNum, MDK_NORMAL_PKT, NULL, numDesc, 0, 0,
1, 1, queueIndex, &(pktSize), &(pLibDev->tx[queueIndex].pktAddress));
//printf("SNOOP::stabilizePower::numDesc=%d:pktSize=%d\n", numDesc, pktSize);
// 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
if (isFalcon(devNum) || isDragon(devNum)) {
localDesc.bufferPhysPtr = FALCON_MEM_ADDR_MASK | (pLibDev->tx[queueIndex].pktAddress);
} else {
localDesc.bufferPhysPtr = pLibDev->tx[queueIndex].pktAddress;
}
#endif
ar5kInitData[pLibDev->ar5kInitIndex].pMacAPI->setDescriptor( devNum, &localDesc, pktSize,
antenna, 0, rateValues[dataRate], 1 );
descAddress = pLibDev->tx[queueIndex].descAddress;
// put this check outside the for loop for speed
if (isFalcon(devNum) || isDragon(devNum)) {
for (i = 0; i < numDesc; i++) {
//write link pointer
if (i == numDesc - 1) { //ie its the last descriptor
localDesc.nextPhysPtr = 0;
}
else {
localDesc.nextPhysPtr = FALCON_MEM_ADDR_MASK | (descAddress + sizeof(MDK_ATHEROS_DESC));
}
writeDescriptor(devNum, descAddress, &localDesc);
//increment descriptor address
descAddress += sizeof(MDK_ATHEROS_DESC);
}
} else {
for (i = 0; i < numDesc; i++) {
//write link pointer
if (i == numDesc - 1) { //ie its the last descriptor
localDesc.nextPhysPtr = 0;
}
else {
#if defined(COBRA_AP) && defined(PCI_INTERFACE)
if(isCobra(pLibDev->swDevID)) {
localDesc.nextPhysPtr = (descAddress + sizeof(MDK_ATHEROS_DESC));
}
else {
localDesc.nextPhysPtr = (descAddress + sizeof(MDK_ATHEROS_DESC)) | HOST_PCI_SDRAM_BASEADDR;
}
#else
localDesc.nextPhysPtr = (descAddress + sizeof(MDK_ATHEROS_DESC));
#endif
}
writeDescriptor(devNum, descAddress, &localDesc);
//increment descriptor address
descAddress += sizeof(MDK_ATHEROS_DESC);
}
}
//start the transmit
pLibDev->tx[queueIndex].txEnable = 1; //This is new. Funcs need to know what queue to activate
//start the transmit
REGW(devNum, 0x58, 0x8120);
//printf("SNOOP::Press any key to Create next packet\n"); ch = getchar();
ar5kInitData[pLibDev->ar5kInitIndex].pMacAPI->txBeginConfig(devNum, 0);
if(pLibDev->mode == MODE_11B) {
timeout = 9000;
}
//printf("SNOOP::stabilizePower::xmit enabled:TXDP in q0=%x\n", REGR(devNum, 0x800));
//memDisplay(devNum, REGR(devNum, 0x800), 16);
//printf("SNOOP::Press any key to read status\n"); ch = getchar();
for(i = 0; i < timeout; i++) {
txComplete = ar5kInitData[pLibDev->ar5kInitIndex].pMacAPI->isTxComplete(devNum);
if(txComplete) {
ar5kInitData[pLibDev->ar5kInitIndex].pMacAPI->rxCleanupConfig(devNum);
break;
}
mSleep(1);
}
if(i == timeout) {
mError(devNum, EIO, "Device Number %d:stabilize power packet transmit took longer than %d seconds\n", devNum,
timeout/1000);
return FALSE;
}
//###########################Need to experiment with this delay
if((type == CONT_DATA) && (pLibDev->mode == MODE_11B)) {
mSleep(10);
}
mSleep(10);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -