summaryrefslogtreecommitdiff
path: root/cesar
diff options
context:
space:
mode:
authorNélio Laranjeiro2011-01-28 10:57:09 +0100
committerNélio Laranjeiro2011-02-07 17:11:50 +0100
commitdcb2f6d35d78a3f4b68d79e26f88dc2d97775cbb (patch)
tree083aee4f937ef3b0cc38c7d5fd699d4b6b2593cb /cesar
parentb21bc67eb9f4df3f5a44fd04f2547f00096443ee (diff)
cesar/bsu: add stats, closes #2213
- current ntb_tck_offset - current frequency error in q30.
Diffstat (limited to 'cesar')
-rw-r--r--cesar/bsu/aclf/Config2
-rw-r--r--cesar/bsu/aclf/aclf.h4
-rw-r--r--cesar/bsu/aclf/src/aclf.c17
-rw-r--r--cesar/bsu/aclf/test/utest/Config3
4 files changed, 23 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 c135dcc862..6402bbc619 100644
--- a/cesar/bsu/aclf/aclf.h
+++ b/cesar/bsu/aclf/aclf.h
@@ -101,6 +101,10 @@ struct bsu_aclf_t
hal_timer_instance_t timer;
/** Activated status. */
bool activate;
+ /** 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 8a4d382fe4..42be338ae1 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;
}
}
@@ -233,6 +240,8 @@ bsu_aclf_clear (bsu_aclf_t *ctx)
ctx->bto[i] = 0;
ctx->zero_cross_last_date = 0;
ctx->aclsc = false;
+ ctx->pwl_sync_nb = 0;
+ ctx->pwl_sync_weight = BSU_ACLF_WP_FAST;
}
/**
@@ -263,6 +272,8 @@ bsu_aclf_init (phy_t *phy, mac_config_t *mac_config, hal_timer_t *timer)
ctx->mac_config = mac_config;
ctx->hal_timer = timer;
hal_timer_instance_init (timer, &ctx->timer, ctx, bsu_aclf_timer_event);
+ 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