summaryrefslogtreecommitdiff
path: root/hifi/xaf/hifi-dpf/include/xf-timebase.h
blob: 7b27d580c9406c82c86180211cdbe4834f0982f8 (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*******************************************************************************
* Copyright (C) 2018 Cadence Design Systems, Inc.
* 
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to use this Software with Cadence processor cores only and 
* not with any other processors and platforms, subject to
* the following conditions:
* 
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
* 
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

******************************************************************************/

/*******************************************************************************
 * xf-timebase.h
 *
 * Common timebase for deadline-driven scheduler
 *
 *******************************************************************************/

#ifndef __XF_H
#error "xf-timebase.h mustn't be included directly"
#endif

/*******************************************************************************
 * Timebase for deadline-driven scheduler
 ******************************************************************************/
#ifdef XAF_ENABLE_NON_HIKEY
/* ...set internal scheduler frequency as a LCM of all supported sample rates;
 * it is in general not a problem to have large number here, however it should
 * be noted that maximal-size audio-buffer that we handle, when expressed in
 * ticks of this virtual frequency, must not exceed 2**31 (for otherwise
 * scheduler timestamp comparison function will misbehave).
 */
#define XF_TIMEBASE_FREQ           (4 * 3 * 56448000U)
/* ...add paranoic check considering maximal audio-buffer duration as 0.1 sec */
C_BUG((u32)(XF_TIMEBASE_FREQ / 10) >= (1 << 31));
#else
/* ...set internal scheduler frequency as a LCM of all supported sample rates */
#define XF_TIMEBASE_FREQ           56448000U
#endif
/* ...supported sampling rates */
C_BUG(XF_TIMEBASE_FREQ % 4000);
C_BUG(XF_TIMEBASE_FREQ % 8000);
C_BUG(XF_TIMEBASE_FREQ % 11025);
C_BUG(XF_TIMEBASE_FREQ % 12000);
C_BUG(XF_TIMEBASE_FREQ % 16000);
C_BUG(XF_TIMEBASE_FREQ % 22050);
C_BUG(XF_TIMEBASE_FREQ % 24000);
C_BUG(XF_TIMEBASE_FREQ % 32000);
C_BUG(XF_TIMEBASE_FREQ % 44100);
C_BUG(XF_TIMEBASE_FREQ % 48000);
C_BUG(XF_TIMEBASE_FREQ % 64000);
C_BUG(XF_TIMEBASE_FREQ % 88200);
C_BUG(XF_TIMEBASE_FREQ % 96000);
C_BUG(XF_TIMEBASE_FREQ % 128000);
C_BUG(XF_TIMEBASE_FREQ % 176400);
C_BUG(XF_TIMEBASE_FREQ % 192000);

/* ...calculate upsampling factor for given sample rate */
static inline u32 xf_timebase_factor(u32 sample_rate)
{
    /* ...probably we can tolerate single division */
    switch(sample_rate)
    {
    case 4000:
        return XF_TIMEBASE_FREQ / 4000;
    case 8000:
        return XF_TIMEBASE_FREQ / 8000;
    case 11025:
        return XF_TIMEBASE_FREQ / 11025;
    case 12000:
        return XF_TIMEBASE_FREQ / 11025;
    case 16000:
        return XF_TIMEBASE_FREQ / 16000;
    case 22050:
        return XF_TIMEBASE_FREQ / 22050;
    case 24000:
        return XF_TIMEBASE_FREQ / 24000;
    case 32000:
        return XF_TIMEBASE_FREQ / 32000;
    case 44100:
        return XF_TIMEBASE_FREQ / 44100;
    case 48000:
        return XF_TIMEBASE_FREQ / 48000;
    case 64000:
        return XF_TIMEBASE_FREQ / 64000;
    case 88200:
        return XF_TIMEBASE_FREQ / 88200;
    case 96000:
        return XF_TIMEBASE_FREQ / 96000;
    case 128000:
        return XF_TIMEBASE_FREQ / 128000;
    case 176400:
        return XF_TIMEBASE_FREQ / 176400;
    case 192000:
        return XF_TIMEBASE_FREQ / 192000;
    default:
        return 0;
    }
}

/* ...core timebase */
static inline u32 xf_core_timebase(u32 core)
{
    xf_core_data_t     *cd = XF_CORE_DATA(core);
    
    /* ...get local scheduler timebase */
    return xf_sched_timestamp(&cd->sched);
}

/* ...compare timestamps */
static inline int xf_time_after(u32 a, u32 b)
{
    return ((s32)(a - b) > 0);
}
    
/* ...compare timstamps */
static inline int xf_time_before(u32 a, u32 b)
{
    return ((s32)(a - b) < 0);
}