12-12-2009 09:12 AM - edited 12-12-2009 09:14 AM
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
12-12-2009 09:40 PM
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
12-12-2009 12:28 PM
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
12-12-2009 09:40 PM
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