Quantcast
Channel: Oracle Bloggers
Viewing all articles
Browse latest Browse all 19780

RPi with an Oscilloscope and Java Embedded: Ready for Benchmarking (Part 5)

$
0
0
One way to convert the C language GPIO access of /dev/mem is to use a Java NIO memory mapped buffer to open the Raspberry Pi memory as a device (with a Linux file descriptor), then get the file channel, then map it into the Java NIO accessible memory.

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...


Viewing all articles
Browse latest Browse all 19780

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>