Esempio n. 1
0
void LinkRxDump(void *dr, int ndump, int np)
{
	char buffer[MBUFFER];
	int datalen;
	int it;

	if(ndump>MBUFFER)
	{
		ndump=MBUFFER;
	}
	RxDescriptorPrint(dr,buffer,MBUFFER);
	UserPrint("%s\n",buffer);
    //
	// fetch the data
	//
	datalen=RxDescriptorDataLen(dr);
	if(ndump>datalen)
	{
		ndump=datalen;
	}
    MyMemoryRead(LinkRxLoopBuffer[np], (unsigned int *)buffer, ndump);
	//
	// print
	//
	for(it=0; it<ndump; it++)
	{
		UserPrint("%02x ",buffer[it]);
	}
	UserPrint("\n");
}
Esempio n. 2
0
void LinkRxComplete(int timeout, 
	int ndump, unsigned char *dataPattern, int dataPatternLength, int (*done)())
{
    unsigned int startTime, endTime, ctime;
	int it;
	int notdone;
	int stop;
	int behind;
	int scount;
	unsigned int mDescriptor;			// address of descriptor in shared memory
#ifdef MEMORYREAD
	unsigned int descriptor[MDESCRIPTOR+30];	// private copy of current descriptor
#else
    unsigned int *descriptor;
#endif
	int pass;
    int dsize;
	int isdone;

	pass=0;
	dataPatternLength=0;
	dataPattern=0;
	scount=0;
    dsize=RxDescriptorSize();
    //
	// Loop timeout condition.
	// This number can be large since it is only used for
	// catastrophic failure of cart. The normal terminating
	// condition is a message from cart saying STOP.
	//
    startTime=TimeMillisecond();
	ctime=startTime;
//	if(timeout<=0)
//	{
//		timeout=60*60*1000;             // one hour
//	}
	endTime=startTime+timeout;		
	//
	// set pointer to first descriptor
	//
//    mDescriptor = LinkRxLoopFirst(0);
	//
	// keep track of how many times we look and the descriptor is not done
	// this is used to control the sleep interval
	//
	notdone=0;
	stop=0;
	behind=0;
	//
	// loop looking for descriptors with received packets.
	//
	for(it = 0; ; it++) 
	{
		mDescriptor=LinkRxLoopDescriptor[it%LinkRxLoopMany];
#ifdef MEMORYREAD
        //
		// read the next descriptor
		//
        MyMemoryRead(mDescriptor, descriptor, dsize);		
#else
        descriptor=(unsigned int *)MyMemoryPtr(mDescriptor);
#endif
        //
		// descriptor is ready, we have a new packet
		//
        if(RxDescriptorDone(descriptor)) 
		{
#ifdef MEMORYREAD
            //
		    // read the next descriptor
		    //
            MyMemoryRead(mDescriptor, descriptor, dsize);
#endif

		
			notdone=0;
			behind++;
			scount=0;
#ifdef FASTER
			if((it%100)==0)
			{
				UserPrint(" %d",it);
			}
#endif         
            //
			// dump packet contents
			//
            if(ndump>0) 
			{
				UserPrint("\n");
                LinkRxDump(descriptor, ndump, it%LinkRxLoopMany);
            }
			//
			// extract stats
			//
			LinkRxStatExtract(descriptor,it);
			//
			// reset the descriptor so that we can use it again
			//
			RxDescriptorReset(descriptor);
#ifdef MEMORYREAD
			//
			// copy it back to the shared memory
			//
			MyMemoryWrite(mDescriptor,descriptor,dsize);
#endif
			//
			// need to queue the descriptor with the hardware
			//
            if(LinkRxDescriptorFifo)
            {
	            DeviceReceiveDescriptorPointer(mDescriptor);
            }
        } 
		//
		// descriptor not ready
		//
		else 
		{
			if(stop)
			{
				scount++;
				if(scount>200)
				{
				    break;
				}
			}
			it--;
			//
			// sleep every other time, need to keep up with fast rates
			//
			if(notdone>100)
			{
			    UserPrint(".");
//			    MyDelay(1);
				notdone=0;
			}
			else
			{
				notdone=1;      // this makes sure we never sleep
			}
        }
		//
		// check for message from cart telling us to stop
		// this is the normal terminating condition
		//
		pass++;
		if(pass>100)
		{
			if(done!=0)
			{
				isdone=(*done)();
				if(isdone!=0)
				{
					UserPrint(" %d Stop",it);
					if(stop==0)
					{
						stop=1;
						scount=0;
						behind=0;
					}
					//
					// immediate stop
					//
					if(isdone==2)
					{
						break;
					}
	//				break;
				}
			}
			pass=0;
		    //
		    // check for timeout
		    // rare terminating condition when cart crashes or disconnects
		    //
		    ctime=TimeMillisecond();
		    if(timeout>0 && ((endTime>startTime && (ctime>endTime || ctime<startTime)) || (endTime<startTime && ctime>endTime && ctime<startTime)))
		    {
			    UserPrint("%d Timeout",it);
			    break;
		    }
		}
    } 
    //
	// cleanup
	//
	DeviceReceiveDisable();

	LinkRxLoopDestroy(0);

    //
	// do data verify if requested
	//
	UserPrint(" %d\n",it);

	LinkRxStatFinish();

    return;
}
Esempio n. 3
0
// Added VSG sync detection 
void LinkRxComplete_vsgSync(int timeout, 
	int ndump, unsigned char *dataPattern, int dataPatternLength, int (*done)(), int chainMask)
{
    unsigned int startTime, endTime, ctime;
	int it, ii;
	int notdone;
	int stop;
	int behind;
	int scount;
	unsigned int mDescriptor;			// address of descriptor in shared memory
#ifdef MEMORYREAD
	unsigned int descriptor[MDESCRIPTOR+30];	// private copy of current descriptor
#else
    unsigned int *descriptor;
#endif
	int pass;
    int dsize;
	int isdone;

    int ss; 
    int rssic[MCHAIN], rssie[MCHAIN], rssi; 
    #define MSPECTRUM 1024 
    int nspectrum,spectrum[MSPECTRUM]; 
    int ndata; 
    unsigned char data[MBUFFER]; 
    int sscount=0; 
    unsigned int vsgSync = 0;

	pass=0;
	dataPatternLength=0;
	dataPattern=0;
	scount=0;
    dsize=RxDescriptorSize();
    //
	// Loop timeout condition.
	// This number can be large since it is only used for
	// catastrophic failure of cart. The normal terminating
	// condition is a message from cart saying STOP.
	//
    startTime=TimeMillisecond();
	ctime=startTime;
	if(timeout<=0)
	{
		timeout=2*60*1000;             // 2 mins
	}
	endTime=startTime+timeout;		
	//
	// set pointer to first descriptor
	//
//    mDescriptor = LinkRxLoopFirst(0);
	//
	// keep track of how many times we look and the descriptor is not done
	// this is used to control the sleep interval
	//
	notdone=0;
	stop=0;
	behind=0;
	//
	// loop looking for descriptors with received packets.
	//
	for(it = 0; ; it++) 
	{
		mDescriptor=LinkRxLoopDescriptor[it%LinkRxLoopMany];
#ifdef MEMORYREAD
        //
		// read the next descriptor
		//
        MyMemoryRead(mDescriptor, descriptor, dsize);		

#else
        descriptor=(unsigned int *)MyMemoryPtr(mDescriptor);
#endif
        //
		// descriptor is ready, we have a new packet
		//
       
        if(RxDescriptorDone(descriptor)) 
		{
#ifdef MEMORYREAD
            //
		    // read the next descriptor
		    //
            MyMemoryRead(mDescriptor, descriptor, dsize);
#endif
			notdone=0;
			behind++;
			scount=0;
#ifdef FASTER
			if((it%SASAMPLINGS)==0)   
			{
				UserPrint(" %d",it);
			}
#endif         

            if(_LinkRxSpectralScan) 
            { 
                ss=Ar9300RxDescriptorSpectralScan(descriptor); 
                if(ss) 
                { 
                    // 
                    // extract rssi and evm measurements. we need these for both good and bad packets 
                    // 
                    rssi=RxDescriptorRssiCombined(descriptor); 
                    if(rssi&0x80) 
                    { 
                        rssi|=0xffffff00; 
                    } 
                    rssic[0]=RxDescriptorRssiAnt00(descriptor); 
                    rssic[1]=RxDescriptorRssiAnt01(descriptor); 
                    rssic[2]=RxDescriptorRssiAnt02(descriptor); 
                    rssie[0]=RxDescriptorRssiAnt10(descriptor); 
                    rssie[1]=RxDescriptorRssiAnt11(descriptor); 
                    rssie[2]=RxDescriptorRssiAnt12(descriptor); 


                    for(ii=0; ii<3; ii++) 
                    { 
                        if(rssic[ii]&0x80) 
                        { 
                           rssic[ii]|=0xffffff00; 
                        } 
                        if(rssie[ii]&0x80) 
                        { 
                            rssie[ii]|=0xffffff00; 
                        } 
                    }

                    ndata=RxDescriptorDataLen(descriptor); 
                    MyMemoryRead(LinkRxLoopBuffer[it%LinkRxLoopMany], (unsigned int *)data, ndata); 
                    nspectrum=Ar9300SpectralScanProcess(data,ndata,spectrum,MSPECTRUM); 

                    if(_LinkRxSpectralScanFunction!=0) 
                    { 
                        (*_LinkRxSpectralScanFunction)(rssi,rssic,rssie,MCHAIN,spectrum,nspectrum); 
                    }
                    // 
                    // extract stats 

                    if (!vsgSync)
                    {
                        vsgSync = ((rssic[0] >= ISSM80DBM_THRESHOLD) && (chainMask & (1 << 0)) || 
                                   (rssic[1] >= ISSM80DBM_THRESHOLD) && (chainMask & (1 << 1)) ||
                                   (rssic[2] >= ISSM80DBM_THRESHOLD) && (chainMask & (1 << 2)) );
                    }
                    else
                    {
                        LinkRxStatSpectralScanExtract(descriptor,it); 
                    
                        sscount++; 
	                //UserPrint("ss_cnt:rssic:mask %d, %d, %d, %d\n",sscount, rssic[0], rssic[1], chainMask);
                    }

                    if(sscount >= SASAMPLINGS)   
                    { 
                        break; 
                    } 
                } 
            } 
            else 
            { 
                // dump packet contents
	    		//
                if(ndump>0) 
			    {
				    UserPrint("\n");
                    LinkRxDump(descriptor, ndump, it%LinkRxLoopMany);
                }
			    //
			    // extract stats
			    //
			    LinkRxStatExtract(descriptor,it);

            }
			//
			// reset the descriptor so that we can use it again
			//
			RxDescriptorReset(descriptor);
#ifdef MEMORYREAD
			//
			// copy it back to the shared memory
			//
			MyMemoryWrite(mDescriptor,descriptor,dsize);
#endif
			//
			// need to queue the descriptor with the hardware
			//
            if(LinkRxDescriptorFifo)
            {
	            DeviceReceiveDescriptorPointer(mDescriptor);
            }
        } 
		//
		// descriptor not ready
		//
		else 
		{
			if(stop)
			{
				scount++;
				if(scount>200)
				{
				    break;
				}
			}
			it--;
			//
			// sleep every other time, need to keep up with fast rates
			//
			if(notdone>100)
			{
			    UserPrint(".");
//			    MyDelay(1);
				notdone=0;
			}
			else
			{
				notdone=1;      // this makes sure we never sleep
			}
        }
		//
		// check for message from cart telling us to stop
		// this is the normal terminating condition
		//
		pass++;
		if(pass>100)
		{
			if(done!=0)
			{
				isdone=(*done)();
				if(isdone!=0)
				{
					UserPrint(" %d Stop",it);
					if(stop==0)
					{
						stop=1;
						scount=0;
						behind=0;
					}
					//
					// immediate stop
					//
					if(isdone==2)
					{
						break;
					}
	//				break;
				}
			}
			pass=0;
		    //
		    // check for timeout
		    // rare terminating condition when cart crashes or disconnects
		    //
		    ctime=TimeMillisecond();

#if 1
            if( timeout>0 && ((endTime>startTime && (ctime>endTime || ctime<startTime)) || (endTime<startTime && ctime>endTime && ctime<startTime)))
		    {

			    UserPrint("%d Timeout",it);
			    break;
		    }
#endif
		}
    } 
    //
	// cleanup
	//

    if(_LinkRxSpectralScan) 
    { 
        //DeviceSpectralScanDisable(); 
        Ar9300SpectralScanDisable();
    } 

	DeviceReceiveDisable();

	LinkRxLoopDestroy(0);

    //
	// do data verify if requested
	//
	UserPrint(" %d\n",it);

	LinkRxStatFinish();

    return;
}