GPIO access from users pace?
Hi, is it possible to access ARM's GPIOs (EP93xx) runnning 2.6.21 Linux, from user space?
if yes how? what are the system call? any tutorials? thanks |
You can always write a driver to be able to do it. The manufacturer of your board may already provide a reference driver.
|
Yes u can.
try to look for "Low level I/O API", like read(), write(), also mmap().. |
mmap is the answer you are looking for, if you look at the ep9301 user guide (or one more appropriate to the chip you are using) you can see where it maps pins to memory.
- snippet of code for ep9302 memory mapping of gpio pins - Code:
#define GPIO_BASE 0x80840000 *PBDDR = 0xff; /* data direction register, 0xff makes all the pins outputs iirc, been a while since I've read the user guide */ *PBDR = 0x01; /* drive the lowest pin that it controls high */ |
Hi estabroo
thanks for the helpful reply, i have tested the code (after rewriting it by adding main function,etc.. )and i get this error on Olimex CS-e9302 board Code:
Segmentation fault |
Segmentation fault means a wild pointer.
|
Can you run it in a debugger and find out where the segfault occurred? If not you might have to put in fprintf to stderr messages to narrow it down, does it have a console (serial, vga, ...)? You should also check the value you get back from mmap to make sure it didn't fail. Can you post your code?
|
Quote:
if u mean someting like hyperterminal, then yes i am using cutecom. here is the code: Code:
#include <stdio.h> |
Okay the problem is your declaration of gpio. It was ** in the function I posted because it was being passed in by reference, since you have it in the main program you should do this instead
Code:
#include <stdio.h> |
thanks very much,,it works now
|
interruption
Hi, Your code was very very usefull to me, but I would like know how I can set an interruption in GIOPORT, for example:
if the pin x from portA or B detect a low level (0) then execute a function (eg, increase a counter) thanks |
I would imagine you'd need to write a kernel module that setup an irq handler function and requested interrupts generated by that gpio be sent to it. Take a look at the set_irq_type and request_irq functions in the kernel.
|
Hi,
dealing with interrupts can be done only in Kernel space not user space. just use as estabroo said, "request_irq" to register ur irq number and device name, etc.. then write the handler (ISR).. at the exit of the module just free the irq. http://www.xml.com/ldd/chapter/book/ch09.html cheers |
interruption
Thanks estabroo and raedbenz. I will tray write a module in kernel that let me manage an IO interruption. When I finish I will write here the code.
|
All times are GMT -5. The time now is 05:46 PM. |