summaryrefslogtreecommitdiff
path: root/cesar/ce/rx/inc/rx.h
blob: b8412d5ef070d885deaa847a956d7e58ec8c3ca5 (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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#ifndef ce_rx_inc_rx_h
#define ce_rx_inc_rx_h
/* Cesar project {{{
 *
 * Copyright (C) 2009 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    ce/rx/inc/rx.h
 * \brief   Channel Estimation in Receive mode (private part).
 * \ingroup ce_rx
 *
 * This header provide the private declaration of the CE in RX.
 */

#include "mac/common/tonemap.h"
#include "mac/common/store.h"
#include "lib/mbox.h"
#include "lib/slab.h"

/* In order to include this header without eCos support, let's only include
 * and define eCos variable when we are building for an eCos target. */
#if defined (ECOS) && ECOS
#   include <cyg/kernel/kapi.h>
#   include <cyg/hal/hal_arch.h>
#endif

#include "ce/rx/cp/cp.h"

#include "ce/rx/bitloading/inc/initial.h"
#include "ce/rx/bitloading/inc/bitloading.h"
#include "common/defs/priority.h"
#include "ce/rx/inc/trace.h"

/**
 * Thread name of the CE in RX.
 */
#define CE_RX_THREAD_NAME "CE_RX"

/**
 * Statistics of the CE in RX.
 */
typedef struct ce_rx_stat_t
{
    /**
     * How many times we have re-sent (not just send) the tone map because TX
     * is not using it.
     */
    uint resend_tm;
} ce_rx_stat_t;

struct ce_rx_t
{
    /**
     * Pointer to the MAC store context.
     */
    mac_store_t *mac_store;
    /**
     * Pointer to the MAC config context.
     */
    mac_config_t *mac_config;
#if defined (ECOS) && ECOS
    /**
     * Flag to know if the CE in RX thread has something to do.
     * Basically, the CE in RX thread sleep until another thread tell it to do
     * something (process measurements, stop, ...).
     */
    cyg_flag_t work_flag;
    /**
     * Stack used bu the thread.
     */
    u8 thread_stack[CE_RX_THREAD_STACK_SIZE];
    /**
     * ECos thread handler.
     */
    cyg_handle_t thread_handler;
    /**
     * The CE in RX ECos thread.
     */
    cyg_thread thread;
#endif
    /**
     * Stop the CE in RX.
     */
    bool stop_flag;
    /**
     * List of released tone maps.
     */
    tonemap_release_list_t tonemap_release_list;
    /**
     * Mailbox for the measure communication.
     */
    mbox_t measure_mbox;
    /**
     * Cache slab allocator for the mailbox nodes.
     */
    slab_cache_t measure_cache;
    /**
     * Mailbox for the exchange wih the CP.
     */
    mbox_t cp_mbox;
    /**
     * Cache SLAB allocator for the CP mailbox nodes.
     */
    slab_cache_t cp_mbox_cache;
    /**
     * The CP context that need to be contacted when we send MME.
     */
    cp_t *cp_ctx;
    /**
     * The callback that need to be called when we need to send a MME.
     */
    ce_rx_cp_signal_work_t cp_cb;
#if defined (ECOS) && ECOS
    /**
     * eCos real-time clock handler (for real-time clock timers/alarms).
     */
    cyg_handle_t real_time_clock_handle;
    /**
     * eCos real-time counter (for real-time clock timers/alarms).
     */
    cyg_handle_t real_time_counter;
    /**
     * eCos alarm.
     */
    cyg_alarm alarm;
    /**
     * eCos alarm handler.
     */
    cyg_handle_t alarm_handler;
#endif
#if CONFIG_TRACE
    /**
     * CE/RX trace buffer, important.
     */
    trace_buffer_t trace;
    /**
     * CE/RX trace verbose (less important).
     */
    trace_buffer_t trace_verbose;
#endif
    /**
     * Tick per RTC, for eCos timer & co.
     */
    u32 tck_per_rtc;
    /**
     * Extra tone mask context used to handle faulty carriers.
     */
    tonemask_info_t tonemask;
    /**
     * Statistics.
     */
    ce_rx_stat_t stats;
    /**
     * Context of the bsu aclf used to retrieve the theoretical beacon
     * period duration.
     */
    bsu_aclf_t *aclf;
};

/**
 * Function prototype to calls when flag is set.
 */
typedef void (*ce_rx_process_work_t) (ce_rx_t *);

/**
 * List of supported flags for work supported by the CE in RX.
 * This list correspond to the position of the flag in the bitfield.
 */
typedef enum ce_rx_work_flag_t
{
    /** Stop the CE in RX thread. */
    CE_RX_WORK_FLAG_QUIT = 0,
    /** Measurements processing from SAR. */
    CE_RX_WORK_FLAG_MEASURE = 1,
    /** Size of this enum. */
    CE_RX_WORK_FLAG_SIZE
} ce_rx_work_flag_t;

BEGIN_DECLS

#if defined (ECOS) && ECOS
/**
 * Main function of the CE RX thread.
 * \param  data  the CE RX context.
 */
void
ce_rx_thread (cyg_addrword_t data);
#endif

/**
 * Add work for the CE RX thread.
 * \param  ce_rx  the context of the CE RX.
 * \param  work  the work to add to the CE RX.
 */
void
ce_rx_work_add (ce_rx_t *ce_rx, ce_rx_work_flag_t work);

/**
 * Process quit request from other threads.
 * \param  ce_rx  the CE in RX context.
 */
void
ce_rx_process_work_quit (ce_rx_t *ce_rx);

/**
 * Process new measure from the SAR.
 * \param  ce_rx  the CE in RX context.
 */
void
ce_rx_process_work_measure (ce_rx_t *ce_rx);

#if defined (ECOS) && ECOS
/**
 * Prevent tone maps expiration.
 * This function is called every one second to go through each STA and check
 * if we need to send a MME to prevent tone maps expiration.
 * \param  alarm  the eCos alarm handler.
 * \param  data  the data associated.
 */
void
ce_rx_timer_prevent_tone_map_expiration (cyg_handle_t alarm_handler,
                                         cyg_addrword_t data);
#endif

/**
 * Initialize statistics of the CE in RX.
 * \param  ce_rx  the CE in RX context.
 */
void
ce_rx_stats_init (ce_rx_t *ce_rx);

END_DECLS

#endif /* ce_rx_inc_rx_h */