summaryrefslogtreecommitdiff
path: root/cesar/maximus/stationtest/src/test_tx_rx.c
blob: 32b3f719d60c235df54ad7905cf09a5f5670d22e (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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
/* Cesar project {{{
 *
 * Copyright (C) 2007 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    test_tx_rx.c
 * \brief   station executable used for the test tx rx program
 * \ingroup 
 */

#include <cyg/infra/diag.h>
#include <cyg/kernel/kapi.h>
#include <errno.h>
#include "common/std.h"
#include "host/station/station.h"
#include "hal/phy/phy.h"
#include "mac/common/defs.h"
#include "hal/phy/maximus/inc/maximus_phy_ctx.h" // for 'phy_t'
#include "hal/phy/maximus/inc/maximus_interrupts.h" // for 'PHY_HAL_INTERRUPT_...'

extern station_ctx_t my_station;
phy_t * ctx;
int user_data = 123;

unsigned short fc_mode = 0;
bool short_ppdu = false;
unsigned short mod = 0;
unsigned short fecrate = 0;
unsigned short pb_size = 0;
unsigned short gil = 0;
unsigned short pb_nb = 0;

// For noise
phy_chandata_t freq_chan[6];
phy_chandata_t time_chan;
u8 freq_chan_data[6][MAC_PB520_BYTES];
u8 time_chan_data[MAC_PB520_BYTES];


void start_pbdma (void)
{
    diag_write_string("=> start_pbdma\n");

    int i = 0;
    char c = 0;

    static u32 nek[4];

    // Test with maximum 10 PBs of 512 octets
    int pb_length = MAC_MAX_PB_PER_MPDU;
    static u8 pb_data[MAC_MAX_PB_PER_MPDU][MAC_PB520_BYTES];
    static phy_pb_t pb[MAC_MAX_PB_PER_MPDU];

    // Start PBDMA
    for (i=0; i<pb_length; i++)
    {
        memset(&pb_data[i][0], c, MAC_PB520_BYTES);
        pb[i].pb_rx.blk.data = &pb_data[i][0];
        if (i != pb_length-1)
        {
            pb[i].pb_rx.blk.next = &pb[i+1].pb_rx.blk;
        }
        else
        {
            pb[i].pb_rx.blk.next = NULL;
        }
        c++;
    }
    for (i=0; i<4; i++)
    {
      nek[i] = i;
    }
    phy_pbdma_start(ctx, true /* bypass_aes */,
                    nek, (uint)pb_nb /* nb_total */, (uint)pb_nb /* nb_ready */,
                    (uint)pb_nb /* nb_pb_it */, &pb[0], NULL, false);
}


void start_pbdma_chandata (void)
{
    diag_write_string("=> start_pbdma_chandata\n");

    int i = 0;
    char c = 0;

    // For noise
    int transfer_size = 128;
    int chan_length = ((PHY_CARRIER_NB * sizeof(u16)) + ((4 * transfer_size) - 1 )) / (4 * transfer_size);

    // Time noise
    memset(time_chan_data, c, MAC_PB520_BYTES);
    time_chan.blk.data = time_chan_data;
    time_chan.blk.next = &freq_chan[0].blk;
    time_chan.conf.size = transfer_size;
    time_chan.conf.last = 0;
    time_chan.conf.type = PHY_CHANDATA_TYPE_NRJ_SYMBOL;
    time_chan.conf.address = 0;

    // Frequency noise
    for (i=0; i<chan_length; i++)
    {
        memset(&freq_chan_data[i][0], c, MAC_PB520_BYTES);
        freq_chan[i].blk.data = &freq_chan_data[i][0];
        if (i != chan_length-1)
        {
            freq_chan[i].blk.next = &freq_chan[i+1].blk;
            freq_chan[i].conf.last = 0;
        }
        else
        {
            freq_chan[i].blk.next = NULL;
            freq_chan[i].conf.last = 1;
        }
        freq_chan[i].conf.size = transfer_size;
        freq_chan[i].conf.type = PHY_CHANDATA_TYPE_NRJ;
        freq_chan[i].conf.address = 0;
        c++;
    }

    phy_pbdma_start_chandata(ctx, &time_chan);
}


bool phy_rx_fc_cb (void *user, u32 rx_date, const u32 *fc_av)
{
    diag_write_string("=> phy_rx_fc_cb\n");

    // Reset IT
    maximus_pending_isrs &= (0 << PHY_HAL_INTERRUPT_PHY);

    // When the FC is received, prepare RX
    phy_rx_prepare(ctx, PHY_COMBO_PARAMS (mod, fecrate, pb_size),
                   (phy_gil_t)gil, 0);

    return true;    
}


bool phy_access_cb (void *user)
{
    diag_write_string("=> phy_access_cb\n");

    // Reset IT
    maximus_pending_isrs &= (0 << PHY_HAL_INTERRUPT_PHY);

    return true;
}


bool phy_access_conf_cb (void *user)
{
    diag_write_string("=> phy_access_conf_cb\n");

    // Reset IT
    maximus_pending_isrs &= (0 << PHY_HAL_INTERRUPT_PHY);

    return true;
}


bool phy_pbdma_cb (void *user, u32 status_word)
{
    diag_write_string("=> phy_pbdma_cb\n");

    // Reset IT
    maximus_pending_isrs &= (0 << PHY_HAL_INTERRUPT_PBDMA);

    phy_pbdma_status_t status = *((phy_pbdma_status_t*)&status_word);
    if (status.end_rx_pb)
    {
        // Set TX parameters
        if (ctx->control.rx_param.short_ppdu)
            phy_tx_param_short (ctx, ctx->control.rx_param.fc_mode);
        else
            phy_tx_param (ctx, ctx->control.rx_param.fc_mode,
                          PHY_COMBO_PARAMS (ctx->control.rx_param.mod,
                                            ctx->control.rx_param.fecrate,
                                            ctx->control.rx_param.pb_size),
                          ctx->control.rx_param.gil);
        if (0 != ctx->control.rx_param.fc_10)
        {
            phy_tx_fc10 (ctx, (u32)my_station.current_tick_tck +
                         PHY_FC_10_PREPARATION_DELAY_TCK, ctx->control.rx_param.fc_10);
        }

        if (!ctx->control.rx_param.short_ppdu)
        {
            // Start PBDMA
            phy_pbdma_start(ctx, ctx->pbdma.bypass_aes,
                            ctx->pbdma.nek, (uint)pb_nb /* nb_total */, (uint)pb_nb /* nb_ready */,
                            (uint)pb_nb /* nb_pb_it */, ctx->pbdma.first_pb,
                            NULL, false);
        }

        phy_tx_frame (ctx, (u32)my_station.current_tick_tck + PHY_FC_10_PREPARATION_DELAY_TCK,
                      false /* want_conf */, false /* stop_tx_on_prp_lost */, ctx->control.rx_param.fc_av);
    }

    return true;
}


bool phy_tx_false_alarm_cb (void *user)
{
    diag_write_string("=> phy_tx_false_alarm_cb\n");

    // Reset IT
    maximus_pending_isrs &= (0 << PHY_HAL_INTERRUPT_PHY);

    return true;
}


void phy_deferred_cb (void *user)
{
    diag_write_string("=> phy_deferred_cb\n");

    return;
}


bool phy_extra_timer_cb (void *user)
{
    diag_write_string("=> phy_extra_timer_cb\n");

    // Reset IT
    maximus_pending_isrs &= (0 << PHY_HAL_INTERRUPT_PHY);

    return true;
}


int set_tonemask (fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void *data)
{
    u8 tonemask[(PHY_CARRIER_NB+7)/8];
    blk_t tonemap1;
    blk_t tonemap2;
    u8 tonemap1_data[MAC_PB520_BYTES];
    u8 tonemap2_data[(PHY_CARRIER_NB+1)/2-MAC_PB520_BYTES];
    int i = 0;

    diag_write_string("=> set_tonemask\n");

    // Initialize the HAL PHY
    ctx = phy_init ((void *)&user_data, &phy_rx_fc_cb, &phy_access_cb, &phy_access_conf_cb, &phy_pbdma_cb, &phy_tx_false_alarm_cb, &phy_deferred_cb);

    // Enable assertions on warnings
    ctx->warning_assert = true;

    // Set TONEMASK
    for (i=0; i<(PHY_CARRIER_NB+7)/8; i++)
    {
      tonemask[i] = 0xEE;
    }
    phy_set_tonemask(ctx, (u32 *)tonemask, PHY_CARRIER_NB);

    // Set TONEMAP
    memset(tonemap1_data, 'b', MAC_PB520_BYTES*sizeof(u8));
    memset(tonemap2_data, 'c', ((PHY_CARRIER_NB+1)/2-MAC_PB520_BYTES)*sizeof(u8));
    tonemap2.next = NULL;
    tonemap2.data = tonemap2_data;
    tonemap1.next = &tonemap2;
    tonemap1.data = tonemap1_data;
    phy_set_tonemap(ctx, &tonemap1);

    /* now make the return parameter list */
    fcall_param_reset(*param);

    return 0; 
}


int prepare_rx (fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void *data)
{
    diag_write_string("=> prepare_rx\n");

    /* get parameters content */
    fcall_param_bind_short(*param, *msg, "fc_mode", &fc_mode);
    fcall_param_bind(*param, *msg, "short_ppdu", sizeof(bool), &short_ppdu);
    if (!short_ppdu)
    {
        fcall_param_bind_short(*param, *msg, "mod", &mod);
        fcall_param_bind_short(*param, *msg, "fecrate", &fecrate);
        fcall_param_bind_short(*param, *msg, "pb_size", &pb_size);
        fcall_param_bind_short(*param, *msg, "gil", &gil);
        fcall_param_bind_short(*param, *msg, "pb_nb", &pb_nb);
    }

    // Activate RX
    phy_rx_activate(ctx, true /* now */, my_station.current_tick_tck, true /* pre_detection */);

    // Set RX parameters
    phy_rx_param(ctx, (phy_fc_mode_t)fc_mode);

    if (!short_ppdu)
    {
        // Start PBDMA
        start_pbdma();

        // Start PBDMA chandata
        start_pbdma_chandata();
    }

    /* now make the return parameter list */
    fcall_param_reset(*param);

    return 0;
}


int uninit_phy (fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void *data)
{
    diag_write_string("=> uninit_phy\n");

    // Uninitialize the HAL PHY
    phy_uninit (ctx);

    /* now make the return parameter list */
    fcall_param_reset(*param);

    return 0; 
}


int main (void)
{
    station_log_set_level(&my_station, STATION_LOG_DEBUG);
    station_log_set_mask(&my_station, STATION_LOGTYPE_ALL);
    my_station.pipe_log_fd = 1;

    fcall_register(my_station.fcall, "set_tonemask", (void*)&set_tonemask, NULL);
    fcall_register(my_station.fcall, "prepare_rx", (void*)&prepare_rx, NULL);
    fcall_register(my_station.fcall, "uninit_phy", (void*)&uninit_phy, NULL);

    return 0;
}