8.8.1.1.2.2.12. Registers¶
- class Registers¶
- getRegisterGroups(groupId) RegistersGroupsResult¶
Returns the registers and groups under the specified group.
# Reads the top level groups topLevel = session.registers.getRegisterGroups() # Reads the registers and subgroups of group "adc0" adc0 = session.registers.getRegisterGroups("adc0") groups, registers = adc0['groups'], adc0['registers'] # One can build an object representing the whole register tree recursively calling this # The 'root' parameter is the id of top level group to start from def queryRegisterTree(session, root): children = session.registers.getRegisterGroups(root) groups = { grp['name']: queryRegisterTree(session, grp['id']) for grp in children['groups'] } regs = { reg['name']: reg for reg in children['registers'] } return { 'groups': groups, 'registers': regs } registerTree = queryRegisterTree(session, 'adc0')
- Parameters:
groupId (str | None) -- The id of the group to fetch the subgroups of. If unset or is ""(empty string), fetch the root groups.
- Returns:
Two lists of registers and groups under the specified group, or a list of the top level groups and empty list if groupId is blank.
- Return type:
- getBitfields(registerId) list[RegisterBitfield]¶
Returns the bitfields under a register.
# get the bitfields of the register 'adc0_ADC0_SCOMP1' scopm1 = session.registers.getBitfields('adc0_ADC0_SCOMP1') print(f"id: {scopm1['id']}") print(f"name: {scopm1['name']}") print(f"start: {scopm1['start']}") print(f"end: {scopm1['end']}") print(f"readable: {scopm1['readable']}") print(f"writable: {scopm1['writable']}")
- Parameters:
registerId (str) -- The id of the register who's bitfields will be fetched.
- Returns:
A list of the bitfields, each entry containing the id, name, start and end of the bitfield, and whether it is readable/writable.
- Return type:
list[
RegisterBitfield]
- read(registerName) int | str¶
Reads the specified register.
# Reads the PC register value = session.registers.read("PC")
- Parameters:
registerName (str) -- The name of the register to be read.
- Returns:
The value of the register.
- Return type:
int | str
- write(registerName, value) None¶
Write to the specified register.
# Writes 0x12345 to the PC register session.registers.write("PC", 0x12345) # Writes -1 to the R0 register session.registers.write("R0", -1)
- Parameters:
registerName (str) -- The name of the register to be written to.
value (int | str) -- The value to be written to the register. Can be a bigint, or an integer represented as a string, or a javascript number.
- Return type:
None
- exportAsJson(groupIds, filePath, style=None) None¶
Recursively reads all the register under the specified group and returns the data in a tree structure.
# Export the core registers and the group "adc0" to "/user/dump.json" session.registers.exportAsJson(["Core Registers", "adc0"], "/user/dump.json") # Export the core registers to "/user/dump.json" in one line session.registers.exportAsJson("Core Registers", "/user/dump.json", False) # equivalently session.registers.exportAsJson([""], "/user/dump.json") # Export all the registers to "/user/dump.json" in styled format session.registers.exportAsJson("", "/user/dump.json", True)
- Parameters:
groupIds (list[str]) -- The ids of the groups to read registers from. Can be a single id, or an array of ids. Use ""(empty string) to read all the groups.
filePath (str) -- The full path of the file to write the data to.
style (bool) -- (optional) If true, write the data string in a tree structure. If false, write the data string in one line. Default is false.
- Return type:
None
- importFromJson(filePath) None¶
Recursively writes all the register under the specified group from a file.
# Import from "/user/dump.json" session.registers.importFromJson("/user/dump.json")
- Parameters:
filePath (str) -- The full path of the file to write the data to.
- Return type:
None