host_audio_task.h File Reference

#include "config.h"

Include dependency graph for host_audio_task.h:

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

Go to the source code of this file.

Defines

#define AUDIO_AS_INTERFACE_CLASS   0x01
#define AUDIO_AS_INTERFACE_SUB_CLASS   0x02
#define SET_CUR   0x01
#define CS_MUTE   0x0100
#define PORT_A_RIGHT   0
#define PORT_A_CPLX   1
#define DAC_OUT   PORT_A_CPLX
#define Dac_output_init()   (PORTA = 0x00, DDRA = 0xFF)
#define MUTE_ON   TRUE
#define MUTE_OFF   FALSE
#define host_audio_set_cur(cs_mute)

Functions

void host_audio_task_init (void)
 This function initializes the USB Host Audio application.
void host_audio_task (void)
void sof_action (void)
void DAC_SendPort (U8)

Variables

volatile U8 audio_connected
volatile U8 audio_cpt_sof


Detailed Description

This file contains the function declarations for USB Host Audio task application - Compiler: IAR EWAVR and GNU GCC for AVR

Definition in file host_audio_task.h.


Define Documentation

#define AUDIO_AS_INTERFACE_CLASS   0x01

Definition at line 52 of file host_audio_task.h.

#define AUDIO_AS_INTERFACE_SUB_CLASS   0x02

Definition at line 53 of file host_audio_task.h.

#define SET_CUR   0x01

Definition at line 54 of file host_audio_task.h.

#define CS_MUTE   0x0100

Definition at line 55 of file host_audio_task.h.

#define PORT_A_RIGHT   0

Definition at line 59 of file host_audio_task.h.

#define PORT_A_CPLX   1

Definition at line 60 of file host_audio_task.h.

#define DAC_OUT   PORT_A_CPLX

Definition at line 65 of file host_audio_task.h.

 
#define Dac_output_init (  )     (PORTA = 0x00, DDRA = 0xFF)

Definition at line 67 of file host_audio_task.h.

Referenced by host_audio_task_init().

#define MUTE_ON   TRUE

Definition at line 72 of file host_audio_task.h.

#define MUTE_OFF   FALSE

Definition at line 73 of file host_audio_task.h.

#define host_audio_set_cur ( cs_mute   ) 

Value:

Definition at line 74 of file host_audio_task.h.

Referenced by host_audio_task().


Function Documentation

void host_audio_task_init ( void   ) 

This function initializes the USB Host Audio application.

Parameters:
none 
Returns:
none

Definition at line 85 of file host_audio_task.c.

References audio_connected, Dac_output_init, Joy_init, and Leds_init.

00086 {
00087    Leds_init();
00088    audio_connected = 0;
00089    Joy_init();
00090    
00091    // D/A converter output rate management
00092    // At 8 kHz, output should be updated every 125µs. But real-time issues may occur between both USB devices :
00093    // The Host send a token to the Device every millisecond, to get back a new samples frame.
00094    // On the Device side, this frame is loaded into endpoint every millisecond. So some frames may be missed in
00095    // the case where the endpoint is not yet validated while the token has been sent.
00096    // To decrease error cases and probability, the device sample rate has been fixed to 120µs.
00097    // The Host ouput rate is also set to 120µs.
00098    TCCR2A=0x02;         // Prescaler div8
00099    OCR2A=120;           // Reload value to count 8x120=960 for FOSC 8MHz =>120µS refresh rate
00100    TCCR2B=0x02;         // Timer 2 mode CTC
00101    TIMSK2|=(1<<OCIE2A); // Enable compare interrupt
00102    
00103    // D/A converter hardware configuration
00104    // In this case, user is free to do what he wants
00105    Dac_output_init();
00106 }

void host_audio_task ( void   ) 

This function manages the USB Host Audio application

Parameters:
none 
Returns:
none

Definition at line 115 of file host_audio_task.c.

References AUDIO_AS_INTERFACE_CLASS, AUDIO_AS_INTERFACE_SUB_CLASS, audio_connected, audio_cpt_sof, audio_stream_empty, audio_stream_in, audio_stream_ptr_rd, audio_stream_ptr_wr, audio_stream_size, AUDIO_STREAM_SIZE, FALSE, Get_class, Get_ep_addr, Get_nb_ep, Get_nb_supported_interface, Get_subclass, Host_ack_all_errors, Host_ack_in_received, host_audio_set_cur, Host_continuous_in_mode, Host_data_length_U8, Host_enable_sof_interrupt, host_get_hwd_pipe_nb(), Host_read_byte, Host_select_pipe, Host_send_in, host_set_interface, Host_unfreeze_pipe, i, interf_audio_stream, Is_device_disconnection_event, Is_ep_addr_in, Is_host_in_received, Is_host_pipe_error, Is_host_ready, Is_host_stall, Is_joy_down, Is_new_device_connection_event, j, Led0_on, Led3_off, Led3_on, Leds_off, LOG_STR_CODE, mute, PIPE_AUDIO_IN, pipe_audio_in, and TRUE.

00116 {
00117 U8 i, j;
00118 
00119    // Audio Device Management
00120    // *********************
00121    if(Is_host_ready())
00122    {
00123       if(Is_new_device_connection_event())   // Device connection
00124       {
00125          for(i=0;i<Get_nb_supported_interface();i++)
00126          {
00127             // Audio Streaming Interface
00128             // Select the audio streaming interface that has an IN PIPE
00129             if((Get_class(i)==AUDIO_AS_INTERFACE_CLASS) && (Get_subclass(i)==AUDIO_AS_INTERFACE_SUB_CLASS) && (Get_nb_ep(i) != 0))
00130             {
00131                for (j=0 ; j<Get_nb_ep(i) ; j++)
00132                {
00133                  if (Is_ep_addr_in(Get_ep_addr(i,j)))
00134                  {
00135                    // Log in device
00136                    audio_connected=1;
00137                    audio_stream_ptr_wr = 0;
00138                    audio_stream_ptr_rd = 0;
00139                    audio_stream_empty = TRUE;
00140                    Led0_on();
00141                    Host_enable_sof_interrupt();
00142                    LOG_STR_CODE(log_audio_connect);
00143                    
00144                    // Select and enable ISOCHRONOUS pipe
00145                    pipe_audio_in = host_get_hwd_pipe_nb(Get_ep_addr(i,j));
00146                    Host_select_pipe(PIPE_AUDIO_IN);
00147                    Host_continuous_in_mode();
00148                    Host_unfreeze_pipe();
00149                    
00150                    // Set the Device in Mute mode
00151                    mute = TRUE;
00152                    Led3_on();   // LED3 is ON when device muted
00153                    host_audio_set_cur(mute);        // set device default state : muted
00154                    
00155                    // Enable alternate streaming interface
00156                    interf_audio_stream = i;                     // store interface number
00157                    host_set_interface(interf_audio_stream,1);   // enable streaming interface with "alternate 1" on Device
00158                    break;
00159                  }
00160                }
00161             }
00162          }
00163       }
00164 
00165       if (audio_connected)
00166       {
00167          // Check in AUDIO_PIPE_IN for incoming stream
00168          // ******************************************
00169          Host_select_pipe(PIPE_AUDIO_IN);
00170          
00171          // Error management : clear any error (time-out, CRC, etc...) and unfreeze pipe if error flag rises
00172          // Error flag rises after three errors. Errors can be identified in UPERRX register.
00173          if (Is_host_pipe_error())
00174          {
00175            Host_ack_all_errors();
00176            Host_unfreeze_pipe();
00177          }
00178 
00179          // Stream management
00180          if (Is_host_in_received() && (Is_host_stall()==FALSE))
00181          {
00182            // Pipe has received a new frame !
00183            Disable_interrupt();   // to avoid interrupt access to audio_stream_in[] buffer
00184            while ((Host_data_length_U8() != 0) && (audio_stream_ptr_wr != AUDIO_STREAM_SIZE))
00185            {
00186               audio_stream_in[audio_stream_ptr_wr] = Host_read_byte();
00187               audio_stream_ptr_wr++;
00188            }
00189            audio_stream_size = audio_stream_ptr_wr;
00190            audio_stream_empty = FALSE;
00191            Host_ack_in_received();  // all the pipe data has been read
00192            Host_send_in();
00193            Enable_interrupt();
00194          }
00195          
00196          // Mute control : toggle MUTE state with Joystick DOWN direction
00197          if (Is_joy_down())
00198          {
00199            audio_cpt_sof = 0;
00200            while (audio_cpt_sof != 10); // debounce
00201            if (mute == TRUE)
00202            {
00203              mute=FALSE;
00204              Led3_off();
00205            }
00206            else
00207            {
00208              mute=TRUE;
00209              Led3_on();
00210            }
00211            host_audio_set_cur(mute);
00212            while (Is_joy_down());
00213            audio_cpt_sof = 0;           // debounce
00214            while (audio_cpt_sof != 10);
00215          }
00216       }
00217    }
00218 
00219    // Device disconnection...
00220    if(Is_device_disconnection_event())
00221    {
00222       Leds_off();
00223       audio_stream_empty = TRUE;
00224       audio_stream_ptr_rd = 0;
00225       audio_stream_ptr_wr = 0;
00226       audio_stream_size = 0;
00227       audio_connected = 0;
00228    }
00229 }

Here is the call graph for this function:

void DAC_SendPort ( U8  data_dac  ) 

Function that ouputs the 8-bits value to the R-2R ladder (2 configurations possibles) Refer to the "fig" folder that contains the schematics of the two R-2R ladder configurations

Note:
This function can also be modified to transmit the 8-bit sound sample to an external DAC (external peripheral, PWM, etc..)
Parameters:
none 
Returns:
none

Definition at line 311 of file host_audio_task.c.

00312 {
00313   U8   port_value;
00314   
00315   // DAC_OUT value must be set to the value specified by your external DAC ladder configuration
00316 #if   (DAC_OUT==PORT_A_RIGHT)
00317   // In this configuration, see the R-2R ladder configuration on the "R2R_LADDER_RIGHT" schematic
00318   PORTA = data_dac;
00319 #elif (DAC_OUT==PORT_A_CPLX)
00320   // In this configuration (easier to mount directly on EXPAND0 connector...), the connexions of the PORTA signals are not
00321   // the same that for the R2R_LADDER_RIGHT schematic. The resistor structure is the same, but the port connexions are differents :
00322   // see R2R_LADDER_CPLX schematic.
00323   port_value  = (data_dac&0x01);          // bit 0 : portA,0
00324   port_value |= (data_dac&0x02)<<(2-1);   // bit 1 : portA,2
00325   port_value |= (data_dac&0x04)<<(4-2);   // bit 2 : portA,4
00326   port_value |= (data_dac&0x08)<<(6-3);   // bit 3 : portA,6
00327   port_value |= (data_dac&0x10)<<(7-4);   // bit 4 : portA,7
00328   port_value |= (data_dac&0x20);          // bit 5 : portA,5
00329   port_value |= (data_dac&0x40)>>(6-3);   // bit 6 : portA,3
00330   port_value |= (data_dac&0x80)>>(7-1);   // bit 7 : portA,1
00331   PORTA = port_value;
00332 #endif
00333 }


Variable Documentation

volatile U8 audio_connected

Definition at line 65 of file host_audio_task.c.

volatile U8 audio_cpt_sof

Definition at line 66 of file host_audio_task.c.


Generated on Fri Oct 31 15:19:19 2008 for ATMEL by  doxygen 1.5.3