Code seems to loops indefinitely
-
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 352for (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
-
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 352for (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
Hi, that is not C# code, so you're in the wrong forum. your code does not look good I'm not going to study it in any detail, unless you put it inside PRE tags (you can still edit your message) is the other side receiving anything? how much? does your code ever finish (say within calculated time * 10)? :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
-
Hi, that is not C# code, so you're in the wrong forum. your code does not look good I'm not going to study it in any detail, unless you put it inside PRE tags (you can still edit your message) is the other side receiving anything? how much? does your code ever finish (say within calculated time * 10)? :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
@Luc: On the other side, my image file keeps growing > 1.8MB. The code never finishes.
-
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 352for (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
Starting with the fact that your code does not compile as it stands, I have got it to run through in a couple of minutes; obviously without the data transfer. I guess you should check that the data is actually getting transmitted OK. [edit]Also note this is C++ so should be in that forum[/edit]
-
@Luc: On the other side, my image file keeps growing > 1.8MB. The code never finishes.
so look at what is in the file; there should be 288/2 * 352 * 3 = about 150KB: - are the first 150KB what you expect? if not, is there a pattern in the differences? - what's there after 150KB? this is call debugging: observe, observe closer, when something isn't what it seems, look at an earlier point, bring the last good point and the first bad point closer together, until you know where it goes wrong, then fix it. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
-
so look at what is in the file; there should be 288/2 * 352 * 3 = about 150KB: - are the first 150KB what you expect? if not, is there a pattern in the differences? - what's there after 150KB? this is call debugging: observe, observe closer, when something isn't what it seems, look at an earlier point, bring the last good point and the first bad point closer together, until you know where it goes wrong, then fix it. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Yes, I did check the image. It was garbled. Then I realized my mistake in the calculation of rows and cols... it should be 144 x 176. But that didnt solve the infinite loop until i was able to debug on hardware. I noticed j decreased to 0 and then increased back to the highest (32bit) value. Realized the mistake of making j unsigned int . Loop ends now :) Thank you!
-
Yes, I did check the image. It was garbled. Then I realized my mistake in the calculation of rows and cols... it should be 144 x 176. But that didnt solve the infinite loop until i was able to debug on hardware. I noticed j decreased to 0 and then increased back to the highest (32bit) value. Realized the mistake of making j unsigned int . Loop ends now :) Thank you!
Some compilers warn when a test is bound to always result in the same value; apparently yours didn't then. I always use my compiler at the highest warning level, and massage the code until it emits zero warnings! :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
-
Some compilers warn when a test is bound to always result in the same value; apparently yours didn't then. I always use my compiler at the highest warning level, and massage the code until it emits zero warnings! :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
True. I am compiling this in the Xilinx SDK.