summaryrefslogtreecommitdiff
path: root/cesar
diff options
context:
space:
mode:
authorNélio Laranjeiro2010-11-23 11:00:30 +0100
committerNélio Laranjeiro2010-12-07 09:22:42 +0100
commitfa81ee2cb662315ae336ab2f2486015c88da578e (patch)
tree3b563eecec06ea73082bc2538d7eb9caf87ec959 /cesar
parentc48aa71719def044dc6b3780a76910a4025d2689 (diff)
cesar/bsu/ntb: better ntb synchronisation, closes #2098
Diffstat (limited to 'cesar')
-rw-r--r--cesar/bsu/ntb/src/ntb.c30
-rw-r--r--cesar/bsu/ntb/test/utest/src/ntb_compute.c28
2 files changed, 51 insertions, 7 deletions
diff --git a/cesar/bsu/ntb/src/ntb.c b/cesar/bsu/ntb/src/ntb.c
index 52a70f1663..96b8a7097c 100644
--- a/cesar/bsu/ntb/src/ntb.c
+++ b/cesar/bsu/ntb/src/ntb.c
@@ -13,12 +13,19 @@
#include "common/std.h"
#include "lib/fixed.h"
#include "bsu/ntb/ntb.h"
+#include "mac/common/timings.h"
#include <string.h>
/** Define a security level for frequency error.
* If frequency error is greater then re-initialise freq error. */
#define BSU_FREQ_ERR_SECURITY 200.0e-6
+/** If the new beacon data received are BSU_NTB_NO_RECEPTION_MS after the last
+ * Beacon's BTS, NTB will not compute the frequency error neither the
+ * ntb_tck_offset. The purpose is to not compute a wrong frequency error and
+ * 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
@@ -104,14 +111,23 @@ bsu_ntb_clk_sync (bsu_ntb_sync_t * ctx, phy_t *phy, u32 beacon_bts,
dbg_assert (ctx);
dbg_assert (phy);
freq_error = ctx->fe;
- bsu_ntb_frequency_error (ctx, freq_error, beacon_bts, beacon_sys_ltmr);
- /** Frequency error is too high reset data. */
- if (ABS (ctx->fe) > BSU_FREQ_ERR_SECURITY)
+ /**
+ * Check the beacon received is not received N MS after the previous one,
+ * if it is the case, frequency error and ntb tick offset should not be
+ * changed until the next beacon reception. */
+ if (ctx->init
+ && less_mod2p32 (beacon_bts,
+ ctx->bts + MAC_MS_TO_TCK (BSU_NTB_NO_RECEPTION_MS)))
{
- freq_error = 0;
- ctx->fe = 0;
- ctx->init = false;
- ctx->second_shoot = false;
+ bsu_ntb_frequency_error (ctx, freq_error, beacon_bts, beacon_sys_ltmr);
+ /** Frequency error is too high reset data. */
+ if (ABS (ctx->fe) > BSU_FREQ_ERR_SECURITY)
+ {
+ freq_error = 0;
+ ctx->fe = 0;
+ ctx->init = false;
+ ctx->second_shoot = false;
+ }
}
ctx->ntb_offset_tck= bsu_ntb_offset (ctx, phy, freq_error, beacon_bts,
beacon_sta_ltmr, beacon_sys_ltmr);
diff --git a/cesar/bsu/ntb/test/utest/src/ntb_compute.c b/cesar/bsu/ntb/test/utest/src/ntb_compute.c
index 77a82caff0..b5ff7a220a 100644
--- a/cesar/bsu/ntb/test/utest/src/ntb_compute.c
+++ b/cesar/bsu/ntb/test/utest/src/ntb_compute.c
@@ -14,6 +14,7 @@
#include "lib/test.h"
#include "bsu/ntb/test/utest/tests.h"
#include "bsu/ntb/ntb.h"
+#include "mac/common/timings.h"
/* Spidcom test files inputs for test. */
#include "spc-bts01.h"
#include "spc-preamble-stadate01.h"
@@ -141,6 +142,33 @@ test_case_freq_error (test_t test)
sync.ntb_offset_tck == sync.bts - sync.preamble_stadate);
}
test_end;
+ test_begin (test, "Beacon received after authorized delay")
+ {
+ bsu_ntb_sync_t sync, scmp;
+ bsu_ntb_init (&sync);
+ /* Configure with real data. */
+ sync.init = true;
+ sync.second_shoot = true;
+ sync.fe = -1.074e-05;
+ sync.bts = 0x8a1ad69;
+ sync.preamble_sysdate = 0x6f04181;
+ sync.preamble_stadate = 0x6f04181;
+ scmp.fe = sync.fe;
+ scmp.bts = sync.bts + MAC_MS_TO_TCK (500);
+ scmp.preamble_sysdate = sync.preamble_sysdate + MAC_MS_TO_TCK (500);
+ scmp.preamble_stadate = sync.preamble_stadate + MAC_MS_TO_TCK (500);
+ /* Compute new Frequency error. */
+ bsu_ntb_clk_sync (
+ &sync, (phy_t*) &t.phy, scmp.bts, scmp.preamble_sysdate,
+ scmp.preamble_stadate);
+ test_fail_unless (sync.fe == scmp.fe);
+ test_fail_unless (scmp.bts == sync.bts);
+ test_fail_unless (scmp.preamble_sysdate == sync.preamble_sysdate);
+ test_fail_unless (scmp.preamble_stadate == sync.preamble_stadate);
+ test_fail_unless (sync.init == true);
+ test_fail_unless (sync.second_shoot == true);
+ }
+ test_end;
}
void