Definition in file dac.c.
#include "dac.h"

Go to the source code of this file.
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. | |
| void abdac_disable | ( | volatile avr32_abdac_t * | abdac | ) |
Disables the ABDAC modules.
This function disables the abdac module.
| 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.
| 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.
| abdac | Pointer to the base register of the ABDAC module. | |
| bus_hz | Speed of peripheral bus in Hz. |
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.
| 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. |
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.
| 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. |
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 }
1.5.5