Class CsrBitSet
- All Implemented Interfaces:
Serializable, Cloneable
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. Internally, the class maintains a copy of the current register settings as a BitSet. Application code can manipulate the contents of the cache using get() and set() methods. Writing the hardware is achieved through the put() methods using the RegisterIo interface.
The class unmarshalls the collection of bitfields from an XML file. An example bit-field descriptor might appear like this in the XML:
<register name="gt.0.precursor" offset="536" length="5">GT TX precursor value</register>
The name attribute is used as the HashMap key.
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.
To support triplicated registers (such as used by the GBTX ASIC), the offset attribute may be a comma-separated list of (usually 3) offsets. The bit-field values are replicated to each offset in the list.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) int(package private) ArrayList<RegisterDescriptor> (package private) HashMap<String, RegisterDescriptor> (package private) BitSet -
Constructor Summary
ConstructorsConstructorDescriptionCsrBitSet(int csrSize, ArrayList<RegisterDescriptor> descriptors, HashMap<String, RegisterDescriptor> map) CsrBitSet(int csrSize, ArrayList<RegisterDescriptor> descriptors, HashMap<String, RegisterDescriptor> map, File cf) -
Method Summary
Modifier and TypeMethodDescriptionclone()voiddecode()Displays the values of all bit-fields on System.outvoidDisplays the values of all bit-fields on System.outGets hex string representation of bit-fieldGets hex string representation of bit-fieldGets hex string representation of bit-fieldbyte[]Deprecated.intReturns the CSR sizeReturns the bit-field descriptor listgetMap()Returns the descriptor map(package private) static StringgetPrefsValue(String key, Preferences prefs, Object defaultValue) Converts a value from a Preference into String representationReturns the RegisterDescriptor for the given keyvoidvoidsaveToBinaryFile(File file) voidset(byte[] buf) Initialises the CsrBitSet from a byte arrayvoidInitialises the CsrBitSet from binary filevoidInitialises the CsrBitSet from a binary file.voidset(FileReader fr) Read the register settings from file and update CsrBitSet.<T> voidset(String key, Preferences prefs, T defaultValue) Sets the register bits from value stored in Java Preference<T> voidSets bit-fieldvoidWrites the value to all register bit-fields matching a regular expression.Get a stream of registers whose name matches the supplied regexGet a stream of registers whose name matches the supplied regex and content matches the supplied value.streamComplement(String regex, String value) Get a stream of registers whose name matches the supplied regex and content does not match the supplied value.Returns a Collection stream.byte[]toByteArray(int arrayOffset) Returns a new byte array containing the register valuesstatic StringConverts value into String representationMethods inherited from class BitSet
and, andNot, cardinality, clear, clear, clear, equals, flip, flip, get, get, hashCode, intersects, isEmpty, length, nextClearBit, nextSetBit, or, previousClearBit, previousSetBit, set, set, set, set, size, stream, toByteArray, toLongArray, toString, valueOf, valueOf, valueOf, valueOf, xor
-
Field Details
-
csrSize
int csrSize -
descriptors
ArrayList<RegisterDescriptor> descriptors -
map
HashMap<String, RegisterDescriptor> map -
roBits
BitSet roBits
-
-
Constructor Details
-
CsrBitSet
public CsrBitSet(int csrSize, ArrayList<RegisterDescriptor> descriptors, HashMap<String, RegisterDescriptor> map) -
CsrBitSet
public CsrBitSet(int csrSize, ArrayList<RegisterDescriptor> descriptors, HashMap<String, RegisterDescriptor> map, File cf)
-
-
Method Details
-
clone
-
getRoBits
-
getCsrSize
public int getCsrSize()Returns the CSR size
- Returns:
- The size
-
getDescriptors
Returns the bit-field descriptor list
- Returns:
- The list
-
getMap
-
streamRegisterDescriptors
Returns a Collection stream.
- Returns:
- The stream
-
get
-
get
Gets hex string representation of bit-field
This variant allows a bit-field to be retrieved from a BitSet that is not necessarily the internally cached version.
- Parameters:
key- The bit-field keybits- A BitSet containing the register values- Returns:
- String containg hex representation of bit-field
-
get
Gets hex string representation of bit-field
This variant allows a bit-field to be retrieved from a byte array that is assumed to have the same shape as the register array described by this CsrBitSet.
- Parameters:
key- The bit-field keyregs- A byte array containing the register values- Returns:
- String containg hex representation of bit-field
-
set
Initialises the CsrBitSet from binary file
The BitSet cache is initialised from the binary data. The previous content, is discarded.
- Parameters:
cf- A File containing the binary data
-
set
Initialises the CsrBitSet from a binary file.
- Parameters:
cf- The configuration file.skip- The number of csrSize blocks in the file to skip
-
set
Read the register settings from file and update CsrBitSet.
- Parameters:
fr- The FileReader from where the values will be read
-
saveToBinaryFile
-
saveToBinaryFile
public void saveToBinaryFile() -
set
public void set(byte[] buf) Initialises the CsrBitSet from a byte array
The BitSet cache is initialised from the binary data. The previous content, is discarded.
- Parameters:
buf- A byte array
-
valueOf
-
getPrefsValue
Converts a value from a Preference into String representation
Types String, Integer and Boolean are allowed. Throws a RuntimeException for any other type.
- Parameters:
key- The key in the Preferences nodeprefs- The Preferences nodedefaultValue- The default value if the Preference does not exist- Returns:
- The hex String representation
-
set
Sets bit-field
- Type Parameters:
T- Type of the value to set- Parameters:
key- The bit-field keyvalue- The value to set
-
set
Sets the register bits from value stored in Java Preference
This is a convenience method for when the bit-field should be set according to a value stored as a Java Preference.
key is both the XML key and the preference key name
The default value is applied if no Preference is found.
- Type Parameters:
T- Type of the value to set- Parameters:
key- The bit-field keyprefs- The Preferences nodedefaultValue- Default value
-
setRegex
-
stream
Get a stream of registers whose name matches the supplied regex
- Parameters:
regex- The pattern to match with the bit-field key- Returns:
- The stream
-
stream
Get a stream of registers whose name matches the supplied regex and content matches the supplied value.
- Parameters:
regex- The pattern to match with the bit-field keyvalue- The value to match with the bit-field content- Returns:
- The stream
-
streamComplement
Get a stream of registers whose name matches the supplied regex and content does not match the supplied value.
- Parameters:
regex- The pattern to match with the bit-field keyvalue- The value to match with the bit-field content- Returns:
- The stream
-
toByteArray
public byte[] toByteArray(int arrayOffset) Returns a new byte array containing the register values
The method creates an array of bytes containing the cached register values starting arrayOffset bytes from the start of the register array.
- Parameters:
arrayOffset- Offset from register array start- Returns:
- The register values
-
getRegisterDescriptor
Returns the RegisterDescriptor for the given key
- Parameters:
key- The bit-field key- Returns:
- The register descriptor
-
getBytes
Deprecated.Returns a new byte array containing the value of the specified bit-field
The method creates an array of bytes containing the cached bit-field value. The value is offset arrayOffset bytes from the start of the returned array.
- Parameters:
key- The bit-field keyarrayOffset- Offset from register array start- Returns:
- The register values
-
decode
public void decode()Displays the values of all bit-fields on System.out
-
decode
Displays the values of all bit-fields on System.out
- Parameters:
bits- The CSR bits.
-