Class Csr


public class Csr extends Object

Bit-oriented register descriptor collection

Hardware interfaces are typically manipulated through a set of addressable byte-oriented registers. This class is intended to simplify bit-oriented access to such registers. It encapsulates a collection of descriptors for fields containing consecutive bits. Each field is assigned a key, a bit offset from the start of the register array and the length of consecutive bits belonging to the field. The descriptors and a HashMap of the registers keyed by name that are passed to the constructor are expected to have been populated by a class that represents a specific hardware device.

Internally, the class maintains a copy of the current register settings as a CsrBitSet. Accessing the hardware is achieved through the put() and get() methods using the RegisterIo interface.

Several of the methods are generic. Where the generic vaue represents a bit-field value, the types Integer, Boolean or String are allowed. All others result in the method throwing a RuntimeException.

See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • unmarshal

      public static Csr unmarshal(String xml)
    • unmarshalMap

      public static CsrMap unmarshalMap(Class context)
    • getCsrAddress

      public int getCsrAddress()

      Gets the register offset

      Returns:
      The address
    • getCsrBits

      public CsrBitSet getCsrBits()

      Gets the cached CsrBitSet

      Returns:
      The CsrBitSet
    • getRdBits

      public CsrBitSet getRdBits()

      Gets the CsrBitSet-encoded read cache.

      Returns:
      The CsrBitSet
    • setIo

      public void setIo(Io io)

      Sets the I/O hardware interface

      Parameters:
      io - The hardware I/O interface
    • cache

      public void cache() throws RegisterIoException

      Initialise the bitset from hardware

      Any existing internally cached CsrBitSet is replaced by this operation.

      Throws:
      RegisterIoException - RegisterIo exception
    • readBits

      public CsrBitSet readBits() throws RegisterIoException

      Read from hardware and encode as BitSet

      Does not update csrBits.

      Returns:
      A CsrBitSet containing the cached registers settings.
      Throws:
      RegisterIoException - RegisterIo exception
    • verify

      public BitSet verify()

      Verify the hardware settings match the mirror

      Returns:
      String representation of differing bits
    • verify

      public BitSet verify(BitSet bs)

      Verify the hardware settings match the mirror

      Parameters:
      bs - Bitset to use in comparing with CsrBits.
      Returns:
      String representation of differing bits
    • load

      public void load() throws RegisterIoException

      Loads the hardware from the bitset

      Throws:
      RegisterIoException - RegisterIo exception
    • get

      public String get(String regName)

      Reads a register bit-field

      Parameters:
      regName - The register bit-field key
      Returns:
      Hex encoded String register value
    • getAsBitSet

      public BitSet getAsBitSet(String regName, int newOffset)

      Returns a register bit-field as a BitSet

      Parameters:
      regName - The register bit-field key
      newOffset - A positive offset to apply to the returned bits.
      Returns:
      BitSet containing the register bits.
    • put

      public <T> void put(String name, T val) throws RegisterIoException

      Writes new bit-field value to hardware

      Updates the internal CsrBitSet and writes to the hardware

      Type Parameters:
      T - The type of the value to write
      Parameters:
      name - The bit-field key
      val - The value to write into the bit-field
      Throws:
      RegisterIoException - RegisterIo exception
    • put

      public <T> void put(String name, Preferences prefs, T defaultValue) throws RegisterIoException

      Writes new bit-field value to hardware

      Updates the internal CsrBitSet and writes to the hardware. Gets the value from Preferences node and applies default value if Preference not found.

      Type Parameters:
      T - The type of the value to write
      Parameters:
      name - The bit-field key
      prefs - The Preferences node
      defaultValue - The default value of the bit-field
      Throws:
      RegisterIoException - RegisterIo exception
    • putRegex

      public void putRegex(String key, String val)

      Writes the value to all register bit-fields matching a regular expression.

      Parameters:
      key - The register bit-field key name regular expression.
      val - The value to write.
    • makePanel

      public JPanel makePanel()

      Convenience method that makes a GUI panel.

      Returns:
      The panel.
    • makePanel_noHardware

      public JPanel makePanel_noHardware()

      Convenience method that makes a GUI panel.

      Returns:
      The panel.
    • main

      public static void main(String[] args)

      Launches a GUI for standalone manipulation of CSRs.

      Parameters:
      args - The command line arguments