📄 mcont.c
字号:
*
*/
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;
A_UINT32 timeout = 1000;
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) );
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));
// Setup descriptor template - only the desc addresses change per descriptor
// write buffer ptr to descriptor
localDesc.bufferPhysPtr = pLibDev->tx[queueIndex].pktAddress;
ar5kInitData[pLibDev->ar5kInitIndex].pMacAPI->setDescriptor( devNum, &localDesc, pktSize,
antenna, 0, rateValues[dataRate], 1 );
descAddress = pLibDev->tx[queueIndex].descAddress;
for (i = 0; i < numDesc; i++) {
//write link pointer
if (i == numDesc - 1) { //ie its the last descriptor
localDesc.nextPhysPtr = 0;
}
else {
localDesc.nextPhysPtr = descAddress + sizeof(MDK_ATHEROS_DESC);
}
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
ar5kInitData[pLibDev->ar5kInitIndex].pMacAPI->txBeginConfig(devNum, 0);
if(pLibDev->mode == MODE_11B) {
timeout = 5000;
}
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);
}
//cleanup the descriptors used
memFree(devNum, pLibDev->tx[queueIndex].pktAddress);
pLibDev->tx[queueIndex].pktAddress = 0;
memFree(devNum, pLibDev->tx[queueIndex].descAddress);
pLibDev->tx[queueIndex].descAddress = 0;
return TRUE;
}
/**************************************************************************
* lclSineWave- Create a Sine Wave Data packet filling 4k bytes
*
*/
void lclSineWave
(
A_UINT32 amplitude,
A_UINT32 frequency,
A_UCHAR sine1[SINE_BUFFER_SIZE],
A_UCHAR sine2[SINE_BUFFER_SIZE],
A_UINT32 turbo
)
{
A_UINT32 i, j, samples;
double step, radian1, radian2, amp, freq, samp;
A_INT32 idata1, qdata1, idata2, qdata2;
amp = amplitude / 100.0;
freq = frequency / 1000.0;
samples = SINE_BUFFER_SIZE;
samp = samples;
if (turbo) {
step = (2 * PI * freq * 25) / samp;
}
else {
step = (2 * PI * freq * 50) / samp;
}
for (i=0, j = (samples/2); i < (samples/2); i++, j++) {
radian1 = i * step;
radian2 = j * step;
idata1 = (A_INT32)((sin(radian1)) * 255 * amp);
qdata1 = (A_INT32)((cos(radian1)) * 255 * amp);
sine1[(2*i)+1] = (A_UCHAR)(((idata1 + 256)>>1) & 0xff);
sine1[(2*i)] = (A_UCHAR)(((qdata1 + 256)>>1) & 0xff);
idata2 = (A_INT32)((sin(radian2)) * 255 * amp);
qdata2 = (A_INT32)((cos(radian2)) * 255 * amp);
sine2[(2*i)+1] = (A_UCHAR)(((idata2 + 256)>>1) & 0xff);
sine2[(2*i)] = (A_UCHAR)(((qdata2 + 256)>>1) & 0xff);
}
}
#define F2_D0_LCL_IFS 0x1040 // MAC DCU-specific IFS settings
#define F2_D_LCL_IFS_CWMIN_M 0x000003FF // Mask for CW_MIN
#define F2_D_LCL_IFS_CWMAX_M 0x000FFC00 // Mask for CW_MAX
#define F2_D_LCL_IFS_CWMAX_S 10 // Shift for CW_MAX
#define F2_D_LCL_IFS_AIFS_M 0x0FF00000 // Mask for AIFS
#define F2_D_LCL_IFS_AIFS_S 20 // Shift for AIFS
/**************************************************************************
* txContFrameBegin - Place device in continuous Burst Frame transmit mode
*
*/
MANLIB_API void txContFrameBegin
(
A_UINT32 devNum,
A_UINT32 length, // in bytes
A_UINT32 ifswait, // in units of slots
A_UINT32 typeOption1, // dataPattern
A_UINT32 typeOption2, // dataRate: 6, 9, 12, ...
A_UINT32 antenna, // ...
A_BOOL performStabilizePower, // flag whether to send 1st 20 pkts: 0=>no, 1=>yes
A_UINT32 numDescriptors, // number of descriptors. 0=>forever.
A_UCHAR *dest //destination to send end packet to if in finite mode
)
{
LIB_DEV_INFO *pLibDev;
A_UCHAR sineBuffer1[SINE_BUFFER_SIZE];
A_UINT32 descAddress, lastDescAddress, pktSize, dataPatLength, i;
A_UCHAR *pData, dataRate;
MDK_ATHEROS_DESC localDesc;
MDK_ATHEROS_DESC localDescRx;
A_UINT16 queueIndex;
A_BOOL infiniteDescMode = FALSE;
A_BOOL retries = FALSE;
A_UINT32 txComplete = 0;
A_UINT32 timeoutComputed; // in ms
if (checkDevNum(devNum) == FALSE) {
mError(devNum, EINVAL, "Device Number %d:txContFrameBegin\n", devNum);
return;
}
if (gLibInfo.pLibDevArray[devNum]->devState < RESET_STATE) {
mError(devNum, EILSEQ, "Device Number %d:txContFrameBegin: 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;
if(typeOption1 > RANDOM_PATTERN) {
mError(devNum, EINVAL,
"Device Number %d:txContFrameBegin: 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:txContFrameBegin: DATA rate does not match a known rate: %d\n", devNum,
typeOption2);
return;
}
pLibDev->tx[queueIndex].contType = CONT_FRAMED_DATA;
//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;
}
//setup the antenna
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 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;
}
// 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;
}
localDescRx.bufferPhysPtr = pLibDev->rx.bufferAddress;
localDescRx.nextPhysPtr = pLibDev->rx.descAddress;
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
ar5kInitData[pLibDev->ar5kInitIndex].pMacAPI->writeRxDescriptor(devNum, pLibDev->rx.descAddress);
//stabilize the power before going into continuous mode
if(performStabilizePower > 0) {
if(!stabilizePower(devNum, dataRate,antenna, CONT_FRAMED_DATA)) {
return;
}
}
//setup the descriptors for transmission
if(numDescriptors == 0) {
//this means infinite mode
infiniteDescMode = 1;
numDescriptors = 1;
retries = TRUE;
}
pLibDev->devState = CONT_ACTIVE_STATE;
pLibDev->rx.rxEnable = 0;
pLibDev->tx[queueIndex].descAddress = memAlloc( devNum, numDescriptors * sizeof(MDK_ATHEROS_DESC) );
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
createTransmitPacket(devNum, MDK_NORMAL_PKT, NULL, numDescriptors, length, pData,
dataPatLength, 1, queueIndex, &(pktSize), &(pLibDev->tx[queueIndex].pktAddress));
// Setup descriptor template - only the desc addresses change per descriptor
// write buffer ptr to descriptor
localDesc.bufferPhysPtr = pLibDev->tx[queueIndex].pktAddress;
ar5kInitData[pLibDev->ar5kInitIndex].pMacAPI->setContDescriptor( devNum, &localDesc, pktSize,
antenna, dataRate );
descAddress = pLibDev->tx[queueIndex].descAddress;
for (i = 0; i < numDescriptors; i++) {
//write link pointer
if (i == (numDescriptors - 1)) { //ie its the last descriptor
if(infiniteDescMode) {
localDesc.nextPhysPtr = pLibDev->tx[queueIndex].descAddress;
}
else {
localDesc.nextPhysPtr = 0;
lastDescAddress = descAddress;
}
}
else {
localDesc.nextPhysPtr = descAddress + sizeof(MDK_ATHEROS_DESC);
}
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
ar5kInitData[pLibDev->ar5kInitIndex].pMacAPI->txBeginContFramedData(devNum, queueIndex, ifswait, retries);
if (!infiniteDescMode)
{
if (pLibDev->mode == MODE_11B)
{
timeoutComputed = 10 + numDescriptors*((A_UINT32)((30+length)*8*10.0/typeOption2) + 6 + 9*ifswait + 20)/1000;
} else
{
timeoutComputed = 10 + numDescriptors*((30+length)*8/typeOption2 + 6 + 9*ifswait + 20)/1000;
}
for(i = 0; i < timeoutComputed*50000; i++)
{
txComplete = ar5kInitData[pLibDev->ar5kInitIndex].pMacAPI->isTxComplete(devNum);
if(txComplete) {
ar5kInitData[pLibDev->ar5kInitIndex].pMacAPI->rxCleanupConfig(devNum);
break;
}
}
pLibDev->devState = RESET_STATE;
if(i == timeoutComputed) {
mError(devNum, EIO, "Device Number %d:stabilize power packet transmit took longer than %d seconds\n", devNum,
timeoutComputed/1000);
return;
}
//come out of AGC deaf mode
ar5kInitData[pLibDev->ar5kInitIndex].pMacAPI->AGCUnDeaf(devNum);
//send the end packet
createEndPacket(devNum, queueIndex, dest, antenna);
sendEndPacket(devNum, queueIndex);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -