summaryrefslogtreecommitdiff
path: root/cesar/ce/tx/src/tx.c
blob: 6b7ae03cf92e9b0801b1aea7071b6df06a35afd2 (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
125
126
127
/* Cesar project {{{
 *
 * Copyright (C) 2007 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    ce/tx/src/tx.c
 * \brief   Channel Estimation in transmit mode (implementation).
 * \ingroup ce
 */

#include "common/std.h"

#include "cp/inc/context.h"
#include "cp/mme.h"
#include "cp/sta/mgr/sta_own_data.h"
#include "cp/sta/mgr/sta_mgr.h"
#include "mac/common/defs.h"
#include "ce/tx/inc/tx.h"
#include "ce/tx/mme.h"
#include "ce/tx/tx.h"

void
ce_tx_init (cp_t *cp)
{
    /* Check parameters. */
    dbg_assert (cp);

    /* Initialize the CE in TX context. */
    cp->ce_tx.mac_store_ctx = cp->mac_store;
    cp->ce_tx.tonemask = cp->mac_config->tonemask_info.tonemask;
}

void
ce_tx_process__cm_chan_est_ind (cp_t *ctx, cp_mme_rx_t *mme)
{
    ce_tx_cm_chan_est_ind_receive (ctx, mme);
}

void
ce_tx_process__cm_update_tm_ind (cp_t *ctx, cp_mme_rx_t *mme)
{
    ce_tx_cm_tm_update_ind_receive (ctx, mme);
}

void
ce_tx_update_tone_map (cp_t *ctx)
{
    /* Check parameters. */
    dbg_assert (ctx);

    /* Are we in a net? */
    if (!MAC_TEI_IS_STA (cp_sta_own_data_get_tei (ctx)))
        return;

    /* Get our net. */
    cp_net_t *net = cp_sta_mgr_get_our_avln (ctx);
    dbg_assert (net);

    /* Go through each STA of our net. */
    sta_t *sta;
    cp_sta_t *cp_sta;
    for (cp_sta = cp_net_sta_get_first (ctx, net, CP_NET_STA_ASSOC);
         cp_sta;
         cp_sta = cp_net_sta_get_next (ctx, net, cp_sta))
    {
        /* Get from mac store a sta from its TEI. */
        sta = mac_store_sta_get (ctx->mac_store, cp_sta_get_tei (cp_sta));
        /* Sta must exist. */
        dbg_assert (sta);
        dbg_assert (sta->tx_tonemaps);
        /* Clean tone maps if error detected by the PBProc. */
        ce_tx_clean_tonemaps (sta->tx_tonemaps);
        /* Decrement expiration timer. */
        if (sta->tx_tonemaps->expiration_s && !--sta->tx_tonemaps->expiration_s)
        {
            /* Reset interval. */
            sta->tx_tonemaps->intervals->intervals_nb = 0;
            sta->tx_tonemaps->default_tmi = TONEMAP_INDEX_INITIAL_START;
            /* Go through each tone map. */
            uint i;
            for (i = NEGOCIATED_TONEMAP_INDEX_FIRST; i < TONEMAP_INDEX_NB;
                 i++)
            {
                /* Release if not used. */
                if (sta->tx_tonemaps->tm[i])
                    tonemap_release (sta->tx_tonemaps, i);
            }
        }
        /* Release STA. */
        blk_release (sta);
    }
}

void
ce_tx_clean_tonemaps (tonemaps_t *tone_maps)
{
    /* Check parameters. */
    dbg_assert (tone_maps);
    /* If default_tmi is set to TONEMAP_INDEX_INITIAL_START (or
     * TONEMAP_INDEX_INITIAL_SOUND_COMPLETE because PBProc could be so fast
     * that it has set TONEMAP_INDEX_INITIAL_START and them
     * TONEMAP_INDEX_INITIAL_SOUND_COMPLETE before we have been called) or
     * TONEMAP_INDEX_INITIAL_ERROR we need to remove all tone maps already
     * allocated (thoses values are set by the PBProc when an error occur
     * and the sound procedure has been restarted ; as the PBProc must be
     * as fast as possible, it only reset the default TMI value ; the
     * cleaning is done by the garbage function of the CP. */
    if (tone_maps->default_tmi == TONEMAP_INDEX_INITIAL_START ||
        tone_maps->default_tmi == TONEMAP_INDEX_INITIAL_SOUND_COMPLETE ||
        tone_maps->default_tmi == TONEMAP_INDEX_INITIAL_ERROR)
    {
        /* Reset interval. */
        tone_maps->intervals->intervals_nb = 0;
        /* Go through each tone map. */
        uint i;
        for (i = NEGOCIATED_TONEMAP_INDEX_FIRST; i < TONEMAP_INDEX_NB;
             i++)
        {
            /* Release if allocated. */
            if (tone_maps->tm[i])
                tonemap_release (tone_maps, i);
        }
    }
}