com.cmpware.cmp.mmio
Class MemoryMappedIO

java.lang.Object
  extended by com.cmpware.cmp.mmio.MemoryMappedIO
All Implemented Interfaces:
ReadWriteInterface

public class MemoryMappedIO
extends java.lang.Object
implements ReadWriteInterface

This class implements the memory mapped IO. Here, registers or devices may be mapped to arbitrary addresses outside of the normal memory range.

This class has been changed to support the standard Memory interface, in addition to the send() and recv(). This only impacts the internal use of this class and should not change the way Link models are implemented.

Copyright (c) 2004, 2005 Cmpware, Inc. All Rights Reserved.

Author:
SAG

Field Summary
static java.lang.String copyright
          Copyright string
 
Constructor Summary
MemoryMappedIO()
           
 
Method Summary
 void addInput(int addr, MemoryMappedIOReader mmior)
          This method adds a Memory Mapped IO Reader interface to the memory mapped IO.
 void addOutput(int addr, MemoryMappedIOWriter mmiow)
          This method adds a Memory Mapped IO Writer interface to the memory mapped IO.
static void commit()
          Since all writes should be shadowed in the Memory Mapped IO output ports, they must all be committed at the end of a simulation cycle.
 java.lang.String dumpPorts()
          This method prints status information about the Memory Mapped IO registers.
 MemoryMappedIOReader[] getInputPorts()
          This method returns an array of Memory Mapped IO Readers currently used as input ports.
 MemoryMappedIOWriter[] getOutputPorts()
          This method returns an array of Memory Mapped IO Writers currently used as output ports.
 boolean isReadable(int addr)
          This method returns true if the current address is readable and false otherwise.
 boolean isValidAddress(int addr)
           
 boolean isWriteable(int addr)
          This method returns true if the current address is writeable and false otherwise.
 byte read(int addr)
          This method returns a byte from the memory at address 'addr'.
 short read16(int addr)
          This method returns a 16-bit short from the memory at address 'addr'.
 int read24(int addr)
          This method returns a 24-bit unsigned integer from the memory at address 'addr'.
 int read32(int addr)
          This method returns a 32-bit int from the memory at address 'addr'.
 long read64(int addr)
          This method returns a 64-bit long from the memory at address 'addr'.
 int recv(int addr)
          This method reads the memory mapped IO from a specified address.
 void send(int addr, int val)
          This method writes the memory mapped IO at a specified address.
 void write(int addr, byte data)
          This method copies a byte from 'a' into the memory at address 'addr'.
 void write16(int addr, short a)
          This method writes the 16-bit value 'a' to the requested memory address.
 void write24(int addr, int a)
          This method writes a 24-bit value 'a' to the requested memory address.
 void write32(int addr, int a)
          This method writes the 32-bit value 'a' to the requested memory address.
 void write64(int addr, long a)
          This method writes the 64-bit value 'a' to the requested memory address.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

copyright

public static final java.lang.String copyright
Copyright string

See Also:
Constant Field Values
Constructor Detail

MemoryMappedIO

public MemoryMappedIO()
Method Detail

addInput

public void addInput(int addr,
                     MemoryMappedIOReader mmior)
This method adds a Memory Mapped IO Reader interface to the memory mapped IO. If a Memory Mapped IO Reader already exists at this address, it is replaced.

Parameters:
addr - the address of the Memory Mapped IO Input port.
mmior - The Memory Mapped IO reader.

addOutput

public void addOutput(int addr,
                      MemoryMappedIOWriter mmiow)
This method adds a Memory Mapped IO Writer interface to the memory mapped IO. If a Memory Mapped IO Writer already exists at this address, it is replaced.

Parameters:
addr - the address of the Memory Mapped IO Output port.
mmiow - The Memroy Mapped IO writer.

recv

public int recv(int addr)
         throws MemoryAccessException
This method reads the memory mapped IO from a specified address.

Parameters:
addr - The address to be read.
Returns:
This method returns the memory mapped IO from a specified address.
Throws:
MemoryAccessException - if no shared register exists at this address.

send

public void send(int addr,
                 int val)
          throws MemoryAccessException
This method writes the memory mapped IO at a specified address.

Parameters:
addr - The address to be written.
val - The value to be written.
Throws:
MemoryAccessException - if no shared register exists at this address or if the write is an attempt to overwrite the shared register.

commit

public static void commit()
Since all writes should be shadowed in the Memory Mapped IO output ports, they must all be committed at the end of a simulation cycle. The method takes the lists of Memory Mapped IO ports read and written since the last commit() and committs them. Note this this method is static and will commit *all* memory mapped IO reads and writes from all users of this class.


getInputPorts

public MemoryMappedIOReader[] getInputPorts()
This method returns an array of Memory Mapped IO Readers currently used as input ports.

Returns:
This method returns an array of Memory Mapped IO Readers currently used as input ports.

getOutputPorts

public MemoryMappedIOWriter[] getOutputPorts()
This method returns an array of Memory Mapped IO Writers currently used as output ports.

Returns:
This method returns an array of Memory Mapped IO Writers currently used as output ports.

isValidAddress

public boolean isValidAddress(int addr)

isReadable

public boolean isReadable(int addr)
Description copied from interface: ReadWriteInterface
This method returns true if the current address is readable and false otherwise.

Specified by:
isReadable in interface ReadWriteInterface
Parameters:
addr - the address
Returns:
This method returns true if the current address is readable and false otherwise.

isWriteable

public boolean isWriteable(int addr)
Description copied from interface: ReadWriteInterface
This method returns true if the current address is writeable and false otherwise.

Specified by:
isWriteable in interface ReadWriteInterface
Parameters:
addr - the address
Returns:
This method returns true if the current address is writeable and false otherwise.

read

public byte read(int addr)
          throws MemoryAccessException
Description copied from interface: ReadWriteInterface
This method returns a byte from the memory at address 'addr'.

Specified by:
read in interface ReadWriteInterface
Parameters:
addr - The memory address.
Returns:
The requested data is returned.
Throws:
MemoryAccessException - if an illegal memory address is encountered.

read16

public short read16(int addr)
             throws MemoryAccessException
Description copied from interface: ReadWriteInterface
This method returns a 16-bit short from the memory at address 'addr'.

Specified by:
read16 in interface ReadWriteInterface
Parameters:
addr - The memory address.
Returns:
The requested data is returned from the memory.
Throws:
MemoryAccessException - if an illegal memory address is encountered.

read24

public int read24(int addr)
           throws MemoryAccessException
Description copied from interface: ReadWriteInterface
This method returns a 24-bit unsigned integer from the memory at address 'addr'. The value is returned as a 32-bit int, with the upper 8 bits always zero.

Specified by:
read24 in interface ReadWriteInterface
Parameters:
addr - The memory address.
Returns:
The requested data is returned from the memory.
Throws:
MemoryAccessException - if an illegal memory address is encountered.

read32

public int read32(int addr)
           throws MemoryAccessException
Description copied from interface: ReadWriteInterface
This method returns a 32-bit int from the memory at address 'addr'. Note that this method also attempts a Memory Mapped IO if an illegal memory address is encountered.

Specified by:
read32 in interface ReadWriteInterface
Parameters:
addr - The memory address.
Throws:
MemoryAccessException - if an illegal memory address is encountered.

read64

public long read64(int addr)
            throws MemoryAccessException
Description copied from interface: ReadWriteInterface
This method returns a 64-bit long from the memory at address 'addr'.

Specified by:
read64 in interface ReadWriteInterface
Parameters:
addr - The memory address.
Throws:
MemoryAccessException - if an illegal memory address is encountered.

write

public void write(int addr,
                  byte data)
           throws MemoryAccessException
Description copied from interface: ReadWriteInterface
This method copies a byte from 'a' into the memory at address 'addr'.

Specified by:
write in interface ReadWriteInterface
Parameters:
addr - The memory address.
data - The data to be written to the memory.
Throws:
MemoryAccessException - if an illegal memory address is encountered.

write16

public void write16(int addr,
                    short a)
             throws MemoryAccessException
Description copied from interface: ReadWriteInterface
This method writes the 16-bit value 'a' to the requested memory address.

Specified by:
write16 in interface ReadWriteInterface
Parameters:
addr - The memory address.
a - The value to be written.
Throws:
MemoryAccessException - if an illegal memory address is encountered.

write24

public void write24(int addr,
                    int a)
             throws MemoryAccessException
Description copied from interface: ReadWriteInterface
This method writes a 24-bit value 'a' to the requested memory address. The upper 8 bits of the value of 'a' are always ignored.

Specified by:
write24 in interface ReadWriteInterface
Parameters:
addr - The memory address.
a - The value to be written.
Throws:
MemoryAccessException - if an illegal memory address is encountered.

write32

public void write32(int addr,
                    int a)
             throws MemoryAccessException
Description copied from interface: ReadWriteInterface
This method writes the 32-bit value 'a' to the requested memory address.

Specified by:
write32 in interface ReadWriteInterface
Parameters:
addr - The memory address.
a - The value to be written.
Throws:
MemoryAccessException - if an illegal memory address is encountered.

write64

public void write64(int addr,
                    long a)
             throws MemoryAccessException
Description copied from interface: ReadWriteInterface
This method writes the 64-bit value 'a' to the requested memory address.

Specified by:
write64 in interface ReadWriteInterface
Parameters:
addr - The memory address.
a - The value to be written.
Throws:
MemoryAccessException - if an illegal memory address is encountered.

dumpPorts

public java.lang.String dumpPorts()
This method prints status information about the Memory Mapped IO registers.