summaryrefslogtreecommitdiff
path: root/cesar/bsu/aclf
diff options
context:
space:
mode:
authorNélio Laranjeiro2011-02-07 18:02:43 +0100
committerNélio Laranjeiro2011-02-07 18:02:43 +0100
commit3d32fabd2a51c4adbfdf789967925e7e5aa5d3bc (patch)
tree7eea8ebdedfb6bbb4c4246a034b7742b95575021 /cesar/bsu/aclf
parent70ae5daad6043272daf32bd81d953bea0359d43f (diff)
cesar/bsu/aclf: two coefficients for beacon period computation, closes #2230
Use a "FAST" weight to synchronise the beacon period on the PowerLine cycle and a "slower" one once this is done. The Switch is made by a number of synchronisation of the PowerLine configured in the Config file. This reverts commit 70ae5daad6043272daf32bd81d953bea0359d43f.
Diffstat (limited to 'cesar/bsu/aclf')
-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