Oracle Java Wireless Client

com.oracle.deviceaccess.mmio
Interface MMIODevice

All Superinterfaces:
Peripheral

public interface MMIODevice
extends Peripheral

The MMIODevice class provides methods to retrieve memory-mapped registers and memory blocks of a peripheral device.

Each memory-mapped I/O device is identified by a numerical ID and by a name.
An MMIODevice instance can be acquired by a call to MMIOManager.getDevice(int) or MMIOManager.getDevice(java.lang.String).

With memory-mapped I/O, peripheral devices can be controlled by directly reading or writing to memory areas representing the registers or memory blocks of the peripheral device. Each register or memory block is represented by a RawMemory instance. All the mapped registers (including memory blocks) of an MMIO device may be retrieved by a call to #getRegisters(). The RawMemory instance associated to a register has a fixed/determined index in the array returned by #getRegisters(). Each register or memory block is also usually assigned a name which can be used for name-based lookup.

An application can register an MMIOEventListener instance to monitor native events of the designated type fired by the peripheral device. To register a MMIOEventListener instance, the application must call the setMMIOEventListener() method. The registered listener can later on be removed by calling the same method with a null listener parameter. Asynchronous notification may not be supported by all memory-mapped devices. An attempt to set a listener on a memory-mapped device which does not supports it will result in an InvalidOperationException being thrown.

Typical usage example is as follows:

 static final int INTERRUPT = 0;
 
 MMIODevice rtc = MMIOManager.getDevice("RTC"); // HITACHI HD146818 Real Time Clock

 //The RTC device has 14 bytes of clock and control registers and 50 bytes
 // of general purpose RAM (see the data sheet of the HITACHI HD146818 Real Time Clock).
 RawByte seconds = rtc.getByteRegister("Seconds");
 RawByte secAlarm = rtc.getByteRegister("SecAlarm");
 RawByte minutes = rtc.getByteRegister("Minutes");
 RawByte minAlarm = rtc.getByteRegister("MinAlarm");
 RawByte hours = rtc.getByteRegister("Hours");
 RawByte hrAlarm = rtc.getByteRegister("HrAlarm");
 ... // More registers
 RawByte registerA = rtc.getByteRegister("RegisterA");
 RawByte registerB = rtc.getByteRegister("RegisterB");
 RawByte registerC = rtc.getByteRegister("RegisterC");
 RawByte registerD = rtc.getByteRegister("RegisterD");
 RawBlock userRAM = rtc.getBlock("UserRam");

 private class AlarmListener implements MMIOEventListener {
      public void eventDispatched(MMIOEvent event) {
          int i = registerC.get();
          // Check the Alarm Interrupt Flag (AF)
          if ((registerC.get()&0X20) != 0) { 
              // Register C is automatically cleared once read
              ... // Notify application of alarm
          }
      }
 }
 
 // Sets the daily alarm for after some delay
 public void setAlarm(byte delaySeconds, byte delayMinutes, byte delayHours) {
      //Directly read from/write to the registers using RawByte instances.
      byte currentSeconds = seconds.get();
      byte currentMinutes = minutes.get();
      byte currentHours = hours.get();
      int i = (currentSeconds + delaySeconds) % 60;
      int j = (currentSeconds + delaySeconds) / 60;
      seconds.set(i);
      i = (currentMinutes + delayMinutes + j) % 60;
      j = (currentMinutes + delayMinutes + j) / 60;
      minutes.set(i);
      i = (currentHours + delayHours + j) % 24;
      hours.set(i);
 
      rtc.setMMIOEventListener(INTERRUPT, new AlarmListener());
      // Set the Alarm Interrupt Enabled (AIE) flag
      registerB.set((byte) (registerB.get()|0X20)); 
 }
 
When done, an application should call the MMIODevice.close() method to release the MMIO device. Any further attempt to access an MMIO device which has been released will result in a PeripheralNotAvailableException been thrown.

Note that the event types (IDs) supported by a memory-mapped device are device as well as platform specific. Refer to the device data sheet and the platform configuration.

See Also:
MMIOManager, MMIOPermission, PeripheralNotAvailableException

Field Summary
static int BIG_ENDIAN
          Big-endian byte ordering.
static int LITTLE_ENDIAN
          Little-endian byte ordering.
static int MIXED_ENDIAN
          Mixed-endian (non-standard) byte ordering.
 
Method Summary
 RawBlock getBlock(java.lang.String name)
          Gets the designated memory block.
 int getByteOrdering()
          Returns the byte ordering of this memory-mapped peripheral device.
 RawByte getByteRegister(java.lang.String name)
          Gets the designated register holding a byte value.
 RawInt getIntRegister(java.lang.String name)
          Gets the designated register holding a int value.
 RawLong getLongRegister(java.lang.String name)
          Gets the designated register holding a long value.
 RawShort getShortRegister(java.lang.String name)
          Gets the designated register holding a short value.
 void setMMIOEventListener(int eventId, MMIOEventListener listener)
          Registers a MMIOEventListener instance to monitor native events of the designated type fired by the peripheral device mapped to this MMIODevice object.
 
Methods inherited from interface com.oracle.deviceaccess.Peripheral
close, getID, getName
 

Field Detail

LITTLE_ENDIAN

static final int LITTLE_ENDIAN
Little-endian byte ordering.

See Also:
Constant Field Values

BIG_ENDIAN

static final int BIG_ENDIAN
Big-endian byte ordering.

See Also:
Constant Field Values

MIXED_ENDIAN

static final int MIXED_ENDIAN
Mixed-endian (non-standard) byte ordering.

See Also:
Constant Field Values
Method Detail

getByteRegister

RawByte getByteRegister(java.lang.String name)
                        throws PeripheralNotAvailableException
Gets the designated register holding a byte value.

Parameters:
name - name of the register.
Returns:
a RawByte object encapsulating the byte value of the designated register.
Throws:
java.lang.IllegalArgumentException - if the provided name does not correspond to any register or if the type of of the value held in the register does not match.
java.lang.NullPointerException - if name is null.
PeripheralNotAvailableException - if the peripheral is not currently available (has been released).

getShortRegister

RawShort getShortRegister(java.lang.String name)
                          throws PeripheralNotAvailableException
Gets the designated register holding a short value.

Parameters:
name - name of the register.
Returns:
a RawShort object encapsulating the short value of the designated register.
Throws:
java.lang.IllegalArgumentException - if the provided name does not correspond to any register or if the type of of the value held in the register does not match.
java.lang.NullPointerException - if name is null.
PeripheralNotAvailableException - if the peripheral is not currently available (has been released).

getIntRegister

RawInt getIntRegister(java.lang.String name)
                      throws PeripheralNotAvailableException
Gets the designated register holding a int value.

Parameters:
name - name of the register.
Returns:
a RawInt object encapsulating the int value of the designated register.
Throws:
java.lang.IllegalArgumentException - if the provided name does not correspond to any register or if the type of of the value held in the register does not match.
java.lang.NullPointerException - if name is null.
PeripheralNotAvailableException - if the peripheral is not currently available (has been released).

getLongRegister

RawLong getLongRegister(java.lang.String name)
                        throws PeripheralNotAvailableException
Gets the designated register holding a long value.

Parameters:
name - name of the register.
Returns:
a RawLong object encapsulating the long value of the designated register.
Throws:
java.lang.IllegalArgumentException - if the provided name does not correspond to any register or if the type of of the value held in the register does not match.
java.lang.NullPointerException - if name is null.
PeripheralNotAvailableException - if the peripheral is not currently available (has been released).

getBlock

RawBlock getBlock(java.lang.String name)
                  throws PeripheralNotAvailableException
Gets the designated memory block.

Parameters:
name - name of the memory block.
Returns:
a RawBlock object encapsulating the designated memory block.
Throws:
java.lang.IllegalArgumentException - if the provided name does not correspond to any memory block or if the type does not match.
java.lang.NullPointerException - if name is null.
PeripheralNotAvailableException - if the peripheral is not currently available (has been released).

setMMIOEventListener

void setMMIOEventListener(int eventId,
                          MMIOEventListener listener)
                          throws PeripheralNotAvailableException
Registers a MMIOEventListener instance to monitor native events of the designated type fired by the peripheral device mapped to this MMIODevice object. While the listener can be triggered by hardware interrupts, there are no real-time guarantees of when the listener will be called.

If listener is null then listener previously registered for the specified event type will be removed.

Only one listener can be registered at a particular time for a particular event type.

Parameters:
eventId - ID of the native event to listen to.
listener - the MMIOEventListener instance to be notified upon occurrence of the designated event.
Throws:
java.lang.IllegalArgumentException - if eventId does not correspond to any supported event.
InvalidOperationException - if this MMIODevice object does not support asynchronous event notification or if listener is not null and a listener is already registered for the specified event type.
java.lang.NullPointerException - if listener is null.
PeripheralNotAvailableException - if the peripheral is not currently available (has been released).

getByteOrdering

int getByteOrdering()
                    throws PeripheralNotAvailableException
Returns the byte ordering of this memory-mapped peripheral device.

Returns:
BIG_ENDIAN if big-endian; LITTLE_ENDIAN if little-endian; MIXED_ENDIAN otherwise.
Throws:
PeripheralNotAvailableException - if the peripheral is not currently available (has been released).

Oracle Java Wireless Client

Copyright (c) 1990, 2012, Oracle and/or its affiliates. All rights reserved.