1 /***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the MIT License which is available at
6 * https://opensource.org/licenses/MIT.
7 *
8 * SPDX-License-Identifier: MIT
9 **************************************************************************/
10
11
12 /**************************************************************************/
13 /**************************************************************************/
14 /** */
15 /** USBX Component */
16 /** */
17 /** Audio Class */
18 /** */
19 /**************************************************************************/
20 /**************************************************************************/
21
22
23 /* Include necessary system files. */
24
25 #define UX_SOURCE_CODE
26
27 #include "ux_api.h"
28 #include "ux_host_class_audio.h"
29 #include "ux_host_stack.h"
30
31
32 /**************************************************************************/
33 /* */
34 /* FUNCTION RELEASE */
35 /* */
36 /* _ux_host_class_audio_interrupt_start PORTABLE C */
37 /* 6.1.12 */
38 /* AUTHOR */
39 /* */
40 /* Chaoqiong Xiao, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* This function starts audio control (AC) interface interrupt */
45 /* message polling. */
46 /* */
47 /* Note it should be called after audio control instance is activated */
48 /* and should be called only once before the instance is deactivated. */
49 /* */
50 /* INPUT */
51 /* */
52 /* audio Pointer to audio control (AC) */
53 /* instance */
54 /* callback_function Callback function invoked on */
55 /* interrupt message reception */
56 /* arg Callback argument passed to */
57 /* callback function */
58 /* */
59 /* OUTPUT */
60 /* */
61 /* Completion Status */
62 /* */
63 /* CALLS */
64 /* */
65 /* _ux_host_stack_class_instance_verify Verify instance is valid */
66 /* _ux_host_stack_transfer_request Process transfer request */
67 /* */
68 /* CALLED BY */
69 /* */
70 /* Application */
71 /* */
72 /* RELEASE HISTORY */
73 /* */
74 /* DATE NAME DESCRIPTION */
75 /* */
76 /* 07-29-2022 Chaoqiong Xiao Initial Version 6.1.12 */
77 /* */
78 /**************************************************************************/
_ux_host_class_audio_interrupt_start(UX_HOST_CLASS_AUDIO_AC * audio,VOID (* callback_function)(UX_HOST_CLASS_AUDIO_AC * audio,UCHAR * message,ULONG length,VOID * arg),VOID * arg)79 UINT _ux_host_class_audio_interrupt_start(UX_HOST_CLASS_AUDIO_AC *audio,
80 VOID(*callback_function)(UX_HOST_CLASS_AUDIO_AC *audio,
81 UCHAR *message, ULONG length,
82 VOID *arg),
83 VOID *arg)
84 {
85 #if !defined(UX_HOST_CLASS_AUDIO_INTERRUPT_SUPPORT)
86 UX_PARAMETER_NOT_USED(audio);
87 UX_PARAMETER_NOT_USED(callback_function);
88 UX_PARAMETER_NOT_USED(arg);
89 return(UX_FUNCTION_NOT_SUPPORTED);
90 #else
91 UX_ENDPOINT *endpoint;
92 UX_TRANSFER *transfer;
93 UINT status;
94
95
96 /* Ensure the instance is valid. */
97 if (_ux_host_stack_class_instance_verify(_ux_system_host_class_audio_name, (VOID *) audio) != UX_SUCCESS)
98 {
99
100 /* Error trap. */
101 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_INSTANCE_UNKNOWN);
102
103 /* If trace is enabled, insert this event into the trace buffer. */
104 UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, audio, 0, 0, UX_TRACE_ERRORS, 0, 0)
105
106 return(UX_HOST_CLASS_INSTANCE_UNKNOWN);
107 }
108
109 /* Ensure endpoint is valid. */
110 endpoint = audio -> ux_host_class_audio_interrupt_endpoint;
111 if (endpoint == UX_NULL)
112 return(UX_FUNCTION_NOT_SUPPORTED);
113
114 /* Check if interrupt started. */
115 if (audio -> ux_host_class_audio_interrupt_started)
116 return(UX_ALREADY_ACTIVATED);
117
118 /* Set application callback and its argument. */
119 audio -> ux_host_class_audio_interrupt_callback_arg = arg;
120 audio -> ux_host_class_audio_interrupt_callback = callback_function;
121
122 /* Get the transfer request. */
123 transfer = &endpoint -> ux_endpoint_transfer_request;
124
125 /* Save class instance to issue this transfer. */
126 transfer -> ux_transfer_request_class_instance = (VOID *)audio;
127
128 /* Save transfer complete callback. */
129 transfer -> ux_transfer_request_completion_function = _ux_host_class_audio_interrupt_notification;
130
131 /* The transfer on the interrupt endpoint can be started. */
132 status = _ux_host_stack_transfer_request(transfer);
133 if (status == UX_SUCCESS)
134 audio -> ux_host_class_audio_interrupt_started = UX_TRUE;
135
136 /* Return completion status. */
137 return(status);
138 #endif
139 }
140
141
142 /**************************************************************************/
143 /* */
144 /* FUNCTION RELEASE */
145 /* */
146 /* _uxe_host_class_audio_interrupt_start PORTABLE C */
147 /* 6.3.0 */
148 /* AUTHOR */
149 /* */
150 /* Chaoqiong Xiao, Microsoft Corporation */
151 /* */
152 /* DESCRIPTION */
153 /* */
154 /* This function checks errors in audio interrupt start function call. */
155 /* */
156 /* INPUT */
157 /* */
158 /* audio Pointer to audio control (AC) */
159 /* instance */
160 /* callback_function Callback function invoked on */
161 /* interrupt message reception */
162 /* arg Callback argument passed to */
163 /* callback function */
164 /* */
165 /* OUTPUT */
166 /* */
167 /* Status */
168 /* */
169 /* CALLS */
170 /* */
171 /* _uxe_host_class_audio_interrupt_start Start audio interrupt polling */
172 /* */
173 /* CALLED BY */
174 /* */
175 /* Application */
176 /* */
177 /* RELEASE HISTORY */
178 /* */
179 /* DATE NAME DESCRIPTION */
180 /* */
181 /* 10-31-2023 Chaoqiong Xiao Initial Version 6.3.0 */
182 /* */
183 /**************************************************************************/
_uxe_host_class_audio_interrupt_start(UX_HOST_CLASS_AUDIO_AC * audio,VOID (* callback_function)(UX_HOST_CLASS_AUDIO_AC * audio,UCHAR * message,ULONG length,VOID * arg),VOID * arg)184 UINT _uxe_host_class_audio_interrupt_start(UX_HOST_CLASS_AUDIO_AC *audio,
185 VOID(*callback_function)(UX_HOST_CLASS_AUDIO_AC *audio,
186 UCHAR *message, ULONG length,
187 VOID *arg),
188 VOID *arg)
189 {
190
191 /* Sanity checks. */
192 if (audio == UX_NULL)
193 return(UX_INVALID_PARAMETER);
194
195 /* Invoke interrupt start function. */
196 return(_ux_host_class_audio_interrupt_start(audio, callback_function, arg));
197 }
198