LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-08-2013, 04:36 AM   #1
rohaanembedded
Member
 
Registered: May 2013
Location: India
Distribution: Ubuntu 11.10
Posts: 178

Rep: Reputation: Disabled
Question Unkown issue in firmware download C code, Don't know where i m making mistake


Dear sir,

i ahve developed one code to download my firmware to cypress FX2LP. i am using the cyusb's cyusb_control_transfer and i am catching the sent bytes and i get perfect match between the Bytes sent and the firmware file size

but sad part is my device doesnt get initialised

Note: Firmware is tested n works fine

i am pasting here my code please do rply and give suggestions.

Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "../../include/cyusb.h"



unsigned int DownloadFirmware();


int main (void)
{

unsigned int a = 0;

a = DownloadFirmware();

if(a == 1)
{
printf("\nsuccessful fd\n");
}

}


unsigned int DownloadFirmware()
{

        cyusb_handle *h;
        int size, r;
        int a, b, c, flag;
    int Sum = 0, Done = 0;
    const char *cbuf;
    const char *filename = "/home/usb/FPR/firmware/fw.bix";
    unsigned char *buf = NULL;
    unsigned char *ptr;
    unsigned char num_bytes = 0;
    unsigned short address = 0;
    unsigned char reset = 0;
    FILE *fp;   /* file pointer */
   



        struct libusb_device_descriptor desc;


        a = cyusb_open();

         if ( a < 0 ) {
              printf("Error opening library\n");
              return -1;
           }
        else if ( a == 0 ) {
                   printf("No device foundd\n");
           }

        h = cyusb_gethandle(0);
        b = cyusb_get_device_descriptor(h, &desc);

        if(b){
           printf("error getting device descriptor\n");
           return -2;
        }




        struct stat st;
        stat(filename, &st);
        size = st.st_size;
       
        printf("size of file = %d\n", size);   
   
            buf = (unsigned char*)malloc(size);       




     /* open file for read */
          if ((fp = fopen("/home/usb/FPR/firmware/fw.bix", "r"))==NULL){
              printf("Cannot open file \n");
        }     

        fread(buf, size, 1 ,fp);
   
        fclose(fp);
    if(buf)
    printf("file copied");

    int ChunkSize = 4000; // seem to sending 4000 but not 5000 at one time
    int BlockSize = size;
    int entry = 0;
    reset = 1;
    sleep(1);


    reset = 0;

        r = cyusb_control_transfer(h, 0x40, 0xA0, 0xE600, 0x00, &reset, 0x01, 1000);
        if (!r) {
           printf("Error in control_transfer\n");
           return r;
        }

    sleep(1);
    sleep(1);
   
    ptr = buf;
   
    while(!Done)
    {


            if(BlockSize < ChunkSize){
                                address += ChunkSize;
                   //             buf = buf+ChunkSize;
                             ptr = ptr + ChunkSize;
                                ChunkSize = BlockSize;
                                flag = 1;
                                }


     r = cyusb_control_transfer(h, 0x40, 0xA0, address, 0x00, ptr, ChunkSize, 30);

        printf("\nturn no. %d\n", r);
         if (!r) {
               printf("Error in control_transfer. . .\n");
               return r;
            }


                          //  buf = buf+ChunkSize;
                             ptr = ptr + ChunkSize;
                                BlockSize -= r;
                Sum += r;
                                if(Sum == size)
                                Done = 1;
    printf("\nsum =  %d\n", Sum);

    }


    sleep(1);


                reset = 1;
                        r = cyusb_control_transfer(h, 0x40, 0xA0, 0xE600, 0x00, &reset, 0x01, 1000);

                reset = 0;
                        r = cyusb_control_transfer(h, 0x40, 0xA0, 0xE600, 0x00, &reset, 0x01, 1000);
   
    sleep(2);



    if(Done == 1){
    return 1;
    free(buf);
    }
}
Quote:
please help me i want to get out of this

Thanks in advance

Regards

Rohaan
 
Old 06-08-2013, 02:05 PM   #2
rohaanembedded
Member
 
Registered: May 2013
Location: India
Distribution: Ubuntu 11.10
Posts: 178

Original Poster
Rep: Reputation: Disabled
Unhappy

HelloOO everyOne,

Any rply on my problem

if any more details i have to give then let me knw,

the "Request feild" and the arguments in the cyusb_control_transfer call are right


i am trying to work on USB driver based on libusb and cyusb usb wrapper for user space driver Development
please Do rply and help me in this. . . .


Thanks & Regards
rohaan

Last edited by rohaanembedded; 06-08-2013 at 02:10 PM.
 
Old 06-09-2013, 12:33 PM   #3
rohaanembedded
Member
 
Registered: May 2013
Location: India
Distribution: Ubuntu 11.10
Posts: 178

Original Poster
Rep: Reputation: Disabled
hieee evrybody

still in need of solution
 
Old 06-10-2013, 01:39 PM   #4
trbennett48
LQ Newbie
 
Registered: Apr 2011
Posts: 23

Rep: Reputation: 3
Just a quick comment:

Your function DownloadFirmware() is declared to return an "unsigned int",
and yet is some places you are returning negative numbers.
 
1 members found this post helpful.
Old 06-11-2013, 02:59 AM   #5
rohaanembedded
Member
 
Registered: May 2013
Location: India
Distribution: Ubuntu 11.10
Posts: 178

Original Poster
Rep: Reputation: Disabled
Unhappy

Quote:
Originally Posted by trbennett48 View Post
Just a quick comment:

Your function DownloadFirmware() is declared to return an "unsigned int",
and yet is some places you are returning negative numbers.
dear sir,
Quote:
Thanks for giving attention and letting me know this thing now i have removed this this. but sir my code doesnt really go in to these "if" conditions where i was returning -ve values
Regards
rohaan
 
Old 06-11-2013, 09:56 AM   #6
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
You are getting few replies because your problem seems to be very specific to the use of a particular library or API. It would help others if you would explain the nature of that API (purpose, origin, etc) either in the narrative of your postings, or with comments in the code, or both. Including specific error messages or at least a detailed description of the expected results contrasted to the observed results. What exactly do you mean by 'my device doesnt get initialised'? How do you know this? You talk about downloading some code to a device. What is the communications channel that you use to send the data to the device? A lot of information seems to be buried in the API you're using, so a verbal description of what you're doing might help someone draw from their past similar, if not identical, experiences.

--- rod.
 
1 members found this post helpful.
Old 07-10-2013, 02:40 AM   #7
rohaanembedded
Member
 
Registered: May 2013
Location: India
Distribution: Ubuntu 11.10
Posts: 178

Original Poster
Rep: Reputation: Disabled
Question

Quote:
Originally Posted by theNbomr View Post
You are getting few replies because your problem seems to be very specific to the use of a particular library or API. It would help others if you would explain the nature of that API (purpose, origin, etc) either in the narrative of your postings, or with comments in the code, or both. Including specific error messages or at least a detailed description of the expected results contrasted to the observed results. What exactly do you mean by 'my device doesnt get initialised'? How do you know this? You talk about downloading some code to a device. What is the communications channel that you use to send the data to the device? A lot of information seems to be buried in the API you're using, so a verbal description of what you're doing might help someone draw from their past similar, if not identical, experiences.

--- rod.
how to delete this thread???
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re enabling Auto eth0 after making a newbie mistake Syek0sis Linux - Wireless Networking 2 05-08-2010 11:40 PM
I have made a mistake. Don't know what to do? muasif80 Linux - Newbie 13 10-06-2008 06:36 PM
Open Firmware code for booting OS from SATA : sample code available somewhere ? drsparikh Linux - Hardware 0 03-12-2004 11:16 AM
SCSI Device unavailable after firmware download. Redhat or "sg" issue? jrvance Linux - Hardware 2 10-21-2003 01:41 PM


All times are GMT -5. The time now is 09:02 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration