summaryrefslogtreecommitdiff
path: root/cesar/maximus/stationtest/src/test_send.c
blob: bcb264b16302cdd72dc9352871764968b491650a (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
/* Cesar project {{{
 *
 * Copyright (C) 2007 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    test_send.c
 * \brief   station executable used for the test send 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'

extern station_ctx_t my_station;
phy_t * ctx;
int user_data = 123;
bool short_ppdu = false;
unsigned short mod = 0;
unsigned short fecrate = 0;
unsigned short pb_size = 0;
unsigned short gil = 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];

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

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

    return true;    
}

bool phy_access_cb (void *user)
{
    return true;
}

bool phy_access_conf_cb (void *user)
{
    return true;  
}

bool phy_pbdma_cb (void *user, u32 status_word)
{
    return true;   
}

bool phy_tx_false_alarm_cb (void *user)
{
    return true;
}

void phy_deferred_cb (void *user)
{
    return;
}

bool phy_extra_timer_cb (void *user)
{
    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];
    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);

    /* 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)
{
    unsigned short fc_mode = 0;
    unsigned short pb_nb = 0;
    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];
    
    // For noise
    int transfer_size = 128;
    int chan_length = ((PHY_CARRIER_NB * sizeof(u16)) + ((4 * transfer_size) - 1 )) / (4 * transfer_size);

    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);

    // 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_pb_it */,
                    &pb[0], NULL, true);

    // Start chandata
    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;
        }
        else
        {
            freq_chan[i].blk.next = &time_chan.blk;
        }
        freq_chan[i].conf.size = transfer_size;
        freq_chan[i].conf.last = 0;
        freq_chan[i].conf.type = PHY_CHANDATA_TYPE_NRJ;
        freq_chan[i].conf.address = 0;
        c++;
    }
    memset(time_chan_data, c, MAC_PB520_BYTES);
    time_chan.blk.data = time_chan_data;
    time_chan.blk.next = NULL;
    time_chan.conf.size = transfer_size;
    time_chan.conf.last = 1;
    time_chan.conf.type = PHY_CHANDATA_TYPE_NRJ_SYMBOL;
    time_chan.conf.address = 0;

    phy_pbdma_start_chandata(ctx, freq_chan);

    /* 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;
}