cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
karvi_in
Observer
Observer
3,530 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
karvi_in
Observer
Observer
4,313 Views
Registered: ‎11-14-2009

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
gszakacs
Professor
Professor
3,517 Views
Registered: ‎08-14-2007

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
karvi_in
Observer
Observer
4,314 Views
Registered: ‎11-14-2009

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