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 /** USBX Component */
15 /** */
16 /** Device Audio Class */
17 /** */
18 /**************************************************************************/
19 /**************************************************************************/
20
21 #define UX_SOURCE_CODE
22
23
24 /* Include necessary system files. */
25
26 #include "ux_api.h"
27 #include "ux_device_class_audio.h"
28 #include "ux_device_stack.h"
29
30
31 /**************************************************************************/
32 /* */
33 /* FUNCTION RELEASE */
34 /* */
35 /* _ux_device_class_audio_read_frame_get PORTABLE C */
36 /* 6.2.1 */
37 /* AUTHOR */
38 /* */
39 /* Chaoqiong Xiao, Microsoft Corporation */
40 /* */
41 /* DESCRIPTION */
42 /* */
43 /* This function obtain frame access pointer from the Audio class. */
44 /* */
45 /* INPUT */
46 /* */
47 /* stream Address of audio stream */
48 /* instance */
49 /* frame_data Pointer to buffer to save */
50 /* pointer to frame data */
51 /* frame_length Pointer to buffer to save */
52 /* pointer to frame length */
53 /* */
54 /* OUTPUT */
55 /* */
56 /* None */
57 /* */
58 /* CALLS */
59 /* */
60 /* */
61 /* CALLED BY */
62 /* */
63 /* Application */
64 /* */
65 /* RELEASE HISTORY */
66 /* */
67 /* DATE NAME DESCRIPTION */
68 /* */
69 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
70 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
71 /* resulting in version 6.1 */
72 /* 03-08-2023 Chaoqiong Xiao Modified comment(s), */
73 /* resulting in version 6.2.1 */
74 /* */
75 /**************************************************************************/
_ux_device_class_audio_read_frame_get(UX_DEVICE_CLASS_AUDIO_STREAM * stream,UCHAR ** frame_data,ULONG * frame_length)76 UINT _ux_device_class_audio_read_frame_get(UX_DEVICE_CLASS_AUDIO_STREAM *stream,
77 UCHAR **frame_data, ULONG *frame_length)
78 {
79
80 UX_SLAVE_ENDPOINT *endpoint;
81 UX_SLAVE_DEVICE *device;
82
83
84 /* Get the pointer to the device. */
85 device = &_ux_system_slave -> ux_system_slave_device;
86
87 /* As long as the device is in the CONFIGURED state. */
88 if (device -> ux_slave_device_state != UX_DEVICE_CONFIGURED)
89 {
90
91 /* Cannot proceed with command, the interface is down. */
92 return(UX_CONFIGURATION_HANDLE_UNKNOWN);
93 }
94
95 /* Check if endpoint is available. */
96 endpoint = stream -> ux_device_class_audio_stream_endpoint;
97 if (endpoint == UX_NULL)
98 return(UX_ERROR);
99
100 /* Check if endpoint direction is OK. */
101 if ((endpoint -> ux_slave_endpoint_descriptor.bEndpointAddress & UX_ENDPOINT_DIRECTION) != UX_ENDPOINT_OUT)
102 return(UX_ERROR);
103
104 /* Underflow!! */
105 if (stream -> ux_device_class_audio_stream_access_pos -> ux_device_class_audio_frame_length == 0)
106 {
107 return(UX_BUFFER_OVERFLOW);
108 }
109
110 /* Obtain frame structure pointer. */
111 *frame_data = stream -> ux_device_class_audio_stream_access_pos -> ux_device_class_audio_frame_data;
112 *frame_length = stream -> ux_device_class_audio_stream_access_pos -> ux_device_class_audio_frame_length;
113
114 return(UX_SUCCESS);
115 }
116
117 /**************************************************************************/
118 /* */
119 /* FUNCTION RELEASE */
120 /* */
121 /* _uxe_device_class_audio_read_frame_get PORTABLE C */
122 /* 6.2.1 */
123 /* AUTHOR */
124 /* */
125 /* Chaoqiong Xiao, Microsoft Corporation */
126 /* */
127 /* DESCRIPTION */
128 /* */
129 /* This function checks errors in frame buffer getting function call. */
130 /* */
131 /* INPUT */
132 /* */
133 /* stream Address of audio stream */
134 /* instance */
135 /* frame_data Pointer to buffer to save */
136 /* pointer to frame data */
137 /* frame_length Pointer to buffer to save */
138 /* pointer to frame length */
139 /* */
140 /* OUTPUT */
141 /* */
142 /* None */
143 /* */
144 /* CALLS */
145 /* */
146 /* _ux_device_class_audio_read_frame_get Get buffer from 1st FIFO item */
147 /* */
148 /* CALLED BY */
149 /* */
150 /* Application */
151 /* */
152 /* RELEASE HISTORY */
153 /* */
154 /* DATE NAME DESCRIPTION */
155 /* */
156 /* 03-08-2023 Chaoqiong Xiao Initial Version 6.2.1 */
157 /* */
158 /**************************************************************************/
_uxe_device_class_audio_read_frame_get(UX_DEVICE_CLASS_AUDIO_STREAM * stream,UCHAR ** frame_data,ULONG * frame_length)159 UINT _uxe_device_class_audio_read_frame_get(UX_DEVICE_CLASS_AUDIO_STREAM *stream,
160 UCHAR **frame_data, ULONG *frame_length)
161 {
162
163 /* Sanity checks. */
164 if (stream == UX_NULL || frame_data == UX_NULL || frame_length == UX_NULL)
165 return(UX_INVALID_PARAMETER);
166
167 /* Get frame access buffer. */
168 return(_ux_device_class_audio_read_frame_get(stream, frame_data, frame_length));
169 }
170