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 /**                                                                       */
15 /** USBX Component                                                        */
16 /**                                                                       */
17 /**   Slave Simulator Controller Driver                                   */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 
23 /**************************************************************************/
24 /*                                                                        */
25 /*  COMPONENT DEFINITION                                   RELEASE        */
26 /*                                                                        */
27 /*    ux_dcd_sim_slave.h                                  PORTABLE C      */
28 /*                                                           6.1.10       */
29 /*  AUTHOR                                                                */
30 /*                                                                        */
31 /*    Chaoqiong Xiao, Microsoft Corporation                               */
32 /*                                                                        */
33 /*  DESCRIPTION                                                           */
34 /*                                                                        */
35 /*    This file contains all the header and extern functions used by the  */
36 /*    USBX slave simulator. It is designed to work ONLY with the USBX     */
37 /*    host simulator.                                                     */
38 /*                                                                        */
39 /*  RELEASE HISTORY                                                       */
40 /*                                                                        */
41 /*    DATE              NAME                      DESCRIPTION             */
42 /*                                                                        */
43 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
44 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
45 /*                                            resulting in version 6.1    */
46 /*  04-02-2021     Chaoqiong Xiao           Modified comment(s),          */
47 /*                                            added HCD connected to,     */
48 /*                                            supported bi-dir-endpoints, */
49 /*                                            resulting in version 6.1.6  */
50 /*  08-02-2021     Chaoqiong Xiao           Modified comment(s),          */
51 /*                                            added extern "C" keyword    */
52 /*                                            for compatibility with C++, */
53 /*                                            resulting in version 6.1.8  */
54 /*  01-31-2022     Chaoqiong Xiao           Modified comment(s),          */
55 /*                                            added standalone support,   */
56 /*                                            resulting in version 6.1.10 */
57 /*                                                                        */
58 /**************************************************************************/
59 
60 #ifndef UX_DCD_SIM_SLAVE_H
61 #define UX_DCD_SIM_SLAVE_H
62 
63 /* Determine if a C++ compiler is being used.  If so, ensure that standard
64    C is used to process the API information.  */
65 
66 #ifdef   __cplusplus
67 
68 /* Yes, C++ compiler is present.  Use standard C.  */
69 extern   "C" {
70 
71 #endif
72 
73 
74 /* Define USB slave simulator major equivalences.  */
75 
76 #define UX_DCD_SIM_SLAVE_SLAVE_CONTROLLER                       98
77 #define UX_DCD_SIM_SLAVE_MAX_ED                                 16
78 
79 
80 /* Define USB slave simulator error code register bits.  */
81 
82 #define UX_DCD_SIM_SLAVE_ERROR_TRANSMISSION_OK                  0x00000001u
83 #define UX_DCD_SIM_SLAVE_ERROR_CODE_MASK                        0x0000000eu
84 #define UX_DCD_SIM_SLAVE_ERROR_CODE_SHIFT                       0x00000001u
85 #define UX_DCD_SIM_SLAVE_ERROR_CODE_PID_ERROR                   0x00000001u
86 #define UX_DCD_SIM_SLAVE_ERROR_CODE_PID_UNKNOWN                 0x00000002u
87 #define UX_DCD_SIM_SLAVE_ERROR_CODE_UNEXPECTED_PACKET           0x00000003u
88 #define UX_DCD_SIM_SLAVE_ERROR_CODE_TOKEN_CRC                   0x00000004u
89 #define UX_DCD_SIM_SLAVE_ERROR_CODE_DATA_CRC                    0x00000005u
90 #define UX_DCD_SIM_SLAVE_ERROR_CODE_TIME_OUT                    0x00000006u
91 #define UX_DCD_SIM_SLAVE_ERROR_CODE_BABBLE                      0x00000007u
92 #define UX_DCD_SIM_SLAVE_ERROR_CODE_UNEXPECTED_EOP              0x00000008u
93 #define UX_DCD_SIM_SLAVE_ERROR_CODE_NAK                         0x00000009u
94 #define UX_DCD_SIM_SLAVE_ERROR_CODE_STALLED                     0x0000000au
95 #define UX_DCD_SIM_SLAVE_ERROR_CODE_OVERFLOW                    0x0000000bu
96 #define UX_DCD_SIM_SLAVE_ERROR_CODE_EMPTY_PACKET                0x0000000cu
97 #define UX_DCD_SIM_SLAVE_ERROR_CODE_BIT_STUFFING                0x0000000du
98 #define UX_DCD_SIM_SLAVE_ERROR_CODE_SYNC_ERROR                  0x0000000eu
99 #define UX_DCD_SIM_SLAVE_ERROR_CODE_DATA_TOGGLE                 0x0000000fu
100 
101 
102 /* Define USB slave simulator physical endpoint status definition.  */
103 
104 #define UX_DCD_SIM_SLAVE_ED_STATUS_UNUSED                       0u
105 #define UX_DCD_SIM_SLAVE_ED_STATUS_USED                         1u
106 #define UX_DCD_SIM_SLAVE_ED_STATUS_TRANSFER                     2u
107 #define UX_DCD_SIM_SLAVE_ED_STATUS_STALLED                      4u
108 #define UX_DCD_SIM_SLAVE_ED_STATUS_DONE                         8u
109 
110 
111 /* Define USB slave simulator physical endpoint structure.  */
112 
113 typedef struct UX_DCD_SIM_SLAVE_ED_STRUCT
114 {
115 
116     ULONG           ux_sim_slave_ed_status;
117     ULONG           ux_sim_slave_ed_index;
118     ULONG           ux_sim_slave_ed_payload_length;
119     ULONG           ux_sim_slave_ed_ping_pong;
120     ULONG           ux_sim_slave_ed_status_register;
121     ULONG           ux_sim_slave_ed_configuration_value;
122     struct UX_SLAVE_ENDPOINT_STRUCT
123                     *ux_sim_slave_ed_endpoint;
124 } UX_DCD_SIM_SLAVE_ED;
125 
126 
127 /* Define USB slave simulator DCD structure definition.  */
128 
129 typedef struct UX_DCD_SIM_SLAVE_STRUCT
130 {
131 
132     struct UX_SLAVE_DCD_STRUCT
133                     *ux_dcd_sim_slave_dcd_owner;
134     struct UX_DCD_SIM_SLAVE_ED_STRUCT
135                     ux_dcd_sim_slave_ed[UX_DCD_SIM_SLAVE_MAX_ED];
136 #ifdef UX_DEVICE_BIDIRECTIONAL_ENDPOINT_SUPPORT
137     struct UX_DCD_SIM_SLAVE_ED_STRUCT
138                     ux_dcd_sim_slave_ed_in[UX_DCD_SIM_SLAVE_MAX_ED];
139 #endif
140     UINT            (*ux_dcd_sim_slave_dcd_control_request_process_hub)(UX_SLAVE_TRANSFER *transfer_request);
141     VOID            *ux_dcd_sim_slave_hcd;
142 } UX_DCD_SIM_SLAVE;
143 
144 
145 /* Define slave simulator function prototypes.  */
146 
147 UINT    _ux_dcd_sim_slave_address_set(UX_DCD_SIM_SLAVE *dcd_sim_slave, ULONG address);
148 UINT    _ux_dcd_sim_slave_endpoint_create(UX_DCD_SIM_SLAVE *dcd_sim_slave, UX_SLAVE_ENDPOINT *endpoint);
149 UINT    _ux_dcd_sim_slave_endpoint_destroy(UX_DCD_SIM_SLAVE *dcd_sim_slave, UX_SLAVE_ENDPOINT *endpoint);
150 UINT    _ux_dcd_sim_slave_endpoint_reset(UX_DCD_SIM_SLAVE *dcd_sim_slave, UX_SLAVE_ENDPOINT *endpoint);
151 UINT    _ux_dcd_sim_slave_endpoint_stall(UX_DCD_SIM_SLAVE *dcd_sim_slave, UX_SLAVE_ENDPOINT *endpoint);
152 UINT    _ux_dcd_sim_slave_endpoint_status(UX_DCD_SIM_SLAVE *dcd_sim_slave, ULONG endpoint_index);
153 UINT    _ux_dcd_sim_slave_frame_number_get(UX_DCD_SIM_SLAVE *dcd_sim_slave, ULONG *frame_number);
154 UINT    _ux_dcd_sim_slave_function(UX_SLAVE_DCD *dcd, UINT function, VOID *parameter);
155 UINT    _ux_dcd_sim_slave_initialize(VOID);
156 UINT    _ux_dcd_sim_slave_initialize_complete(VOID);
157 UINT    _ux_dcd_sim_slave_state_change(UX_DCD_SIM_SLAVE *dcd_sim_slave, ULONG state);
158 UINT    _ux_dcd_sim_slave_transfer_request(UX_DCD_SIM_SLAVE *dcd_sim_slave, UX_SLAVE_TRANSFER *transfer_request);
159 UINT    _ux_dcd_sim_slave_transfer_run(UX_DCD_SIM_SLAVE *dcd_sim_slave, UX_SLAVE_TRANSFER *transfer_request);
160 UINT    _ux_dcd_sim_slave_transfer_abort(UX_DCD_SIM_SLAVE *dcd_sim_slave, UX_SLAVE_TRANSFER *transfer_request);
161 
162 /* Define Device Simulator Class API prototypes.  */
163 
164 #define ux_dcd_sim_slave_initialize                 _ux_dcd_sim_slave_initialize
165 
166 /* Determine if a C++ compiler is being used.  If so, complete the standard
167    C conditional started above.  */
168 #ifdef __cplusplus
169 }
170 #endif
171 
172 #endif
173 
174