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 PIMA 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_pima.h"
29 #include "ux_device_stack.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _ux_device_class_pima_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 pima class. It              */
45 /*    will be called by the device stack enumeration module when the      */
46 /*    host has sent a SET_CONFIGURATION command and the pima 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_pima_initialize       Initialize pima class        */
60 /*    _ux_device_class_pima_activate         Activate pima class          */
61 /*    _ux_device_class_pima_deactivate       Deactivate pima class        */
62 /*    _ux_device_class_pima_control_request  Request control              */
63 /*                                                                        */
64 /*  CALLED BY                                                             */
65 /*                                                                        */
66 /*    PIMA 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_pima_entry(UX_SLAVE_CLASS_COMMAND * command)77 UINT  _ux_device_class_pima_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 PIMA class.  */
91         status =  _ux_device_class_pima_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_DEVICE_CLASS_PIMA_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 pima thread needs to be activated.  */
109         status =  _ux_device_class_pima_activate(command);
110 
111         /* Return the completion status.  */
112         return(status);
113 
114     case UX_SLAVE_CLASS_COMMAND_DEACTIVATE:
115 
116         /* The deactivate command is used when the device has been extracted.
117            The device endpoints have to be dismounted and the pima thread canceled.  */
118         status =  _ux_device_class_pima_deactivate(command);
119 
120         /* Return the completion status.  */
121         return(status);
122 
123     case UX_SLAVE_CLASS_COMMAND_REQUEST:
124 
125         /* The request command is used when the host sends a command on the control endpoint.  */
126         status = _ux_device_class_pima_control_request(command);
127 
128         /* Return the completion status.  */
129         return(status);
130 
131     default:
132 
133         /* If trace is enabled, insert this event into the trace buffer.  */
134         UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_FUNCTION_NOT_SUPPORTED, 0, 0, 0, UX_TRACE_ERRORS, 0, 0)
135 
136         /* Return an error.  */
137         return(UX_FUNCTION_NOT_SUPPORTED);
138     }
139 }
140 
141