1 /**************************************************************************/ 2 /* */ 3 /* Copyright (c) Microsoft Corporation. All rights reserved. */ 4 /* */ 5 /* This software is licensed under the Microsoft Software License */ 6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */ 7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ 8 /* and in the root directory of this software. */ 9 /* */ 10 /**************************************************************************/ 11 12 /**************************************************************************/ 13 /**************************************************************************/ 14 /** */ 15 /** USBX Component */ 16 /** */ 17 /** Device Audio Class */ 18 /** */ 19 /**************************************************************************/ 20 /**************************************************************************/ 21 22 #define UX_SOURCE_CODE 23 24 25 /* Include necessary system files. */ 26 27 #include "ux_api.h" 28 #include "ux_device_class_audio.h" 29 #include "ux_device_stack.h" 30 31 32 #if defined(UX_DEVICE_STANDALONE) 33 /**************************************************************************/ 34 /* */ 35 /* FUNCTION RELEASE */ 36 /* */ 37 /* _ux_device_class_audio_tasks_run PORTABLE C */ 38 /* 6.2.0 */ 39 /* AUTHOR */ 40 /* */ 41 /* Yajun Xia, Microsoft Corporation */ 42 /* */ 43 /* DESCRIPTION */ 44 /* */ 45 /* This function is the background task of the audio. */ 46 /* */ 47 /* It's for standalone mode. */ 48 /* */ 49 /* INPUT */ 50 /* */ 51 /* instance Pointer to audio class */ 52 /* */ 53 /* OUTPUT */ 54 /* */ 55 /* State machine status */ 56 /* UX_STATE_EXIT Device not configured */ 57 /* UX_STATE_IDLE No streaming transfer running */ 58 /* UX_STATE_WAIT Streaming transfer running */ 59 /* */ 60 /* CALLS */ 61 /* */ 62 /* (ux_device_class_audio_stream_task_function) */ 63 /* Run stream task */ 64 /* (ux_device_class_audio_stream_feedback_task_function) */ 65 /* Run stream feedback task */ 66 /* */ 67 /* CALLED BY */ 68 /* */ 69 /* USBX Device Stack */ 70 /* */ 71 /* RELEASE HISTORY */ 72 /* */ 73 /* DATE NAME DESCRIPTION */ 74 /* */ 75 /* 10-31-2022 Yajun Xia Initial Version 6.2.0 */ 76 /* */ 77 /**************************************************************************/ _ux_device_class_audio_tasks_run(VOID * instance)78UINT _ux_device_class_audio_tasks_run(VOID *instance) 79 { 80 UX_SLAVE_DEVICE *device; 81 UX_DEVICE_CLASS_AUDIO *audio; 82 UX_DEVICE_CLASS_AUDIO_STREAM *stream; 83 ULONG stream_index; 84 UINT status; 85 #if defined(UX_DEVICE_CLASS_AUDIO_INTERRUPT_SUPPORT) 86 ULONG interrupt_running_count = 0; 87 #endif 88 ULONG stream_running_count = 0; 89 #if defined(UX_DEVICE_CLASS_AUDIO_FEEDBACK_SUPPORT) 90 ULONG feedback_running_count = 0; 91 #endif 92 93 /* Get audio instance. */ 94 audio = (UX_DEVICE_CLASS_AUDIO *) instance; 95 96 /* Get the pointer to the device. */ 97 device = &_ux_system_slave -> ux_system_slave_device; 98 99 /* Check if the device is configured. */ 100 if (device -> ux_slave_device_state != UX_DEVICE_CONFIGURED) 101 return(UX_STATE_EXIT); 102 103 #if defined(UX_DEVICE_CLASS_AUDIO_INTERRUPT_SUPPORT) 104 105 /* Run audio status tasks. */ 106 status = _ux_device_class_audio_interrupt_task_function(audio); 107 if (status == UX_STATE_EXIT) 108 return(status); 109 if (status == UX_STATE_WAIT) 110 interrupt_running_count++; 111 #endif 112 113 for (stream_index = 0; 114 stream_index < audio -> ux_device_class_audio_streams_nb; 115 stream_index ++) 116 { 117 stream = &audio -> ux_device_class_audio_streams[stream_index]; 118 status = stream -> ux_device_class_audio_stream_task_function(stream); 119 if (status == UX_STATE_EXIT) 120 return(status); 121 if (status == UX_STATE_WAIT) 122 stream_running_count ++; 123 124 #if defined(UX_DEVICE_CLASS_AUDIO_FEEDBACK_SUPPORT) 125 if (stream -> ux_device_class_audio_stream_feedback_task_function != UX_NULL) 126 { 127 status = stream -> ux_device_class_audio_stream_feedback_task_function(stream); 128 if (status == UX_STATE_EXIT) 129 return(status); 130 if (status == UX_STATE_WAIT) 131 feedback_running_count ++; 132 } 133 #endif 134 } 135 136 if ((stream_running_count > 0) 137 #if defined(UX_DEVICE_CLASS_AUDIO_INTERRUPT_SUPPORT) 138 || (interrupt_running_count > 0) 139 #endif 140 #if defined(UX_DEVICE_CLASS_AUDIO_FEEDBACK_SUPPORT) 141 || (feedback_running_count > 0) 142 #endif 143 ) 144 { 145 return UX_STATE_WAIT; 146 } 147 else 148 { 149 return UX_STATE_IDLE; 150 } 151 } 152 153 #endif