diff --git a/common/core/CMakeLists.txt b/common/core/CMakeLists.txt index 0e795d81..9f767540 100644 --- a/common/core/CMakeLists.txt +++ b/common/core/CMakeLists.txt @@ -10,6 +10,7 @@ target_sources(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/src/ux_dcd_sim_slave_function.c ${CMAKE_CURRENT_LIST_DIR}/src/ux_dcd_sim_slave_initialize.c ${CMAKE_CURRENT_LIST_DIR}/src/ux_dcd_sim_slave_initialize_complete.c + ${CMAKE_CURRENT_LIST_DIR}/src/ux_dcd_sim_slave_uninitialize.c ${CMAKE_CURRENT_LIST_DIR}/src/ux_dcd_sim_slave_state_change.c ${CMAKE_CURRENT_LIST_DIR}/src/ux_dcd_sim_slave_transfer_abort.c ${CMAKE_CURRENT_LIST_DIR}/src/ux_dcd_sim_slave_transfer_request.c diff --git a/common/core/inc/ux_dcd_sim_slave.h b/common/core/inc/ux_dcd_sim_slave.h index 8de3029f..626782e5 100644 --- a/common/core/inc/ux_dcd_sim_slave.h +++ b/common/core/inc/ux_dcd_sim_slave.h @@ -1,18 +1,18 @@ /*************************************************************************** - * Copyright (c) 2024 Microsoft Corporation - * + * Copyright (c) 2024 Microsoft Corporation + * * This program and the accompanying materials are made available under the * terms of the MIT License which is available at * https://opensource.org/licenses/MIT. - * + * * SPDX-License-Identifier: MIT **************************************************************************/ /**************************************************************************/ /**************************************************************************/ -/** */ -/** USBX Component */ +/** */ +/** USBX Component */ /** */ /** Slave Simulator Controller Driver */ /** */ @@ -20,26 +20,26 @@ /**************************************************************************/ -/**************************************************************************/ -/* */ -/* COMPONENT DEFINITION RELEASE */ -/* */ -/* ux_dcd_sim_slave.h PORTABLE C */ +/**************************************************************************/ +/* */ +/* COMPONENT DEFINITION RELEASE */ +/* */ +/* ux_dcd_sim_slave.h PORTABLE C */ /* 6.1.10 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ /* */ /* DESCRIPTION */ -/* */ +/* */ /* This file contains all the header and extern functions used by the */ -/* USBX slave simulator. It is designed to work ONLY with the USBX */ -/* host simulator. */ -/* */ -/* RELEASE HISTORY */ -/* */ -/* DATE NAME DESCRIPTION */ -/* */ +/* USBX slave simulator. It is designed to work ONLY with the USBX */ +/* host simulator. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ /* resulting in version 6.1 */ @@ -60,15 +60,15 @@ #ifndef UX_DCD_SIM_SLAVE_H #define UX_DCD_SIM_SLAVE_H -/* Determine if a C++ compiler is being used. If so, ensure that standard - C is used to process the API information. */ +/* Determine if a C++ compiler is being used. If so, ensure that standard + C is used to process the API information. */ -#ifdef __cplusplus +#ifdef __cplusplus -/* Yes, C++ compiler is present. Use standard C. */ -extern "C" { +/* Yes, C++ compiler is present. Use standard C. */ +extern "C" { -#endif +#endif /* Define USB slave simulator major equivalences. */ @@ -110,7 +110,7 @@ extern "C" { /* Define USB slave simulator physical endpoint structure. */ -typedef struct UX_DCD_SIM_SLAVE_ED_STRUCT +typedef struct UX_DCD_SIM_SLAVE_ED_STRUCT { ULONG ux_sim_slave_ed_status; @@ -119,7 +119,7 @@ typedef struct UX_DCD_SIM_SLAVE_ED_STRUCT ULONG ux_sim_slave_ed_ping_pong; ULONG ux_sim_slave_ed_status_register; ULONG ux_sim_slave_ed_configuration_value; - struct UX_SLAVE_ENDPOINT_STRUCT + struct UX_SLAVE_ENDPOINT_STRUCT *ux_sim_slave_ed_endpoint; } UX_DCD_SIM_SLAVE_ED; @@ -127,14 +127,14 @@ typedef struct UX_DCD_SIM_SLAVE_ED_STRUCT /* Define USB slave simulator DCD structure definition. */ typedef struct UX_DCD_SIM_SLAVE_STRUCT -{ +{ - struct UX_SLAVE_DCD_STRUCT + struct UX_SLAVE_DCD_STRUCT *ux_dcd_sim_slave_dcd_owner; - struct UX_DCD_SIM_SLAVE_ED_STRUCT + struct UX_DCD_SIM_SLAVE_ED_STRUCT ux_dcd_sim_slave_ed[UX_DCD_SIM_SLAVE_MAX_ED]; #ifdef UX_DEVICE_BIDIRECTIONAL_ENDPOINT_SUPPORT - struct UX_DCD_SIM_SLAVE_ED_STRUCT + struct UX_DCD_SIM_SLAVE_ED_STRUCT ux_dcd_sim_slave_ed_in[UX_DCD_SIM_SLAVE_MAX_ED]; #endif UINT (*ux_dcd_sim_slave_dcd_control_request_process_hub)(UX_SLAVE_TRANSFER *transfer_request); @@ -154,6 +154,7 @@ UINT _ux_dcd_sim_slave_frame_number_get(UX_DCD_SIM_SLAVE *dcd_sim_slave, ULON UINT _ux_dcd_sim_slave_function(UX_SLAVE_DCD *dcd, UINT function, VOID *parameter); UINT _ux_dcd_sim_slave_initialize(VOID); UINT _ux_dcd_sim_slave_initialize_complete(VOID); +UINT _ux_dcd_sim_slave_uninitialize(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); @@ -162,11 +163,12 @@ UINT _ux_dcd_sim_slave_transfer_abort(UX_DCD_SIM_SLAVE *dcd_sim_slave, UX_SLA /* Define Device Simulator Class API prototypes. */ #define ux_dcd_sim_slave_initialize _ux_dcd_sim_slave_initialize +#define ux_dcd_sim_slave_uninitialize _ux_dcd_sim_slave_uninitialize -/* Determine if a C++ compiler is being used. If so, complete the standard - C conditional started above. */ +/* Determine if a C++ compiler is being used. If so, complete the standard + C conditional started above. */ #ifdef __cplusplus -} +} #endif #endif diff --git a/common/core/inc/ux_hcd_sim_host.h b/common/core/inc/ux_hcd_sim_host.h index f61dbff2..5f8b1dc7 100644 --- a/common/core/inc/ux_hcd_sim_host.h +++ b/common/core/inc/ux_hcd_sim_host.h @@ -1,18 +1,18 @@ /*************************************************************************** - * Copyright (c) 2024 Microsoft Corporation - * + * Copyright (c) 2024 Microsoft Corporation + * * This program and the accompanying materials are made available under the * terms of the MIT License which is available at * https://opensource.org/licenses/MIT. - * + * * SPDX-License-Identifier: MIT **************************************************************************/ /**************************************************************************/ /**************************************************************************/ -/** */ -/** USBX Component */ +/** */ +/** USBX Component */ /** */ /** Host Simulator Controller Driver */ /** */ @@ -20,26 +20,26 @@ /**************************************************************************/ -/**************************************************************************/ -/* */ -/* COMPONENT DEFINITION RELEASE */ -/* */ -/* ux_hcd_sim_host.h PORTABLE C */ +/**************************************************************************/ +/* */ +/* COMPONENT DEFINITION RELEASE */ +/* */ +/* ux_hcd_sim_host.h PORTABLE C */ /* 6.1.10 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ /* */ /* DESCRIPTION */ -/* */ +/* */ /* This file contains all the header and extern functions used by the */ -/* USBX host simulator. It is designed to work ONLY with the USBX */ -/* device (slave) simulator. */ -/* */ -/* RELEASE HISTORY */ -/* */ -/* DATE NAME DESCRIPTION */ -/* */ +/* USBX host simulator. It is designed to work ONLY with the USBX */ +/* device (slave) simulator. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ /* added controller disable, */ @@ -66,23 +66,23 @@ #ifndef UX_HCD_SIM_HOST_H #define UX_HCD_SIM_HOST_H -/* Determine if a C++ compiler is being used. If so, ensure that standard - C is used to process the API information. */ +/* Determine if a C++ compiler is being used. If so, ensure that standard + C is used to process the API information. */ -#ifdef __cplusplus +#ifdef __cplusplus -/* Yes, C++ compiler is present. Use standard C. */ -extern "C" { +/* Yes, C++ compiler is present. Use standard C. */ +extern "C" { -#endif +#endif /* Define simulator host generic definitions. */ #define UX_HCD_SIM_HOST_CONTROLLER 99 #define UX_HCD_SIM_HOST_MAX_PAYLOAD 4096 -#define UX_HCD_SIM_HOST_FRAME_DELAY 4 -#define UX_HCD_SIM_HOST_PERIODIC_ENTRY_NB 32 +#define UX_HCD_SIM_HOST_FRAME_DELAY 4 +#define UX_HCD_SIM_HOST_PERIODIC_ENTRY_NB 32 #define UX_HCD_SIM_HOST_PERIODIC_ENTRY_MASK 0x1f #define UX_HCD_SIM_HOST_AVAILABLE_BANDWIDTH 6000 @@ -116,19 +116,19 @@ typedef struct UX_HCD_SIM_HOST_STRUCT ULONG ux_hcd_sim_host_hcor; UINT ux_hcd_sim_host_nb_root_hubs; ULONG ux_hcd_sim_host_port_status[1]; - struct UX_HCD_SIM_HOST_ED_STRUCT + struct UX_HCD_SIM_HOST_ED_STRUCT *ux_hcd_sim_host_ed_list; - struct UX_HCD_SIM_HOST_TD_STRUCT + struct UX_HCD_SIM_HOST_TD_STRUCT *ux_hcd_sim_host_td_list; - struct UX_HCD_SIM_HOST_ISO_TD_STRUCT + struct UX_HCD_SIM_HOST_ISO_TD_STRUCT *ux_hcd_sim_host_iso_td_list; - struct UX_HCD_SIM_HOST_ED_STRUCT + struct UX_HCD_SIM_HOST_ED_STRUCT *ux_hcd_sim_host_asynch_head_ed; - struct UX_HCD_SIM_HOST_ED_STRUCT + struct UX_HCD_SIM_HOST_ED_STRUCT *ux_hcd_sim_host_asynch_current_ed; - struct UX_HCD_SIM_HOST_ED_STRUCT + struct UX_HCD_SIM_HOST_ED_STRUCT *ux_hcd_sim_host_iso_head_ed; - struct UX_HCD_SIM_HOST_ED_STRUCT + struct UX_HCD_SIM_HOST_ED_STRUCT *ux_hcd_sim_host_interrupt_ed_list[32]; UINT ux_hcd_sim_host_queue_empty; UINT ux_hcd_sim_host_periodic_scheduler_active; @@ -145,19 +145,19 @@ typedef struct UX_HCD_SIM_HOST_STRUCT typedef struct UX_HCD_SIM_HOST_ED_STRUCT { - struct UX_HCD_SIM_HOST_TD_STRUCT + struct UX_HCD_SIM_HOST_TD_STRUCT *ux_sim_host_ed_tail_td; - struct UX_HCD_SIM_HOST_TD_STRUCT + struct UX_HCD_SIM_HOST_TD_STRUCT *ux_sim_host_ed_head_td; - struct UX_HCD_SIM_HOST_ED_STRUCT + struct UX_HCD_SIM_HOST_ED_STRUCT *ux_sim_host_ed_next_ed; - struct UX_HCD_SIM_HOST_ED_STRUCT + struct UX_HCD_SIM_HOST_ED_STRUCT *ux_sim_host_ed_previous_ed; ULONG ux_sim_host_ed_status; - struct UX_ENDPOINT_STRUCT + struct UX_ENDPOINT_STRUCT *ux_sim_host_ed_endpoint; - ULONG ux_sim_host_ed_toggle; - ULONG ux_sim_host_ed_frame; + ULONG ux_sim_host_ed_toggle; + ULONG ux_sim_host_ed_frame; } UX_HCD_SIM_HOST_ED; @@ -171,17 +171,17 @@ typedef struct UX_HCD_SIM_HOST_ED_STRUCT /* Define simulator host TD structure. */ typedef struct UX_HCD_SIM_HOST_TD_STRUCT -{ +{ UCHAR * ux_sim_host_td_buffer; ULONG ux_sim_host_td_length; - struct UX_HCD_SIM_HOST_TD_STRUCT + struct UX_HCD_SIM_HOST_TD_STRUCT *ux_sim_host_td_next_td; - struct UX_TRANSFER_STRUCT + struct UX_TRANSFER_STRUCT *ux_sim_host_td_transfer_request; - struct UX_HCD_SIM_HOST_TD_STRUCT + struct UX_HCD_SIM_HOST_TD_STRUCT *ux_sim_host_td_next_td_transfer_request; - struct UX_HCD_SIM_HOST_ED_STRUCT + struct UX_HCD_SIM_HOST_ED_STRUCT *ux_sim_host_td_ed; ULONG ux_sim_host_td_actual_length; ULONG ux_sim_host_td_status; @@ -192,12 +192,12 @@ typedef struct UX_HCD_SIM_HOST_TD_STRUCT /* Define simulator host TD bitmap. */ -#define UX_HCD_SIM_HOST_TD_SETUP_PHASE 0x00010000 -#define UX_HCD_SIM_HOST_TD_DATA_PHASE 0x00020000 -#define UX_HCD_SIM_HOST_TD_STATUS_PHASE 0x00040000 +#define UX_HCD_SIM_HOST_TD_SETUP_PHASE 0x00010000 +#define UX_HCD_SIM_HOST_TD_DATA_PHASE 0x00020000 +#define UX_HCD_SIM_HOST_TD_STATUS_PHASE 0x00040000 #define UX_HCD_SIM_HOST_TD_OUT 0x00000800 #define UX_HCD_SIM_HOST_TD_IN 0x00001000 -#define UX_HCD_SIM_HOST_TD_ACK_PENDING 0x00002000 +#define UX_HCD_SIM_HOST_TD_ACK_PENDING 0x00002000 #define UX_HCD_SIM_HOST_TD_TOGGLE_FROM_ED 0x80000000 @@ -208,13 +208,13 @@ typedef struct UX_HCD_SIM_HOST_ISO_TD_STRUCT UCHAR * ux_sim_host_iso_td_buffer; ULONG ux_sim_host_iso_td_length; - struct UX_HCD_SIM_HOST_ISO_TD_STRUCT + struct UX_HCD_SIM_HOST_ISO_TD_STRUCT *ux_sim_host_iso_td_next_td; - struct UX_TRANSFER_STRUCT + struct UX_TRANSFER_STRUCT *ux_sim_host_iso_td_transfer_request; - struct UX_HCD_SIM_HOST_ISO_TD_STRUCT + struct UX_HCD_SIM_HOST_ISO_TD_STRUCT *ux_sim_host_iso_td_next_td_transfer_request; - struct UX_HCD_SIM_HOST_ED_STRUCT + struct UX_HCD_SIM_HOST_ED_STRUCT *ux_sim_host_iso_td_ed; ULONG ux_sim_host_iso_td_actual_length; ULONG ux_sim_host_iso_td_status; @@ -228,7 +228,7 @@ VOID _ux_hcd_sim_host_asynch_queue_process(UX_HCD_SIM_HOST *hcd_sim_host); VOID _ux_hcd_sim_host_asynch_schedule(UX_HCD_SIM_HOST *hcd_sim_host); UINT _ux_hcd_sim_host_asynchronous_endpoint_create(UX_HCD_SIM_HOST *hcd_sim_host, UX_ENDPOINT *endpoint); UINT _ux_hcd_sim_host_asynchronous_endpoint_destroy(UX_HCD_SIM_HOST *hcd_sim_host, UX_ENDPOINT *endpoint); -UX_HCD_SIM_HOST_ED +UX_HCD_SIM_HOST_ED *_ux_hcd_sim_host_ed_obtain(UX_HCD_SIM_HOST *hcd_sim_host); VOID _ux_hcd_sim_host_ed_td_clean(UX_HCD_SIM_HOST_ED *ed); UINT _ux_hcd_sim_host_endpoint_reset(UX_HCD_SIM_HOST *hcd_sim_host, UX_ENDPOINT *endpoint); @@ -242,15 +242,15 @@ UINT _ux_hcd_sim_host_interrupt_endpoint_create(UX_HCD_SIM_HOST *hcd_sim_host VOID _ux_hcd_sim_host_iso_queue_process(UX_HCD_SIM_HOST *hcd_sim_host); VOID _ux_hcd_sim_host_iso_schedule(UX_HCD_SIM_HOST *hcd_sim_host); UINT _ux_hcd_sim_host_isochronous_endpoint_create(UX_HCD_SIM_HOST *hcd_sim_host, UX_ENDPOINT *endpoint); -UX_HCD_SIM_HOST_ISO_TD +UX_HCD_SIM_HOST_ISO_TD *_ux_hcd_sim_host_isochronous_td_obtain(UX_HCD_SIM_HOST *hcd_sim_host); -UX_HCD_SIM_HOST_ED +UX_HCD_SIM_HOST_ED *_ux_hcd_sim_host_least_traffic_list_get(UX_HCD_SIM_HOST *hcd_sim_host); UINT _ux_hcd_sim_host_periodic_endpoint_destroy(UX_HCD_SIM_HOST *hcd_sim_host, UX_ENDPOINT *endpoint); VOID _ux_hcd_sim_host_periodic_schedule(UX_HCD_SIM_HOST *hcd_sim_host); UINT _ux_hcd_sim_host_periodic_tree_create(UX_HCD_SIM_HOST *hcd_sim_host); ULONG _ux_hcd_sim_host_port_status_get(UX_HCD_SIM_HOST *hcd_sim_host, ULONG port_index); -UX_HCD_SIM_HOST_TD +UX_HCD_SIM_HOST_TD *_ux_hcd_sim_host_regular_td_obtain(UX_HCD_SIM_HOST *hcd_sim_host); UINT _ux_hcd_sim_host_request_bulk_transfer(UX_HCD_SIM_HOST *hcd_sim_host, UX_TRANSFER *transfer_request); UINT _ux_hcd_sim_host_request_control_transfer(UX_HCD_SIM_HOST *hcd_sim_host, UX_TRANSFER *transfer_request); @@ -267,10 +267,12 @@ UINT _ux_hcd_sim_host_transfer_run(UX_HCD_SIM_HOST *hcd_sim_host, UX_TRANSFER /* Define Device Simulator Class API prototypes. */ #define ux_hcd_sim_host_initialize _ux_hcd_sim_host_initialize -/* Determine if a C++ compiler is being used. If so, complete the standard - C conditional started above. */ +#define ux_hcd_sim_host_uninitialize _ux_hcd_sim_host_uninitialize + +/* Determine if a C++ compiler is being used. If so, complete the standard + C conditional started above. */ #ifdef __cplusplus -} +} #endif #endif diff --git a/common/core/src/ux_dcd_sim_slave_uninitialize.c b/common/core/src/ux_dcd_sim_slave_uninitialize.c new file mode 100644 index 00000000..0ac87213 --- /dev/null +++ b/common/core/src/ux_dcd_sim_slave_uninitialize.c @@ -0,0 +1,88 @@ +/*************************************************************************** + * Copyright (c) 2025-present Eclipse ThreadX Contributors + * + * This program and the accompanying materials are made available under the + * terms of the MIT License which is available at + * https://opensource.org/licenses/MIT. + * + * SPDX-License-Identifier: MIT + **************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** USBX Component */ +/** */ +/** Slave Simulator Controller Driver */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + +#define UX_SOURCE_CODE + + +/* Include necessary system files. */ + +#include "ux_api.h" +#include "ux_dcd_sim_slave.h" + + +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _ux_dcd_sim_slave_uninitialize PORTABLE C */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function uninitializes the USB simulation slave controller. */ +/* The controller releases its resources (memory ...). */ +/* */ +/* INPUT */ +/* */ +/* None */ +/* */ +/* OUTPUT */ +/* */ +/* Completion Status */ +/* */ +/* CALLS */ +/* */ +/* _ux_utility_memory_free Free memory block */ +/* */ +/* CALLED BY */ +/* */ +/* Application */ +/* */ +/**************************************************************************/ +UINT _ux_dcd_sim_slave_uninitialize(VOID) +{ + +UX_SLAVE_DCD *dcd; +UX_DCD_SIM_SLAVE *dcd_sim_slave; + + /* Get the pointer to the DCD. */ + dcd = &_ux_system_slave -> ux_system_slave_dcd; + + /* If already unused, treat as success. */ + if (dcd -> ux_slave_dcd_status == UX_UNUSED) + return(UX_SUCCESS); + + /* Set the state of the controller to HALTED first. */ + dcd -> ux_slave_dcd_status = UX_DCD_STATUS_HALTED; + + /* Free the simulated slave controller. */ + dcd_sim_slave = (UX_DCD_SIM_SLAVE *) dcd -> ux_slave_dcd_controller_hardware; + if (dcd_sim_slave != UX_NULL) + _ux_utility_memory_free(dcd_sim_slave); + + /* Clear DCD bindings. */ + dcd -> ux_slave_dcd_controller_hardware = UX_NULL; + dcd -> ux_slave_dcd_function = UX_NULL; + + /* Set the state of the controller to UNUSED. */ + dcd -> ux_slave_dcd_status = UX_UNUSED; + + return(UX_SUCCESS); +}