Skip to content

Commit

Permalink
Update on 30 Jun 2023. Expand to see details.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
xiaocq2001 committed Jun 30, 2023
1 parent ef2fa77 commit 7c928b4
Show file tree
Hide file tree
Showing 82 changed files with 2,052 additions and 308 deletions.
11 changes: 11 additions & 0 deletions common/core/inc/ux_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@
/* added a new error code, */
/* resulting in version 6.2.1 */
/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), */
/* added a new mode to manage */
/* endpoint buffer in classes, */
/* optimized USB descriptors, */
/* added error checks support, */
/* resulting in version 6.x */
Expand Down Expand Up @@ -208,6 +210,15 @@ extern "C" {
#define UX_HOST_STACK_ENABLE_ERROR_CHECKING
#endif

/* Defined, this value represents the endpoint buffer owner.
0 - The default, endpoint buffer is managed by core stack. Each endpoint takes UX_SLAVE_REQUEST_DATA_MAX_LENGTH bytes.
1 - Endpoint buffer managed by classes. In this case not all endpoints consume UX_SLAVE_REQUEST_DATA_MAX_LENGTH bytes.
*/
#ifndef UX_DEVICE_ENDPOINT_BUFFER_OWNER
#define UX_DEVICE_ENDPOINT_BUFFER_OWNER 0
#endif
#define UX_DEVICE_ENDPOINT_BUFFER_OWNER_CORE 0
#define UX_DEVICE_ENDPOINT_BUFFER_OWNER_CLASS 1

/* Define the maximum length for class names (exclude string null-terminator). */
#define UX_MAX_CLASS_NAME_LENGTH 63
Expand Down
25 changes: 24 additions & 1 deletion common/core/inc/ux_device_class_dpump.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/* COMPONENT DEFINITION RELEASE */
/* */
/* ux_device_class_dpump.h PORTABLE C */
/* 6.1.10 */
/* 6.x */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
Expand All @@ -50,6 +50,10 @@
/* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
/* added standalone support, */
/* resulting in version 6.1.10 */
/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), */
/* added a new mode to manage */
/* endpoint buffer in classes, */
/* resulting in version 6.x */
/* */
/**************************************************************************/

Expand All @@ -67,6 +71,13 @@ extern "C" {
#endif


/* Bulk out endpoint / read buffer size, must be larger than max packet size in framework, and aligned in 4-bytes. */
#define UX_DEVICE_CLASS_DPUMP_READ_BUFFER_SIZE UX_SLAVE_REQUEST_DATA_MAX_LENGTH

/* Bulk in endpoint / write buffer size, must be larger than max packet size in framework, and aligned in 4-bytes. */
#define UX_DEVICE_CLASS_DPUMP_WRITE_BUFFER_SIZE UX_SLAVE_REQUEST_DATA_MAX_LENGTH


/* Define Storage Class USB Class constants. */

#define UX_SLAVE_CLASS_DPUMP_CLASS 0x99
Expand Down Expand Up @@ -94,6 +105,9 @@ typedef struct UX_SLAVE_CLASS_DPUMP_STRUCT
UX_SLAVE_CLASS_DPUMP_PARAMETER ux_slave_class_dpump_parameter;
UX_SLAVE_ENDPOINT *ux_slave_class_dpump_bulkin_endpoint;
UX_SLAVE_ENDPOINT *ux_slave_class_dpump_bulkout_endpoint;
#if UX_DEVICE_ENDPOINT_BUFFER_OWNER == 1
UCHAR *ux_device_class_dpump_endpoint_buffer;
#endif
ULONG ux_slave_class_dpump_alternate_setting;
#if defined(UX_DEVICE_STANDALONE)
UCHAR *ux_device_class_dpump_write_buffer;
Expand All @@ -111,6 +125,15 @@ typedef struct UX_SLAVE_CLASS_DPUMP_STRUCT
#endif
} UX_SLAVE_CLASS_DPUMP;

/* Defined for endpoint buffer settings (when DPUMP owns buffer). */
#define UX_DEVICE_CLASS_DPUMP_ENDPOINT_BUFFER_SIZE_CALC_OVERFLOW \
(UX_OVERFLOW_CHECK_ADD_ULONG(UX_DEVICE_CLASS_DPUMP_READ_BUFFER_SIZE, \
UX_DEVICE_CLASS_DPUMP_WRITE_BUFFER_SIZE))
#define UX_DEVICE_CLASS_DPUMP_ENDPOINT_BUFFER_SIZE (UX_DEVICE_CLASS_DPUMP_READ_BUFFER_SIZE + UX_DEVICE_CLASS_DPUMP_WRITE_BUFFER_SIZE)
#define UX_DEVICE_CLASS_DPUMP_READ_BUFFER(dpump) ((dpump)->ux_device_class_dpump_endpoint_buffer)
#define UX_DEVICE_CLASS_DPUMP_WRITE_BUFFER(dpump) (UX_DEVICE_CLASS_DPUMP_READ_BUFFER(dpump) + UX_DEVICE_CLASS_DPUMP_READ_BUFFER_SIZE)


/* Define Device Data Pump Class prototypes. */

UINT _ux_device_class_dpump_initialize(UX_SLAVE_CLASS_COMMAND *command);
Expand Down
38 changes: 37 additions & 1 deletion common/core/inc/ux_user_sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@
/* added option to enable */
/* basic USBX error checking, */
/* resulting in version 6.2.1 */
/* xx-xx-xxxx Xiuwen Cai Modified comment(s), */
/* xx-xx-xxxx Xiuwen Cai, CQ Xiao Modified comment(s), */
/* added zero copy support */
/* in many device classes, */
/* added a new mode to manage */
/* endpoint buffer in classes, */
/* added option for get string */
/* requests with zero wIndex, */
/* resulting in version 6.x */
Expand Down Expand Up @@ -220,6 +224,33 @@
/* #define UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH 256
*/

/* Defined, this value represents the endpoint buffer owner.
0 - The default, endpoint buffer is managed by core stack. Each endpoint takes UX_SLAVE_REQUEST_DATA_MAX_LENGTH bytes.
1 - Endpoint buffer managed by classes. In this case not all endpoints consume UX_SLAVE_REQUEST_DATA_MAX_LENGTH bytes.
*/

#define UX_DEVICE_ENDPOINT_BUFFER_OWNER 0

/* Defined, it enables device CDC ACM zero copy for bulk in/out endpoints (write/read).
Enabled, the endpoint buffer is not allocated in class, application must
provide the buffer for read/write, and the buffer must meet device controller driver (DCD)
buffer requirements (e.g., aligned and cache safe).
It only works if UX_DEVICE_ENDPOINT_BUFFER_OWNER is 1 (endpoint buffer managed by class).
*/
/* #define UX_DEVICE_CLASS_CDC_ACM_ZERO_COPY */

/* Defined, it enables zero copy and flexible queue support (works if HID owns endpoint buffer).
Enabled, the internal queue buffer is directly used for transfer, the APIs are kept to keep
backword compatibility, to AVOID KEEPING BUFFERS IN APPLICATION.
Flexible queue introduces initialization parameter _event_max_number and _event_max_length,
so each HID function could have different queue settings.
_event_max_number could be 2 ~ UX_DEVICE_CLASS_HID_MAX_EVENTS_QUEUE.
Max of _event_max_length could be UX_DEVICE_CLASS_HID_EVENT_BUFFER_LENGTH.
If the initialization parameters are invalid (are 0s or exceed upper mentioned definition),
UX_DEVICE_CLASS_HID_MAX_EVENTS_QUEUE and UX_DEVICE_CLASS_HID_EVENT_BUFFER_LENGTH are used to
calculate and allocate the queue.
*/
/* #define UX_DEVICE_CLASS_HID_ZERO_COPY */

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

/* #define UX_DEVICE_CLASS_AUDIO_FEEDBACK_SUPPORT */

/* Works if UX_DEVICE_ENDPOINT_BUFFER_OWNER is 1.
Defined, it represents feedback endpoint buffer size.
It should be larger than feedback endpoint max packet size in framework. */
/* #define UX_DEVICE_CLASS_AUDIO_FEEDBACK_ENDPOINT_BUFFER_SIZE 8 */

/* Defined, class _write is pending ZLP automatically (complete transfer) after buffer is sent. */

/* #define UX_DEVICE_CLASS_CDC_ACM_WRITE_AUTO_ZLP */
Expand Down
25 changes: 21 additions & 4 deletions common/core/src/ux_device_class_dpump_activate.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
/* FUNCTION RELEASE */
/* */
/* _ux_device_class_dpump_activate PORTABLE C */
/* 6.1.12 */
/* 6.x */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
Expand Down Expand Up @@ -73,6 +73,10 @@
/* fixed parameter/variable */
/* names conflict C++ keyword, */
/* resulting in version 6.1.12 */
/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), */
/* added a new mode to manage */
/* endpoint buffer in classes, */
/* resulting in version 6.x */
/* */
/**************************************************************************/
UINT _ux_device_class_dpump_activate(UX_SLAVE_CLASS_COMMAND *command)
Expand Down Expand Up @@ -111,18 +115,31 @@ UX_SLAVE_ENDPOINT *endpoint;

/* Look at type. */
if ((endpoint -> ux_slave_endpoint_descriptor.bmAttributes & UX_MASK_ENDPOINT_TYPE) == UX_BULK_ENDPOINT)

{

/* We have found the bulk in endpoint, save it. */
dpump -> ux_slave_class_dpump_bulkin_endpoint = endpoint;

#if UX_DEVICE_ENDPOINT_BUFFER_OWNER == 1
endpoint -> ux_slave_endpoint_transfer_request.
ux_slave_transfer_request_data_pointer =
UX_DEVICE_CLASS_DPUMP_WRITE_BUFFER(dpump);
#endif
}
}
else
{
/* Look at type for out endpoint. */
if ((endpoint -> ux_slave_endpoint_descriptor.bmAttributes & UX_MASK_ENDPOINT_TYPE) == UX_BULK_ENDPOINT)

{

/* We have found the bulk out endpoint, save it. */
dpump -> ux_slave_class_dpump_bulkout_endpoint = endpoint;
#if UX_DEVICE_ENDPOINT_BUFFER_OWNER == 1
endpoint -> ux_slave_endpoint_transfer_request.
ux_slave_transfer_request_data_pointer =
UX_DEVICE_CLASS_DPUMP_READ_BUFFER(dpump);
#endif
}
}

/* Next endpoint. */
Expand Down
17 changes: 15 additions & 2 deletions common/core/src/ux_device_class_dpump_change.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
/* FUNCTION RELEASE */
/* */
/* _ux_device_class_dpump_change PORTABLE C */
/* 6.1.12 */
/* 6.x */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
Expand Down Expand Up @@ -76,6 +76,10 @@
/* fixed parameter/variable */
/* names conflict C++ keyword, */
/* resulting in version 6.1.12 */
/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), */
/* added a new mode to manage */
/* endpoint buffer in classes, */
/* resulting in version 6.x */
/* */
/**************************************************************************/
UINT _ux_device_class_dpump_change(UX_SLAVE_CLASS_COMMAND *command)
Expand Down Expand Up @@ -120,7 +124,11 @@ UX_SLAVE_ENDPOINT *endpoint;

/* We have found the bulk in endpoint, save it. */
dpump -> ux_slave_class_dpump_bulkin_endpoint = endpoint;

#if UX_DEVICE_ENDPOINT_BUFFER_OWNER == 1
endpoint -> ux_slave_endpoint_transfer_request.
ux_slave_transfer_request_data_pointer =
UX_DEVICE_CLASS_DPUMP_WRITE_BUFFER(dpump);
#endif
}
else
{
Expand All @@ -129,6 +137,11 @@ UX_SLAVE_ENDPOINT *endpoint;

/* We have found the bulk out endpoint, save it. */
dpump -> ux_slave_class_dpump_bulkout_endpoint = endpoint;
#if UX_DEVICE_ENDPOINT_BUFFER_OWNER == 1
endpoint -> ux_slave_endpoint_transfer_request.
ux_slave_transfer_request_data_pointer =
UX_DEVICE_CLASS_DPUMP_READ_BUFFER(dpump);
#endif
}

/* Next endpoint. */
Expand Down
20 changes: 18 additions & 2 deletions common/core/src/ux_device_class_dpump_initialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
/* FUNCTION RELEASE */
/* */
/* _ux_device_class_dpump_initialize PORTABLE C */
/* 6.1.12 */
/* 6.x */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
Expand Down Expand Up @@ -70,6 +70,10 @@
/* fixed parameter/variable */
/* names conflict C++ keyword, */
/* resulting in version 6.1.12 */
/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), */
/* added a new mode to manage */
/* endpoint buffer in classes, */
/* resulting in version 6.x */
/* */
/**************************************************************************/
UINT _ux_device_class_dpump_initialize(UX_SLAVE_CLASS_COMMAND *command)
Expand All @@ -91,7 +95,19 @@ UX_SLAVE_CLASS_DPUMP_PARAMETER *dpump_parameter;

/* Save the address of the DPUMP instance inside the DPUMP container. */
class_ptr -> ux_slave_class_instance = (VOID *) dpump;


#if UX_DEVICE_ENDPOINT_BUFFER_OWNER == 1
UX_ASSERT(!UX_DEVICE_CLASS_DPUMP_ENDPOINT_BUFFER_SIZE_CALC_OVERFLOW);
dpump -> ux_device_class_dpump_endpoint_buffer = _ux_utility_memory_allocate(
UX_NO_ALIGN, UX_CACHE_SAFE_MEMORY,
UX_DEVICE_CLASS_DPUMP_ENDPOINT_BUFFER_SIZE);
if (dpump -> ux_device_class_dpump_endpoint_buffer == UX_NULL)
{
_ux_utility_memory_free(dpump);
return(UX_MEMORY_INSUFFICIENT);
}
#endif

/* Get the pointer to the application parameters for the cdc class. */
dpump_parameter = command -> ux_slave_class_command_parameter;

Expand Down
10 changes: 7 additions & 3 deletions common/core/src/ux_device_class_dpump_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
/* FUNCTION RELEASE */
/* */
/* _ux_device_class_dpump_read PORTABLE C */
/* 6.1 */
/* 6.x */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
Expand Down Expand Up @@ -70,6 +70,10 @@
/* verified memset and memcpy */
/* cases, */
/* resulting in version 6.1 */
/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), */
/* added a new mode to manage */
/* endpoint buffer in classes, */
/* resulting in version 6.x */
/* */
/**************************************************************************/
UINT _ux_device_class_dpump_read(UX_SLAVE_CLASS_DPUMP *dpump, UCHAR *buffer,
Expand Down Expand Up @@ -128,10 +132,10 @@ ULONG local_requested_length;
{

/* Check if we have enough in the local buffer. */
if (requested_length > UX_SLAVE_REQUEST_DATA_MAX_LENGTH)
if (requested_length > UX_DEVICE_CLASS_DPUMP_READ_BUFFER_SIZE)

/* We have too much to transfer. */
local_requested_length = UX_SLAVE_REQUEST_DATA_MAX_LENGTH;
local_requested_length = UX_DEVICE_CLASS_DPUMP_READ_BUFFER_SIZE;

else

Expand Down
10 changes: 7 additions & 3 deletions common/core/src/ux_device_class_dpump_read_run.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
/* FUNCTION RELEASE */
/* */
/* _ux_device_class_dpump_read_run PORTABLE C */
/* 6.1.10 */
/* 6.x */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
Expand Down Expand Up @@ -78,6 +78,10 @@
/* DATE NAME DESCRIPTION */
/* */
/* 01-31-2022 Chaoqiong Xiao Initial Version 6.1.10 */
/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), */
/* added a new mode to manage */
/* endpoint buffer in classes, */
/* resulting in version 6.x */
/* */
/**************************************************************************/
UINT _ux_device_class_dpump_read_run(UX_SLAVE_CLASS_DPUMP *dpump, UCHAR *buffer,
Expand Down Expand Up @@ -158,10 +162,10 @@ UINT read_state;
}

/* Check if we have enough in the local buffer. */
if (requested_length > UX_SLAVE_REQUEST_DATA_MAX_LENGTH)
if (requested_length > UX_DEVICE_CLASS_DPUMP_READ_BUFFER_SIZE)

/* We have too much to transfer. */
dpump -> ux_device_class_dpump_read_transfer_length = UX_SLAVE_REQUEST_DATA_MAX_LENGTH;
dpump -> ux_device_class_dpump_read_transfer_length = UX_DEVICE_CLASS_DPUMP_READ_BUFFER_SIZE;

else

Expand Down
Loading

0 comments on commit 7c928b4

Please sign in to comment.