#ifndef ce_rx_bitloading_inc_ber_h #define ce_rx_bitloading_inc_ber_h /* Cesar project {{{ * * Copyright (C) 2009 Spidcom * * <<>> * * }}} */ /** * \file ce/rx/bitloading/inc/ber.h * \brief Functions to compute BER. * \ingroup ce_rx * * This module contains some sets of functions to compute the BER from a given * NSR and modulation. */ #include "ce/rx/bitloading/bitloading.h" #include "ce/common/mod.h" #include "hal/phy/defs.h" #include "ce/rx/inc/measure.h" /** * Degree maximum of polynomial. */ #define CE_RX_BL_BER_POLY_MAX_DEGREE 2 /** * Default theoretical BER value when NSR is under range. */ #define CE_RX_BL_BER_DEFAULT_UNDER 0 /** * Default theoretical BER value when NSR is over range. */ #define CE_RX_BL_BER_DEFAULT_OVER (1ll << 52) /** * BER quantification factor. */ #define CE_RX_BL_BER_QUANT_FACTOR (1ll << 53) /** * Number maximum of polynomial per modulation. */ #define CE_RX_BL_BER_POLY_PER_MOD 10 /** * Quantification factor for the bit per tone. */ #define CE_RX_BL_BPT_QUANT_FACTOR (1ull << 8) /** * Polynomials for each modulation to compute BER. */ struct ce_rx_bl_ber_poly_coef_t { /** * Count of polynomial. */ u8 poly_count; /** * Polynomial degree. */ u8 degree[CE_RX_BL_BER_POLY_PER_MOD]; /** * Table of coefficients. */ s64 coef[CE_RX_BL_BER_POLY_PER_MOD][CE_RX_BL_BER_POLY_MAX_DEGREE + 1]; /** * Range of NSR (entry) value supported by the polynomial function. * First index is min, last one is max. */ u32 range[1 + CE_RX_BL_BER_POLY_PER_MOD]; }; typedef struct ce_rx_bl_ber_poly_coef_t ce_rx_bl_ber_poly_coef_t; /** * Polynomials coefficients for the bit loading. * They work for NSR based on sound and data. */ extern ce_rx_bl_ber_poly_coef_t ce_rx_bl_ber_poly_coef[CE_MOD_COUNT - 1]; /** * Initial value of the bit per tone goal to reach for the bit loading * initial. * It depends on the FEC rate. It corresponds to the "worst case" consign. */ extern const u64 ce_rx_bl_initial_bpt[PHY_FEC_RATE_NB]; /** * Margin to apply to BER target before usage in bit loading algorithm. */ extern s64 ce_rx_bl_ber_margin_[PHY_FEC_RATE_NB]; BEGIN_DECLS /** * Compute the theoretical BER from a NSR and a modulation. * \param poly the polynomial to use. * \param nsr the current NSR. * \param mod_index the index of the modulation. * \return the computed BER for this modulation and current NSR. */ u64 ce_rx_bl_ber_for_mod (ce_rx_bl_ber_poly_coef_t poly[CE_MOD_COUNT - 1], u32 nsr, u8 mod_index); /** * Compute the theoretical BER from a NSR (sound based) and a modulation. * \param nsr the current NSR. * \param mod_index the index of the modulation. * \return the computed BER for this modulation and current NSR. */ #define ce_rx_bl_ber_for_mod_initial(nsr, mod_index) \ ce_rx_bl_ber_for_mod (ce_rx_bl_ber_poly_coef, (nsr), (mod_index)) /** * Get modulations around a corresponding to a BER consign based on a NSR. * \param[in] poly polynomial coefficient to use. * \param[in] nsr mean of NSR. * \param[in] ber_pt BER consign. * \param[out] mod_lower modulation just under ber_pt. * \param[out] ber_lower BER of the modulation just under ber_pt. * \param[out] ber_upper BER of the modulation just over ber_pt. * * This function is used when you want to know the modulation that will * respect a given BER consign for a specific NSR. */ void ce_rx_bl_ber_vs_nsr (ce_rx_bl_ber_poly_coef_t poly[CE_MOD_COUNT - 1], u32 nsr, u64 ber_pt, u8 *mod_lower, u64 *ber_lower, u64 *ber_upper); /** * Compute the BER pt to reach according to the FEC rate, the number of used * carrier in the tone mask and the bits per tone. * \param fec_rate the FEC rate. * \param carrier_nb number of used carrier in tone mask. * \param bpt bit per tone. * \return the BER pt. */ u64 ce_rx_bl_ber_pt_bpt (phy_fecrate_t fec_rate, uint carrier_nb, u64 bpt); /** * Change margin to apply to BER target before usage in the bit loading * algorithms. * \param margin_q margin to apply to BER target (depend on FEC rate) */ void ce_rx_bl_ber_margin_set (s64 margin_q[PHY_FEC_RATE_NB]); /** * Update BER sliding means with received measures on a frame. * \param bl the bit loading structure of the station * \param ber the BER in quantified on the received frame */ void ce_rx_bl_ber_sliding_mean_update (ce_rx_bitloading_t *bl, u64 ber); /** * From a BER sum on a frame, compute the BER in quantified. * \param ber_sum the sum of BER on a frame * \param good_crc_pb_count the count of PB with good CRC on the frame * \param pb_size the size of the PB * \return the BER in in quantified format */ u64 ce_rx_bl_ber_quantify (ce_rx_measure_mbox_t *measure, u64 ber_reached, u16 pb_size); /** * Get theoretical BER target for a ROBO tone map. * \param carrier_nb number of used carrier in tone mask. * \return theoretical BER target of a ROBO tone map. */ u64 ce_rx_bl_ber_pt_robo (uint carrier_nb); END_DECLS #endif /* ce_rx_bitloading_inc_ber_h */