2009-06-03 16:56:56     SPI delay

Document created by Aaronwu Employee on Aug 15, 2013
Version 1Show Document
  • View in full screen mode

2009-06-03 16:56:56     SPI delay

damien OLLIVE (UNITED STATES)

Message: 75131   

 

hi,

 

I try to download by SPI a file frome a device.

I use spidev and a program in the user space that read word by word and write them in a file.

 

    if((fp = fopen("appli", "w")) == NULL) {

    printf("Cannot open file.\n");

    exit(1);

    }

 

    while(1){

        readval = do_msgread(fd, len);

        printf("readval %c\n",readval);

        buffer[0] = readval;

        fwrite(buffer, sizeof(char), 1, fp);

    }

    if( fclose( fp ))

        printf("File close error.\n");

 

A word is readen all the 240us during 20ms and after the comunication stop during 300ms and restart for 20ms and stop again for 300ms...

I want to be able to download a new file system by this way and with this speed that will take 6 hours... too long

 

Do you have an idea of where do that come from and how can i cut this delay of 300ms?

 

thanks

QuoteReplyEditDelete

 

 

2009-06-03 20:42:58     Re: SPI delay

Robin Getz (UNITED STATES)

Message: 75137   

 

Damien:

 

What kind of device is on the other end of the SPI?

 

-Robin

QuoteReplyEditDelete

 

 

2009-06-04 03:20:49     Re: SPI delay

Sonic Zhang (CHINA)

Message: 75142   

 

What release do you use? What SPI device and driver do you download the file? What does do_msgread(fd, len); do? Why do you read only one byte in one loop?

QuoteReplyEditDelete

 

 

2009-06-04 10:02:29     Re: SPI delay

damien OLLIVE (UNITED STATES)

Message: 75211   

 

hi,

 

I have a VNC1L from FTDI, it is an USB/SPI interface.

i read or write just 8 bits of data because of it is his communication protocol, i use it in command mode.

 

the function do_msgread is

static char do_msgread(int fd, int len)

{

    struct spi_ioc_transfer    xfer[2];

    unsigned char        buf[32], *bp;

    int            status;

    __u16            mot;

 

    memset(xfer, 0, sizeof xfer);

    memset(buf, 0, sizeof buf);

 

    if (len > sizeof buf)

        len = sizeof buf;

 

    mot = 0xc000;

 

    buf[0] = mot;

    buf[1] =  mot >> 8;

 

    xfer[0].tx_buf = (__u64) buf;

    xfer[0].len = 2;

     xfer[0].rx_buf = (__u64) buf;

//     xfer[1].len = 2;

 

    status = ioctl(fd, SPI_IOC_MESSAGE(2), xfer);

    if (status < 0) {

        perror("SPI_IOC_MESSAGE");

        return;

    }

    mot = 0x0000;

    printf("response(%2d, %2d): ", len, status);

    for (bp = buf; len; len--){

        mot = (mot << 8);

        printf(" %02x", mot |= *bp++);

    }

 

    mot = ((mot >> 8) & 0x00ff) | ((mot << 8) & 0xff00);

    mot = ((mot &0x1fe0) >> 5);

    printf("  : %c\n",mot);

 

    return mot;

}

 

it is similar to the function do_msg in linux-2.6.x/documentation/spidev_fdx.c

 

i have the svn revision (2009 kernel)

 

The chip works well but i have a problem when i try to use the spidev continually during a period like if the kernel suspend my application to do something else. Could be a priority problem?

Attachments

    Outcomes