summaryrefslogtreecommitdiff
path: root/ce/inc/rx.h
blob: 2f0ae3e2fb24726b8b541f02f39269f88a8386ad (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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#ifndef ce_inc_rx_h
#define ce_inc_rx_h
/* Cesar project {{{
 *
 * Copyright (C) 2007 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 *  * \file    ../../inc/rx.h
 *   * \brief   « brief description »
 *    * \ingroup 
 *     *
 *      * « long description »
 *       */

#include "ce/inc/cei_param.h"
#include "ce/inc/mpdu_measure_store.h"
#include "cyg/kernel/kapi.h"
#include "lib/trace.h"
#include "mac/sar/sar.h"
#ifdef MAXIMUS_TEST
#define TXCE
#endif

/** Priority of CEI message */
#define CEI_PRIORITY 2

// The MARGE can be optimized versus the stations number, and the knowledge of
// worst case where rxce can turned.
#ifndef EXPIRATION_TEST
#define RXCE_TONEMAPS_REFRESH_MARGIN_S 2
#define RXCE_TONEMAPS_REFRESH_PERIOD_S (TONEMAPS_LIFE_DURATION_S - RXCE_TONEMAPS_REFRESH_MARGIN_S)
#else
#define RXCE_TONEMAPS_REFRESH_MARGIN_S 1
#define RXCE_TONEMAPS_REFRESH_PERIOD_S (2 - RXCE_TONEMAPS_REFRESH_MARGIN_S)
#endif

/** Structure describing the last received sound frame situation */
struct sound_param_t
{
    uint stei;
    uint reason_code;
};
typedef struct sound_param_t sound_param_t;

/** Global structure for rxce context. */
struct rxce_t
{
    /** Semaphore incremented when rxce has something to do :
     *      -PBproc would have a Sound complete flag.
     *      -A CEI must be built (a cei_param has been added in the
     *      cei_param_fifo.)
     *      -Computation can be done. (A frame measurement has been added, but
     *      not the first).
     *
     */
    cyg_sem_t job;
    mac_store_t *mac_store_ctx;
    /** Pointer to global tonemask */
    u8 *mask;
    /** Received sound frame information.*/
    bool pbproc_need_scf;
    sound_param_t sound_param;

    mpdu_measure_store_t *mpdu_measure_store_ctx;

    /** Tracing system */
#if CONFIG_TRACE
    /** cl Trace */
    trace_buffer_t trace;
#endif /* !CONFIG_TRACE */
};
typedef struct rxce_t rxce_t;

#ifdef EXPIRATION_TEST
typedef void ( *test_cb_t) (int);

void
rxce_init_test_cb (test_cb_t test);

test_cb_t expiration_test;

#endif

BEGIN_DECLS

/**
 * Initialize the global structure of rxce context.
 * \param  mac_store_ctx  Access to the sta.
 * \param  mac_config_ctx  Access to the tonemask.
 * \return  the rxce context.
 *
 */
rxce_t *
rxce_init (sar_t *sar_ctx, mac_store_t *mac_store_ctx, mac_config_t *mac_config_ctx);

/**
 * Callback called by pbproc when it need to have a SCF i.e when it receives a
 * sound frame. If CE is late, pbproc returns a SCF to false.
 * \param  tei  tei of station that has sent the sound frame.
 * \param  src  SoundReasonCode :why station has sent the sound frame.
 *
 * The rxce initialize the pbproc status variables and add a job to do.
 */
void
pbproc_need_scf_cb (uint tei, uint src);

/**
 * Callback called by SAR when it need to has new pb measurement. This
 * function add the pb measurement in the list of frame measurement.
 * \param  user  .
 * \param  rx_params  Frame reception condition.
 * \param  pb_nb  The pb measurement number that the SAR wants to dispose.
 * \param  first  First descriptor and so data block where to store pb
 * measurement.
 * \param  last  Last descriptor and so data block where to store pb
 * measurement.
 */
bool // does channel estimation need pb_measurement?
rxce_mpdu_measurement_add (void *user, pbproc_rx_params_t *rx_params,
                    uint pb_nb, blk_t **first, blk_t **last,
                    pb_t *noise, uint n, uint *blk_offset);

/**
 * Add a 'cei message job' for each tonemaps that must be updated and evaluate
 * the next milestone to redo it.
 * \param  ctx  rxce context
 * \return  the next refresh date.
 *
 * For rx_tonemaps, the expiration_rtc_date must be interpreted as a
 * refresh_rtc_date that is the expiration_rtc_date less a marging to allow the
 * CP to create cei message, to the lower layers to send it, and the
 * destination station to receive it.
 * Dates are expressed in rtc, real-time clock is ecos context, i.e. the tick
 * ecos. (certainly 10ms).
 * Algorithm runs stupidly all tonemaps. An optimized algorithm with a
 * management of a tree could be envisaged.
 */
cyg_tick_count_t
rxce_tonemaps_refresh_management(rxce_t *ctx);

/**
 * Determine the value of SCF that PBproc must answer to the station
 * sound transmitter versus the announced SRC stored in rxce context.
 * \return  SCF to be sent by PBproc.
 *
 * Function called in rxce process when there is a new 'pbproc need scf job'
 * to do.
 */
bool
compute_scf (rxce_t *ctx);

/**
 * Compute the first frame measurement present in the list of frame
 * measurement.
 *
 * Function called in rxce process when there is a 'frame measurement job' to
 * do.
 */
void
rxce_next_measurement_compute (rxce_t *ctx);

/**
 * Main thread of rxce.
 * \param  data allows the pass the rxce context.
 *
 * rxce_process wait on the 'job' semaphore. The several callback can
 * provide new 'jobs'. Three sort of 'job' exists :
 *      -PBproc need to know the scf to return.
 *      -A station need or must receive a CEI to update its set of tonemaps.
 *      -Noise (any frame measurement) are waiting to be computed.
 * Those 'jobs' are described by priority order.
 *
 * More, the semaphore can be timeout in order to ensure tonemaps refresh.
 * Timeout is reestimatimate at each loop of the process thanks to
 * rxce_tonemaps_refresh_management.
 */
void
rxce_process (cyg_addrword_t data);

/**
 * Add a job for rxce that will create and add a cei message to transmit
 * \param  ctx  rxce context.
 * \param  tms  set of tonemaps to encode in cei message.
 * \param  new_tmi  new tmi created if necessary, else NULL_TONEMAP_INDEX.
 * \param  old_tmi  tmi that new_tmi will replace.
 * \param  dtei  destination tei of cei message.
 *
 */
void
rxce_job_cei_add (rxce_t *ctx, uint dtei, tonemaps_t *tms, uint new_tmi, uint old_tmi);

END_DECLS

#endif /* ce_inc_rx_h */