Hardware Reference
In-Depth Information
Discussion
This code is very fast at copying one GPIO bit to another. The disadvantage is that it uses
100 percent of the CPU. If you need the CPU to do other things, try uncommenting the
usleep() command and recompiling. In my case, the response is fast, but only 30 per-
cent of the CPU is used.
In this code, the mmap() command is used to map the GPIO0 registers to gpio_addr .
The next few lines add the register offsets to gpio_addr to get the address for the re-
gisters being used. The code then goes into a tight while loop checking GPIO 7 and writ-
ing to GPIO 31.
The code uses -O3 when compiling to tell the compiler to optimize the code.
This is likely the fastest way to process GPIOs with this kernel. The problem is that other
programs are running on the Bone while this one is running. Sometimes, one of those pro-
grams can be using the CPU when the GPIO changes, and your program won't get control
until several milliseconds later. Recipe 8.5 shows how to reconfigure the kernel to minim-
ize the time your program can be interrupted.
Search WWH ::




Custom Search