USRP Hardware Driver and USRP Manual  Version: 4.0.0.0-172-g5802a362f
UHD and USRP Manual
uhd::rfnoc::mock_reg_iface_t Class Reference

#include <uhd/rfnoc/mock_block.hpp>

Inheritance diagram for uhd::rfnoc::mock_reg_iface_t:
uhd::rfnoc::register_iface

Public Member Functions

 mock_reg_iface_t ()=default
 
virtual ~mock_reg_iface_t ()=default
 
void poke32 (uint32_t addr, uint32_t data, uhd::time_spec_t time, bool ack)
 
void multi_poke32 (const std::vector< uint32_t > addrs, const std::vector< uint32_t > data, uhd::time_spec_t time, bool ack)
 
void block_poke32 (uint32_t first_addr, const std::vector< uint32_t > data, uhd::time_spec_t timestamp, bool ack)
 
uint32_t peek32 (uint32_t addr, uhd::time_spec_t time)
 
std::vector< uint32_t > block_peek32 (uint32_t first_addr, size_t length, uhd::time_spec_t time)
 
void poll32 (uint32_t addr, uint32_t data, uint32_t mask, uhd::time_spec_t, uhd::time_spec_t time=uhd::time_spec_t::ASAP, bool=false)
 
void sleep (uhd::time_spec_t, bool)
 
void register_async_msg_validator (async_msg_validator_t)
 
void register_async_msg_handler (async_msg_callback_t)
 
void set_policy (const std::string &name, const uhd::device_addr_t &args)
 
uint16_t get_src_epid () const
 
uint16_t get_port_num () const
 
- Public Member Functions inherited from uhd::rfnoc::register_iface
virtual ~register_iface ()=default
 
void poke64 (uint32_t addr, uint64_t data, time_spec_t time=uhd::time_spec_t::ASAP, bool ack=false)
 
uint64_t peek64 (uint32_t addr, time_spec_t time=uhd::time_spec_t::ASAP)
 

Public Attributes

bool force_timeout = false
 
std::unordered_map< uint32_t, uint32_t > read_memory
 All pokes end up writing to this map. More...
 
std::unordered_map< uint32_t, uint32_t > write_memory
 All peeks read from this map. A peek will fail if the address has not. More...
 

Protected Member Functions

virtual void _poke_cb (uint32_t, uint32_t, uhd::time_spec_t, bool)
 
virtual void _peek_cb (uint32_t, uhd::time_spec_t)
 

Additional Inherited Members

- Public Types inherited from uhd::rfnoc::register_iface
using sptr = std::shared_ptr< register_iface >
 
using async_msg_validator_t = std::function< bool(uint32_t addr, const std::vector< uint32_t > &data)>
 
using async_msg_callback_t = std::function< void(uint32_t addr, const std::vector< uint32_t > &data, boost::optional< uint64_t >)>
 

Detailed Description

Mock version of a register interface

This can be used for mock blocks, usually for the sake of unit testing.

Constructor & Destructor Documentation

◆ mock_reg_iface_t()

uhd::rfnoc::mock_reg_iface_t::mock_reg_iface_t ( )
default

◆ ~mock_reg_iface_t()

virtual uhd::rfnoc::mock_reg_iface_t::~mock_reg_iface_t ( )
virtualdefault

Member Function Documentation

◆ _peek_cb()

virtual void uhd::rfnoc::mock_reg_iface_t::_peek_cb ( uint32_t  ,
uhd::time_spec_t   
)
inlineprotectedvirtual

◆ _poke_cb()

virtual void uhd::rfnoc::mock_reg_iface_t::_poke_cb ( uint32_t  ,
uint32_t  ,
uhd::time_spec_t  ,
bool   
)
inlineprotectedvirtual

◆ block_peek32()

std::vector<uint32_t> uhd::rfnoc::mock_reg_iface_t::block_peek32 ( uint32_t  first_addr,
size_t  length,
uhd::time_spec_t  time 
)
inlinevirtual

Read multiple 32-bit consecutive registers implemented in the NoC block.

Parameters
first_addrThe byte address of the first register to read from (truncated to 20 bits).
lengthThe number of 32-bit values to read
timeThe time at which the transaction should be executed.
Returns
data New value of this register.

Example: If first_addr is set to 0, and length is 8, then this function will return a vector of length 8, with the content of registers at addresses 0, 4, 8, 12, 16, 20, 24, and 28 respectively.

Note: There is no guarantee that under the hood, the implementation won't separate the reads.

Exceptions
op_failedif the transaction fails
op_timeoutif no response is received
op_seqerrif a sequence error occurs

Implements uhd::rfnoc::register_iface.

◆ block_poke32()

void uhd::rfnoc::mock_reg_iface_t::block_poke32 ( uint32_t  first_addr,
const std::vector< uint32_t >  data,
uhd::time_spec_t  time,
bool  ack 
)
inlinevirtual

Write multiple consecutive 32-bit registers implemented in the NoC block.

This function will only allow writes to adjacent registers, in increasing order. If addr is set to 0, and the length of data is 8, then this method triggers eight writes, in order, to addresses 0, 4, 8, 12, 16, 20, 24, 28. For arbitrary addresses, cf. multi_poke32().

Note: There is no guarantee that under the hood, the implementation won't separate the writes.

Parameters
first_addrThe byte addresses of the first register to write
dataNew values of these registers
timeThe time at which the first transaction should be executed.
ackShould transaction completion be acknowledged?
Exceptions
op_failedif an ACK is requested and the transaction fails
op_timeoutif an ACK is requested and no response is received
op_seqerrif an ACK is requested and a sequence error occurs
op_timeerrif an ACK is requested and a time error occurs (late command)

Implements uhd::rfnoc::register_iface.

◆ get_port_num()

uint16_t uhd::rfnoc::mock_reg_iface_t::get_port_num ( ) const
inlinevirtual

Get the port number of the software counterpart of this register interface. This information is useful to send async messages to the host.

Returns
The 10-bit port number

Implements uhd::rfnoc::register_iface.

◆ get_src_epid()

uint16_t uhd::rfnoc::mock_reg_iface_t::get_src_epid ( ) const
inlinevirtual

Get the endpoint ID of the software counterpart of this register interface. This information is useful to send async messages to the host.

Returns
The 16-bit endpoint ID

Implements uhd::rfnoc::register_iface.

◆ multi_poke32()

void uhd::rfnoc::mock_reg_iface_t::multi_poke32 ( const std::vector< uint32_t >  addrs,
const std::vector< uint32_t >  data,
uhd::time_spec_t  time,
bool  ack 
)
inlinevirtual

Write multiple 32-bit registers implemented in the NoC block.

This method should be called when multiple writes need to happen that are at non-consecutive addresses. For consecutive writes, cf. block_poke32().

Parameters
addrsThe byte addresses of the registers to write to (each truncated to 20 bits).
dataNew values of these registers. The lengths of data and addr must match.
timeThe time at which the first transaction should be executed.
ackShould transaction completion be acknowledged?
Exceptions
uhd::value_errorif lengths of data and addr don't match
op_failedif an ACK is requested and the transaction fails
op_timeoutif an ACK is requested and no response is received
op_seqerrif an ACK is requested and a sequence error occurs
op_timeerrif an ACK is requested and a time error occurs (late command)

Implements uhd::rfnoc::register_iface.

◆ peek32()

uint32_t uhd::rfnoc::mock_reg_iface_t::peek32 ( uint32_t  addr,
uhd::time_spec_t  time 
)
inlinevirtual

Read a 32-bit register implemented in the NoC block.

Parameters
addrThe byte address of the register to read from (truncated to 20 bits).
timeThe time at which the transaction should be executed.
Exceptions
op_failedif the transaction fails
op_timeoutif no response is received
op_seqerrif a sequence error occurs

Implements uhd::rfnoc::register_iface.

◆ poke32()

void uhd::rfnoc::mock_reg_iface_t::poke32 ( uint32_t  addr,
uint32_t  data,
uhd::time_spec_t  time,
bool  ack 
)
inlinevirtual

Write a 32-bit register implemented in the NoC block.

Parameters
addrThe byte address of the register to write to (truncated to 20 bits).
dataNew value of this register.
timeThe time at which the transaction should be executed.
ackShould transaction completion be acknowledged?
Exceptions
op_failedif an ACK is requested and the transaction fails
op_timeoutif an ACK is requested and no response is received
op_seqerrif an ACK is requested and a sequence error occurs
op_timeerrif an ACK is requested and a time error occurs (late command)

Implements uhd::rfnoc::register_iface.

◆ poll32()

void uhd::rfnoc::mock_reg_iface_t::poll32 ( uint32_t  addr,
uint32_t  data,
uint32_t  mask,
uhd::time_spec_t  timeout,
uhd::time_spec_t  time = uhd::time_spec_t::ASAP,
bool  ack = false 
)
inlinevirtual

Poll a 32-bit register until its value for all bits in mask match data&mask

This will insert a command into the command queue to wait until a register is of a certain value. This can be used, e.g., to poll for a lock pin before executing the next command. It is related to sleep(), except it has a condition to wait on, rather than an unconditional stall duration. The timeout is hardware-timed. If the register does not attain the requested value within the requested duration, ${something bad happens}.

Example: Assume readback register 16 is a status register, and bit 0 indicates a lock is in place (i.e., we want it to be 1) and bit 1 is an error flag (i.e., we want it to be 0). The previous command can modify the state of the block, so we give it 1ms to settle. In that case, the call would be thus:

// iface is a register_iface::sptr:
iface->poll32(16, 0x1, 0x3, 1e-3);
Parameters
addrThe byte address of the register to read from (truncated to 20 bits).
dataThe values that the register must have
maskThe bitmask that is applied before checking the readback value
timeoutThe max duration that the register is allowed to take before reaching its new state.
timeWhen the poll should be executed
ackShould transaction completion be acknowledged? This is typically only necessary if the software needs a condition to be fulfilled before continueing, or during debugging.
Exceptions
op_failedif an ACK is requested and the transaction fails
op_timeoutif an ACK is requested and no response is received
op_seqerrif an ACK is requested and a sequence error occurs
op_timeerrif an ACK is requested and a time error occurs (late command)

Implements uhd::rfnoc::register_iface.

◆ register_async_msg_handler()

void uhd::rfnoc::mock_reg_iface_t::register_async_msg_handler ( async_msg_callback_t  callback_f)
inlinevirtual

Register a callback function for when an async message is received

Only one callback function can be registered. When calling this multiple times, only the last callback will be accepted.

Parameters
callback_fThe function to call when an asynchronous message is received.

Implements uhd::rfnoc::register_iface.

◆ register_async_msg_validator()

void uhd::rfnoc::mock_reg_iface_t::register_async_msg_validator ( async_msg_validator_t  callback_f)
inlinevirtual

Register a callback function to validate a received async message

The purpose of this callback is to provide a method to the framework to make sure a received async message is valid. If this callback is provided, the framework will first pass the message to the validator for validation. If the validator returns true, the async message is ACK'd with a ctrl_status_t::CMD_OKAY response, and then the async message is executed. If the validator returns false, then the async message is ACK'd with a ctrl_status_t::CMD_CMDERR, and the async message handler is not excecuted.

This callback may not communicate with the device, it can only look at the data and make a valid/not valid decision.

Only one callback function can be registered. When calling this multiple times, only the last callback will be accepted.

Parameters
callback_fThe function to call when an asynchronous message is received.

Implements uhd::rfnoc::register_iface.

◆ set_policy()

void uhd::rfnoc::mock_reg_iface_t::set_policy ( const std::string &  name,
const uhd::device_addr_t args 
)
inlinevirtual

Set a policy that governs the operational parameters of this register bus. Policies can be used to make tradeoffs between performance, resilience, latency, etc.

Parameters
nameThe name of the policy to apply
argsAdditional arguments to pass to the policy governor

Implements uhd::rfnoc::register_iface.

◆ sleep()

void uhd::rfnoc::mock_reg_iface_t::sleep ( uhd::time_spec_t  duration,
bool  ack 
)
inlinevirtual

Send a command to halt (block) the control bus for a specified time. This is a hardware-timed sleep.

Parameters
durationThe amount of time to sleep.
ackShould transaction completion be acknowledged?
Exceptions
op_failedif an ACK is requested and the transaction fails
op_timeoutif an ACK is requested and no response is received
op_seqerrif an ACK is requested and a sequence error occurs

Implements uhd::rfnoc::register_iface.

Member Data Documentation

◆ force_timeout

bool uhd::rfnoc::mock_reg_iface_t::force_timeout = false

◆ read_memory

std::unordered_map<uint32_t, uint32_t> uhd::rfnoc::mock_reg_iface_t::read_memory

All pokes end up writing to this map.

◆ write_memory

std::unordered_map<uint32_t, uint32_t> uhd::rfnoc::mock_reg_iface_t::write_memory

All peeks read from this map. A peek will fail if the address has not.


The documentation for this class was generated from the following file: