#ifndef ce_rx_bitloading_context_h #define ce_rx_bitloading_context_h /* Cesar project {{{ * * Copyright (C) 2012 MStar * * <<>> * * }}} */ /** * \file ce/rx/bitloading/context.h * \brief CE RX bit-loading context. * \ingroup ce_rx */ #include "lib/blk.h" #include "lib/blk_table.h" #include "ce/rx/bitloading/pber.h" #include "ce/rx/bitloading/ber_margin_update.h" typedef enum ce_rx_bitloading_ber_sliding_mean_t { /** BER sliding mean fast index. */ CE_RX_BL_BER_SLIDING_MEAN_FAST, /** BER sliding mean slow index. */ CE_RX_BL_BER_SLIDING_MEAN_SLOW, /** BER sliding mean count. */ CE_RX_BL_BER_SLIDING_MEAN_NB, } ce_rx_bitloading_ber_sliding_mean_t; /** * Restart reason of the CE. * Fields order is important for VS_GET_CE_STATS MME. */ typedef enum ce_rx_bitloading_restart_reason_t { /** * CE restarted because BER is too low. */ CE_RX_BL_RESTART_REASON_BER_LOW = 0, /** * CE restarted because PB error rate is too high. */ CE_RX_BL_RESTART_REASON_PBERR_HIGH = 1, /** * CE restarted because peer requested it (frame sound received). */ CE_RX_BL_RESTART_REASON_PEER_REQUEST = 2, /** * CE restarted because a tone map update has occurred. */ CE_RX_BL_RESTART_REASON_TONEMAP_UPDATE = 3, /** * CE restarted because a BER margin update has occurred. */ CE_RX_BL_RESTART_REASON_BER_MARGIN_UPDATE = 4, /** * Number of reason to restart the CE. * Should not be moved to keep numeration. */ CE_RX_BL_RESTART_REASON_NB, /** * No restart yet. */ CE_RX_BL_RESTART_REASON_NO_RESTART = 255 } ce_rx_bitloading_restart_reason_t; /** * Next dates we are allowed to restart the CE. */ typedef enum ce_rx_bitloading_date_criteria_t { /** * PBErrorRate criteria. */ CE_RX_BL_DATE_CRITERIA_PBER, /** * BER criteria. */ CE_RX_BL_DATE_CRITERIA_BER, /** * BER margin update criteria. */ CE_RX_BL_DATE_BER_MARGIN_UPDATE, /** * Number of date used in bit loading algorithm. */ CE_RX_BL_DATE_CRITERIA_NB, } ce_rx_bitloading_date_criteria_t; /** * Statistics of the CE/RX bit-loading. */ typedef struct ce_rx_bitloading_stats_t { /** * Number of PB in the last received frame. */ u8 curr_nb_pb; /** * Number of PB with CRC false in the last received frame. */ u8 curr_nb_pb_crc_false; /** * BER sum in the last frame received. */ uint curr_ber_sum; /** * Last BER sliding means after the last frame received. */ u64 curr_ber_mean[CE_RX_BL_BER_SLIDING_MEAN_NB]; /** * Last PB error rate mean after the last frame received. */ u32 curr_pberr_rate_mean; /** * Number of restart of the CE for each reasons. * Those counters can overflow. */ uint restart_reason[CE_RX_BL_RESTART_REASON_NB]; /** * Previous BER target, before the last CE restart. */ u64 prev_ber_target; /** * Previous BER reached, before the last CE restart. */ u64 prev_ber_target_reached; /** * BER sliding means of the previous tone map. */ u64 prev_ber_mean[CE_RX_BL_BER_SLIDING_MEAN_NB]; /** * PB Error Rate of the previous tone map. */ u32 prev_pberr_rate_mean; /** * Last CE restart reason. */ ce_rx_bitloading_restart_reason_t last_restart_reason; /** * Count of times when bit-loading can not optimize tone map as much as * possible (out of optimization table). */ uint optimization_failure; } ce_rx_bitloading_stats_t; /** * Bit-loading data per station. */ typedef struct ce_rx_bitloading_t { /** State of the bit loading. */ u32 fsm; /** Mean of the noise NRJ (on multiple blk) per intervals. */ blk_t *noise_nrj; /** Number of allocated block for the noise NRJ. */ u8 noise_nrj_blk_count; /** Mean count. */ u32 mean_count; /** Counter of frame with high PB error rate. */ uint high_pb_error_rate_frame_counter; /** BER sliding means (-1 if they are reseted). */ s64 ber_sliding_mean[CE_RX_BL_BER_SLIDING_MEAN_NB]; /** Next time we are allowed to restart the CE. */ u32 next_date_min_for_restart_rtc_date[CE_RX_BL_DATE_CRITERIA_NB]; /** Optimisation table of the station, this table only contain the index * of the carrier sorted by impact on the ber. */ blk_table_t *opti_table; /** Index of the optimization cursor in the optimization table. */ uint opti_table_cursor; /** Statistics of the bit-loading. */ ce_rx_bitloading_stats_t stats; /** PBER context. */ ce_rx_bl_pber_t pber; /** Need to resend tone map to TX? */ bool resend_tm; /** Timer to know when to re-send the tone map (if TX peer does not use * default TMI). */ uint resend_tm_date; /** BER margin update context. */ ce_rx_bl_bmu_t bmu; /** Actual bit-loading failed to optimize tone map as much as possible. */ bool optimization_failed; /** Use ROBO for default tonemap? * The goal of this field is to allow us to update default tonemap when * intervals are activated. When one interval is restarting, it can use * this field to indicate that channel quality may be decreasing * significantly and that we should use ROBO as the default tonemap, * at least temporarily. * /!\ This field is only valid between interval reset and tonemap * calculation and with intervals activated! */ bool default_robo; } ce_rx_bitloading_t; #endif /* ce_rx_bitloading_context_h */