summaryrefslogtreecommitdiff
path: root/cesar/ce/rx/bitloading/bitloading.h
blob: aa500aefcbfcd6dc3f60b3d1ed3071a37ca66cc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#ifndef ce_rx_bitloading_bitloading_h
#define ce_rx_bitloading_bitloading_h
/* Cesar project {{{
 *
 * Copyright (C) 2009 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    ce/rx/bitloading/bitloading.h
 * \brief   CE RX bit-loading (public declaration).
 * \ingroup ce_rx
 *
 * This module is responsible to manage the bit-loading state and data per
 * station.
 *
 * Basically, a structure is added to the sta_t with some information (like
 * the state of the bit-loading).
 */

#include "ce/rx/bitloading/context.h"
#include "ce/rx/bitloading/nsr.h"

#include "common/module.h"

BEGIN_DECLS

/**
 * Reset BER sliding means.
 * \param  bl  the bit loading structure of the station
 */
extern inline void
ce_rx_bl_ber_sliding_mean_reset (ce_rx_bitloading_t *bl)
{
    /* Check parameter. */
    dbg_assert (bl);
    uint i;
    for (i = 0; i < CE_RX_BL_BER_SLIDING_MEAN_NB; i++)
        bl->ber_sliding_mean[i] = -1;
}

/**
 * Initialize bit-loading statistics.
 */
extern inline void
ce_rx_bl_stats_init (ce_rx_bitloading_t *bl)
{
    /* Check parameter. */
    dbg_assert (bl);

    uint i;
    bl->stats.curr_nb_pb = 0;
    bl->stats.curr_nb_pb_crc_false = 0;
    bl->stats.curr_ber_sum = 0;
    for (i = 0; i < CE_RX_BL_BER_SLIDING_MEAN_NB; i++)
    {
        bl->stats.curr_ber_mean[i] = 0;
        bl->stats.prev_ber_mean[i] = 0;
    }
    bl->stats.curr_pberr_rate_mean = 0;
    for (i = 0; i < CE_RX_BL_RESTART_REASON_NB; i++)
        bl->stats.restart_reason[i] = 0;
    bl->stats.prev_ber_target = 0;
    bl->stats.prev_ber_target_reached = 0;
    bl->stats.prev_pberr_rate_mean = 0;
    bl->stats.last_restart_reason = CE_RX_BL_RESTART_REASON_NO_RESTART;
    bl->stats.optimization_failure = 0;
}

/**
 * Initialize bit-loading data.
 * \param  bt  the bit-loading data & state structure.
 * @note the structure must be already allocated.
 */
extern inline void
ce_rx_bitloading_init (ce_rx_bitloading_t *bt)
{
    /* Check parameter. */
    dbg_assert (bt);
    /* Initialize. */
    bt->fsm = 0;
    bt->noise_nrj_blk_count = 0;
    dbg_invalid_ptr (bt->noise_nrj);
    bt->high_pb_error_rate_frame_counter = 0;
    ce_rx_bl_ber_sliding_mean_reset (bt);
    ce_rx_bl_stats_init (bt);
    bt->opti_table = NULL;
#if MODULE_INCLUDED (ce_rx_bitloading)
    ce_rx_bl_pber_reset (&bt->pber);
#endif
    bt->resend_tm = false;
    bt->resend_tm_date = 0;
    ce_rx_bl_bmu_reset (&bt->bmu);
    bt->optimization_failed = false;
    bt->default_robo = true;
}

/**
 * Un-initialize bit-loading data.
 * \param  bt  the bit-loading data & state structure.
 * @note this function does not delete the structure itself, just clean the
 * structure.
 */
extern inline void
ce_rx_bitloading_uninit (ce_rx_bitloading_t *bt)
{
    /* Check parameter. */
    dbg_assert (bt);
    /* Clean if needed. */
    if (bt->noise_nrj_blk_count)
    {
        ce_rx_bl_nsr_clean (bt);
    }
    /* Letting the FSM in its current state. */

    /* Free optimization table. */
    if (bt->opti_table != NULL)
        blk_table_free (bt->opti_table);
}

END_DECLS

#endif /* ce_rx_bitloading_bitloading_h */