summaryrefslogtreecommitdiff
path: root/cesar/ce/test/rx/general/src/test_rx.c
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/ce/test/rx/general/src/test_rx.c')
-rwxr-xr-xcesar/ce/test/rx/general/src/test_rx.c281
1 files changed, 281 insertions, 0 deletions
diff --git a/cesar/ce/test/rx/general/src/test_rx.c b/cesar/ce/test/rx/general/src/test_rx.c
new file mode 100755
index 0000000000..e33ca4ec74
--- /dev/null
+++ b/cesar/ce/test/rx/general/src/test_rx.c
@@ -0,0 +1,281 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file ./src/test_tx.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+#include "common/std.h"
+#include "cyg/hal/hal_intr.h"
+#include "ce/inc/rx.h"
+#include "mac/common/tonemap.h"
+#include "ce/test/common/print_utils.h"
+#include "ce/test/rx/inc/test_rx.h"
+#include "lib/bitstream.h"
+#include "lib/rnd.h"
+#include "lib/test.h"
+#include "cp/interf/interf.h"
+#include "lib/trace.h"
+#include "mac/common/ntb.h"
+#include "ce/inc/trace.h"
+#include "ce/inc/bitloading.h"
+#include "mac/sar/sar.h"
+
+lib_rnd_t rnd;
+test_t test;
+phy_t *phy_ctx;
+rxce_t *rxce_ctx;
+sar_t *sar;
+
+
+#define FRAME_PRIORITY 10
+cyg_thread frame_thread;
+cyg_handle_t frame_handle;
+unsigned char frame_stack[CYGNUM_HAL_STACK_SIZE_TYPICAL];
+
+#define RXCE_PRIORITY 14
+cyg_thread rxce_thread;
+cyg_handle_t rxce_handle;
+unsigned char rxce_stack[CYGNUM_HAL_STACK_SIZE_TYPICAL];
+
+uint noise[PHY_CARRIER_NB];
+uint false_bit_nb[MAC_MAX_PB_PER_MPDU];
+
+struct test_status_t
+{
+ mac_store_t *mac_store_ctx;
+ sta_t *sta;
+ uint sound_nb;
+ uint null_ber_frame_nb;
+ uint date;
+};
+typedef struct test_status_t test_status_t;
+test_status_t status;
+
+struct frame_t
+{
+ bool sound;
+ uint sound_reason_code;
+ uint pb_nb;
+ pbproc_rx_params_t *rx_params;
+ uint *noise;
+ uint *false_bit_nb;
+};
+typedef struct frame_t frame_t;
+
+
+bool next_scf;
+
+void
+pbproc_rxce_init (pbproc_need_scf_cb_t need_scf)
+{
+ need_scf_cb = need_scf;
+}
+
+void
+pbproc_scf (void)
+{
+ //my_print ("pbproc scf\n");
+ next_scf = true;
+}
+
+void
+over_pbproc_init (void)
+{
+ next_scf = false;
+}
+
+bool
+pbproc_send_scf (void)
+{
+ ce_print ("\t\t\t\t ACK with scf = %d\n", next_scf);
+ bool ret = next_scf;
+ next_scf = false;
+ return (ret);
+}
+
+void
+sar_noise_new (pbproc_rx_params_t *rx_params, uint noise[], uint symbol_nb)
+{
+ uint i;
+ uint lambda = 0;
+ phy_chandata_t *time_noise;
+ time_noise = (phy_chandata_t *) blk_alloc_desc();
+ time_noise->blk.next = NULL;
+ time_noise->last = 0;
+ time_noise->type = PHY_CHANDATA_TYPE_NRJ_SYMBOL;
+ phy_noise_energy_t *time_data = (phy_noise_energy_t *) time_noise->blk.data;
+ phy_chandata_t *freq_noise, *last;
+ freq_noise = (phy_chandata_t *) blk_alloc_desc_range (mpdu_measure_chandata_blk_nb[PHY_CHANDATA_TYPE_NRJ],
+ (blk_t **) &last);
+ freq_noise->type = PHY_CHANDATA_TYPE_NRJ;
+ phy_chandata_t * ch = freq_noise;
+ phy_noise_energy_t *freq_data = (phy_noise_energy_t *) ch->blk.data;
+ for (i=0; i<PHY_CARRIER_NB; i++)
+ {
+ ch->type = PHY_CHANDATA_TYPE_NRJ;
+ ch->last = 0;
+ if ( ((i%PHY_NOISE_NB_PER_BLK) == 0) && (i!=0) )
+ {
+ ch = (phy_chandata_t *) ch->blk.next;
+ freq_data = (phy_noise_energy_t *) ch->blk.data;
+ }
+ * (freq_data+(i%PHY_NOISE_NB_PER_BLK)) = noise[i];
+ lambda+=noise[i];
+ }
+ lambda = lambda/PHY_CARRIER_NB;
+ last->last = 1;
+ last->blk.next = NULL;
+ for (i=0; i<symbol_nb; i++) *(time_data+i) = lambda;
+ time_noise->blk.next = (blk_t *) freq_noise;
+ ce_print ("\t\t\t\t ADD NOISES\n");
+ rxce_mpdu_measurement_add (rxce_ctx, rx_params, 0, NULL, NULL, (pb_t *) time_noise,
+ mpdu_measure_chandata_blk_nb[PHY_CHANDATA_TYPE_NRJ] +
+ mpdu_measure_chandata_blk_nb[PHY_CHANDATA_TYPE_NRJ_SYMBOL], NULL);
+}
+
+void
+frame_new (frame_t *frame)
+{
+ uint symbol_nb = 0;
+ frame->rx_params->preamble_ntb = status.date;
+ if (frame->sound)
+ {
+ symbol_nb = 19;
+ status.date += (19);
+ status.sound_nb++;
+ need_scf_cb (frame->rx_params->tei, frame->sound_reason_code);
+ cyg_thread_delay (symbol_nb/19);
+ sar_noise_new (frame->rx_params, frame->noise, symbol_nb);
+ }
+ else
+ {
+ ;
+ }
+}
+
+void
+frame_process (cyg_addrword_t data)
+{
+ mac_store_sta_add (status.mac_store_ctx, 1);
+ status.sta = mac_store_sta_get (status.mac_store_ctx, 1);
+ status.sound_nb = 0;
+ test_case_begin (test, "CE-rxce_process with noise reception");
+ test_begin (test, "rxce test1")
+ {
+ uint j;
+ uint nb_frame = 0;
+ uint worst[PHY_CARRIER_NB];
+
+ cyg_thread_delay (1);
+ lib_rnd_init (&rnd, 12);
+ do
+ {
+ frame_t *frame = blk_alloc();
+ pbproc_rx_params_t *rx_params = blk_alloc ();
+ frame->sound = true;
+ frame->sound_reason_code = 0xFD;
+ frame->pb_nb = 0;
+ frame->rx_params = rx_params;
+ frame->rx_params->tei = 1;
+ for (j=0; j<PHY_CARRIER_NB; j++)
+ {
+ if (nb_frame < FRAME_NB_TO_COMPUTE_IN_INITIAL_STEP) noise[j] = j + lib_rnd_uniform(&rnd,(j+1));
+ else noise[j] = 0;
+ if (nb_frame == 0) worst[j] = noise[j];
+ else
+ {
+ if (worst[j]<noise[j]) worst[j] = noise[j];
+ }
+ }
+ frame->noise = noise;
+ frame_new (frame);
+ nb_frame++;
+ test_fail_if (status.sta->rxce.stable_ROBO_nb<FRAME_NB_TO_COMPUTE_IN_INITIAL_STEP && status.sta->rx_tonemaps->default_tmi != TONEMAP_INDEX_INITIAL_START);
+ test_fail_if (status.sta->rxce.stable_ROBO_nb>FRAME_NB_TO_COMPUTE_IN_INITIAL_STEP && status.sta->rx_tonemaps->default_tmi == TONEMAP_INDEX_INITIAL_START);
+ blk_release (frame);
+ } while (!pbproc_send_scf ());
+ bitstream_t stream;
+ bitstream_init (&stream, status.sta->rx_tonemaps->tm[status.sta->rx_tonemaps->default_tmi]->tmdma_desc_head->data, BLK_SIZE, BITSTREAM_READ);
+ for (j=0; j<PHY_CARRIER_NB; j++)
+ {
+ if (j==1024)
+ {
+ bitstream_init (&stream, status.sta->rx_tonemaps->tm[status.sta->rx_tonemaps->default_tmi]->tmdma_desc_head->next->data, BLK_SIZE, BITSTREAM_READ);
+ }
+ uint mod;
+ bitstream_access (&stream, &mod, 4);
+ if (mod==0)
+ {
+ test_fail_if (worst[j] <=THR3[1][0]);
+ }
+ else
+ {
+ if (mod==7)
+ {
+ test_fail_if (worst[j] > THR3[1][6]);
+ }
+ else
+ {
+ test_fail_if (worst[j]<=THR3[1][mod] || worst[j]>THR3[1][mod-1]);
+ }
+ }
+
+ }
+ } test_end;
+ // rxce_process can end to process and free pending frames.
+ cyg_thread_delay (1);
+
+ blk_release (status.sta);
+ mac_store_sta_remove (status.mac_store_ctx, 1);
+ mac_store_uninit (status.mac_store_ctx);
+ blk_release (phy_ctx);
+ rxce_trace_print(rxce_ctx);
+ rxce_trace_uninit (rxce_ctx);
+ blk_release (sar);
+ trace_uninit();
+ test_begin (test, "check alloc/free")
+ {
+ test_fail_unless (blk_check_memory());
+ } test_end;
+ test_result (test);
+ HAL_PLATFORM_EXIT (test_nb_failed (test) == 0 ? 0 : 1);
+}
+
+void
+cyg_user_start (int argc, char **argv)
+{
+ trace_init();
+ phy_ctx = blk_alloc();
+ test_init (test, argc, argv);
+ mac_config_t mac_config;
+ mac_config_init (&mac_config);
+ status.mac_store_ctx = mac_store_init ();
+ mac_ntb_init (phy_ctx, &mac_config);
+ sar = blk_alloc();
+ rxce_ctx = rxce_init (sar, status.mac_store_ctx, &mac_config);
+ over_pbproc_init ();
+ pbproc_rxce_init (pbproc_need_scf_cb);
+
+ cyg_thread_create (RXCE_PRIORITY, &rxce_process, (cyg_addrword_t) rxce_ctx, "rxce",
+ rxce_stack, CYGNUM_HAL_STACK_SIZE_TYPICAL,
+ &rxce_handle, &rxce_thread);
+ cyg_thread_create (FRAME_PRIORITY, &frame_process, 0, "frame_test",
+ frame_stack, CYGNUM_HAL_STACK_SIZE_TYPICAL,
+ &frame_handle, &frame_thread);
+
+
+ //my_print ("launch rxce process\n");
+ cyg_thread_resume (rxce_handle);
+
+ //my_print ("launch frame process\n");
+ cyg_thread_resume (frame_handle);
+}
+