summaryrefslogtreecommitdiff
path: root/cesar
diff options
context:
space:
mode:
Diffstat (limited to 'cesar')
-rw-r--r--cesar/bsu/aclf/Config1
-rw-r--r--cesar/bsu/aclf/aclf.h3
-rw-r--r--cesar/bsu/aclf/src/aclf.c117
-rw-r--r--cesar/bsu/aclf/test/utest/Config2
-rw-r--r--cesar/bsu/aclf/test/utest/Makefile18
-rw-r--r--cesar/bsu/aclf/test/utest/src/bpsd.c9
-rw-r--r--cesar/bsu/aclf/test/utest/src/freq.c14
-rw-r--r--cesar/common/config-sets/plc-board1
8 files changed, 106 insertions, 59 deletions
diff --git a/cesar/bsu/aclf/Config b/cesar/bsu/aclf/Config
index 93c8d536c1..353c828751 100644
--- a/cesar/bsu/aclf/Config
+++ b/cesar/bsu/aclf/Config
@@ -1,2 +1,3 @@
# Wait 40s before changing the weight.
CONFIG_ACLF_SYNC_TO_SLOWER_WEIGHT_NB=1000
+CONFIG_ACLF_TRACKING=n
diff --git a/cesar/bsu/aclf/aclf.h b/cesar/bsu/aclf/aclf.h
index e6ea17693c..3eb7ae616a 100644
--- a/cesar/bsu/aclf/aclf.h
+++ b/cesar/bsu/aclf/aclf.h
@@ -42,7 +42,8 @@ enum bsu_aclf_bp_t
{
BSU_ACLF_BP_50HZ_TCK = 1000000,
BSU_ACLF_BP_55HZ_TCK = 909090,
- BSU_ACLF_BP_60HZ_TCK = 833333
+ BSU_ACLF_BP_60HZ_TCK = 833333,
+ BSU_ACLF_BP_CABLE_TCK = BSU_ACLF_BP_50HZ_TCK
};
typedef enum bsu_aclf_bp_t bsu_aclf_bp_t;
diff --git a/cesar/bsu/aclf/src/aclf.c b/cesar/bsu/aclf/src/aclf.c
index a43e6618c8..ca781b9e3d 100644
--- a/cesar/bsu/aclf/src/aclf.c
+++ b/cesar/bsu/aclf/src/aclf.c
@@ -35,12 +35,24 @@ bsu_aclf_set_frequency (bsu_aclf_t *ctx, bsu_aclf_frequency_t freq)
{
dbg_assert (freq < BSU_ACLF_FREQ_NB);
*((bsu_aclf_frequency_t*) &ctx->frequency) = freq;
- if (freq == BSU_ACLF_FREQ_60HZ)
+ switch (freq)
+ {
+ case BSU_ACLF_FREQ_60HZ:
*((bsu_aclf_bp_t*) &ctx->beacon_period_theo_tck) =
BSU_ACLF_BP_60HZ_TCK;
- else
+ break;
+ case BSU_ACLF_FREQ_50HZ:
*((bsu_aclf_bp_t*) &ctx->beacon_period_theo_tck) =
BSU_ACLF_BP_50HZ_TCK;
+ break;
+ case BSU_ACLF_FREQ_CABLE:
+ case BSU_ACLF_FREQ_UNKNOWN:
+ *((bsu_aclf_bp_t*) &ctx->beacon_period_theo_tck) =
+ BSU_ACLF_BP_CABLE_TCK;
+ break;
+ default:
+ dbg_assert_default ();
+ }
}
/**
@@ -82,10 +94,7 @@ bsu_aclf_truncate_beacon_period (bsu_aclf_t *ctx)
uint clk_max_tck =
ctx->beacon_period_theo_tck
+ BITS_ONES (HPAV_BEACON_BTO_VALID_BITS);
- /* Special cases for cable mode. */
- if (ctx->beacon_period_tck == 0)
- ctx->beacon_period_tck = BSU_ACLF_BP_50HZ_TCK;
- else if (ctx->beacon_period_tck > clk_max_tck)
+ if (ctx->beacon_period_tck > clk_max_tck)
ctx->beacon_period_tck = clk_max_tck;
else if (ctx->beacon_period_tck < clk_min_tck)
ctx->beacon_period_tck = clk_min_tck;
@@ -94,30 +103,33 @@ bsu_aclf_truncate_beacon_period (bsu_aclf_t *ctx)
void
bsu_aclf_track_powerline (bsu_aclf_t *ctx)
{
- u32 cross_date = phy_clock_get_zero_cross_captured_date (ctx->phy);
- if (ctx->pwl_sync.trig_present && ctx->pwl_sync.init)
- {
- uint hinterval_tck = ctx->pwl_sync.cross_interval_tck / 2;
- dbg_assert (hinterval_tck);
- uint diff_tck = cross_date - ctx->pwl_sync.cross_date;
- uint nb_cross = (diff_tck + hinterval_tck / 2) / hinterval_tck;
- /* Compute the estimated cross. */
- ctx->pwl_sync.cross_est_date +=
- ctx->pwl_sync.w_err_tck + nb_cross * hinterval_tck;
- int err_tck = cross_date - ctx->pwl_sync.cross_est_date;
- ctx->pwl_sync.w_err_tck =
- (err_tck >> BSU_ACLF_PWL_E0)
- + (ctx->pwl_sync.w_err_tck >> BSU_ACLF_PWL_W0);
- ctx->pwl_sync.cross_date = cross_date;
- ctx->pwl_sync.cross_interval_tck += ctx->pwl_sync.w_err_tck;
- }
- else
+ if (CONFIG_ACLF_TRACKING)
{
- /* Simply initialise the PLL for the next step. */
- ctx->pwl_sync.cross_date = cross_date;
- ctx->pwl_sync.cross_est_date = cross_date;
- ctx->pwl_sync.w_err_tck = 0;
- ctx->pwl_sync.init = true;
+ u32 cross_date = phy_clock_get_zero_cross_captured_date (ctx->phy);
+ if (ctx->pwl_sync.trig_present && ctx->pwl_sync.init)
+ {
+ uint hinterval_tck = ctx->pwl_sync.cross_interval_tck / 2;
+ dbg_assert (hinterval_tck);
+ uint diff_tck = cross_date - ctx->pwl_sync.cross_date;
+ uint nb_cross = (diff_tck + hinterval_tck / 2) / hinterval_tck;
+ /* Compute the estimated cross. */
+ ctx->pwl_sync.cross_est_date +=
+ ctx->pwl_sync.w_err_tck + nb_cross * hinterval_tck;
+ int err_tck = cross_date - ctx->pwl_sync.cross_est_date;
+ ctx->pwl_sync.w_err_tck =
+ (err_tck >> BSU_ACLF_PWL_E0)
+ + (ctx->pwl_sync.w_err_tck >> BSU_ACLF_PWL_W0);
+ ctx->pwl_sync.cross_date = cross_date;
+ ctx->pwl_sync.cross_interval_tck += ctx->pwl_sync.w_err_tck;
+ }
+ else
+ {
+ /* Simply initialise the PLL for the next step. */
+ ctx->pwl_sync.cross_date = cross_date;
+ ctx->pwl_sync.cross_est_date = cross_date;
+ ctx->pwl_sync.w_err_tck = 0;
+ ctx->pwl_sync.init = true;
+ }
}
}
@@ -128,11 +140,19 @@ bsu_aclf_shift_beacon_period_start_date (bsu_aclf_t *ctx)
dbg_assert (ctx);
for (i = 0; i < BSU_ACLF_BPSD_NB - 1; i++)
ctx->bpsd[i] = ctx->bpsd[i+1];
- /* For the last beacon period start date, add the difference of the
- * previous one, this should help the station to keep a
- * synchronisation near the CCo's clock even if it miss 5 beacons. */
- ctx->bpsd[BSU_ACLF_BPSD_NB - 1] +=
- ctx->bpsd[BSU_ACLF_BPSD_NB - 2] - ctx->bpsd[BSU_ACLF_BPSD_NB - 3];
+ if (CONFIG_ACLF_TRACKING)
+ {
+ /* For the last beacon period start date, add the difference of the
+ * previous one, this should help the station to keep a
+ * synchronisation near the CCo's clock even if it miss 5 beacons. */
+ ctx->bpsd[BSU_ACLF_BPSD_NB - 1] +=
+ ctx->bpsd[BSU_ACLF_BPSD_NB - 2] - ctx->bpsd[BSU_ACLF_BPSD_NB - 3];
+ }
+ else
+ {
+ ctx->bpsd[BSU_ACLF_BPSD_NB - 1] =
+ ctx->bpsd[BSU_ACLF_BPSD_NB - 2] + ctx->beacon_period_theo_tck;
+ }
ctx->beacon_period_tck = ctx->bpsd[1] - ctx->bpsd[0];
}
@@ -142,15 +162,15 @@ bsu_aclf_ac_compute_beacon_period_start_date (bsu_aclf_t *ctx)
dbg_assert (ctx);
uint i;
int bto;
- uint bpsd_delay_tck = MAC_MS_TO_TCK (ctx->bpsd_delay_ms);
- dbg_assert (bpsd_delay_tck <= ctx->beacon_period_theo_tck / 2);
- if (ctx->pwl_sync.trig_present)
+ if (CONFIG_ACLF_TRACKING && ctx->pwl_sync.trig_present)
+ {
ctx->beacon_period_tck = ctx->pwl_sync.cross_interval_tck;
- bsu_aclf_truncate_beacon_period (ctx);
+ bsu_aclf_truncate_beacon_period (ctx);
+ }
/* First time the function is called. */
if (ctx->bpsd[0] == ctx->bpsd[1])
{
- if (ctx->pwl_sync.trig_present)
+ if (CONFIG_ACLF_TRACKING && ctx->pwl_sync.trig_present)
ctx->bpsd[0] = ctx->pwl_sync.cross_est_date;
else
ctx->bpsd[0] = phy_date ();
@@ -164,8 +184,10 @@ bsu_aclf_ac_compute_beacon_period_start_date (bsu_aclf_t *ctx)
ctx->bpsd[i] = ctx->bpsd[i+1];
/* Add on the last beacon period start date the beacon period
* estimated. */
- if (ctx->beacon_period_tck == ctx->pwl_sync.cross_interval_tck)
+ if (CONFIG_ACLF_TRACKING
+ && ctx->beacon_period_tck == ctx->pwl_sync.cross_interval_tck)
{
+ dbg_assert (ctx->bpsd_delay_ms <= ctx->beacon_period_theo_tck / 2);
uint pwl_cross_tck = ctx->beacon_period_tck / 2;
u32 bpsd_last =
ctx->pwl_sync.cross_est_date
@@ -202,10 +224,8 @@ void
bsu_aclf_acl_frequency_detection (bsu_aclf_t *ctx)
{
ctx->beacon_period_tck = 0;
- u32 now = phy_date ();
bool zc_activity = false;
- /* Protection for maximus. */
- if (less_mod2p32 (now, phy_date ()))
+ if (CONFIG_ACLF_TRACKING)
{
uint nb = 0, sum = 0;
u32 cross_new_date, cross_old_date;
@@ -241,14 +261,14 @@ bsu_aclf_acl_frequency_detection (bsu_aclf_t *ctx)
}
}
/* Frequency can now be configured. */
- if (zc_activity)
+ if (CONFIG_ACLF_TRACKING && zc_activity)
{
/* A 0_cross activity without a trig present means that all intervals
* computed are not valid. */
if (ctx->pwl_sync.trig_present == false)
{
bsu_aclf_set_frequency (ctx, BSU_ACLF_FREQ_UNKNOWN);
- ctx->beacon_period_tck = BSU_ACLF_BP_50HZ_TCK;
+ ctx->beacon_period_tck = ctx->beacon_period_theo_tck;
}
else
{
@@ -256,15 +276,16 @@ bsu_aclf_acl_frequency_detection (bsu_aclf_t *ctx)
bsu_aclf_set_frequency (ctx, BSU_ACLF_FREQ_50HZ);
else
bsu_aclf_set_frequency (ctx, BSU_ACLF_FREQ_60HZ);
+ bsu_aclf_truncate_beacon_period (ctx);
}
}
- /* No 0_cross activity, means medium is a cable. */
+ /* No 0_cross activity, means medium is a cable.
+ * or CONFIG_ACLF_TRACKING not set. */
else
{
bsu_aclf_set_frequency (ctx, BSU_ACLF_FREQ_CABLE);
- ctx->beacon_period_tck = BSU_ACLF_BP_50HZ_TCK;
+ ctx->beacon_period_tck = ctx->beacon_period_theo_tck;
}
- bsu_aclf_truncate_beacon_period (ctx);
}
void
diff --git a/cesar/bsu/aclf/test/utest/Config b/cesar/bsu/aclf/test/utest/Config
index 7e0f77a8bb..2ab0d84445 100644
--- a/cesar/bsu/aclf/test/utest/Config
+++ b/cesar/bsu/aclf/test/utest/Config
@@ -1,3 +1,5 @@
CONFIG_TRACE = y
CONFIG_STATS = y
CONFIG_ACLF_SYNC_TO_SLOWER_WEIGHT_NB=1000000
+CONFIG_ACLF_TRACKING[target-cable] = n
+CONFIG_ACLF_TRACKING[target-tracking] = y
diff --git a/cesar/bsu/aclf/test/utest/Makefile b/cesar/bsu/aclf/test/utest/Makefile
index b9c10002e8..4d38a48e18 100644
--- a/cesar/bsu/aclf/test/utest/Makefile
+++ b/cesar/bsu/aclf/test/utest/Makefile
@@ -1,7 +1,19 @@
BASE = ../../../..
-HOST_PROGRAMS = aclf
-aclf_SOURCES = aclf.c common.c bpsd.c freq.c
-aclf_MODULES = lib bsu/aclf hal/timer/stub
+BUILD_TYPES = target-tracking target-cable
+
+TARGET_tracking=
+TARGET_cable=
+
+COMMON_SOURCES = aclf.c common.c bpsd.c freq.c
+COMMON_MODULES = lib bsu/aclf hal/timer/stub
+
+TARGET_tracking_PROGRAMS = test_aclf_tracking
+test_aclf_tracking_SOURCES = $(COMMON_SOURCES)
+test_aclf_tracking_MODULES = $(COMMON_MODULES)
+
+TARGET_cable_PROGRAMS = test_aclf_cable
+test_aclf_cable_SOURCES = $(COMMON_SOURCES)
+test_aclf_cable_MODULES = $(COMMON_MODULES)
include $(BASE)/common/make/top.mk
diff --git a/cesar/bsu/aclf/test/utest/src/bpsd.c b/cesar/bsu/aclf/test/utest/src/bpsd.c
index d3a8d210e2..d5c25175e6 100644
--- a/cesar/bsu/aclf/test/utest/src/bpsd.c
+++ b/cesar/bsu/aclf/test/utest/src/bpsd.c
@@ -13,6 +13,7 @@
#include "common/std.h"
#include "lib/test.h"
#include "common.h"
+#include "config/aclf/tracking.h"
#include <string.h>
void
@@ -134,6 +135,7 @@ test_case_bpsd_ac_compute (test_t t)
ctx.aclf->pwl_sync.trig_present = false;
ctx.phy->frequency_hz = 50.0;
*((u32*)&ctx.aclf->beacon_period_theo_tck) = BSU_ACLF_BP_50HZ_TCK;
+ ctx.aclf->beacon_period_tck = ctx.aclf->beacon_period_theo_tck;
ctx.aclf->pwl_sync.cross_interval_tck = BSU_ACLF_BP_50HZ_TCK;
uint i;
for (i = 0; i < BSU_ACLF_BPSD_NB; i++)
@@ -199,8 +201,11 @@ void
test_suite_aclf__track_powerline (test_t t)
{
test_suite_begin (t, "Track PowerLine");
- test_case_powerline_stable (t);
- test_case_powerline_unstable (t);
+ if (CONFIG_ACLF_TRACKING)
+ {
+ test_case_powerline_stable (t);
+ test_case_powerline_unstable (t);
+ }
test_case_bpsd_ac_compute (t);
test_case_sync_clear (t);
}
diff --git a/cesar/bsu/aclf/test/utest/src/freq.c b/cesar/bsu/aclf/test/utest/src/freq.c
index 8e23fa529a..bc1e983cf0 100644
--- a/cesar/bsu/aclf/test/utest/src/freq.c
+++ b/cesar/bsu/aclf/test/utest/src/freq.c
@@ -42,11 +42,14 @@ test_aclf_verify_beacon_period (
(bp >= BSU_ACLF_50HZ_CLK_MIN_TCK
&& bp <= BSU_ACLF_50HZ_CLK_MAX_TCK)
|| (bp >= BSU_ACLF_60HZ_CLK_MIN_TCK
- && bp <= BSU_ACLF_60HZ_CLK_MAX_TCK));
- if ((bp_freq_tck >= BSU_ACLF_50HZ_CLK_MIN_TCK
- && bp_freq_tck <= BSU_ACLF_50HZ_CLK_MAX_TCK)
- || (bp_freq_tck >= BSU_ACLF_60HZ_CLK_MIN_TCK
+ && bp <= BSU_ACLF_60HZ_CLK_MAX_TCK)
+ || (bp == BSU_ACLF_BP_CABLE_TCK));
+ if (((bp_freq_tck >= BSU_ACLF_50HZ_CLK_MIN_TCK
+ && bp_freq_tck <= BSU_ACLF_50HZ_CLK_MAX_TCK)
+ || (bp_freq_tck >= BSU_ACLF_60HZ_CLK_MIN_TCK
&& bp_freq_tck <= BSU_ACLF_60HZ_CLK_MAX_TCK))
+ && (ctx->aclf->frequency == BSU_ACLF_FREQ_60HZ
+ || ctx->aclf->frequency == BSU_ACLF_FREQ_50HZ))
{
int diff_tck = bp_freq_tck - bp;
test_fail_unless (diff_tck >= -25 && diff_tck <= 25);
@@ -56,7 +59,8 @@ test_aclf_verify_beacon_period (
&& ctx->aclf->frequency == BSU_ACLF_FREQ_50HZ));
}
else
- test_fail_unless (ctx->aclf->frequency == BSU_ACLF_FREQ_UNKNOWN);
+ test_fail_unless (ctx->aclf->frequency == BSU_ACLF_FREQ_UNKNOWN
+ || ctx->aclf->frequency == BSU_ACLF_FREQ_CABLE);
}
/**
diff --git a/cesar/common/config-sets/plc-board b/cesar/common/config-sets/plc-board
index 62d692e997..e986e45fa4 100644
--- a/cesar/common/config-sets/plc-board
+++ b/cesar/common/config-sets/plc-board
@@ -1,3 +1,4 @@
+CONFIG_ACLF_TRACKING = y
CONFIG_BLK_SLACK = 512
CONFIG_DEBUG_CLAIM = n
CONFIG_GPIO_LED_TRAFFIC = y