Package cbsw

Class Csr


  • public class Csr
    extends java.lang.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:
    RegisterDescriptor, RegisterIo, CsrBitSet
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void cache()
      Initialise the bitset from hardware
      void cache​(RegisterIo io)
      Initialise the bitset from hardware
      java.lang.String get​(java.lang.String regName)
      Reads a register bit-field
      int getBaseAddress()
      Gets the register base address
      CsrBitSet getCsrBits()
      Gets the cached CsrBitSet
      CsrBitSet getRdBits()
      Gets the CsrBitSet-encoded read cache.
      void load()
      Loads the hardware from the bitset
      javax.swing.JPanel makePanel()
      Convenience method that makes a GUI panel.
      void put​(java.lang.String name, RegisterIo io)
      Writes bytes corresponding to bit-field to hardware
      <T> void put​(java.lang.String name, java.util.prefs.Preferences prefs, T defaultValue)
      Writes new bit-field value to hardware
      <T> void put​(java.lang.String name, T val)
      Writes new bit-field value to hardware
      void putRegex​(java.lang.String key, java.lang.String val)
      Writes the value to all register bit-fields matching a regular expression.
      void readBits()
      Read from hardware and encode as BitSet
      void setIo​(Io io)
      Sets the I/O hardware interface
      static Csr unmarshal​(java.lang.String xml)  
      java.util.BitSet verify()
      Verify the hardware settings match the mirror
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • baseAddress

        int baseAddress
      • io

        Io io
      • regNameCB

        javax.swing.JComboBox<java.lang.String> regNameCB
      • regValueTF

        javax.swing.JTextField regValueTF
    • Constructor Detail

      • Csr

        public Csr()
      • Csr

        public Csr​(int baseAddress,
                   int csrSize,
                   java.util.ArrayList<RegisterDescriptor> descriptors,
                   java.util.HashMap<java.lang.String,​RegisterDescriptor> map,
                   java.io.File cf)
    • Method Detail

      • unmarshal

        public static Csr unmarshal​(java.lang.String xml)
      • getBaseAddress

        public int getBaseAddress()

        Gets the register base address

        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 void readBits()

        Read from hardware and encode as BitSet

        Does not update csrBits.

        Throws:
        RegisterIoException - RegisterIo exception
      • verify

        public java.util.BitSet verify()

        Verify the hardware settings match the mirror

        Returns:
        String representation of differing bits
        Throws:
        RegisterIoException - RegisterIo exception
      • cache

        public void cache​(RegisterIo io)
                   throws RegisterIoException

        Initialise the bitset from hardware

        Any existing internally cached CsrBitSet is replaced by this operation.

        Parameters:
        io - The hardware I/O interface
        Throws:
        RegisterIoException - RegisterIo exception
      • get

        public java.lang.String get​(java.lang.String regName)

        Reads a register bit-field

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

        public void put​(java.lang.String name,
                        RegisterIo io)
                 throws RegisterIoException

        Writes bytes corresponding to bit-field to hardware

        Parameters:
        name - The bit-field key
        io - The hardware I/O interface
        Throws:
        RegisterIoException - RegisterIo exception
      • put

        public <T> void put​(java.lang.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​(java.lang.String name,
                            java.util.prefs.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​(java.lang.String key,
                             java.lang.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 javax.swing.JPanel makePanel()

        Convenience method that makes a GUI panel.

        Returns:
        The panel.