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 /**   Slave Simulator Controller Driver                                   */
19 /**                                                                       */
20 /**************************************************************************/
21 /**************************************************************************/
22 
23 #define UX_SOURCE_CODE
24 
25 /* Include necessary system files.  */
26 
27 #include "ux_api.h"
28 #include "ux_dcd_sim_slave.h"
29 
30 
31 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _ux_dcd_sim_slave_function                          PORTABLE C      */
36 /*                                                           6.1.10       */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    Chaoqiong Xiao, Microsoft Corporation                               */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    This function dispatches the DCD function internally to the         */
44 /*    slave simulator controller.                                         */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    dcd                                   Pointer to device controller  */
49 /*    function                              Function requested            */
50 /*    parameter                             Pointer to parameter structure*/
51 /*                                                                        */
52 /*                                                                        */
53 /*  OUTPUT                                                                */
54 /*                                                                        */
55 /*    Completion Status                                                   */
56 /*                                                                        */
57 /*  CALLS                                                                 */
58 /*                                                                        */
59 /*    _ux_dcd_sim_slave_address_set         Set address                   */
60 /*    _ux_dcd_sim_slave_endpoint_create     Create endpoint               */
61 /*    _ux_dcd_sim_slave_endpoint_destroy    Destroy endpoint              */
62 /*    _ux_dcd_sim_slave_endpoint_reset      Reset endpoint                */
63 /*    _ux_dcd_sim_slave_endpoint_stall      Stall endpoint                */
64 /*    _ux_dcd_sim_slave_endpoint_status     Get endpoint status           */
65 /*    _ux_dcd_sim_slave_frame_number_get    Get frame number              */
66 /*    _ux_dcd_sim_slave_state_change        Change state                  */
67 /*    _ux_dcd_sim_slave_transfer_abort      Abort transfer                */
68 /*    _ux_dcd_sim_slave_transfer_request    Request transfer              */
69 /*                                                                        */
70 /*  CALLED BY                                                             */
71 /*                                                                        */
72 /*    USBX Device Stack                                                   */
73 /*                                                                        */
74 /*  RELEASE HISTORY                                                       */
75 /*                                                                        */
76 /*    DATE              NAME                      DESCRIPTION             */
77 /*                                                                        */
78 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
79 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
80 /*                                            resulting in version 6.1    */
81 /*  01-31-2022     Chaoqiong Xiao           Modified comment(s),          */
82 /*                                            added standalone support,   */
83 /*                                            resulting in version 6.1.10 */
84 /*                                                                        */
85 /**************************************************************************/
_ux_dcd_sim_slave_function(UX_SLAVE_DCD * dcd,UINT function,VOID * parameter)86 UINT   _ux_dcd_sim_slave_function(UX_SLAVE_DCD *dcd, UINT function, VOID *parameter)
87 {
88 
89 UINT                    status;
90 UX_DCD_SIM_SLAVE        *dcd_sim_slave;
91 
92 
93     /* Check the status of the controller.  */
94     if (dcd -> ux_slave_dcd_status == UX_UNUSED)
95     {
96 
97         /* Error trap. */
98         _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_DCD, UX_CONTROLLER_UNKNOWN);
99 
100         /* If trace is enabled, insert this event into the trace buffer.  */
101         UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_CONTROLLER_UNKNOWN, 0, 0, 0, UX_TRACE_ERRORS, 0, 0)
102 
103         return(UX_CONTROLLER_UNKNOWN);
104     }
105 
106     /* Get the pointer to the Slave simulation DCD.  */
107     dcd_sim_slave =  (UX_DCD_SIM_SLAVE *) dcd -> ux_slave_dcd_controller_hardware;
108 
109     /* Look at the function and route it.  */
110     switch(function)
111     {
112 
113     case UX_DCD_GET_FRAME_NUMBER:
114 
115         status =  _ux_dcd_sim_slave_frame_number_get(dcd_sim_slave, (ULONG *) parameter);
116         break;
117 
118 #if defined(UX_DEVICE_STANDALONE)
119     case UX_DCD_TRANSFER_RUN:
120 
121         status =  _ux_dcd_sim_slave_transfer_run(dcd_sim_slave, (UX_SLAVE_TRANSFER *) parameter);
122         break;
123 #else
124     case UX_DCD_TRANSFER_REQUEST:
125 
126         status =  _ux_dcd_sim_slave_transfer_request(dcd_sim_slave, (UX_SLAVE_TRANSFER *) parameter);
127         break;
128 #endif
129 
130     case UX_DCD_TRANSFER_ABORT:
131 
132         status =  _ux_dcd_sim_slave_transfer_abort(dcd_sim_slave, (UX_SLAVE_TRANSFER *) parameter);
133         break;
134 
135     case UX_DCD_CREATE_ENDPOINT:
136 
137         status =  _ux_dcd_sim_slave_endpoint_create(dcd_sim_slave, parameter);
138         break;
139 
140     case UX_DCD_DESTROY_ENDPOINT:
141 
142         status =  _ux_dcd_sim_slave_endpoint_destroy(dcd_sim_slave, parameter);
143         break;
144 
145     case UX_DCD_RESET_ENDPOINT:
146 
147         status =  _ux_dcd_sim_slave_endpoint_reset(dcd_sim_slave, parameter);
148         break;
149 
150     case UX_DCD_STALL_ENDPOINT:
151 
152         status =  _ux_dcd_sim_slave_endpoint_stall(dcd_sim_slave, parameter);
153         break;
154 
155     case UX_DCD_SET_DEVICE_ADDRESS:
156 
157         status =  _ux_dcd_sim_slave_address_set(dcd_sim_slave, (ULONG) (ALIGN_TYPE) parameter);
158         break;
159 
160     case UX_DCD_CHANGE_STATE:
161 
162         status =  _ux_dcd_sim_slave_state_change(dcd_sim_slave, (ULONG) (ALIGN_TYPE)  parameter);
163         break;
164 
165     case UX_DCD_ENDPOINT_STATUS:
166 
167         status =  _ux_dcd_sim_slave_endpoint_status(dcd_sim_slave, (ULONG) (ALIGN_TYPE) parameter);
168         break;
169 
170     case UX_DCD_ISR_PENDING:
171 
172         status = UX_SUCCESS;
173         break;
174 
175     default:
176 
177         /* Error trap. */
178         _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_DCD, UX_FUNCTION_NOT_SUPPORTED);
179 
180         /* If trace is enabled, insert this event into the trace buffer.  */
181         UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_FUNCTION_NOT_SUPPORTED, 0, 0, 0, UX_TRACE_ERRORS, 0, 0)
182 
183         status = UX_FUNCTION_NOT_SUPPORTED;
184     }
185 
186     /* Return completion status.  */
187     return(status);
188 }
189 
190