Class Csr
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 Summary
FieldsModifier and TypeFieldDescription(package private) int(package private) CsrBitSet(package private) Io(package private) CsrBitSet(package private) JTextField -
Constructor Summary
ConstructorsConstructorDescriptionCsr()Csr(int csrAddress, int csrSize, ArrayList<RegisterDescriptor> descriptors, HashMap<String, RegisterDescriptor> map) Csr(int csrAddress, int csrSize, ArrayList<RegisterDescriptor> descriptors, HashMap<String, RegisterDescriptor> map, File cf) Csr(int csrSize, ArrayList<RegisterDescriptor> descriptors, HashMap<String, RegisterDescriptor> map) Csr(int csrSize, ArrayList<RegisterDescriptor> descriptors, HashMap<String, RegisterDescriptor> map, File cf) Csr(CsrType csr, HashMap<String, RegisterDescriptor> map) Constructer used by CsrAdapter. -
Method Summary
Modifier and TypeMethodDescriptionvoidcache()Initialise the bitset from hardwareReads a register bit-fieldgetAsBitSet(String regName, int newOffset) Returns a register bit-field as a BitSetintGets the register offsetGets the cached CsrBitSetGets the CsrBitSet-encoded read cache.voidload()Loads the hardware from the bitsetstatic voidLaunches a GUI for standalone manipulation of CSRs.Convenience method that makes a GUI panel.Convenience method that makes a GUI panel.<T> voidput(String name, Preferences prefs, T defaultValue) Writes new bit-field value to hardware<T> voidWrites new bit-field value to hardwarevoidWrites the value to all register bit-fields matching a regular expression.readBits()Read from hardware and encode as BitSetvoidSets the I/O hardware interfacestatic Csrstatic CsrMapunmarshalMap(Class context) verify()Verify the hardware settings match the mirrorVerify the hardware settings match the mirror
-
Field Details
-
csrBits
CsrBitSet csrBits -
rdBits
CsrBitSet rdBits -
csrAddress
int csrAddress -
io
Io io -
regNameCB
-
regValueTF
JTextField regValueTF
-
-
Constructor Details
-
Csr
public Csr() -
Csr
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 csrSize, ArrayList<RegisterDescriptor> descriptors, HashMap<String, RegisterDescriptor> map) -
Csr
public Csr(int csrAddress, int csrSize, ArrayList<RegisterDescriptor> descriptors, HashMap<String, RegisterDescriptor> map) -
Csr
public Csr(int csrSize, ArrayList<RegisterDescriptor> descriptors, HashMap<String, RegisterDescriptor> map, File cf) -
Csr
public Csr(int csrAddress, int csrSize, ArrayList<RegisterDescriptor> descriptors, HashMap<String, RegisterDescriptor> map, File cf)
-
-
Method Details
-
unmarshal
-
unmarshalMap
-
getCsrAddress
public int getCsrAddress()Gets the register offset
- Returns:
- The address
-
getCsrBits
-
getRdBits
-
setIo
Sets the I/O hardware interface
- Parameters:
io- The hardware I/O interface
-
cache
Initialise the bitset from hardware
Any existing internally cached CsrBitSet is replaced by this operation.
- Throws:
RegisterIoException- RegisterIo exception
-
readBits
Read from hardware and encode as BitSet
Does not update csrBits.
- Returns:
- A CsrBitSet containing the cached registers settings.
- Throws:
RegisterIoException- RegisterIo exception
-
verify
Verify the hardware settings match the mirror
- Returns:
- String representation of differing bits
-
verify
-
load
Loads the hardware from the bitset
- Throws:
RegisterIoException- RegisterIo exception
-
get
-
getAsBitSet
-
put
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
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
-
makePanel
-
makePanel_noHardware
-
main
Launches a GUI for standalone manipulation of CSRs.
- Parameters:
args- The command line arguments
-