device_audio_task.h File Reference


Detailed Description

Management of the USB device mouse Audio task.

This file manages the USB device mouse Audio task.

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file device_audio_task.h.

#include "conf_usb.h"

Go to the source code of this file.

Data Structures

struct  device_audio_task_data_t
 Define for each 'feature unit' the max numbers of bmaControls One of them is used by the microphone! More...

Defines

#define MAX_BMA_CONTROLS   4
 Define for each 'feature unit' the max numbers of bmControls.

Functions

void device_audio_disable_microphone (void)
void device_audio_enable_microphone (void)
void device_audio_task (void)
 Entry point of the device Audio task management.
void device_audio_task_init (void)
 This function initializes the hardware/software resources required for device Audio task.
void usb_sof_action (void)
 usb_sof_action


Define Documentation

#define MAX_BMA_CONTROLS   4

Define for each 'feature unit' the max numbers of bmControls.

Definition at line 64 of file device_audio_task.h.


Function Documentation

void device_audio_disable_microphone ( void   ) 

Definition at line 582 of file device_audio_task.c.

References b_microphone_pause.

Referenced by audio_speaker_set_sample_freq().

00583 {
00584   b_microphone_pause=TRUE;
00585 }

void device_audio_enable_microphone ( void   ) 

Definition at line 587 of file device_audio_task.c.

References b_microphone_pause.

Referenced by audio_speaker_set_sample_freq().

00588 {
00589   b_microphone_pause=FALSE;
00590 }

void device_audio_task ( void   ) 

Entry point of the device Audio task management.

Definition at line 431 of file device_audio_task.c.

References b_microphone_started, microphone_st::buffer, EP_AUDIO_IN, EP_AUDIO_OUT, EP_SIZE_IN, is_joystick_pressed(), mic_buf_id, mic_frame_id, microphone, mmi_activity_display(), mmi_display(), mmi_state, mute, sample_sound, SAMPLE_SOUND_LEN, and microphone_st::size.

Referenced by device_audio_task_init(), and main().

00433 {
00434 #if( BOARD!=EVK1105) || (DEFAULT_DACS!=AUDIO_MIXER_DAC_AIC23B)
00435   U32  i;
00436 #endif
00437   U32  fifo_cnt;
00438   int  stream_status;
00439 
00440 #ifdef FREERTOS_USED
00441   portTickType xLastWakeTime;
00442   xLastWakeTime = xTaskGetTickCount();
00443   LED_On(LED0);
00444 
00445   while (TRUE)
00446   {
00447     vTaskDelayUntil(&xLastWakeTime, configTSK_USB_DAUDIO_PERIOD);
00448 
00449     // First, check the device enumeration state
00450     if (!Is_device_enumerated()) { mmi_state=0; continue; }
00451 #else
00452     // First, check the device enumeration state
00453     if (!Is_device_enumerated()) { mmi_state=0; return; }
00454 #endif  // FREERTOS_USED
00455 
00456     mmi_display();
00457 
00458 #if( BOARD!=EVK1105) || (DEFAULT_DACS!=AUDIO_MIXER_DAC_AIC23B)
00459     // Microphone emulation
00460     //
00461     if ( is_joystick_pressed() )
00462     {
00463        if (Is_usb_write_enabled(EP_AUDIO_IN))   // Endpoint buffer free ?
00464        {
00465           Usb_reset_endpoint_fifo_access(EP_AUDIO_IN);
00466           for( i=0 ; i<EP_SIZE_IN ; i++ )   // Fill endpoint with sample raw
00467           {
00468              if(mute==FALSE)
00469              {
00470                 U8 sample;
00471                 sample = sample_sound[dat_sample_index++];
00472                 LED_Set_Intensity(LED0, sample);
00473                 Usb_write_endpoint_data(EP_AUDIO_IN, 8, sample);
00474                 if (dat_sample_index >= SAMPLE_SOUND_LEN)
00475                 {  dat_sample_index=0; }
00476              }
00477              else
00478              {
00479                 LED_Set_Intensity(LED0, 0);
00480                 Usb_write_endpoint_data(EP_AUDIO_IN, 8, 0x00);
00481              }
00482           }
00483           Usb_ack_in_ready_send(EP_AUDIO_IN);
00484        }
00485     }
00486 #else
00487     // Handle input stream from microphone
00488     if( !b_microphone_started && (Is_usb_write_enabled(EP_AUDIO_IN)) && audio_mixer_dacs_input(NULL, 0) )
00489     {
00490       // Start ADC conversion. This will launch the IRL in background...
00491       mic_buf_id = 0;
00492       mic_frame_id=2;
00493       microphone[mic_buf_id].size=45;
00494       audio_mixer_dacs_input(microphone[0].buffer, 45 /*microphone[mic_buf_id].size*/);
00495       audio_mixer_dacs_input(microphone[1].buffer, 45 /*microphone[mic_buf_id].size*/);
00496       b_microphone_started=TRUE;
00497     }
00498 #endif
00499 
00500 
00501 
00502     // Handle incoming audio samples
00503     //
00504     if((Is_usb_out_received(EP_AUDIO_OUT) )
00505     /*&& (Is_usb_stall(EP_AUDIO_OUT)==FALSE)*/)
00506     {
00507        stream_status = usb_stream_input(USB_STREAM_DEVICE, EP_AUDIO_OUT, &fifo_cnt);
00508        Usb_ack_out_received_free(EP_AUDIO_OUT);
00509        mmi_activity_display(FALSE, fifo_cnt);
00510     }    
00511 #if USB_RESYNC_AUDIO_STREAM && (USB_RESYNC_AUDIO_STREAM==ENABLED)
00512     usb_stream_resync();
00513 #endif
00514 
00515 #ifdef FREERTOS_USED
00516   }
00517 #endif
00518 }

void device_audio_task_init ( void   ) 

This function initializes the hardware/software resources required for device Audio task.

Definition at line 154 of file device_audio_task.c.

References b_microphone_pause, b_microphone_started, microphone_st::buffer, device_audio_task(), microphone, microphone_st::size, sof_cnt, and SPEAKER_FREQUENCY.

Referenced by main().

00155 {
00156   sof_cnt   =0;
00157 #if (BOARD!=EVK1105)
00158   dat_sample_index =0;
00159 #endif
00160 
00161 #ifndef FREERTOS_USED
00162   #if USB_HOST_FEATURE == ENABLED
00163   // If both device and host features are enabled, check if device mode is engaged
00164   // (accessing the USB registers of a non-engaged mode, even with load operations,
00165   // may corrupt USB FIFO data).
00166   if (Is_usb_device())
00167   #endif  // USB_HOST_FEATURE == ENABLED
00168     Usb_enable_sof_interrupt();
00169 #endif  // FREERTOS_USED
00170 
00171   player_init();
00172 
00173   if (!device_audio_task_data)
00174     device_audio_task_data = calloc(1, sizeof(*device_audio_task_data));
00175 
00176 #if (BOARD==EVK1105) && (DEFAULT_DACS==AUDIO_MIXER_DAC_AIC23B)
00177   // Allocate memory for the microphone audio samples.
00178   // Receiving stereo samples from the ADC.
00179   // For a 48KHz, needs 196 bytes. Let's use a little more.
00180   microphone[0].buffer= (U16*)malloc(200);
00181   microphone[0].size  = 0;
00182   microphone[1].buffer= (U16*)malloc(200);
00183   microphone[1].size  = 0;
00184   b_microphone_started=FALSE;
00185   b_microphone_pause=FALSE;
00186 #endif
00187 
00188   usb_stream_init(
00189     SPEAKER_FREQUENCY
00190   , 2
00191   , 16
00192   , FALSE
00193   );
00194 
00195 #ifdef FREERTOS_USED
00196   xTaskCreate(device_audio_task,
00197               configTSK_USB_DAUDIO_NAME,
00198               configTSK_USB_DAUDIO_STACK_SIZE,
00199               NULL,
00200               configTSK_USB_DAUDIO_PRIORITY,
00201               NULL);
00202 
00203 #endif  // FREERTOS_USED
00204 }


Generated on Fri Feb 19 02:32:02 2010 for AVR32 - USB AUDIO Example by  doxygen 1.5.5