hw_spdif.c
4.02 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#include "c_def.h"
#include "debug.h"
#include "oem.h"
#include "hw_dma.h"
#include "hw_da_pp.h"
#include "hw_spdif.h"
#include "hw_gpio.h"
#include "app_gpio.h"
//U8 spdif_sr_double; /*0, normal, 2, x2; 4, x4*/
//#define SPDIF_OUT_ENABLE
void spdif_init(int channel)
{
volatile U32 tmp;
SPDIF_CONFIG_AHB *spdif_config;
tmp = SPDIF_CONFIG;
spdif_config = (SPDIF_CONFIG_AHB *) &tmp;
#ifdef SPDIF_OUT_ENABLE
spdif_config->spdif_enc_enable = 1;
#else
spdif_config->spdif_enc_enable = 0;
#endif
spdif_config->spdif_dec_enable = 1;
spdif_config->spdif_data_sel = 0;
spdif_config->spdif_enc_inv = 0;
spdif_config->spdif_dec_inv = 0;
//spdif_config->spdif_dec_sr_detect_level = 1;
spdif_config->spdif_dec_sr_detect_start = 0;
//spdif_config->spdif_dec_aux_mask = 0;
spdif_config->sync_err_auto_recover = 0;
//if (MI2S_CHANs == 3)
// spdif_config->spdif_enc_stream = 2;
//else
spdif_config->spdif_enc_stream = 0;
spdif_config->spdif_enc_sample_delay = 6;
SPDIF_CONFIG = tmp;
//spdif_sr_double = 0;
SPDIF_ENC_STATUS_L = 0x0110004;
SPDIF_ENC_STATUS_H = 0x1fb;
}
void spdif_open(int channel)
{
//U32 *pDmaSrc;
//pDmaSrc = (U32 *)DA_SPDIF_IN_FIFO_ADDR;
//DMA_Channel2_Init((U32 *)awInSampleStore[0], pDmaSrc, CD_DA_SECTOR_SIZE/4, SOURCE_DMA_SPDIF_IN);
if (channel == SPDIF_IN_CH_0)
{
spdif_din_select(SPDIF_IN_CH_0);
}
else if (channel == SPDIF_IN_CH_1)
{
spdif_din_select(SPDIF_IN_CH_1);
}
else if (channel == SPDIF_IN_CH_2)
{
spdif_din_select(SPDIF_IN_CH_2);
}
else if (channel == SPDIF_IN_CH_3)
{
spdif_din_select(SPDIF_IN_CH_3);
}
}
void spdif_close(int channel)
{
}
void spdif_fini(void)
{
volatile U32 tmp;
SPDIF_CONFIG_AHB *spdif_config;
tmp = SPDIF_CONFIG;
spdif_config = (SPDIF_CONFIG_AHB *) &tmp;
spdif_config->spdif_enc_enable = 0;
spdif_config->spdif_dec_enable = 0;
spdif_config->spdif_dec_sr_detect_start = 0;
SPDIF_CONFIG = tmp;
}
void spdif_sr_detect_enable(void)
{
volatile U32 tmp;
SPDIF_CONFIG_AHB *spdif_config;
tmp = SPDIF_CONFIG;
spdif_config = (SPDIF_CONFIG_AHB *) &tmp;
spdif_config->spdif_dec_enable = 1;
spdif_config->spdif_dec_sr_detect_start = 1;
SPDIF_CONFIG = tmp;
}
void spdif_dec_enable(void)
{
volatile U32 tmp;
SPDIF_CONFIG_AHB *spdif_config;
tmp = SPDIF_CONFIG;
spdif_config = (SPDIF_CONFIG_AHB *) &tmp;
spdif_config->spdif_dec_enable = 1;
SPDIF_CONFIG = tmp;
}
void spdif_dec_disable(void)
{
volatile U32 tmp;
SPDIF_CONFIG_AHB *spdif_config;
tmp = SPDIF_CONFIG;
spdif_config = (SPDIF_CONFIG_AHB *) &tmp;
spdif_config->spdif_dec_enable = 0;
spdif_config->spdif_dec_sr_detect_start = 0;
SPDIF_CONFIG = tmp;
}
void spdif_sr_detect_disable(void)
{
volatile U32 tmp;
SPDIF_CONFIG_AHB *spdif_config;
tmp = SPDIF_CONFIG;
spdif_config = (SPDIF_CONFIG_AHB *) &tmp;
spdif_config->spdif_dec_sr_detect_start = 0;
SPDIF_CONFIG = tmp;
}
void spdif_din_select(U16 sel)
{
volatile U32 tmp;
SPDIF_CONFIG_AHB *spdif_config;
tmp = SPDIF_CONFIG;
spdif_config = (SPDIF_CONFIG_AHB *) &tmp;
spdif_config->spdif_data_sel = (sel & 0x3);
SPDIF_CONFIG = tmp;
}
void spdif_detect_level(u8 high)
{
#if 0
volatile U32 tmp;
SPDIF_CONFIG_AHB *spdif_config;
tmp = SPDIF_CONFIG;
spdif_config = (SPDIF_CONFIG_AHB *) &tmp;
if (high == 0) {
//detect low
spdif_config->spdif_dec_sr_detect_level = 0;
}
else {
spdif_config->spdif_dec_sr_detect_level = 1;
}
SPDIF_CONFIG = tmp;
#endif
}
void spdif_output_set(U8 con)
{
#ifndef AUDIO_PWM_OUTPUT
volatile U32 temp;
//SPDIF_CONFIGs *spdif_config;
SPDIF_CONFIG_AHB *spdif_config;
//spdif_config = (SPDIF_CONFIGs *)&temp;
spdif_config = (SPDIF_CONFIG_AHB *)&temp;
//temp = 0;
temp = SPDIF_CONFIG;
spdif_config->spdif_enc_enable = TRUE;
SPDIF_CONFIG = temp;
//SPDIF_ENC_STATUS_L = 0x0110004;
//SPDIF_ENC_STATUS_H = 0x1fb;
if (con)
{
//gpio0_SetFunction(SPDIF_OUT_CH_1_PIN , FALSE);
app_gpio_MUXfunction_select(SPDIF_OUT_CH_1_PIN, MUX_SEL_FUNCTION2);
}
else
{
//gpio0_SetFunction(SPDIF_OUT_CH_1_PIN , TRUE);
app_gpio_MUXfunction_select(SPDIF_OUT_CH_1_PIN, MUX_SEL_GPIO_INPUT);
}
#endif
}