summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlacour2008-03-05 16:51:38 +0000
committerlacour2008-03-05 16:51:38 +0000
commitbf2c4cb8098717b7f833de553bf3a47db58dc9c5 (patch)
treed46830e24f71e832c2316378510476d29c337f08
parentf2f531b365d547b59fe6e1c1e9f2260992827b5b (diff)
Separation between computation and acquisition of
frame_measurement : Add bitloading.h, bitloading.c ; clean frame_measurement ; Adapt tests. Change any functions and variables name. git-svn-id: svn+ssh://pessac/svn/cesar/trunk@1567 017c9cb6-072f-447c-8318-d5b54f68fe89
-rwxr-xr-xce/Module2
-rw-r--r--ce/inc/bitloading.h120
-rwxr-xr-xce/inc/cei.h10
-rwxr-xr-xce/inc/cei_param.h4
-rwxr-xr-xce/inc/frame_measurement.h60
-rwxr-xr-xce/inc/rx.h7
-rw-r--r--ce/src/bitloading.c202
-rwxr-xr-xce/src/frame_measurement.c124
-rwxr-xr-xce/src/rx.c97
-rwxr-xr-xce/test/rx/general/host-Makefile5
-rwxr-xr-xce/test/rx/general/src/test_bitloading.c217
-rwxr-xr-xce/test/rx/general/src/test_frame_measurement.c240
-rwxr-xr-xce/test/rx/general/src/test_rx.c1
-rwxr-xr-xce/test/rx/general/src/test_sar_integration.c1
-rw-r--r--ce/test/rx/general/target-Makefile2
-rwxr-xr-xce/test/rx/host_linux_sparc/Makefile2
-rw-r--r--ce/test/rx/maximus/Makefile2
-rw-r--r--ce/test/rx/tonemap_refresh/Makefile2
-rw-r--r--common/tests/tests3
19 files changed, 586 insertions, 515 deletions
diff --git a/ce/Module b/ce/Module
index 7cc4be012b..84d2b93da6 100755
--- a/ce/Module
+++ b/ce/Module
@@ -1,4 +1,4 @@
-SOURCES := rx.c tx.c rxce_stats.c
+SOURCES := rx.c tx.c rxce_stats.c bitloading.c
ifeq ($(CONFIG_TRACE),y)
SOURCES += trace.c
endif
diff --git a/ce/inc/bitloading.h b/ce/inc/bitloading.h
new file mode 100644
index 0000000000..ac21e4280f
--- /dev/null
+++ b/ce/inc/bitloading.h
@@ -0,0 +1,120 @@
+#ifndef ce_inc_bitloading_h
+#define ce_inc_bitloading_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file ce/inc/bitloading.h
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+#include "ce/inc/frame_measurement.h"
+#include "mac/common/store.h"
+
+/** The noise provided by the DSP is expressed in UND that is the length of
+ * the diagonal in the constellation of the modulation on which measurement has been done.
+ */
+/** noise saturation */
+#define MAX_UND 4
+/** Number of bit used to code the noise */
+#define UND_CODE_BIT_NB 16
+/** Code value of the maximum noise */
+#define MAX_UND_CODE ((1<<UND_CODE_BIT_NB)-1)
+/** Code value of one UND */
+#define UND_CODE (MAX_UND_CODE/MAX_UND)
+/** The DSP accumulate noise along the MPDU (but should provide the average)*/
+#define ACCU_MAX_NB 1 // DSP provides the average (no accumulation)
+/** Code value of the maximum accumulated noise */
+#define NOISE_MAX (ACCU_MAX_NB * MAX_UND_CODE )
+
+ /** The ROBO (include sound) frame number limit before a
+ * worst_tonemap becomes a tonemap default.*/
+#define FRAME_NB_TO_COMPUTE_IN_INITIAL_STEP 20 //TBD
+
+/** Table of noises threshold versus modulation when measurement for ber=10^-3.
+ * Example : If noise has been computed by DSP with a tone QPSK
+ * and if THR3[QPSK][QAM256] < noise_average < THR3[QPSK][QAM1024],
+ * then we can put the modulation to QAM256 for a BER<10^-3.
+ */
+uint THR3[7][7];
+uint current_threshold[7];
+
+struct bitloading_modification_t
+{
+ /** Set of tonemap that has been changed. If hasn't, NULL.*/
+ tonemaps_t *changed_tonemaps;
+ /** frame measurement-processed source station TEI.*/
+ uint stei;
+ /** Tonemap index of the new tonemap (if there is).*/
+ uint new_tmi;
+ /** If a reference tonemap has been used to compute the new one, index of
+ * this reference tonemap. (Will allow to create a CM_UPDATE_TM.IND instead of CM_CHAN_EST.IND).*/
+ uint old_tmi;
+};
+typedef struct bitloading_modification_t bitloading_modification_t;
+
+/**
+ * Computation of tonemaps from frame measurement.
+ * \param mac_store_ctx Concerned sta with its rx_tonemaps and statistics.
+ * \param measurement Frame measurement data.
+ * \return the status of modification while computation.
+ *
+ */
+bitloading_modification_t
+bitloading_run (mac_store_t *mac_store_ctx, frame_measurement_t *measurement);
+
+bitloading_modification_t
+bitloading_initial_step (sta_t *sta, frame_measurement_t *measurement);
+
+bitloading_modification_t
+bitloading_dynamic_step (sta_t *sta, frame_measurement_t *measurement);
+
+bool // Has tonemap been modified?.
+bitloading_worst_tonemap_compute (tonemap_t **worst_tm, phy_chandata_t *noise_nrj);
+
+bool // Is noise stable along the MPDU?.
+bitloading_mpdu_noise_stability (phy_chandata_t *noise_nrj_symbol);
+
+static inline void
+bitloading_update_threshold (uint accumulation, int measurement_mod)
+{
+ int m;
+ for (m=0; m<7; m++)
+ {
+ current_threshold[m] = accumulation * THR3[measurement_mod][m];
+ }
+}
+
+/**
+ * Find the modulation using the table of noises threshold.
+ * \param noise code value of noise.
+ * \param accumulation // MUST BE 1 (already average provided).
+ * \param measurement_mod modulation used when measurement has been
+ * computed.
+ * \return the modulation according to thresholds.
+ *
+ */
+static inline int
+bitloading_noise2mod (uint noise /*, int accumulation, int measurement_mod*/)
+{
+ int m;
+ for(m=0; m<7; m++)
+ {
+ if (noise > current_threshold[m]) //DSP should provide average. If not, update threshold before instead of multiply at each carrier... TODO
+ {
+ return (m);
+ }
+ }
+ return (7);
+}
+
+void
+bitloading_threshold_init (void);
+
+#endif /* ce_inc_bitloading_h */
diff --git a/ce/inc/cei.h b/ce/inc/cei.h
index 3a831035b4..3dc96ff78c 100755
--- a/ce/inc/cei.h
+++ b/ce/inc/cei.h
@@ -27,14 +27,14 @@
//TODO Accelerate access in tonemap and tonemask management.
-struct cei_created_information_t
+struct cei_created_status_t
{
/** Length of mm_entry. */
uint length;
/** type of created CEI to send.*/
uint mm_type;
};
-typedef struct cei_created_information_t cei_created_information_t;
+typedef struct cei_created_status_t cei_created_status_t;
BEGIN_DECLS
@@ -152,7 +152,7 @@ cei_tmdata_encode (bitstream_t *ctx_stream, blk_t *tm, u8 *mask)
* \param old_tmi Tonemap index from which the new tonemap has been computed.
* If old_tmi is TONEMAP_INDEX_NULL, a CM_CHAN_EST.IND must be created,
* else a CM_UPDATE_TM.IND must be created.
- * \return cei_created_information necessary to send CEI via the CP.
+ * \return cei_created_status necessary to send CEI via the CP.
*
* function calls cei_tmdata_encode for the Run Length Encoding. Encoding is done
* every time even if it is not interresting because it can be worst. (except
@@ -160,7 +160,7 @@ cei_tmdata_encode (bitstream_t *ctx_stream, blk_t *tm, u8 *mask)
* TODO : Management of old_tmi to create a CM_UPDATE_TM.IND instead of
* CM_CHAN_EST.IND
*/
-static cei_created_information_t
+static cei_created_status_t
cei_create (u8 *dest_mm_entry, u8 *mask, tonemaps_t *rx_tonemaps, uint new_tmi, uint old_tmi)
{
bitstream_t stream_writer;
@@ -214,7 +214,7 @@ cei_create (u8 *dest_mm_entry, u8 *mask, tonemaps_t *rx_tonemaps, uint new_tmi,
}
bitstream_finalise (&stream_writer);
mme_len = ((u32) stream_writer.stream) - ((u32)stream_writer.start) + ((stream_writer.bit_offset+7)/8);
- cei_created_information_t ret;
+ cei_created_status_t ret;
ret.length = mme_len;
ret.mm_type = CM_CHAN_EST_IND;
return(ret);
diff --git a/ce/inc/cei_param.h b/ce/inc/cei_param.h
index 0d1cda2e93..c481e40817 100755
--- a/ce/inc/cei_param.h
+++ b/ce/inc/cei_param.h
@@ -26,7 +26,7 @@
#define CEI_WANTED_MAX 32
-/** Pamaters allowing to build the CEI message */
+/** Parameters allowing to build the CEI message.*/
struct cei_param_t
{
/** Set of tonemaps concerned */
@@ -39,8 +39,6 @@ struct cei_param_t
uint priority;
/** Destination tei useful to find the MAC ADDRESS */
uint dtei;
- /** Length of mmentry once created. */
- uint length;
};
typedef struct cei_param_t cei_param_t;
diff --git a/ce/inc/frame_measurement.h b/ce/inc/frame_measurement.h
index 00ae5bb60a..d7cbb95a86 100755
--- a/ce/inc/frame_measurement.h
+++ b/ce/inc/frame_measurement.h
@@ -25,34 +25,11 @@
#include "hal/phy/pbdma.h"
#include "mac/common/sta.h"
-/** The noise provided by the DSP is expressed in UND that is the length of
- * the diagonal in the constellation of the modulation on which measurement has been done.
- */
-/** noise saturation */
-#define MAX_UND 4
-/** Number of bit used to code the noise */
-#define UND_CODE_BIT_NB 16
-/** Code value of the maximum noise */
-#define MAX_UND_CODE ((1<<UND_CODE_BIT_NB)-1)
-/** Code value of one UND */
-#define UND_CODE (MAX_UND_CODE/MAX_UND)
-/** The DSP accumulate noise along the MPDU (but should provide the average)*/
-#define ACCU_MAX_NB 1 // DSP provides the average (no accumulation)
-/** Code value of the maximum accumulated noise */
-#define NOISE_MAX (ACCU_MAX_NB * MAX_UND_CODE )
/** Number maximal of PB in a MPDU (<256).*/
#define MAX_PB 256
/** Length of the circular buffer that stock the frame measurement expressed in frame number. */
#define FRAME_MEASUREMENT_STOCK_LEN 30
-/** Table of noises threshold versus modulation when measurement for ber=10^-3.
- * Example : If noise has been computed by DSP with a tone QPSK
- * and if THR3[QPSK][QAM256] < noise_average < THR3[QPSK][QAM1024],
- * then we can put the modulation to QAM256 for a BER<10^-3.
- */
-uint THR3[7][7];
-
-uint current_threshold[7];
/** Phy_chandata blocks number versus type */
uint CHANDATA_TYPE_BLK_NB[PHY_CHANDATA_TYPE_NB];
@@ -125,43 +102,6 @@ compute_worst_tonemap2 (tonemap_t **worst_tm, phy_chandata_t *freq_noise);
void
manage_interval (tonemaps_t *tms, frame_measurement_t *frame_measurement);
-static inline void
-update_threshold (uint accumulation, int measurement_mod)
-{
- int m;
- for (m=0; m<7; m++)
- {
- current_threshold[m] = accumulation * THR3[measurement_mod][m];
- }
-}
-
-/**
- * Find the modulation using the table of noises threshold.
- * \param noise code value of noise.
- * \param accumulation // MUST BE 1 (already average provided).
- * \param measurement_mod modulation used when measurement has been
- * computed.
- * \return the modulation according to thresholds.
- *
- */
-static inline int
-noise2mod (uint noise /*, int accumulation, int measurement_mod*/)
-{
- //int mod = 6;
- int m;
- for(m=0; m<7; m++)
- {
- if (noise > current_threshold[m]) //DSP should provide average. If not, update threshold before instead of multiply at each carrier... TODO
- {
- //mod = m-1;
- //break;
- return (m);
- }
- }
- //mod++;
- //return (mod);
- return (7);
-}
/**
* Release data pointed into frame measurement.
diff --git a/ce/inc/rx.h b/ce/inc/rx.h
index 9e760617bc..ee391e3c7b 100755
--- a/ce/inc/rx.h
+++ b/ce/inc/rx.h
@@ -23,9 +23,6 @@
#define TXCE
#endif
-/** The ROBO (include sound) frame number limit before compute a
- * tonemap default.*/
-#define FRAME_NB_TO_COMPUTE_IN_INITIAL_STEP 20 //TBD
/** Priority of CEI message */
#define CEI_PRIORITY 2
@@ -159,7 +156,7 @@ compute_scf (rxce_t *ctx);
* do.
*/
void
-rxce_compute_measurement (rxce_t *ctx);
+rxce_next_measurement_compute (rxce_t *ctx);
/**
* When no tonemap default from a station, a first and fast analysis on Sound
@@ -212,7 +209,7 @@ rxce_process (cyg_addrword_t data);
*
*/
void
-rxce_job_cei_add (rxce_t *ctx, tonemaps_t *tms, uint new_tmi, uint old_tmi, uint dtei);
+rxce_job_cei_add (rxce_t *ctx, uint dtei, tonemaps_t *tms, uint new_tmi, uint old_tmi);
END_DECLS
diff --git a/ce/src/bitloading.c b/ce/src/bitloading.c
new file mode 100644
index 0000000000..4e4526a7e7
--- /dev/null
+++ b/ce/src/bitloading.c
@@ -0,0 +1,202 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file ce/src/bitloading.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+
+#include "common/std.h"
+#include "ce/inc/bitloading.h"
+
+#define SET_WORST_NIBBLE(old,new,noise) do { \
+ u32 mod = bitloading_noise2mod (noise); \
+ u32 zmod = old & 0xF; \
+ /*printf ("new mod eventuel = 0x%x, ex mod = 0x%x\n", mod, zmod);*/ \
+ if (mod < zmod) \
+ { \
+ zmod = mod; \
+ ret = true; \
+ } \
+ new = (new>>4) | (zmod<<28); \
+} while (0);
+
+#define SET_TWO_NIBBLES(new,old,two_noise) do { \
+ u32 noise = two_noise & 0x0000FFFF; \
+ SET_WORST_NIBBLE(old,new,noise); \
+ old = old >> 4; \
+ noise = (two_noise & 0xFFFF0000) >> 16; \
+ SET_WORST_NIBBLE(old,new,noise); \
+ old = old >> 4; \
+} while (0);
+
+#define SET_EIGHT_NIBBLES(tm_data,two_noise_ptr) do { \
+ u32 old = tm_data; \
+ /*printf ("old = 0x%x\n", old);*/ \
+ u32 new = 0; \
+ {SET_TWO_NIBBLES(new,old,(*two_noise_ptr)); two_noise_ptr++;} \
+ {SET_TWO_NIBBLES(new,old,(*two_noise_ptr)); two_noise_ptr++;} \
+ {SET_TWO_NIBBLES(new,old,(*two_noise_ptr)); two_noise_ptr++;} \
+ {SET_TWO_NIBBLES(new,old,(*two_noise_ptr)); two_noise_ptr++;} \
+ tm_data = new; \
+ /*printf ("new = 0x%x\n", new);*/ \
+} while (0);
+
+#define SET_256_NIBBLES(noise_blk,tm_data_ptr) do { \
+ u32 b; \
+ u32 *two_noise_ptr = (u32 *) noise_blk->data; \
+ for (b=0; b<32; b++) \
+ { \
+ SET_EIGHT_NIBBLES((*tm_data_ptr),two_noise_ptr); \
+ tm_data_ptr++; \
+ } \
+} while (0);
+
+bitloading_modification_t
+bitloading_run (mac_store_t *mac_store_ctx, frame_measurement_t *measurement)
+{
+ bitloading_modification_t ret;
+ dbg_assert (mac_store_ctx);
+ dbg_assert (measurement);
+ pbproc_rx_params_t *rx_params = measurement->rx_params;
+ dbg_assert (rx_params);
+ sta_t *ssta = mac_store_sta_get (mac_store_ctx, rx_params->tei);
+ dbg_assert (ssta);
+ if (ssta->rx_tonemaps->default_tmi == TONEMAP_INDEX_INITIAL_START ) // no default_tonemap
+ {
+ ret = bitloading_initial_step (ssta, measurement);
+ }
+ else
+ {
+ ret = bitloading_dynamic_step (ssta, measurement);
+ }
+ ssta->rxce.measurement_computed_nb++;
+ blk_release (ssta);
+ return ret;
+}
+
+
+bitloading_modification_t
+bitloading_initial_step (sta_t *ssta, frame_measurement_t *measurement)
+{
+ dbg_assert (ssta);
+ dbg_assert (measurement);
+ bitloading_modification_t ret;
+ tonemaps_t *tms = ssta->rx_tonemaps;
+ ret.stei = ssta->tei;
+ ret.changed_tonemaps = NULL;
+ {
+ bitloading_worst_tonemap_compute (&ssta->rxce.tm_in_build, measurement->type_head[PHY_CHANDATA_TYPE_NRJ]);
+ if (ssta->rxce.measurement_computed_nb >= FRAME_NB_TO_COMPUTE_IN_INITIAL_STEP)
+ {
+ tms->default_tmi = tonemap_set_first_free (tms, ssta->rxce.tm_in_build);
+ ssta->rxce.tm_in_build = NULL;
+ ret.changed_tonemaps = tms;
+ ret.new_tmi = tms->default_tmi;
+ ret.old_tmi = TONEMAP_INDEX_NULL;
+ }
+ }
+ if (bitloading_mpdu_noise_stability (measurement->type_head[PHY_CHANDATA_TYPE_NRJ_SYMBOL]))
+ {
+ ssta->rxce.stable_ROBO_nb++;
+ }
+ else
+ {
+ ssta->rxce.unstable_ROBO_nb++;
+ }
+ return ret;
+}
+
+bitloading_modification_t
+bitloading_dynamic_step (sta_t *sta, frame_measurement_t *measurement)
+{
+ bitloading_modification_t ret;
+ dbg_assert (sta);
+ dbg_assert (measurement);
+ ret.stei = sta->tei;
+ ret.changed_tonemaps = NULL;
+ ret.new_tmi = TONEMAP_INDEX_NULL;
+ ret.old_tmi = TONEMAP_INDEX_NULL;
+ if (!sta->rxce.tm_in_build) sta->rxce.tm_in_build = tonemap_alloc ();
+ return ret;
+}
+
+bool // Has tonemap been modified?.
+bitloading_worst_tonemap_compute (tonemap_t **worst_tm, phy_chandata_t *noise_nrj)
+{
+ dbg_assert (noise_nrj);
+ bool ret = false;
+ u32 *tm_data;
+ u32 i;
+ blk_t *blk_noise = (blk_t *) noise_nrj;
+ if (!(*worst_tm)) *worst_tm = tonemap_alloc();
+ tm_data = (u32 *) (*worst_tm)->tmdma_desc_head->data;
+ bitloading_update_threshold (1, 1);
+ for (i=0; i<4; i++)
+ {
+ SET_256_NIBBLES(blk_noise, tm_data); blk_noise = blk_noise->next;
+ }
+ tm_data = (u32 *) (*worst_tm)->tmdma_desc_head->next->data;
+ u32 *two_noise = (u32 *) blk_noise->data;
+ for (i=0; i<17; i++)
+ {
+ SET_EIGHT_NIBBLES((*tm_data), two_noise);
+ tm_data++;
+ }
+ // Not really necessary but delete the tone of unused carriers created by
+ // previous computation due to 1155%8!=0...
+ tm_data--;
+ *tm_data = *tm_data | 0xFFFFF000;
+ /** Padding of last byte force to 0 */
+ *tm_data = *tm_data & 0xFFFF0FFF;
+ return ret;
+}
+
+bool // Is noise stable along the MPDU?.
+bitloading_mpdu_noise_stability (phy_chandata_t *noise_nrj_symbol)
+{
+ dbg_assert (noise_nrj_symbol);
+ // BE CAREFUL to overflow of variables (accumulation of multiplication)
+ uint i;
+ u64 sum_x_2 = 0;
+ u64 sum_x2 = 0;
+ u64 comparator;
+ u32 val;
+ phy_noise_t *data = (phy_noise_t *) noise_nrj_symbol->blk.data;
+ uint symbol_number = noise_nrj_symbol->size;
+ // computation : is sigma > 0.1 *lambda ?
+ // cf spec about bitloading
+ for (i=0; i< symbol_number; i++)
+ {
+ val = *(data++);
+ dbg_assert_print (val<= NOISE_MAX, "noise overflow");
+ sum_x_2 += val;
+ sum_x2 += val * val;
+ }
+ sum_x_2 = sum_x_2 * sum_x_2;
+ comparator = 100 * (symbol_number * sum_x2 - sum_x_2);
+ return (comparator <= sum_x_2);
+}
+
+void
+bitloading_threshold_init (void)
+{
+ //QPSK_THR103 = {0.21, 0.105, 0.036,
+ //0.022, 0.0056, 0.00144, 0.00037};
+ THR3[1][0] = (uint) (0.21 * UND_CODE);
+ THR3[1][1] = (uint) (0.105 * UND_CODE);
+ THR3[1][2] = (uint) (0.036 * UND_CODE);
+ THR3[1][3] = (uint) (0.022 * UND_CODE);
+ THR3[1][4] = (uint) (0.0056 * UND_CODE);
+ THR3[1][5] = (uint) (0.00144 * UND_CODE);
+ THR3[1][6] = (uint) (0.00037 * UND_CODE);
+}
+
+
diff --git a/ce/src/frame_measurement.c b/ce/src/frame_measurement.c
index 7cd5bbc980..67c8632a68 100755
--- a/ce/src/frame_measurement.c
+++ b/ce/src/frame_measurement.c
@@ -17,83 +17,23 @@
#include "ce/test/common/print_utils.h"
#include "hal/phy/defs.h"
-#define SET_WORST_NIBBLE(old,new,noise) do { \
- u32 mod = noise2mod (noise); \
- u32 zmod = old & 0xF; \
- /*printf ("new mod eventuel = 0x%x, ex mod = 0x%x\n", mod, zmod);*/ \
- if (mod < zmod) \
- { \
- zmod = mod; \
- ret = true; \
- } \
- new = (new>>4) | (zmod<<28); \
-} while (0);
-
-#define SET_TWO_NIBBLES(new,old,two_noise) do { \
- u32 noise = two_noise & 0x0000FFFF; \
- SET_WORST_NIBBLE(old,new,noise); \
- old = old >> 4; \
- noise = (two_noise & 0xFFFF0000) >> 16; \
- SET_WORST_NIBBLE(old,new,noise); \
- old = old >> 4; \
-} while (0);
-
-#define SET_EIGHT_NIBBLES(tm_data,two_noise_ptr) do { \
- u32 old = tm_data; \
- /*printf ("old = 0x%x\n", old);*/ \
- u32 new = 0; \
- {SET_TWO_NIBBLES(new,old,(*two_noise_ptr)); two_noise_ptr++;} \
- {SET_TWO_NIBBLES(new,old,(*two_noise_ptr)); two_noise_ptr++;} \
- {SET_TWO_NIBBLES(new,old,(*two_noise_ptr)); two_noise_ptr++;} \
- {SET_TWO_NIBBLES(new,old,(*two_noise_ptr)); two_noise_ptr++;} \
- tm_data = new; \
- /*printf ("new = 0x%x\n", new);*/ \
-} while (0);
-
-#define SET_256_NIBBLES(noise_blk,tm_data_ptr) do { \
- u32 b; \
- u32 *two_noise_ptr = (u32 *) noise_blk->data; \
- for (b=0; b<32; b++) \
- { \
- SET_EIGHT_NIBBLES((*tm_data_ptr),two_noise_ptr); \
- tm_data_ptr++; \
- } \
-} while (0);
void
frame_measurement_init (void)
{
- //my_print ("frame_measurement_init\n");
- //QPSK_THR103 = {0.21, 0.105, 0.036,
- //0.022, 0.0056, 0.00144, 0.00037};
- THR3[1][0] = (uint) (0.21 * UND_CODE);
- THR3[1][1] = (uint) (0.105 * UND_CODE);
- THR3[1][2] = (uint) (0.036 * UND_CODE);
- THR3[1][3] = (uint) (0.022 * UND_CODE);
- THR3[1][4] = (uint) (0.0056 * UND_CODE);
- THR3[1][5] = (uint) (0.00144 * UND_CODE);
- THR3[1][6] = (uint) (0.00037 * UND_CODE);
int i;
- //for (i=0; i<7; i++) ce_print ("thr3QPSK : 0x%x\t",THR3[1][i]); ce_print("\n");
- //if (first_frame) frame_measurement_free (first_frame);
- //if (last_frame) frame_measurement_free (last_frame);
- //first_frame = NULL;
- //last_frame = NULL;
fm_reader = 0;
fm_writer = 0;
fm_number = 0;
for (i=0; i<FRAME_MEASUREMENT_STOCK_LEN; i++)
{
- //fm_stock[i].rx_params = NULL;
fm_stock[i].ber_measurement = NULL;
int j;
for (j=0; j<PHY_CHANDATA_TYPE_NB; j++)
{
fm_stock[i].type_head[j] = NULL;
}
- //my_print ("&fm_stock(%d]=0x%x\n", i, &fm_stock[i]);
- //frame_measurement_print (&fm_stock[i]);
}
CHANDATA_TYPE_BLK_NB[PHY_CHANDATA_TYPE_NO_MEMORY_READ] = 0;
@@ -108,70 +48,6 @@ frame_measurement_init (void)
CHANDATA_TYPE_BLK_NB[PHY_CHANDATA_TYPE_COPY_VOTE_COEF] = 1;
}
-bool
-is_time_noise_stable (phy_chandata_t *time_noise)
-{
- //my_print ("is_time_noise_stable\n");
- dbg_assert (time_noise);
- // BE CAREFUL to overflow of variables (accumulation of multiplication)
- uint i;
- u64 sum_x_2 = 0;
- u64 sum_x2 = 0;
- u64 comparator;
- u32 val;
- phy_noise_t *data = (phy_noise_t *) time_noise->blk.data;
- uint symbol_number = time_noise->size;
- // computation : is sigma > 0.1 *lambda ?
- // cf spec on CE computation
- for (i=0; i< symbol_number; i++)
- {
- val = *(data++);
- dbg_assert_print (val<= NOISE_MAX, "noise overflow");
- sum_x_2 += val;
- sum_x2 += val * val;
- }
- sum_x_2 = sum_x_2 * sum_x_2;
- comparator = 100 * (symbol_number * sum_x2 - sum_x_2);
- return (comparator <= sum_x_2);
-}
-
-bool
-compute_worst_tonemap (tonemap_t **worst_tm, phy_chandata_t *freq_noise)
-{
- dbg_assert (freq_noise);
- bool ret = false;
- u32 *tm_data;
- u32 i;
- blk_t *blk_noise = (blk_t *) freq_noise;
- if (!(*worst_tm)) *worst_tm = tonemap_alloc();
- tm_data = (u32 *) (*worst_tm)->tmdma_desc_head->data;
- update_threshold (1, 1);
- for (i=0; i<4; i++)
- {
- SET_256_NIBBLES(blk_noise, tm_data); blk_noise = blk_noise->next;
- // SET_256_NIBBLES(blk_noise, tm_data); blk_noise = blk_noise->next;
- // SET_256_NIBBLES(blk_noise, tm_data); blk_noise = blk_noise->next;
- // SET_256_NIBBLES(blk_noise, tm_data); blk_noise = blk_noise->next;
- }
- tm_data = (u32 *) (*worst_tm)->tmdma_desc_head->next->data;
- u32 *two_noise = (u32 *) blk_noise->data;
- for (i=0; i<17; i++)
- {
- SET_EIGHT_NIBBLES((*tm_data), two_noise);
- tm_data++;
- }
- // Not really necessary but delete the tone of unused carriers created by
- // previous computation due to 1155%8!=0...
- tm_data--;
- *tm_data = *tm_data | 0xFFFFF000;
- /** Padding of last byte force to 0 */
- *tm_data = *tm_data & 0xFFFF0FFF;
-
- return ret;
-}
-
-
-
void
phy_chandata_release (phy_chandata_t *noise, uint n)
diff --git a/ce/src/rx.c b/ce/src/rx.c
index 57c93d117d..8b6e74ed85 100755
--- a/ce/src/rx.c
+++ b/ce/src/rx.c
@@ -18,6 +18,7 @@
#include "common/defs/ethernet.h"
#include "ce/inc/rx.h"
#include "ce/inc/trace.h"
+#include "ce/inc/bitloading.h"
#define RXCE //for static functions of cei.h
#include "ce/inc/cei.h"
#include "ce/test/common/print_utils.h"
@@ -38,7 +39,6 @@ rxce_init_test_cb (test_cb_t test)
}
#endif
-
rxce_t *
rxce_init (mac_store_t *mac_store_ctx, mac_config_t *mac_config_ctx)
{
@@ -99,7 +99,7 @@ sar_mpdu_measurement_cb (void *user, pbproc_rx_params_t *rx_params,
/** todo Cf SPEC HPAV HPAV-FrameControl -- SoundVariantField -- SoundReasonCode */
bool
-compute_scf (rxce_t *ctx)
+rxce_scf_compute (rxce_t *ctx)
{
dbg_assert (ctx);
bool ret = false;
@@ -109,7 +109,7 @@ compute_scf (rxce_t *ctx)
if (src >= 0x04 && src <= 0x1F) //Interval with an invalid tonemap.
{
sta = mac_store_sta_get(ctx->mac_store_ctx, ctx->sound_param.stei);
- rxce_job_cei_add (ctx, sta->rx_tonemaps, src - 4, TONEMAP_INDEX_NULL, ctx->sound_param.stei);
+ rxce_job_cei_add (ctx, ctx->sound_param.stei, sta->rx_tonemaps, src - 4, TONEMAP_INDEX_NULL);
ret = true;
blk_release (sta);
}
@@ -147,77 +147,16 @@ compute_scf (rxce_t *ctx)
}
void
-rxce_compute_measurement (rxce_t *ctx)
-{
- dbg_assert (ctx);
- ce_print ("\t\t\t\t\t\t\t\t\t\t\t\tcompute_measurement\n");
- //frame_measurement_t *frame_measurement = frame_measurement_get_first();
- frame_measurement_t *frame_measurement = frame_measurement_get_next ();
- dbg_assert (frame_measurement);
- pbproc_rx_params_t *rx_params = frame_measurement->rx_params;
- dbg_assert (rx_params);
- //my_print ("@rx_params = 0x%x, tei = %d\n", rx_params, rx_params->tei);
- sta_t *ssta = mac_store_sta_get (ctx->mac_store_ctx, rx_params->tei);
- dbg_assert (ssta);
- //cyg_thread_delay (1);
- if ( ssta->rx_tonemaps->default_tmi == TONEMAP_INDEX_INITIAL_START ) // no default_tonemap
- {
- rxce_initial (ctx, ssta, frame_measurement);
- }
- else
- {
- rxce_dynamic (ctx, ssta, frame_measurement);
- }
- ssta->rxce.measurement_computed_nb++;
- blk_release (ssta);
- frame_measurement_release (frame_measurement);
-}
-
-void
-rxce_initial (rxce_t *ctx, sta_t *ssta, frame_measurement_t *frame_measurement)
+rxce_next_measurement_compute (rxce_t *ctx)
{
- ce_print ("\t\t\t\t\t\t\t\t\t\t\t\tinitial_ce\n");
dbg_assert (ctx);
- dbg_assert (ssta);
- dbg_assert (frame_measurement);
- tonemaps_t *tms = ssta->rx_tonemaps;
- {
- //TODO if ROBO
- compute_worst_tonemap (&ssta->rxce.tm_in_build, frame_measurement->type_head[PHY_CHANDATA_TYPE_NRJ]);
- if (ssta->rxce.measurement_computed_nb >= FRAME_NB_TO_COMPUTE_IN_INITIAL_STEP)
- {
- //my_print ("swapping temporary tonemap to default\n");
- tms->default_tmi = tonemap_set_first_free (tms, ssta->rxce.tm_in_build);
- ssta->rxce.tm_in_build = NULL;
- rxce_job_cei_add (ctx, tms, tms->default_tmi, 0, ssta->tei);
- }
- //TODO else if timestamp_ROBO_us > 20000
- }
- if (is_time_noise_stable(frame_measurement->type_head[PHY_CHANDATA_TYPE_NRJ_SYMBOL]))
- {
- //todo if ROBO
- ssta->rxce.stable_ROBO_nb++; // else stable_nonROBO_nb
- }
- else
- {
-
- //TODO if ROBO
- ssta->rxce.unstable_ROBO_nb++; // else stable_nonROBO_nb
- //TODO manage_interval (tms, frame_measurement);
- }
- //if (ssta->rx_tonemaps->default_tmi != NULL_TONEMAP_INDEX ) print_tonemap (ssta->rx_tonemaps->tm[ssta->rx_tonemaps->default_tmi]);
+ frame_measurement_t *measurement = frame_measurement_get_next ();
+ dbg_assert (measurement);
+ bitloading_modification_t bl = bitloading_run (ctx->mac_store_ctx, measurement);
+ frame_measurement_release (measurement);
+ if (bl.changed_tonemaps ) rxce_job_cei_add (ctx, bl.stei, bl.changed_tonemaps, bl.new_tmi, bl.old_tmi);
}
-void
-rxce_dynamic (rxce_t *ctx, sta_t *sta, frame_measurement_t *frame_measurement)
-{
- dbg_assert (ctx);
- dbg_assert (sta);
- dbg_assert (frame_measurement);
- if (!sta->rxce.tm_in_build) sta->rxce.tm_in_build = tonemap_alloc ();
- //print_tonemap (sta->rxce.tm_in_build);
- // SOMETHING TODO BUT WHAT...???
-}
cyg_tick_count_t
rxce_tonemaps_refresh_management(rxce_t *ctx)
@@ -236,7 +175,7 @@ rxce_tonemaps_refresh_management(rxce_t *ctx)
cyg_tick_count_t expiration_date = lsta->rx_tonemaps->expiration_rtc_date;
if ( date >= expiration_date )
{
- rxce_job_cei_add (ctx, lsta->rx_tonemaps, TONEMAP_INDEX_NULL, TONEMAP_INDEX_NULL, tei);
+ rxce_job_cei_add (ctx, lsta->tei, lsta->rx_tonemaps, TONEMAP_INDEX_NULL, TONEMAP_INDEX_NULL);
}
if (lowest_expiration_date > expiration_date)
{
@@ -250,19 +189,19 @@ rxce_tonemaps_refresh_management(rxce_t *ctx)
}
void
-rxce_job_cei_add (rxce_t *ctx, tonemaps_t *tms, uint new_tmi, uint old_tmi, uint dtei)
+rxce_job_cei_add (rxce_t *ctx, uint dtei, tonemaps_t *tonemaps, uint new_tmi, uint old_tmi)
{
dbg_assert (ctx);
bool b;
cei_param_t cei_param;
- cei_param.tms = tms;
+ cei_param.tms = tonemaps;
cei_param.new_tmi = new_tmi;
cei_param.old_tmi = old_tmi;
cei_param.priority = CEI_PRIORITY;
cei_param.dtei = dtei;
b = cei_param_add (&cei_param);
if (b) cyg_semaphore_post (&(ctx->job));
- tms->expiration_rtc_date = cyg_current_time() + S_TO_RTC (RXCE_TONEMAPS_REFRESH_PERIOD_S);
+ tonemaps->expiration_rtc_date = cyg_current_time() + S_TO_RTC (RXCE_TONEMAPS_REFRESH_PERIOD_S);
}
void
@@ -282,7 +221,7 @@ rxce_process (cyg_addrword_t data)
// todo : Not sure that this part of code will not be interrupted
// by pbproc_need_scf_cb and so, the answer could not correspond to
// the last situation {src,tei} given by pbproc.
- bool b = compute_scf (ctx);
+ bool b = rxce_scf_compute (ctx);
if (b)
{
pbproc_scf (); // a pbproc function.
@@ -302,19 +241,19 @@ rxce_process (cyg_addrword_t data)
#ifdef EXPIRATION_TEST
expiration_test (param->dtei);
#endif
- cei_create (buf, ctx->mask, param->tms, param->new_tmi, param->old_tmi);
+ cei_created_status_t cei_status = cei_create (buf, ctx->mask, param->tms, param->new_tmi, param->old_tmi);
ce_print_buffer (buf, ETH_PACKET_MAX_SIZE);
- interf_send (buf, param->length, param->dtei, param->priority);
+ interf_send (buf, cei_status.length, param->dtei, param->priority);
#ifdef MAXIMUS_TEST
sta_t *sta = mac_store_sta_get (ctx->mac_store_ctx, param->dtei);
- cei_decode (sta->tx_tonemaps, CM_CHAN_EST_IND, buf, ctx->mask);
+ cei_decode (sta->tx_tonemaps, cei_status.mm_type, buf, ctx->mask);
#endif
}
else
{
if (fm_number) //Then Compute measurement
{
- rxce_compute_measurement (ctx);
+ rxce_next_measurement_compute (ctx);
}
}
}
diff --git a/ce/test/rx/general/host-Makefile b/ce/test/rx/general/host-Makefile
index 3febc79e5d..78e6298c00 100755
--- a/ce/test/rx/general/host-Makefile
+++ b/ce/test/rx/general/host-Makefile
@@ -14,13 +14,16 @@ test_cei_param_host_linux_i386_MODULES = lib mac/common ce ce/test/common ce/tes
HOST_PROGRAMS += test_fm_host_linux_i386
test_fm_host_linux_i386_SOURCES = test_frame_measurement.c
test_fm_host_linux_i386_MODULES = lib mac/common ce ce/test/common ce/test/common/ecos_overide/cyg/kernel
+HOST_PROGRAMS += test_bitloading_host_linux_i386
+test_bitloading_host_linux_i386_SOURCES = test_bitloading.c
+test_bitloading_host_linux_i386_MODULES = lib mac/common ce ce/test/common ce/test/common/ecos_overide/cyg/kernel
#HOST_PROGRAMS += test_speed_host_linux_i386
#test_speed_host_linux_i386_SOURCES = test_speed.c
#test_speed_host_linux_i386_MODULES = lib mac/common ce ce/test/common
-ce_MODULE_SOURCES = cei_param.c frame_measurement.c
+ce_MODULE_SOURCES = cei_param.c frame_measurement.c bitloading.c
ce_test_common_MODULE_SOURCES = print_utils.c gaussian.c
mac_common_MODULE_SOURCES = tonemap.c tonemask.c store.c mfs.c sta.c
diff --git a/ce/test/rx/general/src/test_bitloading.c b/ce/test/rx/general/src/test_bitloading.c
new file mode 100755
index 0000000000..f4f8f3f12c
--- /dev/null
+++ b/ce/test/rx/general/src/test_bitloading.c
@@ -0,0 +1,217 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file ./src/test_tx.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+
+
+#include "common/std.h"
+#include "lib/bitstream.h"
+#include "mac/common/tonemap.h"
+#include "ce/test/common/print_utils.h"
+#include "ce/inc/bitloading.h"
+#include "lib/rnd.h"
+#include "ce/test/common/gaussian.h"
+#include "lib/test.h"
+
+lib_rnd_t rnd;
+
+void
+test_is_time_noise_stable (test_t t)
+{
+ test_begin (t, "is_time_noise_stable")
+ {
+ int i,j,k;
+ phy_chandata_t *test = (phy_chandata_t *) blk_alloc_desc ();
+ test->type = PHY_CHANDATA_TYPE_NRJ_SYMBOL;
+ test->size = 113 ;
+ double var;
+ double sigma_lambda=0.00;
+ uint stable_nb=0;
+ for (k = 1 ; k < 20; k++)
+ {
+ sigma_lambda += 0.01;
+ stable_nb = 0;
+ for (j=0; j<100; j++)
+ {
+ lib_rnd_init (&rnd, j);
+ phy_noise_t *data = (phy_noise_t *) test->blk.data;
+ for (i=0; i<113; i++)
+ {
+ int l = 2*UND_CODE;
+ var = lib_rnd_gaussian (&rnd, l, sigma_lambda*l);
+ if (var < 0) var = 2*l-var;
+ if (var > MAX_UND_CODE) var = 2*l -var;
+ if (var < 0) var = 0;
+ if (var > MAX_UND_CODE) var = MAX_UND_CODE;
+ *(data++) = (int) (var);
+ }
+ if (bitloading_mpdu_noise_stability (test)) stable_nb++;
+
+ }
+ test_fail_if (k < 10 && stable_nb < 80 );
+ test_fail_if (k > 10 && stable_nb > 20 );
+ test_fail_if (k == 10 && (stable_nb < 20 || stable_nb > 80) );
+ }
+ blk_release_desc ((blk_t *) test);
+ } test_end;
+}
+
+void
+test_noise2mod (test_t t)
+{
+ test_begin (t, "noise to modulation")
+ {
+ uint accu = 1 ; // DSP provides directly the average
+ uint noise_CODE;
+ uint mod;
+ uint mod_measurement;
+ frame_measurement_init ();
+ bitloading_update_threshold (accu, 1);
+ for (noise_CODE=0; noise_CODE<=UND_CODE; noise_CODE++)
+ {
+ mod_measurement = 1; // ONLY THR-QPSK TODO others
+ {
+ mod = bitloading_noise2mod (noise_CODE);
+ if (mod == 7 ) test_verbose_print ("mod = %d : %d <= %d?", mod, noise_CODE, THR3[mod_measurement][mod-1]);
+ if (mod == 0 ) test_verbose_print ("mod = %d : %d > %d?", mod, noise_CODE, THR3[mod_measurement][mod]);
+ if (mod != 0 && mod != 7 ) test_verbose_print ("mod = %d : %d E ]%d,%d]?", mod, noise_CODE, THR3[mod_measurement][mod], THR3[mod_measurement][mod-1]);
+ if (mod == 7 ) test_fail_if (noise_CODE > accu*THR3[mod_measurement][mod-1]);
+ else
+ {
+ test_fail_if (noise_CODE <= accu*THR3[mod_measurement][mod]);
+ if (mod != 0) test_fail_if (noise_CODE > accu*THR3[mod_measurement][mod-1]);
+ }
+ }
+ }
+ } test_end;
+}
+
+void
+test_compute_worst_tonemap (test_t t)
+{
+ test_begin (t, "update or new worst tonemap")
+ {
+ uint c;
+
+ phy_chandata_t *b, *l;
+ phy_chandata_t *freq_noise = (phy_chandata_t *) blk_alloc_desc_range (PHY_CHANDATA_NRJ_BLK_NB, (blk_t **) &l);
+ tonemap_t *tm = NULL;
+
+ l->blk.next = NULL;
+ l->last = 1;
+
+ int carrier_uninit = PHY_CARRIER_NB;
+ int carrier_init = 0;
+ int carrier_index = -1;
+ int k=0;
+ uint noise1[PHY_CARRIER_NB];
+ for (b = freq_noise; b; b = (phy_chandata_t *) b->blk.next)
+ {
+ if (carrier_uninit > 128) b->size = 128;
+ else b->size = carrier_uninit;
+ b->type = PHY_CHANDATA_TYPE_NRJ;
+ phy_noise_t *data = (phy_noise_t *) b->blk.data;
+ for (c=0; c<BLK_SIZE/sizeof(phy_noise_t); c++)
+ {
+ carrier_index++;
+ carrier_uninit--;
+ carrier_init++;
+ *(data+c) = THR3[1][k%7];
+ k++;
+ noise1[carrier_index] = *(data+c);
+ if (carrier_uninit == 0) break;
+ }
+ }
+ bitloading_worst_tonemap_compute (&tm, freq_noise);
+ test_fail_if (!tm);
+ bitstream_t stream;
+ bitstream_init(&stream, tm->tmdma_desc_head->data, BLK_SIZE, BITSTREAM_READ);
+ for (c=0; c< PHY_CARRIER_NB; c++)
+ {
+ if (c == 1024)
+ {
+ bitstream_init(&stream, tm->tmdma_desc_head->next->data, BLK_SIZE, BITSTREAM_READ);
+ }
+ uint mod;
+ bitstream_access (&stream, &mod, 4);
+ uint noise = noise1[c];
+ if (mod == 0) test_fail_if (noise < THR3[1][0]);
+ if (mod == 7) test_fail_if (noise > THR3[1][6]);
+ if (mod>0 && mod<7)
+ {
+ test_fail_if (noise > THR3[1][mod-1]);
+ test_fail_if (noise <= THR3[1][mod]);
+ }
+ }
+
+ lib_rnd_init (&rnd, 23);
+
+ carrier_uninit = PHY_CARRIER_NB;
+ carrier_init = 0;
+ carrier_index = -1;
+ uint noise2[PHY_CARRIER_NB];
+ for (b = freq_noise; b; b = (phy_chandata_t *) b->blk.next)
+ {
+ phy_noise_t *data = (phy_noise_t *) b->blk.data;
+ for (c=0; c<BLK_SIZE/sizeof(phy_noise_t); c++)
+ {
+ carrier_index++;
+ carrier_uninit--;
+ carrier_init++;
+ *(data+c) = lib_rnd_uniform (&rnd, 2*noise1[carrier_index]+1);
+ noise2[carrier_index] = *(data+c);
+ if (carrier_uninit == 0) break;
+ }
+ }
+ bitloading_worst_tonemap_compute (&tm, freq_noise);
+ test_fail_if (!tm);
+ bitstream_init(&stream, tm->tmdma_desc_head->data, BLK_SIZE, BITSTREAM_READ);
+ for (c=0; c< PHY_CARRIER_NB; c++)
+ {
+ if (c == 1024)
+ {
+ bitstream_init(&stream, tm->tmdma_desc_head->next->data, BLK_SIZE, BITSTREAM_READ);
+ }
+ uint mod;
+ bitstream_access (&stream, &mod, 4);
+ uint noise = noise2[c]; if (noise1[c]>noise2[c]) noise = noise1[c];
+ if (mod == 0) test_fail_if (noise < THR3[1][0]);
+ if (mod == 7) test_fail_if (noise > THR3[1][6]);
+ if (mod>0 && mod<7)
+ {
+ test_fail_if (noise > THR3[1][mod-1]);
+ test_fail_if (noise <= THR3[1][mod]);
+ }
+ }
+ blk_release_desc_range ((blk_t *) freq_noise,(blk_t *) l);
+ blk_t *f = tm->tmdma_desc_head;
+ blk_release_desc_range (f, f->next);
+ tm = NULL;
+
+ } test_end;
+}
+
+int
+main (int argc, char **argv)
+{
+ test_t test;
+ frame_measurement_init();
+ test_init (test, argc, argv);
+ test_case_begin (test, "CE-computation");
+ test_is_time_noise_stable (test);
+ test_noise2mod (test);
+ test_compute_worst_tonemap (test);
+ test_result (test);
+ return (test_nb_failed (test) == 0 ? 0 : 1);
+}
+
diff --git a/ce/test/rx/general/src/test_frame_measurement.c b/ce/test/rx/general/src/test_frame_measurement.c
index fdab1bfa0d..96f8fe5b82 100755
--- a/ce/test/rx/general/src/test_frame_measurement.c
+++ b/ce/test/rx/general/src/test_frame_measurement.c
@@ -15,212 +15,19 @@
#include "common/std.h"
-#include "lib/bitstream.h"
#include "mac/common/tonemap.h"
#include "ce/test/common/print_utils.h"
-
#include "lib/rnd.h"
-#include "ce/test/common/gaussian.h"
#include "lib/test.h"
+//#include "ce/inc/frame_measurement.h"
lib_rnd_t rnd;
-int affect;
-int delay_unit;
-
-void
-test_is_time_noise_stable (test_t t)
-{
- test_begin (t, "is_time_noise_stable")
- {
- int i,j,k;
- phy_chandata_t *test = (phy_chandata_t *) blk_alloc_desc ();
- test->type = PHY_CHANDATA_TYPE_NRJ_SYMBOL;
- test->size = 113 ;
- double var;
- double sigma_lambda=0.00;
- uint stable_nb=0;
- for (k = 1 ; k < 20; k++)
- {
- sigma_lambda += 0.01;
- stable_nb = 0;
- for (j=0; j<100; j++)
- {
- lib_rnd_init (&rnd, j);
- phy_noise_t *data = (phy_noise_t *) test->blk.data;
- for (i=0; i<113; i++)
- {
- //my_print (" %d ", (int)(100.0*sigma_lambda));
- int l = 2*UND_CODE;
- var = lib_rnd_gaussian (&rnd, l, sigma_lambda*l);
- //printf ("var = %lf\n", var);
- if (var < 0) var = 2*l-var;
- if (var > MAX_UND_CODE) var = 2*l -var;
- if (var < 0) var = 0;
- if (var > MAX_UND_CODE) var = MAX_UND_CODE;
- //my_print ("%x\n",(int) var);
- *(data++) = (int) (var);
- }
- //print_buffer (test->blk.data, 128*4);
- if (is_time_noise_stable (test)) stable_nb++;
-
- }
- //test_verbose_print (" %d%% stable for s/l=0.01*%d", stable_nb, k);
- test_fail_if (k < 10 && stable_nb < 80 );
- test_fail_if (k > 10 && stable_nb > 20 );
- test_fail_if (k == 10 && (stable_nb < 20 || stable_nb > 80) );
- }
- blk_release_desc ((blk_t *) test);
- } test_end;
-}
-
-void
-test_noise2mod (test_t t)
-{
- test_begin (t, "noise to modulation")
- {
- uint accu = 1 ; // DSP provides directly the average
- uint noise_CODE;
- uint mod;
- uint mod_measurement;
- frame_measurement_init ();
- update_threshold (accu, 1);
- for (noise_CODE=0; noise_CODE<=UND_CODE; noise_CODE++)
- {
- //for (mod_measurement=0; mod_measurement<7;mod_measurement++)
- mod_measurement = 1; // ONLY THR-QPSK TODO others
- {
- mod = noise2mod (noise_CODE);
- if (mod == 7 ) test_verbose_print ("mod = %d : %d <= %d?", mod, noise_CODE, THR3[mod_measurement][mod-1]);
- if (mod == 0 ) test_verbose_print ("mod = %d : %d > %d?", mod, noise_CODE, THR3[mod_measurement][mod]);
- if (mod != 0 && mod != 7 ) test_verbose_print ("mod = %d : %d E ]%d,%d]?", mod, noise_CODE, THR3[mod_measurement][mod], THR3[mod_measurement][mod-1]);
- if (mod == 7 ) test_fail_if (noise_CODE > accu*THR3[mod_measurement][mod-1]);
- else
- {
- test_fail_if (noise_CODE <= accu*THR3[mod_measurement][mod]);
- if (mod != 0) test_fail_if (noise_CODE > accu*THR3[mod_measurement][mod-1]);
- }
- }
- }
- } test_end;
-}
-
-void
-test_compute_worst_tonemap (test_t t)
-{
- test_begin (t, "update or new worst tonemap")
- {
- uint c;
-
- phy_chandata_t *b, *l;
- phy_chandata_t *freq_noise = (phy_chandata_t *) blk_alloc_desc_range (PHY_CHANDATA_NRJ_BLK_NB, (blk_t **) &l);
- tonemap_t *tm = NULL;
-
- l->blk.next = NULL;
- l->last = 1;
-
- int carrier_uninit = PHY_CARRIER_NB;
- int carrier_init = 0;
- int carrier_index = -1;
- int k=0;
- uint noise1[PHY_CARRIER_NB];
- for (b = freq_noise; b; b = (phy_chandata_t *) b->blk.next)
- {
- if (carrier_uninit > 128) b->size = 128;
- else b->size = carrier_uninit;
- b->type = PHY_CHANDATA_TYPE_NRJ;
- phy_noise_t *data = (phy_noise_t *) b->blk.data;
- for (c=0; c<BLK_SIZE/sizeof(phy_noise_t); c++)
- {
- carrier_index++;
- carrier_uninit--;
- carrier_init++;
- *(data+c) = /*carrier_uninit*3*/ THR3[1][k%7]/*+lib_rnd_uniform (&rnd, 10)*/;
- k++;
- noise1[carrier_index] = *(data+c);
-
- if (carrier_uninit == 0) break;
- }
- }
- compute_worst_tonemap (&tm, freq_noise);
- test_fail_if (!tm);
- bitstream_t stream;
- bitstream_init(&stream, tm->tmdma_desc_head->data, BLK_SIZE, BITSTREAM_READ);
- for (c=0; c< PHY_CARRIER_NB; c++)
- {
- if (c == 1024)
- {
- bitstream_init(&stream, tm->tmdma_desc_head->next->data, BLK_SIZE, BITSTREAM_READ);
- }
- uint mod;
- bitstream_access (&stream, &mod, 4);
- uint noise = noise1[c];
- //ce_print ("test : mod = %d, noise=%d E [%d,%d[?\n",mod, noise, THR3[1][mod-1], THR3[1][mod]);
- if (mod == 0) test_fail_if (noise < THR3[1][0]);
- if (mod == 7) test_fail_if (noise > THR3[1][6]);
- if (mod>0 && mod<7)
- {
- test_fail_if (noise > THR3[1][mod-1]);
- test_fail_if (noise <= THR3[1][mod]);
- }
- }
- //ce_print_tonemap (tm);
-
- lib_rnd_t rnd;
- lib_rnd_init (&rnd, 23);
-
- carrier_uninit = PHY_CARRIER_NB;
- carrier_init = 0;
- carrier_index = -1;
- uint noise2[PHY_CARRIER_NB];
- for (b = freq_noise; b; b = (phy_chandata_t *) b->blk.next)
- {
- phy_noise_t *data = (phy_noise_t *) b->blk.data;
- for (c=0; c<BLK_SIZE/sizeof(phy_noise_t); c++)
- {
- carrier_index++;
- carrier_uninit--;
- carrier_init++;
- *(data+c) = lib_rnd_uniform (&rnd, 2*noise1[carrier_index]+1);
- noise2[carrier_index] = *(data+c);
- if (carrier_uninit == 0) break;
- }
- }
- compute_worst_tonemap (&tm, freq_noise);
- //ce_print_tonemap (tm);
- test_fail_if (!tm);
- bitstream_init(&stream, tm->tmdma_desc_head->data, BLK_SIZE, BITSTREAM_READ);
- for (c=0; c< PHY_CARRIER_NB; c++)
- {
- if (c == 1024)
- {
- bitstream_init(&stream, tm->tmdma_desc_head->next->data, BLK_SIZE, BITSTREAM_READ);
- }
- uint mod;
- bitstream_access (&stream, &mod, 4);
- uint noise = noise2[c]; if (noise1[c]>noise2[c]) noise = noise1[c];
- //ce_print ("test : mod = %d, noise=%d E [%d,%d[?\n",mod, noise, THR3[1][mod-1], THR3[1][mod]);
- if (mod == 0) test_fail_if (noise < THR3[1][0]);
- if (mod == 7) test_fail_if (noise > THR3[1][6]);
- if (mod>0 && mod<7)
- {
- test_fail_if (noise > THR3[1][mod-1]);
- test_fail_if (noise <= THR3[1][mod]);
- }
- }
- blk_release_desc_range ((blk_t *) freq_noise,(blk_t *) l);
- blk_t *f = tm->tmdma_desc_head;
- blk_release_desc_range (f, f->next);
- tm = NULL;
-
- } test_end;
-}
void
test_alloc_release (test_t test)
{
test_begin (test, "frame_measurement allocation and release")
{
- //blk_print_memory ();
test_fail_unless (blk_check_memory ());
} test_end;
}
@@ -228,8 +35,6 @@ test_alloc_release (test_t test)
void
sar_fill_ber (pb_measurement_list_t *first, uint n, uint ber_init_value)
{
- //my_print ("sar fill %d pb in buffer @0x%x started from %d\n",
- // n, first, ber_init_value);
uint i;
u32 *wrdata = (u32 *) first->data;
uint offset = first->pb_nb;
@@ -257,11 +62,9 @@ test_frame_measurement_ber_add (test_t t)
{
uint sar_call_nb, pb_nb_per_call;
for (sar_call_nb=1; sar_call_nb < MAX_PB; sar_call_nb++)
- //sar_call_nb =1;
{
uint max_pb_nb_per_call = MAX_PB / sar_call_nb;
for (pb_nb_per_call=1; pb_nb_per_call<max_pb_nb_per_call ; pb_nb_per_call ++)
- //pb_nb_per_call = 1;
{
uint N = sar_call_nb;
uint pb_nb_to_add = pb_nb_per_call;
@@ -271,8 +74,6 @@ test_frame_measurement_ber_add (test_t t)
pbproc_rx_params_t *rx_params = (pbproc_rx_params_t *) blk_alloc();
frame_measurement_append (rx_params, 0, &first_ber, &last_ber, NULL);
frame_measurement_t *fm = frame_measurement_get_next();
- //my_print ("fm management : %d %d %d\n",fm_reader, fm_writer, fm_number);
- //frame_measurement_print (fm);
for (n=0; n<N; n++)
{
frame_measurement_ber_add (fm, pb_nb_to_add, &first_ber, &last_ber);
@@ -307,7 +108,6 @@ test_frame_measurement_ber_add (test_t t)
if ((N*pb_nb_to_add)%(BLK_SIZE/4) >0) comp++;
test_fail_if (cpt != comp);
frame_measurement_release (fm);
- //frame_measurement_print (fm);
}
}
} test_end;
@@ -353,7 +153,6 @@ test_frame_measurement_noise_add (test_t t)
}
for (i=0; i<PHY_CHANDATA_TYPE_NB; i++)
{
- //my_print ("%d ",i);
phy_chandata_t *chandata = fm->type_head[i];
while (chandata)
{
@@ -364,7 +163,6 @@ test_frame_measurement_noise_add (test_t t)
test_fail_if (*(data+j) != i*j);
}
int last = chandata->last;
- //my_print ("last = %d\n", last);
chandata = (phy_chandata_t *) chandata->blk.next;
if (!chandata) test_fail_if (last == 0);
else test_fail_if (last == 1);
@@ -388,11 +186,9 @@ test_frame_measurement_add (test_t t)
int i;
for (i=0; i<N; i++)
{
- //my_print ("added = %d \t pending = %d \n",nb_frame_added, nb_frame_measurement);
alea = lib_rnd_uniform (&rnd, 100);
if (alea > 5 )
{
- //my_print (" one more\n");
pbproc_rx_params_t *rx_params = (pbproc_rx_params_t *) blk_alloc();
pb_measurement_list_t **f,**l;
f = l = NULL;
@@ -403,21 +199,15 @@ test_frame_measurement_add (test_t t)
nb_frame_added++;
nb_frame_measurement++;
}
- else
- {
- //my_print ("cancelled\n");
- }
}
else
{
if (nb_frame_measurement == 0)
{
- //my_print (" no more frame\n");
test_fail_if (fm_number != 0);
}
else
{
- //my_print (" one less\n");
frame_measurement_t *first = frame_measurement_get_next ();
int test = first->rx_params->preamble_ntb;
test_fail_if (test != (nb_frame_added - nb_frame_measurement));
@@ -430,7 +220,6 @@ test_frame_measurement_add (test_t t)
{
frame_measurement_t *first = frame_measurement_get_next ();
int test = first->rx_params->preamble_ntb;
- //my_print (" test= %d <-> (%d - %d)\n",test, nb_frame_added, nb_frame_measurement);
test_fail_if (test != (nb_frame_added - nb_frame_measurement));
frame_measurement_release (first);
nb_frame_measurement--;
@@ -443,26 +232,13 @@ int
main (int argc, char **argv)
{
test_t test;
- //dbg_fatal_try_begin
- {
- frame_measurement_init();
- test_init (test, argc, argv);
-
- test_case_begin (test, "CE-computation");
- test_is_time_noise_stable (test);
- test_noise2mod (test);
- test_compute_worst_tonemap (test);
- test_case_begin (test, "CE-frame measurement management");
- test_frame_measurement_ber_add (test);
- test_frame_measurement_noise_add (test);
- test_frame_measurement_add (test);
- test_alloc_release (test);
- }
- //dbg_fatal_try_catch (const char *fatal_message)
- {
- //my_print ("assertion failure... %s \n",fatal_message);
- }
- //dbg_fatal_try_end;
+ frame_measurement_init();
+ test_init (test, argc, argv);
+ test_case_begin (test, "CE-frame measurement management");
+ test_frame_measurement_ber_add (test);
+ test_frame_measurement_noise_add (test);
+ test_frame_measurement_add (test);
+ test_alloc_release (test);
test_result (test);
return (test_nb_failed (test) == 0 ? 0 : 1);
}
diff --git a/ce/test/rx/general/src/test_rx.c b/ce/test/rx/general/src/test_rx.c
index 8f77c51deb..8d5654154f 100755
--- a/ce/test/rx/general/src/test_rx.c
+++ b/ce/test/rx/general/src/test_rx.c
@@ -25,6 +25,7 @@
#include "lib/trace.h"
#include "mac/common/ntb.h"
#include "ce/inc/trace.h"
+#include "ce/inc/bitloading.h"
lib_rnd_t rnd;
test_t test;
diff --git a/ce/test/rx/general/src/test_sar_integration.c b/ce/test/rx/general/src/test_sar_integration.c
index a4db2a1602..0d31cf2d55 100755
--- a/ce/test/rx/general/src/test_sar_integration.c
+++ b/ce/test/rx/general/src/test_sar_integration.c
@@ -23,6 +23,7 @@
#include "mac/common/ntb.h"
#include "ce/inc/trace.h"
#include "hal/phy/phy.h"
+#include "ce/inc/bitloading.h"
#define FRAME_PRIORITY 10
cyg_thread frame_thread;
diff --git a/ce/test/rx/general/target-Makefile b/ce/test/rx/general/target-Makefile
index f88db9a399..b34e0ac597 100644
--- a/ce/test/rx/general/target-Makefile
+++ b/ce/test/rx/general/target-Makefile
@@ -17,7 +17,7 @@ test_sar_target_ecos_synth_MODULES = lib mac/sar ce mac/common mac/sar/bridgedma
mac_pbproc_MODULE_SOURCES = mfs.c
-ce_MODULE_SOURCES = cei_param.c frame_measurement.c rx.c trace.c
+ce_MODULE_SOURCES = bitloading.c cei_param.c frame_measurement.c rx.c trace.c
ce_test_common_MODULE_SOURCES = print_utils.c
VARIANT = target
diff --git a/ce/test/rx/host_linux_sparc/Makefile b/ce/test/rx/host_linux_sparc/Makefile
index 178da8a77b..9dba358e66 100755
--- a/ce/test/rx/host_linux_sparc/Makefile
+++ b/ce/test/rx/host_linux_sparc/Makefile
@@ -10,7 +10,7 @@ HOST_PROGRAMS = test_speed_host_linux_sparc
test_speed_host_linux_sparc_SOURCES = test_speed.c
test_speed_host_linux_sparc_MODULES = lib mac/common ce ce/test/common
-ce_MODULE_SOURCES = cei_param.c frame_measurement.c
+ce_MODULE_SOURCES = cei_param.c frame_measurement.c bitloading.c
ce_test_common_MODULE_SOURCES = print_utils.c
include $(BASE)/common/make/top.mk
diff --git a/ce/test/rx/maximus/Makefile b/ce/test/rx/maximus/Makefile
index 6508095d21..67c5d5b5b9 100644
--- a/ce/test/rx/maximus/Makefile
+++ b/ce/test/rx/maximus/Makefile
@@ -9,7 +9,7 @@ TARGET_PROGRAMS = test_rx
test_rx_SOURCES = test_rx.c
test_rx_MODULES=lib host mac/common hal/phy/maximus mac/sar ce ce/test/rx/maximus/overide/mac/pbproc ce/test/rx/general/overide/cp/interf ce/test/common
-ce_MODULE_SOURCES = cei_param.c frame_measurement.c rx.c trace.c
+ce_MODULE_SOURCES = cei_param.c frame_measurement.c rx.c trace.c bitloading.c
include $(BASE)/common/make/top.mk
diff --git a/ce/test/rx/tonemap_refresh/Makefile b/ce/test/rx/tonemap_refresh/Makefile
index fe6c7dd9d9..c8353c0248 100644
--- a/ce/test/rx/tonemap_refresh/Makefile
+++ b/ce/test/rx/tonemap_refresh/Makefile
@@ -12,7 +12,7 @@ test_tonemaps_refresh_target_ecos_synth_SOURCES = test_tonemaps_refresh.c
test_tonemaps_refresh_target_ecos_synth_MODULES = lib mac/common ce ce/test/common ce/test/rx/general/overide/cp/interf
-ce_MODULE_SOURCES = cei_param.c frame_measurement.c rx.c trace.c
+ce_MODULE_SOURCES = cei_param.c frame_measurement.c rx.c trace.c bitloading.c
ce_test_common_MODULE_SOURCES = print_utils.c
diff --git a/common/tests/tests b/common/tests/tests
index 461f0791dd..9d95ccbab6 100644
--- a/common/tests/tests
+++ b/common/tests/tests
@@ -202,6 +202,7 @@ make
ce_test_cei: ./obj/host/test_cei_host_linux_i386
ce_test_cei_param: ./obj/host/test_cei_param_host_linux_i386
ce_test_frame_measurement: ./obj/host/test_fm_host_linux_i386
+ce_test_bitloading: ./obj/host/test_bitloading_host_linux_i386
ce_test_rx: ./obj/target/test_rx_target_ecos_synth.elf
ce_test_sar_integration: ./obj/target/test_sar_target_ecos_synth.elf
@@ -210,7 +211,7 @@ make
ce_test_tonemaps_refresh: ./obj/test_tonemaps_refresh_target_ecos_synth.elf
ce/test/tx:
-make: make COV=y
+make
ce_test_tx: ./obj/host/test_tx
ce_test_tonemaps_expiration : ./obj/target/test_expiration_target_ecos_synth.elf