summaryrefslogtreecommitdiff
path: root/cesar/bsu/aclf/test/utest/src/freq.c
blob: a1a3f9223f1b0ebddd2b8074df9b9afe61d9f852 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* Cesar project {{{
 *
 * Copyright (C) 2010 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    bsu/aclf/test/utest/src/freq.c
 * \brief   Frequency test error.
 * \ingroup bsu_aclf
 */
#include "common/std.h"
#include "mac/common/timings.h"
#include "lib/test.h"
#include "lib/rnd.h"
#include "bsu/aclf/test/utest/common.h"
#include "bsu/aclf/test/utest/obj/zc_cross.h"

/** Will be used for the zc cross detection simulation. */
static bsu_aclf_test_t test;

void
test_case_aclf_all_frequencies (test_t t)
{
    test_case_begin (t, "All frequency possible");
    test_begin (t, "Frequency increase.")
    {
        u32 acl_zc;
        lib_rnd_t rnd;
        lib_rnd_init (&rnd, 0x12324);
        bsu_aclf_test_init (&test);
        for (test.phy.frequency = 40, test.phy.zc_cross_index = 0;
             test.phy.frequency <= 80;
             test.phy.frequency++, test.phy.zc_cross_index++)
        {
            if (test.phy.frequency)
                acl_zc = MAC_MS_TO_TCK (1000 / test.phy.frequency) / 2;
            else
                acl_zc = 0;
            test.phy.phy = lib_rnd32 (&rnd);
            test.phy.zc = test.phy.phy - acl_zc + 1000;
            bsu_aclf_acl_frequency_detection (test.aclf);
            if (test.phy.frequency < 56)
                test_fail_unless (test.aclf->frequency == BSU_ACLF_FREQ_50HZ);
            else
                test_fail_unless (test.aclf->frequency == BSU_ACLF_FREQ_60HZ);
        }
        bsu_aclf_test_uninit (&test);
    }
    test_end;
}

void
test_suite_aclf__frequency (test_t t)
{
    test_suite_begin (t, "Frequency tests");
    test_case_aclf_all_frequencies (t);
}

static void
phy_zero_cross (bsu_aclf_test_phy_t *test)
{
    u32 last_zc;
    /* Compute last ZC. */
    if (test->frequency)
    {
        last_zc = test->zc + zero_cross[test->zc_cross_index];
        if (lesseq_mod2p32 (last_zc, test->phy))
            test->zc = last_zc;
    }
}

u32
phy_date (phy_t *ctx)
{
    bsu_aclf_test_phy_t *test = (bsu_aclf_test_phy_t *) ctx;
    dbg_assert (ctx);
    phy_zero_cross (test);
    test->phy += 100;
    return test->phy;
}