summaryrefslogtreecommitdiff
path: root/cesar/ce/inc
diff options
context:
space:
mode:
authorsave2008-04-07 14:17:42 +0000
committersave2008-04-07 14:17:42 +0000
commit3d58a62727346b7ac1a6cb36fed1a06ed72228dd (patch)
treed7788c3cf9f76426aef0286d0202e2097f0fa0eb /cesar/ce/inc
parent095dca4b0a8d4924093bab424f71f588fdd84613 (diff)
Moved the complete svn base into the cesar directory.
git-svn-id: svn+ssh://pessac/svn/cesar/trunk@1769 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cesar/ce/inc')
-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
8 files changed, 1201 insertions, 0 deletions
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 */