#include <avr32/io.h>
#include "compiler.h"
#include "board.h"
#include "dsp.h"
#include "pm.h"
#include "gpio.h"
#include "usart.h"
#include "intc.h"
#include "pwm.h"
#include "flashc.h"
#include "preprocessor.h"
#include "pdca.h"
Macros | |
#define | BUFFER_SIZE 2048 |
The size of the buffer. More... | |
#define | CP_PBA_SPEED 48000000 |
The clock frequency. More... | |
#define | DAC_PWM_FREQUENCY (CP_PBA_SPEED >> 8) |
USART Settings | |
#define | EXAMPLE_USART (&AVR32_USART1) |
#define | EXAMPLE_USART_RX_PIN AVR32_USART1_RXD_0_0_PIN |
#define | EXAMPLE_USART_RX_FUNCTION AVR32_USART1_RXD_0_0_FUNCTION |
#define | EXAMPLE_USART_TX_PIN AVR32_USART1_TXD_0_0_PIN |
#define | EXAMPLE_USART_TX_FUNCTION AVR32_USART1_TXD_0_0_FUNCTION |
#define | DAC_PWM_CHANNEL_LSB 2 |
#define | DAC_PWM_CHANNEL_LSB_PIN |
#define | DAC_PWM_CHANNEL_MSB 3 |
#define | DAC_PWM_CHANNEL_MSB_PIN |
Functions | |
void | dac_pwm_init () |
Initialize the PWM to make it works as a DAC. More... | |
static void | dac_pwm_int_handler (void) |
The PWM interrupt handler. More... | |
void | init_pdca () |
void | init_usart () |
this function initializes the USART module at 115200 bauds More... | |
int | main (int argc, char *argv[]) |
The main function. More... | |
static void | pdca_interrupt_handler (void) |
void | print_fct (char *str) |
This function is used by the debugging module. It permits to print a string through the USART. More... | |
void | set_new_dac_buffer (char *_next_buffer) |
Read the next block. More... | |
void | sys_cpu_48MHz (void) |
To set the clock frequency to 48MHz. More... | |
Variables | |
int | block_size |
The size of a block. More... | |
A_ALIGNED char | buffer [BUFFER_SIZE] |
The main buffer. More... | |
int | cur_i_buffer = 0 |
The offset of the current writing buffer. More... | |
int | cur_i_read_buffer = 0 |
The offset of the current reading buffer. More... | |
int | dac_pwm_period |
int | dac_pwm_periods_per_sample |
int | fill_activ = 0 |
A flag to tell if the buffer is currently filled or not. More... | |
volatile int | get_new_block = 0 |
A flag to tell if we need to get a new block from the USART. More... | |
volatile int | get_sample = 0 |
A flag to tell if we need to play a new sample with the DAC. More... | |
int | nb_buffers |
The number of buffers. More... | |
char * | pbuffer_r |
A pointer on the current reading block. More... | |
char * | pbuffer_w |
A pointer on the current writing block. More... | |
int | pdca_channel_usart = 0 |
In the example we will use the pdca channel 0. There is 17 possible pdca channel in AT32UC3A0512. More... | |
A_ALIGNED short | predicted_value |
Predicted value for the adpcm decoder. More... | |
A_ALIGNED short | step_index |
Step index for the adpcm decoder. More... | |
#define BUFFER_SIZE 2048 |
The size of the buffer.
Referenced by main(), and pdca_interrupt_handler().
#define CP_PBA_SPEED 48000000 |
The clock frequency.
#define DAC_PWM_CHANNEL_LSB 2 |
Referenced by dac_pwm_init(), and main().
#define DAC_PWM_CHANNEL_LSB_PIN |
Referenced by dac_pwm_init().
#define DAC_PWM_CHANNEL_MSB 3 |
Referenced by dac_pwm_init(), and main().
#define DAC_PWM_CHANNEL_MSB_PIN |
Referenced by dac_pwm_init().
#define DAC_PWM_FREQUENCY (CP_PBA_SPEED >> 8) |
Referenced by main().
#define EXAMPLE_USART (&AVR32_USART1) |
Referenced by init_usart(), main(), and print_fct().
#define EXAMPLE_USART_RX_FUNCTION AVR32_USART1_RXD_0_0_FUNCTION |
Referenced by init_usart().
#define EXAMPLE_USART_RX_PIN AVR32_USART1_RXD_0_0_PIN |
Referenced by init_usart().
#define EXAMPLE_USART_TX_FUNCTION AVR32_USART1_TXD_0_0_FUNCTION |
Referenced by init_usart().
#define EXAMPLE_USART_TX_PIN AVR32_USART1_TXD_0_0_PIN |
Referenced by init_usart().
void dac_pwm_init | ( | ) |
Initialize the PWM to make it works as a DAC.
References ATPASTE4, DAC_PWM_CHANNEL_LSB, DAC_PWM_CHANNEL_LSB_PIN, DAC_PWM_CHANNEL_MSB, DAC_PWM_CHANNEL_MSB_PIN, dac_pwm_int_handler(), gpio_enable_module(), and INTC_register_interrupt().
Referenced by main().
|
static |
void init_pdca | ( | ) |
References pdca_channel_options_t::addr, buffer, INTC_register_interrupt(), NULL, pdca_channel_usart, pdca_init_channel(), pdca_interrupt_handler(), and PDCA_TRANSFER_SIZE_BYTE.
Referenced by main().
void init_usart | ( | ) |
this function initializes the USART module at 115200 bauds
References usart_options_t::baudrate, EXAMPLE_USART, EXAMPLE_USART_RX_FUNCTION, EXAMPLE_USART_RX_PIN, EXAMPLE_USART_TX_FUNCTION, EXAMPLE_USART_TX_PIN, FOSC0, gpio_enable_module(), USART_1_STOPBIT, usart_init_rs232(), USART_NO_PARITY, and USART_NORMAL_CHMODE.
int main | ( | int | argc, |
char * | argv[] | ||
) |
The main function.
Enable pdca transfer interrupt when completed
add the address of memory buffer
add the address of memory buffer
Enable pdca transfer interrupt when completed
add the address of memory buffer
Enable pdca transfer interrupt when completed
References block_size, buffer, BUFFER_SIZE, c, cur_i_buffer, cur_i_read_buffer, DAC_PWM_CHANNEL_LSB, DAC_PWM_CHANNEL_MSB, DAC_PWM_FREQUENCY, dac_pwm_init(), dac_pwm_period, dac_pwm_periods_per_sample, Disable_global_interrupt, dsp_adpcm_ima_decode_nibble(), Enable_global_interrupt, EXAMPLE_USART, fill_activ, flashc_set_wait_state(), get_new_block, get_sample, i, init_pdca(), init_usart(), INTC_init_interrupts(), nb_buffers, pbuffer, pbuffer_r, pbuffer_w, pdca_channel_usart, pdca_enable(), pdca_enable_interrupt_transfer_complete(), pdca_reload_channel(), predicted_value, set_new_dac_buffer(), step_index, sys_cpu_48MHz(), and usart_putchar().
|
static |
References block_size, buffer, BUFFER_SIZE, fill_activ, get_new_block, pbuffer_w, pdca_channel_usart, and pdca_disable_interrupt_transfer_complete().
Referenced by init_pdca().
void print_fct | ( | char * | str | ) |
This function is used by the debugging module. It permits to print a string through the USART.
str | The input string to print. |
References EXAMPLE_USART, and usart_write_line().
void set_new_dac_buffer | ( | char * | _next_buffer | ) |
Read the next block.
References cur_i_read_buffer, pbuffer_r, predicted_value, and step_index.
Referenced by main().
void sys_cpu_48MHz | ( | void | ) |
To set the clock frequency to 48MHz.
References FOSC0, OSC0_STARTUP, pm_cksel(), pm_pll_enable(), pm_pll_set_option(), pm_pll_setup(), pm_switch_to_clock(), pm_switch_to_osc0(), pm_wait_for_pll0_locked(), and TRUE.
int block_size |
The size of a block.
Referenced by main(), membag_alloc(), membag_free(), membag_init(), pdca_interrupt_handler(), and udi_msc_trans_block().
A_ALIGNED char buffer[BUFFER_SIZE] |
The main buffer.
int cur_i_buffer = 0 |
The offset of the current writing buffer.
Referenced by main().
int cur_i_read_buffer = 0 |
The offset of the current reading buffer.
Referenced by main(), and set_new_dac_buffer().
int dac_pwm_period |
Referenced by dac_pwm_int_handler(), and main().
int dac_pwm_periods_per_sample |
Referenced by main().
int fill_activ = 0 |
A flag to tell if the buffer is currently filled or not.
Referenced by main(), and pdca_interrupt_handler().
volatile int get_new_block = 0 |
A flag to tell if we need to get a new block from the USART.
Referenced by main(), and pdca_interrupt_handler().
volatile int get_sample = 0 |
A flag to tell if we need to play a new sample with the DAC.
int nb_buffers |
The number of buffers.
Referenced by audio_mixer_create_buffers_direct(), and main().
char* pbuffer_r |
A pointer on the current reading block.
char* pbuffer_w |
A pointer on the current writing block.
int pdca_channel_usart = 0 |
In the example we will use the pdca channel 0. There is 17 possible pdca channel in AT32UC3A0512.
Referenced by init_pdca(), main(), and pdca_interrupt_handler().
A_ALIGNED short predicted_value |
Predicted value for the adpcm decoder.
Referenced by dsp_adpcm_ima_decode(), dsp_adpcm_ima_encode(), main(), and set_new_dac_buffer().
A_ALIGNED short step_index |
Step index for the adpcm decoder.
Referenced by dsp16_gen_step(), dsp32_gen_step(), dsp_adpcm_ima_decode(), dsp_adpcm_ima_encode(), main(), and set_new_dac_buffer().