summaryrefslogtreecommitdiff
path: root/mac/sar/test/src/ce.c
blob: a56c7019c990d019c315402b6b850ad9e7dffb46 (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
128
129
130
131
132
133
134
135
136
137
138
139
140
/* Cesar project {{{
 *
 * Copyright (C) 2007 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    ce.c
 * \brief   Context of the CE
 * \ingroup mac/sar/test/src
 * 
 * contains a minimum of the CE data to take the measurement of the PBs.
 * 
 */

#include "common/std.h"
#include "mac/sar/test/inc/ce.h"

/**
 * Init the CE and get the context pointer.
 */
ce_t *ce_init (void)
{
    ce_ctx.measurement_head = NULL;
    ce_ctx.measurement_tail = NULL;

    ce_ctx.rx_params_head = NULL;
    ce_ctx.rx_params_tail = NULL;

    return &ce_ctx;
}

/**
 * Pb measurement RX callback for Channel estimation.
 * This call back will return one or two block in order to insert all the 
 * measurements contained in each PB of the mpdu received.
 * Two cases can happen, the first the pb_nb is lesser than the blk capacity, 
 * this callback will return only a blk pointed by the first and the last 
 * pointer.
 * In the second case the quantity of PB are greater than one blk capacity, this
 * callback will return two blk (chained) the first pointed by the first pointer
 * and the last one by the last pointer.
 * 
 * \param  user User data 
 * \param  rx_params Frame control information to know date and tonemap used
 * \param  number of pbs
 * \param  first blk to insert the measurements.
 * \param  last blk to insert the measurements.
 * \param  chandata chan data measurements
 * 
 * \return boolean to indicate if a block had been returned or not.
 */
bool ce_measurements (void *user, pbproc_rx_params_t *rx_params, uint pb_nb,
        blk_t **first, blk_t **last, pb_t *chandata, uint nb_chandata, uint
        *blk_offset)
{
    ce_store_rx_params_t *ce_rx_params = NULL;

    /*
     * author nelio
     * 26 sept. 07 - 09:56:56
     *
     * Not use by the SAR the rx_params are only copied from the CA to provide
     * it to the CE.
     */

    dbg_assert (rx_params);
    ce_rx_params = blk_alloc ();

    /* If the quantity of PBs are greater than 128 allocates two BLK */
    if (pb_nb > 128)
    {
        *first = blk_alloc_desc ();
        *last = blk_alloc_desc ();
        ((blk_t *)*first)->next = *last;
    }
    else
    {
        *first = blk_alloc_desc ();
        *last = *first;
    }

    /* Keep it in the structure */
    if (ce_ctx.measurement_head == NULL)
    {
        ce_ctx.measurement_head = *first;
        ce_ctx.measurement_tail = *last;
    }
    else
    {
        ce_ctx.measurement_tail->next = *first;
        ce_ctx.measurement_tail = *last;
    }

    /* allocate the structure to store the rx_params */
    ce_rx_params->rx_params = rx_params;

    /* Store the rx_params to the structure */
    if (ce_ctx.rx_params_head == NULL)
    {
        ce_ctx.rx_params_head = ce_rx_params;
        ce_ctx.rx_params_tail = ce_rx_params;
    }
    else
    {
        ce_ctx.rx_params_tail->next = ce_rx_params;
        ce_ctx.rx_params_tail = ce_rx_params;
    }
    ce_ctx.rx_params_tail->next = NULL;

    ce_ctx.chandata = chandata;

    ((blk_t *)*last)->next = NULL;
    *blk_offset = 0;

    return true;
}

void ce_uninit (void)
{
    ce_store_rx_params_t *tmp;

    blk_t *curr;
    while (ce_ctx.measurement_head)
    {
        curr = ce_ctx.measurement_head;
        ce_ctx.measurement_head = ce_ctx.measurement_head->next;

        blk_release_desc (curr);
    }

    while (ce_ctx.rx_params_head)
    {
        tmp = ce_ctx.rx_params_head;
        ce_ctx.rx_params_head = ce_ctx.rx_params_head->next;
        blk_release (tmp->rx_params);
        blk_release (tmp);
    }
}