none
hi this is regarding cypress cy7c68013

    Question

  • pls help me in understanding this part of my code
    deviceiocontrol

     FILE *fp=fopen(m_browse,"rb+");
      fseek(fp,0,SEEK_END);
      int size=ftell(fp);
      fclose(fp);
      fp=fopen(m_browse,"rb+");
      FILE *fp1=fopen("USB_OUT.dat","wb+"); 

      if(size<=512)
      {
       fread(outBuffer,1,size,fp);
       DeviceIoControl (outDevice,IOCTL_EZUSB_BULK_WRITE,&bulkControl1,sizeof(BULK_TRANSFER_CONTROL),
                    &outBuffer[0], size,&nBytes,NULL);

       DeviceIoControl (inDevice,IOCTL_EZUSB_BULK_READ,&bulkControl2,sizeof(BULK_TRANSFER_CONTROL),
           &inBuffer[0], 512,&nBytes,NULL);
       fwrite(inBuffer,1,512,fp1);


      }

                                                        

    pls help me its urgent

    Wednesday, November 18, 2009 1:09 PM

Answers

  • This code opens a file, and checks how much data there is in that file.
    If there is less  or equal than 512 bytes, it reads the data into a buffer, and then uses a device IO control command to send that data to a USB device. then it reads 512 bytes back from that device and writes it to a USB_OUT.dat file.

    What it is doing is trivial. How it is doing it is horrible. No error checking anywhere, and no check of the file handles. I hope this is not production code, but a proof of concept sample.
    • Proposed as answer by Nancy Shao Friday, November 20, 2009 3:43 AM
    • Marked as answer by Nancy Shao Wednesday, November 25, 2009 11:19 AM
    Wednesday, November 18, 2009 7:42 PM

All replies

  • This code opens a file, and checks how much data there is in that file.
    If there is less  or equal than 512 bytes, it reads the data into a buffer, and then uses a device IO control command to send that data to a USB device. then it reads 512 bytes back from that device and writes it to a USB_OUT.dat file.

    What it is doing is trivial. How it is doing it is horrible. No error checking anywhere, and no check of the file handles. I hope this is not production code, but a proof of concept sample.
    • Proposed as answer by Nancy Shao Friday, November 20, 2009 3:43 AM
    • Marked as answer by Nancy Shao Wednesday, November 25, 2009 11:19 AM
    Wednesday, November 18, 2009 7:42 PM
  • hey thanks a lot.
     yes this is part of a code i m using for loopback..
    actually m facing a lil problem

    i have my doubts.ill be really grateful if u could reply to them.

    1. what is the function of ftell.
    2.in this actually vc code which i m using is for interacting with computer and cypress controller and a vhdl code for intereacting between cypress and the fpga kit.so a loopback is happening from computer to cypress controller to fpga kit and from fpga kit to cypress controller(by vhdl code) back to computer.

    in the modification i want to make it only one way ie some value into the fifo(fpga) from some other source and then from fpga to cypress controller and then finally to the pc,for this m i required to make some changes in the vc code.

    if u just gimme ur email id i can mail u the code.


    thanks in advance
    Friday, November 20, 2009 6:40 AM
  • Hi Seemaj,

    ftell function gets the current position of a file pointer. For more information, see MSDN article about ftell function with link:

    http://msdn.microsoft.com/en-us/library/0ys3hc0b(VS.71).aspx

    About your second question, I would suggest you post in FPGA related forum or use Bing to search. The reason why I suggest you post in FPGA related forum is that your question is more related to FPGA, and if you post the question in the right forum, you will get bettter answer.

    Best Regards,
    Nancy

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, November 25, 2009 6:18 AM