WARP Project Forums - Wireless Open-Access Research Platform

You are not logged in.

#1 2012-Mar-22 22:13:54

cx
Member
Registered: 2012-Feb-17
Posts: 24

timer doesn't work

Hi, all.

I tried to measure how much delay the PHY layer is causing in OFDM reference design. So I tweaked the code in csmamac.c (codes started with comment "//C.X." are the codes I added). I use the built-in timer to measure the time.

However, the outcome was the startTime and finishTime both equals to 500. So does this mean the timer is not accurate enough? But as I understand the accuracy is 1 time unit = 12.5nsec. Or is it because my way using timer was wrong?

Thank you.


Code:

 
        void dataFromNetworkLayer_callback(Xuint32 length, char* payload){
	unsigned char rxSeqNum;
	unsigned char destNode;
	
	//C.X. use timer 3 to measure transmition delay in PHY layer. following to varialbes are used to record the counter in timer3
	unsigned int startTime;
	unsigned int finishTime;
	unsigned int elapsedTime;
	unsigned int microsecond;

	//Reset the contention window to its minimum
	warpmac_resetCurrentCW();

	//Disable further Ethernet packets (will be re-enabled after this packet is ACK'd or dropped)
	warpmac_disableDataFromNetwork();

	//Update the Tx packet header with this packet's values
	txMacframe.header.length = length;
	txMacframe.header.pktType = PKTTYPE_DATA;

	//Set the modulation scheme for the packet's full-rate symbols
	txMacframe.header.fullRate = pktFullRate;

	//Set the code rate for the packet's payload
	txMacframe.header.codeRate = pktCodeRate;

	//For now, assume our destination is our opposite ID (all traffic is 0 <-> 1)
	destNode = (myID+1)%2;

	//Copy in the packet's destination MAC address
	txMacframe.header.destAddr = (unsigned short int)(NODEID_TO_ADDR(destNode));

	//Use the next sequence number for this node (top four bits) and resend count of 0 (bottom four bits)
	txSequences[destNode] = (txSequences[destNode] + 1) % 256;
	txMacframe.header.seqNum = txSequences[destNode];

	//Set the remaining Tx counter to the maximum numeber of transmissions
	txMacframe.header.remainingTx = (maximumReSend+1);

	if(warpmac_carrierSense()) {
		//If the modium is idle:

		//Copy the header to the Tx packet buffer
		warpmac_prepPhyForXmit(&txMacframe, pktBuf_tx_DATA);
	
		//C.X. start measuring time
		warp_timer_setTimer(4, 0, 500);
		//C.X. record the start time			
		warp_timer_start(4);
		xil_printf("this is new\r\n");
		startTime = XIo_In32(XPAR_WARP_TIMER_PLBW_0_MEMMAP_TIMER4_SLOTCOUNT);	
		xil_printf("startTime = %d\r\n =0x%x\r\n", startTime, startTime);
		
		//Transmit the packet
		warpmac_startPhyXmit(pktBuf_tx_DATA);
		
		//Wait for it to finish
		warpmac_finishPhyXmit();
		
		//C.X. read time		
		warp_timer_pause(4);
		finishTime = XIo_In32(XPAR_WARP_TIMER_PLBW_0_MEMMAP_TIMER4_SLOTCOUNT);
		xil_printf("finishTime = %d\r\n =0x%x\r\n", finishTime, finishTime);
		elapsedTime = finishTime - startTime;
		xil_printf("elapsedTime = %d\r\n =0x%x\r\n", elapsedTime, elapsedTime);
		microsecond = elapsedTime/TIMERCLK_CYCLES_PER_USEC;
		xil_printf("microsecond = %d\r\n =0x%x\r\n", microsecond, microsecond);
		
		
		//Start a timeout timer
		warpmac_setTimer(TIMEOUT_TIMER);
		warpmac_decrementRemainingReSend(&txMacframe);
	}
	else {
		//Medium was busy; start a backoff timer
		warpmac_setTimer(BACKOFF_TIMER);
	}

	return;
}

Offline

 

#2 2012-Mar-22 23:19:14

murphpo
Administrator
From: Mango Communications
Registered: 2006-Jul-03
Posts: 5159

Re: timer doesn't work

The warp_timer core doesn't provide a regster to read the internal counter's current value. The register you're reading (TIMER4_SLOTCOUNT) sets the count-to value, hence it never changing.

I suggest using the PPC's internal timer via the XTime functions. Something like this should work:

Code:

#include xtime_l.h
XTime start_timer, end_timer;
long long timeDiff = 0;

XTime_GetTime(&start_timer);

//Do something time consuming here

XTime_GetTime(&end_timer);

//Calculate time difference in PPC clock cycles
timeDiff = end_timer - start_timer;

The actual duration for timeDiff will depend on the PPC clock frequency. In the OFDM ref design v16.1 this is 240MHz. In general this is specified in the parameters of the clock_generator core in your XPS project. Look for the C_CLKOUTx_FREQ parameter corresponding to the clock output driving proc_clk_s.

Offline

 

#3 2013-Apr-08 14:18:37

Marka
Member
Registered: 2013-Apr-08
Posts: 9

Re: timer doesn't work

Hi. I'm using WARP v3. Does anyone know how to get the timestamp in Microblaze? Thank you.

Offline

 

#4 2013-Apr-08 16:30:56

chunter
Administrator
From: Mango Communications
Registered: 2006-Aug-24
Posts: 1212

Re: timer doesn't work

I don't believe the Microblaze has a built in counter like the PowerPCs did. We just use the Xilinx-provided XPS Timer peripheral for doing that. Check out the WARP v3 On-Board Template Project to see how we use that core to implement usleep() in the example code.

Offline

 

#5 2013-Apr-09 23:20:10

Marka
Member
Registered: 2013-Apr-08
Posts: 9

Re: timer doesn't work

Thank you, Chris. I'm working on OFDM reference design. I used the timer this way, can you help me check if this is the right way using it?
0. declaration:

Code:

XTmrCtr Timer;
XTmrCtr *TmrPtr = &Timer;

1. start the timer:

Code:

XTmrCtr_Initialize(TmrPtr, TMRCTR_DEVICE_ID);    // set reset point
XTmrCtr_SetResetValue(TmrPtr, 0, 0x00000000);    // reset timer
XTmrCtr_Reset(TmrPtr, 0);    // start timer
XTmrCtr_Start(TmrPtr, 0);

2. stop the timer and get the time stamp:

Code:

XTmrCtr_Stop(TmrPtr, 0);// stop timer
cycle = XTmrCtr_GetValue(TmrPtr, 0);

I think these codes won't mess with the backoff timer, will they?
Also, just to make sure, is the frequency of this timer 80Mhz?
Thank you.

Last edited by Marka (2013-Apr-10 00:41:28)

Offline

 

#6 2013-Apr-10 09:21:39

chunter
Administrator
From: Mango Communications
Registered: 2006-Aug-24
Posts: 1212

Re: timer doesn't work

I noticed you don't have a call to 'XTmrCtr_SetOptions.' Does it default to counting up instead of down? You may want to set that explicitly. Otherwise I think that's correct.

The frequency of the timer depends on the speed of the bus that it sits on. Thankfully, XPS is smart in that it will automatically populate a #define for you that contains the speed. The #define is XPAR_XPS_TIMER_0_CLOCK_FREQ_HZ if the name of your core is xps_timer_0.

This won't mess up the backoff timer. That timer is actually a totally separate custom core that we developed that knows what slot times are and knows how to automatically pause when the medium has not been idle for a full DIFS period.

Offline

 

#7 2015-Feb-27 11:34:47

Yb2015
Member
Registered: 2015-Jan-13
Posts: 15

Re: timer doesn't work

Hey,

I got one question based on backoff timer.
I want to utilize the difference between real time backoff number in our design.
In the 802.11 reference design, is it possible that I could read the real time number in the backoff timer in the C code?
I only find functions about set and reset the backoff timer.
Thanks for your suggestion.

Offline

 

#8 2015-Feb-27 11:48:08

murphpo
Administrator
From: Mango Communications
Registered: 2006-Jul-03
Posts: 5159

Re: timer doesn't work

The current backoff counter value is captured in the MAC hardware status register. Use the macro wlan_mac_get_backoff_count() to read the current backoff value. This macro only works in CPU Low.

Offline

 

Board footer