UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Observer karvi_in
Observer
3,422 Views
Registered: ‎11-14-2009

Code seems to loops indefinitely

Jump to solution

I am trying to transmit about 75Kbytes of image data at 115200 baud. Ideally it should take about 5 secs. But this code seems to loop forever. Am I missing something obvious here?


#define rows 288
#define cols 352

 for (j=rows-2; j>=0; j-=2)
    {
        for (i = (j*cols); i<((j*cols)+cols); i++)
        {
            cam_output = ram_read(i*4);
            SendBuffer[0] = (cam_output >> 24) & 0xff;
            SendBuffer[1] = (cam_output >> 16) & 0xff;              
            SendBuffer[2] = (cam_output >> 8) & 0xff;
                          
            uart_send(&SendBuffer, 3);    
            
        }        
    }


void uart_send(u8 *DataBufferPtr, unsigned int NumBytes)
{
    int i;
    
    for (i=0; i<NumBytes; i++)
    {
        XUartLite_SendByte(XPAR_UARTLITE_0_BASEADDR, *(DataBufferPtr+i));
    }

}

 

 

 

Regards,

 

Karthik

Message Edited by karvi_in on 12-12-2009 09:14 AM
0 Kudos
1 Solution

Accepted Solutions
Observer karvi_in
Observer
4,205 Views
Registered: ‎11-14-2009

Re: Code seems to loops indefinitely

Jump to solution

I should've mentioned it should be 144 * 176 * 3 ~ 5secs.

 

But the problem was 'j' was declared as unsigned int. So when j reached zero at the end of the loop, the last j-2 ended up giving j the (highest 32bit numbe - 2).  So the loop never ended.

 

Thank you! 

 

 

Regards,

Karthik

View solution in original post

0 Kudos
2 Replies
Professor
Professor
3,409 Views
Registered: ‎08-14-2007

Re: Code seems to loops indefinitely

Jump to solution

I'm not sure how you came up with 5 seconds.  It looks like you have rows/2 times cols times 3 bytes:

 

144 * 352 * 3 = 152064

 

For a normal UART with one start and one stop bit, multiply by ten to get the number of bit times:

 

152064 * 10 = 1520640

 

Then divide by the baud rate to get time:

 

1520640 / 115200 = 13.2 seconds.

 

Still not forever...

 

Are you getting any data that you expect?  I'm not sure you wanted to write

"&SendBuffer"  I would think you either wanted "SendBuffer" or "&SendBuffer[0]"

but I don't see how that would cause an infinite loop unless you are somehow

trashing your stack.

 

HTH,

Gabor

-- Gabor
Observer karvi_in
Observer
4,206 Views
Registered: ‎11-14-2009

Re: Code seems to loops indefinitely

Jump to solution

I should've mentioned it should be 144 * 176 * 3 ~ 5secs.

 

But the problem was 'j' was declared as unsigned int. So when j reached zero at the end of the loop, the last j-2 ended up giving j the (highest 32bit numbe - 2).  So the loop never ended.

 

Thank you! 

 

 

Regards,

Karthik

View solution in original post

0 Kudos