summaryrefslogtreecommitdiff
path: root/common/core/inc/ux_hcd_sim_host.h
blob: 4a40fe5d8fd0477d2858f3dff8847bde5a1aced1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/***************************************************************************
 * Copyright (c) 2024 Microsoft Corporation
 * Copyright (c) 2026-present Eclipse ThreadX contributors
 *
 * This program and the accompanying materials are made available under the
 * terms of the MIT License which is available at
 * https://opensource.org/licenses/MIT.
 *
 * SPDX-License-Identifier: MIT
 **************************************************************************/


/**************************************************************************/
/**************************************************************************/
/**                                                                       */
/** USBX Component                                                        */
/**                                                                       */
/**   Host Simulator Controller Driver                                    */
/**                                                                       */
/**************************************************************************/
/**************************************************************************/


/**************************************************************************/
/*                                                                        */
/*  COMPONENT DEFINITION                                   RELEASE        */
/*                                                                        */
/*    ux_hcd_sim_host.h                                   PORTABLE C      */
/*                                                           6.1.10       */
/*  AUTHOR                                                                */
/*                                                                        */
/*    Chaoqiong Xiao, Microsoft Corporation                               */
/*                                                                        */
/*  DESCRIPTION                                                           */
/*                                                                        */
/*    This file contains all the header and extern functions used by the  */
/*    USBX host simulator. It is designed to work ONLY with the USBX      */
/*    device (slave) simulator.                                           */
/*                                                                        */
/**************************************************************************/

#ifndef UX_HCD_SIM_HOST_H
#define UX_HCD_SIM_HOST_H

/* Determine if a C++ compiler is being used.  If so, ensure that standard
   C is used to process the API information.  */

#ifdef   __cplusplus

/* Yes, C++ compiler is present.  Use standard C.  */
extern   "C" {

#endif


/* Define simulator host generic definitions.  */

#define UX_HCD_SIM_HOST_CONTROLLER                              99
#define UX_HCD_SIM_HOST_MAX_PAYLOAD                             4096
#define UX_HCD_SIM_HOST_FRAME_DELAY                             4
#define UX_HCD_SIM_HOST_PERIODIC_ENTRY_NB                       32
#define UX_HCD_SIM_HOST_PERIODIC_ENTRY_MASK                     0x1f
#define UX_HCD_SIM_HOST_AVAILABLE_BANDWIDTH                     6000



/* Define simulator host completion code errors.  */

#define UX_HCD_SIM_HOST_NO_ERROR                                0x00
#define UX_HCD_SIM_HOST_ERROR_CRC                               0x01
#define UX_HCD_SIM_HOST_ERROR_BIT_STUFFING                      0x02
#define UX_HCD_SIM_HOST_ERROR_DATA_TOGGLE                       0x03
#define UX_HCD_SIM_HOST_ERROR_STALL                             0x04
#define UX_HCD_SIM_HOST_ERROR_DEVICE_NOT_RESPONDING             0x05
#define UX_HCD_SIM_HOST_ERROR_PID_FAILURE                       0x06
#define UX_HCD_SIM_HOST_ERROR_PID_UNEXPECTED                    0x07
#define UX_HCD_SIM_HOST_ERROR_DATA_OVERRRUN                     0x08
#define UX_HCD_SIM_HOST_ERROR_DATA_UNDERRUN                     0x09
#define UX_HCD_SIM_HOST_ERROR_BUFFER_OVERRRUN                   0x0c
#define UX_HCD_SIM_HOST_ERROR_BUFFER_UNDERRUN                   0x0d
#define UX_HCD_SIM_HOST_NOT_ACCESSED                            0x0e
#define UX_HCD_SIM_HOST_NAK                                     0x0f


/* Define simulator host structure.  */

typedef struct UX_HCD_SIM_HOST_STRUCT
{

    struct UX_HCD_STRUCT
                    *ux_hcd_sim_host_hcd_owner;
    ULONG           ux_hcd_sim_host_hcor;
    UINT            ux_hcd_sim_host_nb_root_hubs;
    ULONG           ux_hcd_sim_host_port_status[1];
    struct UX_HCD_SIM_HOST_ED_STRUCT
                    *ux_hcd_sim_host_ed_list;
    struct UX_HCD_SIM_HOST_TD_STRUCT
                    *ux_hcd_sim_host_td_list;
    struct UX_HCD_SIM_HOST_ISO_TD_STRUCT
                    *ux_hcd_sim_host_iso_td_list;
    struct UX_HCD_SIM_HOST_ED_STRUCT
                    *ux_hcd_sim_host_asynch_head_ed;
    struct UX_HCD_SIM_HOST_ED_STRUCT
                    *ux_hcd_sim_host_asynch_current_ed;
    struct UX_HCD_SIM_HOST_ED_STRUCT
                    *ux_hcd_sim_host_iso_head_ed;
    struct UX_HCD_SIM_HOST_ED_STRUCT
                    *ux_hcd_sim_host_interrupt_ed_list[32];
    UINT            ux_hcd_sim_host_queue_empty;
    UINT            ux_hcd_sim_host_periodic_scheduler_active;
    UINT            ux_hcd_sim_host_interruptible;
    ULONG           ux_hcd_sim_host_interrupt_count;
#if !defined(UX_HOST_STANDALONE)
    UX_TIMER        ux_hcd_sim_host_timer;
#endif
} UX_HCD_SIM_HOST;


/* Define simulator host ED structure.  */

typedef struct UX_HCD_SIM_HOST_ED_STRUCT
{

    struct UX_HCD_SIM_HOST_TD_STRUCT
                    *ux_sim_host_ed_tail_td;
    struct UX_HCD_SIM_HOST_TD_STRUCT
                    *ux_sim_host_ed_head_td;
    struct UX_HCD_SIM_HOST_ED_STRUCT
                    *ux_sim_host_ed_next_ed;
    struct UX_HCD_SIM_HOST_ED_STRUCT
                    *ux_sim_host_ed_previous_ed;
    ULONG           ux_sim_host_ed_status;
    struct UX_ENDPOINT_STRUCT
                    *ux_sim_host_ed_endpoint;
    ULONG           ux_sim_host_ed_toggle;
    ULONG           ux_sim_host_ed_frame;
} UX_HCD_SIM_HOST_ED;


/* Define simulator host ED bitmap.  */

#define UX_HCD_SIM_HOST_ED_STATIC                               0x80000000u
#define UX_HCD_SIM_HOST_ED_SKIP                                 0x40000000u
#define UX_HCD_SIM_HOST_ED_TRANSFER                             0x00100000u


/* Define simulator host TD structure.  */

typedef struct UX_HCD_SIM_HOST_TD_STRUCT
{

    UCHAR *         ux_sim_host_td_buffer;
    ULONG           ux_sim_host_td_length;
    struct UX_HCD_SIM_HOST_TD_STRUCT
                    *ux_sim_host_td_next_td;
    struct UX_TRANSFER_STRUCT
                    *ux_sim_host_td_transfer_request;
    struct UX_HCD_SIM_HOST_TD_STRUCT
                    *ux_sim_host_td_next_td_transfer_request;
    struct UX_HCD_SIM_HOST_ED_STRUCT
                    *ux_sim_host_td_ed;
    ULONG           ux_sim_host_td_actual_length;
    ULONG           ux_sim_host_td_status;
    ULONG           ux_sim_host_td_direction;
    ULONG           ux_sim_host_td_toggle;
} UX_HCD_SIM_HOST_TD;


/* Define simulator host TD bitmap.  */

#define UX_HCD_SIM_HOST_TD_SETUP_PHASE                          0x00010000
#define UX_HCD_SIM_HOST_TD_DATA_PHASE                           0x00020000
#define UX_HCD_SIM_HOST_TD_STATUS_PHASE                         0x00040000
#define UX_HCD_SIM_HOST_TD_OUT                                  0x00000800
#define UX_HCD_SIM_HOST_TD_IN                                   0x00001000
#define UX_HCD_SIM_HOST_TD_ACK_PENDING                          0x00002000
#define UX_HCD_SIM_HOST_TD_TOGGLE_FROM_ED                       0x80000000


/* Define simulator host ISOCHRONOUS TD structure.  */

typedef struct UX_HCD_SIM_HOST_ISO_TD_STRUCT
{

    UCHAR *         ux_sim_host_iso_td_buffer;
    ULONG           ux_sim_host_iso_td_length;
    struct UX_HCD_SIM_HOST_ISO_TD_STRUCT
                    *ux_sim_host_iso_td_next_td;
    struct UX_TRANSFER_STRUCT
                    *ux_sim_host_iso_td_transfer_request;
    struct UX_HCD_SIM_HOST_ISO_TD_STRUCT
                    *ux_sim_host_iso_td_next_td_transfer_request;
    struct UX_HCD_SIM_HOST_ED_STRUCT
                    *ux_sim_host_iso_td_ed;
    ULONG           ux_sim_host_iso_td_actual_length;
    ULONG           ux_sim_host_iso_td_status;
    ULONG           ux_sim_host_iso_td_direction;
} UX_HCD_SIM_HOST_ISO_TD;


/* Define simulator host function prototypes.  */

VOID    _ux_hcd_sim_host_asynch_queue_process(UX_HCD_SIM_HOST *hcd_sim_host);
VOID    _ux_hcd_sim_host_asynch_schedule(UX_HCD_SIM_HOST *hcd_sim_host);
UINT    _ux_hcd_sim_host_asynchronous_endpoint_create(UX_HCD_SIM_HOST *hcd_sim_host, UX_ENDPOINT *endpoint);
UINT    _ux_hcd_sim_host_asynchronous_endpoint_destroy(UX_HCD_SIM_HOST *hcd_sim_host, UX_ENDPOINT *endpoint);
UX_HCD_SIM_HOST_ED
        *_ux_hcd_sim_host_ed_obtain(UX_HCD_SIM_HOST *hcd_sim_host);
VOID    _ux_hcd_sim_host_ed_td_clean(UX_HCD_SIM_HOST_ED *ed);
UINT    _ux_hcd_sim_host_endpoint_reset(UX_HCD_SIM_HOST *hcd_sim_host, UX_ENDPOINT *endpoint);
UINT    _ux_hcd_sim_host_entry(UX_HCD *hcd, UINT function, VOID *parameter);
UINT    _ux_hcd_sim_host_frame_number_get(UX_HCD_SIM_HOST *hcd_sim_host, ULONG *frame_number);
VOID    _ux_hcd_sim_host_frame_number_set(UX_HCD_SIM_HOST *hcd_sim_host, ULONG frame_number);
UINT    _ux_hcd_sim_host_initialize(UX_HCD *hcd);
UINT    _ux_hcd_sim_host_uninitialize(UX_HCD_SIM_HOST *hcd);
UINT    _ux_hcd_sim_host_controller_disable(UX_HCD_SIM_HOST *hcd);
UINT    _ux_hcd_sim_host_interrupt_endpoint_create(UX_HCD_SIM_HOST *hcd_sim_host, UX_ENDPOINT *endpoint);
VOID    _ux_hcd_sim_host_iso_queue_process(UX_HCD_SIM_HOST *hcd_sim_host);
VOID    _ux_hcd_sim_host_iso_schedule(UX_HCD_SIM_HOST *hcd_sim_host);
UINT    _ux_hcd_sim_host_isochronous_endpoint_create(UX_HCD_SIM_HOST *hcd_sim_host, UX_ENDPOINT *endpoint);
UX_HCD_SIM_HOST_ISO_TD
        *_ux_hcd_sim_host_isochronous_td_obtain(UX_HCD_SIM_HOST *hcd_sim_host);
UX_HCD_SIM_HOST_ED
        *_ux_hcd_sim_host_least_traffic_list_get(UX_HCD_SIM_HOST *hcd_sim_host);
UINT    _ux_hcd_sim_host_periodic_endpoint_destroy(UX_HCD_SIM_HOST *hcd_sim_host, UX_ENDPOINT *endpoint);
VOID    _ux_hcd_sim_host_periodic_schedule(UX_HCD_SIM_HOST *hcd_sim_host);
UINT    _ux_hcd_sim_host_periodic_tree_create(UX_HCD_SIM_HOST *hcd_sim_host);
ULONG   _ux_hcd_sim_host_port_status_get(UX_HCD_SIM_HOST *hcd_sim_host, ULONG port_index);
UX_HCD_SIM_HOST_TD
        *_ux_hcd_sim_host_regular_td_obtain(UX_HCD_SIM_HOST *hcd_sim_host);
UINT    _ux_hcd_sim_host_request_bulk_transfer(UX_HCD_SIM_HOST *hcd_sim_host, UX_TRANSFER *transfer_request);
UINT    _ux_hcd_sim_host_request_control_transfer(UX_HCD_SIM_HOST *hcd_sim_host, UX_TRANSFER *transfer_request);
UINT    _ux_hcd_sim_host_request_interrupt_transfer(UX_HCD_SIM_HOST *hcd_sim_host, UX_TRANSFER *transfer_request);
UINT    _ux_hcd_sim_host_request_isochronous_transfer(UX_HCD_SIM_HOST *hcd_sim_host, UX_TRANSFER *transfer_request);
UINT    _ux_hcd_sim_host_request_transfer(UX_HCD_SIM_HOST *hcd_sim_host, UX_TRANSFER *transfer_request);
VOID    _ux_hcd_sim_host_timer_function(ULONG hcd_sim_host_addr);
UINT    _ux_hcd_sim_host_transaction_schedule(UX_HCD_SIM_HOST *hcd_sim_host, UX_HCD_SIM_HOST_ED *ed);
UINT    _ux_hcd_sim_host_transfer_abort(UX_HCD_SIM_HOST *hcd_sim_host, UX_TRANSFER *transfer_request);
UINT    _ux_hcd_sim_host_port_reset(UX_HCD_SIM_HOST *hcd_sim_host, ULONG port_index);

UINT    _ux_hcd_sim_host_transfer_run(UX_HCD_SIM_HOST *hcd_sim_host, UX_TRANSFER *transfer_request);

/* Define Device Simulator Class API prototypes.  */

#define ux_hcd_sim_host_initialize                 _ux_hcd_sim_host_initialize
#define ux_hcd_sim_host_uninitialize               _ux_hcd_sim_host_uninitialize

/* Determine if a C++ compiler is being used.  If so, complete the standard
   C conditional started above.  */
#ifdef __cplusplus
}
#endif

#endif