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 /**   Device Data Pump Class                                              */
19 /**                                                                       */
20 /**************************************************************************/
21 /**************************************************************************/
22 
23 #define UX_SOURCE_CODE
24 
25 
26 /* Include necessary system files.  */
27 
28 #include "ux_api.h"
29 #include "ux_device_class_dpump.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _ux_device_class_dpump_entry                        PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Chaoqiong Xiao, Microsoft Corporation                               */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function is the entry point of the device dpump class. It      */
45 /*    will be called by the device stack enumeration module when the      */
46 /*    host has sent a SET_CONFIGURATION command and the dpump interface   */
47 /*    needs to be mounted.                                                */
48 /*                                                                        */
49 /*  INPUT                                                                 */
50 /*                                                                        */
51 /*    command                               Pointer to class command      */
52 /*                                                                        */
53 /*  OUTPUT                                                                */
54 /*                                                                        */
55 /*    Completion Status                                                   */
56 /*                                                                        */
57 /*  CALLS                                                                 */
58 /*                                                                        */
59 /*    _ux_device_class_dpump_initialize      Initialize dpump class       */
60 /*    _ux_device_class_dpump_activate        Activate dpump class         */
61 /*    _ux_device_class_dpump_deactivate      Deactivate dpump class       */
62 /*    _ux_device_class_dpump_change          Alternate setting change     */
63 /*                                                                        */
64 /*  CALLED BY                                                             */
65 /*                                                                        */
66 /*    Device Data Pump Class                                              */
67 /*                                                                        */
68 /*  RELEASE HISTORY                                                       */
69 /*                                                                        */
70 /*    DATE              NAME                      DESCRIPTION             */
71 /*                                                                        */
72 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
73 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
74 /*                                            resulting in version 6.1    */
75 /*                                                                        */
76 /**************************************************************************/
_ux_device_class_dpump_entry(UX_SLAVE_CLASS_COMMAND * command)77 UINT  _ux_device_class_dpump_entry(UX_SLAVE_CLASS_COMMAND *command)
78 {
79 
80 UINT        status;
81 
82 
83     /* The command request will tell us we need to do here, either a enumeration
84        query, an activation or a deactivation.  */
85     switch (command -> ux_slave_class_command_request)
86     {
87 
88     case UX_SLAVE_CLASS_COMMAND_INITIALIZE:
89 
90         /* Call the init function of the DPUMP class.  */
91         status =  _ux_device_class_dpump_initialize(command);
92 
93         /* Return the completion status.  */
94         return(status);
95 
96     case UX_SLAVE_CLASS_COMMAND_QUERY:
97 
98         /* Check the CLASS definition in the interface descriptor. */
99         if (command -> ux_slave_class_command_class == UX_SLAVE_CLASS_DPUMP_CLASS)
100             return(UX_SUCCESS);
101         else
102             return(UX_NO_CLASS_MATCH);
103 
104     case UX_SLAVE_CLASS_COMMAND_ACTIVATE:
105 
106         /* The activate command is used when the host has sent a SET_CONFIGURATION command
107            and this interface has to be mounted. Both Bulk endpoints have to be mounted
108            and the dpump thread needs to be activated.  */
109         status =  _ux_device_class_dpump_activate(command);
110 
111         /* Return the completion status.  */
112         return(status);
113 
114     case UX_SLAVE_CLASS_COMMAND_CHANGE:
115 
116         /* The change command is used when the host has sent a SET_INTERFACE command
117            to go from Alternate Setting 0 to 1 or revert to the default mode.  */
118         status =  _ux_device_class_dpump_change(command);
119 
120         /* Return the completion status.  */
121         return(status);
122 
123     case UX_SLAVE_CLASS_COMMAND_DEACTIVATE:
124 
125         /* The deactivate command is used when the device has been extracted.
126            The device endpoints have to be dismounted and the dpump thread canceled.  */
127         status =  _ux_device_class_dpump_deactivate(command);
128 
129         /* Return the completion status.  */
130         return(status);
131 
132     case UX_SLAVE_CLASS_COMMAND_REQUEST:
133 
134         /* Return the completion status.  */
135         return(UX_SUCCESS);
136 
137     default:
138 
139         /* Error trap. */
140         _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_FUNCTION_NOT_SUPPORTED);
141 
142         /* If trace is enabled, insert this event into the trace buffer.  */
143         UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_FUNCTION_NOT_SUPPORTED, 0, 0, 0, UX_TRACE_ERRORS, 0, 0)
144 
145         /* Return an error.  */
146         return(UX_FUNCTION_NOT_SUPPORTED);
147     }
148 }
149 
150