I have spent many hours researching this topic and am finding that it is much harder than I expected to get help with micro-controller questions if you are a newbie like myself.
I have found some reference to mmap() functions but that seems like a function best left alone unless you know what you are doing.
I have come to the conclusion that for rookies like myself, and I am guessing the OP, that using the /sys/class/gpio drivers are the safe way to go, although I am not sure if timing will be a problem, I want to use the pins to communicate with sensors via 1-wire or 2-wire protocol.
Anyway to the OP, if you are using the Linux OS on this board you should have /sys/class/gpio/ directory with:
-
export (file)
-
unexport (file)
-
gpiochip32 (directory)
-
gpiochip64 (directory)
-
gpiochip96 (directory)
In each respective directory will be a few files, the “label” file should give a description of the port, on mine for example they are:
/gpiochip32/label = A
/gpiochip64/label = B
/gpiochip96/label = C
I look at the data sheet for the board and find that the 40-pin header (EXT) is labeled with mostly PB#'s, so I choose a “B” port pin to work with.
The base for “B” is 64, ie. gpiochip64, this will also see this via
cat /sys/class/gpio/gpiochip64/base
I want to manipulate PB0 and PB1, pins 5 and 7 on the 40-pin header so I “export” them from the command line like so:
– PB0: 64 + 0 = 64
echo 64 > /sys/class/gpio/export
– PB1: 64 + 1 = 65
echo 65 > /sys/class/gpio/export
These commands will create directories “gpio64” and “gpio65” under /sys/class/gpio.
In each of these new folders will be four files, the files we are interested in are “direction” and “value”. You can see the current values via the cat command from the command line, you can set them via echo commands.
cd /sys/class/gpio/gpio64 (make sure you are in the correct directory)
cat direction (output will be "in" or "out")
cat value (output will be "1" or "0")
echo "out" > direction (set the direction of the pin to out)
echo 1 > value (set the value to "1" or high)
echo 0 > value (set the value to "0" or low)
To use this in a C program you write yourself and compile to run on Linux OS of this board there is some example code at the following link that I used and seemed to work when I tested it on my board:
http://xilinx.wikidot.com/gpio-user-space-app
Just make sure you change the “240” in the code to match your gpio, for my board I changed the “240” to “64” for PB0(pin 5 of 40-pin header).
Hope this helps.