summaryrefslogtreecommitdiff
path: root/cesar/ce/rx/bitloading/src/bitloading.c
diff options
context:
space:
mode:
authordufour2009-07-17 14:40:28 +0000
committerdufour2009-07-17 14:40:28 +0000
commit0e096d415fe2e3cbdb77f90127f2ede3532183c7 (patch)
tree386683747fc614b685173071cb04c384c8c0bf92 /cesar/ce/rx/bitloading/src/bitloading.c
parent66d52364da1217be970d6fecfecb68cf4f2943af (diff)
* ce/rx, mac/common:
- move out everything relative to bitloading into the bitloading directory, - update some test and some includes. git-svn-id: svn+ssh://pessac/svn/cesar/trunk@5010 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cesar/ce/rx/bitloading/src/bitloading.c')
-rw-r--r--cesar/ce/rx/bitloading/src/bitloading.c156
1 files changed, 156 insertions, 0 deletions
diff --git a/cesar/ce/rx/bitloading/src/bitloading.c b/cesar/ce/rx/bitloading/src/bitloading.c
new file mode 100644
index 0000000000..132d91ad15
--- /dev/null
+++ b/cesar/ce/rx/bitloading/src/bitloading.c
@@ -0,0 +1,156 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2009 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file ce/rx/bitloading/src/bitloading.c
+ * \brief Bit loading computing for the CE RX (private implementation part).
+ * \ingroup ce_rx
+ */
+#include "common/std.h"
+
+#include "lib/slab.h"
+#include "ce/rx/bitloading/inc/bitloading.h"
+#include "ce/rx/inc/rx.h"
+
+void
+ce_rx_bitloading_allocate (ce_rx_t *ce_rx, ce_rx_bitloading_t *bt,
+ phy_chandata_t *chan_data, uint chan_data_count)
+{
+ /* Check parameters. */
+ dbg_assert (ce_rx);
+ dbg_assert (bt);
+ dbg_assert (chan_data);
+ dbg_assert (chan_data_count);
+
+ /* Look for noise NRJ. */
+ uint count = 0, noise_nrj_blk_count = 0;
+ bool finished = false;
+ phy_chandata_t *cur = chan_data;
+ /* While not finished. */
+ while (!finished)
+ {
+ dbg_assert (cur);
+ /* Noise NRJ block. */
+ if (cur->conf.type == PHY_CHANDATA_TYPE_NRJ)
+ {
+ /* First block. */
+ if (cur->conf.address = 0)
+ bt->noise_nrj = cur->blk;
+ noise_nrj_blk_count++;
+ blk_addref_desc (&cur->blk);
+ }
+ /* Get next channel data block. */
+ if (++count < chan_data_count)
+ cur = PARENT_OF (phy_chandata_t, blk, cur->blk.next);
+ else
+ finished = true;
+ }
+ {
+ /* Sanity check. */
+ if (PHY_CARRIER_NB % (BLK_SIZE / CE_RX_BITLOADING_NOISE_NRJ_SIZE))
+ {
+ dbg_assert (count ==
+ PHY_CARRIER_NB / (BLK_SIZE /
+ CE_RX_BITLOADING_NOISE_NRJ_SIZE)
+ + 1);
+ }
+ else
+ {
+ dbg_assert (count ==
+ PHY_CARRIER_NB / (BLK_SIZE /
+ CE_RX_BITLOADING_NOISE_NRJ_SIZE));
+ }
+ }
+ bt->noise_nrj_blk_count = noise_nrj_blk_count;
+ bt->mean_count = 0;
+}
+
+void
+ce_rx_bitloading_initial (ce_rx_t *ce_rx, ce_rx_bitloading_t *bt,
+ phy_chandata_t *chan_data, uint chan_data_count)
+{
+ /* Check parameter. */
+ dbg_assert (chan_data);
+ dbg_assert (chan_data_count);
+
+ uint count = 0;
+ bool finished = false;
+ phy_chandata_t *cur = chan_data;
+ blk_t *cur_blk = &bt->noise_nrj;
+ u32 *mean_noise_nrj;
+ u32 *noise_nrj;
+ /* While not finished. */
+ while (!finished)
+ {
+ dbg_assert (cur);
+ /* Noise NRJ block. */
+ if (cur->conf.type == PHY_CHANDATA_TYPE_NRJ)
+ {
+ /* Get mean noise NRJ. */
+ mean_noise_nrj = (u32 *) cur_blk->data;
+ /* Get noise NRJ. */
+ noise_nrj = (u32 *) cur->blk.data;
+ uint i;
+ for (i = 0; i < cur->conf.size; cur++)
+ {
+ mean_noise_nrj[i] += noise_nrj[i];
+ }
+ /* Next mean noise NRJ. */
+ if (!cur->conf.last)
+ cur_blk = cur_blk->next;
+ }
+ /* Get next channel data block. */
+ if (++count < chan_data_count)
+ cur = PARENT_OF (phy_chandata_t, blk, cur->blk.next);
+ else
+ finished = true;
+ }
+ bt->mean_count++;
+}
+
+void
+ce_rx_bitloading_generate_initial (ce_rx_t *ce_rx, sta_t *sta)
+{
+ /* Check parameters. */
+ dbg_assert (ce_rx);
+ dbg_assert (sta);
+
+ /* Compute the mean. */
+ /* To prevent too many divisions that can be long for the processor, we
+ * replace them by a multiplication and a shift.
+ * div = a / b <=> div = a * k / 2^m.
+ * k = (1 << m) / mean_count; m = 29. */
+ const u8 m = 29;
+ const uint k = (1 << m) / sta->ce_rx_bt.mean_count;
+
+ /* Go through the sum. */
+ uint i;
+ uint blk_count = 0;
+ bool finished = false;
+ blk_t *cur_blk = &sta->ce_rx_bt.noise_nrj;
+ u32 *mean_noise_nrj;
+ /* Go through each block of block of sum of noise NRJ. */
+ while (!finished)
+ {
+ /* Get mean noise NRJ (the sum in fact). */
+ mean_noise_nrj = (u32 *) cur_blk->data;
+ /* Go through each entry of the current block. */
+ for (i = 0; i < BLK_SIZE / CE_RX_BITLOADING_NOISE_NRJ_SIZE; i++)
+ {
+ /* Compute the initial mean. */
+ mean_noise_nrj[i] = mean_noise_nrj[i] * (u64) k / (1 << m);
+ }
+ /* Next mean noise NRJ if we are not at the end. */
+ if (++blk_count == sta->ce_rx_bt.noise_nrj_blk_count)
+ finished = true;
+ else
+ cur_blk = cur_blk->next;
+ }
+ /* TODO:
+ - compute BER vs SNR table, sort it, and use it to build the tone map.
+ */
+}