/* Cesar project {{{ * * Copyright (C) 2011 Spidcom * * <<>> * * }}} */ /** * \file ce/rx/bitloading/src/pber.c * \brief PB Error Rate functions * \ingroup ce_rx */ #include "common/std.h" #include "mac/common/defs.h" #include "ce/rx/bitloading/pber.h" #include "ce/rx/bitloading/inc/pber.h" #include "ce/rx/ce_rx_param.h" /** * Maximum value of the PB error rate quantified. * This is a possible value. */ #define CE_RX_BL_PBER_MAX (1 << 16) /** * PBER quantification factor. */ #define CE_RX_BL_PBER_QUANT (1 << 16) ce_rx_bl_pber_conf_t ce_rx_bl_pber_conf = { .mean_coef = CE_RX_BL_PBER_SLIDING_MEAN_COEF, .mean_init = CE_RX_BL_PBER_MEAN_INIT, }; void ce_rx_bl_pber_reset (ce_rx_bl_pber_t *ctx) { dbg_assert (ctx); /* Reset to an invalid value. */ ctx->mean_q16 = ce_rx_bl_pber_conf.mean_init; } void ce_rx_bl_pber_update (ce_rx_bl_pber_t *ctx, uint pb_total, uint pb_crc_false) { /* Check parameters. */ dbg_assert (ctx); dbg_assert (pb_total); /* Quantify PBER mean of current frame by PB. */ uint pb_mean_q16 = pb_crc_false * CE_RX_BL_PBER_QUANT; /* If set to impossible value, this is the first frame. */ if (ctx->mean_q16 > CE_RX_BL_PBER_MAX) ctx->mean_q16 = pb_mean_q16; else { dbg_assert (pb_crc_false <= pb_total); dbg_assert (pb_total < CE_RX_BL_PBER_MAX_PB_PER_FRAME); dbg_assert (pb_total < ce_rx_bl_pber_conf.mean_coef); ctx->mean_q16 = (ctx->mean_q16 * (ce_rx_bl_pber_conf.mean_coef - pb_total) + pb_mean_q16) / ce_rx_bl_pber_conf.mean_coef; } }