dac_example.c 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_example.c.

#include "dac.h"
#include "settings.h"
#include "sinus.h"

Include dependency graph for dac_example.c:

Go to the source code of this file.

Typedefs

typedef unsigned char avr32_piomap_t [][2]

Functions

int main (void)
 Main function, executing starts here.
static int pio_enable_module (avr32_piomap_t piomap, unsigned int size)
 Set the pins under module control.


Typedef Documentation

typedef unsigned char avr32_piomap_t[][2]

Definition at line 60 of file dac_example.c.


Function Documentation

int main ( void   ) 

Main function, executing starts here.

Returns:
Only on error.

Definition at line 67 of file dac_example.c.

References abdac_disable(), abdac_enable(), abdac_set_dac_hz(), abdac_sink(), BUSHZ, GPIO_DEBOUNCE, pio_enable_module(), and sin_table().

00068 {
00069     int pi = 0;
00070     int retval = 0;
00071     int playing = 0;
00072     unsigned long debounce = 0;
00073     volatile avr32_pio_t *piob = &AVR32_PIOB;
00074     avr32_piomap_t abdac_piomap = {
00075         {AVR32_ABDAC_DATA_0_PIN, AVR32_ABDAC_DATA_0_FUNCTION},
00076         {AVR32_ABDAC_DATA_1_PIN, AVR32_ABDAC_DATA_1_FUNCTION},
00077         {AVR32_ABDAC_DATAN_0_PIN, AVR32_ABDAC_DATAN_0_FUNCTION},
00078         {AVR32_ABDAC_DATAN_1_PIN, AVR32_ABDAC_DATAN_1_FUNCTION},
00079     };
00080 
00081     /* Enable the GPIO pins for the ABDAC peripheral. */
00082     retval = pio_enable_module(abdac_piomap, 4);
00083     if (retval) {
00084         goto out;
00085     }
00086 
00087     /* Setup GPIO for LED and switch. */
00088     piob->per = 0x000001ff;
00089     piob->oer = 0x000000ff;
00090     piob->codr = 0x000000ff;
00091 
00092     abdac_set_dac_hz(&AVR32_ABDAC, BUSHZ, BUSHZ/256);
00093 
00094     for (;;) {
00095         /* Check if SW0 i pushed. */
00096         if (!(piob->pdsr & AVR32_PIO_P8_MASK) && !debounce) {
00097             if (playing) {
00098                 playing = 0;
00099                 piob->codr = AVR32_PIO_P0_MASK;
00100                 debounce = GPIO_DEBOUNCE;
00101                 abdac_disable(&AVR32_ABDAC);
00102             } else {
00103                 playing = 1;
00104                 piob->sodr = AVR32_PIO_P0_MASK;
00105                 abdac_enable(&AVR32_ABDAC);
00106                 debounce = GPIO_DEBOUNCE / 50;
00107             }
00108         }
00109 
00110         if (playing) {
00111             retval = abdac_sink(&AVR32_ABDAC,
00112                     sin_table(pi), sin_table(pi));
00113             if (retval) {
00114                 goto out;
00115             }
00116 
00117             ++pi;
00118         }
00119 
00120         if (debounce) {
00121             --debounce;
00122         }
00123     }
00124 
00125 out:
00126     return retval;
00127 }

Here is the call graph for this function:

static int pio_enable_module ( avr32_piomap_t  piomap,
unsigned int  size 
) [static]

Set the pins under module control.

Parameters:
piomap A map describing how the setup of the PIO.
size Number of elements in the map.
Returns:
Status or error code.
Return values:
0 on success.
EINVAL on bad values in piomap.

Definition at line 138 of file dac_example.c.

References EINVAL.

Referenced by main().

00139 {
00140     int i;
00141     volatile struct avr32_pio_t *pio;
00142 
00143     /* Get the base address for the port. */
00144     switch ((**piomap) / 32) {
00145     case 0:
00146         pio = &AVR32_PIOA;
00147         break;
00148     case 1:
00149         pio = &AVR32_PIOB;
00150         break;
00151     case 2:
00152         pio = &AVR32_PIOC;
00153         break;
00154     case 3:
00155         pio = &AVR32_PIOD;
00156         break;
00157     case 4:
00158         pio = &AVR32_PIOE;
00159         break;
00160     default:
00161         return -EINVAL;
00162     }
00163 
00164     for (i = 0; i < size; i++) {
00165         pio->pdr  |= (1 << ((**piomap) % 32));
00166         pio->pudr |= (1 << ((**piomap) % 32));
00167 
00168         switch (*(*piomap + 1)) {
00169         case 0:
00170             pio->asr |= (1 << ((**piomap) % 32));
00171             break;
00172         case 1:
00173             pio->bsr |= (1 << ((**piomap) % 32));
00174             break;
00175         default:
00176             return -EINVAL;
00177         }
00178         ++piomap;
00179     }
00180 
00181     return 0;
00182 }


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