Class Csr
- java.lang.Object
-
- cbsw.Csr
-
public class Csr extends java.lang.ObjectBit-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) intbaseAddress(package private) intcsrAddress(package private) CsrBitSetcsrBits(package private) Ioio(package private) CsrBitSetrdBits(package private) javax.swing.JComboBox<java.lang.String>regNameCB(package private) javax.swing.JTextFieldregValueTF
-
Constructor Summary
Constructors Constructor Description Csr()Csr(int baseAddress, int csrAddress, int csrSize, java.util.ArrayList<RegisterDescriptor> descriptors, java.util.HashMap<java.lang.String,RegisterDescriptor> map)Csr(int baseAddress, int csrAddress, int csrSize, java.util.ArrayList<RegisterDescriptor> descriptors, java.util.HashMap<java.lang.String,RegisterDescriptor> map, java.io.File cf)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)Csr(CsrType csr, java.util.HashMap<java.lang.String,RegisterDescriptor> map)Constructer used by CsrAdapter.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcache()Initialise the bitset from hardwarejava.lang.Stringget(java.lang.String regName)Reads a register bit-fieldintgetBaseAddress()Gets the register base addressintgetCsrAddress()Gets the register offsetCsrBitSetgetCsrBits()Gets the cached CsrBitSetCsrBitSetgetRdBits()Gets the CsrBitSet-encoded read cache.voidload()Loads the hardware from the bitsetjavax.swing.JPanelmakePanel()Convenience method that makes a GUI panel.voidput(java.lang.String name, RegisterIo io)Writes bytes corresponding to bit-field to hardware<T> voidput(java.lang.String name, java.util.prefs.Preferences prefs, T defaultValue)Writes new bit-field value to hardware<T> voidput(java.lang.String name, T val)Writes new bit-field value to hardwarevoidputRegex(java.lang.String key, java.lang.String val)Writes the value to all register bit-fields matching a regular expression.CsrBitSetreadBits()Read from hardware and encode as BitSetvoidsetIo(Io io)Sets the I/O hardware interfacestatic Csrunmarshal(java.lang.String xml)static CsrMapunmarshalMap(java.lang.Class context)java.util.BitSetverify()Verify the hardware settings match the mirror
-
-
-
Constructor Detail
-
Csr
public Csr()
-
Csr
public Csr(CsrType csr, java.util.HashMap<java.lang.String,RegisterDescriptor> map)
Constructer used by CsrAdapter.
- Parameters:
csr- Descriptor containing parameters required by constructor.map- HashMap of the register discriptors hashed by name.
-
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 csrAddress, 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)
-
Csr
public Csr(int baseAddress, int csrAddress, 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)
-
unmarshalMap
public static CsrMap unmarshalMap(java.lang.Class context)
-
getBaseAddress
public int getBaseAddress()
Gets the register base address
- Returns:
- The address
-
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 RegisterIoExceptionInitialise 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 java.util.BitSet verify()
Verify the hardware settings match the mirror
- Returns:
- String representation of differing bits
-
load
public void load() throws RegisterIoExceptionLoads the hardware from the bitset
- 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 RegisterIoExceptionWrites 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 RegisterIoExceptionWrites 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 RegisterIoExceptionWrites 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.
-
-