File utils.h

FileList > midas_fe > utils.h

Go to the source code of this file

Utility functions for bit-level parameter setting and ODB indexing. More...

  • #include "FEBSlowcontrolInterface.h"
  • #include "mutrig_config.h"
  • #include "Mutrig3Config.h"
  • #include "bits_utils.h"

Public Functions

Type Name
int ChangeTDCTest (FEBSlowcontrolInterface & feb_sc, midas::odb m_settings)
int ConfigureASICs (FEBSlowcontrolInterface & feb_sc, midas::odb m_settings, uint8_t * bitpattern_w)
Configures all enabled ASICs across active FEBs using bit patterns.
int ConfigureInjectASICs (FEBSlowcontrolInterface & feb_sc, const std::vector< uint8_t > & inj_col, const std::vector< uint8_t > & inj_row)
Configure injection. Structure of injection 1.) Set VCal(a VDAC) in a different interface: chips for which VCal is set to none Zero will experience the injection This can however also be accomodated in this interface at some point, for now Chip Injection Selection via VCal 2.) Select the pixel you want to inject: DISCLAIMER: Due to chip design choices, always two neighbouring pixels will be injected at the same time. ( Condition; int(col)/2=int(col+1)/2 [Integer Division] The selection is achieved via a crosshair selection: row and col adresses are set and all combinations of rows and cols will be anabled for injection. In this first approach we will only select one pixel at a time, ie. one row, one column. This should probably remain like this, due to the limited driving power of the Injection circuit.
int ConfigureMuTRiGASICs (FEBSlowcontrolInterface & feb_sc, midas::odb m_settings, uint8_t * bitpattern_w)
Configures all enabled ASICs across active MuTRiG FEBs using bit patterns.
int ConfigureTDACs (FEBSlowcontrolInterface & feb_sc, midas::odb m_settings)
Write TDACs to all enabled ASICs across active FEBs.
int FullChipInjection (FEBSlowcontrolInterface & feb_sc, midas::odb m_settings, uint8_t min_columns, uint8_t max_columns, uint8_t min_rows, uint8_t max_rows, uint32_t injection_pulse_duration, uint32_t num_repetitions, uint32_t wait_between_pulses)
int InitFEBs (FEBSlowcontrolInterface & feb_sc, midas::odb m_settings)
Initializes all active Front-End Boards (FEBs) using slow control.
int InjectASICs (FEBSlowcontrolInterface & feb_sc, uint32_t injection_pulse_duration)
int InjectASICsInLoop (FEBSlowcontrolInterface & feb_sc, uint32_t injection_pulse_duration, uint32_t num_repetitions, uint32_t wait_between_pulses)
int MuTRiGResetLVDSAddr (FEBSlowcontrolInterface & feb_sc, midas::odb m_settings)
int MuTRiG_reset_asics (FEBSlowcontrolInterface & feb_sc, midas::odb m_settings)
int MuTRiG_reset_counters (FEBSlowcontrolInterface & feb_sc, midas::odb m_settings)
int MuTRiG_reset_datapath (FEBSlowcontrolInterface & feb_sc, midas::odb m_settings)
Trigger Reset on MuTRiG FEB.
int MuTRiG_reset_lvds (FEBSlowcontrolInterface & feb_sc, midas::odb m_settings)
int TBinit (FEBSlowcontrolInterface & feb_sc, midas::odb m_settings)
int UpdatePower (FEBSlowcontrolInterface & feb_sc, midas::odb m_settings)
int UpdatePowerOverride (FEBSlowcontrolInterface & feb_sc, midas::odb m_settings)
void adcContinuousReadout (FEBSlowcontrolInterface & feb_sc, midas::odb m_settings)
uint64_t calculateADCCommand (ADC_Command adcCommand, uint16_t adcDivisionFactor, ADC_Mode adcMode)
int create_dummy_event (uint32_t * dma_buf_dummy, size_t eventSize, int nEvents, int serial_number)
Creates one or more dummy MIDAS events in memory.
uint32_t generate_random_pixel_hit_swb (uint32_t time_stamp)
Generates a simulated pixel hit for test data streams.
uint32_t getODBIdx (midas::odb odb, std::string name)
Gets the index of a named key in a MIDAS ODB object.
uint32_t getOffset (midas::odb odb, std::string name)
Computes the bit offset of a named field in a MIDAS ODB structure.
void get_BiasDACs_from_odb (midas::odb m_config, uint8_t * bitpattern_w, uint32_t asicIDx)
Extracts and writes Bias DAC configuration bits for a given ASIC.
void get_ConfDACs_from_odb (midas::odb m_config, uint8_t * bitpattern_w, uint32_t asicIDx)
Extracts and writes Configuration DAC bits for a given ASIC.
void get_DACs_from_odb (midas::odb m_nbits, midas::odb m_config, uint8_t * bitpattern_w, uint32_t asicIDx, std::string firstWord, std::string lastWord, bool inverted)
Writes DAC configuration bits from ODB to the bit pattern buffer.
void get_VDACs_from_odb (midas::odb m_config, uint8_t * bitpattern_w, uint32_t asicIDx)
Extracts and writes Voltage DAC bits for a given ASIC.
int read_tdac_file (vector< uint32_t > & vec, std::string path)
Read TDAC file from a given path.
int resetASICs (FEBSlowcontrolInterface & feb_sc, midas::odb m_settings)
Sends a reset to all MuPix chips.
void sendCommand (FEBSlowcontrolInterface & feb_sc, midas::odb m_settings, uint64_t command)
int to_signed_12b (uint32_t i)
int to_signed_16b (uint32_t i)

Detailed Description

This header provides common utility routines used in frontend configuration and data preparation tasks. These functions support bitfield encoding and MIDAS Online Database (ODB) access.

Included Functions: * getODBIdx: Retrieves the index of a named subkey in a midas::odb structure. * getOffset: Computes a bit offset for a named subkey in the ODB. * get_DACs_from_odb: Writes DAC configuration bits from ODB to the bit pattern buffer. * get_BiasDACs_from_odb: Extracts and writes Bias DAC configuration bits for a given ASIC. * get_ConfDACs_from_odb: Extracts and writes Configuration DAC bits for a given ASIC. * get_VDACs_from_odb: Extracts and writes Voltage DAC bits for a given ASIC. * InitFEBs: Initializes all active Front-End Boards (FEBs) using slow control. * ConfigureASICs: Configures all enabled ASICs across active FEBs using bit patterns. * generate_random_pixel_hit_swb: Generates a simulated pixel hit for test data streams. * create_dummy_event: Creates one or more dummy MIDAS events in memory.

These utilities simplify frontend implementation by abstracting repetitive logic related to bit encoding and dynamic configuration.

Note:

These functions are performance-sensitive and should be used with care in high-rate paths such as configuration loops.

Public Functions Documentation

function ChangeTDCTest

int ChangeTDCTest (
    FEBSlowcontrolInterface & feb_sc,
    midas::odb m_settings
) 

function ConfigureASICs

Configures all enabled ASICs across active FEBs using bit patterns.

int ConfigureASICs (
    FEBSlowcontrolInterface & feb_sc,
    midas::odb m_settings,
    uint8_t * bitpattern_w
) 

For each ASIC enabled by the ASIC mask, retrieves DAC configurations from the ODB, encodes them into a payload, and sends them to the corresponding FEB.

Parameters:

  • feb_sc Reference to the FEB slow control interface.
  • m_settings MIDAS ODB object containing DAQ and config sections.
  • bitpattern_w Temporary buffer used to build the configuration bitstream.

Returns:

FE_SUCCESS if all ASICs configured successfully; error code otherwise.


function ConfigureInjectASICs

Configure injection. Structure of injection 1.) Set VCal(a VDAC) in a different interface: chips for which VCal is set to none Zero will experience the injection This can however also be accomodated in this interface at some point, for now Chip Injection Selection via VCal 2.) Select the pixel you want to inject: DISCLAIMER: Due to chip design choices, always two neighbouring pixels will be injected at the same time. ( Condition; int(col)/2=int(col+1)/2 [Integer Division] The selection is achieved via a crosshair selection: row and col adresses are set and all combinations of rows and cols will be anabled for injection. In this first approach we will only select one pixel at a time, ie. one row, one column. This should probably remain like this, due to the limited driving power of the Injection circuit.

int ConfigureInjectASICs (
    FEBSlowcontrolInterface & feb_sc,
    const std::vector< uint8_t > & inj_col,
    const std::vector< uint8_t > & inj_row
) 

128x7bit long register [Enable Injection Row<0>,Enable Injection Row<1>,NCNC,AmpOut,Enable Injection Column, HitBusEnable]-->(Shift direction)--> The implementation for the characterisation setup can be found here: https://bitbucket.org/mu3e/mupix8_daq/src/master/library/sensors/MuPix11.cpp

3.) Send Injection Command to trigger injection [ 4 bit Chip Address | 6 bit Inject Command | 10 bit Duration | zeroes/ones/random ]

Parameters:

  • feb_sc Reference to the FEB slow control interface.
  • inj_col Reference to the FEB slow control interface.
  • inj_row MIDAS ODB object containing DAQ and config sections.

Returns:

FE_SUCCESS if all ASICs configured successfully; error code otherwise.


function ConfigureMuTRiGASICs

Configures all enabled ASICs across active MuTRiG FEBs using bit patterns.

int ConfigureMuTRiGASICs (
    FEBSlowcontrolInterface & feb_sc,
    midas::odb m_settings,
    uint8_t * bitpattern_w
) 

For each ASIC enabled by the ASIC mask, retrieves DAC configurations from the ODB, encodes them into a payload, and sends them to the corresponding FEB.

Parameters:

  • feb_sc Reference to the FEB slow control interface.
  • m_settings MIDAS ODB object containing DAQ and config sections.
  • bitpattern_w Temporary buffer used to build the configuration bitstream.

Returns:

FE_SUCCESS if all ASICs configured successfully; error code otherwise.


function ConfigureTDACs

Write TDACs to all enabled ASICs across active FEBs.

int ConfigureTDACs (
    FEBSlowcontrolInterface & feb_sc,
    midas::odb m_settings
) 

For each ASIC enabled by the ASIC mask, retrieves TDAC configurations from a TDAC file, encodes them into a payload, and sends them to the corresponding FEB.

Parameters:

  • feb_sc Reference to the FEB slow control interface.
  • m_settings MIDAS ODB object containing DAQ and config sections.

Returns:

FE_SUCCESS if all ASICs configured successfully; error code otherwise.


function FullChipInjection

int FullChipInjection (
    FEBSlowcontrolInterface & feb_sc,
    midas::odb m_settings,
    uint8_t min_columns,
    uint8_t max_columns,
    uint8_t min_rows,
    uint8_t max_rows,
    uint32_t injection_pulse_duration,
    uint32_t num_repetitions,
    uint32_t wait_between_pulses
) 

function InitFEBs

Initializes all active Front-End Boards (FEBs) using slow control.

int InitFEBs (
    FEBSlowcontrolInterface & feb_sc,
    midas::odb m_settings
) 

Writes unique FPGA IDs and configures LVDS link settings for each active FEB.

Parameters:

  • feb_sc Reference to the FEB slow control interface.
  • m_settings MIDAS ODB object containing DAQ link configuration.

Returns:

FE_SUCCESS on success.


function InjectASICs

int InjectASICs (
    FEBSlowcontrolInterface & feb_sc,
    uint32_t injection_pulse_duration
) 

function InjectASICsInLoop

int InjectASICsInLoop (
    FEBSlowcontrolInterface & feb_sc,
    uint32_t injection_pulse_duration,
    uint32_t num_repetitions,
    uint32_t wait_between_pulses
) 

function MuTRiGResetLVDSAddr

int MuTRiGResetLVDSAddr (
    FEBSlowcontrolInterface & feb_sc,
    midas::odb m_settings
) 

function MuTRiG_reset_asics

int MuTRiG_reset_asics (
    FEBSlowcontrolInterface & feb_sc,
    midas::odb m_settings
) 

function MuTRiG_reset_counters

int MuTRiG_reset_counters (
    FEBSlowcontrolInterface & feb_sc,
    midas::odb m_settings
) 

function MuTRiG_reset_datapath

Trigger Reset on MuTRiG FEB.

int MuTRiG_reset_datapath (
    FEBSlowcontrolInterface & feb_sc,
    midas::odb m_settings
) 

Parameters:

  • feb_sc : slow control interface

Returns:

FE_SUCCESS


function MuTRiG_reset_lvds

int MuTRiG_reset_lvds (
    FEBSlowcontrolInterface & feb_sc,
    midas::odb m_settings
) 

function TBinit

int TBinit (
    FEBSlowcontrolInterface & feb_sc,
    midas::odb m_settings
) 

function UpdatePower

int UpdatePower (
    FEBSlowcontrolInterface & feb_sc,
    midas::odb m_settings
) 

function UpdatePowerOverride

int UpdatePowerOverride (
    FEBSlowcontrolInterface & feb_sc,
    midas::odb m_settings
) 

function adcContinuousReadout

void adcContinuousReadout (
    FEBSlowcontrolInterface & feb_sc,
    midas::odb m_settings
) 

function calculateADCCommand

uint64_t calculateADCCommand (
    ADC_Command adcCommand,
    uint16_t adcDivisionFactor,
    ADC_Mode adcMode
) 

function create_dummy_event

Creates one or more dummy MIDAS events in memory.

int create_dummy_event (
    uint32_t * dma_buf_dummy,
    size_t eventSize,
    int nEvents,
    int serial_number
) 

Fills a provided DMA buffer with synthetic event headers and pixel hits. This simulates what a real event would look like for testing purposes.

Parameters:

  • dma_buf_dummy Pointer to the target DMA buffer.
  • eventSize Size of a single event (in words).
  • nEvents Number of events to create.
  • serial_number Starting event serial number (incremented internally).

Returns:

Updated serial number after all events are written.


function generate_random_pixel_hit_swb

Generates a simulated pixel hit for test data streams.

uint32_t generate_random_pixel_hit_swb (
    uint32_t time_stamp
) 

Encodes a random chip, column, row, and time-over-threshold (ToT) value into a 32-bit hit word.

Parameters:

  • time_stamp Timestamp to embed in the hit word.

Returns:

uint32_t Encoded hit data.


function getODBIdx

Gets the index of a named key in a MIDAS ODB object.

uint32_t getODBIdx (
    midas::odb odb,
    std::string name
) 

Searches the top-level keys in a midas::odb structure and returns the index of the key matching the provided name.

Parameters:

  • odb The midas::odb object representing the configuration section.
  • name The name of the subkey to find.

Returns:

uint32_t The index of the key if found, otherwise the total count.


function getOffset

Computes the bit offset of a named field in a MIDAS ODB structure.

uint32_t getOffset (
    midas::odb odb,
    std::string name
) 

Iterates through subkeys in an ODB group to determine the bit offset of a given field, assuming each key represents a sequential bit region.

Parameters:

  • odb The midas::odb group containing configuration fields.
  • name The name of the target field.

Returns:

uint32_t The cumulative bit offset of the named field.


function get_BiasDACs_from_odb

Extracts and writes Bias DAC configuration bits for a given ASIC.

void get_BiasDACs_from_odb (
    midas::odb m_config,
    uint8_t * bitpattern_w,
    uint32_t asicIDx
) 

Calls get_DACs_from_odb() with hardcoded range for Bias DAC fields.

Parameters:

  • m_config ODB root configuration node.
  • bitpattern_w Target buffer for encoded configuration bits.
  • asicIDx Index of the ASIC to configure.

function get_ConfDACs_from_odb

Extracts and writes Configuration DAC bits for a given ASIC.

void get_ConfDACs_from_odb (
    midas::odb m_config,
    uint8_t * bitpattern_w,
    uint32_t asicIDx
) 

Calls get_DACs_from_odb() with hardcoded range for Conf DAC fields.

Parameters:

  • m_config ODB root configuration node.
  • bitpattern_w Target buffer for encoded configuration bits.
  • asicIDx Index of the ASIC to configure.

function get_DACs_from_odb

Writes DAC configuration bits from ODB to the bit pattern buffer.

void get_DACs_from_odb (
    midas::odb m_nbits,
    midas::odb m_config,
    uint8_t * bitpattern_w,
    uint32_t asicIDx,
    std::string firstWord,
    std::string lastWord,
    bool inverted
) 

This function reads DAC values from an ODB configuration and writes them into a byte buffer as bit-encoded values, using the setParameter function.

Parameters:

  • m_nbits ODB subkey describing bit widths for each DAC parameter.
  • m_config ODB subkey containing DAC values per ASIC.
  • bitpattern_w Target buffer for encoded configuration bits.
  • asicIDx Index of the ASIC to configure.
  • firstWord Name of the first DAC parameter to include.
  • lastWord Name of the last DAC parameter to include.
  • inverted Whether to encode bits in MSB-first (inverted) order.

function get_VDACs_from_odb

Extracts and writes Voltage DAC bits for a given ASIC.

void get_VDACs_from_odb (
    midas::odb m_config,
    uint8_t * bitpattern_w,
    uint32_t asicIDx
) 

Calls get_DACs_from_odb() with hardcoded range for VDAC fields.

Parameters:

  • m_config ODB root configuration node.
  • bitpattern_w Target buffer for encoded configuration bits.
  • asicIDx Index of the ASIC to configure.

function read_tdac_file

Read TDAC file from a given path.

int read_tdac_file (
    vector< uint32_t > & vec,
    std::string path
) 

Tries to read a TDAC file from a given path. If the path is not present an empty TDAC configuration (no pixel is masked) is created.

Parameters:

  • vec Reference to the bitpattern vector.
  • path Path to th file.

Returns:

FE_SUCCESS if the file is read; error code otherwise.


function resetASICs

Sends a reset to all MuPix chips.

int resetASICs (
    FEBSlowcontrolInterface & feb_sc,
    midas::odb m_settings
) 

Sends a reset to all MuPix chips.

Parameters:

  • feb_sc Reference to the FEB slow control interface.
  • m_settings MIDAS ODB object containing DAQ and config sections.

Returns:

FE_SUCCESS on success.


function sendCommand

void sendCommand (
    FEBSlowcontrolInterface & feb_sc,
    midas::odb m_settings,
    uint64_t command
) 

function to_signed_12b

int to_signed_12b (
    uint32_t i
) 

function to_signed_16b

int to_signed_16b (
    uint32_t i
) 


The documentation for this class was generated from the following file midas_fe/utils.h