Debug went crazy

Hi friends.
I built some simple i2c protocol driver code to work with Xilinx.
When I debug the code, something strange happens - the code run back and forth between 2 lines and never continue (And in debug it's always go sequentially).

Here is a code-snippet:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
	while(1){
		statug_reg = Xil_In32(IIC_IP_BaseAddr+SR_Address);
		if ((statug_reg>>1)&0x1){   // slv_addr detected
			printf("\n\rstep 1 - slv_addr detected\n\r");

			if ((((Xil_In32(IIC_IP_BaseAddr+SR_Address))>>3)&0x1) == 0){  //master writing to slave
				printf("\n\rstep 2 - master writing to slave\n\r");
				for(int i=0; i<recvLen;i++) {

					CheckFifoNotEmpty(IIC_IP_BaseAddr);
					data_in = Xil_In32(IIC_IP_BaseAddr+Rx_FIFO);
					*(rxDataBuffer+i) = data_in;
					printf("Read location %d in Rx_FIFO\n\r",i);
				}
				return 0;
			}
		}
	}


The debug goes back and forth lines 2 and 3.

Xil_In32 definition:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
*
* @brief    Performs an input operation for a memory location by
*           reading from the specified address and returning the 32 bit Value
*           read  from that address.
*
* @param	Addr: contains the address to perform the input operation
*
* @return	The 32 bit Value read from the specified input address.
*
******************************************************************************/
static INLINE u32 Xil_In32(UINTPTR Addr)
{
	return *(volatile u32 *) Addr;
}


I guess it is something to so with this function, but I can't figure out what.



Last edited on
Maybe Xil_In32 also needs to be declared as a volatile function.

1
2
3
4
static volatile INLINE u32 Xil_In32(UINTPTR Addr)
{
	return *(volatile u32 *) Addr;
}



The same would be true for any other function which reads external hardware, and that hardware is capable of changing state without the program doing anything.

Topic archived. No new replies allowed.