Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Code seems to loops indefinitely

Code seems to loops indefinitely

Scheduled Pinned Locked Moved C#
question
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Karthik S Prakash
    wrote on last edited by
    #1

    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

    L L 2 Replies Last reply
    0
    • K Karthik S Prakash

      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

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      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


      K 1 Reply Last reply
      0
      • L Luc Pattyn

        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


        K Offline
        K Offline
        Karthik S Prakash
        wrote on last edited by
        #3

        @Luc: On the other side, my image file keeps growing > 1.8MB. The code never finishes.

        L 1 Reply Last reply
        0
        • K Karthik S Prakash

          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

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          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]

          1 Reply Last reply
          0
          • K Karthik S Prakash

            @Luc: On the other side, my image file keeps growing > 1.8MB. The code never finishes.

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            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


            K 1 Reply Last reply
            0
            • L Luc Pattyn

              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


              K Offline
              K Offline
              Karthik S Prakash
              wrote on last edited by
              #6

              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!

              L 1 Reply Last reply
              0
              • K Karthik S Prakash

                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!

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #7

                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


                K 1 Reply Last reply
                0
                • L Luc Pattyn

                  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


                  K Offline
                  K Offline
                  Karthik S Prakash
                  wrote on last edited by
                  #8

                  True. I am compiling this in the Xilinx SDK.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups