Dear All,
In my project I have to connect via GPIOs on J3A1 and J3A2 pin headers to a dedicated hardware - PAL video input/output chip. To do this, I decided to write a linux kernel module. I started with registering gpios with:
int gpio_request(unsigned gpio, const char *label)
Then set its directories as input or output with:
int gpio_direction_input(unsigned gpio)
int gpio_direction_output(unsigned gpio, int value)
Then I perform a test read of 8 pins with my custom test function:
int read_vdox(void){
int val = 0;
val = val | (gpio_get_value(VDOX0) << 0);
val = val | (gpio_get_value(VDOX1) << 1);
val = val | (gpio_get_value(VDOX2) << 2);
val = val | (gpio_get_value(VDOX3) << 3);
val = val | (gpio_get_value(VDOX4) << 4);
val = val | (gpio_get_value(VDOX5) << 5);
val = val | (gpio_get_value(VDOX6) << 6);
val = val | (gpio_get_value(VDOX7) << 7);
return val;
}
(I know that if val is nonzero but not equal one, then the result value may not be correct, but this is not the case in this test).
To test the read time, I call this function in a loop 1440*625 times (total number of YCrCb pixels obtained from the PAL signal) and measure the execution time with jiffies.
start = jiffies;
for(i=0; i<1440*625; i++)
test_vdox = read_vdox();
stop = jiffies;
msec = (stop - start)*1000 / HZ;
printk(KERN_ALERT "pins-test: VDOX value is %d, read in %d\n", test_vdox, (int)msec);
The resulting time is about 3 seconds, which is definitely too long. To achieve the task, I need to read the whole image in about 20 ms. (The code above tests only gpio read time and does not deal with details of video transfer protocol).
Is there any way for faster GPIO access? Or I do something in a wrong way?
I guess that internals of gpio_get_value can call some memory barriers, i.e. 8 instead of 1, but my dive into the kernel source code and documentation didn’t give me any details.
Looking forward for any answer.