Skip to content

Commit 7c928b4

Browse files
committed
Update on 30 Jun 2023. Expand to see details.
92c60270 Added device HID flexible event queue and zero copy support. a15f80ab Added device CDC ACM zero copy support 9fcd26f7 Improve device request handling with print GET_DEVICE_ID support. bea6252c Add new device side endpoint buffer management mode.
1 parent ef2fa77 commit 7c928b4

File tree

82 files changed

+2052
-308
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+2052
-308
lines changed

common/core/inc/ux_api.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@
134134
/* added a new error code, */
135135
/* resulting in version 6.2.1 */
136136
/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), */
137+
/* added a new mode to manage */
138+
/* endpoint buffer in classes, */
137139
/* optimized USB descriptors, */
138140
/* added error checks support, */
139141
/* resulting in version 6.x */
@@ -208,6 +210,15 @@ extern "C" {
208210
#define UX_HOST_STACK_ENABLE_ERROR_CHECKING
209211
#endif
210212

213+
/* Defined, this value represents the endpoint buffer owner.
214+
0 - The default, endpoint buffer is managed by core stack. Each endpoint takes UX_SLAVE_REQUEST_DATA_MAX_LENGTH bytes.
215+
1 - Endpoint buffer managed by classes. In this case not all endpoints consume UX_SLAVE_REQUEST_DATA_MAX_LENGTH bytes.
216+
*/
217+
#ifndef UX_DEVICE_ENDPOINT_BUFFER_OWNER
218+
#define UX_DEVICE_ENDPOINT_BUFFER_OWNER 0
219+
#endif
220+
#define UX_DEVICE_ENDPOINT_BUFFER_OWNER_CORE 0
221+
#define UX_DEVICE_ENDPOINT_BUFFER_OWNER_CLASS 1
211222

212223
/* Define the maximum length for class names (exclude string null-terminator). */
213224
#define UX_MAX_CLASS_NAME_LENGTH 63

common/core/inc/ux_device_class_dpump.h

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
/* COMPONENT DEFINITION RELEASE */
2727
/* */
2828
/* ux_device_class_dpump.h PORTABLE C */
29-
/* 6.1.10 */
29+
/* 6.x */
3030
/* AUTHOR */
3131
/* */
3232
/* Chaoqiong Xiao, Microsoft Corporation */
@@ -50,6 +50,10 @@
5050
/* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
5151
/* added standalone support, */
5252
/* resulting in version 6.1.10 */
53+
/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), */
54+
/* added a new mode to manage */
55+
/* endpoint buffer in classes, */
56+
/* resulting in version 6.x */
5357
/* */
5458
/**************************************************************************/
5559

@@ -67,6 +71,13 @@ extern "C" {
6771
#endif
6872

6973

74+
/* Bulk out endpoint / read buffer size, must be larger than max packet size in framework, and aligned in 4-bytes. */
75+
#define UX_DEVICE_CLASS_DPUMP_READ_BUFFER_SIZE UX_SLAVE_REQUEST_DATA_MAX_LENGTH
76+
77+
/* Bulk in endpoint / write buffer size, must be larger than max packet size in framework, and aligned in 4-bytes. */
78+
#define UX_DEVICE_CLASS_DPUMP_WRITE_BUFFER_SIZE UX_SLAVE_REQUEST_DATA_MAX_LENGTH
79+
80+
7081
/* Define Storage Class USB Class constants. */
7182

7283
#define UX_SLAVE_CLASS_DPUMP_CLASS 0x99
@@ -94,6 +105,9 @@ typedef struct UX_SLAVE_CLASS_DPUMP_STRUCT
94105
UX_SLAVE_CLASS_DPUMP_PARAMETER ux_slave_class_dpump_parameter;
95106
UX_SLAVE_ENDPOINT *ux_slave_class_dpump_bulkin_endpoint;
96107
UX_SLAVE_ENDPOINT *ux_slave_class_dpump_bulkout_endpoint;
108+
#if UX_DEVICE_ENDPOINT_BUFFER_OWNER == 1
109+
UCHAR *ux_device_class_dpump_endpoint_buffer;
110+
#endif
97111
ULONG ux_slave_class_dpump_alternate_setting;
98112
#if defined(UX_DEVICE_STANDALONE)
99113
UCHAR *ux_device_class_dpump_write_buffer;
@@ -111,6 +125,15 @@ typedef struct UX_SLAVE_CLASS_DPUMP_STRUCT
111125
#endif
112126
} UX_SLAVE_CLASS_DPUMP;
113127

128+
/* Defined for endpoint buffer settings (when DPUMP owns buffer). */
129+
#define UX_DEVICE_CLASS_DPUMP_ENDPOINT_BUFFER_SIZE_CALC_OVERFLOW \
130+
(UX_OVERFLOW_CHECK_ADD_ULONG(UX_DEVICE_CLASS_DPUMP_READ_BUFFER_SIZE, \
131+
UX_DEVICE_CLASS_DPUMP_WRITE_BUFFER_SIZE))
132+
#define UX_DEVICE_CLASS_DPUMP_ENDPOINT_BUFFER_SIZE (UX_DEVICE_CLASS_DPUMP_READ_BUFFER_SIZE + UX_DEVICE_CLASS_DPUMP_WRITE_BUFFER_SIZE)
133+
#define UX_DEVICE_CLASS_DPUMP_READ_BUFFER(dpump) ((dpump)->ux_device_class_dpump_endpoint_buffer)
134+
#define UX_DEVICE_CLASS_DPUMP_WRITE_BUFFER(dpump) (UX_DEVICE_CLASS_DPUMP_READ_BUFFER(dpump) + UX_DEVICE_CLASS_DPUMP_READ_BUFFER_SIZE)
135+
136+
114137
/* Define Device Data Pump Class prototypes. */
115138

116139
UINT _ux_device_class_dpump_initialize(UX_SLAVE_CLASS_COMMAND *command);

common/core/inc/ux_user_sample.h

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@
9999
/* added option to enable */
100100
/* basic USBX error checking, */
101101
/* resulting in version 6.2.1 */
102-
/* xx-xx-xxxx Xiuwen Cai Modified comment(s), */
102+
/* xx-xx-xxxx Xiuwen Cai, CQ Xiao Modified comment(s), */
103+
/* added zero copy support */
104+
/* in many device classes, */
105+
/* added a new mode to manage */
106+
/* endpoint buffer in classes, */
103107
/* added option for get string */
104108
/* requests with zero wIndex, */
105109
/* resulting in version 6.x */
@@ -220,6 +224,33 @@
220224
/* #define UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH 256
221225
*/
222226

227+
/* Defined, this value represents the endpoint buffer owner.
228+
0 - The default, endpoint buffer is managed by core stack. Each endpoint takes UX_SLAVE_REQUEST_DATA_MAX_LENGTH bytes.
229+
1 - Endpoint buffer managed by classes. In this case not all endpoints consume UX_SLAVE_REQUEST_DATA_MAX_LENGTH bytes.
230+
*/
231+
232+
#define UX_DEVICE_ENDPOINT_BUFFER_OWNER 0
233+
234+
/* Defined, it enables device CDC ACM zero copy for bulk in/out endpoints (write/read).
235+
Enabled, the endpoint buffer is not allocated in class, application must
236+
provide the buffer for read/write, and the buffer must meet device controller driver (DCD)
237+
buffer requirements (e.g., aligned and cache safe).
238+
It only works if UX_DEVICE_ENDPOINT_BUFFER_OWNER is 1 (endpoint buffer managed by class).
239+
*/
240+
/* #define UX_DEVICE_CLASS_CDC_ACM_ZERO_COPY */
241+
242+
/* Defined, it enables zero copy and flexible queue support (works if HID owns endpoint buffer).
243+
Enabled, the internal queue buffer is directly used for transfer, the APIs are kept to keep
244+
backword compatibility, to AVOID KEEPING BUFFERS IN APPLICATION.
245+
Flexible queue introduces initialization parameter _event_max_number and _event_max_length,
246+
so each HID function could have different queue settings.
247+
_event_max_number could be 2 ~ UX_DEVICE_CLASS_HID_MAX_EVENTS_QUEUE.
248+
Max of _event_max_length could be UX_DEVICE_CLASS_HID_EVENT_BUFFER_LENGTH.
249+
If the initialization parameters are invalid (are 0s or exceed upper mentioned definition),
250+
UX_DEVICE_CLASS_HID_MAX_EVENTS_QUEUE and UX_DEVICE_CLASS_HID_EVENT_BUFFER_LENGTH are used to
251+
calculate and allocate the queue.
252+
*/
253+
/* #define UX_DEVICE_CLASS_HID_ZERO_COPY */
223254

224255
/* Defined, this value represents the maximum number of bytes that can be received or transmitted
225256
on any endpoint. This value cannot be less than the maximum packet size of any endpoint. The default
@@ -414,6 +445,11 @@
414445

415446
/* #define UX_DEVICE_CLASS_AUDIO_FEEDBACK_SUPPORT */
416447

448+
/* Works if UX_DEVICE_ENDPOINT_BUFFER_OWNER is 1.
449+
Defined, it represents feedback endpoint buffer size.
450+
It should be larger than feedback endpoint max packet size in framework. */
451+
/* #define UX_DEVICE_CLASS_AUDIO_FEEDBACK_ENDPOINT_BUFFER_SIZE 8 */
452+
417453
/* Defined, class _write is pending ZLP automatically (complete transfer) after buffer is sent. */
418454

419455
/* #define UX_DEVICE_CLASS_CDC_ACM_WRITE_AUTO_ZLP */

common/core/src/ux_device_class_dpump_activate.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
/* FUNCTION RELEASE */
3535
/* */
3636
/* _ux_device_class_dpump_activate PORTABLE C */
37-
/* 6.1.12 */
37+
/* 6.x */
3838
/* AUTHOR */
3939
/* */
4040
/* Chaoqiong Xiao, Microsoft Corporation */
@@ -73,6 +73,10 @@
7373
/* fixed parameter/variable */
7474
/* names conflict C++ keyword, */
7575
/* resulting in version 6.1.12 */
76+
/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), */
77+
/* added a new mode to manage */
78+
/* endpoint buffer in classes, */
79+
/* resulting in version 6.x */
7680
/* */
7781
/**************************************************************************/
7882
UINT _ux_device_class_dpump_activate(UX_SLAVE_CLASS_COMMAND *command)
@@ -111,18 +115,31 @@ UX_SLAVE_ENDPOINT *endpoint;
111115

112116
/* Look at type. */
113117
if ((endpoint -> ux_slave_endpoint_descriptor.bmAttributes & UX_MASK_ENDPOINT_TYPE) == UX_BULK_ENDPOINT)
114-
118+
{
119+
115120
/* We have found the bulk in endpoint, save it. */
116121
dpump -> ux_slave_class_dpump_bulkin_endpoint = endpoint;
117-
122+
#if UX_DEVICE_ENDPOINT_BUFFER_OWNER == 1
123+
endpoint -> ux_slave_endpoint_transfer_request.
124+
ux_slave_transfer_request_data_pointer =
125+
UX_DEVICE_CLASS_DPUMP_WRITE_BUFFER(dpump);
126+
#endif
127+
}
118128
}
119129
else
120130
{
121131
/* Look at type for out endpoint. */
122132
if ((endpoint -> ux_slave_endpoint_descriptor.bmAttributes & UX_MASK_ENDPOINT_TYPE) == UX_BULK_ENDPOINT)
123-
133+
{
134+
124135
/* We have found the bulk out endpoint, save it. */
125136
dpump -> ux_slave_class_dpump_bulkout_endpoint = endpoint;
137+
#if UX_DEVICE_ENDPOINT_BUFFER_OWNER == 1
138+
endpoint -> ux_slave_endpoint_transfer_request.
139+
ux_slave_transfer_request_data_pointer =
140+
UX_DEVICE_CLASS_DPUMP_READ_BUFFER(dpump);
141+
#endif
142+
}
126143
}
127144

128145
/* Next endpoint. */

common/core/src/ux_device_class_dpump_change.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
/* FUNCTION RELEASE */
3434
/* */
3535
/* _ux_device_class_dpump_change PORTABLE C */
36-
/* 6.1.12 */
36+
/* 6.x */
3737
/* AUTHOR */
3838
/* */
3939
/* Chaoqiong Xiao, Microsoft Corporation */
@@ -76,6 +76,10 @@
7676
/* fixed parameter/variable */
7777
/* names conflict C++ keyword, */
7878
/* resulting in version 6.1.12 */
79+
/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), */
80+
/* added a new mode to manage */
81+
/* endpoint buffer in classes, */
82+
/* resulting in version 6.x */
7983
/* */
8084
/**************************************************************************/
8185
UINT _ux_device_class_dpump_change(UX_SLAVE_CLASS_COMMAND *command)
@@ -120,7 +124,11 @@ UX_SLAVE_ENDPOINT *endpoint;
120124

121125
/* We have found the bulk in endpoint, save it. */
122126
dpump -> ux_slave_class_dpump_bulkin_endpoint = endpoint;
123-
127+
#if UX_DEVICE_ENDPOINT_BUFFER_OWNER == 1
128+
endpoint -> ux_slave_endpoint_transfer_request.
129+
ux_slave_transfer_request_data_pointer =
130+
UX_DEVICE_CLASS_DPUMP_WRITE_BUFFER(dpump);
131+
#endif
124132
}
125133
else
126134
{
@@ -129,6 +137,11 @@ UX_SLAVE_ENDPOINT *endpoint;
129137

130138
/* We have found the bulk out endpoint, save it. */
131139
dpump -> ux_slave_class_dpump_bulkout_endpoint = endpoint;
140+
#if UX_DEVICE_ENDPOINT_BUFFER_OWNER == 1
141+
endpoint -> ux_slave_endpoint_transfer_request.
142+
ux_slave_transfer_request_data_pointer =
143+
UX_DEVICE_CLASS_DPUMP_READ_BUFFER(dpump);
144+
#endif
132145
}
133146

134147
/* Next endpoint. */

common/core/src/ux_device_class_dpump_initialize.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
/* FUNCTION RELEASE */
3535
/* */
3636
/* _ux_device_class_dpump_initialize PORTABLE C */
37-
/* 6.1.12 */
37+
/* 6.x */
3838
/* AUTHOR */
3939
/* */
4040
/* Chaoqiong Xiao, Microsoft Corporation */
@@ -70,6 +70,10 @@
7070
/* fixed parameter/variable */
7171
/* names conflict C++ keyword, */
7272
/* resulting in version 6.1.12 */
73+
/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), */
74+
/* added a new mode to manage */
75+
/* endpoint buffer in classes, */
76+
/* resulting in version 6.x */
7377
/* */
7478
/**************************************************************************/
7579
UINT _ux_device_class_dpump_initialize(UX_SLAVE_CLASS_COMMAND *command)
@@ -91,7 +95,19 @@ UX_SLAVE_CLASS_DPUMP_PARAMETER *dpump_parameter;
9195

9296
/* Save the address of the DPUMP instance inside the DPUMP container. */
9397
class_ptr -> ux_slave_class_instance = (VOID *) dpump;
94-
98+
99+
#if UX_DEVICE_ENDPOINT_BUFFER_OWNER == 1
100+
UX_ASSERT(!UX_DEVICE_CLASS_DPUMP_ENDPOINT_BUFFER_SIZE_CALC_OVERFLOW);
101+
dpump -> ux_device_class_dpump_endpoint_buffer = _ux_utility_memory_allocate(
102+
UX_NO_ALIGN, UX_CACHE_SAFE_MEMORY,
103+
UX_DEVICE_CLASS_DPUMP_ENDPOINT_BUFFER_SIZE);
104+
if (dpump -> ux_device_class_dpump_endpoint_buffer == UX_NULL)
105+
{
106+
_ux_utility_memory_free(dpump);
107+
return(UX_MEMORY_INSUFFICIENT);
108+
}
109+
#endif
110+
95111
/* Get the pointer to the application parameters for the cdc class. */
96112
dpump_parameter = command -> ux_slave_class_command_parameter;
97113

common/core/src/ux_device_class_dpump_read.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
/* FUNCTION RELEASE */
3535
/* */
3636
/* _ux_device_class_dpump_read PORTABLE C */
37-
/* 6.1 */
37+
/* 6.x */
3838
/* AUTHOR */
3939
/* */
4040
/* Chaoqiong Xiao, Microsoft Corporation */
@@ -70,6 +70,10 @@
7070
/* verified memset and memcpy */
7171
/* cases, */
7272
/* resulting in version 6.1 */
73+
/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), */
74+
/* added a new mode to manage */
75+
/* endpoint buffer in classes, */
76+
/* resulting in version 6.x */
7377
/* */
7478
/**************************************************************************/
7579
UINT _ux_device_class_dpump_read(UX_SLAVE_CLASS_DPUMP *dpump, UCHAR *buffer,
@@ -128,10 +132,10 @@ ULONG local_requested_length;
128132
{
129133

130134
/* Check if we have enough in the local buffer. */
131-
if (requested_length > UX_SLAVE_REQUEST_DATA_MAX_LENGTH)
135+
if (requested_length > UX_DEVICE_CLASS_DPUMP_READ_BUFFER_SIZE)
132136

133137
/* We have too much to transfer. */
134-
local_requested_length = UX_SLAVE_REQUEST_DATA_MAX_LENGTH;
138+
local_requested_length = UX_DEVICE_CLASS_DPUMP_READ_BUFFER_SIZE;
135139

136140
else
137141

common/core/src/ux_device_class_dpump_read_run.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
/* FUNCTION RELEASE */
4040
/* */
4141
/* _ux_device_class_dpump_read_run PORTABLE C */
42-
/* 6.1.10 */
42+
/* 6.x */
4343
/* AUTHOR */
4444
/* */
4545
/* Chaoqiong Xiao, Microsoft Corporation */
@@ -78,6 +78,10 @@
7878
/* DATE NAME DESCRIPTION */
7979
/* */
8080
/* 01-31-2022 Chaoqiong Xiao Initial Version 6.1.10 */
81+
/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), */
82+
/* added a new mode to manage */
83+
/* endpoint buffer in classes, */
84+
/* resulting in version 6.x */
8185
/* */
8286
/**************************************************************************/
8387
UINT _ux_device_class_dpump_read_run(UX_SLAVE_CLASS_DPUMP *dpump, UCHAR *buffer,
@@ -158,10 +162,10 @@ UINT read_state;
158162
}
159163

160164
/* Check if we have enough in the local buffer. */
161-
if (requested_length > UX_SLAVE_REQUEST_DATA_MAX_LENGTH)
165+
if (requested_length > UX_DEVICE_CLASS_DPUMP_READ_BUFFER_SIZE)
162166

163167
/* We have too much to transfer. */
164-
dpump -> ux_device_class_dpump_read_transfer_length = UX_SLAVE_REQUEST_DATA_MAX_LENGTH;
168+
dpump -> ux_device_class_dpump_read_transfer_length = UX_DEVICE_CLASS_DPUMP_READ_BUFFER_SIZE;
165169

166170
else
167171

0 commit comments

Comments
 (0)