3 #define SRC_RATE 48000U
4 #define reg(n) DSP->base + n
7 int SRCInit ( DEV_STRUCT
* DSP
)
12 /* Clear all SRC RAM then init - keep SRC disabled until done */
13 if (WaitBitd (reg(CONC_dSRCIO_OFF
), SRC_BUSY_BIT
, 0, 1000))
14 return (SRC_ERR_NOT_BUSY_TIMEOUT
);
16 pci_outl(reg(CONC_dSRCIO_OFF
), SRC_DISABLE
);
18 for( i
= 0; i
< 0x80; ++i
)
19 if (SRC_SUCCESS
!= (retVal
= SRCRegWrite(DSP
, (u16_t
)i
, 0U)))
22 if (SRC_SUCCESS
!= (retVal
= SRCRegWrite(DSP
, SRC_SYNTH_BASE
+ SRC_TRUNC_N_OFF
, 16 << 4)))
24 if (SRC_SUCCESS
!= (retVal
= SRCRegWrite(DSP
, SRC_SYNTH_BASE
+ SRC_INT_REGS_OFF
, 16 << 10)))
26 if (SRC_SUCCESS
!= (retVal
= SRCRegWrite(DSP
, SRC_DAC_BASE
+ SRC_TRUNC_N_OFF
, 16 << 4)))
28 if (SRC_SUCCESS
!= (retVal
= SRCRegWrite(DSP
, SRC_DAC_BASE
+ SRC_INT_REGS_OFF
, 16 << 10)))
30 if (SRC_SUCCESS
!= (retVal
= SRCRegWrite(DSP
, SRC_SYNTH_LVOL
, 1 << 12)))
32 if (SRC_SUCCESS
!= (retVal
= SRCRegWrite(DSP
, SRC_SYNTH_RVOL
, 1 << 12)))
34 if (SRC_SUCCESS
!= (retVal
= SRCRegWrite(DSP
, SRC_DAC_LVOL
, 1 << 12)))
36 if (SRC_SUCCESS
!= (retVal
= SRCRegWrite(DSP
, SRC_DAC_RVOL
, 1 << 12)))
38 if (SRC_SUCCESS
!= (retVal
= SRCRegWrite(DSP
, SRC_ADC_LVOL
, 1 << 12)))
40 if (SRC_SUCCESS
!= (retVal
= SRCRegWrite(DSP
, SRC_ADC_RVOL
, 1 << 12)))
43 /* default some rates */
44 SRCSetRate(DSP
, SRC_SYNTH_BASE
, SRC_RATE
);
45 SRCSetRate(DSP
, SRC_DAC_BASE
, SRC_RATE
);
46 SRCSetRate(DSP
, SRC_ADC_BASE
, SRC_RATE
);
48 /* now enable the whole deal */
49 if (WaitBitd (reg(CONC_dSRCIO_OFF
), SRC_BUSY_BIT
, 0, 1000))
50 return (SRC_ERR_NOT_BUSY_TIMEOUT
);
52 pci_outl(reg(CONC_dSRCIO_OFF
), 0UL);
58 int SRCRegRead(DEV_STRUCT
* DSP
, u16_t reg
, u16_t
*data
)
63 if (WaitBitd (reg(CONC_dSRCIO_OFF
), SRC_BUSY_BIT
, 0, 1000))
64 return (SRC_ERR_NOT_BUSY_TIMEOUT
);
66 dtemp
= pci_inl(reg(CONC_dSRCIO_OFF
));
68 /* assert a read request */
69 pci_outl(reg(CONC_dSRCIO_OFF
),
70 (dtemp
& SRC_CTLMASK
) | ((u32_t
) reg
<< 25));
72 /* now wait for the data */
73 if (WaitBitd (reg(CONC_dSRCIO_OFF
), SRC_BUSY_BIT
, 0, 1000))
74 return (SRC_ERR_NOT_BUSY_TIMEOUT
);
77 *data
= (u16_t
) pci_inl(reg(CONC_dSRCIO_OFF
));
83 int SRCRegWrite(DEV_STRUCT
* DSP
, u16_t reg
, u16_t val
)
89 if (WaitBitd (reg(CONC_dSRCIO_OFF
), SRC_BUSY_BIT
, 0, 1000))
90 return (SRC_ERR_NOT_BUSY_TIMEOUT
);
92 dtemp
= pci_inl(reg(CONC_dSRCIO_OFF
));
94 /* assert the write request */
95 pci_outl(reg(CONC_dSRCIO_OFF
),
96 (dtemp
& SRC_CTLMASK
) | SRC_WENABLE
| ((u32_t
) reg
<< 25) | val
);
102 void SRCSetRate(DEV_STRUCT
* DSP
, char base
, u16_t rate
)
104 u32_t freq
, dtemp
, i
;
105 u16_t N
, truncM
, truncStart
, wtemp
;
108 if( base
!= SRC_ADC_BASE
)
110 /* freeze the channel */
111 dtemp
= base
== SRC_SYNTH_BASE
? SRC_SYNTHFREEZE
: SRC_DACFREEZE
;
112 for( i
= 0; i
< SRC_IOPOLL_COUNT
; ++i
)
113 if( !(pci_inl(reg(CONC_dSRCIO_OFF
)) & SRC_BUSY
) )
115 pci_outl(reg(CONC_dSRCIO_OFF
),
116 (pci_inl(reg(CONC_dSRCIO_OFF
)) & SRC_CTLMASK
) |
119 /* calculate new frequency and write it - preserve accum */
120 /* please don't try to understand. */
121 freq
= ((u32_t
) rate
<< 16) / 3000U;
122 SRCRegRead(DSP
, base
+ SRC_INT_REGS_OFF
, &wtemp
);
124 SRCRegWrite(DSP
, base
+ SRC_INT_REGS_OFF
,
126 (u16_t
) (freq
>> 6) & 0xfc00);
128 SRCRegWrite(DSP
, base
+ SRC_VFREQ_FRAC_OFF
, (u16_t
) freq
>> 1);
130 /* un-freeze the channel */
131 dtemp
= base
== SRC_SYNTH_BASE
? SRC_SYNTHFREEZE
: SRC_DACFREEZE
;
132 for( i
= 0; i
< SRC_IOPOLL_COUNT
; ++i
)
133 if( !(pci_inl(reg(CONC_dSRCIO_OFF
)) & SRC_BUSY
) )
135 pci_outl(reg(CONC_dSRCIO_OFF
),
136 (pci_inl(reg(CONC_dSRCIO_OFF
)) & SRC_CTLMASK
) &
139 else /* setting ADC rate */
141 /* freeze the channel */
142 for( i
= 0; i
< SRC_IOPOLL_COUNT
; ++i
)
143 if( !(pci_inl(reg(CONC_dSRCIO_OFF
)) & SRC_BUSY
) )
145 pci_outl(reg(CONC_dSRCIO_OFF
),
146 (pci_inl(reg(CONC_dSRCIO_OFF
)) & SRC_CTLMASK
) |
151 /* derive oversample ratio */
153 if( N
== 15 || N
== 13 || N
== 11 || N
== 9 )
155 SRCRegWrite(DSP
, SRC_ADC_LVOL
, N
<< 8);
156 SRCRegWrite(DSP
, SRC_ADC_RVOL
, N
<< 8);
158 /* truncate the filter and write n/trunc_start */
159 truncM
= (21*N
- 1) | 1;
164 truncStart
= (239 - truncM
) >> 1;
165 SRCRegWrite(DSP
, base
+ SRC_TRUNC_N_OFF
,
166 (truncStart
<< 9) | (N
<< 4));
172 truncStart
= (119 - truncM
) >> 1;
173 SRCRegWrite(DSP
, base
+ SRC_TRUNC_N_OFF
,
174 0x8000U
| (truncStart
<< 9) | (N
<< 4));
177 /* calculate new frequency and write it - preserve accum */
178 freq
= ((48000UL << 16) / rate
) * N
;
179 SRCRegRead(DSP
, base
+ SRC_INT_REGS_OFF
, &wtemp
);
180 SRCRegWrite(DSP
, base
+ SRC_INT_REGS_OFF
,
182 (u16_t
) (freq
>> 6) & 0xfc00);
183 SRCRegWrite(DSP
, base
+ SRC_VFREQ_FRAC_OFF
, (u16_t
) freq
>> 1);
185 /* un-freeze the channel */
186 for( i
= 0; i
< SRC_IOPOLL_COUNT
; ++i
)
187 if( !(pci_inl(reg(CONC_dSRCIO_OFF
)) & SRC_BUSY
) )
189 pci_outl(reg(CONC_dSRCIO_OFF
),
190 (pci_inl(reg(CONC_dSRCIO_OFF
)) & SRC_CTLMASK
) &