WARP Project Forums - Wireless Open-Access Research Platform

You are not logged in.

#1 2015-Sep-22 20:55:45

wenchao88
Member
Registered: 2015-Aug-22
Posts: 26

Global variable in wlan_mac_dcf

I have a strange problem when editing the file wlan_mac_dcf.c file. I want to define some global variables to store values, say count the number of packets sent through dcf mac. However, I found global variable variables doesn't work in wlan_mac_dcf.c

I define the variables here, and change its value in the function "frame_transmit"

Code:

volatile u8                            gl_red_led_index;
volatile u8                            gl_green_led_index;

//Defined by Wenchao
u16 gl_beacon_counter = 0;

I tried the keyword like volatile, static, but non of them works. The value of gl_beacon_counter never changes. What is even more strange is that I wrote

Code:

gl_beacon_counter ++;
xil_printf("%d",  gl_beacon_counter );

The output is still 0!!! I got crazy.

I wonder how the file wlan_mac_dcf.c is called. I believe I compiled the file after the change, because I use different printf each time.

Offline

 

#2 2015-Sep-23 08:48:29

welsh
Administrator
From: Mango Communications
Registered: 2013-May-15
Posts: 612

Re: Global variable in wlan_mac_dcf

That is a very strange issue.

I took the 802.11 Reference design version 1.3.0, and added a global variable in wlan_mac_dcf:

Code:

volatile u8                            gl_red_led_index;
volatile u8                            gl_green_led_index;

u16                                    gl_beacon_counter;

Initialized the variable in main():

Code:

	gl_stationShortRetryCount = 0;
	gl_stationLongRetryCount = 0;

	gl_beacon_counter = 0;

Then added an increment and print to frame_transmit():

Code:

	//Compare the length of this frame to the RTS Threshold
	if(mpdu_length <= gl_dot11RTSThreshold) {
		tx_mode = TX_MODE_SHORT;
	} else {
		tx_mode = TX_MODE_LONG;
	}
	
	gl_beacon_counter++;
	xil_printf("%d\n", gl_beacon_counter);

	while(1) { //This is the retry loop

I downloaded the AP design to CPU High and the DCF design to CPU low.  When I set the DIP switches to make the UART output CPU low (ie the right-most DIP switch is set to zero), I see a steady stream of prints that increment.  You should check that you are seeing the correct UART output and that you are downloading the correct projects as part of the bitstream.

Also, just a note:  Please be careful when printing in CPU low.  There are some timing critical aspects in CPU low and printfs can take a long time relative to the time periods involved.

Offline

 

#3 2015-Sep-23 10:53:47

wenchao88
Member
Registered: 2015-Aug-22
Posts: 26

Re: Global variable in wlan_mac_dcf

Thanks Welsh, I find your code works well. I finally find the case in which xil_printf will go wrong. This code works well

Code:

current_timestamp = get_usec_timestamp();
gl_beacon_counter ++;

xil_printf("Beacon start timestamp: 0x%x\n",current_timestamp);
xil_printf("%x\n", gl_beacon_counter);

But in this code, the output of gl_beacon_counter is always 0.

Code:

current_timestamp = get_usec_timestamp();
gl_beacon_counter ++;

xil_printf("Beacon start timestamp: 0x%x %d\n",current_timestamp, gl_beacon_counter);

In C, they seems to be equivalent. However, WARP has different output. That is what confuses me. Maybe some bug in xil_printf?

Last edited by wenchao88 (2015-Sep-23 10:54:10)

Offline

 

#4 2015-Sep-23 14:47:29

welsh
Administrator
From: Mango Communications
Registered: 2013-May-15
Posts: 612

Re: Global variable in wlan_mac_dcf

Unfortunately, you are running into a quirk with how xil_printf interprets format specifier arguments.  If you look at your declaration for "current_timestamp", you will see that it is a 64 bit unsigned integer (i.e. a u64).  However, due to a number of factors, xil_printf can only use a 32 bit integer (signed or unsigned) for each format specifier.  Therefore, instead of:

Code:

xil_printf("Beacon start timestamp: 0x%x %d\n", current_timestamp, gl_beacon_counter);

what xil_printf is actually trying to process is:

Code:

xil_printf("Beacon start timestamp: 0x%x %d\n", (current_timestamp & 0xFFFFFFFF), (current_timestamp >> 32));

where "(current_timestamp & 0xFFFFFFFF)" is the lower 32 bits of the u64 and "(current_timestamp >> 32)" is the upper 32 bits of the u64.  This is why you are always getting zero for the second argument; the timestamp has not grown bigger than 32 bits.

To fix this, you need to tell the compiler that you only want to print the lower 32 bits of the timestamp:

Code:

xil_printf("Beacon start timestamp: 0x%x %d\n", (u32) current_timestamp, gl_beacon_counter);

If you look through the reference design, you can see a number of places where we print the timestamp like this.

Offline

 

Board footer