This file manages the USB device Audio task.
Definition in file device_audio_task.c.
#include <stdio.h>
#include "usart.h"
#include "conf_usb.h"
#include "board.h"
#include "controller.h"
#include "usb_drv.h"
#include "usb_descriptors.h"
#include "usb_standard_request.h"
#include "device_audio_task.h"
#include "usb_stream_player.h"
#include "audio_example.h"
#include "et024006dhu.h"
#include "cycle_counter.h"
#include "debug.h"
#include "avr32_logo.h"
#include "microphone_samples.h"
Go to the source code of this file.
Defines | |
#define | FONT_HEIGHT 14 |
#define | START_Y_DEMO_TEXT 33 |
#define | TIMER_MMI 1000 |
#define | TIMER_STARTUP 100 |
Functions | |
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. | |
static void | display_box (U32 x, U32 y, U32 size_x, U32 size_y, U16 color, U16 edge_color) |
This function displays a box on the LCD. | |
static void | mmi_activity_display (Bool init, U32 fifo_cnt) |
This function displays the a bargraph indicating the state of the audio buffers and the PPM deviation between the incoming USB audio sampling frequency and the output DAC sampling frequency. | |
static void | mmi_display (void) |
This function displays the MMI interface and some static informations. | |
void | usb_sof_action (void) |
usb_sof_action | |
Variables | |
U8 * | __bss_start |
U8 * | _data |
U8 * | _edata |
U8 * | _estack |
U8 * | _stack |
static U32 | dat_sample_index |
device_audio_task_data_t * | device_audio_task_data = NULL |
U8 * | end |
static U32 | mmi_state = 0 |
Bool | mute |
Public : (bit) mute mute is set to TRUE when ACTIVE mute is set to FALSE otherwise /. | |
static U16 | sof_cnt |
t_cpu_time | timer |
S16 | volume |
Public : (S16) volume volume represents the current volume of audio stream /. |
#define FONT_HEIGHT 14 |
Definition at line 90 of file device_audio_task.c.
Referenced by mmi_activity_display(), and mmi_display().
#define START_Y_DEMO_TEXT 33 |
Definition at line 88 of file device_audio_task.c.
Referenced by mmi_activity_display(), and mmi_display().
#define TIMER_MMI 1000 |
Referenced by mmi_activity_display().
#define TIMER_STARTUP 100 |
Definition at line 87 of file device_audio_task.c.
Referenced by device_hid_task_init(), and mmi_display().
void device_audio_task | ( | void | ) |
Entry point of the device Audio task management.
Definition at line 431 of file device_audio_task.c.
References dat_sample_index, EP_AUDIO_IN, EP_AUDIO_OUT, EP_SIZE_IN, is_joystick_pressed(), mmi_activity_display(), mmi_display(), mmi_state, mute, sample_sound, and SAMPLE_SOUND_LEN.
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 dat_sample_index, device_audio_task(), 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 }
static void display_box | ( | U32 | x, | |
U32 | y, | |||
U32 | size_x, | |||
U32 | size_y, | |||
U16 | color, | |||
U16 | edge_color | |||
) | [static] |
This function displays a box on the LCD.
Definition at line 222 of file device_audio_task.c.
Referenced by mmi_activity_display().
00223 { 00224 et024006_DrawFilledRect(x, y, size_x, size_y, color); 00225 et024006_DrawHorizLine(x, y, size_x, edge_color); 00226 et024006_DrawVertLine(x+size_x-1, y, size_y, edge_color); 00227 et024006_DrawHorizLine(x, y+size_y-1, size_x, edge_color); 00228 et024006_DrawVertLine(x, y, size_y, edge_color); 00229 }
static void mmi_activity_display | ( | Bool | init, | |
U32 | fifo_cnt | |||
) | [static] |
This function displays the a bargraph indicating the state of the audio buffers and the PPM deviation between the incoming USB audio sampling frequency and the output DAC sampling frequency.
Definition at line 319 of file device_audio_task.c.
References display_box(), FCPU_HZ, FONT_HEIGHT, START_Y_DEMO_TEXT, TIMER_MMI, and USB_STREAM_BUFFER_NUMBER.
Referenced by device_audio_task(), and mmi_display().
00320 { 00321 static char tmp[20]; 00322 static S32 ppm; 00323 #define TIMER_MMI 1000 // Unit is in ms. 00324 static t_cpu_time mmi_timer; 00325 static U32 old_fcpu_hz = 0; 00326 static U32 mmi_activity_state=0; 00327 static U32 i; 00328 00329 if( init ) 00330 { 00331 // Display PPM window 00332 et024006_PrintString("PPM", (const unsigned char *)&FONT8x8, 22, 70+4, BLUE, -1); 00333 display_box(50, 70, 40, 16, WHITE, BLACK); 00334 00335 et024006_PrintString("HID", (const unsigned char *)&FONT8x8, 122, 70+4, BLUE, -1); 00336 display_box(150, 70, 40, 16, WHITE, BLACK); 00337 00338 et024006_PrintString("CPU", (const unsigned char *)&FONT8x8, 222, 70+4, BLUE, -1); 00339 display_box(250, 70, 40, 16, WHITE, BLACK); 00340 00341 et024006_PrintString("Buffers", (const unsigned char *)&FONT8x8, 0, 50+4, BLUE, -1); 00342 display_box(50, 50, 195, 16, WHITE, BLACK); 00343 cpu_set_timeout( cpu_ms_2_cy(TIMER_MMI, FCPU_HZ), &mmi_timer ); 00344 goto mmi_end; 00345 } 00346 00347 if( !cpu_is_timeout(&mmi_timer) ) 00348 goto mmi_end; 00349 00350 switch( mmi_activity_state ) 00351 { 00352 case 0: 00353 i = 0; 00354 mmi_activity_state = 1; 00355 // no break here 00356 00357 case 1: 00358 if( i>=USB_STREAM_BUFFER_NUMBER ) 00359 { 00360 mmi_activity_state = 10; 00361 break; 00362 } 00363 if( i<fifo_cnt ) 00364 et024006_DrawFilledRect(50+3 + i*(10+2), 50+3, 10, 10, BLUE_LEV(15) ); 00365 else 00366 et024006_DrawFilledRect(50+3 + i*(10+2), 50+3, 10, 10, WHITE ); 00367 i++; 00368 break; 00369 00370 case 10: 00371 ppm = usb_stream_ppm_get(); 00372 sprintf( tmp, "%4ld", ppm ); 00373 et024006_PrintString(tmp, (const unsigned char *)&FONT8x8, 50+4, 70+4, BLUE, WHITE); 00374 mmi_activity_state = 20; 00375 break; 00376 00377 case 20: 00378 if( old_fcpu_hz==FCPU_HZ ) 00379 { 00380 mmi_activity_state = 30; 00381 break; 00382 } 00383 else 00384 mmi_activity_state = 21; 00385 // No break here 00386 00387 case 21: 00388 old_fcpu_hz=FCPU_HZ; 00389 sprintf( tmp, "%ld", (U32)FCPU_HZ/1000000); 00390 et024006_PrintString(tmp, (const unsigned char *)&FONT8x8, 250+4, 70+4, BLUE, WHITE); 00391 mmi_activity_state = 30; 00392 break; 00393 00394 #if (defined __GNUC__) 00395 case 30: 00396 sprintf( tmp, "%ld", get_heap_total_used_size() ); 00397 et024006_PrintString(tmp, (const unsigned char *)&FONT8x8, 230, START_Y_DEMO_TEXT+13*FONT_HEIGHT, BLUE, WHITE); 00398 mmi_activity_state = 31; 00399 break; 00400 00401 case 31: 00402 sprintf( tmp, "%ld", get_heap_curr_used_size() ); 00403 et024006_PrintString(tmp, (const unsigned char *)&FONT8x8, 230, START_Y_DEMO_TEXT+14*FONT_HEIGHT, BLUE, WHITE); 00404 // No break here 00405 #elif (defined __ICCAVR32__) 00406 case 30: 00407 sprintf( tmp, "%ld", get_heap_free_size() ); 00408 et024006_PrintString(tmp, (const unsigned char *)&FONT8x8, 230, START_Y_DEMO_TEXT+14*FONT_HEIGHT, BLUE, WHITE); 00409 // No break here 00410 00411 #endif 00412 00413 default: 00414 // Rearm timer 00415 cpu_set_timeout( cpu_ms_2_cy(TIMER_MMI, FCPU_HZ), &mmi_timer ); 00416 mmi_activity_state = 0; 00417 break; 00418 } 00419 00420 mmi_end: 00421 return; 00422 }
static void mmi_display | ( | void | ) | [static] |
This function displays the MMI interface and some static informations.
Definition at line 235 of file device_audio_task.c.
References __bss_start, _data, _edata, _estack, _stack, AUDIO_DEMO_STRING, avr32_logo, AVR32_LOGO_HEIGHT, AVR32_LOGO_WIDTH, end, FCPU_HZ, FONT_HEIGHT, mmi_activity_display(), mmi_state, START_Y_DEMO_TEXT, timer, and TIMER_STARTUP.
Referenced by device_audio_task().
00236 { 00237 #if (defined __GNUC__) 00238 char tmp[64]; 00239 #endif 00240 if( mmi_state!=11 ) 00241 { 00242 if( mmi_state==0 ) 00243 { 00244 cpu_set_timeout( cpu_ms_2_cy(TIMER_STARTUP, FCPU_HZ), &timer ); 00245 mmi_state++; 00246 } 00247 else if( cpu_is_timeout(&timer) ) 00248 { 00249 switch( mmi_state++ ) 00250 { 00251 case 1: 00252 LED_On( LED0 ); 00253 cpu_set_timeout( cpu_ms_2_cy(TIMER_STARTUP, FCPU_HZ), &timer ); 00254 00255 // Clear the display 00256 et024006_DrawFilledRect(0, 0, ET024006_WIDTH, ET024006_HEIGHT, WHITE ); 00257 00258 // Display a logo. 00259 et024006_PutPixmap(avr32_logo, AVR32_LOGO_WIDTH, 0, 0 00260 ,(ET024006_WIDTH - AVR32_LOGO_WIDTH)/2 00261 ,(ET024006_HEIGHT - AVR32_LOGO_HEIGHT)/2, AVR32_LOGO_WIDTH, AVR32_LOGO_HEIGHT); 00262 et024006_PrintString(AUDIO_DEMO_STRING , (const unsigned char *)&FONT8x16, 30, 5, BLACK, -1); 00263 #if(defined USB_RESYNC_METHOD) 00264 #if (USB_RESYNC_METHOD == USB_RESYNC_METHOD_EXT_CLOCK_SYNTHESIZER) 00265 et024006_PrintString("32/44.1/48 KHz, HID, CS2200" , (const unsigned char *)&FONT8x8, 50, START_Y_DEMO_TEXT+0*FONT_HEIGHT, BLUE, -1); 00266 #elif (USB_RESYNC_METHOD == USB_RESYNC_METHOD_SOFT_ADAPTIF_SRC) 00267 et024006_PrintString("44.1 KHz, HID, adaptif SRC", (const unsigned char *)&FONT8x8, 50, START_Y_DEMO_TEXT+0*FONT_HEIGHT, BLUE, -1); 00268 #elif (USB_RESYNC_METHOD == USB_RESYNC_METHOD_SOFT_ADD_DEL_SAMPLES) 00269 et024006_PrintString("44.1 KHz, HID, Add/remove sample", (const unsigned char *)&FONT8x8, 50, START_Y_DEMO_TEXT+0*FONT_HEIGHT, BLUE, -1); 00270 #else 00271 #error Unknown synchronization method. 00272 #endif 00273 #endif 00274 00275 // Display bargraph window. 00276 mmi_activity_display(TRUE, (U32)NULL); 00277 00278 #if (defined __GNUC__) 00279 sprintf( tmp, "RAM (DATA): %ld bytes", (U32)&_edata-(U32)&_data); 00280 et024006_PrintString(tmp, (const unsigned char *)&FONT8x8, 50, START_Y_DEMO_TEXT+10*FONT_HEIGHT, BLUE, -1); 00281 00282 sprintf( tmp, "RAM (BSS): %ld bytes", (U32)&end-(U32)&__bss_start); 00283 et024006_PrintString(tmp, (const unsigned char *)&FONT8x8, 50, START_Y_DEMO_TEXT+11*FONT_HEIGHT, BLUE, -1); 00284 00285 sprintf( tmp, "RAM (STACK): %ld bytes", (U32)&_estack-(U32)&_stack); 00286 et024006_PrintString(tmp, (const unsigned char *)&FONT8x8, 50, START_Y_DEMO_TEXT+12*FONT_HEIGHT, BLUE, -1); 00287 #endif 00288 #if (defined __GNUC__) 00289 et024006_PrintString("RAM (total used HEAP): bytes", (const unsigned char *)&FONT8x8, 50, START_Y_DEMO_TEXT+13*FONT_HEIGHT, BLUE, WHITE); 00290 et024006_PrintString("RAM (curr used HEAP): bytes", (const unsigned char *)&FONT8x8, 50, START_Y_DEMO_TEXT+14*FONT_HEIGHT, BLUE, WHITE); 00291 #elif (defined __ICCAVR32__) 00292 et024006_PrintString("RAM (free HEAP): bytes", (const unsigned char *)&FONT8x8, 50, START_Y_DEMO_TEXT+14*FONT_HEIGHT, BLUE, WHITE); 00293 #endif 00294 break; 00295 00296 case 2: cpu_set_timeout( cpu_ms_2_cy(TIMER_STARTUP, FCPU_HZ), &timer ); LED_On( LED1 ); break; 00297 case 3: cpu_set_timeout( cpu_ms_2_cy(TIMER_STARTUP, FCPU_HZ), &timer ); LED_On( LED2 ); break; 00298 case 4: cpu_set_timeout( cpu_ms_2_cy(TIMER_STARTUP, FCPU_HZ), &timer ); LED_On( LED3 ); break; 00299 case 5: cpu_set_timeout( cpu_ms_2_cy(TIMER_STARTUP, FCPU_HZ), &timer ); LED_Off( LED0 ); break; 00300 case 6: cpu_set_timeout( cpu_ms_2_cy(TIMER_STARTUP, FCPU_HZ), &timer ); LED_Off( LED1 ); break; 00301 case 7: cpu_set_timeout( cpu_ms_2_cy(TIMER_STARTUP, FCPU_HZ), &timer ); LED_Off( LED2 ); break; 00302 case 8: 00303 LED_Off( LED3 ); 00304 cpu_stop_timeout(&timer); 00305 break; 00306 00307 default: 00308 break; 00309 } 00310 } 00311 } 00312 }
U8* __bss_start |
Referenced by mmi_display().
U8* _data |
Referenced by mmi_display().
U8* _edata |
Referenced by mmi_display().
U8* _estack |
Referenced by mmi_display().
U8* _stack |
Referenced by mmi_display().
U32 dat_sample_index [static] |
Definition at line 113 of file device_audio_task.c.
Referenced by device_audio_task(), and device_audio_task_init().
Definition at line 91 of file device_audio_task.c.
U8* end |
Referenced by mmi_display().
U32 mmi_state = 0 [static] |
Definition at line 94 of file device_audio_task.c.
Referenced by device_audio_task(), and mmi_display().
Bool mute |
Public : (bit) mute mute is set to TRUE when ACTIVE mute is set to FALSE otherwise /.
Definition at line 104 of file device_audio_task.c.
Referenced by device_audio_task().
U16 sof_cnt [static] |
Definition at line 93 of file device_audio_task.c.
Referenced by device_audio_task_init(), and usb_sof_action().
t_cpu_time timer |
S16 volume |
Public : (S16) volume volume represents the current volume of audio stream /.
Definition at line 110 of file device_audio_task.c.
Referenced by volume_usb_to_appli().