summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cesar/bsu/aclf/src/aclf.c39
1 files changed, 23 insertions, 16 deletions
diff --git a/cesar/bsu/aclf/src/aclf.c b/cesar/bsu/aclf/src/aclf.c
index fb60891420..ece831093c 100644
--- a/cesar/bsu/aclf/src/aclf.c
+++ b/cesar/bsu/aclf/src/aclf.c
@@ -151,35 +151,42 @@ bsu_aclf_ac_compute_beacon_period_start_date (bsu_aclf_t *ctx)
void
bsu_aclf_acl_frequency_detection (bsu_aclf_t *ctx)
{
- uint diff_zc_tck;
+ ctx->beacon_period_tck = 0;
u32 now = phy_date ();
- u32 zero_cross_new_date, zero_cross_date, wait_until_date;
- /* Get the last zero cross date from hardware. */
- zero_cross_date = zero_cross_new_date =
- phy_clock_get_zero_cross_captured_date (ctx->phy);
/* Protection for maximus. */
if (less_mod2p32 (now, phy_date ()))
{
+ uint nb = 0, sum = 0;
+ u32 cross_new_date, cross_old_date;
/* Catch the first zero cross.
* If the frequency does not change the expiration should stop
* the loop. */
- wait_until_date = phy_date () + MAC_MS_TO_TCK (50);
- while (lesseq_mod2p32 (phy_date (), wait_until_date)
- && zero_cross_new_date == zero_cross_date)
- zero_cross_new_date =
+ u32 wait_until_date = phy_date () + MAC_MS_TO_TCK (500);
+ cross_new_date = cross_old_date =
+ phy_clock_get_zero_cross_captured_date (ctx->phy);
+ while (lesseq_mod2p32 (phy_date (), wait_until_date))
+ {
+ cross_new_date =
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;
+ }
+ }
+ /* Protection for Malika DK without trig 50Hz. */
+ if (!sum)
+ ctx->beacon_period_tck = BSU_ACLF_BP_50HZ_TCK;
+ else
+ ctx->beacon_period_tck = 2 * (sum / nb);
+ ctx->zero_cross_last_date = cross_new_date;
}
- /* Compute the beacon period from the zero crossing.
- * Beacon period is twice the zero crossing. Zero crossing is only
- * store by hardware on a rising edge of the PowerLine cycle.*/
- diff_zc_tck = zero_cross_new_date - zero_cross_date;
- ctx->beacon_period_tck = 2 * diff_zc_tck;
- if (diff_zc_tck == 0
+ if (ctx->beacon_period_tck == 0
|| ctx->beacon_period_tck >= BSU_ACLF_BP_55HZ_TCK)
BSU_ACLF_SET_FREQUENCY (50);
else
BSU_ACLF_SET_FREQUENCY (60);
- ctx->zero_cross_last_date = zero_cross_new_date;
bsu_aclf_truncate_beacon_period (ctx);
}