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 /**************************************************************************/ 33 /* */ 34 /* FUNCTION RELEASE */ 35 /* */ 36 /* _ux_device_class_audio_uninitialize PORTABLE C */ 37 /* 6.1.11 */ 38 /* AUTHOR */ 39 /* */ 40 /* Chaoqiong Xiao, Microsoft Corporation */ 41 /* */ 42 /* DESCRIPTION */ 43 /* */ 44 /* This function uninitialize the Audio class. */ 45 /* */ 46 /* INPUT */ 47 /* */ 48 /* command Pointer to a class command */ 49 /* */ 50 /* OUTPUT */ 51 /* */ 52 /* Completion Status */ 53 /* */ 54 /* CALLS */ 55 /* */ 56 /* _ux_device_thread_delete Delete thread used */ 57 /* _ux_utility_memory_free Free used local memory */ 58 /* */ 59 /* CALLED BY */ 60 /* */ 61 /* Device Audio Class */ 62 /* */ 63 /* RELEASE HISTORY */ 64 /* */ 65 /* DATE NAME DESCRIPTION */ 66 /* */ 67 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ 68 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ 69 /* resulting in version 6.1 */ 70 /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */ 71 /* refined macros names, */ 72 /* added feedback support, */ 73 /* fixed stream uninitialize, */ 74 /* resulting in version 6.1.10 */ 75 /* 04-25-2022 Chaoqiong Xiao Modified comment(s), */ 76 /* fixed standalone compile, */ 77 /* resulting in version 6.1.11 */ 78 /* */ 79 /**************************************************************************/ _ux_device_class_audio_uninitialize(UX_SLAVE_CLASS_COMMAND * command)80UINT _ux_device_class_audio_uninitialize(UX_SLAVE_CLASS_COMMAND *command) 81 { 82 83 UX_DEVICE_CLASS_AUDIO *audio; 84 UX_DEVICE_CLASS_AUDIO_STREAM *stream; 85 UX_SLAVE_CLASS *audio_class; 86 ULONG i; 87 88 89 /* Get the class container. */ 90 audio_class = command -> ux_slave_class_command_class_ptr; 91 92 /* Get the class instance in the container. */ 93 audio = (UX_DEVICE_CLASS_AUDIO *) audio_class -> ux_slave_class_instance; 94 95 /* Sanity check. */ 96 if (audio != UX_NULL) 97 { 98 99 /* Free the stream resources. */ 100 stream = (UX_DEVICE_CLASS_AUDIO_STREAM *)((UCHAR *)audio + sizeof(UX_DEVICE_CLASS_AUDIO)); 101 for (i = 0; i < audio -> ux_device_class_audio_streams_nb; i ++) 102 { 103 #if !defined(UX_DEVICE_STANDALONE) 104 _ux_device_thread_delete(&stream -> ux_device_class_audio_stream_thread); 105 #if defined(UX_DEVICE_CLASS_AUDIO_FEEDBACK_SUPPORT) 106 if (stream -> ux_device_class_audio_stream_feedback_thread_stack) 107 { 108 _ux_device_thread_delete(&stream -> ux_device_class_audio_stream_feedback_thread); 109 _ux_utility_memory_free(stream -> ux_device_class_audio_stream_feedback_thread_stack); 110 } 111 #endif 112 _ux_utility_memory_free(stream -> ux_device_class_audio_stream_thread_stack); 113 #endif 114 _ux_utility_memory_free(stream -> ux_device_class_audio_stream_buffer); 115 116 /* Next stream instance. */ 117 stream ++; 118 } 119 120 #if defined(UX_DEVICE_CLASS_AUDIO_INTERRUPT_SUPPORT) 121 #if !defined(UX_DEVICE_STANDALONE) 122 _ux_device_thread_delete(&audio_class -> ux_slave_class_thread); 123 _ux_utility_memory_free(audio_class -> ux_slave_class_thread_stack); 124 125 _ux_device_semaphore_delete(&audio -> ux_device_class_audio_status_semaphore); 126 _ux_device_mutex_delete(&audio -> ux_device_class_audio_status_mutex); 127 #else 128 #endif 129 #endif 130 131 /* Free the audio instance with controls and streams. */ 132 _ux_utility_memory_free(audio); 133 } 134 135 /* Return completion status. */ 136 return(UX_SUCCESS); 137 } 138