summaryrefslogtreecommitdiff
path: root/cesar/ce
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/ce')
-rwxr-xr-xcesar/ce/Module4
-rw-r--r--cesar/ce/doc/architecture.odtbin0 -> 73862 bytes
-rw-r--r--cesar/ce/inc/bitloading.h133
-rwxr-xr-xcesar/ce/inc/cei.h424
-rwxr-xr-xcesar/ce/inc/cei_param.h97
-rw-r--r--cesar/ce/inc/ecos_time.h23
-rwxr-xr-xcesar/ce/inc/mpdu_measure_store.h139
-rwxr-xr-xcesar/ce/inc/rx.h203
-rw-r--r--cesar/ce/inc/trace.h74
-rwxr-xr-xcesar/ce/inc/tx.h108
-rwxr-xr-xcesar/ce/rxce_stats.h96
-rw-r--r--cesar/ce/src/bitloading.c215
-rwxr-xr-xcesar/ce/src/cei_param.c60
-rwxr-xr-xcesar/ce/src/mpdu_measure_store.c260
-rwxr-xr-xcesar/ce/src/rx.c300
-rw-r--r--cesar/ce/src/rxce_stats.c0
-rw-r--r--cesar/ce/src/trace.c52
-rwxr-xr-xcesar/ce/src/tx.c106
-rwxr-xr-xcesar/ce/test/common/Module1
-rw-r--r--cesar/ce/test/common/ecos_overide/cyg/kernel/Module1
-rw-r--r--cesar/ce/test/common/ecos_overide/cyg/kernel/kapi.h45
-rw-r--r--cesar/ce/test/common/ecos_overide/cyg/kernel/src/kapi.c62
-rw-r--r--cesar/ce/test/common/gaussian.h23
-rwxr-xr-xcesar/ce/test/common/print_utils.h60
-rw-r--r--cesar/ce/test/common/src/gaussian.c29
-rwxr-xr-xcesar/ce/test/common/src/print_utils.c145
-rw-r--r--cesar/ce/test/common/tonemap_utils.h135
-rwxr-xr-xcesar/ce/test/cov/cov_all_run.sh42
-rwxr-xr-xcesar/ce/test/cov/cov_one_run.sh63
-rwxr-xr-xcesar/ce/test/rx/Config5
-rw-r--r--cesar/ce/test/rx/general/Makefile8
-rwxr-xr-xcesar/ce/test/rx/general/host-Makefile33
-rw-r--r--cesar/ce/test/rx/general/overide/cp/Module1
-rw-r--r--cesar/ce/test/rx/general/overide/cp/cp.h50
-rw-r--r--cesar/ce/test/rx/general/overide/cp/interf/Module1
-rwxr-xr-xcesar/ce/test/rx/general/overide/cp/interf/interf.h65
-rwxr-xr-xcesar/ce/test/rx/general/overide/cp/interf/src/interf.c52
-rw-r--r--cesar/ce/test/rx/general/overide/cp/src/cp.c92
-rwxr-xr-xcesar/ce/test/rx/general/src/test_bitloading.c235
-rwxr-xr-xcesar/ce/test/rx/general/src/test_cei.c80
-rwxr-xr-xcesar/ce/test/rx/general/src/test_cei_param.c86
-rwxr-xr-xcesar/ce/test/rx/general/src/test_mpdu_measure_store.c294
-rwxr-xr-xcesar/ce/test/rx/general/src/test_rx.c281
-rwxr-xr-xcesar/ce/test/rx/general/src/test_sar_integration.c303
-rw-r--r--cesar/ce/test/rx/general/target-Makefile26
-rwxr-xr-xcesar/ce/test/rx/general/target-ecos.ecc.sh5
-rwxr-xr-xcesar/ce/test/rx/host_linux_sparc/Makefile17
-rw-r--r--cesar/ce/test/rx/host_linux_sparc/src/test_speed.c152
-rwxr-xr-xcesar/ce/test/rx/inc/test_rx.h37
-rw-r--r--cesar/ce/test/rx/maximus/Makefile21
-rw-r--r--cesar/ce/test/rx/maximus/ecos.ecc.sh104
-rw-r--r--cesar/ce/test/rx/maximus/overide/mac/pbproc/Module1
-rw-r--r--cesar/ce/test/rx/maximus/overide/mac/pbproc/pbproc.h145
-rw-r--r--cesar/ce/test/rx/maximus/overide/mac/pbproc/src/pbproc.c261
-rw-r--r--cesar/ce/test/rx/maximus/send_noise.py102
-rw-r--r--cesar/ce/test/rx/maximus/src/test_rx.c187
-rw-r--r--cesar/ce/test/rx/tonemap_refresh/Makefile18
-rwxr-xr-xcesar/ce/test/rx/tonemap_refresh/ecos.ecc.sh5
-rw-r--r--cesar/ce/test/rx/tonemap_refresh/src/test_tonemaps_refresh.c117
-rw-r--r--cesar/ce/test/tx/Makefile8
-rwxr-xr-xcesar/ce/test/tx/host-Makefile17
-rw-r--r--cesar/ce/test/tx/src/test_expiration.c121
-rwxr-xr-xcesar/ce/test/tx/src/test_tx.c150
-rw-r--r--cesar/ce/test/tx/target-Makefile22
-rwxr-xr-xcesar/ce/test/tx/target-ecos.ecc.sh5
-rw-r--r--cesar/ce/test/tx/test.h18
66 files changed, 6025 insertions, 0 deletions
diff --git a/cesar/ce/Module b/cesar/ce/Module
new file mode 100755
index 0000000000..d4db642c42
--- /dev/null
+++ b/cesar/ce/Module
@@ -0,0 +1,4 @@
+SOURCES := rx.c tx.c rxce_stats.c bitloading.c mpdu_measure_store.c cei_param.c
+ifeq ($(CONFIG_TRACE),y)
+SOURCES += trace.c
+endif
diff --git a/cesar/ce/doc/architecture.odt b/cesar/ce/doc/architecture.odt
new file mode 100644
index 0000000000..383e28134b
--- /dev/null
+++ b/cesar/ce/doc/architecture.odt
Binary files differ
diff --git a/cesar/ce/inc/bitloading.h b/cesar/ce/inc/bitloading.h
new file mode 100644
index 0000000000..28b91d996f
--- /dev/null
+++ b/cesar/ce/inc/bitloading.h
@@ -0,0 +1,133 @@
+#ifndef ce_inc_bitloading_h
+#define ce_inc_bitloading_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+
+#include "ce/inc/mpdu_measure_store.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, mpdu_measure_t *measure);
+
+bitloading_modification_t
+bitloading_initial_step (sta_t *sta, mpdu_measure_t *measure);
+
+bitloading_modification_t
+bitloading_dynamic_step (sta_t *sta, mpdu_measure_t *measure);
+
+/**
+ * Read the noise per carrier and choose the appropriate modulation. If the
+ * current modulation is higher, the modulation is modified to the lower.
+ * \param worst_tm Current tonemap to modify or allocate if null. (modulation map).
+ * \param noise_nrj Average noise on each carriers along the MPDU.
+ * \return true if at least one carrier has been down.
+ */
+bool // Has tonemap been modified?.
+bitloading_worst_tonemap_compute (tonemap_t **worst_tm, phy_chandata_t *noise_nrj);
+
+/**
+ * Detect if the noise along the frame has changed 'a lot'.
+ * \param noise_nrj_symbol Average noise by symbols along the MPDU.
+ * \return true if noise is considered as stable and so if the noise per
+ * carrier(noise_nrj) can be trust.
+ */
+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);
+
+uint // date_modulo_BEACON_PERIOD_ATU
+bitloading_date_in_beacon_atu_get (uint mpdu_date_tck, uint beacon_date_tck);
+
+//void
+//manage_interval (tonemaps_t *tms, mpdu_measure_t *mpdu_measure);
+
+#endif /* ce_inc_bitloading_h */
diff --git a/cesar/ce/inc/cei.h b/cesar/ce/inc/cei.h
new file mode 100755
index 0000000000..15e64a341b
--- /dev/null
+++ b/cesar/ce/inc/cei.h
@@ -0,0 +1,424 @@
+#ifndef ce_inc_cei_h
+#define ce_inc_cei_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file ce/inc/cei.h
+ * \brief static functions to create and decode cei messages
+ * \ingroup ce
+ *
+ */
+
+//#include "ce/inc/cei_param.h"
+#include "mac/common/tonemask.h"
+#include "mac/common/timings.h"
+//#include "ce/test/common/print_utils.h"
+#include "lib/bitstream.h"
+#include "cyg/kernel/kapi.h"
+#include "ce/inc/ecos_time.h"
+
+#define CM_CHAN_EST_IND 0x6014
+#define CM_TM_UPDATE_IND 0x6018
+
+//TODO Accelerate access in tonemap and tonemask management.
+
+struct cei_created_status_t
+{
+ /** Length of mm_entry. */
+ uint length;
+ /** type of created CEI to send.*/
+ uint mm_type;
+};
+typedef struct cei_created_status_t cei_created_status_t;
+
+
+BEGIN_DECLS
+
+#ifdef RXCE
+
+static inline void
+STREAM_WRITE (bitstream_t *ptr, uint val, uint length)
+{
+ uint to_write = val;
+ bitstream_access (ptr, &to_write, length);
+}
+
+
+/**
+ * Run Length Encoding tonemap cf Spec HPAV in CM_CHAN_EST.IND description.
+ * \param writer pointer on buffer that manages nibbles writing.
+ * \param tm tonemap to encode.
+ * \param mask tonemask
+ * \return the entry number.
+ *
+ */
+static uint
+cei_tmdata_encode (bitstream_t *ctx_stream, blk_t *tm, u8 *mask)
+{
+ uint nibbles[1155];
+ int c=0;
+ uint i, nibble, next_nibble;
+ int consecutive_nb = 0;
+ int entry_nb = 0;
+ u32 *tm_data = (u32 *) tm->data;
+ uint carrier_nb = tonemask_carrier_nb (mask);
+ for (i=0; i<128; i++)
+ {
+ uint eight_nibble = *(tm_data++);
+ u8 local_mask = mask[i];
+ uint j;
+ for (j=0; j<8; j++)
+ {
+ if ( (local_mask & 0x01) == 0x01 )
+ {
+ nibbles[c++] = eight_nibble & 0x0F;
+ }
+ eight_nibble = eight_nibble >> 4;
+ local_mask = local_mask >> 1;
+ }
+ }
+ tm_data = (u32 *) tm->next->data;
+ for (i=0; i<17; i++)
+ {
+ uint eight_nibble = *(tm_data++);
+ u8 local_mask = mask[(i+128)];
+ uint j;
+ for (j=0; j<8; j++)
+ {
+ if ( (local_mask & 0x01) == 0x01 )
+ {
+ nibbles[c++] = eight_nibble & 0x0F;
+ }
+ eight_nibble = eight_nibble >> 4;
+ local_mask = local_mask >> 1;
+ }
+ }
+ nibble = nibbles[0];
+ for (i=0; i<carrier_nb; i++)
+ {
+ next_nibble = nibbles[i+1];
+ consecutive_nb ++;
+
+ if ( (next_nibble != nibble) || (consecutive_nb == 74)
+ || (i==carrier_nb-1) )
+ {
+ entry_nb++;
+ if(consecutive_nb == 1)
+ {
+ bitstream_access (ctx_stream, &nibble, 4);
+ }
+ else if (consecutive_nb == 2)
+ {
+ bitstream_access (ctx_stream, &nibble, 4);
+ bitstream_access (ctx_stream, &nibble, 4);
+ entry_nb++;
+ }
+ else if (consecutive_nb <= 10)
+ {
+ uint tmp = (consecutive_nb - 3 )|8;
+ bitstream_access (ctx_stream, &nibble, 4);
+ bitstream_access (ctx_stream, &tmp, 4);
+ }
+ else if(consecutive_nb <= 74)
+ {
+ uint tmp = ((( consecutive_nb-3) >> 3) +7);
+ bitstream_access (ctx_stream, &nibble, 4);
+ bitstream_access (ctx_stream, &tmp, 4);
+ tmp = (consecutive_nb-3)|8;
+ bitstream_access (ctx_stream, &tmp, 4);
+ }
+ dbg_assert (consecutive_nb <= 74 );
+ consecutive_nb = 0;
+ }
+ nibble = next_nibble;
+ }
+ bitstream_finalise (ctx_stream);
+
+ return (entry_nb);
+}
+
+/**
+ * Write a cei message in a buffer. // Only mmentry.
+ * \param dest_mm_entry start of mmentry buffer.
+ * \param mask tonemask.
+ * \param rx_tonemaps Set of tonemap used to create the CEI.
+ * \param new_tmi Tonemap index of set whose data must be sent. If no tonemap
+ * data must be sent, new_tmi must be TONEMAP_INDEX_NULL.
+ * \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_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
+ * for time ).
+ * TODO : Management of old_tmi to create a CM_UPDATE_TM.IND instead of
+ * CM_CHAN_EST.IND
+ */
+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;
+ bitstream_t *w_ptr = &stream_writer;
+ int i=0;
+ u8 valid_tm_list_lg=0;
+ u8 respt = 0x00;
+ uint mme_len;
+ tonemap_t *new_tm;
+ uint entry_nb;
+ dbg_assert (dest_mm_entry);
+ dbg_assert (rx_tonemaps);
+ valid_tm_list_lg = tonemap_valid_nb (rx_tonemaps);
+ bitstream_init (w_ptr, dest_mm_entry, 1518, BITSTREAM_WRITE );
+ STREAM_WRITE (w_ptr, rx_tonemaps->max_fl_av, 16);
+ STREAM_WRITE (w_ptr, rx_tonemaps->rifs_av_one_sym_tck / MAC_TCK_PER_FL, 8);
+ STREAM_WRITE (w_ptr, rx_tonemaps->rifs_av_two_sym_tck / MAC_TCK_PER_FL, 8);
+ STREAM_WRITE (w_ptr, rx_tonemaps->rifs_av_g2_sym_tck / MAC_TCK_PER_FL, 8);
+ STREAM_WRITE(w_ptr, respt, 8);
+ STREAM_WRITE(w_ptr, rx_tonemaps->max_tm, 8);
+ STREAM_WRITE(w_ptr, rx_tonemaps->default_tmi, 8);
+ STREAM_WRITE(w_ptr, (u8)rx_tonemaps->scl_cp, 8);
+ STREAM_WRITE(w_ptr, (u8)rx_tonemaps->scl_cfp, 8);
+ STREAM_WRITE(w_ptr, valid_tm_list_lg, 8);
+ for (i=0; i<TONEMAP_INDEX_NB; i++) if (rx_tonemaps->tm[i])
+ {
+ STREAM_WRITE(w_ptr, i+4, 8);
+ }
+
+ tonemap_intervals_t *intervals = rx_tonemaps->intervals;
+ STREAM_WRITE(w_ptr, intervals->intervals_nb, 8);
+ for (i=0; i<(int)intervals->intervals_nb; i++)
+ {
+ STREAM_WRITE(w_ptr, intervals->interval[i].end_offset_atu, 16);
+ STREAM_WRITE(w_ptr, intervals->interval[i].tmi, 8);
+ }
+ if(new_tmi != TONEMAP_INDEX_NULL)
+ {
+ new_tm=rx_tonemaps->tm[new_tmi];
+ dbg_assert_ptr (new_tm);
+ STREAM_WRITE(w_ptr, new_tmi+4, 8);
+ STREAM_WRITE(w_ptr, new_tm->cpf, 8);
+ STREAM_WRITE(w_ptr, new_tm->fecrate, 8);
+ STREAM_WRITE(w_ptr, new_tm->gil, 8);
+ STREAM_WRITE(w_ptr, 0x01, 8);
+ u32 *entry_nb_address = stream_writer.stream;
+ u32 entry_nb_offset = stream_writer.bit_offset;
+ STREAM_WRITE(w_ptr, 0xFFFF, 16);
+ entry_nb = cei_tmdata_encode (&stream_writer, new_tm->tmdma_desc_head, mask);
+ bitstream_direct_write (entry_nb_address, entry_nb_offset, entry_nb, 16);
+ }
+ bitstream_finalise (&stream_writer);
+ mme_len = ((u32) stream_writer.stream) - ((u32)stream_writer.start) + ((stream_writer.bit_offset+7)/8);
+ cei_created_status_t ret;
+ ret.length = mme_len;
+ ret.mm_type = CM_CHAN_EST_IND;
+ return(ret);
+}
+#endif
+
+#ifdef TXCE
+
+static inline void
+cei_tone_write (bitstream_t *stream_writer, uint tone, uint *write_nb, u8 *next_data)
+{
+ bitstream_access (stream_writer, &tone, 4);
+ *write_nb = (*write_nb)+1;
+ if ( (*write_nb) == BLK_SIZE*2)
+ {
+ bitstream_finalise (stream_writer);
+ bitstream_init (stream_writer, next_data, BLK_SIZE, BITSTREAM_WRITE);
+ }
+}
+
+/**
+ * Update a set of tonemap from cei message.
+ * \param tx_tonemaps_to_update set of tonemaps to update.
+ * \param mm_type type of cei message
+ * \param mm_entry start address of mmentry.
+ * \param mask tonemask
+ * \return the valid tonemap. [A32...A0] bits set if valid.
+ */
+static u32 // valid_tonemap u32 as 32 tonemap max.
+cei_decode (tonemaps_t *tx_tonemaps_to_update, int mm_type, u8 *mm_entry, u8 *mask)
+{
+ //TODO switch MMTYPE
+ int i,j;
+ int new_tmi;
+ int valid_nb; // nb tonemap valid announced by mme
+ u32 tonemaps_valid_status; //return value : tonemap_valid_status that must be kept for release_old_tonemap done under lock_it
+ u32 sort; // local tonemap_valid_status that must be kept for release_old_tonemap done under lock_it
+ int next_nibble, next_next_nibble;
+ int entry_nb;
+ int mod; //modulation
+ int codage;
+ int tmp_default_tmi;
+ bitstream_t stream_reader;
+ bitstream_t stream_writer;
+ uint read;
+ uint write_nb = 0;
+ bitstream_init (&stream_reader, mm_entry, 1518, BITSTREAM_READ);
+ bitstream_access (&stream_reader, &read, 16);
+ tx_tonemaps_to_update->max_fl_av = read;
+ bitstream_access (&stream_reader, &read, 8);
+ tx_tonemaps_to_update->rifs_av_one_sym_tck = read*MAC_TCK_PER_FL;
+ bitstream_access (&stream_reader, &read, 8);
+ tx_tonemaps_to_update->rifs_av_two_sym_tck = read*MAC_TCK_PER_FL;
+ bitstream_access (&stream_reader, &read, 8);
+ tx_tonemaps_to_update->rifs_av_g2_sym_tck = read*MAC_TCK_PER_FL;
+ bitstream_access (&stream_reader, &read, 8);
+ bitstream_access (&stream_reader, &read, 8);
+ tx_tonemaps_to_update->max_tm = read;
+ bitstream_access (&stream_reader, &read, 8);
+ tmp_default_tmi = read;
+ bitstream_access (&stream_reader, &read, 8);
+ tx_tonemaps_to_update->scl_cp = read;
+ bitstream_access (&stream_reader, &read, 8);
+ tx_tonemaps_to_update->scl_cfp = read;
+
+ bitstream_access (&stream_reader, &valid_nb, 8);
+ tonemaps_valid_status = 0;
+ for (i=0; i<valid_nb; i++)
+ {
+ bitstream_access (&stream_reader, &read, 8);
+ tonemaps_valid_status = tonemaps_valid_status | ( 1 << (read - 4) );
+ }
+ sort = tonemaps_valid_status;
+ for (i=0; i<TONEMAP_INDEX_NB; i++)
+ {
+ if ( ((sort & 0x01) == 0x01) && (!tx_tonemaps_to_update->tm[i]) )
+ {
+ tx_tonemaps_to_update->tm[i] = tonemap_alloc();
+ }
+ if ( ((sort & 0x01) == 0x00) && (tx_tonemaps_to_update->tm[i]) ) tonemap_release (tx_tonemaps_to_update, i);
+ sort = sort >> 1;
+ }
+ tonemap_intervals_t *intervals = tx_tonemaps_to_update->intervals;
+ if (intervals != tx_tonemaps_to_update->swap_intervals) intervals++;
+ //intervals->intervals_nb = READ_U8;
+ bitstream_access (&stream_reader, &read, 8);
+ intervals->intervals_nb = read;
+ for (i=0; i<(int)intervals->intervals_nb; i++)
+ {
+ //intervals->interval[i].end_offset_atu = (READ_U8 <<8);
+ //intervals->interval[i].end_offset_atu += READ_U8;
+ bitstream_access (&stream_reader, &read, 16);
+ intervals->interval[i].end_offset_atu = read;
+ //intervals->interval[i].tmi = READ_U8;
+ bitstream_access (&stream_reader, &read, 8);
+ intervals->interval[i].tmi = read;
+ }
+
+ bitstream_access (&stream_reader, &new_tmi, 8);
+ if(new_tmi>=4)
+ {
+ new_tmi-=4;
+ dbg_assert (tx_tonemaps_to_update->tm[new_tmi]);
+ dbg_assert (tx_tonemaps_to_update->tm[new_tmi]->tmdma_desc_head);
+ bitstream_access (&stream_reader, &read, 8);
+ tx_tonemaps_to_update->tm[new_tmi]->cpf = read;
+ bitstream_access (&stream_reader, &read, 8);
+ tx_tonemaps_to_update->tm[new_tmi]->fecrate = read;
+ bitstream_access (&stream_reader, &read, 8);
+ tx_tonemaps_to_update->tm[new_tmi]->gil = read;
+ bitstream_access (&stream_reader, &codage, 8);
+
+ if (codage == 1 || codage == 0) // ABSOLUTE CODE(SAME DECODE IF COMPRESSED OR NOT)
+ {
+ bitstream_access (&stream_reader, &entry_nb, 16);
+
+ bitstream_init (&stream_writer, tx_tonemaps_to_update->tm[new_tmi]->tmdma_desc_head->data, BLK_SIZE, BITSTREAM_WRITE);
+ u8 *next_data = tx_tonemaps_to_update->tm[new_tmi]->tmdma_desc_head->next->data;
+ bitstream_access (&stream_reader, &mod, 4);
+
+ int c=0;
+ for (i=0; i<entry_nb; i++)
+ {
+ bitstream_access (&stream_reader, &next_nibble, 4);
+ if (next_nibble < 8 )
+ {
+ while ( ((mask[c/8] & (1<<(c%8)))) == 0)
+ {
+ cei_tone_write (&stream_writer, 0, &write_nb, next_data);
+ c++;
+ }
+ cei_tone_write (&stream_writer, mod, &write_nb, next_data);
+ c++;
+ mod = next_nibble;
+ }
+ else
+ {
+ bitstream_access (&stream_reader, &next_next_nibble, 4);
+ if (next_next_nibble < 8)
+ {
+ for (j=0; j<next_nibble-5; j++)
+ {
+ while (((mask[c/8] & (1<<(c%8)))) == 0)
+ {
+ cei_tone_write (&stream_writer, 0, &write_nb, next_data);
+ c++;
+ }
+ cei_tone_write (&stream_writer, mod, &write_nb, next_data);
+ c++;
+ }
+ mod = next_next_nibble;
+
+ }
+ else
+ {
+ for (j=0; j < (3 + ( ( (next_nibble-7) << 3) | ( next_next_nibble & 7) )); j++)
+ {
+ while ((mask[c/8] & (1<<(c%8))) == 0)
+ {
+ cei_tone_write (&stream_writer, 0, &write_nb, next_data);
+ c++;
+ }
+ cei_tone_write (&stream_writer, mod, &write_nb, next_data);
+ c++;
+ }
+ bitstream_access (&stream_reader, &mod, 4);
+ }
+ }
+ }
+ cei_tone_write (&stream_writer, 0, &write_nb, next_data);
+ }
+ else
+ {
+ // TODO: RELATIVE CODAGE
+ }
+ }
+ bitstream_finalise (&stream_writer);
+ // ATOMIC switch intervals
+ tx_tonemaps_to_update->intervals = intervals;
+ // ATOMIC set tonemap default;
+ tx_tonemaps_to_update->default_tmi = tmp_default_tmi;
+ tx_tonemaps_to_update->expiration_rtc_date = cyg_current_time() + S_TO_RTC (TONEMAPS_LIFE_DURATION_S);
+ return (tonemaps_valid_status);
+}
+#endif
+
+END_DECLS
+
+#endif /* ce_inc_cei_h */
+
+/*
+
+uint ref[75] //Nibble Encoding table reference.
+{
+ 0, 0, 0, // 00 - 02
+ 8, 9, 10, 11, 12, 13, 14, 15, // 03 - 10
+ 0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, // 11 - 18
+ 0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, // 19 - 26
+ 0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, // 27 - 34
+ 0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, // 35 - 42
+ 0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, // 43 - 50
+ 0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, // 51 - 58
+ 0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, // 59 - 66
+ 0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF // 67 - 74
+};
+
+*/
diff --git a/cesar/ce/inc/cei_param.h b/cesar/ce/inc/cei_param.h
new file mode 100755
index 0000000000..c481e40817
--- /dev/null
+++ b/cesar/ce/inc/cei_param.h
@@ -0,0 +1,97 @@
+#ifndef ce_inc_cei_param_h
+#define ce_inc_cei_param_h
+/* Cesar pro ject {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file ce/inc/cei_param.h
+ * \brief header for the storage of cei message to create and send.
+ * \ingroup ce
+ *
+ * A static structure (cei_param_fifo_t) is used to store a maximum number(CEI_WANTED_MAX)
+ * of cei message to create (cei_param_t). It is store as a circular buffer
+ * and when the buffer is full, the next cei_param_t is dropped.
+ * A new cei_param_t can be added when :
+ * -A new tonemap has been computed.
+ * -Enough sound have been sent. (versus sound reason code)
+ * -A tonemap must be refreshed because will soon expired.
+ * A cei_param_t is read when unless one is present and it is the rxce_process turn to
+ * work.
+ */
+#include "mac/common/tonemap.h"
+
+#define CEI_WANTED_MAX 32
+
+/** Parameters allowing to build the CEI message.*/
+struct cei_param_t
+{
+ /** Set of tonemaps concerned */
+ tonemaps_t *tms;
+ /** tonemap index to encode */
+ uint new_tmi;
+ /** tonemap index to inactive */
+ uint old_tmi;
+ /** Priority in control plane mme list (CA2 for cei message) */
+ uint priority;
+ /** Destination tei useful to find the MAC ADDRESS */
+ uint dtei;
+};
+typedef struct cei_param_t cei_param_t;
+
+/** FIFO and pointers manager for CEI message to create */
+struct cei_param_fifo_t
+{
+ /** Space reserved to store the cei_param_t */
+ cei_param_t list[CEI_WANTED_MAX];
+ /** Index of the next cei_param_t to read */
+ uint reader_index;
+ /** Index of the next cei_param_t to write */
+ uint writer_index;
+ /** Number of cei_param_t that are stored. */
+ uint number;
+};
+typedef struct cei_param_fifo_t cei_param_fifo_t;
+
+/** Static FIFO */
+cei_param_fifo_t cei_param_fifo;
+
+BEGIN_DECLS
+
+/**
+ * Add a cei_param_t in the list of cei_param_t to create.
+ * \param new_cei cei_param_t to add.
+ * \return if cei_param_t could be added (the list wasn't full)
+ *
+ * Be sure that cei_param_add is never call when rxce is getting it.
+ * No security in this case.
+ * cei_param_add is run in the rxce_process and not in callback
+ * so that cei_param_get is never interrupted by cei_param_add.
+ *
+ */
+bool
+cei_param_add (cei_param_t *new_cei);
+
+
+/**
+ * Get the oldest cei_param_t of the list.
+ * \return The contents of the oldest cei_param_t of the list.
+ *
+ * cei_param_get must not be interrupted by a cei_param_add :
+ * A cei_param_add must be launch in the rxce_process only.
+ */
+cei_param_t *
+cei_param_get (void);
+
+/**
+ * Initialize the cei_param_fifo_t structure.
+ */
+void
+cei_param_fifo_init (void);
+
+END_DECLS
+
+#endif /* ce_inc_cei_param_h */
diff --git a/cesar/ce/inc/ecos_time.h b/cesar/ce/inc/ecos_time.h
new file mode 100644
index 0000000000..853099a067
--- /dev/null
+++ b/cesar/ce/inc/ecos_time.h
@@ -0,0 +1,23 @@
+#ifndef macro_h
+#define macro_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file macro.h
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+#include <cyg/kernel/kapi.h>
+
+#define RTC_HZ CYGNUM_HAL_RTC_DENOMINATOR
+#define S_TO_RTC(s) (s*RTC_HZ)
+#define US_TO_RTC(us) ((us*RTC_HZ)/1000)
+
+#endif /* macro_h */
diff --git a/cesar/ce/inc/mpdu_measure_store.h b/cesar/ce/inc/mpdu_measure_store.h
new file mode 100755
index 0000000000..f8b7f5e92d
--- /dev/null
+++ b/cesar/ce/inc/mpdu_measure_store.h
@@ -0,0 +1,139 @@
+#ifndef ce_inc_mpdu_measure_store_h
+#define ce_inc_mpdu_measure_store_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file ce/inc/mpdu_measure_store.h
+ * \brief headers for storage and computation of the frames(MPDU) noise measurement.»
+ * \ingroup ce
+ *
+ * Each time a frame is received, the DSP stores PB measurement in the PBs
+ * descriptors and computes several type of measurement along the MPDU. PBproc
+ * will transfer any of this measurement (TODO TBD) in block that SAR will
+ * provide to the CE via callback function.
+ *
+ * This header file provides functions to manage the list of frame in which measurement have been stored.
+ * It provides functions to add measurement within.
+ * It provides too basic functions to process measurement.
+ */
+#include "mac/pbproc/pbproc.h"
+#include "hal/phy/pbdma.h"
+#include "mac/common/sta.h"
+
+/** Length of the circular buffer that stores the mpdu measure expressed in frame number. */
+#define MPDU_MEASURE_STORE_SIZE 30
+
+#define MPDU_MEASURE_GET_BLK_NB(data_nb, data_nb_per_blk) ((data_nb + data_nb_per_blk - 1)/data_nb_per_blk)
+
+#define MPDU_MEASURE_PB_NB_PER_BLK (BLK_SIZE / sizeof(pb_measurement_t))
+
+/** Number of block allocated switch type of chandata*/
+uint mpdu_measure_chandata_blk_nb[PHY_CHANDATA_TYPE_NB];
+
+
+/** The PB measure (ber, half-it, crc_status) are stored in one or two blk switch the number of PB
+ * in the MPDU. The pb_measure_blk must stay allocatable as a blk_t.
+ */
+struct pb_measure_blk_t
+{
+ /** Pointer to the next descriptor */
+ struct pb_measure_blk_t *next;
+ /** Pointer to pb measure data */
+ pb_measurement_t *data;
+ /** Number of valid pb stored in data block.*/
+ uint pb_nb;
+};
+typedef struct pb_measure_blk_t pb_measure_blk_t;
+
+/** All of the measurements made on a MPDU.*/
+struct mpdu_measure_t
+{
+ /** Pointer to the mpdu reception parameters got from pbproc.*/
+ pbproc_rx_params_t *rx_params;
+ /** Pointer to the first pb measure block.*/
+ pb_measure_blk_t *pb_head;
+ /** Pointers to the first of each chandata measurement.*/
+ phy_chandata_t *chandata_head[PHY_CHANDATA_TYPE_NB];
+};
+typedef struct mpdu_measure_t mpdu_measure_t;
+
+/** mpdu measure storage context.
+ * Store has a static space.
+ * Store is managed as a FIFO.*/
+struct mpdu_measure_store_t
+{
+ /** Reserved space to store mpdu measures.*/
+ mpdu_measure_t store[MPDU_MEASURE_STORE_SIZE];
+ /** head of store. To get the oldest mpdu measure.*/
+ uint head;
+ /** tail of store. To put a new mpdu measure inside.*/
+ uint tail;
+ /** Number of mpdu measures in store.*/
+ uint measure_nb;
+};
+typedef struct mpdu_measure_store_t mpdu_measure_store_t;
+
+BEGIN_DECLS
+
+/**
+ * Initialize the mpdu measure store.
+ */
+mpdu_measure_store_t *
+mpdu_measure_store_init (void);
+
+/**
+ * todo : Release the previous one.
+ * \return A pointer to the oldest measure present in the store.
+ *
+ */
+mpdu_measure_t *
+mpdu_measure_store_get (mpdu_measure_store_t *ctx);
+
+
+/**
+ * Release mpdu measure pointed data (rx_param, pb measurement block(s),
+ * chandata(s)).
+ * \param measure Pointer to the mpdu measure that contents measure to release;
+ */
+void
+mpdu_measure_store_release (mpdu_measure_store_t *ctx, mpdu_measure_t *measure);
+
+bool // Was FIFO not full?
+mpdu_measure_store_append (mpdu_measure_store_t *ctx, pbproc_rx_params_t *rx_params, uint pb_nb,
+ pb_measure_blk_t ** first, pb_measure_blk_t **last,
+ phy_chandata_t *chandata_head, uint chandata_nb, uint *blk_offset);
+
+/**
+ * Add pb measurement in a MPDU measurement.
+ * \param fm Frame measurement where to add pb measurement.
+ * \param pb_nb Number of pb measurement to add.
+ * \param first Where to write the first's' pb measurement.
+ * \param last Where to write the following pb measurement
+ *
+ * first and last can already be used to store any previous pb measurement
+ * from the same MPDU. Is this case, function keep first and last. And SAR
+ * will fill the rest of block thanks to pb_nb information in the
+ * pb_measure_blk and update it.
+ * Otherwise, new allocation is done and pb_nb is reset.
+ */
+void
+mpdu_measure_pb_add (mpdu_measure_t *measure, uint pb_nb, pb_measure_blk_t **first, pb_measure_blk_t **last, uint *blk_offset);
+
+/**
+ * Add a particular type noise measurement.
+ * \param fm Frame measurement where to add noise measurement.
+ * \param noise Noise measurement to add.
+ *
+ * The type is described in the phy_chandata descriptor.
+ */
+void
+mpdu_measure_chandata_add (mpdu_measure_t *measure, phy_chandata_t *noise);
+
+END_DECLS
+
+#endif /* ce_inc_mpdu_measure_store_h */
diff --git a/cesar/ce/inc/rx.h b/cesar/ce/inc/rx.h
new file mode 100755
index 0000000000..5a064166c9
--- /dev/null
+++ b/cesar/ce/inc/rx.h
@@ -0,0 +1,203 @@
+#ifndef ce_inc_rx_h
+#define ce_inc_rx_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * * \file ../../inc/rx.h
+ * * \brief « brief description »
+ * * \ingroup
+ * *
+ * * « long description »
+ * */
+
+#include "ce/inc/cei_param.h"
+#include "ce/inc/mpdu_measure_store.h"
+#include "cyg/kernel/kapi.h"
+#include "lib/trace.h"
+#include "mac/sar/sar.h"
+
+#ifdef MAXIMUS_TEST
+#define TXCE
+#endif
+
+/** Priority of CEI message */
+#define CEI_PRIORITY 2
+
+// The MARGE can be optimized versus the stations number, and the knowledge of
+// worst case where rxce can turned.
+#ifndef EXPIRATION_TEST
+#define RXCE_TONEMAPS_REFRESH_MARGIN_S 2
+#define RXCE_TONEMAPS_REFRESH_PERIOD_S (TONEMAPS_LIFE_DURATION_S - RXCE_TONEMAPS_REFRESH_MARGIN_S)
+#else
+#define RXCE_TONEMAPS_REFRESH_MARGIN_S 1
+#define RXCE_TONEMAPS_REFRESH_PERIOD_S (2 - RXCE_TONEMAPS_REFRESH_MARGIN_S)
+#endif
+
+/** Structure describing the last received sound frame situation */
+struct sound_param_t
+{
+ uint stei;
+ uint reason_code;
+};
+typedef struct sound_param_t sound_param_t;
+
+/** Global structure for rxce context. */
+struct rxce_t
+{
+ /** Semaphore incremented when rxce has something to do :
+ * -PBproc would have a Sound complete flag.
+ * -A CEI must be built (a cei_param has been added in the
+ * cei_param_fifo.)
+ * -Computation can be done. (A frame measurement has been added, but
+ * not the first).
+ *
+ */
+ cyg_sem_t job;
+ mac_store_t *mac_store_ctx;
+ /** Pointer to global tonemask */
+ u8 *mask;
+ /** Received sound frame information.*/
+ bool pbproc_need_scf;
+ sound_param_t sound_param;
+
+ mpdu_measure_store_t *mpdu_measure_store_ctx;
+
+ /** Tracing system */
+#if CONFIG_TRACE
+ /** cl Trace */
+ trace_buffer_t trace;
+#endif /* !CONFIG_TRACE */
+#ifdef RXCE_MONITORING
+ /** Pipe to send measurement and tonemap when processed*/
+ int pipe_out_fd;
+ char pipe_out_name[1024];
+#endif
+};
+typedef struct rxce_t rxce_t;
+
+#ifdef EXPIRATION_TEST
+typedef void ( *test_cb_t) (int);
+
+void
+rxce_init_test_cb (test_cb_t test);
+
+test_cb_t expiration_test;
+
+#endif
+
+BEGIN_DECLS
+
+/**
+ * Initialize the global structure of rxce context.
+ * \param mac_store_ctx Access to the sta.
+ * \param mac_config_ctx Access to the tonemask.
+ * \return the rxce context.
+ *
+ */
+rxce_t *
+rxce_init (sar_t *sar_ctx, mac_store_t *mac_store_ctx, mac_config_t *mac_config_ctx);
+
+/**
+ * Callback called by pbproc when it need to have a SCF i.e when it receives a
+ * sound frame. If CE is late, pbproc returns a SCF to false.
+ * \param tei tei of station that has sent the sound frame.
+ * \param src SoundReasonCode :why station has sent the sound frame.
+ *
+ * The rxce initialize the pbproc status variables and add a job to do.
+ */
+void
+pbproc_need_scf_cb (uint tei, uint src);
+
+/**
+ * Callback called by SAR when it need to has new pb measurement. This
+ * function add the pb measurement in the list of frame measurement.
+ * \param user .
+ * \param rx_params Frame reception condition.
+ * \param pb_nb The pb measurement number that the SAR wants to dispose.
+ * \param first First descriptor and so data block where to store pb
+ * measurement.
+ * \param last Last descriptor and so data block where to store pb
+ * measurement.
+ */
+bool // does channel estimation need pb_measurement?
+rxce_mpdu_measurement_add (void *user, pbproc_rx_params_t *rx_params,
+ uint pb_nb, blk_t **first, blk_t **last,
+ pb_t *noise, uint n, uint *blk_offset);
+
+/**
+ * Add a 'cei message job' for each tonemaps that must be updated and evaluate
+ * the next milestone to redo it.
+ * \param ctx rxce context
+ * \return the next refresh date.
+ *
+ * For rx_tonemaps, the expiration_rtc_date must be interpreted as a
+ * refresh_rtc_date that is the expiration_rtc_date less a marging to allow the
+ * CP to create cei message, to the lower layers to send it, and the
+ * destination station to receive it.
+ * Dates are expressed in rtc, real-time clock is ecos context, i.e. the tick
+ * ecos. (certainly 10ms).
+ * Algorithm runs stupidly all tonemaps. An optimized algorithm with a
+ * management of a tree could be envisaged.
+ */
+cyg_tick_count_t
+rxce_tonemaps_refresh_management(rxce_t *ctx);
+
+/**
+ * Determine the value of SCF that PBproc must answer to the station
+ * sound transmitter versus the announced SRC stored in rxce context.
+ * \return SCF to be sent by PBproc.
+ *
+ * Function called in rxce process when there is a new 'pbproc need scf job'
+ * to do.
+ */
+bool
+compute_scf (rxce_t *ctx);
+
+/**
+ * Compute the first frame measurement present in the list of frame
+ * measurement.
+ *
+ * Function called in rxce process when there is a 'frame measurement job' to
+ * do.
+ */
+void
+rxce_next_measurement_compute (rxce_t *ctx);
+
+/**
+ * Main thread of rxce.
+ * \param data allows the pass the rxce context.
+ *
+ * rxce_process wait on the 'job' semaphore. The several callback can
+ * provide new 'jobs'. Three sort of 'job' exists :
+ * -PBproc need to know the scf to return.
+ * -A station need or must receive a CEI to update its set of tonemaps.
+ * -Noise (any frame measurement) are waiting to be computed.
+ * Those 'jobs' are described by priority order.
+ *
+ * More, the semaphore can be timeout in order to ensure tonemaps refresh.
+ * Timeout is reestimatimate at each loop of the process thanks to
+ * rxce_tonemaps_refresh_management.
+ */
+void
+rxce_process (cyg_addrword_t data);
+
+/**
+ * Add a job for rxce that will create and add a cei message to transmit
+ * \param ctx rxce context.
+ * \param tms set of tonemaps to encode in cei message.
+ * \param new_tmi new tmi created if necessary, else NULL_TONEMAP_INDEX.
+ * \param old_tmi tmi that new_tmi will replace.
+ * \param dtei destination tei of cei message.
+ *
+ */
+void
+rxce_job_cei_add (rxce_t *ctx, uint dtei, tonemaps_t *tms, uint new_tmi, uint old_tmi);
+
+END_DECLS
+
+#endif /* ce_inc_rx_h */
diff --git a/cesar/ce/inc/trace.h b/cesar/ce/inc/trace.h
new file mode 100644
index 0000000000..4f3e7970dd
--- /dev/null
+++ b/cesar/ce/inc/trace.h
@@ -0,0 +1,74 @@
+#ifndef ce_inc_trace_h
+#define ce_inc_trace_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file ce/inc/trace.h
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+
+#include "lib/trace.h"
+
+/** Shortcut for tracing inside CE. */
+#define RXCE_TRACE(id, args...) \
+ TRACE_FAST_SHORT (RXCE_TRACE_, &ctx->trace, id, ## args)
+
+#if CONFIG_TRACE
+enum
+{
+ RXCE_TRACE_INIT,
+ RXCE_TRACE_SAR_MEASUREMENT_CB,
+ RXCE_TRACE_MEASURE_DROPPED,
+ RXCE_TRACE_PROCESS_WAIT,
+ RXCE_TRACE_PROCESS_TRIGGERED,
+ RXCE_TRACE_SCF_PROCESS,
+ RXCE_TRACE_CEI_PROCESS,
+ RXCE_TRACE_BITLOADING_PROCESS,
+ RXCE_TRACE_REFRESH_PROCESS,
+};
+
+BEGIN_DECLS
+
+/**
+ * Initialize the trace system
+ * \param ctx the ce context.
+ */
+void
+rxce_trace_init (rxce_t *ctx);
+
+/**
+ * Uninitialize the trace system
+ * \param ctx the ce context
+ */
+void
+rxce_trace_uninit (rxce_t *ctx);
+
+/**
+ * Print the traces
+ * \param ctx the ce context.
+ */
+void
+rxce_trace_print (rxce_t *ctx);
+
+END_DECLS
+
+#else /* !CONFIG_TRACE */
+
+#define rxce_trace_init(ctx) ((void) 0)
+#define rxce_trace_uninit(ctx) ((void) 0)
+#define rxce_trace_print(ctx) ((void) 0)
+
+#endif /* !CONFIG_TRACE */
+
+
+
+
+#endif /*ce_inc_trace_h */
diff --git a/cesar/ce/inc/tx.h b/cesar/ce/inc/tx.h
new file mode 100755
index 0000000000..240ce9c083
--- /dev/null
+++ b/cesar/ce/inc/tx.h
@@ -0,0 +1,108 @@
+#ifndef ce_inc_tx_h
+#define ce_inc_tx_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file tx.h
+ * \brief Sub - Function of Control Plane task that update the set of
+ * tonemaps versus several cei message received.
+ * \ingroup cp
+ *
+ */
+
+#include "mac/common/store.h"
+#include "mac/common/config.h"
+#include "cyg/kernel/kapi.h"
+#include "cp/interf/interf.h"
+
+
+/** Global structure for txce context */
+struct txce_t
+{
+ /** Access to sta and set of tonemaps (TODO ??and mac address) from
+ * rx_params-tei.*/
+ mac_store_t *mac_store_ctx;
+ /** Pointer to global tonemask */
+ u8 *tonemask;
+ /** interf context allowing to add event in CP. */
+ interf_t *interf_ctx;
+ /** Handle to alarm. */
+ cyg_handle_t alarm_hdl;
+ /** Pointer to the alarm object. */
+ cyg_alarm alarm_obj;
+
+};
+typedef struct txce_t txce_t;
+
+BEGIN_DECLS
+
+/**
+ * Expire all tonemaps with an expiration date greater than the current date.
+ * And detect the next expiration date.
+ * \param ctx txce context.
+ * \return the next expiration date.
+ *
+ * Dates are expressed in rtc, real-time clock is ecos context, i.e. the tick
+ * ecos. (certainly 10ms).
+ * Algorithm runs stupidly all tonemaps. An optimized algorithm with a
+ * management of a tree could be envisaged.
+ */
+cyg_tick_count_t
+txce_expiration_tonemaps_management (txce_t *ctx);
+
+/**
+ * Initialize the global structure of txce context.
+ * \param mac_store_ctx Access to the sta.
+ * \param mac_config_ctx Access to the tonemask.
+ * \return the txce context.
+ *
+ */
+txce_t *
+txce_init (mac_store_t *mac_store_ctx, mac_config_t *mac_config_ctx, interf_t *interf);
+
+/**
+ * Control Plane function called when a mme arrives and correspond to a cei
+ * mmtype or when CP manages a TXCE_EVENT.
+ * \param ctx txce context.
+ * \param stei Source station of message received.
+ * \param mmtype Message type CM_TM_UPDATE.IND or CM_CHAN_EST.IND
+ * \param mm_entry Pointer to the start of mm_entry or NULL if launched from a TXCE_EVENT.
+ *
+ * At first, the function computes the cei message (if there is) and update
+ * the set of tonemap concerned and its new expiration date.
+ * Then, function runs the txce_expiration_tonemaps and reprogram the next
+ * alarm date. If alarm occurs, this function will be called without message.
+ * So the function runs the txce_expiration_tonemaps and reprogram the next
+ * alarm date...
+ *
+ * Keep careful : The PBproc can read-access to the set of tonemap while this
+ * function is updating it.
+ * Notices :
+ * - A tonemap is always added, never replaces another.
+ * - Intervals can be modified. Intervals description
+ * is duplicate, and a pointer points to the currents intervals. Change it
+ * atomically.
+ * - Releasing tonemap : Counter reference should protect the situation.
+ */
+void
+txce (txce_t *ctx, uint stei, u32 mmtype, u8 *mm_entry);
+
+/**
+ * function called when alarm occurs.
+ * \param alarm_hdl handle to the alarm.
+ * \param data allows to pass the txce context.
+ *
+ * This function add an TXCE_EVENT in CP in order that CP recall txce_rcv_mme
+ * function with an mm_entry NULL.
+ */
+void
+alarm_cb (cyg_handle_t alarm_hdl, cyg_addrword_t data);
+
+END_DECLS
+
+#endif /* ce_inc_tx_h */
diff --git a/cesar/ce/rxce_stats.h b/cesar/ce/rxce_stats.h
new file mode 100755
index 0000000000..5ada73629c
--- /dev/null
+++ b/cesar/ce/rxce_stats.h
@@ -0,0 +1,96 @@
+#ifndef ce_inc_rxce_stats_h
+#define ce_inc_rxce_stats_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file ce/inc/rxce_stats.h
+ * \brief Management of rxce status by station.
+ * \ingroup ce
+ *
+ */
+
+#include "mac/common/tonemap.h"
+
+/**
+ * Several statistics stored in each station used by rxce process.
+*/
+struct rxce_processing_t
+{
+ /** Tonemap in build while new noise measurement arrive. */
+ tonemap_t *tm_in_build;
+ /** Status of RXCE relative to the station. */
+ uint status;
+ /** Stable frame number received in ROBO mode.
+ * Stable means that PHY_CHANDATA_TYPE_FREQ_NOISE have been exploited
+ * because PHY_CHANDATA_TYPE_TIME_NOISE were enough stable to trust.
+ */
+ uint stable_ROBO_nb;
+ /** Unstable frame number received in ROBO mode. */
+ uint unstable_ROBO_nb;
+ /** Unusable frame number received in ROBO mode.
+ * Unusable means that frame were data and the BER was not null. So the
+ * remodulate noise can be false. */
+ uint unusable_ROBO_nb;
+ /** The time in us since the station is sending ROBO frame. */
+ uint timestamp_ROBO_us;
+ /** Stable frame number received in nonROBO mode.*/
+ uint stable_nonROBO_nb;
+ /** Unstable frame number received in nonROBO mode. */
+ uint unstable_nonROBO_nb;
+ /** Unusable frame number received in nonROBO mode. */
+ uint unusable_nonROBO_nb;
+ /** Total frame number processed by rxce process */
+ uint measurement_computed_nb;
+ /** Informs pbproc about downloading measurements */
+ uint need_measurement;
+ };
+typedef struct rxce_processing_t rxce_processing_t;
+
+BEGIN_DECLS
+
+
+/**
+ * Reset initial rxce statitistics.
+ * \param rxce Structure of rxce statistics.
+ */
+extern inline void
+rxce_stats_init (rxce_processing_t *rxce)
+{
+ rxce->status = 0;
+ rxce->stable_ROBO_nb = 0;
+ rxce->unstable_ROBO_nb = 0;
+ rxce->timestamp_ROBO_us = 0;
+ rxce->stable_nonROBO_nb = 0;
+ rxce->unstable_nonROBO_nb = 0;
+ rxce->unusable_nonROBO_nb = 0;
+ rxce->measurement_computed_nb = 0;
+ rxce->tm_in_build = NULL;
+ rxce->need_measurement = 0;
+}
+
+
+/**
+ * Free eventually allocated blocks in rxce statistics.
+ * \param rxce Structure of rxce statistics.
+ */
+extern inline void
+rxce_stats_uninit (rxce_processing_t *rxce)
+{
+ tonemap_t *tm = rxce->tm_in_build;
+ if (tm)
+ {
+ rxce->tm_in_build = NULL;
+ blk_release_desc_range (tm->tmdma_desc_head, tm->tmdma_desc_head->next);
+ }
+}
+
+
+END_DECLS
+
+#endif /* ce_inc_rxce_stats_h */
+
diff --git a/cesar/ce/src/bitloading.c b/cesar/ce/src/bitloading.c
new file mode 100644
index 0000000000..381affaa23
--- /dev/null
+++ b/cesar/ce/src/bitloading.c
@@ -0,0 +1,215 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file ce/src/bitloading.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+
+#include "common/std.h"
+#include "mac/common/timings.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, mpdu_measure_t *measure)
+{
+ bitloading_modification_t ret;
+ dbg_assert (mac_store_ctx);
+ dbg_assert (measure);
+ pbproc_rx_params_t *rx_params = measure->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, measure);
+ }
+ else
+ {
+ ret = bitloading_dynamic_step (ssta, measure);
+ }
+ blk_release (ssta);
+ return ret;
+}
+
+
+bitloading_modification_t
+bitloading_initial_step (sta_t *ssta, mpdu_measure_t *measure)
+{
+ dbg_assert (ssta);
+ dbg_assert (measure);
+ bitloading_modification_t ret;
+ tonemaps_t *tms = ssta->rx_tonemaps;
+ ret.stei = ssta->tei;
+ ret.changed_tonemaps = NULL;
+ {
+ if (measure->chandata_head[PHY_CHANDATA_TYPE_NRJ])
+ {
+ bitloading_worst_tonemap_compute (&ssta->rxce.tm_in_build, measure->chandata_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;
+ }
+ }
+ ssta->rxce.measurement_computed_nb++;
+ }
+ if (measure->chandata_head[PHY_CHANDATA_TYPE_NRJ_SYMBOL])
+ {
+ if (bitloading_mpdu_noise_stability (measure->chandata_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, mpdu_measure_t *measure)
+{
+ bitloading_modification_t ret;
+ dbg_assert (sta);
+ dbg_assert (measure);
+ 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 ();
+ sta->rxce.measurement_computed_nb++;
+ 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_energy_t *data = (phy_noise_energy_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);
+}
+
+uint // date_modulo_BEACON_PERIOD_ATU
+bitloading_date_in_beacon_atu_get (uint mpdu_date_tck, uint beacon_date_tck)
+{
+ dbg_assert (mpdu_date_tck - beacon_date_tck <= MAC_MS_TO_TCK (40));
+ return ( MAC_TCK_TO_ATU ((uint)(mpdu_date_tck - beacon_date_tck)));
+}
diff --git a/cesar/ce/src/cei_param.c b/cesar/ce/src/cei_param.c
new file mode 100755
index 0000000000..0c6888fd72
--- /dev/null
+++ b/cesar/ce/src/cei_param.c
@@ -0,0 +1,60 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file ce/src/cei_param.c
+ * \brief Manage the list of cei message to create.
+ * \ingroup ce
+ *
+ * « long description »
+ */
+#include "common/std.h"
+#include "ce/inc/cei_param.h"
+
+bool
+cei_param_add (cei_param_t *new_cei)
+{
+ dbg_assert (new_cei);
+ if (cei_param_fifo.number == CEI_WANTED_MAX)
+ {
+ // DROP new_cei because FIFO is full.
+ return (false);
+ }
+ else
+ {
+ cei_param_fifo.list[cei_param_fifo.writer_index] = *new_cei;
+ cei_param_fifo.number++;
+ cei_param_fifo.writer_index++;
+ if (cei_param_fifo.writer_index == CEI_WANTED_MAX)
+ cei_param_fifo.writer_index = 0;
+ return (true);
+ }
+}
+
+cei_param_t *
+cei_param_get (void)
+{
+ cei_param_t *ret = NULL;
+ if (cei_param_fifo.number > 0)
+ {
+ ret = &cei_param_fifo.list[cei_param_fifo.reader_index];
+ cei_param_fifo.reader_index++;
+ if (cei_param_fifo.reader_index == CEI_WANTED_MAX )
+ cei_param_fifo.reader_index = 0;
+ cei_param_fifo.number --;
+ }
+ return (ret);
+}
+
+void
+cei_param_fifo_init (void)
+{
+ cei_param_fifo.reader_index = 0;
+ cei_param_fifo.writer_index = 0;
+ cei_param_fifo.number = 0;
+}
+
diff --git a/cesar/ce/src/mpdu_measure_store.c b/cesar/ce/src/mpdu_measure_store.c
new file mode 100755
index 0000000000..c1f6d051e5
--- /dev/null
+++ b/cesar/ce/src/mpdu_measure_store.c
@@ -0,0 +1,260 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file ce/src/mpdu_measure_store.c
+ * \brief « brief description »
+ * \ingroup ce
+ *
+ * « long description »
+ */
+#include "common/std.h"
+#include "ce/inc/mpdu_measure_store.h"
+#include "hal/phy/defs.h"
+
+static mpdu_measure_store_t mpdu_measure_store_global;
+
+mpdu_measure_store_t *
+mpdu_measure_store_init (void)
+{
+ mpdu_measure_store_t *ctx = &mpdu_measure_store_global;
+ int i,j;
+ ctx->head = 0;
+ ctx->tail = 0;
+ ctx->measure_nb = 0;
+ for (i=0; i<MPDU_MEASURE_STORE_SIZE; i++)
+ {
+ ctx->store[i].pb_head = NULL;
+ for (j=0; j<PHY_CHANDATA_TYPE_NB; j++)
+ {
+ ctx->store[i].chandata_head[j] = NULL;
+ }
+ }
+ mpdu_measure_chandata_blk_nb[ PHY_CHANDATA_TYPE_NO_MEMORY_READ ] = 0;
+ mpdu_measure_chandata_blk_nb[ PHY_CHANDATA_TYPE_NRJ ] = MPDU_MEASURE_GET_BLK_NB (PHY_CARRIER_NB , PHY_NOISE_NB_PER_BLK );
+ mpdu_measure_chandata_blk_nb[ PHY_CHANDATA_TYPE_NRJ_SYMBOL ] = MPDU_MEASURE_GET_BLK_NB (MAC_MAX_SYMB_PER_MPDU , PHY_NOISE_NB_PER_BLK );
+ mpdu_measure_chandata_blk_nb[ PHY_CHANDATA_TYPE_SPECTRUM_TRUNC ] = MPDU_MEASURE_GET_BLK_NB (PHY_CARRIER_NB , PHY_SPECTRUM_NB_PER_BLK );
+ mpdu_measure_chandata_blk_nb[ PHY_CHANDATA_TYPE_SPECTRUM_RE ] = MPDU_MEASURE_GET_BLK_NB (PHY_CARRIER_NB , PHY_SPECTRUM_NB_PER_BLK );
+ mpdu_measure_chandata_blk_nb[ PHY_CHANDATA_TYPE_SPECTRUM_IM ] = MPDU_MEASURE_GET_BLK_NB (PHY_CARRIER_NB , PHY_SPECTRUM_NB_PER_BLK );
+ mpdu_measure_chandata_blk_nb[ PHY_CHANDATA_TYPE_DATA_LLR ] = 1;
+ mpdu_measure_chandata_blk_nb[ PHY_CHANDATA_TYPE_COPY_I_LLR ] = 1;
+ mpdu_measure_chandata_blk_nb[ PHY_CHANDATA_TYPE_COPY_Q_LLR ] = 1;
+ mpdu_measure_chandata_blk_nb[ PHY_CHANDATA_TYPE_COPY_VOTE_COEF ] = 1;
+ return (ctx);
+}
+
+void
+mpdu_measure_chandata_release (phy_chandata_t *head, uint n)
+{
+ if (head)
+ {
+ blk_t *tail = (blk_t *) head;
+ while (tail->next) {tail = tail->next;}
+ blk_release_desc_range ((blk_t *)head, tail);
+ }
+}
+
+void
+mpdu_measure_pb_release (pb_measure_blk_t *head)
+{
+ pb_measure_blk_t *tail;
+ if (head)
+ {
+ // Can have a maximum of 2 allocated blocks.
+ tail = head->next;
+ if (tail)
+ {
+ blk_release_desc_range ((blk_t *) head, (blk_t *)tail);
+ }
+ else
+ {
+ blk_release_desc ((blk_t *) head);
+ }
+ }
+}
+
+void
+mpdu_measure_rx_params_release (pbproc_rx_params_t *rx_params)
+{
+ if (rx_params)
+ {
+ blk_release (rx_params);
+ }
+}
+
+void
+mpdu_measure_drop (pbproc_rx_params_t *rx_params, pb_measure_blk_t *pb_head, phy_chandata_t *chandata_head, uint chandata_nb)
+{
+ mpdu_measure_rx_params_release (rx_params);
+ mpdu_measure_pb_release (pb_head);
+ mpdu_measure_chandata_release (chandata_head, chandata_nb);
+}
+
+void
+mpdu_measure_store_release (mpdu_measure_store_t *ctx, mpdu_measure_t *measure)
+{
+ dbg_assert (measure);
+ int i;
+ mpdu_measure_rx_params_release (measure->rx_params);
+ measure->rx_params = NULL;
+ mpdu_measure_pb_release (measure->pb_head);
+ measure->pb_head = NULL;
+ for (i=0; i<PHY_CHANDATA_TYPE_NB; i++)
+ {
+ if (measure->chandata_head[i])
+ {
+ mpdu_measure_chandata_release (measure->chandata_head[i], mpdu_measure_chandata_blk_nb[i]);
+ measure->chandata_head[i] = NULL;
+ }
+ }
+ ctx->measure_nb--;
+}
+
+mpdu_measure_t *
+mpdu_measure_store_get (mpdu_measure_store_t *ctx)
+{
+ dbg_assert (ctx);
+ mpdu_measure_t *ret = NULL;
+ if (ctx->measure_nb > 0)
+ {
+ ret = &ctx->store[ctx->head];
+ ctx->head++;
+ if (ctx->head == MPDU_MEASURE_STORE_SIZE)
+ ctx->head = 0;
+ }
+ return (ret);
+}
+
+/* TODO : frame_measurement_ber_add manage the fact that an MPDU can be
+ * reassembly in several time. But Not the other functionnalities:
+ * frame_measurement_append doesn't test the last received rx_params before
+ * adding a new frame_measurement, the RXCE process doesn't take into account
+ * the fact that pb_measurement could have been computed although that the complete
+ * MPDU has not been received...
+ */
+bool // Was FIFO not full?
+mpdu_measure_store_append (mpdu_measure_store_t *ctx, pbproc_rx_params_t *rx_params, uint pb_nb,
+ pb_measure_blk_t **pb_first, pb_measure_blk_t **pb_last,
+ phy_chandata_t *chandata_head, uint chandata_nb, uint *blk_offset)
+{
+ dbg_assert (ctx);
+ dbg_assert (!(chandata_nb==0 && chandata_head));
+ dbg_assert (rx_params);
+ bool ret = true;
+ if (ctx->measure_nb == MPDU_MEASURE_STORE_SIZE)
+ {
+ mpdu_measure_drop (rx_params, NULL, chandata_head, chandata_nb);
+ return (false);
+ }
+ else
+ {
+ mpdu_measure_t *measure = &ctx->store[ctx->tail];
+ measure->rx_params = rx_params;
+ if (pb_nb) mpdu_measure_pb_add (measure, pb_nb, pb_first, pb_last, blk_offset);
+ if (chandata_head) mpdu_measure_chandata_add (measure, chandata_head);
+ ctx->measure_nb++;
+ ctx->tail++;
+ if (ctx->tail == MPDU_MEASURE_STORE_SIZE)
+ ctx->tail = 0;
+ return (ret);
+ }
+}
+
+void
+mpdu_measure_pb_add (mpdu_measure_t *measure, uint pb_nb, pb_measure_blk_t **pb_first, pb_measure_blk_t **pb_last, uint *blk_offset)
+{
+ dbg_assert (measure);
+ dbg_assert (pb_nb<=MAC_MAX_PB_PER_MPDU);
+ if (pb_nb != 0)
+ {
+ pb_measure_blk_t *stock = measure->pb_head;
+ // If any pb measure have already been stored.
+ if (stock)
+ {
+ // If a second block has already been used. (max = 2)
+ if (stock->next)
+ {
+ dbg_assert ( (pb_nb + stock->next->pb_nb) <= MPDU_MEASURE_PB_NB_PER_BLK);
+ *blk_offset = stock->next->pb_nb;
+ stock->next->pb_nb += pb_nb;
+ *pb_first = *pb_last = stock->next;
+ }
+ else //Only one block is already used.
+ {
+ dbg_assert ( (pb_nb+stock->pb_nb) <= MAC_MAX_PB_PER_MPDU);
+ *blk_offset = stock->pb_nb;
+ *pb_first = stock;
+ if (pb_nb + stock->pb_nb > MPDU_MEASURE_PB_NB_PER_BLK) //A second block is necessary
+ {
+ *pb_last = (pb_measure_blk_t *) blk_alloc_desc();
+ (*pb_first)->next = *pb_last;
+ stock->next->pb_nb = pb_nb + stock->pb_nb - MPDU_MEASURE_PB_NB_PER_BLK;
+ stock->pb_nb = MPDU_MEASURE_PB_NB_PER_BLK;
+ }
+ else // The first block is enough.
+ {
+ *pb_last = *pb_first;
+ stock->pb_nb += pb_nb;
+ }
+ }
+ }
+ else //No block already allocated
+ {
+ if (pb_nb > MPDU_MEASURE_PB_NB_PER_BLK) //Need two blocks
+ {
+ *pb_first = (pb_measure_blk_t *) blk_alloc_desc_range (2, (blk_t **) pb_last);
+ (*pb_first)->pb_nb = MPDU_MEASURE_PB_NB_PER_BLK;
+ (*pb_last)->pb_nb = pb_nb - MPDU_MEASURE_PB_NB_PER_BLK;
+ }
+ else // Need one block.
+ {
+ *pb_first = *pb_last = (pb_measure_blk_t *) blk_alloc_desc();
+ (*pb_first)->pb_nb = pb_nb;
+ }
+ // Initialize first block pb nb to 0. SAR will start from 0 and update
+ // the new value.
+ *blk_offset = 0;
+ measure->pb_head = *pb_first;
+ }
+ (*pb_last)->next = NULL;
+ }
+ else
+ {
+ *pb_first = NULL; *pb_last = NULL; *blk_offset = 0;
+ }
+}
+
+void
+mpdu_measure_chandata_add (mpdu_measure_t *measure, phy_chandata_t *chandata_head)
+{
+ uint type;
+ dbg_assert (measure);
+ dbg_assert (chandata_head);
+ phy_chandata_t *browser = chandata_head;
+ phy_chandata_t *tmp;
+ do
+ {
+ type = browser->type;
+ dbg_assert (!measure->chandata_head[type]);
+ measure->chandata_head[type] = browser;
+ while (!browser->last && ((phy_chandata_t *) browser->blk.next)->type == type)
+ {
+ browser = (phy_chandata_t *) browser->blk.next;
+ }
+ if (browser->last)
+ {
+ browser->blk.next = NULL;
+ break;
+ }
+ else
+ {
+ tmp = browser;
+ browser = (phy_chandata_t *) browser->blk.next;
+ tmp->blk.next = NULL;
+ }
+ } while (browser->blk.next);
+}
diff --git a/cesar/ce/src/rx.c b/cesar/ce/src/rx.c
new file mode 100755
index 0000000000..66876bd0c5
--- /dev/null
+++ b/cesar/ce/src/rx.c
@@ -0,0 +1,300 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file ../../src/rx.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+#include "common/std.h"
+#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 "cp/interf/interf.h"
+#include "ce/test/rx/inc/test_rx.h" // Should be an overrided pbproc...
+#if CONFIG_TRACE
+#include "mac/common/ntb.h"
+#endif
+#ifdef RXCE_MONITORING
+ #include "host/syscall.h"
+#endif
+
+static rxce_t ce_global;
+
+#ifdef EXPIRATION_TEST
+void
+rxce_init_test_cb (test_cb_t test)
+{
+ expiration_test = test;
+}
+#endif
+
+rxce_t *
+rxce_init (sar_t *sar, mac_store_t *mac_store_ctx, mac_config_t *mac_config_ctx)
+{
+ dbg_assert (mac_store_ctx);
+ dbg_assert (mac_config_ctx);
+ rxce_t *ctx = &ce_global;
+ ctx->mac_store_ctx = mac_store_ctx;
+ // Initialize THRESHOLD NOISE for computation
+ ctx->mpdu_measure_store_ctx = mpdu_measure_store_init ();
+ // Initialize FIFO for cei message to create.
+ cei_param_fifo_init();
+ // Initialize RXCE with no 'job' to do.
+ cyg_semaphore_init (&(ctx->job), 0);
+ // Initialize the pointer to the global tonemask
+ ctx->mask = mac_config_ctx->tonemask_info.tonemask;
+
+ ctx->pbproc_need_scf = false;
+ rxce_trace_init (ctx);
+#ifdef RXCE_WITH_SAR
+ dbg_assert (sar);
+ sar_init_measure_context (sar, ctx);
+ sar_init_measurement_cb (sar, rxce_mpdu_measurement_add);
+#endif
+ RXCE_TRACE (INIT, mac_ntb());
+ return (ctx);
+}
+
+void
+pbproc_need_scf_cb (uint tei, uint reason_code)
+{
+ dbg_assert (&ce_global);
+ rxce_t *ctx = &ce_global;
+ dbg_assert (&(ctx->job));
+ dbg_assert (MAC_TEI_IS_STA(tei));
+ dbg_assert ( (reason_code>=0x04 && reason_code<=0x1F)
+ || (reason_code>=0xFC && reason_code<=0xFF) );
+ //dbg_assert (!ctx->pbproc_need_scf); // rxce_process didn't respond to a previous request of pbproc.
+ ctx->sound_param.stei = tei;
+ ctx->sound_param.reason_code = reason_code;
+ ctx->pbproc_need_scf = true;
+ cyg_semaphore_post (&(ctx->job));
+}
+
+bool
+rxce_mpdu_measurement_add (void *user, pbproc_rx_params_t *rx_params,
+ uint pb_nb, blk_t **f, blk_t **l, pb_t *noise, uint n, uint *blk_offset)
+{
+ dbg_assert (user);
+ rxce_t *ctx = (rxce_t *) user;
+ RXCE_TRACE (SAR_MEASUREMENT_CB, mac_ntb());
+ dbg_assert (rx_params);
+ bool b;
+ pb_measure_blk_t **first = (pb_measure_blk_t **) f;
+ pb_measure_blk_t **last = (pb_measure_blk_t **) l;
+ // Allocate block if necessary. The SAR will fill blocks after !couldn't be stopped by RXCE!.
+ b = mpdu_measure_store_append (ctx->mpdu_measure_store_ctx, rx_params, pb_nb, first, last, (phy_chandata_t *) noise, n, blk_offset);
+ // Give 'job' to RXCE that will process the previous frame.
+ if (b) cyg_semaphore_post (&(ctx->job));
+ else RXCE_TRACE (MEASURE_DROPPED, mac_ntb());
+ return (b);
+}
+
+/** todo Cf SPEC HPAV HPAV-FrameControl -- SoundVariantField -- SoundReasonCode */
+bool
+rxce_scf_compute (rxce_t *ctx)
+{
+ dbg_assert (ctx);
+ bool ret = false;
+ sta_t *sta;
+ tonemaps_t *tms;
+ uint src = ctx->sound_param.reason_code;
+ 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, ctx->sound_param.stei, sta->rx_tonemaps, src - 4, TONEMAP_INDEX_NULL);
+ ret = true;
+ blk_release (sta);
+ }
+ if (src == 0xFC )
+ {
+ //TODO SEND ALL VALID TM
+ ret = true;
+ }
+ if (src == 0xFD )
+ {
+ sta = mac_store_sta_get(ctx->mac_store_ctx, ctx->sound_param.stei);
+ tms = sta->rx_tonemaps;
+ if (tms->default_tmi != TONEMAP_INDEX_INITIAL_START)
+ {
+ ret = true;
+ }
+ else
+ {
+ ret = false;
+ }
+ blk_release (sta);
+ }
+ if (src == 0xFE)
+ {
+ ret = false;
+ // IF INTERVAL CONCERNED HAS TM ret = true;and cei_param_add
+ // ELSE ret = false;
+ // todo - it will be necessary to know the date.
+ }
+ if (src == 0xFF)
+ {
+ ret = false;
+ }
+ return (ret);
+}
+
+void
+rxce_next_measurement_compute (rxce_t *ctx)
+{
+ dbg_assert (ctx);
+ mpdu_measure_t *measure = mpdu_measure_store_get (ctx->mpdu_measure_store_ctx);
+ dbg_assert (measure);
+ bitloading_modification_t bl = bitloading_run (ctx->mac_store_ctx, measure);
+#ifdef RXCE_MONITORING
+ uint toto = 9 + sizeof (pbproc_rx_params_t);
+ write (ctx->pipe_out_fd, &toto, sizeof(toto));
+ write (ctx->pipe_out_fd, "RX_PARAMS", 9);
+ write (ctx->pipe_out_fd, measure->rx_params, sizeof(pbproc_rx_params_t));
+ uint pb_nb = measure->pb_head->pb_nb;
+ if (measure->pb_head->next) pb_nb += measure->pb_head->next->pb_nb;
+ toto = 9 + 1 + pb_nb*4;
+ //printf ("toto = %d\n", toto);
+ write (ctx->pipe_out_fd, &toto, sizeof(toto));
+ write (ctx->pipe_out_fd, "PBMEASURE", 9);
+ write (ctx->pipe_out_fd, &pb_nb, 1);
+ write (ctx->pipe_out_fd, measure->pb_head->data, measure->pb_head->pb_nb * 4);
+ if (measure->pb_head->next)
+ {
+ write (ctx->pipe_out_fd, measure->pb_head->next->data, measure->pb_head->next->pb_nb * 4);
+ }
+
+ //printf ("pb_nb = %d\n", pb_nb);
+ //write (ctx->pipe_out_fd, measure->pb_head->data, 512);
+
+#endif
+ mpdu_measure_store_release (ctx->mpdu_measure_store_ctx, measure);
+ if (bl.changed_tonemaps ) rxce_job_cei_add (ctx, bl.stei, bl.changed_tonemaps, bl.new_tmi, bl.old_tmi);
+}
+
+
+cyg_tick_count_t
+rxce_tonemaps_refresh_management(rxce_t *ctx)
+{
+ dbg_assert (ctx);
+ uint tei;
+ cyg_tick_count_t lowest_expiration_date = 0xFFFFFFFFFFFFFFFFll;
+ for (tei=MAC_TEI_STA_MIN; tei<=MAC_TEI_STA_MAX; tei++)
+ {
+ uint date = cyg_current_time();
+ sta_t *lsta = mac_store_sta_get (ctx->mac_store_ctx, tei);
+ if (lsta)
+ {
+ if (lsta->rx_tonemaps)
+ {
+ cyg_tick_count_t expiration_date = lsta->rx_tonemaps->expiration_rtc_date;
+ if ( date >= expiration_date )
+ {
+ rxce_job_cei_add (ctx, lsta->tei, lsta->rx_tonemaps, TONEMAP_INDEX_NULL, TONEMAP_INDEX_NULL);
+ }
+ if (lowest_expiration_date > expiration_date)
+ {
+ lowest_expiration_date = expiration_date;
+ }
+ }
+ blk_release (lsta);
+ }
+ }
+ return (lowest_expiration_date);
+}
+
+void
+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 = 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));
+ tonemaps->expiration_rtc_date = cyg_current_time() + S_TO_RTC (RXCE_TONEMAPS_REFRESH_PERIOD_S);
+}
+
+void
+rxce_process (cyg_addrword_t data)
+{
+ dbg_assert (data);
+#ifdef EXPIRATION_TEST
+ cyg_tick_count_t watchdog = 0;
+#else
+ cyg_tick_count_t watchdog = 0xFFFFFFFFFFFFFFFFlu;
+#endif
+ mme_t *mme;
+ rxce_t *ctx = (rxce_t *) data;
+ while (true)
+ {
+ RXCE_TRACE (PROCESS_WAIT, mac_ntb());
+ cyg_semaphore_timed_wait (&(ctx->job), watchdog);
+ RXCE_TRACE (PROCESS_TRIGGERED, mac_ntb());
+ if (ctx->pbproc_need_scf) // At first, verify if pbproc waits information about scf.
+ {
+ // 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.
+ RXCE_TRACE (SCF_PROCESS, mac_ntb());
+ bool b = rxce_scf_compute (ctx);
+ if (b)
+ {
+ pbproc_scf (); // a pbproc function.
+ }
+ //TODO ATOMIC
+ ctx->pbproc_need_scf = false;
+ }
+ else
+ {
+ if (cei_param_fifo.number > 0 ) // Then Create CEI if waited.
+ {
+ RXCE_TRACE (CEI_PROCESS, mac_ntb());
+ mme = interf_mme_get ();
+ dbg_assert (mme);
+ cei_param_t *param = cei_param_get ();
+ dbg_assert (param);
+#ifdef EXPIRATION_TEST
+ expiration_test (param->dtei);
+#endif
+ cei_created_status_t cei_status = cei_create (mme->mm_entry, ctx->mask, param->tms, param->new_tmi, param->old_tmi);
+ mme->length = cei_status.length;
+ mme->dtei = param->dtei;
+ mme->mm_type = cei_status.mm_type;
+ interf_mme_send (mme);
+#ifdef MAXIMUS_TEST
+ sta_t *sta = mac_store_sta_get (ctx->mac_store_ctx, param->dtei);
+ cei_decode (sta->tx_tonemaps, cei_status.mm_type, mme->mm_entry, ctx->mask);
+#endif
+ }
+ else
+ {
+ if (ctx->mpdu_measure_store_ctx->measure_nb) //Then Compute measurement
+ {
+ RXCE_TRACE (BITLOADING_PROCESS, mac_ntb());
+ rxce_next_measurement_compute (ctx);
+ }
+ }
+ }
+ if (cyg_current_time() > watchdog)
+ {
+ RXCE_TRACE (REFRESH_PROCESS, mac_ntb());
+ watchdog = rxce_tonemaps_refresh_management(ctx);
+ }
+ }
+}
+
diff --git a/cesar/ce/src/rxce_stats.c b/cesar/ce/src/rxce_stats.c
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/cesar/ce/src/rxce_stats.c
diff --git a/cesar/ce/src/trace.c b/cesar/ce/src/trace.c
new file mode 100644
index 0000000000..c4fd6a177e
--- /dev/null
+++ b/cesar/ce/src/trace.c
@@ -0,0 +1,52 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file ce/src/trace.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+#include "common/std.h"
+#include "ce/inc/rx.h"
+#include "ce/inc/trace.h"
+
+void
+rxce_trace_init (rxce_t *ctx)
+{
+ static trace_namespace_t namespace;
+ static const trace_event_id_t event_ids[] =
+ {
+ TRACE_EVENT (RXCE_TRACE_INIT, "RXCE_INIT", TIMESTAMP),
+ TRACE_EVENT (RXCE_TRACE_SAR_MEASUREMENT_CB,"RXCE_SAR_MEASUREMENT_CB",TIMESTAMP),
+ TRACE_EVENT (RXCE_TRACE_MEASURE_DROPPED, "RXCE_MEASURE_DROPPED",TIMESTAMP),
+ TRACE_EVENT (RXCE_TRACE_PROCESS_WAIT, "RXCE_PROCESS_WAIT",TIMESTAMP),
+ TRACE_EVENT (RXCE_TRACE_PROCESS_TRIGGERED, "RXCE_PROCESS_TRIGGERED",TIMESTAMP),
+ TRACE_EVENT (RXCE_TRACE_SCF_PROCESS, "RXCE_SCF_COMPUTE",TIMESTAMP),
+ TRACE_EVENT (RXCE_TRACE_CEI_PROCESS, "RXCE_CEI_PROCESS",TIMESTAMP),
+ TRACE_EVENT (RXCE_TRACE_BITLOADING_PROCESS, "RXCE_BITLOADING_PROCESS",TIMESTAMP),
+ TRACE_EVENT (RXCE_TRACE_REFRESH_PROCESS, "RXCE_REFRESH_PROCESS",TIMESTAMP),
+ };
+ dbg_assert (ctx);
+ trace_namespace_init (&namespace, event_ids, COUNT (event_ids));
+ trace_buffer_add (&ctx->trace, "ce", 8, 4, true, &namespace);
+}
+
+void
+rxce_trace_uninit (rxce_t *ctx)
+{
+ dbg_assert (ctx);
+ trace_buffer_remove(&ctx->trace);
+}
+
+void
+rxce_trace_print (rxce_t *ctx)
+{
+ dbg_assert(ctx);
+ trace_buffer_dbg_dump(&ctx->trace);
+}
diff --git a/cesar/ce/src/tx.c b/cesar/ce/src/tx.c
new file mode 100755
index 0000000000..d6426fce6f
--- /dev/null
+++ b/cesar/ce/src/tx.c
@@ -0,0 +1,106 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file tx.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+#include "common/std.h"
+#include <stdio.h>
+#include "ce/inc/tx.h"
+#define TXCE
+#include "ce/inc/cei.h"
+
+static txce_t txce_global;
+
+txce_t *
+txce_init (mac_store_t *mac_store_ctx, mac_config_t *mac_config_ctx, interf_t *interf_ctx)
+{
+ dbg_assert (mac_store_ctx);
+ dbg_assert (mac_config_ctx);
+#if defined (ECOS) && ECOS
+ dbg_assert (interf_ctx);
+#endif
+ txce_t *ctx = &txce_global;
+ ctx->mac_store_ctx = mac_store_ctx;
+ ctx->tonemask = mac_config_ctx->tonemask_info.tonemask;
+ ctx->interf_ctx = interf_ctx;
+ cyg_handle_t sys_clk = cyg_real_time_clock();
+ cyg_handle_t counter_hdl;
+ cyg_clock_to_counter (sys_clk, &counter_hdl);
+ cyg_alarm_create (counter_hdl, alarm_cb, (cyg_addrword_t) ctx, &ctx->alarm_hdl, &ctx->alarm_obj);
+ return (ctx);
+}
+
+cyg_tick_count_t
+txce_expiration_tonemaps_management (txce_t *ctx)
+{
+ dbg_assert (ctx);
+ uint tei;
+ cyg_tick_count_t lowest_expiration_date = 0xFFFFFFFFFFFFFFFFll;
+ for (tei=MAC_TEI_STA_MIN; tei<=MAC_TEI_STA_MAX; tei++)
+ {
+ cyg_tick_count_t current_rtc_date = cyg_current_time();
+ sta_t *lsta = mac_store_sta_get (ctx->mac_store_ctx, tei);
+ if (lsta)
+ {
+ tonemaps_t *tms = lsta->tx_tonemaps;
+ if (tms)
+ {
+ cyg_tick_count_t expiration_date = tms->expiration_rtc_date;
+ if (current_rtc_date >= expiration_date )
+ {
+ int tmi;
+ for (tmi = 0; tmi<TONEMAP_INDEX_NB; tmi++)
+ {
+ if (tms->tm[tmi]) tonemap_release (tms, tmi);
+ //tms->intervals = NULL;
+ tms->expiration_rtc_date = 0xFFFFFFFFFFFFFFFFll;
+ }
+ }
+ else
+ {
+ if (lowest_expiration_date > expiration_date)
+ {
+ lowest_expiration_date = expiration_date;
+ }
+ }
+ }
+ blk_release (lsta);
+ }
+ }
+ return lowest_expiration_date;
+}
+
+void
+txce (txce_t *ctx, uint stei, u32 mmtype, u8 *mm_entry)
+{
+ dbg_assert (ctx);
+ if (mm_entry)
+ {
+ dbg_assert (mmtype == CM_CHAN_EST_IND || mmtype == CM_TM_UPDATE_IND);
+ dbg_assert (stei>=MAC_TEI_STA_MIN && stei<=MAC_TEI_STA_MAX);
+ // Get concerned tonemaps from stei.
+ sta_t *source_sta = mac_store_sta_get (ctx->mac_store_ctx, stei);
+ tonemaps_t *source_tms = source_sta->tx_tonemaps;
+ cei_decode (source_tms, mmtype, mm_entry, ctx->tonemask);
+ blk_release (source_sta);
+ }
+ cyg_tick_count_t next_expiration = txce_expiration_tonemaps_management (ctx);
+ cyg_alarm_initialize (ctx->alarm_hdl, next_expiration, 0);
+}
+
+void
+alarm_cb (cyg_handle_t alarm_hdl, cyg_addrword_t data)
+{
+ dbg_assert (data);
+ txce_t *ctx = (txce_t *) data;
+ interf_event_add (ctx->interf_ctx, TXCE_EVENT);
+}
diff --git a/cesar/ce/test/common/Module b/cesar/ce/test/common/Module
new file mode 100755
index 0000000000..ad8c4aa85e
--- /dev/null
+++ b/cesar/ce/test/common/Module
@@ -0,0 +1 @@
+SOURCES := print_utils.c gaussian.c
diff --git a/cesar/ce/test/common/ecos_overide/cyg/kernel/Module b/cesar/ce/test/common/ecos_overide/cyg/kernel/Module
new file mode 100644
index 0000000000..86ae567be7
--- /dev/null
+++ b/cesar/ce/test/common/ecos_overide/cyg/kernel/Module
@@ -0,0 +1 @@
+SOURCES := kapi.c
diff --git a/cesar/ce/test/common/ecos_overide/cyg/kernel/kapi.h b/cesar/ce/test/common/ecos_overide/cyg/kernel/kapi.h
new file mode 100644
index 0000000000..07bfa4e3ec
--- /dev/null
+++ b/cesar/ce/test/common/ecos_overide/cyg/kernel/kapi.h
@@ -0,0 +1,45 @@
+#ifndef kapi_h
+#define kapi_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file kapi.h
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+
+#define CYGNUM_HAL_RTC_DENOMINATOR 100
+
+typedef u64 cyg_tick_count_t;
+typedef u64 cyg_handle_t;
+typedef u64 cyg_alarm;
+typedef void* cyg_addrword_t;
+typedef void (cyg_alarm_t) (cyg_handle_t hdl, cyg_addrword_t data);
+
+cyg_tick_count_t
+cyg_current_time (void);
+
+cyg_handle_t
+cyg_real_time_clock (void);
+
+void
+cyg_clock_to_counter (cyg_handle_t clock_hdl, cyg_handle_t *counter_hdl);
+
+void
+cyg_alarm_create (cyg_handle_t counter_hld, cyg_alarm_t alarm_cb, cyg_addrword_t data, cyg_handle_t *alarm_hdl, cyg_alarm *alarm);
+
+void
+cyg_thread_delay (uint p);
+
+void
+cyg_alarm_initialize (cyg_handle_t alarm, cyg_tick_count_t trigger, cyg_tick_count_t interval);
+
+
+#endif /* kapi_h */
diff --git a/cesar/ce/test/common/ecos_overide/cyg/kernel/src/kapi.c b/cesar/ce/test/common/ecos_overide/cyg/kernel/src/kapi.c
new file mode 100644
index 0000000000..1f9a9d71ec
--- /dev/null
+++ b/cesar/ce/test/common/ecos_overide/cyg/kernel/src/kapi.c
@@ -0,0 +1,62 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file src/kapi.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+#include "common/std.h"
+#include "sys/time.h"
+#include "stdio.h"
+#include "string.h"
+#include "cyg/kernel/kapi.h"
+
+#define PERIOD_RTC_US (1000000/CYGNUM_HAL_RTC_DENOMINATOR)
+
+cyg_tick_count_t
+cyg_current_time (void)
+{
+ u64 ret;
+ struct timeval tv0;
+ gettimeofday (&tv0, NULL);
+ u64 date_us = (tv0.tv_sec*1000000 + tv0.tv_usec);
+ ret = date_us / PERIOD_RTC_US;
+ return ( ret);
+}
+
+cyg_handle_t
+cyg_real_time_clock (void)
+{
+ return (cyg_handle_t )NULL;
+}
+
+void
+cyg_clock_to_counter (cyg_handle_t clock_hdl, cyg_handle_t *counter_hdl)
+{
+ return;
+}
+
+void
+cyg_alarm_create (cyg_handle_t counter_hld, cyg_alarm_t alarm_cb, cyg_addrword_t data, cyg_handle_t *alarm_hdl, cyg_alarm *alarm)
+{
+ return;
+}
+
+void
+cyg_thread_delay (uint p)
+{
+ return;
+}
+
+void
+cyg_alarm_initialize (cyg_handle_t alarm, cyg_tick_count_t trigger, cyg_tick_count_t interval)
+{
+ return;
+}
diff --git a/cesar/ce/test/common/gaussian.h b/cesar/ce/test/common/gaussian.h
new file mode 100644
index 0000000000..454c5417d5
--- /dev/null
+++ b/cesar/ce/test/common/gaussian.h
@@ -0,0 +1,23 @@
+#ifndef ce_test_common_gaussian_h
+#define ce_test_common_gaussian_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file ce/test/common/gaussian.h
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+
+#include "lib/rnd.h"
+
+double
+lib_rnd_gaussian (lib_rnd_t *ctx, double lambda, double sigma);
+
+#endif /* ce_test_common_gaussian_h */
diff --git a/cesar/ce/test/common/print_utils.h b/cesar/ce/test/common/print_utils.h
new file mode 100755
index 0000000000..1f0fe63bb0
--- /dev/null
+++ b/cesar/ce/test/common/print_utils.h
@@ -0,0 +1,60 @@
+#ifndef ce_test_common_print_utils_h
+#define ce_test_common_print_utils_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file ce/test/common/print_utils.h
+ * \brief print function header for test
+ * \ingroup ce_test
+ */
+#include "mac/common/tonemap.h"
+#include "hal/phy/pbdma.h"
+#include "ce/inc/mpdu_measure_store.h"
+
+#ifdef CE_DBG
+BEGIN_DECLS
+
+void
+ce_print (const char *msg, ...);
+
+void
+ce_print_byte (u8 c);
+
+void
+ce_print_nibble (u32 c);
+
+void
+ce_print_buffer (u8 *buf, int length);
+
+void
+ce_print_tonemap (tonemap_t *tm);
+
+void
+ce_print_tonemaps (tonemaps_t *tms);
+
+void
+ce_print_chandata (phy_chandata_t *chandata);
+
+void
+ce_print_frame_measurement (frame_measurement_t *fm);
+
+END_DECLS
+
+
+#else
+#define ce_print(expr,r...) ((void) 0)
+#define ce_print_byte(expr) ((void)0)
+#define ce_print_nibble(expr) ((void)0)
+#define ce_print_buffer(expr,r) ((void)0)
+#define ce_print_tonemap(expr) ((void)0)
+#define ce_print_tonemaps(expr) ((void)0)
+#define ce_print_chandata(expr) ((void)0)
+#define ce_print_frame_measurement(expr) ((void)0)
+#endif
+
+#endif /* ce_test_common_print_utils_h */
diff --git a/cesar/ce/test/common/src/gaussian.c b/cesar/ce/test/common/src/gaussian.c
new file mode 100644
index 0000000000..4d2ca63e93
--- /dev/null
+++ b/cesar/ce/test/common/src/gaussian.c
@@ -0,0 +1,29 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file ce/test/common/src/gaussian.c
+ * \brief generate double float number with a normal repartition (gaussian).
+ * \ingroup ce/test/common
+ *
+ */
+#include "common/std.h"
+#include <math.h>
+#include "ce/test/common/gaussian.h"
+
+double
+lib_rnd_gaussian (lib_rnd_t *ctx, double lambda, double sigma)
+{
+ double a_rnd = 0;
+ while (a_rnd == 0) a_rnd=lib_rnd_uniform (ctx,100000);
+ a_rnd = a_rnd / 100000.0;
+ double b_rnd = lib_rnd_uniform (ctx,100000)/100000.0;
+ double lna = log (a_rnd);
+ double gauss_rnd = sqrt (-2*lna)* cos (2*3.14*b_rnd);
+ return (lambda + sigma *gauss_rnd);
+}
+
diff --git a/cesar/ce/test/common/src/print_utils.c b/cesar/ce/test/common/src/print_utils.c
new file mode 100755
index 0000000000..8fdba1ecb6
--- /dev/null
+++ b/cesar/ce/test/common/src/print_utils.c
@@ -0,0 +1,145 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file ce/test/common/src/print_utils.c
+ * \brief provides print function for test
+ * \ingroup ce_test
+ */
+
+#include "common/std.h"
+#include "ce/test/common/print_utils.h"
+#include <stdio.h>
+
+#ifdef CE_DBG
+void
+ce_print (const char *msg, ...)
+{
+ va_list ap;
+ va_start (ap, msg);
+ vfprintf (stderr, msg, ap);
+ va_end (ap);
+}
+
+void
+ce_print_byte (u8 c)
+{
+ ce_print("%1x%1x",(c>>4),(c&0xF));
+}
+
+void
+ce_print_nibble (u32 w)
+{
+ int i;
+ for (i=0; i<8; i++)
+ {
+ ce_print("%1x", w&0xF);
+ w = w>>4;
+ }
+}
+
+void
+ce_print_buffer (u8 *buf, int length)
+{
+ int i, l32 = (length+3)/4;
+ if (buf)
+ {
+ u32 *browser = (u32 *) buf;
+ ce_print (" BUFFER :\n");
+
+ for (i=0; i<l32; i++)
+ {
+ if ((i%8)==0) ce_print("\n%d\t|", i);
+ //ce_print_byte (*(buf+i));
+ ce_print ("%8x|", *(browser++));
+ }
+ ce_print("\n\n");
+ }
+ else ce_print (" BUFFER NULL !\n");
+}
+
+void
+ce_print_tonemap (tonemap_t *tm)
+{
+ uint i;
+ if(tm)
+ {
+ ce_print("strict:%d ",tm->strict);
+ ce_print("cpf:%d ",tm->cpf);
+ ce_print("fecratio : %d ",tm->fecrate);
+ ce_print("guard : %d ",tm->gil);
+ ce_print("ble = %d \n",tm->ble);
+ u32 *tm_data = (u32 *) tm->tmdma_desc_head->data;
+ for (i=0; i<(PHY_CARRIER_NB+7)/8; i++)
+ {
+ if (i == 128 ) tm_data = (u32 *) tm->tmdma_desc_head->next->data;
+ ce_print_nibble (*(tm_data++));
+ if((i+1)%16==0) ce_print("\n");
+ }
+ ce_print ("\n");
+ }
+}
+
+void
+ce_print_tonemaps (tonemaps_t *tms)
+{
+ int i;
+
+ ce_print ("MAX_FL_AV = %x ",tms->max_fl_av);
+ ce_print ("RIFS %x:%x:%x ",tms->rifs_av_one_sym_tck, tms->rifs_av_two_sym_tck, tms->rifs_av_g2_sym_tck);
+ ce_print ("MAX_TM = %x ",tms->max_tm);
+ ce_print ("Default_tmi = %x ",tms->default_tmi);
+ ce_print ("scl_cp = %x ",tms->scl_cp);
+ ce_print ("scl_cfp = %x ",tms->scl_cfp);
+ ce_print ("expir = %x ",tms->expiration_rtc_date);
+ ce_print ("valid tm nb = %d \n",tonemap_valid_nb (tms));
+
+ for (i=0; i<TONEMAP_INDEX_NB; i++)
+ {
+ if (tms->tm[i])
+ {
+ ce_print("indice %d (%d) ",i,i+4);
+ ce_print_tonemap(tms->tm[i]);
+ }
+ }
+
+ tonemap_intervals_t *intervals = tms->intervals;
+ ce_print ("intervals nb = %d ",intervals->intervals_nb);
+ for (i=0; i<(int)intervals->intervals_nb; i++)
+ {
+ ce_print ("interval[%d]={%.0f,%d} ", i,intervals->interval[i].end_offset_atu*10.24,
+ intervals->interval[i].tmi);
+ }
+ ce_print ("\n");
+}
+
+void
+ce_print_chandata (phy_chandata_t *f)
+{
+ uint i;
+ for(i=0; i<PHY_CHANDATA_BLK_NB; i++)
+ //while (f)
+ {
+ ce_print("{size:%d, last:%d, type:%d, @0x%x}",f->size, f->last, f->type, f->address);
+ if( (i+1) < PHY_CHANDATA_BLK_NB) ce_print ("->\n");
+ f = (phy_chandata_t *) f->blk.next;
+ }
+ ce_print ("\n");
+}
+
+void
+ce_print_frame_measurement (frame_measurement_t *fm)
+{
+ int j;
+ ce_print ("rx_params @ 0x%x -> 0x%x\n", &fm->rx_params, fm->rx_params);
+ ce_print ("ber_stock @ 0x%x -> 0x%x\n", &fm->ber_measurement, fm->ber_measurement);
+ for (j=0; j<PHY_CHANDATA_TYPE_NB; j++)
+ {
+ ce_print ("noise[%d] is @ 0x%x -> 0x%x\n", j, &fm->type_head[j], fm->type_head[j]);
+ }
+}
+#endif
diff --git a/cesar/ce/test/common/tonemap_utils.h b/cesar/ce/test/common/tonemap_utils.h
new file mode 100644
index 0000000000..7d214c6e5a
--- /dev/null
+++ b/cesar/ce/test/common/tonemap_utils.h
@@ -0,0 +1,135 @@
+#ifndef ___common_tonemap_utils_h
+#define ___common_tonemap_utils_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file ../common/tonemap_utils.h
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+#include "mac/common/tonemap.h"
+#include "lib/test.h"
+#include "lib/rnd.h"
+#include "lib/bitstream.h"
+
+lib_rnd_t rnd;
+
+#ifndef MAXIMUS_TEST
+static void
+create_tm (tonemaps_t *tms, u8 *mask, uint tmi, uint max_rnd, uint offset)
+{
+ int i;
+ bitstream_t stream;
+ tms->default_tmi = 0;
+ tms->tm[tmi] = tonemap_alloc ();
+ tms->tm[tmi]->cpf = 1;
+ tms->tm[tmi]->fecrate = 2;
+ tms->tm[tmi]->gil = 3;
+ bitstream_init (&stream, tms->tm[tmi]->tmdma_desc_head->data, 512, BITSTREAM_WRITE);
+ for (i=0; i<PHY_CARRIER_NB+1; i++)
+ {
+ int n = i/8;
+ int r = i%8;
+ int pos = 1<<r;
+ uint to_write;
+ if (i==1024)
+ {
+ bitstream_finalise (&stream);
+ bitstream_init (&stream, tms->tm[tmi]->tmdma_desc_head->next->data, 512, BITSTREAM_WRITE);
+ }
+ if ( (mask[n] & pos) == 0)
+ {
+ to_write = 0; bitstream_access (&stream, &to_write, 4);
+ }
+ else
+ {
+ if (max_rnd != 0 )
+ {
+ to_write = offset+lib_rnd_uniform(&rnd,max_rnd); bitstream_access (&stream, &to_write, 4);
+ }
+ else
+ {
+ to_write = (i&0x07); bitstream_access (&stream, &to_write, 4);
+ }
+ }
+ bitstream_finalise (&stream);
+ }
+}
+#endif
+
+/**
+ * Compare two tonemaps in the test environment
+ * \param t test
+ * \param tms1 tonemaps 1
+ * \param tms2 tonemaps 2
+ *
+ * Check all tonemap (TONEMAP_INDEX_NB)
+ */
+static void
+compare_tonemaps (test_t t, tonemaps_t *tms1, tonemaps_t *tms2, u8 *mask)
+{
+ test_begin (t, "tonemap compare")
+ {
+ int i,j;
+ test_fail_if (tms1->max_fl_av != tms2->max_fl_av);
+ test_fail_if (tms1->rifs_av_one_sym_tck != tms2->rifs_av_one_sym_tck);
+ test_fail_if (tms1->rifs_av_two_sym_tck != tms2->rifs_av_two_sym_tck);
+ test_fail_if (tms1->rifs_av_g2_sym_tck != tms2->rifs_av_g2_sym_tck);
+ test_fail_if (tms1->max_tm != tms2->max_tm);
+ test_fail_if (tms1->default_tmi != tms2->default_tmi);
+ test_fail_if (tms1->scl_cp != tms2->scl_cp);
+ test_fail_if (tms1->scl_cfp != tms2->scl_cfp);
+
+ for (i=0; i<TONEMAP_INDEX_NB; i++)
+ {
+ if(tms1->tm[i] && tms2->tm[i])
+ {
+ //my_print ("test tm[%d]\n",i);
+ tonemap_t *tm1=tms1->tm[i];
+ tonemap_t *tm2=tms2->tm[i];
+ bitstream_t stream1;
+ bitstream_t stream2;
+ bitstream_init (&stream1, tm1->tmdma_desc_head->data, BLK_SIZE, BITSTREAM_READ);
+ bitstream_init (&stream2, tm2->tmdma_desc_head->data, BLK_SIZE, BITSTREAM_READ);
+ test_fail_if (tm1->cpf != tm2->cpf);
+ test_fail_if (tm1->fecrate != tm2->fecrate);
+ test_fail_if (tm1->gil != tm2->gil);
+ for(j=0; j<PHY_CARRIER_NB; j++)
+ {
+
+ if (j==1024)
+ {
+ bitstream_init (&stream1, tm1->tmdma_desc_head->next->data, BLK_SIZE, BITSTREAM_READ);
+ bitstream_init (&stream2, tm2->tmdma_desc_head->next->data, BLK_SIZE, BITSTREAM_READ);
+ }
+
+ u8 d1,d2;
+ bitstream_access (&stream1, &d1, 4);
+ bitstream_access (&stream2, &d2, 4);
+ //ce_print ("c%d : m1-%d m2-%d\n",j, d1, d2);
+ test_fail_if ( d1 != d2 && ((mask[j/8] & (1<<(j%8))) != 0) );
+ }
+ tonemap_intervals_t *intervals1 = tms1->intervals;
+ tonemap_intervals_t *intervals2 = tms2->intervals;
+ test_fail_if (intervals1->intervals_nb != intervals2->intervals_nb);
+ for (j=0; j<(int)intervals1->intervals_nb; j++)
+ {
+ tonemap_interval_t tmi1=intervals1->interval[j];
+ tonemap_interval_t tmi2=intervals2->interval[j];
+ test_fail_if ( tmi1.end_offset_atu != tmi2.end_offset_atu );
+ test_fail_if ( tmi1.tmi != tmi2.tmi );
+ }
+ }
+ else test_fail_if (tms1->tm[i] != tms2->tm[i]);
+ }
+ } test_end;
+}
+
+#endif /* ___common_tonemap_utils_h */
diff --git a/cesar/ce/test/cov/cov_all_run.sh b/cesar/ce/test/cov/cov_all_run.sh
new file mode 100755
index 0000000000..f405ec2a79
--- /dev/null
+++ b/cesar/ce/test/cov/cov_all_run.sh
@@ -0,0 +1,42 @@
+#!/bin/sh
+
+clean=
+firefox=0
+MAXIMUS_ARG=
+run=
+
+while getopts cfm:et: opt
+do
+ case "$opt" in
+ c) clean="-c";;
+ e) run="-e";;
+ f) firefox=1;;
+ m) MAXIMUS_ARG="-x $OPTARG";;
+ t) test_path="$OPTARG";;
+ [?]) print >&2 "Usage: $0 [-c] [-e] [-f] [-m maximus_path] [-t test_path] "
+ exit 1;;
+ esac
+done
+
+cov_path=`dirname $0`
+if [ "$run" != "" ]
+then
+ echo "Erase coverage result"
+ rm -rf $cov_path/result
+ mkdir $cov_path/result
+fi
+
+$cov_path/cov_one_run.sh -t $test_path -s tx -m host-Makefile -o obj/host $clean $run -h host
+$cov_path/cov_one_run.sh -t $test_path -s tx -m target-Makefile -o obj/target $clean $run -h target
+$cov_path/cov_one_run.sh -t $test_path -s rx/general -m host-Makefile -o obj/host $clean $run -h host
+$cov_path/cov_one_run.sh -t $test_path -s rx/general -m target-Makefile -o obj/target $clean $run -h target
+$cov_path/cov_one_run.sh -t $test_path -s rx/tonemap_refresh -m Makefile -o obj $clean $run -h target
+$cov_path/cov_one_run.sh -t $test_path -s rx/maximus -m Makefile -o obj $clean $run -p send_noise.py $MAXIMUS_ARG -h target
+
+if [ "$firefox" = "1" ]
+then
+ ls -l $cov_path/result
+ genhtml -q -o $cov_path/result -s $cov_path/result/*.info
+ firefox $cov_path/result/index.html
+fi
+
diff --git a/cesar/ce/test/cov/cov_one_run.sh b/cesar/ce/test/cov/cov_one_run.sh
new file mode 100755
index 0000000000..ecb2530e4e
--- /dev/null
+++ b/cesar/ce/test/cov/cov_one_run.sh
@@ -0,0 +1,63 @@
+#!/bin/sh
+
+py=
+maximus_path=
+clean=
+run=
+cross=target
+
+echo "$0 $@"
+while getopts t:s:m:o:cep:x:h: opt
+do
+ case "$opt" in
+ t) TEST_PATH="$OPTARG";;
+ s) SUBTEST_PATH="$OPTARG";;
+ m) MAKEFILE_NAME="$OPTARG";;
+ o) OBJ_PATH="$OPTARG";;
+ c) clean=1;;
+ p) py="$OPTARG";;
+ x) maximus_path="$OPTARG";;
+ e) run=1;;
+ h) cross="$OPTARG";;
+ [?]) print >&2 "Usage: $0 -t test_path -s subtest_path -m makefile -o objpath [-c(clean)] [-e(exec)] [-p] python_file [-x] maximus_path [-h] host/target"
+ exit 1;;
+ esac
+done
+
+SUBTEST_PATH=$TEST_PATH/$SUBTEST_PATH
+OBJ_PATH=$SUBTEST_PATH/$OBJ_PATH
+
+if [ "$clean" != "" ]
+then
+ echo "Make Clean @ $SUBTEST_PATH..."
+ rm -rf $SUBTEST_PATH/obj
+ rm -f $SUBTEST_PATH/*.da; rm -f $SUBTEST_PATH/*.bb*;rm -f $SUBTEST_PATH/*.log
+fi
+
+if [ "$run" != "" ]
+then
+ echo "Compiling $MAKEFILE_NAME in $SUBTEST_PATH ..."
+ make COV=Y -C $SUBTEST_PATH --file=$MAKEFILE_NAME --no-print-directory > $SUBTEST_PATH/$MAKEFILE_NAME.log
+ #for i in `ls $OBJ_PATH | grep "\.elf$"`
+ for i in `ls -l $OBJ_PATH | grep "^-rwxr-xr-x" | cut -d " " -f8`
+ do
+ if [ "$py" != "" ]
+ then
+ echo "Running python $SUBTEST_PATH/$py -e $OBJ_PATH/$i -d false -l 1"
+ python $SUBTEST_PATH/$py -e $OBJ_PATH/$i -d false -l 1 --maximus_path $maximus_path
+ else
+ echo "Running " $OBJ_PATH/$i;
+ ./$OBJ_PATH/$i
+ fi
+ echo "Make coverage report ..."
+ if [ "$cross" = "target" ]
+ then
+ sleep 1
+ lcov -q -d $SUBTEST_PATH -b $SUBTEST_PATH -c -o $OBJ_PATH/$i.info -g /usr/local/toolchains/gnutools/i386-elf/bin/i386-elf-gcov
+ else
+ lcov -q -d $OBJ_PATH -b $SUBTEST_PATH -c -o $OBJ_PATH/$i.info
+ fi
+ echo "Copying files .info"
+ cp $OBJ_PATH/$i.info $TEST_PATH/cov/result
+ done
+fi
diff --git a/cesar/ce/test/rx/Config b/cesar/ce/test/rx/Config
new file mode 100755
index 0000000000..f3da7ad972
--- /dev/null
+++ b/cesar/ce/test/rx/Config
@@ -0,0 +1,5 @@
+CONFIG_DEBUG_FATAL_CATCH=y
+#CONFIG_RESTRACK=y
+#CONFIG_RESTRACK_KEEP=y
+CONFIG_TRACE=y
+
diff --git a/cesar/ce/test/rx/general/Makefile b/cesar/ce/test/rx/general/Makefile
new file mode 100644
index 0000000000..b0e6e8d3fa
--- /dev/null
+++ b/cesar/ce/test/rx/general/Makefile
@@ -0,0 +1,8 @@
+all :
+ $(MAKE) -f host-Makefile --no-print-directory
+ $(MAKE) -f target-Makefile --no-print-directory
+
+clean :
+ $(MAKE) -f host-Makefile clean
+ $(MAKE) -f target-Makefile clean
+
diff --git a/cesar/ce/test/rx/general/host-Makefile b/cesar/ce/test/rx/general/host-Makefile
new file mode 100755
index 0000000000..296fad4b8d
--- /dev/null
+++ b/cesar/ce/test/rx/general/host-Makefile
@@ -0,0 +1,33 @@
+BASE = ../../../..
+
+INCLUDES=ce/test/rx
+INCLUDES+=ce/test/common
+INCLUDES+=ce/test/common/ecos_overide
+
+EXTRA_HOST_LDFLAGS=-lm
+HOST_PROGRAMS = test_cei_host_linux_i386
+test_cei_host_linux_i386_SOURCES = test_cei.c
+test_cei_host_linux_i386_MODULES = lib mac/common ce ce/test/common ce/test/common/ecos_overide/cyg/kernel
+HOST_PROGRAMS += test_cei_param_host_linux_i386
+test_cei_param_host_linux_i386_SOURCES = test_cei_param.c
+test_cei_param_host_linux_i386_MODULES = lib mac/common ce ce/test/common ce/test/common/ecos_overide/cyg/kernel
+HOST_PROGRAMS += test_measure_store_host_linux_i386
+test_measure_store_host_linux_i386_SOURCES = test_mpdu_measure_store.c
+test_measure_store_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 mpdu_measure_store.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
+
+VARIANT = host
+
+include $(BASE)/common/make/top.mk
+
diff --git a/cesar/ce/test/rx/general/overide/cp/Module b/cesar/ce/test/rx/general/overide/cp/Module
new file mode 100644
index 0000000000..3983e4ac20
--- /dev/null
+++ b/cesar/ce/test/rx/general/overide/cp/Module
@@ -0,0 +1 @@
+SOURCES := cp.c
diff --git a/cesar/ce/test/rx/general/overide/cp/cp.h b/cesar/ce/test/rx/general/overide/cp/cp.h
new file mode 100644
index 0000000000..f2094aa56f
--- /dev/null
+++ b/cesar/ce/test/rx/general/overide/cp/cp.h
@@ -0,0 +1,50 @@
+#ifndef ___rx_general_overide_cp_cp_h
+#define ___rx_general_overide_cp_cp_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file ../rx/general/overide/cp/cp.h
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+#include "mac/common/tonemap.h"
+#include "mac/common/store.h"
+#include "mac/common/config.h"
+#include "cyg/kernel/kapi.h"
+#include "ce/inc/tx.h"
+
+struct cp_t
+{
+ mac_store_t *mac_store_ctx;
+ mac_config_t *mac_config;
+ u8 *tonemask;
+ uint has_event;
+ u8 cei_buffer[1536];
+ bool stop_rcv_mme;
+ txce_t *txce_ctx;
+};
+typedef struct cp_t cp_t;
+
+void
+cp_process (cyg_addrword_t data);
+
+void
+cp_stop (cp_t *ctx);
+
+cp_t *
+cp_init (mac_store_t *mac_store_ctx, mac_config_t *mac_config);
+
+void
+cp_event_add (cp_t *ctx, uint type_event);
+
+void
+cp_emul_cei_reception (cp_t *ctx);
+
+#endif /* ___rx_general_overide_cp_cp_h */
diff --git a/cesar/ce/test/rx/general/overide/cp/interf/Module b/cesar/ce/test/rx/general/overide/cp/interf/Module
new file mode 100644
index 0000000000..5950fd7d38
--- /dev/null
+++ b/cesar/ce/test/rx/general/overide/cp/interf/Module
@@ -0,0 +1 @@
+SOURCES := interf.c
diff --git a/cesar/ce/test/rx/general/overide/cp/interf/interf.h b/cesar/ce/test/rx/general/overide/cp/interf/interf.h
new file mode 100755
index 0000000000..8c3545604e
--- /dev/null
+++ b/cesar/ce/test/rx/general/overide/cp/interf/interf.h
@@ -0,0 +1,65 @@
+#ifndef cp_interf_interf_h
+#define cp_interf_interf_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file ./overide/cp/cp.h
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+
+#include "common/defs/ethernet.h"
+#include "mac/sar/inc/sar_mf.h"
+#include "cyg/kernel/kapi.h"
+
+#define TXCE_EVENT 0
+
+u8 buf[ETH_PACKET_MAX_SIZE];
+
+typedef void (*interf_event_add_cb_t) (void *userdata, uint type_event);
+
+struct interf_t
+{
+ interf_event_add_cb_t event_add_cb;
+ void *event_add_userdata;
+};
+typedef struct interf_t interf_t;
+
+struct mme_t
+{
+ /** Destination TEI of the MME.*/
+ uint dtei;
+ /** Length of the MM_ENTRY.*/
+ uint length;
+ /** Type of the MME.*/
+ uint mm_type;
+ /** Pointer to the start of the MM_ENTRY.*/
+ u8 * mm_entry;
+};
+typedef struct mme_t mme_t;
+
+BEGIN_DECLS
+
+interf_t *
+interf_init ( interf_event_add_cb_t event_add_cb, void* userdata);
+
+mme_t *
+interf_mme_get (void);
+
+void
+interf_mme_send (mme_t *mme);
+
+void
+interf_event_add (interf_t *interf, uint type_event);
+
+
+END_DECLS
+
+#endif /* cp_interf_interf_h */
diff --git a/cesar/ce/test/rx/general/overide/cp/interf/src/interf.c b/cesar/ce/test/rx/general/overide/cp/interf/src/interf.c
new file mode 100755
index 0000000000..424b9426b3
--- /dev/null
+++ b/cesar/ce/test/rx/general/overide/cp/interf/src/interf.c
@@ -0,0 +1,52 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file ./overide/cp/src/cp.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+#include "common/std.h"
+#include "cp/interf/interf.h"
+#include "ce/inc/tx.h"
+#include "ce/inc/cei.h"
+
+static interf_t interf_global;
+mme_t mme;
+
+interf_t *
+interf_init ( interf_event_add_cb_t event_add_cb, void* userdata)
+{
+ interf_t *interf = &interf_global;
+ interf->event_add_cb = event_add_cb;
+ interf->event_add_userdata = userdata;
+ return (interf);
+}
+
+mme_t *
+interf_mme_get (void)
+{
+ mme.mm_entry = buf;
+ return &mme;
+}
+
+void
+interf_mme_send (mme_t *mme_to_send)
+{
+ dbg_assert (mme_to_send = &mme);
+ return;
+}
+
+void
+interf_event_add (interf_t *ctx, uint type_event)
+{
+ ctx->event_add_cb (ctx->event_add_userdata, type_event);
+ return;
+}
+
diff --git a/cesar/ce/test/rx/general/overide/cp/src/cp.c b/cesar/ce/test/rx/general/overide/cp/src/cp.c
new file mode 100644
index 0000000000..c810c1d82c
--- /dev/null
+++ b/cesar/ce/test/rx/general/overide/cp/src/cp.c
@@ -0,0 +1,92 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file ../rx/general/overide/cp/src/cp.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+#include "common/std.h"
+#include "cp/cp.h"
+#include "cp/interf/interf.h"
+#include "tonemap_utils.h"
+#include "lib/rnd.h"
+#include "ce/inc/cei_param.h"
+#define RXCE
+#include "ce/inc/cei.h"
+
+
+static cp_t cp_global;
+
+void
+cp_process (cyg_addrword_t data)
+{
+ cp_t *ctx = (cp_t *) data;
+ ctx->stop_rcv_mme = false;
+ while (true)
+ {
+ cyg_thread_delay (100);
+ if (ctx->has_event)
+ {
+ txce (ctx->txce_ctx, 0, 0, NULL);
+ ctx->has_event--;
+ }
+ if (!ctx->stop_rcv_mme) cp_emul_cei_reception (ctx);
+ }
+}
+
+void
+cp_stop (cp_t *ctx)
+{
+ ctx->stop_rcv_mme = true;
+}
+
+cp_t *
+cp_init (mac_store_t *mac_store_ctx, mac_config_t *mac_config)
+{
+ cp_t *ctx = &cp_global;
+ ctx->mac_store_ctx = mac_store_ctx;
+ ctx->mac_config = mac_config;
+ interf_t *interf = interf_init(&cp_event_add, (void *) ctx);
+ ctx->txce_ctx = txce_init (mac_store_ctx, mac_config, interf);
+ lib_rnd_init (&rnd, 123);
+ ctx->tonemask = (ctx->mac_config->tonemask_info.tonemask);
+ return ctx;
+}
+
+void
+cp_emul_cei_reception (cp_t *ctx)
+{
+ uint i;
+ uint alea_new_mme = lib_rnd_uniform (&rnd, 20);
+ if (alea_new_mme > 5)
+ {
+ return;
+ }
+ for (i=0; i<alea_new_mme; i++)
+ {
+ uint rnd_tmi = lib_rnd_uniform (&rnd, TONEMAP_INDEX_NB);
+ uint rnd_tei = lib_rnd_uniform (&rnd, MAC_TEI_STA_MAX) + MAC_TEI_STA_MIN;
+ mac_store_sta_add (ctx->mac_store_ctx, rnd_tei);
+ sta_t *lsta = mac_store_sta_get (ctx->mac_store_ctx, rnd_tei);
+ if (lsta->tx_tonemaps->tm[rnd_tmi] == NULL)
+ {
+ create_tm (lsta->tx_tonemaps, ctx->tonemask, rnd_tmi, 1, 4);
+ cei_create (ctx->cei_buffer, ctx->tonemask, lsta->tx_tonemaps, rnd_tmi, TONEMAP_INDEX_NULL);
+ txce (ctx->txce_ctx, rnd_tei, CM_CHAN_EST_IND, ctx->cei_buffer);
+ }
+ }
+}
+
+void
+cp_event_add (cp_t *ctx, uint type)
+{
+ if (type == TXCE_EVENT) ctx->has_event++;
+ return;
+}
diff --git a/cesar/ce/test/rx/general/src/test_bitloading.c b/cesar/ce/test/rx/general/src/test_bitloading.c
new file mode 100755
index 0000000000..319b06ca48
--- /dev/null
+++ b/cesar/ce/test/rx/general/src/test_bitloading.c
@@ -0,0 +1,235 @@
+/* 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 "mac/common/timings.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_energy_t *data = (phy_noise_energy_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;
+ //mpdu_measure_store_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 (mpdu_measure_chandata_blk_nb[PHY_CHANDATA_TYPE_NRJ], (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_energy_t *data = (phy_noise_energy_t *) b->blk.data;
+ for (c=0; c<PHY_NOISE_NB_PER_BLK; 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_energy_t *data = (phy_noise_energy_t *) b->blk.data;
+ for (c=0; c<PHY_NOISE_NB_PER_BLK; 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;
+ }
+
+void
+test_date_in_beacon_atu_get (test_t t)
+{
+ test_begin (t, "check date_atu_get")
+ {
+ int i;
+ for (i=0; i<MAC_MS_TO_TCK(40)/2; i++)
+ {
+ uint ans = bitloading_date_in_beacon_atu_get (i, (0xFFFFFFFF)-i);
+ test_fail_if (ans != (uint) MAC_TCK_TO_ATU(2*i+1));
+ ans = bitloading_date_in_beacon_atu_get (1000000-i, i);
+ test_fail_if (ans != (uint) MAC_TCK_TO_ATU(1000000-2*i));
+ }
+ } test_end;
+}
+
+int
+main (int argc, char **argv)
+{
+ test_t test;
+ mpdu_measure_store_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_date_in_beacon_atu_get (test);
+ test_result (test);
+ return (test_nb_failed (test) == 0 ? 0 : 1);
+}
+
diff --git a/cesar/ce/test/rx/general/src/test_cei.c b/cesar/ce/test/rx/general/src/test_cei.c
new file mode 100755
index 0000000000..3c883cbd71
--- /dev/null
+++ b/cesar/ce/test/rx/general/src/test_cei.c
@@ -0,0 +1,80 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file ./src/test_cei.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+#include "common/std.h"
+#define RXCE
+#define TXCE
+#include "ce/inc/cei.h"
+#include "lib/test.h"
+#include "mac/common/tonemask.h"
+#include "ce/test/common/tonemap_utils.h"
+#include "ce/test/common/print_utils.h"
+
+void
+test_exchange (test_t test, tonemaps_t *rx_tms, tonemaps_t *tx_tms,
+ u8 *mask, uint tmi, uint max_rnd, uint offset)
+{
+ u8 buffer[1536];
+ int i; for (i=0; i<1536; i++) buffer[i]=0;
+ create_tm (rx_tms, mask, tmi, max_rnd, offset);
+ ce_print_tonemaps (rx_tms);
+ cei_create (buffer, mask, rx_tms, tmi, TONEMAP_INDEX_NULL);
+ ce_print_buffer (buffer, 512);
+ cei_decode (tx_tms, CM_CHAN_EST_IND, buffer, mask);
+ ce_print_tonemaps (tx_tms);
+ compare_tonemaps (test, rx_tms, tx_tms, mask);
+}
+
+int
+main (int argc, char **argv)
+{
+ int i;
+ u8 mask[(PHY_CARRIER_NB+7)/8];
+ for (i=0; i<(PHY_CARRIER_NB+7)/8; i++) mask[i] = 0xFF;
+ mask[i-1] = ((1<<(PHY_CARRIER_NB%8))-1);
+ test_t test;
+ lib_rnd_init (&rnd, 12);
+ test_init (test, argc, argv);
+ tonemaps_t *rx_tms = tonemaps_alloc();
+ tonemaps_t *tx_tms = tonemaps_alloc();
+ test_case_begin (test, "CE-cei-full mask");
+ test_exchange (test, rx_tms, tx_tms, mask, 0, 3, 1);
+ test_exchange (test, rx_tms, tx_tms, mask, 1, 2, 6);
+ test_exchange (test, rx_tms, tx_tms, mask, 2, 1, 3);
+ test_exchange (test, rx_tms, tx_tms, mask, 3, 0, 3);
+ tonemaps_release (rx_tms);
+ tonemaps_release (tx_tms);
+ test_begin (test, "check alloc/free")
+ {
+ test_fail_unless (blk_check_memory());
+ } test_end;
+
+ rx_tms = tonemaps_alloc();
+ tx_tms = tonemaps_alloc();
+ tonemask_default (mask);
+ test_case_begin (test, "CE-cei-default mask");
+ test_exchange (test, rx_tms, tx_tms, mask, 0, 3, 1);
+ test_exchange (test, rx_tms, tx_tms, mask, 1, 2, 6);
+ test_exchange (test, rx_tms, tx_tms, mask, 2, 1, 3);
+ test_exchange (test, rx_tms, tx_tms, mask, 3, 0, 3);
+ tonemaps_release (rx_tms);
+ tonemaps_release (tx_tms);
+ test_begin (test, "check alloc/free")
+ {
+ test_fail_unless (blk_check_memory());
+ } test_end;
+ test_result (test);
+ return (test_nb_failed (test) == 0 ? 0 : 1);
+}
+
diff --git a/cesar/ce/test/rx/general/src/test_cei_param.c b/cesar/ce/test/rx/general/src/test_cei_param.c
new file mode 100755
index 0000000000..66a869d4d2
--- /dev/null
+++ b/cesar/ce/test/rx/general/src/test_cei_param.c
@@ -0,0 +1,86 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file ./src/test_tx.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+
+
+#include "common/std.h"
+#include "ce/test/common/print_utils.h"
+#include "ce/inc/cei_param.h"
+
+#include "lib/rnd.h"
+#include "lib/test.h"
+
+lib_rnd_t rnd;
+
+void
+test_cei_param (test_t test, uint read_percent)
+{
+ test_begin (test, "test_cei_param")
+ {
+ int n;
+ //test_debug_print ("%d%% of read %d%% of write ", read_percent, 100-read_percent);
+ lib_rnd_init (&rnd, 23);
+ //cei_param_t cei_param;
+ cei_param_fifo_init ();
+ cei_param_t cei_param;
+ cei_param.tms = NULL;
+ cei_param.new_tmi = 0;
+ cei_param.old_tmi = 0;
+ cei_param.priority = 0xFF;
+ cei_param.dtei = 0xFF;
+ uint cpt = 0;
+ for (n=0; n<1000; n++)
+ {
+ uint alea = lib_rnd_uniform (&rnd, 100);
+ //my_print ("%d\n" ,alea);
+ test_fail_if (cpt>CEI_WANTED_MAX);
+ if (alea > read_percent)
+ {
+ //my_print (" get %d <=> %d\n", cpt, cei_param_fifo.number);
+ uint reader_index = cei_param_fifo.reader_index;
+ test_fail_if (cpt != cei_param_fifo.number);
+ cei_param_t *param = cei_param_get ();
+ //if (!param) my_print ("param = NULL\n");
+ test_fail_if (!param && cpt!=0);
+ if (param)
+ {
+ //my_print ("%d <==> %d\n", reader_index, 0);
+ test_fail_if (reader_index != param->priority);
+ cpt--;
+ }
+ }
+ else
+ {
+ //my_print (" add\n");
+ cei_param.priority = cei_param_fifo.writer_index;
+ if (cei_param_add (&cei_param)) cpt++;
+ }
+ }
+ } test_end;
+}
+
+int
+main (int argc, char **argv)
+{
+ test_t test;
+ test_init (test, argc, argv);
+ test_case_begin (test, "CE-mme 75% of read");
+ test_cei_param (test, 75);
+ test_case_begin (test, "CE-mme 25% of read");
+ test_cei_param (test, 25);
+ test_case_begin (test, "CE-mme 50% of read");
+ test_cei_param (test, 50);
+ test_result (test);
+ return (test_nb_failed (test) == 0 ? 0 : 1);
+}
diff --git a/cesar/ce/test/rx/general/src/test_mpdu_measure_store.c b/cesar/ce/test/rx/general/src/test_mpdu_measure_store.c
new file mode 100755
index 0000000000..8b95e3cafd
--- /dev/null
+++ b/cesar/ce/test/rx/general/src/test_mpdu_measure_store.c
@@ -0,0 +1,294 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file ./src/test_tx.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+
+
+#include "common/std.h"
+#include "mac/common/tonemap.h"
+#include "ce/test/common/print_utils.h"
+#include "lib/rnd.h"
+#include "lib/test.h"
+
+lib_rnd_t rnd;
+
+void
+test_alloc_release (test_t test)
+{
+ test_begin (test, "mpdu_measure allocation and release")
+ {
+ if (!blk_check_memory()) blk_print_memory();
+ test_fail_unless (blk_check_memory ());
+ } test_end;
+}
+
+void
+sar_fill_ber (blk_t *first, uint n, uint ber_init_value, uint offset)
+{
+ uint i;
+ u32 *wrdata = (u32 *) first->data;
+ uint cpt = offset;
+ for (i=0; i<n; i++)
+ {
+ if (cpt == BLK_SIZE/4)
+ {
+ dbg_assert (first->next);
+ first = first->next;
+ wrdata = (u32 *) first->data;
+ cpt=0;
+ }
+ *(wrdata+cpt) = i+ber_init_value;
+ cpt++;
+ }
+}
+
+void
+test_mpdu_measure_pb_add (test_t t, mpdu_measure_store_t *ctx)
+{
+ test_begin (t, "add pb measures")
+ {
+ uint sar_call_nb, pb_nb_per_call;
+ for (sar_call_nb=1; sar_call_nb < MAC_MAX_PB_PER_MPDU; sar_call_nb++)
+ {
+ uint max_pb_nb_per_call = MAC_MAX_PB_PER_MPDU / sar_call_nb;
+ for (pb_nb_per_call=1; pb_nb_per_call<max_pb_nb_per_call ; pb_nb_per_call ++)
+ {
+ uint N = sar_call_nb;
+ uint pb_nb_to_add = pb_nb_per_call;
+ uint n,i;
+ uint offset;
+ pb_measure_blk_t *first_ber =NULL;
+ pb_measure_blk_t *last_ber = NULL;
+
+ pbproc_rx_params_t *rx_params = (pbproc_rx_params_t *) blk_alloc();
+ mpdu_measure_store_append (ctx, rx_params, 0, &first_ber, &last_ber, NULL, 0, NULL);
+ mpdu_measure_t *measure = mpdu_measure_store_get(ctx);
+ for (n=0; n<N; n++)
+ {
+ mpdu_measure_pb_add (measure, pb_nb_to_add, &first_ber, &last_ber, &offset);
+ sar_fill_ber ((blk_t *)first_ber, pb_nb_to_add, n * pb_nb_to_add, offset);
+ }
+ pb_measure_blk_t *rd = measure->pb_head;
+ u32 *rddata = (u32 *) rd->data;
+ test_fail_if (!measure);
+ test_fail_if (!rd);
+ uint k=0;
+ uint cpt = 1;
+ do
+ {
+ for (i=0; i<BLK_SIZE/4; i++)
+ {
+ test_fail_if ( (i<rd->pb_nb) && *(rddata+i)!=k);
+ k++;
+ }
+ if (rd->next)
+ {
+ rd = rd->next;
+ rddata = (u32 *) rd->data;
+ cpt++;
+ }
+ else
+ {
+ test_fail_if (rd != last_ber);
+ rd = rd->next;
+ }
+ } while (rd);
+ uint comp = (N*pb_nb_to_add)/(BLK_SIZE/4);
+ if ((N*pb_nb_to_add)%(BLK_SIZE/4) >0) comp++;
+ test_fail_if (cpt != comp);
+ mpdu_measure_store_release (ctx, measure);
+ }
+ }
+ } test_end;
+}
+
+phy_chandata_t *
+chandata_init (int type)
+{
+ phy_chandata_t *last;
+ phy_chandata_t *chandata = (phy_chandata_t *) blk_alloc_desc_range (
+ mpdu_measure_chandata_blk_nb[type], (blk_t **) &last);
+ chandata->type = type;
+ last->blk.next = NULL;
+ phy_chandata_t *ch = chandata;
+ while (ch)
+ {
+ uint i;
+ phy_noise_energy_t * data = (phy_noise_energy_t *) ch->blk.data;
+ for (i=0; i<PHY_NOISE_NB_PER_BLK; i++ ) *(data+i) = (type)*i;
+ ch->last = 0;
+ ch->type = type;
+ ch = (phy_chandata_t *) ch->blk.next;
+ }
+ last->last = 1;
+ return (chandata);
+}
+
+void
+test_mpdu_measure_chandata_add (test_t t, mpdu_measure_store_t *ctx)
+{
+ test_begin (t, "add noise")
+ {
+ uint i;
+ pbproc_rx_params_t *rx_params = (pbproc_rx_params_t *) blk_alloc();
+ bool b = mpdu_measure_store_append (ctx, rx_params, 0, NULL, NULL, NULL, 0, NULL);
+ if (b)
+ {
+ mpdu_measure_t *measure = mpdu_measure_store_get(ctx);
+ for (i=1; i<PHY_CHANDATA_TYPE_NB; i++)
+ {
+ phy_chandata_t *chandata = chandata_init (i);
+ mpdu_measure_chandata_add (measure, chandata);
+ }
+ for (i=0; i<PHY_CHANDATA_TYPE_NB; i++)
+ {
+ phy_chandata_t *chandata = measure->chandata_head[i];
+ while (chandata)
+ {
+ phy_noise_energy_t *data = (phy_noise_energy_t *) chandata->blk.data;
+ uint j;
+ for (j=0; j<PHY_NOISE_NB_PER_BLK; j++)
+ {
+ test_fail_if (*(data+j) != i*j);
+ }
+ int last = chandata->last;
+ chandata = (phy_chandata_t *) chandata->blk.next;
+ if (!chandata) test_fail_if (last == 0);
+ else test_fail_if (last == 1);
+ }
+ }
+ mpdu_measure_store_release (ctx, measure);
+ }
+ } test_end;
+}
+
+void
+test_mpdu_measure_add (test_t t, mpdu_measure_store_t *ctx)
+{
+ test_begin (t, "add/remove mpdu measures")
+ {
+ lib_rnd_init (&rnd, 23);
+ int nb_frame_added = 0;
+ int nb_frame_measurement = 0;
+ int alea ;
+ int N = 1000;
+ int i;
+ for (i=0; i<N; i++)
+ {
+ alea = lib_rnd_uniform (&rnd, 100);
+ if (alea > 5 )
+ {
+ pbproc_rx_params_t *rx_params = (pbproc_rx_params_t *) blk_alloc();
+ pb_measure_blk_t **f,**l;
+ f = l = NULL;
+ bool b = mpdu_measure_store_append (ctx, rx_params, 0, f, l, NULL, 0, NULL);
+ if (b)
+ {
+ rx_params->preamble_ntb = nb_frame_added;
+ nb_frame_added++;
+ nb_frame_measurement++;
+ }
+ }
+ else
+ {
+ if (nb_frame_measurement == 0)
+ {
+ test_fail_if (ctx->measure_nb != 0);
+ }
+ else
+ {
+ mpdu_measure_t *first = mpdu_measure_store_get (ctx);
+ int test = first->rx_params->preamble_ntb;
+ test_fail_if (test != (nb_frame_added - nb_frame_measurement));
+ mpdu_measure_store_release (ctx, first);
+ nb_frame_measurement--;
+ }
+ }
+ }
+ while (nb_frame_measurement > 0)
+ {
+ mpdu_measure_t *first = mpdu_measure_store_get (ctx);
+ int test = first->rx_params->preamble_ntb;
+ test_fail_if (test != (nb_frame_added - nb_frame_measurement));
+ mpdu_measure_store_release (ctx, first);
+ nb_frame_measurement--;
+ }
+ test_fail_if (mpdu_measure_store_get (ctx));
+ } test_end;
+}
+
+void
+test_mpdu_measure_store_management (test_t t, mpdu_measure_store_t *ctx)
+{
+ test_begin (t, "store is full get-add-release")
+ {
+ int N = MPDU_MEASURE_STORE_SIZE;
+ int i;
+ // Fill the store.
+ for (i=0; i<N; i++)
+ {
+ pbproc_rx_params_t *rx_params = (pbproc_rx_params_t *) blk_alloc();
+ pb_measure_blk_t **f,**l;
+ f = l = NULL;
+ bool b = mpdu_measure_store_append (ctx, rx_params, 0, f, l, NULL, 0, NULL);
+ if (b)
+ {
+ rx_params->preamble_ntb = i;
+ }
+ }
+ // Get first then add before release.*/
+ mpdu_measure_t *first = mpdu_measure_store_get (ctx);
+ pbproc_rx_params_t *rx_params = (pbproc_rx_params_t *) blk_alloc();
+ pb_measure_blk_t **f,**l;
+ f = l = NULL;
+ bool b = mpdu_measure_store_append (ctx, rx_params, 0, f, l, NULL, 0, NULL);
+ test_fail_if (b);
+ mpdu_measure_store_release (ctx, first);
+ // Release all the store.
+ while (ctx->measure_nb)
+ {
+ mpdu_measure_store_release (ctx, mpdu_measure_store_get (ctx));
+ }
+ } test_end;
+ test_begin (t, "store is empty get-add-get-release")
+ {
+ mpdu_measure_t *first = mpdu_measure_store_get (ctx);
+ pbproc_rx_params_t *rx_params = (pbproc_rx_params_t *) blk_alloc();
+ pb_measure_blk_t **f,**l;
+ f = l = NULL;
+ // Test store empty.
+ first = mpdu_measure_store_get (ctx);
+ test_fail_if (first);
+ mpdu_measure_store_append (ctx, rx_params, 0, f, l, NULL, 0, NULL);
+ first = mpdu_measure_store_get (ctx);
+ test_fail_unless (first->rx_params == rx_params);
+ mpdu_measure_store_release (ctx, first);
+ } test_end;
+}
+
+int
+main (int argc, char **argv)
+{
+ test_t test;
+ mpdu_measure_store_t *ctx = mpdu_measure_store_init();
+ test_init (test, argc, argv);
+ test_case_begin (test, "RXCE-mpdu_measure_store");
+ test_mpdu_measure_pb_add (test, ctx);
+ test_mpdu_measure_chandata_add (test, ctx);
+ test_mpdu_measure_add (test, ctx);
+ test_mpdu_measure_store_management (test, ctx);
+ test_alloc_release (test);
+ test_result (test);
+ return (test_nb_failed (test) == 0 ? 0 : 1);
+}
+
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);
+}
+
diff --git a/cesar/ce/test/rx/general/src/test_sar_integration.c b/cesar/ce/test/rx/general/src/test_sar_integration.c
new file mode 100755
index 0000000000..e580928cea
--- /dev/null
+++ b/cesar/ce/test/rx/general/src/test_sar_integration.c
@@ -0,0 +1,303 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file ce/test/rx/sar_integration.c
+ * \brief Use sar callback for Channel estimation.
+ * \ingroup ce
+ *
+ */
+#include "common/std.h"
+#include "cyg/hal/hal_intr.h"
+#include "lib/test.h"
+#include "mac/sar/sar.h"
+#include "ce/inc/rx.h"
+#include "mac/common/pb.h" // PB header initialisation
+#include "ce/test/common/print_utils.h"
+#include "cp/interf/interf.h"
+//#include "mac/sar/inc/trace.h"
+#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;
+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];
+
+test_t test;
+mac_store_t *mac_store_ctx;
+mac_config_t mac_config;
+rxce_t *rxce_ctx;
+phy_t *phy;
+
+u32
+phy_date (phy_t *phy)
+{
+ return (cyg_current_time());
+}
+
+void
+pbproc_scf (void)
+{
+ ce_print("pbproc_scf()\n");
+}
+
+void
+emul_reassembly (int pb_nb, uint date, pbproc_rx_params_t **rx_params,
+ pb_t **f, pb_t **l, phy_chandata_t **noise)
+{
+ uint i, j;
+ if (pb_nb > 0)
+ {
+ *f = (pb_t *) blk_alloc_desc_range (pb_nb,(blk_t **)l);
+ (*l)->next = NULL;
+ phy_pb_rx_t *p = (phy_pb_rx_t *) *f;
+ for (i=0; i<(uint) pb_nb; i++)
+ {
+ p->pb_measurement.ber = i;
+ ((pb_t *)p)->header.vpbf = 0;
+ p = (phy_pb_rx_t *) p->blk.next;
+ }
+ }
+ else
+ {
+ *f = *l = NULL;
+ }
+
+ phy_chandata_t *l_noise, *p_noise;
+ phy_chandata_t *f_noise = (phy_chandata_t *) blk_alloc_desc_range (mpdu_measure_chandata_blk_nb[PHY_CHANDATA_TYPE_NRJ], (blk_t **)&l_noise);
+ p_noise = f_noise;
+ phy_noise_energy_t *data;
+ for (i=0; i<mpdu_measure_chandata_blk_nb[PHY_CHANDATA_TYPE_NRJ]; i++)
+ {
+ if (p_noise == l_noise)
+ {
+ p_noise->last = 1;
+ p_noise->blk.next = NULL;
+ dbg_assert (i == (mpdu_measure_chandata_blk_nb[PHY_CHANDATA_TYPE_NRJ]-1));
+ }
+ else
+ {
+ p_noise->last = 0;
+ }
+ p_noise->type = PHY_CHANDATA_TYPE_NRJ;
+ data = (phy_noise_energy_t *) p_noise->blk.data;
+ for (j=0; j<PHY_NOISE_NB_PER_BLK; j++) *data++ = (i+1) * j*3;
+ p_noise = (phy_chandata_t *) p_noise->blk.next;
+ }
+
+ *noise = (phy_chandata_t *) blk_alloc_desc ();
+ data = (phy_noise_energy_t *) (*noise)->blk.data;
+ for (j=0; j<PHY_NOISE_NB_PER_BLK; j++)
+ {
+ *data++ = 1000;
+ }
+ (*noise)->type = PHY_CHANDATA_TYPE_NRJ_SYMBOL;
+ (*noise)->last = 0;
+ (*noise)->blk.next =(blk_t *) f_noise;
+
+ *rx_params = blk_alloc();
+ (*rx_params)->preamble_ntb = date;
+ (*rx_params)->tei = 1;
+ (*rx_params)->lid = 1;
+}
+void
+run_one_reassembly (sar_t *sar_ctx, uint pb_nb)
+{
+ pbproc_rx_params_t *rx_params;
+ pb_t *f, *l;
+ phy_chandata_t *noise;
+
+ emul_reassembly (pb_nb, 0x00, &rx_params, &f, &l, &noise);
+ sar_mpdu_add (sar_ctx, NULL, NULL, rx_params, f, l, pb_nb, (pb_t *) noise,
+ mpdu_measure_chandata_blk_nb[PHY_CHANDATA_TYPE_NRJ] +
+ mpdu_measure_chandata_blk_nb[PHY_CHANDATA_TYPE_NRJ_SYMBOL]
+ );
+ blk_release (rx_params); // pbproc can erase it.
+ sar_launch (sar_ctx);
+}
+
+void
+START (sar_t **sar_ctx, sta_t **sta, ca_t **ca)
+{
+ pbproc_t *pbproc_ctx = pbproc_init (&mac_config, mac_store_ctx);
+ *ca = (ca_t *) blk_alloc();
+ *sar_ctx = sar_init (mac_store_ctx, pbproc_ctx, *ca);
+ sar_init_measure_context (*sar_ctx, rxce_ctx);
+ sar_init_measurement_cb (*sar_ctx, &rxce_mpdu_measurement_add);
+ mac_store_sta_add (mac_store_ctx, 1);
+ *sta = mac_store_sta_get (mac_store_ctx, 1);
+}
+
+void
+END (sar_t *sar_ctx, sta_t *sta, ca_t *ca)
+{
+ //sar_trace_print (sar_ctx);
+ 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
+frame_process (cyg_addrword_t data)
+{
+
+ sar_t *sar_ctx;
+ sta_t *sta;
+ ca_t *ca;
+ int n;
+ int tmi_null;
+ int tmp_exists;
+
+ test_case_begin (test, "One sound frame");
+ START (&sar_ctx, &sta, &ca);
+ run_one_reassembly (sar_ctx, 0);
+ cyg_thread_delay (3); //rxce can process
+ test_begin (test, "check rxce status")
+ {
+ test_fail_if (sta->rx_tonemaps->default_tmi != TONEMAP_INDEX_INITIAL_START);
+ test_fail_if (!sta->rxce.tm_in_build);
+ } test_end;
+ END (sar_ctx, sta, ca);
+
+ test_case_begin (test, "One 1-PB frame");
+ START (&sar_ctx, &sta, &ca);
+ run_one_reassembly (sar_ctx, 1);
+ cyg_thread_delay (3); //rxce can process
+ test_begin (test, "check rxce status")
+ {
+ test_fail_if (sta->rx_tonemaps->default_tmi != TONEMAP_INDEX_INITIAL_START);
+ test_fail_if (!sta->rxce.tm_in_build);
+ } test_end;
+ END (sar_ctx, sta, ca);
+
+ test_case_begin (test, "One 200-PB frame");
+ START (&sar_ctx, &sta, &ca);
+ run_one_reassembly (sar_ctx, 200);
+ cyg_thread_delay (1); //rxce can process
+ test_begin (test, "check rxce status")
+ {
+ test_fail_if (sta->rx_tonemaps->default_tmi != TONEMAP_INDEX_INITIAL_START);
+ test_fail_if (!sta->rxce.tm_in_build);
+ } test_end;
+ END (sar_ctx, sta, ca);
+
+ test_case_begin (test, "Several sound frames processed one by one");
+ START (&sar_ctx, &sta, &ca);
+ test_begin (test, "check rxce status")
+ {
+ for (n=0; n<FRAME_NB_TO_COMPUTE_IN_INITIAL_STEP+10; n++)
+ {
+ run_one_reassembly (sar_ctx, 0);
+ cyg_thread_delay (3); //rxce can process
+ tmi_null = sta->rx_tonemaps->default_tmi == TONEMAP_INDEX_INITIAL_START;
+ tmp_exists = (int) sta->rxce.tm_in_build;
+ test_fail_if (n<FRAME_NB_TO_COMPUTE_IN_INITIAL_STEP && !tmi_null);
+ test_fail_if (n<FRAME_NB_TO_COMPUTE_IN_INITIAL_STEP && !tmp_exists);
+ test_fail_if (n>=FRAME_NB_TO_COMPUTE_IN_INITIAL_STEP && tmi_null);
+ test_fail_if (n==FRAME_NB_TO_COMPUTE_IN_INITIAL_STEP && tmp_exists);
+ test_fail_if (n>FRAME_NB_TO_COMPUTE_IN_INITIAL_STEP && !tmp_exists);
+ }
+ } test_end;
+ END (sar_ctx, sta, ca);
+
+ test_case_begin (test, "Several sound frames and rxce late");
+ START (&sar_ctx, &sta, &ca);
+ test_begin (test, "check rxce status")
+ {
+ for (n=0; n<FRAME_NB_TO_COMPUTE_IN_INITIAL_STEP+10; n++)
+ {
+ run_one_reassembly (sar_ctx, 0);
+ if (n == FRAME_NB_TO_COMPUTE_IN_INITIAL_STEP -5 )
+ {
+ cyg_thread_delay (3); //rxce can process
+ uint frame_nb = sta->rxce.measurement_computed_nb-1;
+ tmi_null = sta->rx_tonemaps->default_tmi == TONEMAP_INDEX_INITIAL_START;
+ tmp_exists = (int) sta->rxce.tm_in_build;
+ //my_print ("%d, tmi_null=%d, tmp_exists=%d\n",frame_nb, tmi_null, tmp_exists);
+ test_fail_if (frame_nb<FRAME_NB_TO_COMPUTE_IN_INITIAL_STEP && !tmi_null);
+ test_fail_if (frame_nb<FRAME_NB_TO_COMPUTE_IN_INITIAL_STEP && !tmp_exists);
+ test_fail_if (frame_nb>=FRAME_NB_TO_COMPUTE_IN_INITIAL_STEP && tmi_null);
+ test_fail_if (frame_nb==FRAME_NB_TO_COMPUTE_IN_INITIAL_STEP && tmp_exists);
+ test_fail_if (frame_nb>FRAME_NB_TO_COMPUTE_IN_INITIAL_STEP && !tmp_exists);
+ }
+ if (n == FRAME_NB_TO_COMPUTE_IN_INITIAL_STEP )
+ {
+ cyg_thread_delay (3); //rxce can process
+ uint frame_nb = sta->rxce.measurement_computed_nb-1;
+ tmi_null = sta->rx_tonemaps->default_tmi == TONEMAP_INDEX_INITIAL_START;
+ tmp_exists = (int) sta->rxce.tm_in_build;
+ //my_print ("%d, tmi_null=%d, tmp_exists=%d\n",frame_nb, tmi_null, tmp_exists);
+ test_fail_if (frame_nb<FRAME_NB_TO_COMPUTE_IN_INITIAL_STEP && !tmi_null);
+ test_fail_if (frame_nb<FRAME_NB_TO_COMPUTE_IN_INITIAL_STEP && !tmp_exists);
+ test_fail_if (frame_nb>=FRAME_NB_TO_COMPUTE_IN_INITIAL_STEP && tmi_null);
+ test_fail_if (frame_nb==FRAME_NB_TO_COMPUTE_IN_INITIAL_STEP && tmp_exists);
+ test_fail_if (frame_nb>FRAME_NB_TO_COMPUTE_IN_INITIAL_STEP && !tmp_exists);
+ }
+ if (n == FRAME_NB_TO_COMPUTE_IN_INITIAL_STEP + 5 -1 )
+ {
+ cyg_thread_delay (3); //rxce can process
+ uint frame_nb = sta->rxce.measurement_computed_nb-1;
+ tmi_null = sta->rx_tonemaps->default_tmi == TONEMAP_INDEX_INITIAL_START;
+ tmp_exists = (int) sta->rxce.tm_in_build;
+ //my_print ("%d, tmi_null=%d, tmp_exists=%d\n",frame_nb, tmi_null, tmp_exists);
+ test_fail_if (frame_nb<FRAME_NB_TO_COMPUTE_IN_INITIAL_STEP && !tmi_null);
+ test_fail_if (frame_nb<FRAME_NB_TO_COMPUTE_IN_INITIAL_STEP && !tmp_exists);
+ test_fail_if (frame_nb>=FRAME_NB_TO_COMPUTE_IN_INITIAL_STEP && tmi_null);
+ test_fail_if (frame_nb==FRAME_NB_TO_COMPUTE_IN_INITIAL_STEP && tmp_exists);
+ test_fail_if (frame_nb>FRAME_NB_TO_COMPUTE_IN_INITIAL_STEP && !tmp_exists);
+ }
+ cyg_thread_delay (3); //rxce can process
+ }
+ } test_end;
+ END (sar_ctx, sta, ca);
+
+ mac_store_uninit (mac_store_ctx);
+ rxce_trace_print (rxce_ctx);
+ rxce_trace_uninit (rxce_ctx);
+ trace_uninit();
+ blk_release (phy);
+ 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)
+ {
+ test_init (test, argc, argv);
+ trace_init();
+ phy = (phy_t *) blk_alloc();
+ mac_ntb_init (phy, &mac_config);
+
+ tonemask_default ((u8 *)(&(mac_config.tonemask_info.tonemask)));
+ mac_store_ctx = mac_store_init ();
+ sar_t *sar = blk_alloc();
+ rxce_ctx = rxce_init (sar, mac_store_ctx, &mac_config);
+ 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_resume (rxce_handle);
+ cyg_thread_create (FRAME_PRIORITY, &frame_process, 0, "frame_test",
+ frame_stack, CYGNUM_HAL_STACK_SIZE_TYPICAL,
+ &frame_handle, &frame_thread);
+ cyg_thread_resume (frame_handle);
+ blk_release (sar);
+
+}
+
+
diff --git a/cesar/ce/test/rx/general/target-Makefile b/cesar/ce/test/rx/general/target-Makefile
new file mode 100644
index 0000000000..96f9d8b9d4
--- /dev/null
+++ b/cesar/ce/test/rx/general/target-Makefile
@@ -0,0 +1,26 @@
+BASE = ../../../..
+
+INCLUDES = ce/test/rx/
+INCLUDES += ce/test/rx/general
+INCLUDES += ce/test/rx/general/overide
+INCLUDES += ce/test/common
+
+ECOS = y
+DEFS=-DSAR_UNIT_TEST=1
+
+TARGET_PROGRAMS=test_rx_target_ecos_synth
+test_rx_target_ecos_synth_SOURCES = test_rx.c
+test_rx_target_ecos_synth_MODULES = lib mac/common ce ce/test/common ce/test/rx/general/overide/cp/interf mac/sar mac/sar/test mac/pbproc mac/sar/bridgedma
+TARGET_PROGRAMS += test_sar_target_ecos_synth
+test_sar_target_ecos_synth_SOURCES = test_sar_integration.c
+test_sar_target_ecos_synth_MODULES = lib mac/sar ce mac/common mac/sar/bridgedma mac/pbproc mac/sar/test ce/test/common ce/test/rx/general/overide/cp/interf
+mac_pbproc_MODULE_SOURCES = mfs.c
+
+
+#ce_MODULE_SOURCES = bitloading.c cei_param.c mpdu_measure_store.c rx.c trace.c
+#ce_test_common_MODULE_SOURCES = print_utils.c
+
+VARIANT = target
+
+include $(BASE)/common/make/top.mk
+
diff --git a/cesar/ce/test/rx/general/target-ecos.ecc.sh b/cesar/ce/test/rx/general/target-ecos.ecc.sh
new file mode 100755
index 0000000000..2443d0e40f
--- /dev/null
+++ b/cesar/ce/test/rx/general/target-ecos.ecc.sh
@@ -0,0 +1,5 @@
+config=${1:-ecos-gen.ecc}
+ecosconfig --config=$config new linux default
+cat >> $config <<'EOF'
+EOF
+ecosconfig --config=$config check
diff --git a/cesar/ce/test/rx/host_linux_sparc/Makefile b/cesar/ce/test/rx/host_linux_sparc/Makefile
new file mode 100755
index 0000000000..7c653a0e09
--- /dev/null
+++ b/cesar/ce/test/rx/host_linux_sparc/Makefile
@@ -0,0 +1,17 @@
+BASE = ../../../..
+
+CC=sparc-linux-gcc
+INCLUDES=ce/test/rx
+INCLUDES+=ce/test/rx/host_linux_sparc
+
+EXTRA_HOST_CFLAGS=-O3
+EXTRA_HOST_LDFLAGS=-lm
+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 mpdu_measure_store.c bitloading.c
+ce_test_common_MODULE_SOURCES = print_utils.c
+
+include $(BASE)/common/make/top.mk
+
diff --git a/cesar/ce/test/rx/host_linux_sparc/src/test_speed.c b/cesar/ce/test/rx/host_linux_sparc/src/test_speed.c
new file mode 100644
index 0000000000..a469d1e557
--- /dev/null
+++ b/cesar/ce/test/rx/host_linux_sparc/src/test_speed.c
@@ -0,0 +1,152 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file ./src/test_speed.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+
+#include "common/std.h"
+#include "sys/time.h"
+#include "stdio.h"
+#include "string.h"
+#include "ce/inc/mpdu_measure_store.h"
+#include "mac/common/tonemap.h"
+#include "ce/test/common/print_utils.h"
+#include "lib/bitstream.h"
+#define RXCE
+#include "ce/inc/cei.h"
+#include "math.h"
+
+
+int
+main (int argc, char **argv)
+{
+ struct timeval tv0, tv1;
+ uint word = 0x76543210;
+ uint i, test;
+ int nibble;
+ bitstream_t stream_writer;
+ gettimeofday (&tv0, NULL);
+ gettimeofday (&tv1, NULL);
+ printf ("getitmeofday duration %d\n",(int) (tv1.tv_usec - tv0.tv_usec));
+ gettimeofday (&tv0, NULL);
+ for (test=0; test<1000; test++)
+ {
+ word = 0;
+ for (i=0; i<8; i++)
+ {
+ nibble = i+1;
+ word = (word >> 4) | (nibble << 28);
+ }
+ }
+ gettimeofday (&tv1, NULL);
+ printf ("nibble to u32 duration test1 %d /1000\n",(int) (tv1.tv_usec - tv0.tv_usec));
+
+ gettimeofday (&tv0, NULL);
+ for (test=0; test<1000; test++)
+ {
+ word = 0;
+ for (i=0; i<8; i++)
+ {
+ nibble = i+1;
+ word = word | (nibble << (i<<2));
+ }
+ }
+ gettimeofday (&tv1, NULL);
+ printf ("nibble to u32 duration test2 %d /1000\n",(int) (tv1.tv_usec - tv0.tv_usec));
+
+ frame_measurement_init ();
+
+ uint noise = 0;
+ gettimeofday (&tv0, NULL);
+ update_threshold (1, 1);
+ for (i=0; i<1536; i++)
+ {
+ noise2mod (noise);
+ }
+ gettimeofday (&tv1, NULL);
+ printf ("noise2mod duration --worst : %d\n",(int) (tv1.tv_usec - tv0.tv_usec));
+
+ noise = 10000;
+ gettimeofday (&tv0, NULL);
+ update_threshold (1, 1);
+ for (i=0; i<1536; i++)
+ {
+ noise2mod (noise);
+ }
+ gettimeofday (&tv1, NULL);
+ printf ("noise2mod duration --best : %d\n",(int) (tv1.tv_usec - tv0.tv_usec));
+
+
+ gettimeofday (&tv0, NULL);
+ blk_t *blk = blk_alloc_desc ();
+ gettimeofday (&tv1, NULL);
+ printf ("first blk allocation duration : %d\n",(int) (tv1.tv_usec - tv0.tv_usec));
+ blk_release_desc (blk);
+ gettimeofday (&tv0, NULL);
+ blk = blk_alloc_desc ();
+ gettimeofday (&tv1, NULL);
+ printf ("second blk allocation duration : %d\n",(int) (tv1.tv_usec - tv0.tv_usec));
+ blk_release_desc (blk);
+
+ blk_t *blk_last;
+ gettimeofday (&tv0, NULL);
+ blk_t *blk_first = blk_alloc_desc_range (10, &blk_last);
+ gettimeofday (&tv1, NULL);
+ printf ("multi-blk allocation duration (10) : %d\n",(int) (tv1.tv_usec - tv0.tv_usec));
+ blk_release_desc_range (blk_first, blk_last);
+
+
+ phy_chandata_t *last, *browser;
+ phy_chandata_t *first = (phy_chandata_t *) blk_alloc_desc_range (PHY_CHANDATA_NRJ_BLK_NB, (blk_t **) &last);
+ last->last = 1;
+ last->blk.next = NULL;
+ browser = first;
+ noise = 0;
+ int j, k=0;
+ u32 * data = (u32 * ) browser->blk.data;
+ for (i=0; i<PHY_CHANDATA_NRJ_BLK_NB; i++)
+ {
+ for (j=0; j<BLK_SIZE/4; j++)
+ {
+ data[j] = (THR3[1][k%7]) | ((THR3[1][(k+1)%7])<<16);
+ k+=2;
+ }
+ browser = (phy_chandata_t *) (browser->blk.next);
+ if (browser) data = (u32 * ) browser->blk.data;
+ }
+ tonemap_t *worst_tonemap = NULL;
+ gettimeofday (&tv0, NULL);
+ compute_worst_tonemap (&worst_tonemap, first);
+ gettimeofday (&tv1, NULL);
+ printf ("default tonemap computation duration : %d\n",(int) (tv1.tv_usec - tv0.tv_usec));
+ ce_print_tonemap (worst_tonemap);
+ blk_release_desc_range ((blk_t *) first, (blk_t *)last);
+
+ u8 buf[1536];
+ for (i=0; i<1536; i++) buf[i] = 0x00;
+ u8 mask[(PHY_CARRIER_NB+7)/8];
+ for (i=0; i<(PHY_CARRIER_NB+7)/8; i++) mask[i] = 0xFF;
+ mask[i-1] = ((1<<(PHY_CARRIER_NB%8))-1);
+ uint entry_nb;
+ gettimeofday (&tv0, NULL);
+ for (test=0; test<100; test++)
+ {
+ bitstream_init (&stream_writer, buf, 1518, BITSTREAM_WRITE);
+ entry_nb = cei_encode_tm (&stream_writer, worst_tonemap->tmdma_desc_head, mask);
+ }
+ gettimeofday (&tv1, NULL);
+ printf ("cei building duration : %d\n",(int) (tv1.tv_usec - tv0.tv_usec));
+
+ tonemap_free (worst_tonemap);
+ return 0;
+}
+
diff --git a/cesar/ce/test/rx/inc/test_rx.h b/cesar/ce/test/rx/inc/test_rx.h
new file mode 100755
index 0000000000..dc8ee6f637
--- /dev/null
+++ b/cesar/ce/test/rx/inc/test_rx.h
@@ -0,0 +1,37 @@
+#ifndef __test_rx_h
+#define __test_rx_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file ./test_rx.h
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+
+BEGIN_DECLS
+
+typedef void (*pbproc_need_scf_cb_t) (uint tei, uint src);
+pbproc_need_scf_cb_t need_scf_cb;
+
+void
+pbproc_rxce_init (pbproc_need_scf_cb_t need_scf);
+
+void
+pbproc_scf (void);
+
+void
+over_pbproc_init(void);
+
+bool
+pbproc_send_scf (void);
+
+END_DECLS
+
+#endif /* __test_rx_h */
diff --git a/cesar/ce/test/rx/maximus/Makefile b/cesar/ce/test/rx/maximus/Makefile
new file mode 100644
index 0000000000..ba5c632834
--- /dev/null
+++ b/cesar/ce/test/rx/maximus/Makefile
@@ -0,0 +1,21 @@
+all :
+ $(MAKE) -C ../../../../maximus/python --no-print-directory
+
+BASE = ../../../..
+INCLUDES = ce/test/rx/maximus/overide
+INCLUDES += ce/test/rx/maximus
+INCLUDES += ce/test/rx/general/overide
+INCLUDES += ce/test/common
+ECOS = y
+DEFS=-DSAR_UNIT_TEST=1
+
+EXTRA_TARGET_CFLAGS=-DMAXIMUS_TEST -DRXCE_WITH_SAR
+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 mpdu_measure_store.c rx.c trace.c bitloading.c
+
+
+include $(BASE)/common/make/top.mk
+
diff --git a/cesar/ce/test/rx/maximus/ecos.ecc.sh b/cesar/ce/test/rx/maximus/ecos.ecc.sh
new file mode 100644
index 0000000000..19597e4621
--- /dev/null
+++ b/cesar/ce/test/rx/maximus/ecos.ecc.sh
@@ -0,0 +1,104 @@
+config=${1:-ecos-gen.ecc}
+ecosconfig --config=$config new maximus default
+cat >> $config <<'EOF'
+cdl_option CYGPKG_HAL_MAXIMUS_CFLAGS_ADD {
+ user_value "-I\$(BASE) -I\$(OBJ_DIR)/inc"
+ # value_source user
+ # Default value: "-I\$(REPOSITORY)/../.."
+}
+cdl_option CYGBLD_GLOBAL_CFLAGS {
+ user_value "-Wall -Wpointer-arith -Wstrict-prototypes -Winline -Wundef -Woverloaded-virtual -g -ffunction-sections -fdata-sections -fno-rtti -fno-exceptions -fvtable-gc -finit-priority -finline"
+ # value_source user
+ # Default value: "-Wall -Wpointer-arith -Wstrict-prototypes -Winline -Wundef -Woverloaded-virtual -g -O2 -ffunction-sections -fdata-sections -fno-rtti -fno-exceptions -fvtable-gc -finit-priority"
+}
+cdl_option CYGDBG_KERNEL_DEBUG_GDB_THREAD_SUPPORT {
+ user_value 0
+ inferred_value 0
+}
+cdl_option CYGBLD_ISO_CTYPE_HEADER {
+ inferred_value 1 <cyg/libc/i18n/ctype.inl>
+}
+cdl_option CYGBLD_ISO_ERRNO_CODES_HEADER {
+ inferred_value 1 <cyg/error/codes.h>
+}
+cdl_option CYGBLD_ISO_ERRNO_HEADER {
+ inferred_value 1 <cyg/error/errno.h>
+}
+cdl_option CYGBLD_ISO_STDIO_FILETYPES_HEADER {
+ inferred_value 1 <cyg/libc/stdio/stdio.h>
+}
+cdl_option CYGBLD_ISO_STDIO_STREAMS_HEADER {
+ inferred_value 1 <cyg/libc/stdio/stdio.h>
+}
+cdl_option CYGBLD_ISO_STDIO_FILEOPS_HEADER {
+ inferred_value 1 <cyg/libc/stdio/stdio.h>
+}
+cdl_option CYGBLD_ISO_STDIO_FILEACCESS_HEADER {
+ inferred_value 1 <cyg/libc/stdio/stdio.h>
+}
+cdl_option CYGBLD_ISO_STDIO_FORMATTED_IO_HEADER {
+ inferred_value 1 <cyg/libc/stdio/stdio.h>
+}
+cdl_option CYGBLD_ISO_STDIO_CHAR_IO_HEADER {
+ inferred_value 1 <cyg/libc/stdio/stdio.h>
+}
+cdl_option CYGBLD_ISO_STDIO_DIRECT_IO_HEADER {
+ inferred_value 1 <cyg/libc/stdio/stdio.h>
+}
+cdl_option CYGBLD_ISO_STDIO_FILEPOS_HEADER {
+ inferred_value 1 <cyg/libc/stdio/stdio.h>
+}
+cdl_option CYGBLD_ISO_STDIO_ERROR_HEADER {
+ inferred_value 1 <cyg/libc/stdio/stdio.h>
+}
+cdl_option CYGBLD_ISO_STDLIB_STRCONV_HEADER {
+ inferred_value 1 <cyg/libc/stdlib/atox.inl>
+}
+cdl_option CYGBLD_ISO_STDLIB_ABS_HEADER {
+ inferred_value 1 <cyg/libc/stdlib/abs.inl>
+}
+cdl_option CYGBLD_ISO_STDLIB_DIV_HEADER {
+ inferred_value 1 <cyg/libc/stdlib/div.inl>
+}
+cdl_option CYGBLD_ISO_STRERROR_HEADER {
+ inferred_value 1 <cyg/error/strerror.h>
+}
+cdl_option CYGBLD_ISO_STRTOK_R_HEADER {
+ inferred_value 1 <cyg/libc/string/string.h>
+}
+cdl_option CYGBLD_ISO_STRING_LOCALE_FUNCS_HEADER {
+ inferred_value 1 <cyg/libc/string/string.h>
+}
+cdl_option CYGBLD_ISO_STRING_BSD_FUNCS_HEADER {
+ inferred_value 1 <cyg/libc/string/bsdstring.h>
+}
+cdl_option CYGBLD_ISO_STRING_MEMFUNCS_HEADER {
+ inferred_value 1 <cyg/libc/string/string.h>
+}
+cdl_option CYGBLD_ISO_STRING_STRFUNCS_HEADER {
+ inferred_value 1 <cyg/libc/string/string.h>
+}
+cdl_option CYGBLD_ISO_C_TIME_TYPES_HEADER {
+ inferred_value 1 <cyg/libc/time/time.h>
+}
+cdl_option CYGBLD_ISO_C_CLOCK_FUNCS_HEADER {
+ inferred_value 1 <cyg/libc/time/time.h>
+}
+cdl_option CYGBLD_ISO_SIGNAL_NUMBERS_HEADER {
+ inferred_value 1 <cyg/libc/signals/signal.h>
+}
+cdl_option CYGBLD_ISO_SIGNAL_IMPL_HEADER {
+ inferred_value 1 <cyg/libc/signals/signal.h>
+}
+cdl_option CYGBLD_ISO_SETJMP_HEADER {
+ inferred_value 1 <cyg/libc/setjmp/setjmp.h>
+}
+cdl_option CYGNUM_LIBC_MAIN_DEFAULT_STACK_SIZE {
+ user_value 16384
+ inferred_value 16384
+}
+cdl_option CYGSEM_ERROR_PER_THREAD_ERRNO {
+ user_value 0
+}
+EOF
+ecosconfig --config=$config check
diff --git a/cesar/ce/test/rx/maximus/overide/mac/pbproc/Module b/cesar/ce/test/rx/maximus/overide/mac/pbproc/Module
new file mode 100644
index 0000000000..e9f0167e68
--- /dev/null
+++ b/cesar/ce/test/rx/maximus/overide/mac/pbproc/Module
@@ -0,0 +1 @@
+SOURCES := pbproc.c
diff --git a/cesar/ce/test/rx/maximus/overide/mac/pbproc/pbproc.h b/cesar/ce/test/rx/maximus/overide/mac/pbproc/pbproc.h
new file mode 100644
index 0000000000..57d28489fa
--- /dev/null
+++ b/cesar/ce/test/rx/maximus/overide/mac/pbproc/pbproc.h
@@ -0,0 +1,145 @@
+#ifndef overide_pbproc_h
+#define overide_pbproc_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file overide/pbproc.h
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+#include "host/station.h"
+#include "hal/phy/maximus/inc/maximus_phy_ctx.h" // 'phy_t'
+#include "mac/common/mfs.h"
+#include "mac/common/pb.h"
+#include "mac/ca/ca.h"
+
+
+struct pbproc_rx_params_t
+{
+ /** Preamble start NTB. */
+ u32 preamble_ntb;
+ /** TEI of the transmitter. */
+ u8 tei;
+ /** Link ID of this MPDU. */
+ u8 lid;
+ /** Short network identifier. */
+ uint snid:4;
+ /** Whether this is a multicast frame. */
+ bool bcast:1;
+ /** Multi-network broadcast flag. */
+ bool multi_net_bcast:1;
+ /** Network encryption key select. */
+ uint eks:4;
+ /** Pending PB. */
+ uint pending_seg_nb:8;
+ /** Bit loading estimate. */
+ uint ble:8;
+ /** Tone map index. */
+ uint tmi_av:5;
+ /** Beacon detect flag. */
+ bool bdf:1;
+ /** Homeplug 1.0.1 detect flag. */
+ bool hp10df:1;
+ /** Homeplug 1.1 detect flag. */
+ bool hp11df:1;
+};
+typedef struct pbproc_rx_params_t pbproc_rx_params_t;
+
+typedef void (*pbproc_rx_cb_t) (void *user, mfs_t *mfs, mfs_t *mfs_mme,
+ const pbproc_rx_params_t *rx_params,
+ pb_t *pb_first, pb_t *pb_last,
+ uint pb_nb, pb_t *chandata_first, uint chandata_nb);
+
+struct pbproc_t
+{
+ pbproc_rx_cb_t rx_cb;
+ mac_config_t *config;
+};
+typedef struct pbproc_t pbproc_t;
+
+struct pbproc_rx_beacon_params_t
+{
+ /** Preamble start NTB. */
+ u32 preamble_ntb;
+ /** Beacon Time Stamp. */
+ u32 bts;
+ /** Beacon Transmission Offset. */
+ u16 bto[4];
+ /** Short network identifier. */
+ u8 snid;
+};
+typedef struct pbproc_rx_beacon_params_t pbproc_rx_beacon_params_t;
+
+typedef void (*pbproc_rx_beacon_cb_t) (void *user, pb_beacon_t *pb,
+ pbproc_rx_beacon_params_t *params);
+
+typedef struct pbproc_tx_beacon_params_t pbproc_tx_beacon_params_t;
+
+BEGIN_DECLS
+
+bool phy_rx_fc_cb (void *user, u32 rx_date, const u32 *fc_av);
+
+bool phy_access_cb (void *user);
+
+bool phy_access_conf_cb (void *user);
+
+bool phy_pbdma_cb (void *user, u32 status_word);
+
+void phy_deferred_cb (void *user);
+
+bool phy_extra_timer_cb (void *user);
+
+int set_tonemask (fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void *data);
+
+int prepare_rx (fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void *data);
+
+pbproc_t *
+pbproc_init (mac_config_t *config, mac_store_t *store);
+
+void
+pbproc_init_cb (pbproc_t *ctx, void *user_data, pbproc_rx_cb_t rx_cb, pbproc_rx_beacon_cb_t rx_beacon_cb);
+
+void
+pbproc_uninit (pbproc_t *ctx);
+
+void
+pbproc_rx_segment_refill (pbproc_t *ctx, pb_t *first, pb_t *last,
+ uint nb);
+
+pb_t *
+pbproc_mfs_extract_tail (mfs_tx_t *mfs);
+
+void
+pbproc_mfs_insert (mfs_tx_t *mfs, pb_t *first, pb_t *last, uint nb, uint cap);
+
+void
+pbproc_mfs_provide (mfs_tx_t *mfs, uint nb);
+
+/** set SCF in pbproc ctx */
+void
+pbproc_scf (void);
+
+void
+pbproc_set_config (mac_config_t *config);
+
+
+bool
+ca_mfs_remove (ca_t *ctx, mfs_tx_t *mfs);
+
+void
+ca_mfs_update (ca_t *ctx, mfs_tx_t *mfs);
+
+void
+pbproc_mfs_beacon_prepare (pbproc_t *ctx, mfs_tx_t *mfs, pb_beacon_t *pb,
+ const pbproc_tx_beacon_params_t *params);
+
+END_DECLS
+
+#endif /* overide_pbproc_h */
diff --git a/cesar/ce/test/rx/maximus/overide/mac/pbproc/src/pbproc.c b/cesar/ce/test/rx/maximus/overide/mac/pbproc/src/pbproc.c
new file mode 100644
index 0000000000..3801433efa
--- /dev/null
+++ b/cesar/ce/test/rx/maximus/overide/mac/pbproc/src/pbproc.c
@@ -0,0 +1,261 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file ./overide/src/pbproc.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+#include <cyg/infra/diag.h>
+#include "common/std.h"
+#include "mac/pbproc/pbproc.h"
+#include "mac/common/tonemask.h"
+#include "hal/phy/maximus/dur/inc/maximus_dur.h"
+#include "ce/test/common/print_utils.h"
+#include "mac/common/ntb.h"
+
+phy_t * phy_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;
+//u8 tonemask[(PHY_CARRIER_NB+7)/8];
+
+static pbproc_t pbproc_global;
+phy_chandata_t *rx_chandata_first;
+phy_pb_t *rx_pb_first;
+phy_pb_t *rx_pb_last;
+uint rx_pb_nb;
+pbproc_rx_params_t rx_params;
+void *sar_ctx;
+uint rx_symbol_nb;
+uint rx_chandata_nb;
+
+bool phy_rx_fc_cb (void *user, u32 rx_date, const u32 *fc_av)
+{
+ // When the FC is received, prepare RX
+ rx_symbol_nb = maximus_dur_symbol_nb ((phy_fecrate_t) fecrate,
+ (phy_pb_size_t) pb_size,
+ maximus_dur_bits_per_symbol ( (phy_mod_t) mod,
+ pbproc_global.config->tonemask_info.tonemask,
+ NULL,
+ maximus_dur_carrier_nb (pbproc_global.config->tonemask_info.tonemask)
+ ),
+ rx_pb_nb
+ );
+
+
+ ce_print ("phy_rx_fc_cb ******* symbol NB = %d\n",rx_symbol_nb);
+ phy_rx_prepare(phy_ctx, short_ppdu, (phy_mod_t)mod,
+ (phy_fecrate_t)fecrate, (phy_pb_size_t)pb_size, (phy_gil_t)gil,
+ 0 /* tonemap_index */, rx_symbol_nb);
+
+ 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)
+{
+ ce_print ("phy_pbdma_cb ******* PB NB = %d\n",rx_pb_nb);
+ phy_pbdma_status_t status = *(phy_pbdma_status_t *)&status_word;
+ rx_params.tei = 1;
+ rx_params.lid = 0;
+ if (1 == status.end_chandata)
+ {
+ pbproc_global.rx_cb (sar_ctx, NULL, NULL, &rx_params, (pb_t *) rx_pb_first,(pb_t *) rx_pb_last, rx_pb_nb,(pb_t *) rx_chandata_first, rx_chandata_nb);
+ }
+ 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 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;
+ u32 iv[3];
+ u32 nek[4];
+
+ phy_pb_t *pb_last;
+ phy_pb_t *pb_first;
+
+ ce_print("=> 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);
+ 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);
+
+ dbg_assert (pb_nb);
+ pb_first = (phy_pb_t *) blk_alloc_desc_range (pb_nb, (blk_t **) &pb_last);
+ pb_last->blk.next = NULL;
+
+ // Activate RX
+ phy_rx_activate(phy_ctx, true /* now */, my_station.current_tick_tck, true /* pre_detection */);
+
+ // Set RX parameters
+ phy_rx_param(phy_ctx, (phy_fc_mode_t)fc_mode);
+
+ for (i=0; i<3; i++)
+ {
+ iv[i] = i;
+ }
+ for (i=0; i<4; i++)
+ {
+ nek[i] = i;
+ }
+ phy_pbdma_start(phy_ctx, true /* bypass_aes */, iv,
+ nek, (uint)pb_nb /* nb_total */, (uint)pb_nb /* nb_ready */,
+ (uint)pb_nb /* nb_pb_it */, pb_first);
+
+ phy_chandata_t *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;
+ time_noise->size = (pb_nb * sizeof(phy_noise_energy_t)+ 3)/4;
+
+ phy_chandata_t *last_chan;
+ phy_chandata_t *freq_noise = (phy_chandata_t *) blk_alloc_desc_range(mpdu_measure_chandata_blk_nb[PHY_CHANDATA_TYPE_NRJ], (blk_t **) &last_chan);
+ last_chan->blk.next = NULL;
+ last_chan->last = 1;
+ last_chan->type = PHY_CHANDATA_TYPE_NRJ;
+ last_chan->size = ((PHY_CARRIER_NB*sizeof(phy_noise_energy_t) % PHY_NOISE_NB_PER_BLK) + 3)/4;
+ phy_chandata_t *browser = freq_noise;
+ uint address=0;
+ while (browser != last_chan)
+ {
+ browser->last = 0;
+ browser->type = PHY_CHANDATA_TYPE_NRJ;
+ browser->size = 128;
+ browser->address = address;
+ browser = (phy_chandata_t *)browser->blk.next;
+ address+= 128;
+ }
+ last_chan->address = address;
+
+
+
+ /** registering reception status to be able to run pbproc_rx_cb that wake
+ * up the sar */
+ rx_pb_first = pb_first;
+ rx_pb_last = pb_last;
+ //rx_chandata_first = freq_noise;
+ //last_chan->blk.next = time_noise;
+ rx_chandata_first = time_noise;
+ time_noise->blk.next = (blk_t *) freq_noise;
+ rx_pb_nb = pb_nb;
+
+ ce_print_chandata (time_noise);
+ rx_chandata_nb = 6;
+
+ phy_pbdma_start_chandata(phy_ctx, time_noise);
+ //phy_pbdma_start_chandata(ctx, freq_noise);
+
+ /* now make the return parameter list */
+ fcall_param_reset(*param);
+
+ return 0;
+}
+
+pbproc_t *
+pbproc_init (mac_config_t *config, mac_store_t *store)
+{
+ pbproc_t *pbproc_ctx = &pbproc_global;
+ pbproc_ctx->config = config;
+ // Initialize the HAL PHY
+ 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);
+ mac_ntb_init (phy_ctx, config);
+
+ // Enable assertions on warnings
+ phy_ctx->warning_assert = true;
+
+ // Set TONEMASK
+ phy_set_tonemask(phy_ctx, config->tonemask_info.tonemask, PHY_CARRIER_NB);
+ return(pbproc_ctx);
+}
+
+void
+pbproc_init_cb (pbproc_t *ctx, void *user_data, pbproc_rx_cb_t rx_cb, pbproc_rx_beacon_cb_t rx_beacon_cb)
+{
+ dbg_assert (ctx);
+ dbg_assert (rx_cb);
+ dbg_assert (rx_beacon_cb);
+ //ctx->user_data = user_data;
+ ctx->rx_cb = rx_cb;
+ //ctx->rx_beacon_cb = rx_beacon_cb;
+}
+
+void
+pbproc_rx_segment_refill (pbproc_t *ctx, pb_t *f, pb_t *l, uint nb)
+{
+ return;
+}
+
+pb_t *
+pbproc_mfs_extract_tail (mfs_tx_t *mfs) {return NULL;}
+
+void
+pbproc_mfs_insert (mfs_tx_t *mfs, pb_t *first, pb_t *last, uint nb, uint cap) {return;}
+
+void
+pbproc_mfs_provide (mfs_tx_t *mfs, uint nb) {return;}
+
+void
+pbproc_scf (void)
+{
+ return;
+}
+
+bool
+ca_mfs_remove (ca_t *ctx, mfs_tx_t *mfs)
+{
+ return true;
+}
+
+void
+ca_mfs_update (ca_t *ctx, mfs_tx_t *mfs)
+{
+
+}
+
+void
+pbproc_mfs_beacon_prepare (pbproc_t *ctx, mfs_tx_t *mfs, pb_beacon_t *pb,
+ const pbproc_tx_beacon_params_t *params)
+{
+ return;
+}
diff --git a/cesar/ce/test/rx/maximus/send_noise.py b/cesar/ce/test/rx/maximus/send_noise.py
new file mode 100644
index 0000000000..7c8666ce56
--- /dev/null
+++ b/cesar/ce/test/rx/maximus/send_noise.py
@@ -0,0 +1,102 @@
+#!/usr/bin/python
+
+#print __name__
+
+import sys
+
+maximus_path = '../../../../maximus'
+pos_maximus_path = -1
+for i in range(len(sys.argv)):
+ if sys.argv[i] == '--maximus_path':
+ pos_maximus_path = i
+ maximus_path = sys.argv[i+1]
+if pos_maximus_path > 0:
+ sys.argv = sys.argv[0:pos_maximus_path] + sys.argv[pos_maximus_path+2:len(sys.argv)]
+sys.path.append (maximus_path+'/python')
+sys.path.append (maximus_path+'/python/obj')
+
+from interface import *
+from maximus.macframe import *
+from maximus.macframe.msdu import MAX_SIZE_OF_MSDU
+from struct import *
+
+# Create and initializes Maximus
+maximus = Maximus()
+maximus.init(sys.argv)
+
+# Create a station
+sta = maximus.create_sta ()
+sta.debug()
+maximus.disturb_channel()
+
+pb_nb = 200
+frame_nb = 22
+
+ce_init_fcall = maximus.create_fcall ('ce_init')
+ce_init_fcall.send(sta)
+sar_start_fcall = maximus.create_fcall ('sar_start')
+sar_start_fcall.send(sta)
+
+ce_check_stock_fcall = maximus.create_fcall ('ce_check_stock')
+ce_check_stock_fcall.add_param_ushort ('frame_nb', frame_nb);
+ce_check_stock_fcall.add_param_ushort ('pb_nb', pb_nb);
+ce_start_fcall = maximus.create_fcall ('ce_start')
+ce_check_computation_fcall = maximus.create_fcall ('ce_check_computation')
+
+
+def prepare_rx_param_init():
+ prepare_rx_fcall = maximus.create_fcall('prepare_rx')
+ fc_mode = 2 # PHY_FC_MODE_AV_1
+ prepare_rx_fcall.add_param_ushort("fc_mode", fc_mode)
+ prepare_rx_fcall.add_param_bool("short_ppdu", False)
+ mod = 0 # PHY_MOD_ROBO
+ prepare_rx_fcall.add_param_ushort("mod", mod)
+ fecrate = 0 # PHY_FEC_RATE_1_2
+ prepare_rx_fcall.add_param_ushort("fecrate", fecrate)
+ pb_size = 1
+ prepare_rx_fcall.add_param_ushort("pb_size", pb_size)
+ gil = 1 # PHY_GIL_567
+ prepare_rx_fcall.add_param_ushort("gil", gil)
+ #pb_nb = 1
+ prepare_rx_fcall.add_param_ushort("pb_nb", pb_nb)
+ #prepare_rx_fcall.send(sta)
+ return prepare_rx_fcall
+
+test_result_fcall = maximus.create_fcall('test_result_get')
+
+queue = MACFrameQueue()
+queue.set_fc_av(pack('IIII', 0, 456, 789, 10))
+payload = 512*'X'+(pb_nb-1)*512*'Y'
+macframe_nb = (len(payload) + (MAX_SIZE_OF_MSDU-1)) / MAX_SIZE_OF_MSDU
+payload = payload[macframe_nb*6:]
+
+def create_msdu():
+ msdu = MACFrame()
+ msdu.set_macframeheader ('MF')
+ msdu.set_icv ('CRC0')
+ return msdu
+
+def send_queue():
+ for i in range (macframe_nb):
+ macFrame = create_msdu()
+ macFrame.set_msdu(payload[i*MAX_SIZE_OF_MSDU:min((i+1)*MAX_SIZE_OF_MSDU, len(payload))])
+ queue.add(macFrame)
+ queue.send(maximus)
+
+for i in range(frame_nb) :
+ prepare_rx_param_init().send(sta)
+ send_queue()
+
+ce_check_stock_fcall.send(sta)
+ce_start_fcall.send(sta)
+ce_check_computation_fcall.send(sta)
+
+maximus.wait(10000000)
+
+res = test_result_fcall.send(sta)
+result = res.bind_param_ushort ("test_result")
+#print "test has returned ", hex(result)
+sta.remove()
+
+sys.exit(result)
+
diff --git a/cesar/ce/test/rx/maximus/src/test_rx.c b/cesar/ce/test/rx/maximus/src/test_rx.c
new file mode 100644
index 0000000000..06ab584c51
--- /dev/null
+++ b/cesar/ce/test/rx/maximus/src/test_rx.c
@@ -0,0 +1,187 @@
+#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"
+#include "lib/trace.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_ERROR);
+ 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;
+}
+
diff --git a/cesar/ce/test/rx/tonemap_refresh/Makefile b/cesar/ce/test/rx/tonemap_refresh/Makefile
new file mode 100644
index 0000000000..e0fe57d3b4
--- /dev/null
+++ b/cesar/ce/test/rx/tonemap_refresh/Makefile
@@ -0,0 +1,18 @@
+BASE = ../../../..
+
+INCLUDES = ce/test/rx
+INCLUDES += ce/test/rx/tonemap_refresh
+INCLUDES += ce/test/rx/general/overide
+INCLUDES += ce/test/common
+
+ECOS = y
+
+EXTRA_TARGET_CFLAGS=-DEXPIRATION_TEST
+TARGET_PROGRAMS=test_tonemaps_refresh_target_ecos_synth
+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
+
+
+
+include $(BASE)/common/make/top.mk
+
diff --git a/cesar/ce/test/rx/tonemap_refresh/ecos.ecc.sh b/cesar/ce/test/rx/tonemap_refresh/ecos.ecc.sh
new file mode 100755
index 0000000000..2443d0e40f
--- /dev/null
+++ b/cesar/ce/test/rx/tonemap_refresh/ecos.ecc.sh
@@ -0,0 +1,5 @@
+config=${1:-ecos-gen.ecc}
+ecosconfig --config=$config new linux default
+cat >> $config <<'EOF'
+EOF
+ecosconfig --config=$config check
diff --git a/cesar/ce/test/rx/tonemap_refresh/src/test_tonemaps_refresh.c b/cesar/ce/test/rx/tonemap_refresh/src/test_tonemaps_refresh.c
new file mode 100644
index 0000000000..d6a7e2d296
--- /dev/null
+++ b/cesar/ce/test/rx/tonemap_refresh/src/test_tonemaps_refresh.c
@@ -0,0 +1,117 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file ./src/test_tonemaps_expiration.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+#include "common/std.h"
+#include "lib/rnd.h"
+#include "lib/test.h"
+#include "ce/inc/rx.h"
+#include "ce/test/common/print_utils.h"
+#include "ce/inc/ecos_time.h"
+
+#define TEST_REFRESH_NUMBER 5000
+#define CPU_LOAD_PRIORITY 10
+cyg_thread cpu_load_thread;
+cyg_handle_t cpu_load_handle;
+unsigned char cpu_load_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];
+
+test_t test;
+mac_store_t *mac_store_ctx;
+mac_config_t mac_config;
+rxce_t *rxce_ctx;
+lib_rnd_t rnd;
+bool stop = false;
+int refresh_number = 0;
+cyg_tick_count_t date[255];
+
+// Just for commpilation. Not used.
+void
+pbproc_scf (void)
+{;}
+
+void
+test_expiration_cb (int dtei)
+{
+ cyg_tick_count_t current = cyg_current_time ();
+ sta_t *lsta = mac_store_sta_get (mac_store_ctx, dtei);
+ test_begin (test, "Check date of cei creation\n")
+ {
+ test_fail_if (current > date[dtei] + S_TO_RTC (TONEMAPS_LIFE_DURATION_S));
+ } test_end;
+ blk_release (lsta);
+ date[dtei] = current;
+ if (refresh_number > TEST_REFRESH_NUMBER ) stop = true;
+ else refresh_number++;
+ if (refresh_number % 100 == 0) test_result(test);
+}
+
+void
+cpu_load_process (cyg_addrword_t data)
+{
+ int i;
+ int r;
+ while (!stop)
+ {
+ double z;
+ r = lib_rnd_uniform (&rnd, 2000000);
+ for (i=0; i< r; i++)
+ {
+ z = (i*1.0)/r;
+ }
+ cyg_thread_delay(1);
+ }
+ test_result (test);
+ HAL_PLATFORM_EXIT (test_nb_failed (test) == 0 ? 0 : 1);
+}
+
+void
+cyg_user_start (int argc, char **argv)
+{
+ int i;
+ test_init (test, argc, argv);
+ test_case_begin (test, "Expiration");
+ trace_init();
+ lib_rnd_init (&rnd, 123);
+ mac_store_ctx = mac_store_init ();
+ rxce_ctx = rxce_init (NULL, mac_store_ctx, &mac_config);
+ rxce_init_test_cb (&test_expiration_cb);
+ for (i=1; i<= 250; i++)
+ {
+ int b = mac_store_get_free_tei (mac_store_ctx);
+ if (b != -1 )
+ {
+ mac_store_sta_add (mac_store_ctx, b);
+ sta_t *lsta = mac_store_sta_get (mac_store_ctx, b);
+ tonemaps_t *tms = tonemaps_alloc();
+ lsta->rx_tonemaps = tms;
+ int random = lib_rnd_uniform (&rnd, 5000);
+ date[i] = cyg_current_time() + random;
+ tms->expiration_rtc_date = date[i] + S_TO_RTC (RXCE_TONEMAPS_REFRESH_PERIOD_S);
+ blk_release (lsta);
+ }
+ }
+ 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_resume (rxce_handle);
+
+ cyg_thread_create (CPU_LOAD_PRIORITY, &cpu_load_process,(cyg_addrword_t) 0, "cpu_load",
+ cpu_load_stack, CYGNUM_HAL_STACK_SIZE_TYPICAL,
+ &cpu_load_handle, &cpu_load_thread);
+ cyg_thread_resume (cpu_load_handle);
+}
diff --git a/cesar/ce/test/tx/Makefile b/cesar/ce/test/tx/Makefile
new file mode 100644
index 0000000000..b0e6e8d3fa
--- /dev/null
+++ b/cesar/ce/test/tx/Makefile
@@ -0,0 +1,8 @@
+all :
+ $(MAKE) -f host-Makefile --no-print-directory
+ $(MAKE) -f target-Makefile --no-print-directory
+
+clean :
+ $(MAKE) -f host-Makefile clean
+ $(MAKE) -f target-Makefile clean
+
diff --git a/cesar/ce/test/tx/host-Makefile b/cesar/ce/test/tx/host-Makefile
new file mode 100755
index 0000000000..ba9d305904
--- /dev/null
+++ b/cesar/ce/test/tx/host-Makefile
@@ -0,0 +1,17 @@
+BASE = ../../..
+
+INCLUDES = ce/test/tx
+INCLUDES+= ce/test/common
+INCLUDES+= ce/test/common/ecos_overide
+INCLUDES += ce/test/rx/general/overide
+
+HOST_PROGRAMS = test_tx
+test_tx_SOURCES = test_tx.c
+test_tx_MODULES = lib mac/common ce ce/test/common ce/test/common/ecos_overide/cyg/kernel ce/test/rx/general/overide/cp/interf
+
+ce_MODULE_SOURCES = tx.c rxce_stats.c
+ce_test_common_MODULE_SOURCES = print_utils.c
+
+VARIANT = host
+
+include $(BASE)/common/make/top.mk
diff --git a/cesar/ce/test/tx/src/test_expiration.c b/cesar/ce/test/tx/src/test_expiration.c
new file mode 100644
index 0000000000..e26a473608
--- /dev/null
+++ b/cesar/ce/test/tx/src/test_expiration.c
@@ -0,0 +1,121 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file ./src/test_expiration.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+#include "common/std.h"
+#include "cyg/kernel/kapi.h"
+#include "ce/inc/tx.h"
+#include "lib/test.h"
+#include "cp/interf/interf.h"
+#include "cp/cp.h"
+#include "mac/common/tonemap.h"
+#include "ce/inc/ecos_time.h"
+
+#define CP_PRIORITY 20
+cyg_thread cp_thread;
+cyg_handle_t cp_handle;
+unsigned char cp_stack[CYGNUM_HAL_STACK_SIZE_TYPICAL];
+
+#define TEST_PRIORITY 10
+cyg_thread test_thread;
+cyg_handle_t test_handle;
+unsigned char test_stack[CYGNUM_HAL_STACK_SIZE_TYPICAL];
+
+test_t test;
+mac_store_t *mac_store_ctx;
+cp_t *cp_ctx;
+
+void
+test_process (cyg_addrword_t data)
+{
+ int n=0;
+ test_begin (test, "txce expiration")
+ {
+ int i, tmi;
+ bool has_tonemap = false;
+ // Let CP running and simulate CEI reception. Check during 1mn if
+ // tonemap that should have been expirated is still in mac_store.
+ while (n++<S_TO_RTC (TONEMAPS_LIFE_DURATION_S*2))
+ {
+ //printf ("%d\n",n);
+ cyg_thread_delay(1);
+ for (i=MAC_TEI_STA_MIN; i<MAC_TEI_STA_MAX; i++)
+ {
+ sta_t *lsta = mac_store_sta_get (mac_store_ctx, i);
+ if (lsta)
+ {
+ has_tonemap = false;
+ for (tmi=0; tmi<TONEMAP_INDEX_NB; tmi++)
+ {
+ if (lsta->tx_tonemaps->tm[tmi] != NULL)
+ {
+ has_tonemap = true;
+ break;
+ }
+ }
+ test_fail_if ( has_tonemap && (cyg_current_time() > lsta->tx_tonemaps->expiration_rtc_date));
+ blk_release (lsta);
+ }
+ }
+ }
+ // Stop the simulation of received CEI.
+ cp_stop (cp_ctx);
+ // Wait the life of tonemaps duration.
+ // After this, all the tonemaps must have been expirated.
+ cyg_thread_delay (S_TO_RTC(TONEMAPS_LIFE_DURATION_S));
+ has_tonemap = false;
+ for (i=MAC_TEI_STA_MIN; i<MAC_TEI_STA_MAX; i++)
+ {
+ sta_t *lsta = mac_store_sta_get (mac_store_ctx, i);
+ if (lsta)
+ {
+ for (tmi=0; tmi<TONEMAP_INDEX_NB; tmi++)
+ {
+ if (lsta->tx_tonemaps->tm[tmi] != NULL)
+ {
+ has_tonemap = true;
+ break;
+ }
+ }
+ test_fail_if ( has_tonemap );
+ blk_release (lsta);
+ }
+ }
+
+ } test_end;
+ test_result (test);
+ HAL_PLATFORM_EXIT (test_nb_failed (test) == 0 ? 0 : 1);
+}
+
+
+void
+cyg_user_start (int argc, char **argv)
+{
+ test_init (test, argc, argv);
+ mac_config_t mac_config;
+ mac_config_init (&mac_config);
+ mac_store_ctx = mac_store_init();
+ cp_ctx = cp_init (mac_store_ctx, &mac_config);
+ cyg_thread_create (CP_PRIORITY, &cp_process,(cyg_addrword_t) cp_ctx, "cp",
+ cp_stack, CYGNUM_HAL_STACK_SIZE_TYPICAL,
+ &cp_handle, &cp_thread);
+
+ cyg_thread_create (TEST_PRIORITY, &test_process,(cyg_addrword_t) 0, "test",
+ test_stack, CYGNUM_HAL_STACK_SIZE_TYPICAL,
+ &test_handle, &test_thread);
+
+
+
+ cyg_thread_resume (test_handle);
+ cyg_thread_resume (cp_handle);
+}
diff --git a/cesar/ce/test/tx/src/test_tx.c b/cesar/ce/test/tx/src/test_tx.c
new file mode 100755
index 0000000000..ab47d20c0d
--- /dev/null
+++ b/cesar/ce/test/tx/src/test_tx.c
@@ -0,0 +1,150 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file ./src/test_tx.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+
+#include "common/std.h"
+
+#include <stdio.h>
+#include "ce/test/common/print_utils.h"
+
+#include "mac/common/store.h"
+#include "ce/inc/tx.h"
+#include "mac/common/tonemask.h"
+#include "ce/inc/cei.h"
+#include "mac/common/timings.h"
+#include "lib/test.h"
+
+#define MME_BUFFER_SIZE 1536
+
+#define STEI 1
+
+
+int
+main (int argc, char **argv)
+{
+ int i;
+ test_t test;
+ mac_config_t mac_config;
+ test_init (test, argc, argv);
+ mac_config_init (&mac_config);
+ //for (i=0; i< PHY_CARRIER_NB/8; i++) mac_config.tonemask_info.tonemask[i] = 0xFF;
+ u16 MAX_FL_FL = MAC_MAX_FL_MAX_FL;
+ u8 RIFS1 = MAC_RIFS_AV_ONE_SYM_FL;
+ u8 RIFS2 = MAC_RIFS_AV_TWO_SYM_FL;
+ u8 RIFS3 = MAC_RIFS_AV_G2_SYM_FL;
+ u8 RESPT = 0;
+ u8 MAXTM = TONEMAP_INDEX_NB;
+ u8 DEFAULT_TMI = 0x04;
+ u8 SCL = 0x0;
+ u8 TM_VALID_NB = 0x1;
+ u8 TMI_VALID0 = DEFAULT_TMI;
+ u8 NINT = 0;
+ u8 NEW_TMI = DEFAULT_TMI;
+ u8 CPF = 1;
+ u8 FEC = 0;
+ u8 GI = 0;
+ u8 CBDENC = 0;
+ u8 rx_mm_entry[MME_BUFFER_SIZE];
+ bitstream_t stream;
+ bitstream_t *writer = &stream;
+ bitstream_init (writer, rx_mm_entry, MME_BUFFER_SIZE, BITSTREAM_WRITE);
+ bitstream_access (writer, &MAX_FL_FL, 16);
+ bitstream_access (writer, &RIFS1, 8);
+ bitstream_access (writer, &RIFS2, 8);
+ bitstream_access (writer, &RIFS3, 8);
+ bitstream_access (writer, &RESPT, 8);
+ bitstream_access (writer, &MAXTM, 8);
+ bitstream_access (writer, &DEFAULT_TMI, 8);
+ bitstream_access (writer, &SCL, 8);
+ bitstream_access (writer, &SCL, 8);
+ bitstream_access (writer, &TM_VALID_NB, 8);
+ bitstream_access (writer, &TMI_VALID0, 8);
+ bitstream_access (writer, &NINT, 8);
+ bitstream_access (writer, &NEW_TMI, 8);
+ bitstream_access (writer, &CPF, 8);
+ bitstream_access (writer, &FEC, 8);
+ bitstream_access (writer, &GI, 8);
+ bitstream_access (writer, &CBDENC, 8);
+
+ uint mask_len = mac_config.tonemask_info.carrier_nb;
+ bitstream_access (writer, &mask_len, 16);
+
+ u8 tonemap[PHY_CARRIER_NB];
+ for (i=0; i<PHY_CARRIER_NB; i++) tonemap[i] = (i%7)+1;
+ for (i = 0; i<PHY_CARRIER_NB; i++)
+ {
+ bitstream_access (writer, &tonemap[i], 4);
+ }
+ bitstream_finalise(writer);
+
+ mac_store_t *mac_store_ctx = mac_store_init();
+ mac_store_sta_add (mac_store_ctx, STEI);
+ sta_t *sta = mac_store_sta_get (mac_store_ctx, STEI);
+ txce_t *txce_ctx = txce_init (mac_store_ctx, &mac_config, NULL);
+ txce (txce_ctx, STEI, CM_CHAN_EST_IND, rx_mm_entry);
+ ce_print_tonemaps (sta->tx_tonemaps);
+ test_case_begin (test, "CE-create tonemap from cei received");
+ test_begin (test, "No encodage")
+ {
+ test_fail_if (sta->tx_tonemaps->max_fl_av != MAX_FL_FL);
+ test_fail_if (sta->tx_tonemaps->rifs_av_one_sym_tck != MAC_RIFS_AV_ONE_SYM_TCK);
+ test_fail_if (sta->tx_tonemaps->rifs_av_two_sym_tck != MAC_RIFS_AV_TWO_SYM_TCK);
+ test_fail_if (sta->tx_tonemaps->rifs_av_g2_sym_tck != MAC_RIFS_AV_G2_SYM_TCK);
+ test_fail_if (sta->tx_tonemaps->max_tm != MAXTM);
+ test_fail_if (sta->tx_tonemaps->default_tmi != DEFAULT_TMI);
+ test_fail_if (sta->tx_tonemaps->scl_cp != SCL);
+ test_fail_if (sta->tx_tonemaps->scl_cfp != SCL);
+ int nint = tonemap_valid_nb (sta->tx_tonemaps);
+ test_fail_if (nint != TM_VALID_NB);
+ u8 *mask = (mac_config.tonemask_info.tonemask);
+ u8 tmp[PHY_CARRIER_NB];
+ u8 *tm_data = sta->tx_tonemaps->tm[DEFAULT_TMI-4]->tmdma_desc_head->data;
+ for (i=0; i<PHY_CARRIER_NB; i++)
+ {
+ if (i==1024) tm_data = sta->tx_tonemaps->tm[DEFAULT_TMI-4]->tmdma_desc_head->next->data;
+ uint n1 = (uint) *tm_data++;
+ uint n2 = n1>>4;
+ n1 = n1&0xF;
+ tmp[i++]= n1;
+ tmp[i] = n2;
+ }
+ uint z=0;
+ for (i=0; i<PHY_CARRIER_NB; i++)
+ {
+ //ce_print ("c%d : tone=%d\n",i, tmp[i]);
+ if ((mask[i/8] & (1<<(i%8))) == 0)
+ {
+ //ce_print ("c%d : masked\n",i);
+ test_fail_if (tmp[i] != 0 && tmp[i]<0x08);
+ }
+ else
+ {
+ //ce_print ("c%d : tmp[%d]=%d; previous=%d\n",i,i,tmp[i],z);
+ test_fail_if (tmp[i]!= (z+1));
+ z = tmp[i];
+ if (z==7) z=0;
+ }
+ }
+ test_fail_if (sta->tx_tonemaps->intervals->intervals_nb != NINT);
+ } test_end;
+ blk_release (sta);
+ dbg_check (mac_store_sta_remove (mac_store_ctx, STEI));
+ test_begin (test, "check alloc/free")
+ {
+ test_fail_unless (blk_check_memory());
+ } test_end;
+ test_result (test);
+ return (test_nb_failed (test) == 0 ? 0 : 1);
+}
+
diff --git a/cesar/ce/test/tx/target-Makefile b/cesar/ce/test/tx/target-Makefile
new file mode 100644
index 0000000000..783d886c70
--- /dev/null
+++ b/cesar/ce/test/tx/target-Makefile
@@ -0,0 +1,22 @@
+BASE = ../../..
+
+INCLUDES = ce/test/tx/
+INCLUDES += ce/test/common
+INCLUDES += ce/test/rx/general/overide
+
+ECOS = y
+
+TARGET_PROGRAMS=test_alarm_target_ecos_synth
+test_alarm_target_ecos_synth_SOURCES = essai_alarm.c
+
+TARGET_PROGRAMS=test_expiration_target_ecos_synth
+test_expiration_target_ecos_synth_SOURCES = test_expiration.c
+test_expiration_target_ecos_synth_MODULES = lib ce mac/common ce/test/common ce/test/rx/general/overide/cp/interf ce/test/rx/general/overide/cp
+
+
+ce_MODULE_SOURCES = tx.c
+
+VARIANT = target
+
+include $(BASE)/common/make/top.mk
+
diff --git a/cesar/ce/test/tx/target-ecos.ecc.sh b/cesar/ce/test/tx/target-ecos.ecc.sh
new file mode 100755
index 0000000000..8253d98c9a
--- /dev/null
+++ b/cesar/ce/test/tx/target-ecos.ecc.sh
@@ -0,0 +1,5 @@
+config=${1:-ecos-gen.ecc}
+ecosconfig --config=$config new linux default
+cat >> $config <<EOF
+EOF
+ecosconfig --config=$config check
diff --git a/cesar/ce/test/tx/test.h b/cesar/ce/test/tx/test.h
new file mode 100644
index 0000000000..9d0fde9ad4
--- /dev/null
+++ b/cesar/ce/test/tx/test.h
@@ -0,0 +1,18 @@
+#ifndef ___tx_test_h
+#define ___tx_test_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file ../tx/test.h
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+
+#endif /* ___tx_test_h */