summaryrefslogtreecommitdiff
path: root/cesar/hal/phy/src/hlut.c
blob: da3a3b78efa06751c82ccab88291ee92036770d8 (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
83
84
85
86
87
88
89
90
91
92
93
94
95
/* Cesar project {{{
 *
 * Copyright (C) 2012 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    hal/phy/src/hlut.c
 * \brief   Table parameters and registers for HLUT.
 * \ingroup hal_phy
 */
#include "common/std.h"
#include "lib/stats.h"
#include "hal/arch/platform.h"
#include "hal/phy/inc/regs.h"
#include "hal/phy/inc/hlut.h"

/** HLUT tunable parameters. */
struct hlut_tunable_parameters_t
{
    /** HLUT span variable. */
    u32 span;
    /** HLUT offset variable. */
    u32 offset;
    /** HLUT threshold variable. */
    u32 threshold;
};
typedef struct hlut_tunable_parameters_t hlut_tunable_parameters_t;

/** Global tunable parameters. */
static hlut_tunable_parameters_t hlut_tunable_params = {
    PHY_HLUT_SPAN_DEFAULT,
    PHY_HLUT_THRESHOLD_DEFAULT,
    PHY_HLUT_OFFSET_DEFAULT,
};

/**
 * Initialise the tunable parameters settable by the lib stats.
 */
static inline void
phy_hlut_stats_init (void)
{
#if CONFIG_STATS
    lib_stats_set_stat_value_notype ("HLUT_SPAN",
                                     &hlut_tunable_params.span,
                                     LIB_STATS_ACCESS_WRITE_ONLY,
                                     LIB_STATS_DEBUG);
    lib_stats_set_stat_value_notype ("HLUT_OFFSET",
                                     &hlut_tunable_params.offset,
                                     LIB_STATS_ACCESS_WRITE_ONLY,
                                     LIB_STATS_DEBUG);
    lib_stats_set_stat_value_notype ("HLUT_THRESHOLD",
                                     &hlut_tunable_params.threshold,
                                     LIB_STATS_ACCESS_WRITE_ONLY,
                                     LIB_STATS_DEBUG);
#endif /* CONFIG_STATS */
}

void
phy_hlut_init (void)
{
    /* This is not valid on SPC300. */
    if (arch_is_mse500 ())
    {
        /** HLUT table parameters for the gain function. */
        static const u32 phy_hlut_table[] = {
            0,  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, 41, 41, 41, 41, 41, 41,
            41, 41, 41, 41, 41, 41, 41, 41,
            41, 41, 41, 41, 41, 41, 41, 41
        };
        uint i;
        /* Set the MAGIC HLUT parameters. */
        for (i = 0; i < COUNT (phy_hlut_table); i++)
            PHY_DSPSS_MAGIC_HLUT_TABLE_n[i] = phy_hlut_table[i];
        phy_hlut_stats_init ();
    }
}

void
phy_hlut_set_tunable (void)
{
    /* This is not valid on SPC300. */
    if (arch_is_mse500 ())
    {
        PHY_DSPSS_MAGIC_HLUT_SPAN = hlut_tunable_params.span;
        PHY_DSPSS_MAGIC_HLUT_OFFSET = hlut_tunable_params.offset;
        PHY_DSPSS_MAGIC_HLUT_THRESHOLD = hlut_tunable_params.threshold;
    }
}