summaryrefslogtreecommitdiff
path: root/cesar/mac/pbproc/test/pbproc_eoc/src/phy.c
blob: a25696b83bb612d2a6ee76d01f902eec07619f63 (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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
/* Cesar project {{{
 *
 * Copyright (C) 2007 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    src/phy.c
 * \brief   Override HAL Phy functions.
 * \ingroup test
 */
#include "common/std.h"

#include "hal/phy/phy.h"
#include "hal/phy/pbdma.h"

#include "hal/phy/inc/context.h"

#include "lib/scenario/scenario.h"

static phy_t phy_global;

phy_t *
phy_init (void *user_data, phy_rx_fc_cb_t rx_fc_cb, phy_access_cb_t access_cb,
          phy_access_conf_cb_t access_conf_cb, phy_pbdma_cb_t pbdma_cb,
          phy_tx_false_alarm_cb_t tx_false_alarm_cb,
          phy_deferred_cb_t deferred_cb)
{
    phy_t *ctx = &phy_global;
    ctx->current_date = 0;
    ctx->user_data = user_data;
    ctx->rx_fc_cb = rx_fc_cb;
    ctx->access_cb = access_cb;
    ctx->access_conf_cb = access_conf_cb;
    ctx->pbdma_cb = pbdma_cb;
    ctx->tx_false_alarm_cb = tx_false_alarm_cb;
    ctx->deferred_cb = deferred_cb;
    ctx->prp_won = false;
    ctx->slot_count = 0;
    ctx->pbdma_nb_total = 0;
    ctx->pbdma_first_pb = NULL;
    uint i;
    for (i = 0; i < COUNT (ctx->tx_fc); i++)
        ctx->tx_fc[i] = 0;
    for (i = 0; i < COUNT (ctx->crc_bitmap); i++)
        ctx->crc_bitmap[i] = 0;
    return ctx;
}

void
phy_check_hardware (phy_t *ctx)
{
}

void
phy_uninit (phy_t *ctx)
{
}

void
phy_prepare (phy_t *ctx, phy_prepare_type_t type, bool wait)
{
    scenario_event (phy_prepare, params);
    dbg_assert (ctx);
    test_fail_unless (type == params->type);
    test_fail_unless (wait == params->wait);
}

void
phy_deferred_schedule (phy_t *ctx)
{
    scenario_event (phy_deferred_schedule);
    dbg_assert (ctx);
    ctx->dsr_scheduled = true;
}

u32
phy_date (void)
{
    return phy_global.current_date;
}

void
phy_set_tonemask (phy_t *ctx, u32 *tonemask, uint carrier_nb)
{
}

void
phy_set_tonemap (phy_t *ctx, blk_t *tonemap)
{
    scenario_event (phy_set_tonemap);
    /* Test tonemap? */
}

void
phy_freq_error_set (phy_t *ctx, bool sync, s32 rho_q30)
{
    scenario_event (phy_freq_error_set, params);
    test_fail_unless (sync == params->sync);
    test_fail_unless (rho_q30 == params->rho_q30);
}

void
phy_tx_fc10 (phy_t *ctx, u32 date, u32 fc_10)
{
    scenario_event (phy_tx_fc10, params);
    test_fail_unless (date == params->date);
    test_fail_unless (fc_10 == params->fc10);
}

void
phy_tx_param_ (phy_t *ctx, phy_fc_mode_t fc_mode, u32 mod_fecrate_pb_size,
               phy_gil_t gil PHY_TRACE_SYMBOL_NB (uint symbol_nb))
{
    phy_mod_t mod = BF_GET (PHY_COMBO_PARAMS__MOD, mod_fecrate_pb_size);
    phy_fecrate_t fecrate = BF_GET (PHY_COMBO_PARAMS__FECRATE,
                                    mod_fecrate_pb_size);
    phy_pb_size_t pb_size = BF_GET (PHY_COMBO_PARAMS__PB_SIZE,
                                    mod_fecrate_pb_size);
    scenario_event (phy_tx_param, params);
    test_fail_unless (fc_mode == params->fc_mode);
    test_fail_unless (mod == params->mod);
    test_fail_unless (fecrate == params->fecrate);
    test_fail_unless (pb_size == params->pb_size);
    test_fail_unless (gil == params->gil);
#if CONFIG_TRACE
    test_fail_unless (symbol_nb == params->symbol_nb);
#endif
}

void
phy_tx_param_short (phy_t *ctx, phy_fc_mode_t fc_mode)
{
    scenario_event (phy_tx_param_short, params);
    test_fail_unless (fc_mode == params->fc_mode);
}

void
phy_tx_param_sound_ (phy_t *ctx, phy_fc_mode_t fc_mode, uint nb_pb,
                     u32 mod_fecrate_pb_size, phy_gil_t gil
                     PHY_TRACE_SYMBOL_NB (uint symbol_nb))
{
    phy_mod_t mod = BF_GET (PHY_COMBO_PARAMS__MOD, mod_fecrate_pb_size);
    phy_fecrate_t fecrate = BF_GET (PHY_COMBO_PARAMS__FECRATE,
                                    mod_fecrate_pb_size);
    phy_pb_size_t pb_size = BF_GET (PHY_COMBO_PARAMS__PB_SIZE,
                                    mod_fecrate_pb_size);
    scenario_event (phy_tx_param_sound, params);
    test_fail_unless (fc_mode == params->fc_mode);
    test_fail_unless (nb_pb == params->nb_pb);
    test_fail_unless (mod == params->mod);
    test_fail_unless (fecrate == params->fecrate);
    test_fail_unless (pb_size == params->pb_size);
    test_fail_unless (gil == params->gil);
#if CONFIG_TRACE
    test_fail_unless (symbol_nb == params->symbol_nb);
#endif
}

void
phy_tx_frame_ (phy_t *ctx, u32 date, u32 want_conf__stop_tx_on_prp_lost,
               const u32 fc_av[4])
{
    bool want_conf = (want_conf__stop_tx_on_prp_lost & PHY_WANT_CONF)
        ? true : false;
    bool stop_tx_on_prp_lost = (want_conf__stop_tx_on_prp_lost
                                & PHY_STOP_ON_PRP_LOST) ? true : false;
    scenario_event (phy_tx_frame, params);
    test_fail_unless (date == params->date);
    test_fail_unless (want_conf == params->want_conf);
    test_fail_unless (stop_tx_on_prp_lost == params->stop_tx_on_prp_lost);
    ctx->tx_fc[0] = fc_av[0];
    ctx->tx_fc[1] = fc_av[1];
    ctx->tx_fc[2] = fc_av[2];
    ctx->tx_fc[3] = fc_av[3];
}

void
phy_tx_prepare (phy_t *ctx)
{
    scenario_event (phy_tx_prepare);
    test_fail_unless (ctx->pbdma_nb_total != 0);
}

void
phy_tx_cancel (phy_t *ctx)
{
    scenario_event (phy_tx_cancel);
}

void
phy_rx_param (phy_t *ctx, phy_fc_mode_t fc_mode)
{
    scenario_event (phy_rx_param, params);
    test_fail_unless (fc_mode == params->fc_mode);
}

void
phy_rx_activate (phy_t *ctx, bool now, u32 date, bool pre_detection)
{
    scenario_event (phy_rx_activate, params);
    test_fail_unless (now == params->now);
    test_fail_unless (date == params->date);
    test_fail_unless (pre_detection == params->pre_detection);
}

void
phy_rx_prepare (phy_t *ctx, uint nb_pb, u32 mod_fecrate_pb_size,
                phy_gil_t gil, uint symbol_nb, uint tcc_halfit)
{
    phy_mod_t mod = BF_GET (PHY_COMBO_PARAMS__MOD, mod_fecrate_pb_size);
    phy_fecrate_t fecrate = BF_GET (PHY_COMBO_PARAMS__FECRATE,
                                    mod_fecrate_pb_size);
    phy_pb_size_t pb_size = BF_GET (PHY_COMBO_PARAMS__PB_SIZE,
                                    mod_fecrate_pb_size);
    scenario_event (phy_rx_prepare, params);
    test_fail_unless (nb_pb == params->nb_pb);
    test_fail_unless (mod == params->mod);
    test_fail_unless (fecrate == params->fecrate);
    test_fail_unless (pb_size == params->pb_size);
    test_fail_unless (gil == params->gil);
    test_fail_unless (symbol_nb == params->symbol_nb);
    test_fail_unless (tcc_halfit == params->tcc_halfit);
}

void
phy_rx_prepare_short (phy_t *ctx)
{
    scenario_event (phy_rx_prepare_short);
}

void
phy_rx_prepare_sound (phy_t *ctx, uint nb_pb, u32 mod_fecrate_pb_size,
                      phy_gil_t gil, uint symbol_nb)
{
    phy_mod_t mod = BF_GET (PHY_COMBO_PARAMS__MOD, mod_fecrate_pb_size);
    phy_fecrate_t fecrate = BF_GET (PHY_COMBO_PARAMS__FECRATE,
                                    mod_fecrate_pb_size);
    phy_pb_size_t pb_size = BF_GET (PHY_COMBO_PARAMS__PB_SIZE,
                                    mod_fecrate_pb_size);
    scenario_event (phy_rx_prepare_sound, params);
    test_fail_unless (nb_pb == params->nb_pb);
    test_fail_unless (mod == params->mod);
    test_fail_unless (fecrate == params->fecrate);
    test_fail_unless (pb_size == params->pb_size);
    test_fail_unless (gil == params->gil);
    test_fail_unless (symbol_nb == params->symbol_nb);
}

u32
phy_rx_fc10 (phy_t *ctx)
{
    dbg_assert (ctx);
    return ctx->fc10;
}

u32
phy_rx_sysdate (phy_t *ctx)
{
    dbg_assert (ctx);
    return ctx->rx_sysdate;
}

void
phy_access_timer_cancel (phy_t *ctx)
{
    dbg_assert (ctx);
    scenario_event (phy_access_timer_cancel);
}

void
phy_extra_timer_init (phy_t *ctx, void *extra_timer_user_data,
                      phy_extra_timer_cb_t extra_timer_cb)
{
    dbg_assert (ctx);
    dbg_assert (extra_timer_user_data == ctx->user_data);
    ctx->extra_timer_cb = extra_timer_cb;
}

void
phy_extra_timer_program (phy_t *ctx, u32 date)
{
    dbg_assert (ctx);
    scenario_event (phy_extra_timer_program, params);
    test_fail_unless (date == params->date);
}

void
phy_access_timer_program (phy_t *ctx, u32 date)
{
    dbg_assert (ctx);
}

uint
phy_access_backoff_slot_count (phy_t *ctx)
{
    dbg_assert (ctx);
    return ctx->slot_count;
}

bool
phy_access_backoff_prp_won (phy_t *ctx)
{
    dbg_assert (ctx);
    return ctx->prp_won;
}

void
phy_pbdma_start (phy_t *ctx, bool bypass_aes, const u32 nek[4], uint nb_total,
                 uint nb_pb_it, phy_pb_t *first_pb,
                 phy_chandata_t *first_chandata, bool now)
{
    scenario_event (phy_pbdma_start, params);
    test_fail_unless (bypass_aes == params->bypass_aes);
    test_fail_unless (nb_total == params->nb_total);
    test_fail_unless (nb_pb_it == params->nb_pb_it);
    test_fail_unless ((first_chandata ? true : false) == params->chandata);
    test_fail_unless (now == params->now);
    ctx->pbdma_nb_total = nb_total;
    ctx->pbdma_first_pb = first_pb;
}

void
phy_pbdma_update (phy_t *ctx, uint nb_pb_it)
{
    scenario_event (phy_pbdma_update, params);
    test_fail_unless (nb_pb_it == params->nb_pb_it);
}

phy_pb_t *
phy_pbdma_get_tail (phy_t *ctx)
{
    dbg_assert (ctx);
    uint i;
    phy_pb_t *pb;
    for (i = 1, pb = ctx->pbdma_first_pb;
         i < ctx->pbdma_nb_total;
         i++, pb = PARENT_OF (phy_pb_t, blk, pb->blk.next))
        ;
    return pb;
}

volatile const u32 *
phy_pbdma_get_crc_bitmap (phy_t *ctx)
{
    return ctx->crc_bitmap;
}

void
phy_pbdma_start_chandata (phy_t *ctx, phy_chandata_t *first_chandata)
{
    scenario_event (phy_pbdma_start_chandata);
}

void
phy_spoc_tx_set (phy_t *ctx, phy_spoc_coeff_t *coeff)
{
    scenario_event (phy_spoc_tx_set);
    dbg_assert (ctx);
    dbg_assert (coeff);
    dbg_assert (coeff->part2);
}

void
phy_spoc_rx_set (phy_t *ctx, phy_spoc_coeff_t *coeff)
{
    scenario_event (phy_spoc_rx_set);
    dbg_assert (ctx);
    dbg_assert (coeff);
    dbg_assert (coeff->part2);
}

u32
phy_rx_agc_gain (phy_t *ctx)
{
    dbg_assert (ctx);
    return 0;
}

void
phy_debug_unexpected (phy_t *ctx, uint expected_event_mask,
                      uint unexpected_event)
{
    ctx->expected_event_mask = expected_event_mask;
    ctx->unexpected_event = unexpected_event;
}

void
phy_compute_spoc_coeff (s32 rho_q30, phy_spoc_coeff_t *coeff)
{
        dbg_assert (coeff);
            coeff->rho_q30 = rho_q30;
}

void
phy_compute_spoc_initial_coeff (phy_spoc_coeff_t *coeff)
{
        phy_compute_spoc_coeff (0, coeff);
}