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 /**                                                                       */
16 /** USBX Component                                                        */
17 /**                                                                       */
18 /**   Audio Class                                                         */
19 /**                                                                       */
20 /**************************************************************************/
21 /**************************************************************************/
22 
23 
24 /* Include necessary system files.  */
25 
26 #define UX_SOURCE_CODE
27 
28 #include "ux_api.h"
29 #include "ux_host_class_audio.h"
30 #include "ux_host_stack.h"
31 
32 
33 /**************************************************************************/
34 /*                                                                        */
35 /*  FUNCTION                                               RELEASE        */
36 /*                                                                        */
37 /*    _ux_host_class_audio_interrupt_start                PORTABLE C      */
38 /*                                                           6.1.12       */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Chaoqiong Xiao, Microsoft Corporation                               */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This function starts audio control (AC) interface interrupt         */
46 /*    message polling.                                                    */
47 /*                                                                        */
48 /*    Note it should be called after audio control instance is activated  */
49 /*    and should be called only once before the instance is deactivated.  */
50 /*                                                                        */
51 /*  INPUT                                                                 */
52 /*                                                                        */
53 /*    audio                                 Pointer to audio control (AC) */
54 /*                                          instance                      */
55 /*    callback_function                     Callback function invoked on  */
56 /*                                          interrupt message reception   */
57 /*    arg                                   Callback argument passed to   */
58 /*                                          callback function             */
59 /*                                                                        */
60 /*  OUTPUT                                                                */
61 /*                                                                        */
62 /*    Completion Status                                                   */
63 /*                                                                        */
64 /*  CALLS                                                                 */
65 /*                                                                        */
66 /*    _ux_host_stack_class_instance_verify  Verify instance is valid      */
67 /*    _ux_host_stack_transfer_request       Process transfer request      */
68 /*                                                                        */
69 /*  CALLED BY                                                             */
70 /*                                                                        */
71 /*    Application                                                         */
72 /*                                                                        */
73 /*  RELEASE HISTORY                                                       */
74 /*                                                                        */
75 /*    DATE              NAME                      DESCRIPTION             */
76 /*                                                                        */
77 /*  07-29-2022     Chaoqiong Xiao           Initial Version 6.1.12        */
78 /*                                                                        */
79 /**************************************************************************/
_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)80 UINT    _ux_host_class_audio_interrupt_start(UX_HOST_CLASS_AUDIO_AC *audio,
81                         VOID(*callback_function)(UX_HOST_CLASS_AUDIO_AC *audio,
82                                                  UCHAR *message, ULONG length,
83                                                  VOID *arg),
84                         VOID *arg)
85 {
86 #if !defined(UX_HOST_CLASS_AUDIO_INTERRUPT_SUPPORT)
87     UX_PARAMETER_NOT_USED(audio);
88     UX_PARAMETER_NOT_USED(callback_function);
89     UX_PARAMETER_NOT_USED(arg);
90     return(UX_FUNCTION_NOT_SUPPORTED);
91 #else
92 UX_ENDPOINT     *endpoint;
93 UX_TRANSFER     *transfer;
94 UINT            status;
95 
96 
97     /* Ensure the instance is valid.  */
98     if (_ux_host_stack_class_instance_verify(_ux_system_host_class_audio_name, (VOID *) audio) != UX_SUCCESS)
99     {
100 
101         /* Error trap. */
102         _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_INSTANCE_UNKNOWN);
103 
104         /* If trace is enabled, insert this event into the trace buffer.  */
105         UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, audio, 0, 0, UX_TRACE_ERRORS, 0, 0)
106 
107         return(UX_HOST_CLASS_INSTANCE_UNKNOWN);
108     }
109 
110     /* Ensure endpoint is valid.  */
111     endpoint = audio -> ux_host_class_audio_interrupt_endpoint;
112     if (endpoint == UX_NULL)
113         return(UX_FUNCTION_NOT_SUPPORTED);
114 
115     /* Check if interrupt started.  */
116     if (audio -> ux_host_class_audio_interrupt_started)
117         return(UX_ALREADY_ACTIVATED);
118 
119     /* Set application callback and its argument.  */
120     audio -> ux_host_class_audio_interrupt_callback_arg = arg;
121     audio -> ux_host_class_audio_interrupt_callback = callback_function;
122 
123     /* Get the transfer request.  */
124     transfer = &endpoint -> ux_endpoint_transfer_request;
125 
126     /* Save class instance to issue this transfer.  */
127     transfer -> ux_transfer_request_class_instance = (VOID *)audio;
128 
129     /* Save transfer complete callback.  */
130     transfer -> ux_transfer_request_completion_function = _ux_host_class_audio_interrupt_notification;
131 
132     /* The transfer on the interrupt endpoint can be started.  */
133     status =  _ux_host_stack_transfer_request(transfer);
134     if (status == UX_SUCCESS)
135         audio -> ux_host_class_audio_interrupt_started = UX_TRUE;
136 
137     /* Return completion status.  */
138     return(status);
139 #endif
140 }
141