-uint Daq_Set_SampleRate(uint rate, uint force)
-
-{
- DECLARE_GLOBAL_DATA_PTR;
- uint mclk_divisor; /* MCLK divisor */
- uint rate_curr; /* Current sample rate */
-
- /*
- * Limit the sample rate to some sensible values.
- */
- if (Daq64xSampling) {
- if (rate > MAX_64x_SAMPLE_RATE) {
- rate = MAX_64x_SAMPLE_RATE;
- }
- }
- else {
- if (rate > MAX_128x_SAMPLE_RATE) {
- rate = MAX_128x_SAMPLE_RATE;
- }
- }
- if (rate < MIN_SAMPLE_RATE) {
- rate = MIN_SAMPLE_RATE;
- }
-
- /* Check to see if we are really changing rates */
- rate_curr = Daq_Get_SampleRate();
- if ((rate != rate_curr) || force) {
- /*
- * Dynamically adjust MCLK based on the new sample rate.
- */
-
- /* Compute the divisors */
- mclk_divisor = BRG_INT_CLK / (rate * MCLK_DIVISOR * SCLK_DIVISOR);
-
- /* Setup MCLK */
- Daq_BRG_Set_Count(MCLK_BRG, mclk_divisor);
-
- /* Setup SCLK */
-# ifdef RUN_SCLK_ON_BRG_INT
- Daq_BRG_Set_Count(SCLK_BRG, mclk_divisor * MCLK_DIVISOR);
-# else
- Daq_BRG_Set_Count(SCLK_BRG, MCLK_DIVISOR);
-# endif
-
-# ifdef RUN_LRCLK_ON_BRG_INT
- Daq_BRG_Set_Count(LRCLK_BRG,
- mclk_divisor * MCLK_DIVISOR * SCLK_DIVISOR);
-# else
- Daq_BRG_Set_Count(LRCLK_BRG, SCLK_DIVISOR);
-# endif
-
- /* Read the BRG's to return the actual sample rate. */
- rate_curr = Daq_Get_SampleRate();
- }
-
- return (rate_curr);
-}
-