Class FromHostBuffer

Inheritance Relationships

Derived Types

Class Documentation

class FromHostBuffer

Abstract class representing a FromHost DMA buffer. The elinks enabled for the corresponding DMA buffers are read from the device in the constructors.

Subclassed by FileFromHostBuffer, FlxFromHostBuffer

Public Functions

inline FromHostBuffer(std::shared_ptr<Device> d)

FromHostBuffer contructor.

Parameters:

d -- Device shared pointer.

virtual ~FromHostBuffer() = default

FromHostBuffer destructor.

inline std::shared_ptr<Device> get_device()
Returns:

pointer to device in use.

inline size_t get_size() const
Returns:

size of DMA buffer.

inline void set_encoder_data_format(int format)
Parameters:

format -- : FromHost data format supported by firmware.

inline int get_dmaid() const
Returns:

identifier of DMA buffer.

inline void set_dmaid(int dma_id)
Parameters:

dma_id -- identifier of DMA buffer.

Returns:

null.

inline void stop()
Returns:

stop DMA transfer operations.

inline std::vector<Elink> get_elinks()
Parameters:

m_dmaid -- DMA identifier

Returns:

vector of enabled e-links.

Parameters:

m_dmaid -- DMA identifier

Returns:

vector of enabled e-links of a given type (DAQ, DCS...)

inline void increment_writer_counter()

increment the counter of writers concurrently acessing the DMA buffer

inline bool has_multiple_writers() const
Returns:

whether the FromHost DMA buffer is in use by more than a writer.

inline size_t compute_msg_dma_occupancy(size_t size)
Parameters:

size -- of message to be encoded and written.

Returns:

size of the encoded messagesss provided by encoder.

void encode_and_write(uint64_t elink, const uint8_t *source, size_t size)

encode and write message in the FromHost buffer.

Parameters:
  • elink -- of message to be encoded and written.

  • source -- of message to be encoded and written.

  • size -- of message to be encoded and written.

inline uint32_t dma_get_free_MB()
Returns:

free space in the FromHost buffer in MB.

void trickle_padding()

Adds padding to the trickle configuration.

The trickle configration total memory occupancy inside the DMA buffer must be a multiple of 4096 bytes. This function adds some padding to make it a multiple of 4096 bytes if necessary. The padding must also be correctly encoded in the Fromhost data format, but to ensure that the padding is discarded by the firmware I used e-link 0x30 which contains a valid link-ID but an invalid e-path (FLX-2562).

FromHostDmaStats get_monitoring_data()
Returns:

monitoring information with rates.

virtual size_t dma_free_bytes() = 0
Returns:

free space in the FromHost buffer in bytes.

virtual void allocate_buffer(size_t size, const std::string &name, bool vmem, bool free_previous_cmem = true) = 0
Parameters:
  • size -- of the FromHost DMA buffer.

  • name -- of the buffer passed to the CMEM driver.

  • vmem -- allocate the buffer without using the CMEM driver.

  • free_previous_cmem -- claim an unlocked/orphaned CMEM buffer with the same name.

Public Members

std::mutex m_buffer_mutex

Protected Functions

virtual void set_oneshot_trickle_buffer() = 0
virtual void dma_start_continuous() = 0
virtual void dma_start_circular_trickle_buffer() = 0
virtual bool dma_is_full() = 0
virtual uint64_t dma_get_read_offset() = 0
virtual uint64_t dma_get_write_ptr() = 0
virtual uint64_t dma_get_write_offset() = 0
virtual void dma_set_write_offset(uint64_t offset) = 0
virtual void dma_advance_write_ptr(size_t bytes) = 0
virtual bool can_write_trickle() = 0
Returns:

true if the buffer is writable, false otherwise.

inline size_t dma_compute_free_bytes(uint64_t fw_rd_ptr, uint64_t pc_wr_ptr, bool even)

Protected Attributes

int m_dmaid = -1
std::shared_ptr<Device> m_device
std::atomic<bool> m_run_flag = {true}
size_t m_size
int m_number_of_writers
Encoder m_encoder
FromHostDmaStats m_mon
FromHostDmaStats m_mon_prev
std::unique_ptr<DmaBuffer> m_buffer