By hinkmond on Mar 21, 2013
This is essentially the same process that Gordon Drogon is using in his WiringPi.c file. Instead of Java NIO, he is using the C and the Linux mmap() function to a file descriptor pointing to /dev/mem. So, our Java translation of that same functionality would look something like this.
/* * Example Code */ import java.io.RandomAccessFile; import java.nio.MappedByteBuffer; import java.nio.channels.FileChannel; //... RandomAccessFile fileHandle = new RandomAccessFile("/dev/mem", "rw"); FileChannel fileChannel = fileHandle.getChannel(); MappedByteBuffer gpioMem = fileChannel.map( FileChannel.MapMode.READ_WRITE, BCM2708_PERI_BASE + 0x200000, PAGE_SIZE);
So, we have our Java code. Let's take a look if this works on the Raspberry Pi with our Java Embedded stack...