summaryrefslogtreecommitdiff
path: root/ce/test/rx/maximus/src/test_rx.c
blob: a6785deb5a5b9549ccc47ec51eaee95bbec7f457 (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
#include <cyg/infra/diag.h>
#include "common/std.h"
#include "host/station.h"
#include "mac/pbproc/pbproc.h"
#include "mac/sar/sar.h"
#include "cyg/kernel/kapi.h"
#include "cyg/hal/hal_arch.h"
#include "ce/inc/rx.h"
#include "ce/test/common/print_utils.h"
#define TXCE
#include "lib/test.h"
#include "ce/test/common/tonemap_utils.h"

extern station_ctx_t my_station;
test_t test;

#define SAR_PRIORITY 14
cyg_thread sar_thread;
cyg_handle_t sar_handle;
unsigned char sar_stack[CYGNUM_HAL_STACK_SIZE_TYPICAL];

#define RXCE_PRIORITY 15
cyg_thread rxce_thread;
cyg_handle_t rxce_handle;
unsigned char rxce_stack[CYGNUM_HAL_STACK_SIZE_TYPICAL];

mac_store_t *mac_store_ctx;
mac_config_t mac_config_ctx;
sar_t *sar_ctx;
sta_t *sta;
ca_t *ca;
rxce_t *rxce_ctx;

bool
local_sar_mpdu_measurement_cb (void *user, pbproc_rx_params_t *rx_params,
                         uint pb_nb, blk_t **f, blk_t **l, pb_t *noise, uint chandata_nb)
{

    uint i,j;
    diag_printf ("pb_nb = %d\n",pb_nb);
    diag_printf ("noise @Ox%x\n",(unsigned int) noise);
    phy_chandata_t *chandata = (phy_chandata_t *) noise;
    phy_noise_energy_t *data_noise;
    for (i=0;
         i < mpdu_measure_chandata_blk_nb[PHY_CHANDATA_TYPE_NRJ] +
         mpdu_measure_chandata_blk_nb[PHY_CHANDATA_TYPE_NRJ_SYMBOL];
         i++)
    {
        diag_printf ("chandata%d @0x%x : type=%d size=%d last=%d\n", i,
                     (uint) chandata,
                     chandata->type,
                     chandata->size,
                     chandata->last);
        data_noise = (phy_noise_energy_t *) chandata->blk.data;
        for (j=0; j<PHY_NOISE_NB_PER_BLK; j++)
        {
            diag_printf ("0x%x ",*data_noise);
            data_noise++;
        }
        diag_printf ("\n");

        chandata = (phy_chandata_t *) chandata->blk.next;
    }

    return true;
}

void
sar_start (void)
{
    mac_store_sta_add (mac_store_ctx, 1);
    sta = mac_store_sta_get (mac_store_ctx, 1);
    cyg_thread_create (SAR_PRIORITY, &sar_process, (cyg_addrword_t)sar_ctx, "sar_test",
                       sar_stack, CYGNUM_HAL_STACK_SIZE_TYPICAL,
                       &sar_handle, &sar_thread);
    cyg_thread_resume (sar_handle);
}

void
sar_end (void)
{
    blk_release (sta); // release reference to sta added by mac_store_mfs_get in START.
    dbg_check (mac_store_sta_remove (mac_store_ctx, 1));
    blk_release(ca);
    sar_uninit (sar_ctx);
}

void
ce_init (void)
{
    pbproc_t *pbproc_ctx = pbproc_init (&mac_config_ctx, mac_store_ctx);
    ca = blk_alloc();
    sar_ctx = sar_init (mac_store_ctx, pbproc_ctx, ca);
    rxce_ctx = rxce_init (sar_ctx, mac_store_ctx, &mac_config_ctx);
    cyg_thread_create (RXCE_PRIORITY, &rxce_process, (cyg_addrword_t) rxce_ctx, "rxce",
                       rxce_stack, CYGNUM_HAL_STACK_SIZE_TYPICAL,
                       &rxce_handle, &rxce_thread);
}

void
ce_check_stock (fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void *data)
{
    unsigned short pb_nb;
    unsigned short fm_nb;
    uint pb_ix, fm_ix;

    fcall_param_bind_short(*param, *msg, "pb_nb", &pb_nb);
    fcall_param_bind_short(*param, *msg, "frame_nb", &fm_nb);

    test_begin (test, "check pb measurement")
    {
        mpdu_measure_store_t *measure_store_ctx = rxce_ctx->mpdu_measure_store_ctx;
        dbg_assert (measure_store_ctx->measure_nb == fm_nb);
        for (fm_ix=0; fm_ix<fm_nb; fm_ix++)
        {
            pb_measure_blk_t *ber_blk = measure_store_ctx->store[fm_ix].pb_head;
            for (pb_ix=0; pb_ix<pb_nb; pb_ix++)
            {
                if (pb_ix == MPDU_MEASURE_PB_NB_PER_BLK)
                {
                    ber_blk = ber_blk->next;
                }
                pb_measurement_t m = *(ber_blk->data+(pb_ix%MPDU_MEASURE_PB_NB_PER_BLK));
                test_fail_if (m.halfit != 0x04);
                test_fail_if ( m.ber != (1<< (pb_ix%16)) );
                test_fail_if ( m.crc_error != (pb_ix%2) );
            }
        }
    } test_end;
    fcall_param_reset(*param);
    return;
}

void
ce_check_computation (void)
{
    sta_t *sta = mac_store_sta_get (mac_store_ctx, 1);
    ce_print_tonemaps (sta->rx_tonemaps);
    ce_print_tonemaps (sta->tx_tonemaps);

    compare_tonemaps (test, sta->rx_tonemaps, sta->tx_tonemaps,
                      (u8 *)(&(mac_config_ctx.tonemask_info.tonemask)));
    test_result (test);
    return;
}

void
ce_start (void)
{
    cyg_thread_resume (rxce_handle);
}

int
test_result_get (fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void *data)
{
    unsigned short result;
    result = (test_nb_failed (test));
    fcall_param_reset(*param);
    fcall_param_add_short(*param, *msg, "test_result", &result);
    return (result);
}

int main(void)
{
    trace_init();
    test_init (test, 0, NULL);
    test_case_begin (test, "RXCE-maximus");
    station_log_set_level(&my_station, STATION_LOG_NONE);
    station_log_set_mask(&my_station, STATION_LOGTYPE_ALL);
    my_station.pipe_log_fd = 1;
    diag_write_string(" hello by eCos in maximus test\n");
    fcall_register(my_station.fcall, "sar_start", (void*)&sar_start, NULL);
    fcall_register(my_station.fcall, "ce_init", (void*)&ce_init, NULL);
    fcall_register(my_station.fcall, "ce_check_stock", (void*)&ce_check_stock, NULL);
    fcall_register(my_station.fcall, "ce_start", (void*)&ce_start, NULL);
    fcall_register(my_station.fcall, "ce_check_computation", (void*)&ce_check_computation, NULL);
    fcall_register(my_station.fcall, "prepare_rx", (void*)&prepare_rx, NULL);
    fcall_register(my_station.fcall, "test_result_get", (void*)&test_result_get, NULL);

    mac_config_init (&mac_config_ctx);

    mac_store_ctx = mac_store_init ();

    return 0;
}