summaryrefslogtreecommitdiff
path: root/cesar/bsu/aclf
diff options
context:
space:
mode:
authorNélio Laranjeiro2011-02-07 18:07:58 +0100
committerNélio Laranjeiro2011-02-07 18:07:58 +0100
commitedd3d26160d17678ade3c1ac90dd8c8ba05b0f85 (patch)
treed4ad92c7eb6f743ea5681b0862b761c70b24c0b9 /cesar/bsu/aclf
parente4e2284d34a30548867d858ec0662d1fad40b8a5 (diff)
parent3d32fabd2a51c4adbfdf789967925e7e5aa5d3bc (diff)
Merge branch 'master' into av
Conflicts: cesar/bsu/aclf/aclf.h cesar/bsu/aclf/src/aclf.c cesar/bsu/aclf/test/utest/src/aclf.c cesar/bsu/src/bsu.c
Diffstat (limited to 'cesar/bsu/aclf')
-rw-r--r--cesar/bsu/aclf/Config2
-rw-r--r--cesar/bsu/aclf/aclf.h5
-rw-r--r--cesar/bsu/aclf/src/aclf.c35
-rw-r--r--cesar/bsu/aclf/test/utest/Config3
-rw-r--r--cesar/bsu/aclf/test/utest/src/aclf.c2
5 files changed, 44 insertions, 3 deletions
diff --git a/cesar/bsu/aclf/Config b/cesar/bsu/aclf/Config
new file mode 100644
index 0000000000..93c8d536c1
--- /dev/null
+++ b/cesar/bsu/aclf/Config
@@ -0,0 +1,2 @@
+# Wait 40s before changing the weight.
+CONFIG_ACLF_SYNC_TO_SLOWER_WEIGHT_NB=1000
diff --git a/cesar/bsu/aclf/aclf.h b/cesar/bsu/aclf/aclf.h
index a24b8ef190..1037fa7486 100644
--- a/cesar/bsu/aclf/aclf.h
+++ b/cesar/bsu/aclf/aclf.h
@@ -19,6 +19,7 @@
#include "mac/common/config.h"
#include "mac/common/timings.h"
#include "common/defs/homeplugAV.h"
+#include "lib/stats.h"
/** Number of beacon period start date handled.
* The value is computed to allow the CCo to compute the four next BTOs. */
@@ -92,6 +93,10 @@ struct bsu_aclf_t
* Last zero_cross read in PRATIC register.
*/
u32 zero_cross_last_date;
+ /** count number of Power Line synchronisation. */
+ u32 pwl_sync_nb;
+ /** Use the weight to compute the beacon period (shift value). */
+ uint pwl_sync_weight;
};
typedef struct bsu_aclf_t bsu_aclf_t;
diff --git a/cesar/bsu/aclf/src/aclf.c b/cesar/bsu/aclf/src/aclf.c
index b1fbff444e..dab1b27fc6 100644
--- a/cesar/bsu/aclf/src/aclf.c
+++ b/cesar/bsu/aclf/src/aclf.c
@@ -16,6 +16,7 @@
#include "mac/common/timings.h"
#include "bsu/aclf/aclf.h"
#include <string.h>
+#include "config/aclf.h"
/** Store constant values with the frequency detection found. */
#define BSU_ACLF_SET_FREQUENCY(freq) \
@@ -26,8 +27,10 @@
= BSU_ACLF_BP_ ## freq ## HZ_TCK; \
} while (0)
-/** WP History coefficient value. */
-#define BSU_ACLF_WP 0.0625
+/** WP History coefficient value fast i.e. 1/2^4. */
+#define BSU_ACLF_WP_FAST 4
+/** WP History coefficient value slow i.e. 1/2^8. */
+#define BSU_ACLF_WP_SLOW 8
/** Local variable. */
static bsu_aclf_t bsu_aclf_global;
@@ -79,10 +82,14 @@ bsu_aclf_compute_beacon_period_from_acl (bsu_aclf_t *ctx)
(zc_diff_tck + zc_interval_tck / 2) / zc_interval_tck;
uint bp_tck = 2 * zc_diff_tck / zc_nb;
ctx->beacon_period_tck +=
- BSU_ACLF_WP * ((int)bp_tck - (int)ctx->beacon_period_tck);
+ ((int)bp_tck - (int)ctx->beacon_period_tck)
+ >> ctx->pwl_sync_weight;
bsu_aclf_truncate_beacon_period (ctx);
/* Store the last zero crossing date. */
ctx->zero_cross_last_date = zero_cross_date;
+ ctx->pwl_sync_nb++;
+ if (ctx->pwl_sync_nb == CONFIG_ACLF_SYNC_TO_SLOWER_WEIGHT_NB)
+ ctx->pwl_sync_weight = BSU_ACLF_WP_SLOW;
}
}
@@ -190,6 +197,25 @@ bsu_aclf_clear (bsu_aclf_t *ctx)
for (i = 0; i < COUNT (ctx->bto); i++)
ctx->bto[i] = 0;
ctx->zero_cross_last_date = 0;
+ ctx->pwl_sync_nb = 0;
+ ctx->pwl_sync_weight = BSU_ACLF_WP_FAST;
+}
+
+/**
+ * Initialise stats.
+ * \param ctx the module context.
+ */
+void
+bsu_aclf_stats_init (bsu_aclf_t *ctx)
+{
+#if CONFIG_STATS
+ dbg_assert (ctx);
+ /* Register our statistics. */
+ lib_stats_set_stat_value_notype ("beacon_period_tck",
+ &ctx->beacon_period_tck,
+ LIB_STATS_ACCESS_READ_ONLY,
+ LIB_STATS_USER);
+#endif
}
bsu_aclf_t*
@@ -201,6 +227,9 @@ bsu_aclf_init (phy_t *phy, mac_config_t *mac_config)
memset (ctx, 0, sizeof (bsu_aclf_t));
ctx->phy = phy;
ctx->mac_config = mac_config;
+ ctx->pwl_sync_nb = 0;
+ ctx->pwl_sync_weight = BSU_ACLF_WP_FAST;
+ bsu_aclf_stats_init (ctx);
return ctx;
}
diff --git a/cesar/bsu/aclf/test/utest/Config b/cesar/bsu/aclf/test/utest/Config
new file mode 100644
index 0000000000..7e0f77a8bb
--- /dev/null
+++ b/cesar/bsu/aclf/test/utest/Config
@@ -0,0 +1,3 @@
+CONFIG_TRACE = y
+CONFIG_STATS = y
+CONFIG_ACLF_SYNC_TO_SLOWER_WEIGHT_NB=1000000
diff --git a/cesar/bsu/aclf/test/utest/src/aclf.c b/cesar/bsu/aclf/test/utest/src/aclf.c
index d1ef5919ec..3250444d66 100644
--- a/cesar/bsu/aclf/test/utest/src/aclf.c
+++ b/cesar/bsu/aclf/test/utest/src/aclf.c
@@ -25,8 +25,10 @@ main (int argc, char **argv)
{
test_t test;
test_init (test, argc, argv);
+ lib_stats_init ();
test_suite_aclf__frequency (test);
test_suite_aclf__bpsd_accurate (test);
+ lib_stats_uninit ();
test_result (test);
return test_nb_failed (test) == 0 ? 0 : 1;
}