2010-12-07 11:42:33     BF537, GPIO speed

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

2010-12-07 11:42:33     BF537, GPIO speed

Andreas Schallenberg (GERMANY)

Message: 96540   

 

Hello,

 

I am using the sysfs GPIO driver to do I/O. uClinux is 2010R1-RC3,

board has a BF537: "VCO: 600 MHz, Core: 600 MHz, System: 120 MHz"

 

inline

void writePinQuick(GpioPin * pinPtr, bool value)

{ fputs(value ? "1\n" : "0\n", pinPtr->valueFd); }

 

...

for (int i = 7; i >= 0; --i) // MSB first

{

            bool value = (0 != (ch & (1 << i)));

            writePinQuick(&pinCfgData0, value);

            writePinQuick(&pinCfgCclk, true);

            writePinQuick(&pinCfgData0, value);

            writePinQuick(&pinCfgCclk, false);

}

 

I am aware that there are some cycles to be gained here. The loop

runs with a frequency of 11Khz (using fwrite it is a bit faster) but that

is still way to slow (given that it runs on a 600 MHz / 120 MHz DSP).

I need a speedup of (at least) 10x to 20x.

 

a) Is there a way to do faster I/O than this from user space?

 

b) If not, I guess it is time for a custom kernel driver. It should operate

in two modes: First, running a loop like above with a large chunk of

data. The second mode would be a custom asynchonous bus interface

with random reads and writes. Are there any existing kernel drivers that

use gpiolib and would be a good example?

 

Andreas

TranslateQuoteReplyEditDelete

 

 

2010-12-07 15:01:00     Re: BF537, GPIO speed

Mike Frysinger (UNITED STATES)

Message: 96542   

 

use pwrite on the fd rather than fputs on an stream.  make sure you specify an offset of 0 with pwrite.

QuoteReplyEditDelete

 

 

2010-12-08 07:25:40     Re: BF537, GPIO speed

Andreas Schallenberg (GERMANY)

Message: 96563   

 

Thank you for that hint! Using pwrite (and some minor optimizations in my code) gave me a factor of about 5x. Another 4x - 6x would get me into the region where it could be sufficient. Are there any other ways to speed things up?

TranslateQuoteReplyEditDelete

 

 

2010-12-08 07:38:11     Re: BF537, GPIO speed

Mike Frysinger (UNITED STATES)

Message: 96565   

 

without seeing your code, i dont know.  but if the only thing you're doing is like while (1) { pwrite(fd, "0", 1, 0); pwrite(fd, "1", 1, 0); }, then you cant get any faster than that in userspace.  writev() doesnt reset the offset, and there is no pwritev().

QuoteReplyEditDelete

 

 

2010-12-08 09:19:36     Re: BF537, GPIO speed

Andreas Schallenberg (GERMANY)

Message: 96566   

 

Yes, my code is quite close to that:

 

...

unsigned char ch = imageData[pos];

unsigned char bit = 0x80;

 

while (bit)

{

  unsigned char value = (ch & bit ? '1' : '0');

  bit >>= 1;

 

  pwrite(data0Fd, &value, 1, 0);

  pwrite(cclk0Fd, "1", 1, 0);

  pwrite(data0Fd, &value, 1, 0);

  pwrite(cclk0Fd, "0", 1, 0);

}

...

 

So I'll need to write a kernel driver to be faster. Which one would be a good starting point to have a look at?

TranslateQuoteReplyEditDelete

 

 

2010-12-09 04:35:50     Re: BF537, GPIO speed

Mike Frysinger (UNITED STATES)

Message: 96586   

 

the old simple gpio might be useful to you:

  blackfin.uclinux.org/gf/project/linux-kernel/scmsvn/?action=browse&path=%2Fbranches%2F2009R1%2Fdrivers%2Fchar%2Fsimple-gpio.c&view=markup

 

otherwise, just pick any file in drivers/char/*bfin*.c

 

or look at the driver examples in our wiki

Attachments

    Outcomes