dac.h File Reference


Detailed Description

AVR32 ABDAC example application.

Application note:
AVR32120 - AVR32 ABDAC audio bitstream DAC driver example
Documentation
For comprehensive code documentation, supported compilers, compiler settings and supported devices see readme.html.
Author:
Atmel Corporation: http://www.atmel.com
Support email: avr32@atmel.com
Revision
506
Date
2007-05-21 20:00:05 +0200 (Mon, 21 May 2007)

Definition in file dac.h.

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define ABDAC_BF(name, value)
 Bit-field macro for GCLK.
#define ABDAC_BIT(name)   (1 << AVR32_ABDAC_##name##_OFFSET)
 Bit macro for ABDAC.
#define GCLK_BF(name, value)
 Bit-field macro for ABDAC GCLK.
#define GCLK_BFEXT(name, value)
 Bit-field extraction macro for ABDAC GCLK.
#define GCLK_BIT(name)   (1 << AVR32_PM_GCCTRL0_##name##_OFFSET)
 Bit macro for ABDAC GCLK.

Enumerations

enum  { EINVAL = 22, ETIMEOUT }

Functions

void abdac_disable (volatile avr32_abdac_t *abdac)
 Disables the ABDAC modules.
void abdac_enable (volatile avr32_abdac_t *abdac)
 Enables the ABDAC modules.
unsigned long abdac_get_dac_hz (volatile avr32_abdac_t *abdac, const unsigned long bus_hz)
 Get the DAC sample rate in Hz.
unsigned long abdac_set_dac_hz (volatile avr32_abdac_t *abdac, const unsigned long bus_hz, const unsigned long dac_hz)
 Set the DAC sample rate in Hz.
int abdac_sink (volatile avr32_abdac_t *abdac, const unsigned short ch0, const unsigned short ch1)
 Send data to the ABDAC.


Define Documentation

#define ABDAC_BF ( name,
value   ) 

Value:

(((value) & ((1 << AVR32_ABDAC_##name##_SIZE) - 1)) \
     << AVR32_ABDAC_##name##_OFFSET)
Bit-field macro for GCLK.

Definition at line 88 of file dac.h.

Referenced by abdac_sink().

#define ABDAC_BIT ( name   )     (1 << AVR32_ABDAC_##name##_OFFSET)

Bit macro for ABDAC.

Definition at line 85 of file dac.h.

Referenced by abdac_disable(), abdac_enable(), and abdac_sink().

#define GCLK_BF ( name,
value   ) 

Value:

(((value) & ((1 << AVR32_PM_GCCTRL0_##name##_SIZE) - 1))\
     << AVR32_PM_GCCTRL0_##name##_OFFSET)
Bit-field macro for ABDAC GCLK.

Definition at line 95 of file dac.h.

Referenced by abdac_set_dac_hz().

#define GCLK_BFEXT ( name,
value   ) 

Value:

(((value) >> AVR32_PM_GCCTRL0_##name##_OFFSET)      \
     & ((1 << AVR32_PM_GCCTRL0_##name##_SIZE) - 1))
Bit-field extraction macro for ABDAC GCLK.

Definition at line 99 of file dac.h.

Referenced by abdac_get_dac_hz().

#define GCLK_BIT ( name   )     (1 << AVR32_PM_GCCTRL0_##name##_OFFSET)

Bit macro for ABDAC GCLK.

Definition at line 92 of file dac.h.

Referenced by abdac_disable(), abdac_enable(), abdac_get_dac_hz(), and abdac_set_dac_hz().


Enumeration Type Documentation

anonymous enum

Enumerator:
EINVAL 
ETIMEOUT 

Definition at line 68 of file dac.h.

00068      {
00069     EINVAL = 22,
00070     ETIMEOUT,
00071 };


Function Documentation

void abdac_disable ( volatile avr32_abdac_t *  abdac  ) 

Disables the ABDAC modules.

This function disables the abdac module.

Parameters:
abdac Pointer to the base register of the ABDAC module.

Definition at line 69 of file dac.c.

References ABDAC_BIT, and GCLK_BIT.

Referenced by main().

00070 {
00071     volatile avr32_pm_t *pm = &AVR32_PM;
00072     abdac->cr &= ~ABDAC_BIT(CR_EN);
00073     pm->gcctrl[ABDAC_GCLK] &= ~GCLK_BIT(CEN);
00074 }

void abdac_enable ( volatile avr32_abdac_t *  abdac  ) 

Enables the ABDAC modules.

This function enables the abdac module.

Parameters:
abdac Pointer to the base register of the ABDAC module.

Definition at line 56 of file dac.c.

References ABDAC_BIT, and GCLK_BIT.

Referenced by main().

00057 {
00058     volatile avr32_pm_t *pm = &AVR32_PM;
00059     pm->gcctrl[ABDAC_GCLK] |= GCLK_BIT(CEN);
00060     abdac->cr |= ABDAC_BIT(CR_EN);
00061 }

unsigned long abdac_get_dac_hz ( volatile avr32_abdac_t *  abdac,
const unsigned long  bus_hz 
)

Get the DAC sample rate in Hz.

This function gets the DAC sample rate in Hz from a given peripheral bus speed.

Parameters:
abdac Pointer to the base register of the ABDAC module.
bus_hz Speed of peripheral bus in Hz.
Returns:
ABDAC sample rate.

Definition at line 121 of file dac.c.

References GCLK_BFEXT, and GCLK_BIT.

00123 {
00124     volatile avr32_pm_t *pm = &AVR32_PM;
00125     unsigned short div = 0;
00126 
00127     if (pm->gcctrl[ABDAC_GCLK] & GCLK_BIT(DIVEN)) {
00128         div = 2 * (GCLK_BFEXT(DIV, pm->gcctrl[ABDAC_GCLK]) + 1);
00129     }
00130 
00131     return (bus_hz / div);
00132 }

unsigned long abdac_set_dac_hz ( volatile avr32_abdac_t *  abdac,
const unsigned long  bus_hz,
const unsigned long  dac_hz 
)

Set the DAC sample rate in Hz.

This function sets the DAC sample rate in Hz from a given peripheral bus speed. The playback data must match this sample speed.

Parameters:
abdac Pointer to the base register of the ABDAC module.
bus_hz Speed of peripheral bus in Hz.
dac_hz Wanted sample rate of ABDAC in Hz.
Returns:
ABDAC sample rate or -EINVAL on error.

Definition at line 87 of file dac.c.

References EINVAL, GCLK_BF, and GCLK_BIT.

Referenced by main().

00089 {
00090     volatile avr32_pm_t *pm = &AVR32_PM;
00091     unsigned short div;
00092 
00093     if (bus_hz < (256 * dac_hz)) {
00094         return -EINVAL;
00095     }
00096 
00097     div = bus_hz / (256 * dac_hz);
00098 
00099     /* div must be a power of 2. */
00100     div = (div + 1) & ~1UL;
00101 
00102     if (div > 2) {
00103         pm->gcctrl[ABDAC_GCLK] = GCLK_BIT(DIVEN) | GCLK_BF(DIV, ((div / 2) - 1));
00104     } else {
00105         pm->gcctrl[ABDAC_GCLK] = GCLK_BIT(DIVEN);
00106     }
00107 
00108     return (bus_hz / (256 * div));
00109 }

int abdac_sink ( volatile avr32_abdac_t *  abdac,
const unsigned short  ch0,
const unsigned short  ch1 
)

Send data to the ABDAC.

This function sends data to the two channels provided by the ABDAC peripheral.

Parameters:
abdac Pointer to the base register of the ABDAC module.
ch0 16-bit unsigned value for channel 0.
ch1 16-bit unsigned value for channel 1.
Returns:
0 on success or -ETIMEOUT on timeout error.

Definition at line 145 of file dac.c.

References ABDAC_BF, ABDAC_BIT, and ETIMEOUT.

Referenced by main().

00147 {
00148     volatile unsigned long timeout = ABDAC_TIMEOUT;
00149 
00150     do {
00151     } while (!(abdac->isr & ABDAC_BIT(ISR_TX_READY)) && timeout--);
00152 
00153     if (0 == timeout) {
00154         return -ETIMEOUT;
00155     }
00156 
00157     abdac->sdr = ABDAC_BF(SDR_CHANNEL0, ch0) | ABDAC_BF(SDR_CHANNEL1, ch1);
00158 
00159     return 0;
00160 }


Generated on Fri Mar 14 15:33:01 2008 for AVR32120 - AVR32 ABDAC audio bitstream DAC driver example by  doxygen 1.5.5