328 changes: 317 additions & 11 deletions common/core/inc/ux_api.h

Large diffs are not rendered by default.

52 changes: 29 additions & 23 deletions common/core/inc/ux_dcd_sim_slave.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/* COMPONENT DEFINITION RELEASE */
/* */
/* ux_dcd_sim_slave.h PORTABLE C */
/* 6.1.8 */
/* 6.1.10 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
Expand All @@ -52,6 +52,9 @@
/* added extern "C" keyword */
/* for compatibility with C++, */
/* resulting in version 6.1.8 */
/* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
/* added standalone support, */
/* resulting in version 6.1.10 */
/* */
/**************************************************************************/

Expand All @@ -77,32 +80,33 @@ extern "C" {

/* Define USB slave simulator error code register bits. */

#define UX_DCD_SIM_SLAVE_ERROR_TRANSMISSION_OK 0x00000001
#define UX_DCD_SIM_SLAVE_ERROR_CODE_MASK 0x0000000e
#define UX_DCD_SIM_SLAVE_ERROR_CODE_SHIFT 0x00000001
#define UX_DCD_SIM_SLAVE_ERROR_CODE_PID_ERROR 0x00000001
#define UX_DCD_SIM_SLAVE_ERROR_CODE_PID_UNKNOWN 0x00000002
#define UX_DCD_SIM_SLAVE_ERROR_CODE_UNEXPECTED_PACKET 0x00000003
#define UX_DCD_SIM_SLAVE_ERROR_CODE_TOKEN_CRC 0x00000004
#define UX_DCD_SIM_SLAVE_ERROR_CODE_DATA_CRC 0x00000005
#define UX_DCD_SIM_SLAVE_ERROR_CODE_TIME_OUT 0x00000006
#define UX_DCD_SIM_SLAVE_ERROR_CODE_BABBLE 0x00000007
#define UX_DCD_SIM_SLAVE_ERROR_CODE_UNEXPECTED_EOP 0x00000008
#define UX_DCD_SIM_SLAVE_ERROR_CODE_NAK 0x00000009
#define UX_DCD_SIM_SLAVE_ERROR_CODE_STALLED 0x0000000a
#define UX_DCD_SIM_SLAVE_ERROR_CODE_OVERFLOW 0x0000000b
#define UX_DCD_SIM_SLAVE_ERROR_CODE_EMPTY_PACKET 0x0000000c
#define UX_DCD_SIM_SLAVE_ERROR_CODE_BIT_STUFFING 0x0000000d
#define UX_DCD_SIM_SLAVE_ERROR_CODE_SYNC_ERROR 0x0000000e
#define UX_DCD_SIM_SLAVE_ERROR_CODE_DATA_TOGGLE 0x0000000f
#define UX_DCD_SIM_SLAVE_ERROR_TRANSMISSION_OK 0x00000001u
#define UX_DCD_SIM_SLAVE_ERROR_CODE_MASK 0x0000000eu
#define UX_DCD_SIM_SLAVE_ERROR_CODE_SHIFT 0x00000001u
#define UX_DCD_SIM_SLAVE_ERROR_CODE_PID_ERROR 0x00000001u
#define UX_DCD_SIM_SLAVE_ERROR_CODE_PID_UNKNOWN 0x00000002u
#define UX_DCD_SIM_SLAVE_ERROR_CODE_UNEXPECTED_PACKET 0x00000003u
#define UX_DCD_SIM_SLAVE_ERROR_CODE_TOKEN_CRC 0x00000004u
#define UX_DCD_SIM_SLAVE_ERROR_CODE_DATA_CRC 0x00000005u
#define UX_DCD_SIM_SLAVE_ERROR_CODE_TIME_OUT 0x00000006u
#define UX_DCD_SIM_SLAVE_ERROR_CODE_BABBLE 0x00000007u
#define UX_DCD_SIM_SLAVE_ERROR_CODE_UNEXPECTED_EOP 0x00000008u
#define UX_DCD_SIM_SLAVE_ERROR_CODE_NAK 0x00000009u
#define UX_DCD_SIM_SLAVE_ERROR_CODE_STALLED 0x0000000au
#define UX_DCD_SIM_SLAVE_ERROR_CODE_OVERFLOW 0x0000000bu
#define UX_DCD_SIM_SLAVE_ERROR_CODE_EMPTY_PACKET 0x0000000cu
#define UX_DCD_SIM_SLAVE_ERROR_CODE_BIT_STUFFING 0x0000000du
#define UX_DCD_SIM_SLAVE_ERROR_CODE_SYNC_ERROR 0x0000000eu
#define UX_DCD_SIM_SLAVE_ERROR_CODE_DATA_TOGGLE 0x0000000fu


/* Define USB slave simulator physical endpoint status definition. */

#define UX_DCD_SIM_SLAVE_ED_STATUS_UNUSED 0
#define UX_DCD_SIM_SLAVE_ED_STATUS_USED 1
#define UX_DCD_SIM_SLAVE_ED_STATUS_TRANSFER 2
#define UX_DCD_SIM_SLAVE_ED_STATUS_STALLED 4
#define UX_DCD_SIM_SLAVE_ED_STATUS_UNUSED 0u
#define UX_DCD_SIM_SLAVE_ED_STATUS_USED 1u
#define UX_DCD_SIM_SLAVE_ED_STATUS_TRANSFER 2u
#define UX_DCD_SIM_SLAVE_ED_STATUS_STALLED 4u
#define UX_DCD_SIM_SLAVE_ED_STATUS_DONE 8u


/* Define USB slave simulator physical endpoint structure. */
Expand Down Expand Up @@ -153,11 +157,13 @@ UINT _ux_dcd_sim_slave_initialize(VOID);
UINT _ux_dcd_sim_slave_initialize_complete(VOID);
UINT _ux_dcd_sim_slave_state_change(UX_DCD_SIM_SLAVE *dcd_sim_slave, ULONG state);
UINT _ux_dcd_sim_slave_transfer_request(UX_DCD_SIM_SLAVE *dcd_sim_slave, UX_SLAVE_TRANSFER *transfer_request);
UINT _ux_dcd_sim_slave_transfer_run(UX_DCD_SIM_SLAVE *dcd_sim_slave, UX_SLAVE_TRANSFER *transfer_request);
UINT _ux_dcd_sim_slave_transfer_abort(UX_DCD_SIM_SLAVE *dcd_sim_slave, UX_SLAVE_TRANSFER *transfer_request);

/* Define Device Simulator Class API prototypes. */

#define ux_dcd_sim_slave_initialize _ux_dcd_sim_slave_initialize

/* Determine if a C++ compiler is being used. If so, complete the standard
C conditional started above. */
#ifdef __cplusplus
Expand Down
27 changes: 24 additions & 3 deletions 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.8 */
/* 6.1.10 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
Expand All @@ -47,6 +47,9 @@
/* added extern "C" keyword */
/* for compatibility with C++, */
/* resulting in version 6.1.8 */
/* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
/* added standalone support, */
/* resulting in version 6.1.10 */
/* */
/**************************************************************************/

Expand Down Expand Up @@ -92,8 +95,20 @@ typedef struct UX_SLAVE_CLASS_DPUMP_STRUCT
UX_SLAVE_ENDPOINT *ux_slave_class_dpump_bulkin_endpoint;
UX_SLAVE_ENDPOINT *ux_slave_class_dpump_bulkout_endpoint;
ULONG ux_slave_class_dpump_alternate_setting;


#if defined(UX_DEVICE_STANDALONE)
UCHAR *ux_device_class_dpump_write_buffer;
ULONG ux_device_class_dpump_write_requested_length;
ULONG ux_device_class_dpump_write_transfer_length;
ULONG ux_device_class_dpump_write_actual_length;
UINT ux_device_class_dpump_write_state;
UINT ux_device_class_dpump_write_status;
UCHAR *ux_device_class_dpump_read_buffer;
ULONG ux_device_class_dpump_read_requested_length;
ULONG ux_device_class_dpump_read_transfer_length;
ULONG ux_device_class_dpump_read_actual_length;
UINT ux_device_class_dpump_read_state;
UINT ux_device_class_dpump_read_status;
#endif
} UX_SLAVE_CLASS_DPUMP;

/* Define Device Data Pump Class prototypes. */
Expand All @@ -104,15 +119,21 @@ UINT _ux_device_class_dpump_deactivate(UX_SLAVE_CLASS_COMMAND *command);
UINT _ux_device_class_dpump_entry(UX_SLAVE_CLASS_COMMAND *command);
UINT _ux_device_class_dpump_read(UX_SLAVE_CLASS_DPUMP *dpump, UCHAR *buffer,
ULONG requested_length, ULONG *actual_length);
UINT _ux_device_class_dpump_read_run(UX_SLAVE_CLASS_DPUMP *dpump, UCHAR *buffer,
ULONG requested_length, ULONG *actual_length);
UINT _ux_device_class_dpump_write(UX_SLAVE_CLASS_DPUMP *dpump, UCHAR *buffer,
ULONG requested_length, ULONG *actual_length);
UINT _ux_device_class_dpump_write_run(UX_SLAVE_CLASS_DPUMP *dpump, UCHAR *buffer,
ULONG requested_length, ULONG *actual_length);
UINT _ux_device_class_dpump_change(UX_SLAVE_CLASS_COMMAND *command);

/* Define Device DPUMP Class API prototypes. */

#define ux_device_class_dpump_entry _ux_device_class_dpump_entry
#define ux_device_class_dpump_read _ux_device_class_dpump_read
#define ux_device_class_dpump_read_run _ux_device_class_dpump_read_run
#define ux_device_class_dpump_write _ux_device_class_dpump_write
#define ux_device_class_dpump_write_run _ux_device_class_dpump_write_run

/* Determine if a C++ compiler is being used. If so, complete the standard
C conditional started above. */
Expand Down
8 changes: 7 additions & 1 deletion common/core/inc/ux_device_stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
/* COMPONENT DEFINITION RELEASE */
/* */
/* ux_device_stack.h PORTABLE C */
/* 6.1.8 */
/* 6.1.10 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
Expand All @@ -46,6 +46,9 @@
/* added extern "C" keyword */
/* for compatibility with C++, */
/* resulting in version 6.1.8 */
/* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
/* added standalone support, */
/* resulting in version 6.1.10 */
/* */
/**************************************************************************/

Expand Down Expand Up @@ -99,6 +102,9 @@ UINT _ux_device_stack_class_unregister(UCHAR *class_name, UINT (*class_entry_
UINT _ux_device_stack_microsoft_extension_register(ULONG vendor_request, UINT (*vendor_request_function)(ULONG, ULONG, ULONG, ULONG, UCHAR *, ULONG *));
UINT _ux_device_stack_uninitialize(VOID);

UINT _ux_device_stack_tasks_run(VOID);
UINT _ux_device_stack_transfer_run(UX_SLAVE_TRANSFER *transfer_request, ULONG slave_length, ULONG host_length);

/* Determine if a C++ compiler is being used. If so, complete the standard
C conditional started above. */
#ifdef __cplusplus
Expand Down
13 changes: 10 additions & 3 deletions common/core/inc/ux_hcd_sim_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/* COMPONENT DEFINITION RELEASE */
/* */
/* ux_hcd_sim_host.h PORTABLE C */
/* 6.1.8 */
/* 6.1.10 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
Expand Down Expand Up @@ -58,6 +58,9 @@
/* added extern "C" keyword */
/* for compatibility with C++, */
/* resulting in version 6.1.8 */
/* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
/* added standalone support, */
/* resulting in version 6.1.10 */
/* */
/**************************************************************************/

Expand Down Expand Up @@ -132,7 +135,9 @@ typedef struct UX_HCD_SIM_HOST_STRUCT
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;


Expand All @@ -159,8 +164,9 @@ typedef struct UX_HCD_SIM_HOST_ED_STRUCT

/* Define simulator host ED bitmap. */

#define UX_HCD_SIM_HOST_ED_STATIC 0x80000000
#define UX_HCD_SIM_HOST_ED_SKIP 0x40000000
#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. */
Expand Down Expand Up @@ -257,6 +263,7 @@ UINT _ux_hcd_sim_host_transaction_schedule(UX_HCD_SIM_HOST *hcd_sim_host, UX_
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. */

Expand Down
9 changes: 8 additions & 1 deletion common/core/inc/ux_host_class_dpump.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/* COMPONENT DEFINITION RELEASE */
/* */
/* ux_host_class_dpump.h PORTABLE C */
/* 6.1.8 */
/* 6.1.10 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
Expand All @@ -47,6 +47,9 @@
/* added extern "C" keyword */
/* for compatibility with C++, */
/* resulting in version 6.1.8 */
/* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
/* added standalone support, */
/* resulting in version 6.1.10 */
/* */
/**************************************************************************/

Expand Down Expand Up @@ -81,6 +84,10 @@ extern "C" {

#define UX_HOST_CLASS_DPUMP_GENERIC_NAME "USB DPUMP"

/* Define R/W lock bits for standalone mode. */

#define UX_HOST_CLASS_DPUMP_READ_LOCK (1u<<0)
#define UX_HOST_CLASS_DPUMP_WRITE_LOCK (1u<<1)

/* Define Printer Class function prototypes. */

Expand Down
33 changes: 32 additions & 1 deletion common/core/inc/ux_host_stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/* COMPONENT DEFINITION RELEASE */
/* */
/* ux_host_stack.h PORTABLE C */
/* 6.1.8 */
/* 6.1.10 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
Expand Down Expand Up @@ -57,6 +57,9 @@
/* added extern "C" keyword */
/* for compatibility with C++, */
/* resulting in version 6.1.8 */
/* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
/* added standalone support, */
/* resulting in version 6.1.10 */
/* */
/**************************************************************************/

Expand All @@ -74,6 +77,32 @@ extern "C" {
#endif


/* Define Host Stack enumeration state machine states. */

#define UX_HOST_STACK_ENUM_PORT_ENABLE (UX_STATE_STEP + 0)
#define UX_HOST_STACK_ENUM_PORT_RESET (UX_STATE_STEP + 1)
#define UX_HOST_STACK_ENUM_PORT_RESET_WAIT (UX_STATE_STEP + 2)
#define UX_HOST_STACK_ENUM_DEVICE_ADDR_SET (UX_STATE_STEP + 3)
#define UX_HOST_STACK_ENUM_DEVICE_ADDR_SENT (UX_STATE_STEP + 4)
#define UX_HOST_STACK_ENUM_DEVICE_DESCR_READ (UX_STATE_STEP + 5)
#define UX_HOST_STACK_ENUM_DEVICE_DESCR_PARSE (UX_STATE_STEP + 6)
#define UX_HOST_STACK_ENUM_CONFIG_DESCR_READ (UX_STATE_STEP + 7)
#define UX_HOST_STACK_ENUM_CONFIG_DESCR_PARSE (UX_STATE_STEP + 8)
#define UX_HOST_STACK_ENUM_CONFIG_DESCR_NEXT (UX_STATE_STEP + 9)
#define UX_HOST_STACK_ENUM_CONFIG_SET (UX_STATE_STEP + 10)
#define UX_HOST_STACK_ENUM_CONFIG_ACTIVATE (UX_STATE_STEP + 11)
#define UX_HOST_STACK_ENUM_ACTIVATE (UX_STATE_STEP + 12)
#define UX_HOST_STACK_ENUM_ACTIVATE_WAIT (UX_STATE_STEP + 13)
#define UX_HOST_STACK_ENUM_RETRY (UX_STATE_STEP + 14)
#define UX_HOST_STACK_ENUM_NEXT (UX_STATE_STEP + 15)
#define UX_HOST_STACK_ENUM_TRANS_LOCK_WAIT (UX_STATE_STEP + 16)
#define UX_HOST_STACK_ENUM_TRANS_WAIT (UX_STATE_STEP + 17)
#define UX_HOST_STACK_ENUM_WAIT (UX_STATE_STEP + 18)
#define UX_HOST_STACK_ENUM_FAIL (UX_STATE_STEP + 19)
#define UX_HOST_STACK_ENUM_DONE (UX_STATE_STEP + 20)
#define UX_HOST_STACK_ENUM_IDLE (UX_STATE_STEP + 21)


/* Define Host Stack component function prototypes. */

#if UX_MAX_DEVICES > 1
Expand Down Expand Up @@ -156,6 +185,8 @@ UINT _ux_host_stack_role_swap(UX_DEVICE *device);
VOID _ux_host_stack_hnp_polling_thread_entry(ULONG id);
#endif

UINT _ux_host_stack_tasks_run(VOID);
UINT _ux_host_stack_transfer_run(UX_TRANSFER *transfer_request);

/* Determine if a C++ compiler is being used. If so, complete the standard
C conditional started above. */
Expand Down
19 changes: 18 additions & 1 deletion common/core/inc/ux_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/* COMPONENT DEFINITION RELEASE */
/* */
/* ux_system.h PORTABLE C */
/* 6.1.3 */
/* 6.1.10 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
Expand All @@ -46,6 +46,10 @@
/* 12-31-2020 Chaoqiong Xiao Modified comment(s), */
/* added BOS support, */
/* resulting in version 6.1.3 */
/* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
/* added standalone support, */
/* added device printer name, */
/* resulting in version 6.1.10 */
/* */
/**************************************************************************/

Expand All @@ -62,6 +66,7 @@
UINT _ux_system_initialize(VOID *regular_memory_pool_start, ULONG regular_memory_size,
VOID *cache_safe_memory_pool_start, ULONG cache_safe_memory_size);
UINT _ux_system_uninitialize(VOID);
UINT _ux_system_tasks_run(VOID);
#endif

/* Define System component external data references. */
Expand Down Expand Up @@ -139,7 +144,19 @@ extern UCHAR _ux_system_slave_class_rndis_name[];
extern UCHAR _ux_system_slave_class_cdc_ecm_name[];
extern UCHAR _ux_system_slave_class_dfu_name[];

extern UCHAR _ux_system_device_class_printer_name[];

#if defined(UX_HOST_SIDE_ONLY)
#define _ux_system_host_tasks_run _ux_host_stack_tasks_run
#else
#define _ux_system_host_tasks_run _ux_system_tasks_run
#endif

#if defined(UX_DEVICE_SIDE_ONLY)
#define _ux_system_device_tasks_run _ux_device_stack_tasks_run
#else
#define _ux_system_device_tasks_run _ux_system_tasks_run
#endif

#endif

82 changes: 80 additions & 2 deletions common/core/inc/ux_user_sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/* PORT SPECIFIC C INFORMATION RELEASE */
/* */
/* ux_user.h PORTABLE C */
/* 6.1.9 */
/* 6.1.10 */
/* */
/* AUTHOR */
/* */
Expand Down Expand Up @@ -68,6 +68,16 @@
/* 10-15-2021 Chaoqiong Xiao Modified comment(s), */
/* added option for assert, */
/* resulting in version 6.1.9 */
/* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
/* added standalone support, */
/* added option for device */
/* audio feedback endpoint, */
/* added option for MTP, */
/* added options for HID */
/* interrupt OUT support, */
/* added option to validate */
/* class code in enumeration, */
/* resulting in version 6.1.10 */
/* */
/**************************************************************************/

Expand Down Expand Up @@ -359,10 +369,39 @@

/* #define UX_DEVICE_CLASS_CDC_ACM_TRANSMISSION_DISABLE */

/* defined, this macro enables device audio feedback endpoint support. */

/* #define UX_DEVICE_CLASS_AUDIO_FEEDBACK_SUPPORT */

/* Defined, device HID interrupt OUT transfer is supported. */

/* #define UX_DEVICE_CLASS_HID_INTERRUPT_OUT_SUPPORT */

/* Defined, this macro enables device bi-directional-endpoint support. */

/* #define UX_DEVICE_BIDIRECTIONAL_ENDPOINT_SUPPORT */

/* Defined, this macro enables device/host PIMA MTP support. */

/* #define UX_PIMA_WITH_MTP_SUPPORT */

/* Defined, this macro enables host device class code validation.
Only following USB-IF allowed device class code is allowed:
0x00, 0x02 (CDC Control), 0x09 (Hub), 0x11 (Billboard), 0xDC (Diagnostic), 0xEF (MISC), 0xFF (Vendor)
Refer to https://www.usb.org/defined-class-codes for more details.
*/

/* #define UX_HOST_DEVICE_CLASS_CODE_VALIDATION_ENABLE */

/* Defined, host HID interrupt OUT transfer is supported. */

/* #define UX_HOST_CLASS_HID_INTERRUPT_OUT_SUPPORT */

/* Define HID report transfer timeout value in millisecond.
The default is 10000 milliseconds. */

/* #define UX_HOST_CLASS_HID_REPORT_TRANSFER_TIMEOUT 10000 */

/* Defined, this value will only enable the host side of usbx. */
/* #define UX_HOST_SIDE_ONLY */

Expand All @@ -380,7 +419,23 @@
#endif
#endif

/* Defined, this value represents the maximum size of single tansfers for the SCSI data phase.
/* Defined, this macro will enable the standalone mode of usbx. */
/* #define UX_STANDALONE */

/* Defined, this macro will remove the FileX dependency of host storage.
In this mode, sector access is offered instead of directly FileX FX_MEDIA support.
Use following APIs for media obtain and access:
- ux_host_class_storage_media_get : get instance of UX_HOST_CLASS_STORAGE_MEDIA
- ux_host_class_storage_media_lock : lock specific media for further read/write
- ux_host_class_storage_media_read : read sectors on locked media
- ux_host_class_storage_media_write : write sectors on locked media
- ux_host_class_storage_media_unlock : unlock media
Note it's forced defined/enabled in standalone mode of usbx.
*/
/* #define UX_HOST_CLASS_STORAGE_NO_FILEX */

/* Defined, this value represents the maximum size of single transfers for the SCSI data phase.
By default it's 1024.
*/

#define UX_HOST_CLASS_STORAGE_MAX_TRANSFER_SIZE (1024 * 1)
Expand All @@ -389,6 +444,29 @@
*/
#define UX_DEBUG_LOG_SIZE (1024 * 16)

/* Defined, this macro represents the non-blocking function to return time tick.
This macro is used only in standalone mode.
The tick rate is defined by UX_PERIODIC_RATE.
If it's not defined, or TX is not included, a external function must be
implement in application:
extern ULONG _ux_utility_time_get(VOID);
*/
/* #define _ux_utility_time_get() tx_time_get() */

/* Defined, this macro represents the non-blocking function to disable interrupts
and return old interrupt setting flags.
If it's not defined, or TX is not included, a external function must be
implement in application:
extern ALIGN_TYPE _ux_utility_interrupt_disable(VOID);
*/
/* #define _ux_utility_interrupt_disable() _tx_thread_interrupt_disable() */

/* Defined, this macro represents the non-blocking function to restore interrupts.
If it's not defined, or TX is not included, a external function must be
implement in application:
extern VOID _ux_utility_interrupt_restore(ALIGN_TYPE);
*/
/* #define _ux_utility_interrupt_restore(flags) _tx_thread_interrupt_restore(flags) */

/* Defined, this enables the assert checks inside usbx. */
#define UX_ENABLE_ASSERT
Expand Down
189 changes: 175 additions & 14 deletions common/core/inc/ux_utility.h

Large diffs are not rendered by default.

26 changes: 21 additions & 5 deletions common/core/src/ux_dcd_sim_slave_endpoint_reset.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
/* FUNCTION RELEASE */
/* */
/* _ux_dcd_sim_slave_endpoint_reset PORTABLE C */
/* 6.1.7 */
/* 6.1.10 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
Expand Down Expand Up @@ -71,20 +71,31 @@
/* cleared transfer flag and */
/* waked up suspended thread, */
/* resulting in version 6.1.7 */
/* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
/* added standalone support, */
/* resulting in version 6.1.10 */
/* */
/**************************************************************************/
UINT _ux_dcd_sim_slave_endpoint_reset(UX_DCD_SIM_SLAVE *dcd_sim_slave, UX_SLAVE_ENDPOINT *endpoint)
{

UX_DCD_SIM_SLAVE_ED *ed;
ULONG transfer_waiting;
#if !defined(UX_DEVICE_STANDALONE)
UX_SLAVE_TRANSFER *transfer;
#endif

UX_PARAMETER_NOT_USED(dcd_sim_slave);

/* Get the physical endpoint address in the endpoint container. */
ed = (UX_DCD_SIM_SLAVE_ED *) endpoint -> ux_slave_endpoint_ed;

#if defined(UX_DEVICE_STANDALONE)

/* Transfer pending always considered. */
transfer_waiting = UX_DCD_SIM_SLAVE_ED_STATUS_TRANSFER;
#else

/* Save waiting status for non-zero endpoints. */
if (ed -> ux_sim_slave_ed_index)
{
Expand All @@ -93,18 +104,23 @@ UX_SLAVE_TRANSFER *transfer;
}
else
transfer_waiting = 0;
#endif

/* Clear pending transfer and stall status. */
ed -> ux_sim_slave_ed_status &= ~(ULONG)(transfer_waiting |
UX_DCD_SIM_SLAVE_ED_STATUS_STALLED |
UX_DCD_SIM_SLAVE_ED_STATUS_DONE);

/* Set the state of the endpoint to not stalled. */
ed -> ux_sim_slave_ed_status &= ~(ULONG)(UX_DCD_SIM_SLAVE_ED_STATUS_STALLED |
transfer_waiting);
#if !defined(UX_DEVICE_STANDALONE)

/* If some thread is pending, signal wakeup. */
if (transfer_waiting)
{
transfer = &endpoint -> ux_slave_endpoint_transfer_request;
transfer -> ux_slave_transfer_request_completion_code = UX_TRANSFER_BUS_RESET;
_ux_utility_semaphore_put(&transfer -> ux_slave_transfer_request_semaphore);
_ux_device_semaphore_put(&transfer -> ux_slave_transfer_request_semaphore);
}
#endif

/* This function never fails. */
return(UX_SUCCESS);
Expand Down
17 changes: 16 additions & 1 deletion common/core/src/ux_dcd_sim_slave_function.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
/* FUNCTION RELEASE */
/* */
/* _ux_dcd_sim_slave_function PORTABLE C */
/* 6.1 */
/* 6.1.10 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
Expand Down Expand Up @@ -78,6 +78,9 @@
/* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
/* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
/* resulting in version 6.1 */
/* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
/* added standalone support, */
/* resulting in version 6.1.10 */
/* */
/**************************************************************************/
UINT _ux_dcd_sim_slave_function(UX_SLAVE_DCD *dcd, UINT function, VOID *parameter)
Expand Down Expand Up @@ -112,10 +115,17 @@ UX_DCD_SIM_SLAVE *dcd_sim_slave;
status = _ux_dcd_sim_slave_frame_number_get(dcd_sim_slave, (ULONG *) parameter);
break;

#if defined(UX_DEVICE_STANDALONE)
case UX_DCD_TRANSFER_RUN:

status = _ux_dcd_sim_slave_transfer_run(dcd_sim_slave, (UX_SLAVE_TRANSFER *) parameter);
break;
#else
case UX_DCD_TRANSFER_REQUEST:

status = _ux_dcd_sim_slave_transfer_request(dcd_sim_slave, (UX_SLAVE_TRANSFER *) parameter);
break;
#endif

case UX_DCD_TRANSFER_ABORT:

Expand Down Expand Up @@ -157,6 +167,11 @@ UX_DCD_SIM_SLAVE *dcd_sim_slave;
status = _ux_dcd_sim_slave_endpoint_status(dcd_sim_slave, (ULONG) (ALIGN_TYPE) parameter);
break;

case UX_DCD_ISR_PENDING:

status = UX_SUCCESS;
break;

default:

/* Error trap. */
Expand Down
7 changes: 5 additions & 2 deletions common/core/src/ux_dcd_sim_slave_state_change.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
/* FUNCTION RELEASE */
/* */
/* _ux_dcd_sim_slave_state_change PORTABLE C */
/* 6.1.6 */
/* 6.1.10 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
Expand Down Expand Up @@ -72,6 +72,9 @@
/* 04-02-2021 Chaoqiong Xiao Modified comment(s), */
/* simulate force disconnect, */
/* resulting in version 6.1.6 */
/* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
/* added standalone support, */
/* resulting in version 6.1.10 */
/* */
/**************************************************************************/
UINT _ux_dcd_sim_slave_state_change(UX_DCD_SIM_SLAVE *dcd_sim_slave, ULONG state)
Expand All @@ -94,7 +97,7 @@ UX_HCD *hcd;
if (hcd)
{
hcd -> ux_hcd_root_hub_signal[0] = 2;
_ux_utility_semaphore_put(&_ux_system_host -> ux_system_host_enum_semaphore);
_ux_host_semaphore_put(&_ux_system_host -> ux_system_host_enum_semaphore);
}
}

Expand Down
8 changes: 6 additions & 2 deletions common/core/src/ux_dcd_sim_slave_transfer_abort.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
/* FUNCTION RELEASE */
/* */
/* _ux_dcd_sim_slave_transfer_abort PORTABLE C */
/* 6.1 */
/* 6.1.10 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
Expand Down Expand Up @@ -67,6 +67,9 @@
/* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
/* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
/* resulting in version 6.1 */
/* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
/* added standalone support, */
/* resulting in version 6.1.10 */
/* */
/**************************************************************************/
UINT _ux_dcd_sim_slave_transfer_abort(UX_DCD_SIM_SLAVE *dcd_sim_slave, UX_SLAVE_TRANSFER *transfer_request)
Expand All @@ -84,7 +87,8 @@ UX_SLAVE_ENDPOINT *endpoint;
ed = (UX_DCD_SIM_SLAVE_ED *) endpoint -> ux_slave_endpoint_ed;

/* Turn off the transfer bit. */
ed -> ux_sim_slave_ed_status &= ~(ULONG)UX_DCD_SIM_SLAVE_ED_STATUS_TRANSFER;
ed -> ux_sim_slave_ed_status &= ~(ULONG)
(UX_DCD_SIM_SLAVE_ED_STATUS_TRANSFER | UX_DCD_SIM_SLAVE_ED_STATUS_DONE);

/* This function never fails. */
return(UX_SUCCESS);
Expand Down
17 changes: 11 additions & 6 deletions common/core/src/ux_dcd_sim_slave_transfer_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
/* FUNCTION RELEASE */
/* */
/* _ux_dcd_sim_slave_transfer_request PORTABLE C */
/* 6.1 */
/* 6.1.10 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
Expand Down Expand Up @@ -73,6 +73,12 @@
/* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
/* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
/* resulting in version 6.1 */
/* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
/* added standalone support, */
/* cleared transfer status */
/* before semaphore wakeup to */
/* avoid a race condition, */
/* resulting in version 6.1.10 */
/* */
/**************************************************************************/
UINT _ux_dcd_sim_slave_transfer_request(UX_DCD_SIM_SLAVE *dcd_sim_slave, UX_SLAVE_TRANSFER *transfer_request)
Expand All @@ -99,20 +105,19 @@ UINT status;
ed -> ux_sim_slave_ed_status |= UX_DCD_SIM_SLAVE_ED_STATUS_TRANSFER;

/* We should wait for the semaphore to wake us up. */
status = _ux_utility_semaphore_get(&transfer_request -> ux_slave_transfer_request_semaphore,
status = _ux_device_semaphore_get(&transfer_request -> ux_slave_transfer_request_semaphore,
transfer_request -> ux_slave_transfer_request_timeout);

/* Reset the ED to TRANSFER status. */
ed -> ux_sim_slave_ed_status &= ~(ULONG)UX_DCD_SIM_SLAVE_ED_STATUS_TRANSFER;

/* Check the completion code. */
if (status != UX_SUCCESS)
{
_ux_dcd_sim_slave_transfer_abort(dcd_sim_slave, transfer_request);
transfer_request -> ux_slave_transfer_request_status = UX_TRANSFER_STATUS_COMPLETED;
return(status);
}


/* ED TRANSFER has been cleared before semaphore wakeup. */

/* Check the transfer request completion code. We may have had a BUS reset or
a device disconnection. */
if (transfer_request -> ux_slave_transfer_request_completion_code != UX_SUCCESS)
Expand Down
148 changes: 148 additions & 0 deletions common/core/src/ux_dcd_sim_slave_transfer_run.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/**************************************************************************/
/* */
/* Copyright (c) Microsoft Corporation. All rights reserved. */
/* */
/* This software is licensed under the Microsoft Software License */
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
/* and in the root directory of this software. */
/* */
/**************************************************************************/


/**************************************************************************/
/**************************************************************************/
/** */
/** USBX Component */
/** */
/** Slave Simulator Controller Driver */
/** */
/**************************************************************************/
/**************************************************************************/

#define UX_SOURCE_CODE


/* Include necessary system files. */

#include "ux_api.h"
#include "ux_dcd_sim_slave.h"


#if defined(UX_DEVICE_STANDALONE)
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _ux_dcd_sim_slave_transfer_run PORTABLE C */
/* 6.1.10 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function will initiate a transfer to a specific endpoint. */
/* If the endpoint is IN, the endpoint register will be set to accept */
/* the request. */
/* */
/* If the endpoint is IN, the endpoint FIFO will be filled with the */
/* buffer and the endpoint register set. */
/* */
/* It's for standalone mode. */
/* */
/* INPUT */
/* */
/* dcd_sim_slave Pointer to device controller */
/* transfer_request Pointer to transfer request */
/* */
/* OUTPUT */
/* */
/* State machine Status to check */
/* UX_STATE_NEXT Transfer done, to next state */
/* UX_STATE_EXIT Abnormal, to reset state */
/* (others) Keep running, waiting */
/* */
/* CALLS */
/* */
/* _ux_utility_semaphore_get Get semaphore */
/* _ux_dcd_sim_slave_transfer_abort Abort transfer */
/* */
/* CALLED BY */
/* */
/* Slave Simulator Controller Driver */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */
/* 01-31-2022 Chaoqiong Xiao Initial Version 6.1.10 */
/* */
/**************************************************************************/
UINT _ux_dcd_sim_slave_transfer_run(UX_DCD_SIM_SLAVE *dcd_sim_slave, UX_SLAVE_TRANSFER *transfer_request)
{

UX_INTERRUPT_SAVE_AREA

UX_SLAVE_ENDPOINT *endpoint;
UX_DCD_SIM_SLAVE_ED *ed;
ULONG ed_status;


UX_PARAMETER_NOT_USED(dcd_sim_slave);

/* Get the pointer to the logical endpoint from the transfer request. */
endpoint = transfer_request -> ux_slave_transfer_request_endpoint;

/* Get the slave endpoint. */
ed = (UX_DCD_SIM_SLAVE_ED *) endpoint -> ux_slave_endpoint_ed;

UX_DISABLE

/* Get current status. */
ed_status = ed -> ux_sim_slave_ed_status;

/* ED freed, must disconnected. */
if (ed_status == UX_DCD_SIM_SLAVE_ED_STATUS_UNUSED)
{
transfer_request -> ux_slave_transfer_request_status = UX_TRANSFER_BUS_RESET;
UX_RESTORE
return(UX_STATE_EXIT);
}

/* For control endpoint, always go to next state. */
if(ed -> ux_sim_slave_ed_index == 0)
{
UX_RESTORE
return(UX_STATE_NEXT);
}

/* ED stalled. */
if (ed_status & UX_DCD_SIM_SLAVE_ED_STATUS_STALLED)
{
ed -> ux_sim_slave_ed_status = UX_DCD_SIM_SLAVE_ED_STATUS_USED;
transfer_request -> ux_slave_transfer_request_status = UX_TRANSFER_STALLED;
UX_RESTORE
return(UX_STATE_NEXT);
}

/* Transfer started. */
if (ed_status & UX_DCD_SIM_SLAVE_ED_STATUS_TRANSFER)
{
if (ed_status & UX_DCD_SIM_SLAVE_ED_STATUS_DONE)
{
ed -> ux_sim_slave_ed_status = UX_DCD_SIM_SLAVE_ED_STATUS_USED;
UX_RESTORE
return(UX_STATE_NEXT);
}
UX_RESTORE
return(UX_STATE_WAIT);
}

/* Start transfer. */
ed->ux_sim_slave_ed_status |= UX_DCD_SIM_SLAVE_ED_STATUS_TRANSFER;
UX_RESTORE
return(UX_STATE_WAIT);

}
#endif
11 changes: 10 additions & 1 deletion 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 */
/* 6.1.10 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
Expand Down Expand Up @@ -66,6 +66,9 @@
/* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
/* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
/* resulting in version 6.1 */
/* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
/* added standalone support, */
/* resulting in version 6.1.10 */
/* */
/**************************************************************************/
UINT _ux_device_class_dpump_activate(UX_SLAVE_CLASS_COMMAND *command)
Expand Down Expand Up @@ -122,6 +125,12 @@ UX_SLAVE_ENDPOINT *endpoint;
endpoint = endpoint -> ux_slave_endpoint_next_endpoint;
}

#if defined(UX_DEVICE_STANDALONE)

/* Reset read/write states. */
dpump -> ux_device_class_dpump_read_state = 0;
dpump -> ux_device_class_dpump_write_state = 0;
#endif

/* If there is a activate function call it. */
if (dpump -> ux_slave_class_dpump_parameter.ux_slave_class_dpump_instance_activate != UX_NULL)
Expand Down
12 changes: 11 additions & 1 deletion 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 */
/* 6.1.10 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
Expand Down Expand Up @@ -69,6 +69,9 @@
/* verified memset and memcpy */
/* cases, */
/* resulting in version 6.1 */
/* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
/* added standalone support, */
/* resulting in version 6.1.10 */
/* */
/**************************************************************************/
UINT _ux_device_class_dpump_change(UX_SLAVE_CLASS_COMMAND *command)
Expand Down Expand Up @@ -144,6 +147,13 @@ UX_SLAVE_ENDPOINT *endpoint;
/* Keep the alternate setting in the dpump structure. */
dpump -> ux_slave_class_dpump_alternate_setting = interface -> ux_slave_interface_descriptor.bAlternateSetting;

#if defined(UX_DEVICE_STANDALONE)

/* Reset read/write states. */
dpump -> ux_device_class_dpump_read_state = 0;
dpump -> ux_device_class_dpump_write_state = 0;
#endif

/* If there is an activate function call it. */
if (dpump -> ux_slave_class_dpump_parameter.ux_slave_class_dpump_instance_activate != UX_NULL)

Expand Down
242 changes: 242 additions & 0 deletions common/core/src/ux_device_class_dpump_read_run.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
/**************************************************************************/
/* */
/* Copyright (c) Microsoft Corporation. All rights reserved. */
/* */
/* This software is licensed under the Microsoft Software License */
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
/* and in the root directory of this software. */
/* */
/**************************************************************************/

/**************************************************************************/
/**************************************************************************/
/** */
/** USBX Component */
/** */
/** Device DPUMP Class */
/** */
/**************************************************************************/
/**************************************************************************/

#define UX_SOURCE_CODE


/* Include necessary system files. */

#include "ux_api.h"
#include "ux_device_class_dpump.h"
#include "ux_device_stack.h"


#if defined(UX_DEVICE_STANDALONE)

#define UX_DEVICE_CLASS_DPUMP_READ_START (UX_STATE_STEP + 1)
#define UX_DEVICE_CLASS_DPUMP_READ_WAIT (UX_STATE_STEP + 2)

/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _ux_device_class_dpump_read_run PORTABLE C */
/* 6.1.10 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function reads from the DPUMP class. */
/* */
/* It's for standalone mode. */
/* */
/* INPUT */
/* */
/* dpump DPUMP class instance */
/* buffer Buffer to hold data read */
/* requested_length Bytes to read */
/* actual_length Bytes read */
/* */
/* OUTPUT */
/* */
/* State machine Status to check */
/* UX_STATE_NEXT Transfer done, to next state */
/* UX_STATE_EXIT Abnormal, to reset state */
/* (others) Keep running, waiting */
/* */
/* CALLS */
/* */
/* _ux_device_stack_transfer_request Request transfer */
/* _ux_utility_memory_copy Copy memory */
/* */
/* CALLED BY */
/* */
/* Application */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */
/* 01-31-2022 Chaoqiong Xiao Initial Version 6.1.10 */
/* */
/**************************************************************************/
UINT _ux_device_class_dpump_read_run(UX_SLAVE_CLASS_DPUMP *dpump, UCHAR *buffer,
ULONG requested_length, ULONG *actual_length)
{

UX_SLAVE_ENDPOINT *endpoint;
UX_SLAVE_DEVICE *device;
UX_SLAVE_TRANSFER *transfer_request;
UINT status;
UINT read_state;


/* If trace is enabled, insert this event into the trace buffer. */
UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_CLASS_DPUMP_READ, dpump, buffer, requested_length, 0, UX_TRACE_DEVICE_CLASS_EVENTS, 0, 0)

/* Get the pointer to the device. */
device = &_ux_system_slave -> ux_system_slave_device;

/* As long as the device is in the CONFIGURED state. */
if (device -> ux_slave_device_state != UX_DEVICE_CONFIGURED)
{

/* Error trap. */
_ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_CONFIGURATION_HANDLE_UNKNOWN);

/* If trace is enabled, insert this event into the trace buffer. */
UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_CONFIGURATION_HANDLE_UNKNOWN, device, 0, 0, UX_TRACE_ERRORS, 0, 0)

/* Cannot proceed with command, the interface is down. */
dpump -> ux_device_class_dpump_read_state = UX_STATE_RESET;
dpump -> ux_device_class_dpump_read_status = UX_CONFIGURATION_HANDLE_UNKNOWN;
return(UX_STATE_EXIT);
}

/* Locate the OUT endpoint. */
endpoint = dpump -> ux_slave_class_dpump_bulkout_endpoint;

/* Check endpoint. If NULL, we have not yet received the proper SET_INTERFACE command. */
if (endpoint == UX_NULL)
{
/* Error trap. */
_ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_ENDPOINT_HANDLE_UNKNOWN);

dpump -> ux_device_class_dpump_read_state = UX_STATE_RESET;
dpump -> ux_device_class_dpump_read_status = UX_ENDPOINT_HANDLE_UNKNOWN;
return(UX_STATE_EXIT);
}

/* All DPUMP reading are on the endpoint OUT, from the host. */
transfer_request = &endpoint -> ux_slave_endpoint_transfer_request;

/* Handle state cases. */
read_state = dpump -> ux_device_class_dpump_read_state;
switch(read_state)
{
case UX_STATE_RESET:
dpump -> ux_device_class_dpump_read_state = UX_DEVICE_CLASS_DPUMP_READ_START;
dpump -> ux_device_class_dpump_read_status = UX_TRANSFER_NO_ANSWER;
dpump -> ux_device_class_dpump_read_buffer = buffer;
dpump -> ux_device_class_dpump_read_requested_length = requested_length;
dpump -> ux_device_class_dpump_read_actual_length = 0;

/* Fall through. */
case UX_DEVICE_CLASS_DPUMP_READ_START:

/* Get remaining requested length. */
requested_length = dpump -> ux_device_class_dpump_read_requested_length -
dpump -> ux_device_class_dpump_read_actual_length;

/* There is no remaining, we are done. */
if (requested_length == 0)
{
*actual_length = dpump -> ux_device_class_dpump_read_actual_length;
dpump -> ux_device_class_dpump_read_state = UX_STATE_RESET;
dpump -> ux_device_class_dpump_read_status = UX_SUCCESS;
return(UX_STATE_NEXT);
}

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

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

else

/* We can proceed with the demanded length. */
dpump -> ux_device_class_dpump_read_transfer_length = requested_length;

/* Next state. */
dpump -> ux_device_class_dpump_read_state = UX_DEVICE_CLASS_DPUMP_READ_WAIT;
UX_SLAVE_TRANSFER_STATE_RESET(transfer_request);

/* Fall through. */
case UX_DEVICE_CLASS_DPUMP_READ_WAIT:

/* Send the request to the device controller. */
status = _ux_device_stack_transfer_run(transfer_request,
dpump -> ux_device_class_dpump_read_transfer_length,
dpump -> ux_device_class_dpump_read_transfer_length);

/* Error case. */
if (status < UX_STATE_NEXT)
{

dpump -> ux_device_class_dpump_read_state = UX_STATE_RESET;
dpump -> ux_device_class_dpump_read_status =
transfer_request -> ux_slave_transfer_request_completion_code;
return(UX_STATE_EXIT);
}

/* Success case. */
if (status == UX_STATE_NEXT)
{

/* We need to copy the buffer locally. */
_ux_utility_memory_copy(dpump -> ux_device_class_dpump_read_buffer,
transfer_request -> ux_slave_transfer_request_data_pointer,
dpump -> ux_device_class_dpump_read_transfer_length); /* Use case of memcpy is verified. */

/* Next buffer address. */
dpump -> ux_device_class_dpump_read_buffer +=
transfer_request -> ux_slave_transfer_request_actual_length;

/* Set the length actually received. */
dpump -> ux_device_class_dpump_read_actual_length +=
transfer_request -> ux_slave_transfer_request_actual_length;

/* Last transfer status. */
dpump -> ux_device_class_dpump_read_status =
transfer_request -> ux_slave_transfer_request_completion_code;

/* Update actual length. */
*actual_length = dpump -> ux_device_class_dpump_read_actual_length;

/* Check short packet. */
if (transfer_request -> ux_slave_transfer_request_actual_length <
transfer_request -> ux_slave_transfer_request_requested_length)
{

/* It's done. */
dpump -> ux_device_class_dpump_read_state = UX_STATE_RESET;
return(UX_STATE_NEXT);
}

/* Next state. */
dpump -> ux_device_class_dpump_read_state = UX_DEVICE_CLASS_DPUMP_READ_START;
}

/* Keep waiting. */
return(UX_STATE_WAIT);

default: /* Error. */
dpump -> ux_device_class_dpump_read_state = UX_STATE_RESET;
break;
}

/* Error case. */
return(UX_STATE_EXIT);
}
#endif
9 changes: 7 additions & 2 deletions common/core/src/ux_device_class_dpump_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@ VOID _ux_device_class_dpump_thread(ULONG dpump_class);
/* FUNCTION RELEASE */
/* */
/* _ux_device_class_dpump_thread PORTABLE C */
/* 6.1 */
/* 6.1.10 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function is the thread of the dpump class. */
/* */
/* It's for RTOS mode. */
/* */
/* INPUT */
/* */
Expand Down Expand Up @@ -74,6 +76,9 @@ VOID _ux_device_class_dpump_thread(ULONG dpump_class);
/* verified memset and memcpy */
/* cases, */
/* resulting in version 6.1 */
/* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
/* refined macros names, */
/* resulting in version 6.1.10 */
/* */
/**************************************************************************/
VOID _ux_device_class_dpump_thread(ULONG dpump_class)
Expand Down Expand Up @@ -163,7 +168,7 @@ ULONG length;

/* We need to suspend ourselves. We will be resumed by the
device enumeration module. */
_ux_utility_thread_suspend(&class -> ux_slave_class_thread);
_ux_device_thread_suspend(&class -> ux_slave_class_thread);
}
}

243 changes: 243 additions & 0 deletions common/core/src/ux_device_class_dpump_write_run.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
/**************************************************************************/
/* */
/* Copyright (c) Microsoft Corporation. All rights reserved. */
/* */
/* This software is licensed under the Microsoft Software License */
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
/* and in the root directory of this software. */
/* */
/**************************************************************************/

/**************************************************************************/
/**************************************************************************/
/** */
/** USBX Component */
/** */
/** Device DPUMP Class */
/** */
/**************************************************************************/
/**************************************************************************/

#define UX_SOURCE_CODE


/* Include necessary system files. */

#include "ux_api.h"
#include "ux_device_class_dpump.h"
#include "ux_device_stack.h"


#if defined(UX_DEVICE_STANDALONE)

#define UX_DEVICE_CLASS_DPUMP_WRITE_START (UX_STATE_STEP + 1)
#define UX_DEVICE_CLASS_DPUMP_WRITE_WAIT (UX_STATE_STEP + 2)

/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _ux_device_class_dpump_write_run PORTABLE C */
/* 6.1.10 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function writes to the DPUMP class. */
/* */
/* It's for standalone mode. */
/* */
/* INPUT */
/* */
/* dpump DPUMP class instance */
/* buffer Buffer data to write */
/* requested_length Bytes to write */
/* actual_length Bytes written */
/* */
/* OUTPUT */
/* */
/* State machine Status to check */
/* UX_STATE_NEXT Transfer done, to next state */
/* UX_STATE_EXIT Abnormal, to reset state */
/* (others) Keep running, waiting */
/* */
/* CALLS */
/* */
/* _ux_device_stack_transfer_request Request transfer */
/* _ux_utility_memory_copy Copy memory */
/* */
/* CALLED BY */
/* */
/* Application */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */
/* 01-31-2022 Chaoqiong Xiao Initial Version 6.1.10 */
/* */
/**************************************************************************/
UINT _ux_device_class_dpump_write_run(UX_SLAVE_CLASS_DPUMP *dpump, UCHAR *buffer,
ULONG requested_length, ULONG *actual_length)
{

UX_SLAVE_ENDPOINT *endpoint;
UX_SLAVE_DEVICE *device;
UX_SLAVE_TRANSFER *transfer_request;
UINT status;
UINT zlp = UX_FALSE;
UINT read_state;


/* If trace is enabled, insert this event into the trace buffer. */
UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_CLASS_DPUMP_WRITE, dpump, buffer, requested_length, 0, UX_TRACE_DEVICE_CLASS_EVENTS, 0, 0)

/* Get the pointer to the device. */
device = &_ux_system_slave -> ux_system_slave_device;

/* As long as the device is in the CONFIGURED state. */
if (device -> ux_slave_device_state != UX_DEVICE_CONFIGURED)
{

/* Error trap. */
_ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_CONFIGURATION_HANDLE_UNKNOWN);

/* If trace is enabled, insert this event into the trace buffer. */
UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_CONFIGURATION_HANDLE_UNKNOWN, device, 0, 0, UX_TRACE_ERRORS, 0, 0)

/* Cannot proceed with command, the interface is down. */
dpump -> ux_device_class_dpump_write_state = UX_STATE_RESET;
dpump -> ux_device_class_dpump_write_status = UX_CONFIGURATION_HANDLE_UNKNOWN;
return(UX_STATE_EXIT);
}

/* Locate the OUT endpoint. */
endpoint = dpump -> ux_slave_class_dpump_bulkin_endpoint;

/* Check endpoint. If NULL, we have not yet received the proper SET_INTERFACE command. */
if (endpoint == UX_NULL)
{
/* Error trap. */
_ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_ENDPOINT_HANDLE_UNKNOWN);

dpump -> ux_device_class_dpump_write_state = UX_STATE_RESET;
dpump -> ux_device_class_dpump_write_status = UX_ENDPOINT_HANDLE_UNKNOWN;
return(UX_STATE_EXIT);
}

/* All DPUMP reading are on the endpoint OUT, from the host. */
transfer_request = &endpoint -> ux_slave_endpoint_transfer_request;

/* Handle state cases. */
read_state = dpump -> ux_device_class_dpump_write_state;
switch(read_state)
{
case UX_STATE_RESET:
dpump -> ux_device_class_dpump_write_state = UX_DEVICE_CLASS_DPUMP_WRITE_START;
dpump -> ux_device_class_dpump_write_status = UX_TRANSFER_NO_ANSWER;
dpump -> ux_device_class_dpump_write_buffer = buffer;
dpump -> ux_device_class_dpump_write_requested_length = requested_length;
dpump -> ux_device_class_dpump_write_actual_length = 0;
if (requested_length == 0)
zlp = UX_TRUE;

/* Fall through. */
case UX_DEVICE_CLASS_DPUMP_WRITE_START:

/* Get remaining requested length. */
requested_length = dpump -> ux_device_class_dpump_write_requested_length -
dpump -> ux_device_class_dpump_write_actual_length;

/* There is no remaining, we are done. */
if (requested_length == 0 && !zlp)
{
*actual_length = dpump -> ux_device_class_dpump_write_actual_length;
dpump -> ux_device_class_dpump_write_state = UX_STATE_RESET;
dpump -> ux_device_class_dpump_write_status = UX_SUCCESS;
return(UX_STATE_NEXT);
}

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

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

else

/* We can proceed with the demanded length. */
dpump -> ux_device_class_dpump_write_transfer_length = requested_length;

/* On a out, we copy the buffer to the caller. Not very efficient but it makes the API
easier. */
_ux_utility_memory_copy(transfer_request -> ux_slave_transfer_request_data_pointer,
dpump -> ux_device_class_dpump_write_buffer,
dpump -> ux_device_class_dpump_write_transfer_length); /* Use case of memcpy is verified. */

/* Next state. */
dpump -> ux_device_class_dpump_write_state = UX_DEVICE_CLASS_DPUMP_WRITE_WAIT;
UX_SLAVE_TRANSFER_STATE_RESET(transfer_request);

/* Fall through. */
case UX_DEVICE_CLASS_DPUMP_WRITE_WAIT:

/* Send the request to the device controller. */
status = _ux_device_stack_transfer_run(transfer_request,
dpump -> ux_device_class_dpump_write_transfer_length,
dpump -> ux_device_class_dpump_write_transfer_length);

/* Error case. */
if (status < UX_STATE_NEXT)
{

dpump -> ux_device_class_dpump_write_state = UX_STATE_RESET;
dpump -> ux_device_class_dpump_write_status =
transfer_request -> ux_slave_transfer_request_completion_code;
return(UX_STATE_EXIT);
}

/* Success case. */
if (status == UX_STATE_NEXT)
{

/* Next buffer address. */
dpump -> ux_device_class_dpump_write_buffer +=
transfer_request -> ux_slave_transfer_request_actual_length;

/* Set the length actually received. */
dpump -> ux_device_class_dpump_write_actual_length +=
transfer_request -> ux_slave_transfer_request_actual_length;

/* Last transfer status. */
dpump -> ux_device_class_dpump_write_status =
transfer_request -> ux_slave_transfer_request_completion_code;

/* Update actual length. */
*actual_length = dpump -> ux_device_class_dpump_write_actual_length;

/* Check ZLP case. */
if (dpump -> ux_device_class_dpump_write_requested_length == 0)
{
dpump -> ux_device_class_dpump_write_state = UX_STATE_RESET;
return(UX_STATE_NEXT);
}

/* Next state. */
dpump -> ux_device_class_dpump_write_state = UX_DEVICE_CLASS_DPUMP_WRITE_START;
}

/* Keep waiting. */
return(UX_STATE_WAIT);

default: /* Error. */
dpump -> ux_device_class_dpump_write_state = UX_STATE_RESET;
break;
}

/* Error case. */
return(UX_STATE_EXIT);
}
#endif
29 changes: 19 additions & 10 deletions common/core/src/ux_device_stack_control_request_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
/* FUNCTION RELEASE */
/* */
/* _ux_device_stack_control_request_process PORTABLE C */
/* 6.1.9 */
/* 6.1.10 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
Expand Down Expand Up @@ -84,6 +84,9 @@
/* fixed possible buffer issue */
/* for control vendor request, */
/* resulting in version 6.1.9 */
/* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
/* added printer support, */
/* resulting in version 6.1.10 */
/* */
/**************************************************************************/
UINT _ux_device_stack_control_request_process(UX_SLAVE_TRANSFER *transfer_request)
Expand Down Expand Up @@ -192,24 +195,30 @@ ULONG application_data_length;
for (class_index = 0; class_index < UX_MAX_SLAVE_INTERFACES; class_index ++)
{

/* Get the class for the interface. */
class = _ux_system_slave -> ux_system_slave_interface_class_array[class_index];

/* If class is not ready, try next. */
if (class == UX_NULL)
continue;

/* Is the request target to an interface? */
if ((request_type & UX_REQUEST_TARGET) == UX_REQUEST_TARGET_INTERFACE)
{

/* Yes, so the request index contains the index of the interface
the request is for. So if the current index does not match
the request index, we should go to the next one. */
if ((request_index & 0xFF) != class_index)
continue;
/* For printer class (0x07) GET_DEVICE_ID (0x00) the high byte of
wIndex is interface index (for recommended index sequence the interface
number is same as interface index inside configuration). */
if (((request_index & 0xFF) != class_index) ||
((class -> ux_slave_class_interface -> ux_slave_interface_descriptor.bInterfaceClass == 0x07) &&
(request == 0x00) &&
*(transfer_request -> ux_slave_transfer_request_setup + UX_SETUP_INDEX + 1) != class_index))
continue;
}

/* Get the class for the interface. */
class = _ux_system_slave -> ux_system_slave_interface_class_array[class_index];

/* If class is not ready, try next. */
if (class == UX_NULL)
continue;

/* Memorize the class in the command. */
class_command.ux_slave_class_command_class_ptr = class;

Expand Down
14 changes: 10 additions & 4 deletions common/core/src/ux_device_stack_endpoint_stall.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
/* FUNCTION RELEASE */
/* */
/* _ux_device_stack_endpoint_stall PORTABLE C */
/* 6.1 */
/* 6.1.10 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
Expand Down Expand Up @@ -70,6 +70,9 @@
/* TX symbols instead of using */
/* them directly, */
/* resulting in version 6.1 */
/* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
/* added standalone support, */
/* resulting in version 6.1.10 */
/* */
/**************************************************************************/
UINT _ux_device_stack_endpoint_stall(UX_SLAVE_ENDPOINT *endpoint)
Expand All @@ -96,14 +99,17 @@ UINT status;

/* Check if the device is in a valid state; as soon as the device is out
of the RESET state, transfers occur and thus endpoints may be stalled. */
if (_ux_system_slave -> ux_system_slave_device.ux_slave_device_state != UX_DEVICE_RESET)
if (_ux_system_slave -> ux_system_slave_device.ux_slave_device_state != UX_DEVICE_RESET &&
endpoint -> ux_slave_endpoint_state != UX_ENDPOINT_HALTED)
{

/* Stall the endpoint. */
status = dcd -> ux_slave_dcd_function(dcd, UX_DCD_STALL_ENDPOINT, endpoint);

/* Mark the endpoint state. */
endpoint -> ux_slave_endpoint_state = UX_ENDPOINT_HALTED;
if ((endpoint -> ux_slave_endpoint_descriptor.bmAttributes & UX_MASK_ENDPOINT_TYPE) !=
UX_CONTROL_ENDPOINT)
endpoint -> ux_slave_endpoint_state = UX_ENDPOINT_HALTED;
}

/* Restore interrupts. */
Expand Down
14 changes: 10 additions & 4 deletions common/core/src/ux_device_stack_initialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ UCHAR _ux_system_slave_class_cdc_ecm_name[] = "ux_
UCHAR _ux_system_slave_class_dfu_name[] = "ux_slave_class_dfu";
UCHAR _ux_system_slave_class_audio_name[] = "ux_slave_class_audio";

UCHAR _ux_system_device_class_printer_name[] = "ux_device_class_printer";

/* Define USBX Host variable. */
UX_SYSTEM_SLAVE *_ux_system_slave;

Expand All @@ -50,7 +52,7 @@ UX_SYSTEM_SLAVE *_ux_system_slave;
/* FUNCTION RELEASE */
/* */
/* _ux_device_stack_initialize PORTABLE C */
/* 6.1 */
/* 6.1.10 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
Expand Down Expand Up @@ -97,6 +99,10 @@ UX_SYSTEM_SLAVE *_ux_system_slave;
/* optimized based on compile */
/* definitions, */
/* resulting in version 6.1 */
/* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
/* added standalone support, */
/* added printer support, */
/* resulting in version 6.1.10 */
/* */
/**************************************************************************/
UINT _ux_device_stack_initialize(UCHAR * device_framework_high_speed, ULONG device_framework_length_high_speed,
Expand Down Expand Up @@ -383,7 +389,7 @@ UCHAR *memory;
}

/* Create the semaphore for the endpoint. */
status = _ux_utility_semaphore_create(&endpoints_pool -> ux_slave_endpoint_transfer_request.ux_slave_transfer_request_semaphore,
status = _ux_device_semaphore_create(&endpoints_pool -> ux_slave_endpoint_transfer_request.ux_slave_transfer_request_semaphore,
"ux_transfer_request_semaphore", 0);

/* Check completion status. */
Expand Down Expand Up @@ -417,8 +423,8 @@ UCHAR *memory;
{

/* Delete ux_slave_transfer_request_semaphore. */
if (endpoints_pool -> ux_slave_endpoint_transfer_request.ux_slave_transfer_request_semaphore.tx_semaphore_id != 0)
_ux_utility_semaphore_delete(&endpoints_pool -> ux_slave_endpoint_transfer_request.ux_slave_transfer_request_semaphore);
if (_ux_device_semaphore_created(&endpoints_pool -> ux_slave_endpoint_transfer_request.ux_slave_transfer_request_semaphore))
_ux_device_semaphore_delete(&endpoints_pool -> ux_slave_endpoint_transfer_request.ux_slave_transfer_request_semaphore);

/* Free ux_slave_transfer_request_data_pointer buffer. */
if (endpoints_pool -> ux_slave_endpoint_transfer_request.ux_slave_transfer_request_data_pointer)
Expand Down
112 changes: 112 additions & 0 deletions common/core/src/ux_device_stack_tasks_run.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/**************************************************************************/
/* */
/* Copyright (c) Microsoft Corporation. All rights reserved. */
/* */
/* This software is licensed under the Microsoft Software License */
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
/* and in the root directory of this software. */
/* */
/**************************************************************************/


/**************************************************************************/
/**************************************************************************/
/** */
/** USBX Component */
/** */
/** Device Stack */
/** */
/**************************************************************************/
/**************************************************************************/

#define UX_SOURCE_CODE


/* Include necessary system files. */

#include "ux_api.h"
#include "ux_device_stack.h"


#if defined(UX_DEVICE_STANDALONE)
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _ux_device_stack_tasks_run PORTABLE C */
/* 6.1.10 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function runs device stack and registered classes tasks. */
/* */
/* It's for standalone mode. */
/* */
/* INPUT */
/* */
/* */
/* OUTPUT */
/* */
/* UX_STATE_RESET Tasks suspended */
/* UX_STATE_IDLE Activated but no task ran */
/* (others > UX_STATE_IDLE) Tasks running */
/* */
/* CALLS */
/* */
/* (ux_slave_dcd_function) run DCD function */
/* (ux_slave_class_task_function) run Class tasks function */
/* */
/* CALLED BY */
/* */
/* Application */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */
/* 01-31-2022 Chaoqiong Xiao Initial Version 6.1.10 */
/* */
/**************************************************************************/
UINT _ux_device_stack_tasks_run(VOID)
{

UX_SLAVE_DCD *dcd;
UX_SLAVE_CLASS *class_instance;
ULONG class_index;
UINT status;


status = UX_STATE_RESET;

/* Run all DCD tasks (pending ISR handle). */
dcd = &_ux_system_slave -> ux_system_slave_dcd;
dcd -> ux_slave_dcd_function(dcd, UX_DCD_TASKS_RUN, UX_NULL);

/* Run all Class instance tasks. */
class_instance = _ux_system_slave -> ux_system_slave_class_array;
for (class_index = 0; class_index < UX_SYSTEM_DEVICE_MAX_CLASS_GET(); class_index++)
{

/* Skip classes not used. */
if (class_instance -> ux_slave_class_status == UX_UNUSED)
continue;

/* Skip classes has no task function. */
if (class_instance -> ux_slave_class_task_function == UX_NULL)
continue;

/* Invoke task function. */
status |= class_instance -> ux_slave_class_task_function(class_instance -> ux_slave_class_instance);

/* Move to the next class. */
class_instance ++;
}

/* Return overall status. */
return(status);
}
#endif
10 changes: 7 additions & 3 deletions common/core/src/ux_device_stack_transfer_abort.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
/* FUNCTION RELEASE */
/* */
/* _ux_device_stack_transfer_abort PORTABLE C */
/* 6.1 */
/* 6.1.10 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
Expand Down Expand Up @@ -76,6 +76,10 @@
/* TX symbols instead of using */
/* them directly, */
/* resulting in version 6.1 */
/* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
/* added standalone support, */
/* assigned aborting code, */
/* resulting in version 6.1.10 */
/* */
/**************************************************************************/
UINT _ux_device_stack_transfer_abort(UX_SLAVE_TRANSFER *transfer_request, ULONG completion_code)
Expand All @@ -94,7 +98,7 @@ UX_SLAVE_DCD *dcd;
dcd = &_ux_system_slave -> ux_system_slave_dcd;

/* Sets the completion code due to bus reset. */
transfer_request -> ux_slave_transfer_request_completion_code = UX_TRANSFER_BUS_RESET;
transfer_request -> ux_slave_transfer_request_completion_code = completion_code;

/* Ensure we're not preempted by the transfer completion ISR. */
UX_DISABLE
Expand All @@ -116,7 +120,7 @@ UX_SLAVE_DCD *dcd;
transfer_request -> ux_slave_transfer_request_status = UX_TRANSFER_STATUS_ABORT;

/* Wake up the device driver who is waiting on the semaphore. */
_ux_utility_semaphore_put(&transfer_request -> ux_slave_transfer_request_semaphore);
_ux_device_semaphore_put(&transfer_request -> ux_slave_transfer_request_semaphore);
}
else
{
Expand Down
21 changes: 19 additions & 2 deletions common/core/src/ux_device_stack_transfer_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
/* FUNCTION RELEASE */
/* */
/* _ux_device_stack_transfer_request PORTABLE C */
/* 6.1 */
/* 6.1.10 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
Expand Down Expand Up @@ -76,13 +76,29 @@
/* TX symbols instead of using */
/* them directly, */
/* resulting in version 6.1 */
/* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
/* added standalone support, */
/* resulting in version 6.1.10 */
/* */
/**************************************************************************/
UINT _ux_device_stack_transfer_request(UX_SLAVE_TRANSFER *transfer_request,
ULONG slave_length,
ULONG host_length)
{

#if defined(UX_DEVICE_STANDALONE)
UINT status;

/* Start a transfer request without waiting it end. */
UX_SLAVE_TRANSFER_STATE_RESET(transfer_request);
status = _ux_device_stack_transfer_run(transfer_request, slave_length, host_length);
if (status == UX_STATE_LOCK)
return(UX_BUSY);
if (status < UX_STATE_NEXT)
return(transfer_request -> ux_slave_transfer_request_completion_code);

/* Started/done, things will be done in BG */
return(UX_SUCCESS);
#else
UX_INTERRUPT_SAVE_AREA

UX_SLAVE_DCD *dcd;
Expand Down Expand Up @@ -184,5 +200,6 @@ ULONG device_state;
/* And return the status. */
return(status);

#endif
}

Loading