Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## avrora.sim
Class Segment

    java.lang.Object
      avrora.sim.Segment

Direct Known Subclasses:
  CodeSegment

public class Segment
extends java.lang.Object

The `Segment` class represents a segment of byte-addressable memory that supports probing. It is used to represent the SRAM, the flash, and the EEPROM. For efficiency, it sharing of the underlying byte array representing the memory.

Nested Class Summary
`class` | `Segment.AddressOutOfBoundsException` The `AddressOutOfBoundsException` class represents an error when using the `get()` and `set()` methods where the user specifies an address that is out of the bounds of the segment.
`static interface` | `Segment.ErrorReporter` The `ErrorReporter` class is used to intercept errors caused by trying to either read or write outside the bounds of this segment.
`static interface` | `Segment.Sharer` The `Sharer` interface must be implemented by a class that needs to share the underlying data representation for efficiency reasons.

Field Summary
`protected Segment.ErrorReporter` | `errorReporter`
`protected BaseInterpreter` | `interpreter`
`protected java.lang.String` | `name`
`protected byte[]` | `segment_data`
`protected MulticastWatch[]` | `segment_watches`
`protected Segment.Sharer` | `sharer`
`protected int` | `size`
`protected byte` | `value`

Constructor Summary
`Segment(java.lang.String name, int size, byte defvalue, BaseInterpreter bi, Segment.ErrorReporter er)` The constructor for the `Segment` class creates an object that represents this segment.

Method Summary
`byte` | `get(int address)` The `get()` method simply retrieves the value of a byte at a particular location in the segment.
`void` | `insertWatch(int data_addr, Simulator.Watch p)` The `insertWatch()` allows user code to insert a watch on a particular memory location.
`byte` | `read(int address)` The `read()` method of the segment reads a byte from a location in the segment, firing any watches on the address before and after the read.
`void` | `removeWatch(int data_addr, Simulator.Watch p)` The `removeWatch()` removes a watch on a particular memory location.
`void` | `set(int address, byte val)` The `set()` method simply sets the value of a byte at a particular location in the segment.
`byte[]` | `share(Segment.Sharer s)` The `share()` method allows sharing of the underlying array representing the values of memory.
`void` | `write(int address, byte val)` The `write()` method of the segment writes a byte to a location in the segment, firing any watches on the address before and after the write.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### interpreter

    protected final BaseInterpreter interpreter

### name

    protected final java.lang.String name

### size

    protected final int size

### value

    protected final byte value

### segment_data

    protected byte[] segment_data

### errorReporter

    protected final Segment.ErrorReporter errorReporter

### segment_watches

    protected MulticastWatch[] segment_watches

### sharer

    protected Segment.Sharer sharer

Constructor Detail

### Segment

    public Segment(java.lang.String name,
                   int size,
                   byte defvalue,
                   BaseInterpreter bi,
                   Segment.ErrorReporter er)

  The constructor for the `Segment` class creates an object that represents this segment. The segment is byte-addressable and allows watches to be placed on individual bytes in memory.

Parameters:
  `name` - the name of the segment as a string
  `size` - the size of the segment in bytes
  `defvalue` - the default value of bytes in this segment
  `er` - an object that is notified when an attempt is made to read or write outside of the bounds of this segment

Method Detail

### share

    public byte[] share(Segment.Sharer s)

  The `share()` method allows sharing of the underlying array representing the values of memory. This is used for performance.

  Parameters:
    `s` - the sharer to allow access to this segment's internal data
  Returns:
    the byte array that is the underlying representation of the memory

### read

    public byte read(int address)

  The `read()` method of the segment reads a byte from a location in the segment, firing any watches on the address before and after the read. This is intended to be called ONLY by the interpreter and device implementations, and NOT by other parts of the simulation that simply want to inspect the state of simulation. A call to the `read()` method will result in a call to the `readError()` method of the `ErrorReporter` object associated with this segment if the access is not within the bounds of the segment.

  Parameters:
    `address` - the address in the segment from which to read the byte
  Returns:
    the byte value at this location

### get

    public byte get(int address)

  The `get()` method simply retrieves the value of a byte at a particular location in the segment. This method will NOT result in triggering any watches installed for this address. This method is intended for use by user code outside of the simulation (such as probes and watches) to inspect the values in this segment.

  Parameters:
    `address` - the address in the segment for which to retrieve the value
  Returns:
    the value of the byte at the specified location, without triggering any monitors on this location
  Throws:
    `Segment.AddressOutOfBoundsException` - if the specified address is not within the bounds of this segment

### write

    public void write(int address,
                      byte val)

  The `write()` method of the segment writes a byte to a location in the segment, firing any watches on the address before and after the write. This is intended to be called ONLY by the interpreter and device implementations, and NOT by other parts of the simulation that want to alter the state of the simulation. A call to the `write()` method will result in a call to the `writeError()` method of the `ErrorReporter` object associated with this segment if the access is not within the bounds of the segment.

  Parameters:
    `address` - the address in the segment which should be written
    `val` - the value to write to the location in the segment

### set

    public void set(int address,
                    byte val)

  The `set()` method simply sets the value of a byte at a particular location in the segment. This method will NOT result in triggering any watches installed for this address. This method is intended for use by code outside of the simulation (such as probes and watches) to alter the state of the memory segment, which should not be done by user code.

  Parameters:
    `address` - the address in the segment which should be written
    `val` - the value to write to this byte in memory
  Throws:
    `Segment.AddressOutOfBoundsException` - if the specified address is not within the bounds of this segment

### insertWatch

    public void insertWatch(int data_addr,
                            Simulator.Watch p)

  The `insertWatch()` allows user code to insert a watch on a particular memory location. The watch will be triggered when a `read()` or `write()` to the memory location occurs in during simulation.

  Parameters:
    `data_addr` - the address of the byte in memory for which to insert the watch
    `p` - the watch to insert on the memory byte

### removeWatch

    public void removeWatch(int data_addr,
                            Simulator.Watch p)

  The `removeWatch()` removes a watch on a particular memory location. The watch will no longer be triggered for subseqent `read()`s or `write()`s occur in during simulation. Reference equality is used to match watches, and NOT `Object.equals()`.

  Parameters:
    `data_addr` - the address of the byte in memory for which to remove the watch
    `p` - the watch to remove

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD