Class Csr
- java.lang.Object
-
- cbsw.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
-
-
Field Summary
Fields Modifier and Type Field Description (package private) int
baseAddress
(package private) CsrBitSet
csrBits
(package private) Io
io
(package private) CsrBitSet
rdBits
(package private) javax.swing.JComboBox<java.lang.String>
regNameCB
(package private) javax.swing.JTextField
regValueTF
-
Constructor Summary
Constructors Constructor Description Csr()
Csr(int baseAddress, int csrSize, java.util.ArrayList<RegisterDescriptor> descriptors, java.util.HashMap<java.lang.String,RegisterDescriptor> map)
Csr(int baseAddress, int csrSize, java.util.ArrayList<RegisterDescriptor> descriptors, java.util.HashMap<java.lang.String,RegisterDescriptor> map, java.io.File cf)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cache()
Initialise the bitset from hardwarevoid
cache(RegisterIo io)
Initialise the bitset from hardwarejava.lang.String
get(java.lang.String regName)
Reads a register bit-fieldint
getBaseAddress()
Gets the register base addressCsrBitSet
getCsrBits()
Gets the cached CsrBitSetCsrBitSet
getRdBits()
Gets the CsrBitSet-encoded read cache.void
load()
Loads the hardware from the bitsetjavax.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 hardwarevoid
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 BitSetvoid
setIo(Io io)
Sets the I/O hardware interfacestatic Csr
unmarshal(java.lang.String xml)
java.util.BitSet
verify()
Verify the hardware settings match the mirror
-
-
-
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)
-
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
-
load
public void load() throws RegisterIoException
Loads the hardware from the bitset
- 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 keyio
- 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 keyval
- 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 keyprefs
- The Preferences nodedefaultValue
- 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.
-
-