summaryrefslogtreecommitdiff
path: root/cesar/bsu/aclf
diff options
context:
space:
mode:
authorNélio Laranjeiro2011-04-19 13:50:53 +0200
committerNélio Laranjeiro2011-05-05 11:28:31 +0200
commitd07482001257c8cf7488ab9bcd42884da3e4b7db (patch)
treea70ffbd98dddc268ed9660e99e35cab391294e1a /cesar/bsu/aclf
parent038a49c82507636c5ba76420bc0e1b333e3dbaa9 (diff)
cesar/bsu/aclf: filter strange 0_cross register dates, refs #2459
0_cross register have sometimes an interval of cross values of 20e3 ticks, a PowerLine cycle is around 250e3 ticks. To avoid a wrong beacon period computation, those values are not used.
Diffstat (limited to 'cesar/bsu/aclf')
-rw-r--r--cesar/bsu/aclf/aclf.h8
-rw-r--r--cesar/bsu/aclf/src/aclf.c28
-rw-r--r--cesar/bsu/aclf/test/utest/src/freq.c41
3 files changed, 50 insertions, 27 deletions
diff --git a/cesar/bsu/aclf/aclf.h b/cesar/bsu/aclf/aclf.h
index b08b71194a..f9619fcf55 100644
--- a/cesar/bsu/aclf/aclf.h
+++ b/cesar/bsu/aclf/aclf.h
@@ -45,16 +45,16 @@ typedef enum bsu_aclf_bp_t bsu_aclf_bp_t;
/** The minimum value for the beacon period in ticks for 50Hz PowerLine. */
#define BSU_ACLF_50HZ_CLK_MIN_TCK \
- BSU_ACLF_BP_50HZ_TCK - BITS_ONES (HPAV_BEACON_BTO_VALID_BITS)
+ (BSU_ACLF_BP_50HZ_TCK - BITS_ONES (HPAV_BEACON_BTO_VALID_BITS))
/** The maximum value for the beacon period in ticks for 50Hz PowerLine. */
#define BSU_ACLF_50HZ_CLK_MAX_TCK \
- BSU_ACLF_BP_50HZ_TCK + BITS_ONES (HPAV_BEACON_BTO_VALID_BITS)
+ (BSU_ACLF_BP_50HZ_TCK + BITS_ONES (HPAV_BEACON_BTO_VALID_BITS))
/** The minimum value for the beacon period in ticks for 60Hz PowerLine. */
#define BSU_ACLF_60HZ_CLK_MIN_TCK \
- BSU_ACLF_BP_60HZ_TCK - BITS_ONES (HPAV_BEACON_BTO_VALID_BITS)
+ (BSU_ACLF_BP_60HZ_TCK - BITS_ONES (HPAV_BEACON_BTO_VALID_BITS))
/** The maximum value for the beacon period in ticks for 60Hz PowerLine. */
#define BSU_ACLF_60HZ_CLK_MAX_TCK \
- BSU_ACLF_BP_60HZ_TCK + BITS_ONES (HPAV_BEACON_BTO_VALID_BITS)
+ (BSU_ACLF_BP_60HZ_TCK + BITS_ONES (HPAV_BEACON_BTO_VALID_BITS))
/** ACLF PowerLine synchronisation information. */
struct bsu_aclf_pwl_sync_t
diff --git a/cesar/bsu/aclf/src/aclf.c b/cesar/bsu/aclf/src/aclf.c
index 4f0ac7463e..b2e580b49c 100644
--- a/cesar/bsu/aclf/src/aclf.c
+++ b/cesar/bsu/aclf/src/aclf.c
@@ -36,6 +36,24 @@
static bsu_aclf_t bsu_aclf_global;
/**
+ * Verify the 0_cross interval dates are possible.
+ * \param ctx the module context.
+ * \param diff_tck the differences between the two 0_cross dates.
+ * \return true if the value is a possible one.
+ */
+static inline bool
+bsu_aclf_zero_cross_is_valid (bsu_aclf_t *ctx, uint diff_tck)
+{
+ /** At this point I still don't know. */
+ if ((diff_tck >= BSU_ACLF_60HZ_CLK_MIN_TCK / 2
+ && diff_tck <= BSU_ACLF_60HZ_CLK_MAX_TCK / 2)
+ || (diff_tck >= BSU_ACLF_50HZ_CLK_MIN_TCK / 2
+ && diff_tck <= BSU_ACLF_50HZ_CLK_MAX_TCK / 2))
+ return true;
+ return false;
+}
+
+/**
* Truncate the beacon period ticks computed to be suitable for BTOs.
* \param ctx the module context.
*
@@ -193,9 +211,13 @@ bsu_aclf_acl_frequency_detection (bsu_aclf_t *ctx)
phy_clock_get_zero_cross_captured_date (ctx->phy);
if (cross_new_date != cross_old_date)
{
- sum += cross_new_date - cross_old_date;
- nb++;
- cross_old_date = cross_new_date;
+ uint diff_tck = cross_new_date - cross_old_date;
+ if (bsu_aclf_zero_cross_is_valid (ctx, diff_tck))
+ {
+ sum += diff_tck;
+ nb++;
+ cross_old_date = cross_new_date;
+ }
}
}
/* Protection for Malika DK without trig 50Hz. */
diff --git a/cesar/bsu/aclf/test/utest/src/freq.c b/cesar/bsu/aclf/test/utest/src/freq.c
index a821eab289..8d79a3b6c2 100644
--- a/cesar/bsu/aclf/test/utest/src/freq.c
+++ b/cesar/bsu/aclf/test/utest/src/freq.c
@@ -27,29 +27,30 @@ bsu_aclf_acl_frequency_detection (bsu_aclf_t *ctx);
/** Verify the beacon period estimated is correct.
* \param t the unit test context.
* \param ctx the bsu_aclf_test context.
- * \param frequency the frequency value used for the test.
+ * \param frequency the frequency value used for the test (*10).
*/
void
test_aclf_verify_beacon_period (
- test_t t, bsu_aclf_test_t *ctx, float frequency)
+ test_t t, bsu_aclf_test_t *ctx, int frequency)
{
test_within (t);
- /* Compute the beacon period from the frequency used by the test.
- * 25.0e6/frequency == PowerLine cycle in ticks.
- * Beacon period is twice the PowerLine cycle.*/
- int diff_tck = 50.0e6 / frequency - ctx->aclf->beacon_period_tck;
- uint clk_min_tck =
- ctx->aclf->beacon_period_theo_tck
- - BITS_ONES (HPAV_BEACON_BTO_VALID_BITS);
- uint clk_max_tck =
- ctx->aclf->beacon_period_theo_tck
- + BITS_ONES (HPAV_BEACON_BTO_VALID_BITS);
+ /* With the new frequency detection algorithm, if the 0_cross is outside
+ * possible values, the default beacon period duration will be used. */
+ uint bp_freq_tck = 500.0e6 / frequency;
+ uint bp = ctx->aclf->beacon_period_tck;
test_fail_unless (
- ctx->aclf->beacon_period_tck == clk_min_tck
- || ctx->aclf->beacon_period_tck == clk_max_tck
- || (diff_tck >= -25 && diff_tck <= 25),
- "Frequency %0.1f bp_tck %d diff_tck %d",
- frequency, ctx->aclf->beacon_period_tck, diff_tck);
+ (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_freq_tck <= BSU_ACLF_60HZ_CLK_MAX_TCK))
+ {
+ int diff_tck = bp_freq_tck - bp;
+ test_fail_unless (diff_tck >= -25 && diff_tck <= 25);
+ }
}
/**
@@ -85,7 +86,7 @@ test_aclf_frequency_variation (test_t t, volatile int frequency, int step)
phy_clock (ctx.phy, ctx.aclf->beacon_period_tck);
bsu_aclf_ac_compute_beacon_period_start_date (ctx.aclf);
}
- test_aclf_verify_beacon_period (t, &ctx, ctx.phy->frequency_hz);
+ test_aclf_verify_beacon_period (t, &ctx, frequency);
}
bsu_aclf_test_uninit (&ctx);
}
@@ -119,7 +120,7 @@ test_aclf_frequency_inc_dec (test_t t, volatile int freq)
phy_clock (ctx.phy, ctx.aclf->beacon_period_tck);
bsu_aclf_ac_compute_beacon_period_start_date (ctx.aclf);
}
- test_aclf_verify_beacon_period (t, &ctx, (float) freq / 10);
+ test_aclf_verify_beacon_period (t, &ctx, freq);
/* Reverse step if frequency is 69 Hz. */
if ((ctx.aclf->frequency == BSU_ACLF_FREQ_50HZ && freq == 575)
|| (ctx.aclf->frequency == BSU_ACLF_FREQ_60HZ && freq == 690))
@@ -145,7 +146,7 @@ test_case_aclf_all_frequencies (test_t t)
frequency = (float) f / 10;
ctx.phy->frequency_hz = frequency;
bsu_aclf_acl_frequency_detection (ctx.aclf);
- test_aclf_verify_beacon_period (t, &ctx, frequency);
+ test_aclf_verify_beacon_period (t, &ctx, f);
}
bsu_aclf_test_uninit (&ctx);
}