summaryrefslogtreecommitdiff
path: root/cesar/bsu/ntb
diff options
context:
space:
mode:
authorNĂ©lio Laranjeiro2011-06-16 09:41:36 +0200
committerNicolas Schodet2011-09-08 16:22:55 +0200
commite56cc9e78763d383e51e4b66f21a761826c3f305 (patch)
treeea5c9f2ac0964611f9365ddefa4f5f8c4350bf40 /cesar/bsu/ntb
parent7acaa2f3e42fd73e7af0a73ac9b43413c8c89c80 (diff)
cesar/bsu: add tunable NTB smooth coefficient, closes #2680
Diffstat (limited to 'cesar/bsu/ntb')
-rw-r--r--cesar/bsu/ntb/ntb.h5
-rw-r--r--cesar/bsu/ntb/src/ntb.c15
-rw-r--r--cesar/bsu/ntb/test/utest/src/ntb_compute.c9
3 files changed, 16 insertions, 13 deletions
diff --git a/cesar/bsu/ntb/ntb.h b/cesar/bsu/ntb/ntb.h
index a71b9861d2..ce01f409da 100644
--- a/cesar/bsu/ntb/ntb.h
+++ b/cesar/bsu/ntb/ntb.h
@@ -16,6 +16,8 @@
#include "mac/common/config.h"
#include "hal/phy/phy.h"
+#define BSU_NTB_CLK_SYNC_WEIGHT_K_DEFAULT 2
+
BEGIN_DECLS
/*
@@ -25,10 +27,11 @@ BEGIN_DECLS
* \param phy the phy context.
* \param beacon_bts beacon time stamp
* \param beacon_sta_ltmr STA local time captured when receiving beacon
+ * \param weight_k the coefficient weight to use to smooth the NTB clock
*/
void
bsu_ntb_clk_sync (bsu_ntb_sync_t * ctx, phy_t *phy, u32 beacon_bts,
- u32 beacon_sys_ltmr, u32 beacon_sta_ltmr);
+ u32 beacon_sys_ltmr, u32 beacon_sta_ltmr, uint weight_k);
/**
* Configure the clock frequency.
diff --git a/cesar/bsu/ntb/src/ntb.c b/cesar/bsu/ntb/src/ntb.c
index 1111597960..fe4a49a7f0 100644
--- a/cesar/bsu/ntb/src/ntb.c
+++ b/cesar/bsu/ntb/src/ntb.c
@@ -25,10 +25,6 @@
* keep a good synchronisation on the medium without reseting history. */
#define BSU_NTB_NO_RECEPTION_MS 400
-#define BSU_NTB_WEIGHT 0.25
-#define BSU_NTB_WF BSU_NTB_WEIGHT
-#define BSU_NTB_WO BSU_NTB_WEIGHT
-
#define BSU_NTB_FE_PPM(fe) \
((double) ((fe) * 1000000.0))
@@ -38,12 +34,14 @@
* \param bts the last beacon time stamp received in the last beacon.
* \param preamble_sysdate the system date preamble corresponding to the
* last beacon received.
+ * \param weight_k the coefficient weight to use to smooth the NTB clock
*/
PRIVATE void
bsu_ntb_frequency_error (bsu_ntb_sync_t *ctx, double freq_err, u32 bts,
- u32 preamble_sysdate)
+ u32 preamble_sysdate, uint weight_k)
{
dbg_assert (ctx);
+ double bsu_ntb_wf = 1.0 / (1 << weight_k);
if (ctx->init)
{
double num = bts - ctx->bts;
@@ -56,7 +54,7 @@ bsu_ntb_frequency_error (bsu_ntb_sync_t *ctx, double freq_err, u32 bts,
else
{
double part2 = num / denum - 1 - freq_err;
- ctx->fe = freq_err + BSU_NTB_WF * part2;
+ ctx->fe = freq_err + bsu_ntb_wf * part2;
}
}
}
@@ -112,7 +110,7 @@ bsu_ntb_uninit (bsu_ntb_sync_t *ctx)
void
bsu_ntb_clk_sync (bsu_ntb_sync_t * ctx, phy_t *phy, u32 beacon_bts,
- u32 beacon_sys_ltmr, u32 beacon_sta_ltmr)
+ u32 beacon_sys_ltmr, u32 beacon_sta_ltmr, uint weight_k)
{
double freq_error;
dbg_assert (ctx);
@@ -126,7 +124,8 @@ bsu_ntb_clk_sync (bsu_ntb_sync_t * ctx, phy_t *phy, u32 beacon_bts,
&& less_mod2p32 (beacon_bts,
ctx->bts + MAC_MS_TO_TCK (BSU_NTB_NO_RECEPTION_MS)))
{
- bsu_ntb_frequency_error (ctx, freq_error, beacon_bts, beacon_sys_ltmr);
+ bsu_ntb_frequency_error (ctx, freq_error, beacon_bts, beacon_sys_ltmr,
+ weight_k);
/** Frequency error is too high reset data. */
if (ABS (ctx->fe) > BSU_FREQ_ERR_SECURITY)
{
diff --git a/cesar/bsu/ntb/test/utest/src/ntb_compute.c b/cesar/bsu/ntb/test/utest/src/ntb_compute.c
index b5ff7a220a..19745c4c65 100644
--- a/cesar/bsu/ntb/test/utest/src/ntb_compute.c
+++ b/cesar/bsu/ntb/test/utest/src/ntb_compute.c
@@ -12,6 +12,7 @@
*/
#include "common/std.h"
#include "lib/test.h"
+#include "lib/fixed.h"
#include "bsu/ntb/test/utest/tests.h"
#include "bsu/ntb/ntb.h"
#include "mac/common/timings.h"
@@ -78,7 +79,7 @@ test_case_ntb_ntb_sync (test_t test, bsu_ntb_test_type_t type)
/* In this test the sys_date_preamble is the same as the station
* date preamble. */
bsu_ntb_clk_sync (&sync, (phy_t*) &t.phy, bts[i],
- preamble_sysdate[i], preamble_stadate[i]);
+ preamble_sysdate[i], preamble_stadate[i], 2);
test_fail_unless (ABS(sync.fe - freqerr[i]) < 1.0e-12,
"Freq different in loop %d", i);
test_fail_unless (sync.ntb_offset_tck == offset[i],
@@ -118,7 +119,7 @@ test_case_freq_error (test_t test)
sync.preamble_stadate = 0x6f04181;
/* Compute new Frequency error. */
bsu_ntb_clk_sync (&sync, (phy_t*) &t.phy, 0x21e04ad,
- 0x1ddf30d3, 0x1ddf30d3);
+ 0x1ddf30d3, 0x1ddf30d3, 2);
test_fail_unless (sync.fe == 0);
test_fail_unless (sync.init == true);
test_fail_unless (sync.second_shoot == false);
@@ -134,7 +135,7 @@ test_case_freq_error (test_t test)
sync.preamble_stadate = 0x6f04181;
/* Compute new Frequency error. */
bsu_ntb_clk_sync (&sync, (phy_t*) &t.phy, sync.bts + 1,
- sync.preamble_sysdate + 1, 0x1ddf30d3);
+ sync.preamble_sysdate + 1, 0x1ddf30d3, 2);
test_fail_unless (sync.fe == 0);
test_fail_unless (sync.init == true);
test_fail_unless (sync.second_shoot == false);
@@ -160,7 +161,7 @@ test_case_freq_error (test_t test)
/* Compute new Frequency error. */
bsu_ntb_clk_sync (
&sync, (phy_t*) &t.phy, scmp.bts, scmp.preamble_sysdate,
- scmp.preamble_stadate);
+ scmp.preamble_stadate, 2);
test_fail_unless (sync.fe == scmp.fe);
test_fail_unless (scmp.bts == sync.bts);
test_fail_unless (scmp.preamble_sysdate == sync.preamble_sysdate);