Loading...
Searching...
No Matches
Gain Calibration

## Description

These functions are thread-safe.

## Data Structures

struct | bladerf_gain_cal_entry
| Individual gain calibration entry. Each entry associates a frequency with a corresponding gain correction factor. More...
struct | bladerf_gain_cal_tbl
| Gain calibration table. The table contains a series of entries, each associating a frequency with a gain correction factor. Entries are sorted by frequency, from start_freq to stop_freq. More...

## Functions

API_EXPORT int CALL_CONV | bladerf_load_gain_calibration (struct bladerf *dev, bladerf_channel ch, const char *cal_file_loc)
| Loads and applies gain calibration for a specified channel from a file.
API_EXPORT int CALL_CONV | bladerf_print_gain_calibration (struct bladerf *dev, bladerf_channel ch, bool with_entries)
| Displays gain calibration details for a specified channel.
API_EXPORT int CALL_CONV | bladerf_enable_gain_calibration (struct bladerf *dev, bladerf_channel ch, bool en)
| Toggles gain calibration for a specified channel.
API_EXPORT int CALL_CONV | bladerf_get_gain_calibration (struct bladerf *dev, bladerf_channel ch, const struct bladerf_gain_cal_tbl **tbl)
| Provides read-only access to a channel's gain calibration table.
API_EXPORT int CALL_CONV | bladerf_get_gain_target (struct bladerf *dev, bladerf_channel ch, int *gain_target)
| Computes the gain target for a specified channel, incorporating calibration corrections.

## Function Documentation

## bladerf_enable_gain_calibration()

API_EXPORT int CALL_CONV bladerf_enable_gain_calibration | ( | struct bladerf * | dev,
|  | bladerf_channel | ch,
|  | bool | en )

Toggles gain calibration for a specified channel.

Enables or disables automatic gain adjustment based on a preloaded calibration table for the specified channel. This operation is thread-safe.

Note
  Gain calibration mode persists until device reset or power cycle. Ensure a calibration table is loaded before enabling.

Parameters

  [in] | dev | Non-NULL pointer to the bladeRF device.
  [in] | ch | Channel (BLADERF_CHANNEL_RX(0), BLADERF_CHANNEL_TX(0), etc.) to set gain calibration for.
  [in] | en | true to enable or false to disable gain calibration.

Returns
  0 on success, or a BLADERF_ERR_* code on failure (e.g., if calibration table is not initialized).

## bladerf_get_gain_calibration()

API_EXPORT int CALL_CONV bladerf_get_gain_calibration | ( | struct bladerf * | dev,
|  | bladerf_channel | ch,
|  | const struct bladerf_gain_cal_tbl ** | tbl )

Provides read-only access to a channel's gain calibration table.

Returns a read-only pointer to a specified channel's gain calibration table, preventing modification. Access is thread-safe, protected by device mutexes.

Parameters

  [in] | dev | Non-NULL pointer to a BladeRF device structure.
  [in] | ch | Channel to retrieve the gain calibration table for.
  [out] | tbl | On success, updated to point to the read-only gain calibration table.

Returns
  0 on success, BLADERF_ERR_UNEXPECTED if the table is not loaded, or BLADERF_ERR_INVAL for invalid inputs.

## bladerf_get_gain_target()

API_EXPORT int CALL_CONV bladerf_get_gain_target | ( | struct bladerf * | dev,
|  | bladerf_channel | ch,
|  | int * | gain_target )

Computes the gain target for a specified channel, incorporating calibration corrections.

For a channel, this calculates the target gain considering the current gain setting and calibration corrections, if available. In MGC mode, it returns the target gain from the calibration table. In AGC mode, it adjusts the target based on the calibration correction for the current frequency.

Note
  Access to device and calibration data is thread-safe.

Parameters

  [in] | dev | Non-NULL pointer to a BladeRF device.
  [in] | ch | Channel (RX/TX) for querying the gain target.
  [out] | gain_target | Where to store the computed gain target. Reflects current gain and calibration corrections.

Returns
  0 if successful, with gain_target updated. On failure, returns BLADERF_ERR_UNEXPECTED if calibration is uninitialized, or other error codes for different failures.

## bladerf_load_gain_calibration()

API_EXPORT int CALL_CONV bladerf_load_gain_calibration | ( | struct bladerf * | dev,
|  | bladerf_channel | ch,
|  | const char * | cal_file_loc )

Loads and applies gain calibration for a specified channel from a file.

This function adjusts the specified channel's gain settings on the bladeRF device using calibration data from the provided file path. It supports calibration files in CSV format, automatically converting them to binary format as required by the device. This ensures the device operates with optimized gain settings across its frequency range. The operation is protected by mutex locks to maintain thread safety.

Parameters

  [in] | dev | Pointer to the initialized bladeRF device.
  [in] | ch | The target channel (RX or TX) for gain calibration.
  [in] | cal_file_loc | Path to the calibration file, either in CSV or binary format. CSV files are converted to binary format during the process.

Returns
  0 on success, indicating that the calibration data was successfully applied to the channel. Returns BLADERF_ERR_UNSUPPORTED if the device or channel does not support gain calibration. Other BLADERF_ERR_* error codes indicate specific failures, such as file access issues or conversion errors.

## bladerf_print_gain_calibration()

API_EXPORT int CALL_CONV bladerf_print_gain_calibration | ( | struct bladerf * | dev,
|  | bladerf_channel | ch,
|  | bool | with_entries )

Displays gain calibration details for a specified channel.

Outputs the gain calibration information to the console. The level of detail is adjustable via with_entries.

Note
  This operation is thread-safe.

Parameters

  [in] | dev | Non-NULL pointer to a bladeRF device.
  [in] | ch | Channel to display gain calibration for. Use bladerf_channel.
  [in] | with_entries | Set to true to print all calibration entries, or false for a summary only.

Returns
  0 on success, BLADERF_ERR_UNSUPPORTED if calibration is not supported on the device, or other BLADERF_ERR_* codes for different failures.