diff options
| author | Chaoqiong Xiao <[email protected]> | 2023-10-23 05:31:40 +0000 |
|---|---|---|
| committer | Chaoqiong Xiao <[email protected]> | 2023-10-23 05:31:40 +0000 |
| commit | 26585e42dccf2e1ce954d8cdb4890fac72d04864 (patch) | |
| tree | fea8480672351b161488e07c31e3d704d82ee10a /common/core/src | |
| parent | 7c928b43db68b72970b3effd5a2582eb5a6869c7 (diff) | |
Update on 23 Oct 2023. Expand to see details.v6.3.0_rel
52c60057 Update headers and readme for 6.3.0 release.
5360ad52 Host H264 frame support.
4b097e80 Add javascript to codeql detection
70278ae3 Fixed use after free issues.
5560620e Improved standalone enum transfer flow. Turn off ASIX in standalone build. Im...
39a01206 Improved host HID clients (mouse/keyboard/remote control) deactivation sequence.
be2c7fd5 Improved standalone host CDC ACM control and data instance link management (MSRC 81489,81570)
c2368eb2 Improved AC AS management and error handing.
b9c23b38 PIMA Host/device optional interrupt endpoint support and host unused semaphore removal.
34ca3af9 Removed interface link in class linked to device.
5d3c9dd0 Improved endpoints get error handling (host CDC-ECM/ACM, storage). Moved stor...
71b08ad1 Improved host audio descriptors validation
4717e3f1 Enable weekly pipeline build to avoid CodeQL expiration
ca408b54 Checked XML tag nesting depth in Pictbridge object parsing
c300a00c Limited pictbridge array element to hexa output array size.
0e644aaa Reject fake CDC-ECM data interface not located next to its control interface.
911007a9 Improved host HID usage handling.
d0576877 Enable dummy check of python for CodeQL
2761e105 Fixed some split transfer issue.
db0dbeda Added packet length validation for received nx packet.
f5007249 Fix PIMA issues on data set extraction
3ec66399 Fixing device RNDIS bugs with zero copy
1ec77d6b Fix device HID issue when adding class memory man and zero copy.
d52e55c0 Add zero copy support in device printer
a5cb883f Added zero copy support in device CDC_ECM and RNDIS
1f967ae2 Enable codeql in onebranch pipeline
de265dbc Enable zero copy for device audio and video
53aee275 Refined memory management to reduce overhead.
Diffstat (limited to 'common/core/src')
41 files changed, 1004 insertions, 670 deletions
diff --git a/common/core/src/ux_device_class_dpump_activate.c b/common/core/src/ux_device_class_dpump_activate.c index ab6963b..7c0f61e 100644 --- a/common/core/src/ux_device_class_dpump_activate.c +++ b/common/core/src/ux_device_class_dpump_activate.c @@ -34,7 +34,7 @@ /* FUNCTION RELEASE */ /* */ /* _ux_device_class_dpump_activate PORTABLE C */ -/* 6.x */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -73,10 +73,10 @@ /* fixed parameter/variable */ /* names conflict C++ keyword, */ /* resulting in version 6.1.12 */ -/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), */ +/* 10-31-2023 Chaoqiong Xiao Modified comment(s), */ /* added a new mode to manage */ /* endpoint buffer in classes, */ -/* resulting in version 6.x */ +/* resulting in version 6.3.0 */ /* */ /**************************************************************************/ UINT _ux_device_class_dpump_activate(UX_SLAVE_CLASS_COMMAND *command) diff --git a/common/core/src/ux_device_class_dpump_change.c b/common/core/src/ux_device_class_dpump_change.c index 24f52ae..ef22087 100644 --- a/common/core/src/ux_device_class_dpump_change.c +++ b/common/core/src/ux_device_class_dpump_change.c @@ -33,7 +33,7 @@ /* FUNCTION RELEASE */ /* */ /* _ux_device_class_dpump_change PORTABLE C */ -/* 6.x */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -76,10 +76,10 @@ /* fixed parameter/variable */ /* names conflict C++ keyword, */ /* resulting in version 6.1.12 */ -/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), */ +/* 10-31-2023 Chaoqiong Xiao Modified comment(s), */ /* added a new mode to manage */ /* endpoint buffer in classes, */ -/* resulting in version 6.x */ +/* resulting in version 6.3.0 */ /* */ /**************************************************************************/ UINT _ux_device_class_dpump_change(UX_SLAVE_CLASS_COMMAND *command) diff --git a/common/core/src/ux_device_class_dpump_initialize.c b/common/core/src/ux_device_class_dpump_initialize.c index 853b4f8..bcd3641 100644 --- a/common/core/src/ux_device_class_dpump_initialize.c +++ b/common/core/src/ux_device_class_dpump_initialize.c @@ -34,7 +34,7 @@ /* FUNCTION RELEASE */ /* */ /* _ux_device_class_dpump_initialize PORTABLE C */ -/* 6.x */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -70,10 +70,10 @@ /* fixed parameter/variable */ /* names conflict C++ keyword, */ /* resulting in version 6.1.12 */ -/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), */ +/* 10-31-2023 Chaoqiong Xiao Modified comment(s), */ /* added a new mode to manage */ /* endpoint buffer in classes, */ -/* resulting in version 6.x */ +/* resulting in version 6.3.0 */ /* */ /**************************************************************************/ UINT _ux_device_class_dpump_initialize(UX_SLAVE_CLASS_COMMAND *command) diff --git a/common/core/src/ux_device_class_dpump_read.c b/common/core/src/ux_device_class_dpump_read.c index c93df01..c70b4e6 100644 --- a/common/core/src/ux_device_class_dpump_read.c +++ b/common/core/src/ux_device_class_dpump_read.c @@ -34,7 +34,7 @@ /* FUNCTION RELEASE */ /* */ /* _ux_device_class_dpump_read PORTABLE C */ -/* 6.x */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -70,10 +70,10 @@ /* verified memset and memcpy */ /* cases, */ /* resulting in version 6.1 */ -/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), */ +/* 10-31-2023 Chaoqiong Xiao Modified comment(s), */ /* added a new mode to manage */ /* endpoint buffer in classes, */ -/* resulting in version 6.x */ +/* resulting in version 6.3.0 */ /* */ /**************************************************************************/ UINT _ux_device_class_dpump_read(UX_SLAVE_CLASS_DPUMP *dpump, UCHAR *buffer, diff --git a/common/core/src/ux_device_class_dpump_read_run.c b/common/core/src/ux_device_class_dpump_read_run.c index 0bd3da4..16fd2f4 100644 --- a/common/core/src/ux_device_class_dpump_read_run.c +++ b/common/core/src/ux_device_class_dpump_read_run.c @@ -39,7 +39,7 @@ /* FUNCTION RELEASE */ /* */ /* _ux_device_class_dpump_read_run PORTABLE C */ -/* 6.x */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -78,10 +78,10 @@ /* DATE NAME DESCRIPTION */ /* */ /* 01-31-2022 Chaoqiong Xiao Initial Version 6.1.10 */ -/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), */ +/* 10-31-2023 Chaoqiong Xiao Modified comment(s), */ /* added a new mode to manage */ /* endpoint buffer in classes, */ -/* resulting in version 6.x */ +/* resulting in version 6.3.0 */ /* */ /**************************************************************************/ UINT _ux_device_class_dpump_read_run(UX_SLAVE_CLASS_DPUMP *dpump, UCHAR *buffer, diff --git a/common/core/src/ux_device_class_dpump_write.c b/common/core/src/ux_device_class_dpump_write.c index 2e950aa..b739dff 100644 --- a/common/core/src/ux_device_class_dpump_write.c +++ b/common/core/src/ux_device_class_dpump_write.c @@ -34,7 +34,7 @@ /* FUNCTION RELEASE */ /* */ /* _ux_device_class_dpump_write PORTABLE C */ -/* 6.x */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -70,10 +70,10 @@ /* verified memset and memcpy */ /* cases, */ /* resulting in version 6.1 */ -/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), */ +/* 10-31-2023 Chaoqiong Xiao Modified comment(s), */ /* added a new mode to manage */ /* endpoint buffer in classes, */ -/* resulting in version 6.x */ +/* resulting in version 6.3.0 */ /* */ /**************************************************************************/ UINT _ux_device_class_dpump_write(UX_SLAVE_CLASS_DPUMP *dpump, UCHAR *buffer, diff --git a/common/core/src/ux_device_class_dpump_write_run.c b/common/core/src/ux_device_class_dpump_write_run.c index b08e49b..9a4bce1 100644 --- a/common/core/src/ux_device_class_dpump_write_run.c +++ b/common/core/src/ux_device_class_dpump_write_run.c @@ -39,7 +39,7 @@ /* FUNCTION RELEASE */ /* */ /* _ux_device_class_dpump_write_run PORTABLE C */ -/* 6.x */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -78,10 +78,10 @@ /* DATE NAME DESCRIPTION */ /* */ /* 01-31-2022 Chaoqiong Xiao Initial Version 6.1.10 */ -/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), */ +/* 10-31-2023 Chaoqiong Xiao Modified comment(s), */ /* added a new mode to manage */ /* endpoint buffer in classes, */ -/* resulting in version 6.x */ +/* resulting in version 6.3.0 */ /* */ /**************************************************************************/ UINT _ux_device_class_dpump_write_run(UX_SLAVE_CLASS_DPUMP *dpump, UCHAR *buffer, diff --git a/common/core/src/ux_device_stack_class_register.c b/common/core/src/ux_device_stack_class_register.c index ad61647..aa799d6 100644 --- a/common/core/src/ux_device_stack_class_register.c +++ b/common/core/src/ux_device_stack_class_register.c @@ -172,7 +172,7 @@ ULONG class_index; /* FUNCTION RELEASE */ /* */ /* _uxe_device_stack_class_register PORTABLE C */ -/* 6.x */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -206,7 +206,7 @@ ULONG class_index; /* */ /* DATE NAME DESCRIPTION */ /* */ -/* xx-xx-xxxx Chaoqiong Xiao Initial Version 6.x */ +/* 10-31-2023 Chaoqiong Xiao Initial Version 6.3.0 */ /* */ /**************************************************************************/ UINT _uxe_device_stack_class_register(UCHAR *class_name, diff --git a/common/core/src/ux_device_stack_class_unregister.c b/common/core/src/ux_device_stack_class_unregister.c index 8d1bde0..0e8fe58 100644 --- a/common/core/src/ux_device_stack_class_unregister.c +++ b/common/core/src/ux_device_stack_class_unregister.c @@ -156,7 +156,7 @@ ULONG class_index; /* FUNCTION RELEASE */ /* */ /* _uxe_device_stack_class_unregister PORTABLE C */ -/* 6.x */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -187,7 +187,7 @@ ULONG class_index; /* */ /* DATE NAME DESCRIPTION */ /* */ -/* xx-xx-xxxx Chaoqiong Xiao Initial Version 6.x */ +/* 10-31-2023 Chaoqiong Xiao Initial Version 6.3.0 */ /* */ /**************************************************************************/ UINT _uxe_device_stack_class_unregister(UCHAR *class_name, diff --git a/common/core/src/ux_device_stack_control_request_process.c b/common/core/src/ux_device_stack_control_request_process.c index 826097a..e8a2a98 100644 --- a/common/core/src/ux_device_stack_control_request_process.c +++ b/common/core/src/ux_device_stack_control_request_process.c @@ -33,7 +33,7 @@ /* FUNCTION RELEASE */ /* */ /* _ux_device_stack_control_request_process PORTABLE C */ -/* 6.x */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -94,10 +94,10 @@ /* 03-08-2023 Chaoqiong Xiao Modified comment(s), */ /* fixed vendor request issue, */ /* resulting in version 6.2.1 */ -/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), */ +/* 10-31-2023 Chaoqiong Xiao Modified comment(s), */ /* improved interface request */ /* process with print class, */ -/* resulting in version 6.x */ +/* resulting in version 6.3.0 */ /* */ /**************************************************************************/ UINT _ux_device_stack_control_request_process(UX_SLAVE_TRANSFER *transfer_request) diff --git a/common/core/src/ux_device_stack_descriptor_send.c b/common/core/src/ux_device_stack_descriptor_send.c index 4ce10a8..b7b5a57 100644 --- a/common/core/src/ux_device_stack_descriptor_send.c +++ b/common/core/src/ux_device_stack_descriptor_send.c @@ -41,7 +41,7 @@ /* FUNCTION RELEASE */ /* */ /* _ux_device_stack_descriptor_send PORTABLE C */ -/* 6.x */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -89,11 +89,11 @@ /* 04-25-2022 Chaoqiong Xiao Modified comment(s), */ /* internal clean up, */ /* resulting in version 6.1.11 */ -/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), */ +/* 10-31-2023 Chaoqiong Xiao Modified comment(s), */ /* moved compile option check, */ /* added support for get string*/ /* requests with zero wIndex, */ -/* resulting in version 6.x */ +/* resulting in version 6.3.0 */ /* */ /**************************************************************************/ UINT _ux_device_stack_descriptor_send(ULONG descriptor_type, ULONG request_index, ULONG host_length) diff --git a/common/core/src/ux_device_stack_initialize.c b/common/core/src/ux_device_stack_initialize.c index 5b7a9b1..d6b628e 100644 --- a/common/core/src/ux_device_stack_initialize.c +++ b/common/core/src/ux_device_stack_initialize.c @@ -54,7 +54,7 @@ UX_SYSTEM_SLAVE *_ux_system_slave; /* FUNCTION RELEASE */ /* */ /* _ux_device_stack_initialize PORTABLE C */ -/* 6.x */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -109,10 +109,10 @@ UX_SYSTEM_SLAVE *_ux_system_slave; /* added CCID support, */ /* added video support, */ /* resulting in version 6.1.11 */ -/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), */ +/* 10-31-2023 Chaoqiong Xiao Modified comment(s), */ /* added a new mode to manage */ /* endpoint buffer in classes, */ -/* resulting in version 6.x */ +/* resulting in version 6.3.0 */ /* */ /**************************************************************************/ UINT _ux_device_stack_initialize(UCHAR * device_framework_high_speed, ULONG device_framework_length_high_speed, @@ -474,7 +474,7 @@ UCHAR *memory; /* FUNCTION RELEASE */ /* */ /* _uxe_device_stack_initialize PORTABLE C */ -/* 6.x */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -505,7 +505,7 @@ UCHAR *memory; /* */ /* DATE NAME DESCRIPTION */ /* */ -/* xx-xx-xxxx Chaoqiong Xiao Initial Version 6.x */ +/* 10-31-2023 Chaoqiong Xiao Initial Version 6.3.0 */ /* */ /**************************************************************************/ UINT _uxe_device_stack_initialize(UCHAR * device_framework_high_speed, ULONG device_framework_length_high_speed, diff --git a/common/core/src/ux_device_stack_uninitialize.c b/common/core/src/ux_device_stack_uninitialize.c index 4622e38..0112878 100644 --- a/common/core/src/ux_device_stack_uninitialize.c +++ b/common/core/src/ux_device_stack_uninitialize.c @@ -33,7 +33,7 @@ /* FUNCTION RELEASE */ /* */ /* _ux_device_stack_uninitialize PORTABLE C */ -/* 6.x */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -72,10 +72,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), */ +/* 10-31-2023 Chaoqiong Xiao Modified comment(s), */ /* added a new mode to manage */ /* endpoint buffer in classes, */ -/* resulting in version 6.x */ +/* resulting in version 6.3.0 */ /* */ /**************************************************************************/ UINT _ux_device_stack_uninitialize(VOID) diff --git a/common/core/src/ux_hcd_sim_host_initialize.c b/common/core/src/ux_hcd_sim_host_initialize.c index 65a3947..cc895c0 100644 --- a/common/core/src/ux_hcd_sim_host_initialize.c +++ b/common/core/src/ux_hcd_sim_host_initialize.c @@ -12,8 +12,8 @@ /**************************************************************************/ /**************************************************************************/ -/** */ -/** USBX Component */ +/** */ +/** USBX Component */ /** */ /** Host Simulator Controller Driver */ /** */ @@ -30,43 +30,43 @@ #include "ux_dcd_sim_slave.h" -/**************************************************************************/ -/* */ -/* FUNCTION RELEASE */ -/* */ -/* _ux_hcd_sim_host_initialize PORTABLE C */ -/* 6.1.10 */ +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _ux_hcd_sim_host_initialize PORTABLE C */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ /* */ /* DESCRIPTION */ -/* */ -/* This function initializes the simulated host controller */ -/* */ -/* INPUT */ -/* */ -/* HCD Pointer to HCD */ -/* */ -/* OUTPUT */ -/* */ -/* Completion Status */ -/* */ -/* CALLS */ -/* */ -/* _ux_hcd_sim_host_periodic_tree_create Create periodic tree */ -/* _ux_utility_memory_allocate Allocate memory block */ -/* _ux_utility_semaphore_put Semaphore put */ -/* _ux_utility_timer_create Create timer */ -/* */ -/* CALLED BY */ -/* */ +/* */ +/* This function initializes the simulated host controller */ +/* */ +/* INPUT */ +/* */ +/* HCD Pointer to HCD */ +/* */ +/* OUTPUT */ +/* */ +/* Completion Status */ +/* */ +/* CALLS */ +/* */ +/* _ux_hcd_sim_host_periodic_tree_create Create periodic tree */ +/* _ux_utility_memory_allocate Allocate memory block */ +/* _ux_utility_semaphore_put Semaphore put */ +/* _ux_utility_timer_create Create timer */ +/* */ +/* CALLED BY */ +/* */ /* Host Simulator Controller Driver */ -/* */ -/* RELEASE HISTORY */ -/* */ -/* DATE NAME DESCRIPTION */ -/* */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ /* optimized based on compile */ @@ -81,6 +81,9 @@ /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */ /* added standalone support, */ /* resulting in version 6.1.10 */ +/* 10-31-2023 Yajun Xia Modified comment(s), */ +/* refined memory management, */ +/* resulting in version 6.3.0 */ /* */ /**************************************************************************/ UINT _ux_hcd_sim_host_initialize(UX_HCD *hcd) @@ -89,12 +92,12 @@ UINT _ux_hcd_sim_host_initialize(UX_HCD *hcd) UX_SLAVE_DCD *dcd; UX_DCD_SIM_SLAVE *dcd_sim_slave; UX_HCD_SIM_HOST *hcd_sim_host; -UINT status; +UINT status = UX_ERROR; /* The controller initialized here is of host simulator type. */ hcd -> ux_hcd_controller_type = UX_HCD_SIM_HOST_CONTROLLER; - + /* Allocate memory for this host simulator HCD instance. */ hcd_sim_host = _ux_utility_memory_allocate(UX_NO_ALIGN, UX_REGULAR_MEMORY, sizeof(UX_HCD_SIM_HOST)); if (hcd_sim_host == UX_NULL) @@ -119,14 +122,17 @@ UINT status; hcd -> ux_hcd_status = UX_HCD_STATUS_HALTED; /* Allocate the list of EDs. All EDs are allocated on 16 byte memory boundary. */ - hcd_sim_host -> ux_hcd_sim_host_ed_list = _ux_utility_memory_allocate(UX_ALIGN_16, UX_REGULAR_MEMORY, (ULONG)sizeof(UX_HCD_SIM_HOST_ED) * _ux_system_host -> ux_system_host_max_ed); - if (hcd_sim_host -> ux_hcd_sim_host_ed_list == UX_NULL) - status = UX_MEMORY_INSUFFICIENT; - else - status = UX_SUCCESS; + if (_ux_system_host -> ux_system_host_max_ed != 0) + { + hcd_sim_host -> ux_hcd_sim_host_ed_list = _ux_utility_memory_allocate(UX_ALIGN_16, UX_REGULAR_MEMORY, (ULONG)sizeof(UX_HCD_SIM_HOST_ED) * _ux_system_host -> ux_system_host_max_ed); + if (hcd_sim_host -> ux_hcd_sim_host_ed_list == UX_NULL) + status = UX_MEMORY_INSUFFICIENT; + else + status = UX_SUCCESS; + } /* Allocate the list of TDs. All TDs are allocated on 32 byte memory boundary. */ - if (status == UX_SUCCESS) + if ((status == UX_SUCCESS) && (_ux_system_host -> ux_system_host_max_td != 0)) { hcd_sim_host -> ux_hcd_sim_host_td_list = _ux_utility_memory_allocate(UX_ALIGN_32, UX_REGULAR_MEMORY, (ULONG)sizeof(UX_HCD_SIM_HOST_TD) * _ux_system_host -> ux_system_host_max_td); if (hcd_sim_host -> ux_hcd_sim_host_td_list == UX_NULL) @@ -134,7 +140,7 @@ UINT status; } /* Allocate the list of isochronous TDs. All TDs are allocated on 32 byte memory boundary. */ - if (status == UX_SUCCESS) + if ((status == UX_SUCCESS) && (_ux_system_host -> ux_system_host_max_iso_td != 0)) { hcd_sim_host -> ux_hcd_sim_host_iso_td_list = _ux_utility_memory_allocate(UX_ALIGN_32, UX_REGULAR_MEMORY, (ULONG)sizeof(UX_HCD_SIM_HOST_ISO_TD) * _ux_system_host -> ux_system_host_max_iso_td); if (hcd_sim_host -> ux_hcd_sim_host_iso_td_list == UX_NULL) @@ -156,7 +162,7 @@ UINT status; /* The periodic scheduler is not active. */ hcd_sim_host -> ux_hcd_sim_host_periodic_scheduler_active = 0; - + /* We start a timer that will invoke the simulator every timer tick. */ status = _ux_host_timer_create(&hcd_sim_host -> ux_hcd_sim_host_timer, "USBX Simulation Timer", _ux_hcd_sim_host_timer_function, (ULONG) (ALIGN_TYPE) hcd_sim_host, 1, 1, UX_AUTO_ACTIVATE); @@ -197,7 +203,7 @@ UINT status; } } - /* Get the number of ports on the controller. The number of ports needs to be reflected both + /* Get the number of ports on the controller. The number of ports needs to be reflected both for the generic HCD container and the local sim_host container. In the simulator, the number of ports is hardwired to 1 only. */ hcd -> ux_hcd_nb_root_hubs = 1; diff --git a/common/core/src/ux_hcd_sim_host_uninitialize.c b/common/core/src/ux_hcd_sim_host_uninitialize.c index bfd8a48..234c595 100644 --- a/common/core/src/ux_hcd_sim_host_uninitialize.c +++ b/common/core/src/ux_hcd_sim_host_uninitialize.c @@ -34,7 +34,7 @@ /* FUNCTION RELEASE */ /* */ /* _ux_hcd_sim_host_uninitialize PORTABLE C */ -/* 6.1.10 */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -70,6 +70,9 @@ /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */ /* added standalone support, */ /* resulting in version 6.1.10 */ +/* 10-31-2023 Yajun Xia Modified comment(s), */ +/* refined memory management, */ +/* resulting in version 6.3.0 */ /* */ /**************************************************************************/ UINT _ux_hcd_sim_host_uninitialize(UX_HCD_SIM_HOST *hcd_sim_host) @@ -115,9 +118,14 @@ UINT td_index; #endif /* Free TD/ED memories. */ - _ux_utility_memory_free(hcd_sim_host -> ux_hcd_sim_host_iso_td_list); - _ux_utility_memory_free(hcd_sim_host -> ux_hcd_sim_host_td_list); - _ux_utility_memory_free(hcd_sim_host -> ux_hcd_sim_host_ed_list); + if (hcd_sim_host -> ux_hcd_sim_host_iso_td_list) + _ux_utility_memory_free(hcd_sim_host -> ux_hcd_sim_host_iso_td_list); + + if (hcd_sim_host -> ux_hcd_sim_host_td_list) + _ux_utility_memory_free(hcd_sim_host -> ux_hcd_sim_host_td_list); + + if (hcd_sim_host -> ux_hcd_sim_host_ed_list) + _ux_utility_memory_free(hcd_sim_host -> ux_hcd_sim_host_ed_list); /* Free simulated host controller memory. */ _ux_utility_memory_free(hcd_sim_host); diff --git a/common/core/src/ux_host_stack_class_get.c b/common/core/src/ux_host_stack_class_get.c index 9f52c22..2654670 100644 --- a/common/core/src/ux_host_stack_class_get.c +++ b/common/core/src/ux_host_stack_class_get.c @@ -34,7 +34,7 @@ /* FUNCTION RELEASE */ /* */ /* _ux_host_stack_class_get PORTABLE C */ -/* 6.x */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -78,8 +78,8 @@ /* optimized based on compile */ /* definitions, */ /* resulting in version 6.1 */ -/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), */ -/* resulting in version 6.x */ +/* 10-31-2023 Chaoqiong Xiao Modified comment(s), */ +/* resulting in version 6.3.0 */ /* */ /**************************************************************************/ UINT _ux_host_stack_class_get(UCHAR *class_name, UX_HOST_CLASS **host_class) @@ -145,7 +145,7 @@ ULONG class_index; /* FUNCTION RELEASE */ /* */ /* _uxe_host_stack_class_get PORTABLE C */ -/* 6.x */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -175,7 +175,7 @@ ULONG class_index; /* */ /* DATE NAME DESCRIPTION */ /* */ -/* xx-xx-xxxx Chaoqiong Xiao Initial Version 6.x */ +/* 10-31-2023 Chaoqiong Xiao Initial Version 6.3.0 */ /* */ /**************************************************************************/ UINT _uxe_host_stack_class_get(UCHAR *class_name, UX_HOST_CLASS **host_class) diff --git a/common/core/src/ux_host_stack_class_instance_get.c b/common/core/src/ux_host_stack_class_instance_get.c index fbdf2a0..8a19038 100644 --- a/common/core/src/ux_host_stack_class_instance_get.c +++ b/common/core/src/ux_host_stack_class_instance_get.c @@ -119,7 +119,7 @@ VOID **current_class_instance; /* FUNCTION RELEASE */ /* */ /* _uxe_host_stack_class_instance_get PORTABLE C */ -/* 6.x */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -151,7 +151,7 @@ VOID **current_class_instance; /* */ /* DATE NAME DESCRIPTION */ /* */ -/* xx-xx-xxxx Chaoqiong Xiao Initial Version 6.x */ +/* 10-31-2023 Chaoqiong Xiao Initial Version 6.3.0 */ /* */ /**************************************************************************/ UINT _uxe_host_stack_class_instance_get(UX_HOST_CLASS *host_class, UINT class_index, VOID **class_instance) diff --git a/common/core/src/ux_host_stack_class_register.c b/common/core/src/ux_host_stack_class_register.c index fdbb034..376a0d2 100644 --- a/common/core/src/ux_host_stack_class_register.c +++ b/common/core/src/ux_host_stack_class_register.c @@ -180,7 +180,7 @@ ULONG class_index; /* FUNCTION RELEASE */ /* */ /* _uxe_host_stack_class_register PORTABLE C */ -/* 6.x */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -211,7 +211,7 @@ ULONG class_index; /* */ /* DATE NAME DESCRIPTION */ /* */ -/* xx-xx-xxxx Chaoqiong Xiao Initial Version 6.x */ +/* 10-31-2023 Chaoqiong Xiao Initial Version 6.3.0 */ /* */ /**************************************************************************/ UINT _uxe_host_stack_class_register(UCHAR *class_name, diff --git a/common/core/src/ux_host_stack_configuration_interface_get.c b/common/core/src/ux_host_stack_configuration_interface_get.c index b18444e..679cc75 100644 --- a/common/core/src/ux_host_stack_configuration_interface_get.c +++ b/common/core/src/ux_host_stack_configuration_interface_get.c @@ -193,7 +193,7 @@ UX_INTERFACE *current_interface; /* FUNCTION RELEASE */ /* */ /* _uxe_host_stack_configuration_interface_get PORTABLE C */ -/* 6.x */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -227,7 +227,7 @@ UX_INTERFACE *current_interface; /* */ /* DATE NAME DESCRIPTION */ /* */ -/* xx-xx-xxxx Chaoqiong Xiao Initial Version 6.x */ +/* 10-31-2023 Chaoqiong Xiao Initial Version 6.3.0 */ /* */ /**************************************************************************/ UINT _uxe_host_stack_configuration_interface_get(UX_CONFIGURATION *configuration, diff --git a/common/core/src/ux_host_stack_device_configuration_activate.c b/common/core/src/ux_host_stack_device_configuration_activate.c index 06b4fd8..3665d34 100644 --- a/common/core/src/ux_host_stack_device_configuration_activate.c +++ b/common/core/src/ux_host_stack_device_configuration_activate.c @@ -191,7 +191,7 @@ UINT status; /* FUNCTION RELEASE */ /* */ /* _uxe_host_stack_device_configuration_activate PORTABLE C */ -/* 6.x */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -222,7 +222,7 @@ UINT status; /* */ /* DATE NAME DESCRIPTION */ /* */ -/* xx-xx-xxxx Chaoqiong Xiao Initial Version 6.x */ +/* 10-31-2023 Chaoqiong Xiao Initial Version 6.3.0 */ /* */ /**************************************************************************/ UINT _uxe_host_stack_device_configuration_activate(UX_CONFIGURATION *configuration) diff --git a/common/core/src/ux_host_stack_device_configuration_deactivate.c b/common/core/src/ux_host_stack_device_configuration_deactivate.c index 69198bd..5d35776 100644 --- a/common/core/src/ux_host_stack_device_configuration_deactivate.c +++ b/common/core/src/ux_host_stack_device_configuration_deactivate.c @@ -200,7 +200,7 @@ UINT status; /* FUNCTION RELEASE */ /* */ /* _uxe_host_stack_device_configuration_deactivate PORTABLE C */ -/* 6.x */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -231,7 +231,7 @@ UINT status; /* */ /* DATE NAME DESCRIPTION */ /* */ -/* xx-xx-xxxx Chaoqiong Xiao Initial Version 6.x */ +/* 10-31-2023 Chaoqiong Xiao Initial Version 6.3.0 */ /* */ /**************************************************************************/ UINT _uxe_host_stack_device_configuration_deactivate(UX_DEVICE *device) diff --git a/common/core/src/ux_host_stack_device_configuration_get.c b/common/core/src/ux_host_stack_device_configuration_get.c index cb47600..5feb9f6 100644 --- a/common/core/src/ux_host_stack_device_configuration_get.c +++ b/common/core/src/ux_host_stack_device_configuration_get.c @@ -140,7 +140,7 @@ UX_CONFIGURATION *current_configuration; /* FUNCTION RELEASE */ /* */ /* _uxe_host_stack_device_configuration_get PORTABLE C */ -/* 6.x */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -173,7 +173,7 @@ UX_CONFIGURATION *current_configuration; /* */ /* DATE NAME DESCRIPTION */ /* */ -/* xx-xx-xxxx Chaoqiong Xiao Initial Version 6.x */ +/* 10-31-2023 Chaoqiong Xiao Initial Version 6.3.0 */ /* */ /**************************************************************************/ UINT _uxe_host_stack_device_configuration_get(UX_DEVICE *device, UINT configuration_index, diff --git a/common/core/src/ux_host_stack_device_get.c b/common/core/src/ux_host_stack_device_get.c index de20f99..3ddb9d7 100644 --- a/common/core/src/ux_host_stack_device_get.c +++ b/common/core/src/ux_host_stack_device_get.c @@ -155,7 +155,7 @@ ULONG current_device_index; /* FUNCTION RELEASE */ /* */ /* _uxe_host_stack_device_get PORTABLE C */ -/* 6.x */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -185,7 +185,7 @@ ULONG current_device_index; /* */ /* DATE NAME DESCRIPTION */ /* */ -/* xx-xx-xxxx Chaoqiong Xiao Initial Version 6.x */ +/* 10-31-2023 Chaoqiong Xiao Initial Version 6.3.0 */ /* */ /**************************************************************************/ UINT _uxe_host_stack_device_get(ULONG device_index, UX_DEVICE **device) diff --git a/common/core/src/ux_host_stack_device_string_get.c b/common/core/src/ux_host_stack_device_string_get.c index 2c44a31..db84f26 100644 --- a/common/core/src/ux_host_stack_device_string_get.c +++ b/common/core/src/ux_host_stack_device_string_get.c @@ -154,7 +154,7 @@ UINT status; /* FUNCTION RELEASE */ /* */ /* _uxe_host_stack_device_string_get PORTABLE C */ -/* 6.x */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -190,7 +190,7 @@ UINT status; /* */ /* DATE NAME DESCRIPTION */ /* */ -/* xx-xx-xxxx Chaoqiong Xiao Initial Version 6.x */ +/* 10-31-2023 Chaoqiong Xiao Initial Version 6.3.0 */ /* */ /**************************************************************************/ UINT _uxe_host_stack_device_string_get(UX_DEVICE *device, UCHAR *descriptor_buffer, ULONG length, ULONG language_id, ULONG string_index) diff --git a/common/core/src/ux_host_stack_endpoint_transfer_abort.c b/common/core/src/ux_host_stack_endpoint_transfer_abort.c index fdef80b..b212a8c 100644 --- a/common/core/src/ux_host_stack_endpoint_transfer_abort.c +++ b/common/core/src/ux_host_stack_endpoint_transfer_abort.c @@ -98,7 +98,7 @@ UINT status; /* FUNCTION RELEASE */ /* */ /* _uxe_host_stack_endpoint_transfer_abort PORTABLE C */ -/* 6.x */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -129,7 +129,7 @@ UINT status; /* */ /* DATE NAME DESCRIPTION */ /* */ -/* xx-xx-xxxx Chaoqiong Xiao Initial Version 6.x */ +/* 10-31-2023 Chaoqiong Xiao Initial Version 6.3.0 */ /* */ /**************************************************************************/ UINT _uxe_host_stack_endpoint_transfer_abort(UX_ENDPOINT *endpoint) diff --git a/common/core/src/ux_host_stack_hcd_register.c b/common/core/src/ux_host_stack_hcd_register.c index cd9f868..2816e00 100644 --- a/common/core/src/ux_host_stack_hcd_register.c +++ b/common/core/src/ux_host_stack_hcd_register.c @@ -163,7 +163,7 @@ ULONG hcd_index; /* FUNCTION RELEASE */ /* */ /* _uxe_host_stack_hcd_register PORTABLE C */ -/* 6.x */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -193,7 +193,7 @@ ULONG hcd_index; /* */ /* DATE NAME DESCRIPTION */ /* */ -/* xx-xx-xxxx Chaoqiong Xiao Initial Version 6.x */ +/* 10-31-2023 Chaoqiong Xiao Initial Version 6.3.0 */ /* */ /**************************************************************************/ UINT _uxe_host_stack_hcd_register(UCHAR *hcd_name, diff --git a/common/core/src/ux_host_stack_hcd_unregister.c b/common/core/src/ux_host_stack_hcd_unregister.c index 9baed92..08bb43f 100644 --- a/common/core/src/ux_host_stack_hcd_unregister.c +++ b/common/core/src/ux_host_stack_hcd_unregister.c @@ -202,7 +202,7 @@ UINT hcd_name_length = 0; /* FUNCTION RELEASE */ /* */ /* _uxe_host_stack_hcd_unregister PORTABLE C */ -/* 6.x */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -234,7 +234,7 @@ UINT hcd_name_length = 0; /* */ /* DATE NAME DESCRIPTION */ /* */ -/* xx-xx-xxxx Chaoqiong Xiao Initial Version 6.x */ +/* 10-31-2023 Chaoqiong Xiao Initial Version 6.3.0 */ /* */ /**************************************************************************/ UINT _uxe_host_stack_hcd_unregister(UCHAR *hcd_name, diff --git a/common/core/src/ux_host_stack_interface_endpoint_get.c b/common/core/src/ux_host_stack_interface_endpoint_get.c index 9bec702..bf098ad 100644 --- a/common/core/src/ux_host_stack_interface_endpoint_get.c +++ b/common/core/src/ux_host_stack_interface_endpoint_get.c @@ -142,7 +142,7 @@ UX_ENDPOINT *current_endpoint; /* FUNCTION RELEASE */ /* */ /* _uxe_host_stack_interface_endpoint_get PORTABLE C */ -/* 6.x */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -174,7 +174,7 @@ UX_ENDPOINT *current_endpoint; /* */ /* DATE NAME DESCRIPTION */ /* */ -/* xx-xx-xxxx Chaoqiong Xiao Initial Version 6.x */ +/* 10-31-2023 Chaoqiong Xiao Initial Version 6.3.0 */ /* */ /**************************************************************************/ UINT _uxe_host_stack_interface_endpoint_get(UX_INTERFACE *interface_ptr, UINT endpoint_index, UX_ENDPOINT **endpoint) diff --git a/common/core/src/ux_host_stack_interface_setting_select.c b/common/core/src/ux_host_stack_interface_setting_select.c index fd96be9..5b634ba 100644 --- a/common/core/src/ux_host_stack_interface_setting_select.c +++ b/common/core/src/ux_host_stack_interface_setting_select.c @@ -221,7 +221,7 @@ UINT status; /* FUNCTION RELEASE */ /* */ /* _uxe_host_stack_interface_setting_select PORTABLE C */ -/* 6.x */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -252,7 +252,7 @@ UINT status; /* */ /* DATE NAME DESCRIPTION */ /* */ -/* xx-xx-xxxx Chaoqiong Xiao Initial Version 6.x */ +/* 10-31-2023 Chaoqiong Xiao Initial Version 6.3.0 */ /* */ /**************************************************************************/ UINT _uxe_host_stack_interface_setting_select(UX_INTERFACE *interface_ptr) diff --git a/common/core/src/ux_host_stack_tasks_run.c b/common/core/src/ux_host_stack_tasks_run.c index 6363268..ed893aa 100644 --- a/common/core/src/ux_host_stack_tasks_run.c +++ b/common/core/src/ux_host_stack_tasks_run.c @@ -44,7 +44,7 @@ static inline VOID _ux_host_stack_pending_transfers_run(VOID); /* FUNCTION RELEASE */ /* */ /* _ux_host_stack_tasks_run PORTABLE C */ -/* 6.2.0 */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -110,6 +110,9 @@ static inline VOID _ux_host_stack_pending_transfers_run(VOID); /* fixed activation issue on */ /* no class linked interfaces, */ /* resulting in version 6.2.0 */ +/* 10-31-2023 Chaoqiong Xiao Modified comment(s), */ +/* improved enum transfer, */ +/* resulting in version 6.3.0 */ /* */ /**************************************************************************/ UINT _ux_host_stack_tasks_run(VOID) @@ -200,8 +203,8 @@ static inline VOID _ux_host_stack_enum_address_sent(UX_DEVICE *device) { /* Address (request wValue) applied to device. */ - device -> ux_device_address = - device -> ux_device_enum_trans -> ux_transfer_request_value; + device -> ux_device_address = device -> ux_device_control_endpoint. + ux_endpoint_transfer_request.ux_transfer_request_value & 0x7F; device -> ux_device_state = UX_DEVICE_ADDRESSED; /* Unlock enumeration. */ @@ -625,7 +628,7 @@ INT immediate_state = UX_TRUE; case UX_HOST_STACK_ENUM_DEVICE_ADDR_SENT: /* Transfer error check. */ - trans = device -> ux_device_enum_trans; + trans = &device -> ux_device_control_endpoint.ux_endpoint_transfer_request; if (trans -> ux_transfer_request_completion_code != UX_SUCCESS) { device -> ux_device_enum_state = UX_HOST_STACK_ENUM_RETRY; @@ -659,7 +662,7 @@ INT immediate_state = UX_TRUE; case UX_HOST_STACK_ENUM_DEVICE_DESCR_PARSE: /* Transfer error check. */ - trans = device -> ux_device_enum_trans; + trans = &device -> ux_device_control_endpoint.ux_endpoint_transfer_request; buffer = trans -> ux_transfer_request_data_pointer; if (UX_HOST_STACK_ENUM_TRANS_ERROR(trans)) { @@ -707,6 +710,7 @@ INT immediate_state = UX_TRUE; trans -> ux_transfer_request_requested_length = UX_DEVICE_DESCRIPTOR_LENGTH; /* Issue GetDescriptor(Device) again and parse it. */ + device -> ux_device_enum_trans = trans; UX_TRANSFER_STATE_RESET(trans); device -> ux_device_enum_state = UX_HOST_STACK_ENUM_TRANS_WAIT; device -> ux_device_enum_next_state = UX_HOST_STACK_ENUM_DEVICE_DESCR_PARSE; @@ -744,7 +748,7 @@ INT immediate_state = UX_TRUE; case UX_HOST_STACK_ENUM_CONFIG_DESCR_PARSE: /* Transfer error check. */ - trans = device -> ux_device_enum_trans; + trans = &device -> ux_device_control_endpoint.ux_endpoint_transfer_request; buffer = trans -> ux_transfer_request_data_pointer; if (UX_HOST_STACK_ENUM_TRANS_ERROR(trans)) { @@ -792,6 +796,7 @@ INT immediate_state = UX_TRUE; configuration -> ux_configuration_descriptor.wTotalLength; /* Start transfer again. */ + device -> ux_device_enum_trans = trans; UX_TRANSFER_STATE_RESET(device -> ux_device_enum_trans); device -> ux_device_enum_state = UX_HOST_STACK_ENUM_TRANS_WAIT; device -> ux_device_enum_next_state = UX_HOST_STACK_ENUM_CONFIG_DESCR_PARSE; @@ -866,7 +871,7 @@ INT immediate_state = UX_TRUE; continue; case UX_HOST_STACK_ENUM_CONFIG_ACTIVATE: - trans = device -> ux_device_enum_trans; + trans = &device -> ux_device_control_endpoint.ux_endpoint_transfer_request; if (UX_HOST_STACK_ENUM_TRANS_ERROR(trans)) { device -> ux_device_enum_state = UX_HOST_STACK_ENUM_RETRY; @@ -960,6 +965,7 @@ INT immediate_state = UX_TRUE; /* Transfer done - next state. */ if (status == UX_STATE_NEXT || status == UX_STATE_IDLE) { + device -> ux_device_enum_trans = UX_NULL; device -> ux_device_enum_state = device -> ux_device_enum_next_state; continue; } @@ -979,6 +985,7 @@ INT immediate_state = UX_TRUE; _ux_utility_memory_free(device -> ux_device_enum_inst.ptr); device -> ux_device_enum_inst.ptr = UX_NULL; } + device -> ux_device_enum_trans = UX_NULL; device -> ux_device_enum_state = UX_HOST_STACK_ENUM_FAIL; continue; } @@ -996,6 +1003,7 @@ INT immediate_state = UX_TRUE; _ux_utility_memory_free(device -> ux_device_enum_inst.ptr); device -> ux_device_enum_inst.ptr = UX_NULL; } + device -> ux_device_enum_trans = UX_NULL; device -> ux_device_enum_state = UX_HOST_STACK_ENUM_RETRY; continue; } diff --git a/common/core/src/ux_host_stack_transfer_request.c b/common/core/src/ux_host_stack_transfer_request.c index 876f528..71c3ae7 100644 --- a/common/core/src/ux_host_stack_transfer_request.c +++ b/common/core/src/ux_host_stack_transfer_request.c @@ -224,7 +224,7 @@ UINT status; /* FUNCTION RELEASE */ /* */ /* _uxe_host_stack_transfer_request PORTABLE C */ -/* 6.x */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -253,7 +253,7 @@ UINT status; /* */ /* DATE NAME DESCRIPTION */ /* */ -/* xx-xx-xxxx Chaoqiong Xiao Initial Version 6.x */ +/* 10-31-2023 Chaoqiong Xiao Initial Version 6.3.0 */ /* */ /**************************************************************************/ UINT _uxe_host_stack_transfer_request(UX_TRANSFER *transfer_request) diff --git a/common/core/src/ux_host_stack_transfer_request_abort.c b/common/core/src/ux_host_stack_transfer_request_abort.c index ea84afd..aee4078 100644 --- a/common/core/src/ux_host_stack_transfer_request_abort.c +++ b/common/core/src/ux_host_stack_transfer_request_abort.c @@ -153,7 +153,7 @@ ULONG completion_code; /* FUNCTION RELEASE */ /* */ /* _uxe_host_stack_transfer_request_abort PORTABLE C */ -/* 6.x */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -183,7 +183,7 @@ ULONG completion_code; /* */ /* DATE NAME DESCRIPTION */ /* */ -/* xx-xx-xxxx Chaoqiong Xiao Initial Version 6.x */ +/* 10-31-2023 Chaoqiong Xiao Initial Version 6.3.0 */ /* */ /**************************************************************************/ UINT _uxe_host_stack_transfer_request_abort(UX_TRANSFER *transfer_request) diff --git a/common/core/src/ux_host_stack_transfer_run.c b/common/core/src/ux_host_stack_transfer_run.c index c9478db..6308fc7 100644 --- a/common/core/src/ux_host_stack_transfer_run.c +++ b/common/core/src/ux_host_stack_transfer_run.c @@ -300,7 +300,7 @@ UX_TRANSFER *previous; /* FUNCTION RELEASE */ /* */ /* _uxe_host_stack_transfer_run PORTABLE C */ -/* 6.x */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -329,7 +329,7 @@ UX_TRANSFER *previous; /* */ /* DATE NAME DESCRIPTION */ /* */ -/* xx-xx-xxxx Chaoqiong Xiao Initial Version 6.x */ +/* 10-31-2023 Chaoqiong Xiao Initial Version 6.3.0 */ /* */ /**************************************************************************/ UINT _uxe_host_stack_transfer_run(UX_TRANSFER *transfer_request) diff --git a/common/core/src/ux_system_initialize.c b/common/core/src/ux_system_initialize.c index 06fc65e..a8fe4fd 100644 --- a/common/core/src/ux_system_initialize.c +++ b/common/core/src/ux_system_initialize.c @@ -12,8 +12,8 @@ /**************************************************************************/ /**************************************************************************/ -/** */ -/** USBX Component */ +/** */ +/** USBX Component */ /** */ /** System */ /** */ @@ -64,46 +64,46 @@ UCHAR _ux_system_usb_2_0_extension_descriptor_structure[] = {1,1 UCHAR _ux_system_container_id_descriptor_structure[] = {1,1,1,1,4,4,4,4}; -/**************************************************************************/ -/* */ -/* FUNCTION RELEASE */ -/* */ -/* _ux_system_initialize PORTABLE C */ -/* 6.x */ +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _ux_system_initialize PORTABLE C */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ /* */ /* DESCRIPTION */ -/* */ -/* This function initializes the various control data structures for */ -/* the USBX system. */ -/* */ -/* INPUT */ -/* */ +/* */ +/* This function initializes the various control data structures for */ +/* the USBX system. */ +/* */ +/* INPUT */ +/* */ /* regular_memory_pool_start Start of non cached memory pool */ -/* regular_memory_size Size of non cached memory pool */ +/* regular_memory_size Size of non cached memory pool */ /* cache_safe_memory_pool_start Start of cached memory pool */ -/* cache_safe_memory_size Size of cached memory pool */ -/* */ -/* OUTPUT */ -/* */ +/* cache_safe_memory_size Size of cached memory pool */ +/* */ +/* OUTPUT */ +/* */ /* None */ -/* */ -/* CALLS */ -/* */ +/* */ +/* CALLS */ +/* */ /* _ux_utility_memory_allocate Allocate memory */ -/* _ux_utility_memory_set Set memory */ +/* _ux_utility_memory_set Set memory */ /* _ux_utility_mutex_create Create mutex */ -/* */ -/* CALLED BY */ -/* */ -/* Application */ -/* */ -/* RELEASE HISTORY */ -/* */ -/* DATE NAME DESCRIPTION */ -/* */ +/* */ +/* CALLED BY */ +/* */ +/* Application */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ /* verified memset and memcpy */ @@ -115,24 +115,28 @@ UCHAR _ux_system_container_id_descriptor_structure[] = {1,1 /* 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), */ +/* 10-31-2023 Chaoqiong Xiao Modified comment(s), */ +/* refined memory management, */ /* added UX_ASSERT check for */ /* STD descriptor parse size, */ -/* resulting in version 6.x */ +/* resulting in version 6.3.0 */ /* */ /**************************************************************************/ -UINT _ux_system_initialize(VOID *regular_memory_pool_start, ULONG regular_memory_size, +UINT _ux_system_initialize(VOID *regular_memory_pool_start, ULONG regular_memory_size, VOID *cache_safe_memory_pool_start, ULONG cache_safe_memory_size) { - -UX_MEMORY_BLOCK *memory_block; ALIGN_TYPE int_memory_pool_start; VOID *regular_memory_pool_end; +VOID *cache_safe_memory_pool_end; ULONG memory_pool_offset; #if !defined(UX_STANDALONE) UINT status; #endif +ULONG pool_size; + /* Check if the regular memory pool is valid. */ + if ((regular_memory_pool_start == UX_NULL) || (regular_memory_size == 0)) + return(UX_INVALID_PARAMETER); /* Reset memory block */ _ux_utility_memory_set(regular_memory_pool_start, 0, regular_memory_size); /* Use case of memset is verified. */ @@ -150,8 +154,8 @@ UINT status; /* Add to the memory offset the size of the allocated block. */ memory_pool_offset += (ULONG)sizeof(UX_SYSTEM_HOST); - -#endif + +#endif #ifndef UX_HOST_SIDE_ONLY @@ -160,8 +164,8 @@ UINT status; /* Add to the memory offset the size of the allocated block. */ memory_pool_offset += (ULONG)sizeof(UX_SYSTEM_SLAVE); - -#endif + +#endif #ifdef UX_OTG_SUPPORT @@ -171,18 +175,36 @@ UINT status; /* Add to the memory offset the size of the allocated block. */ memory_pool_offset += (ULONG)sizeof(UX_SYSTEM_OTG); -#endif +#endif + /* Set the regular memory pool structure. */ + _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_REGULAR] = (UX_MEMORY_BYTE_POOL *) (((UCHAR *) regular_memory_pool_start) + memory_pool_offset); + + /* Add to the memory offset the size of the allocated block. */ + memory_pool_offset += (ULONG)sizeof(UX_MEMORY_BYTE_POOL); + + /* Check if the cache save memory pool is valid. */ + if ((cache_safe_memory_pool_start != UX_NULL) && (cache_safe_memory_size != 0)) + { - /* Set the cache safe memory for the dynamic pool */ - _ux_system -> ux_system_regular_memory_pool_start = (UX_MEMORY_BLOCK *) (((UCHAR *) regular_memory_pool_start) - + memory_pool_offset); + /* Set the cache safe memory pool structure. */ + _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_CACHE_SAFE] = (UX_MEMORY_BYTE_POOL *) (((UCHAR *) regular_memory_pool_start) + memory_pool_offset); + + /* Add to the memory offset the size of the allocated block. */ + memory_pool_offset += (ULONG)sizeof(UX_MEMORY_BYTE_POOL); + } + else + { + + /* Set the cache safe memory pool structure to regular pool. */ + _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_CACHE_SAFE] = _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_REGULAR]; + } /* Make sure the regular memory pool is aligned properly */ - int_memory_pool_start = (ALIGN_TYPE) _ux_system -> ux_system_regular_memory_pool_start; - int_memory_pool_start += UX_ALIGN_MIN; - int_memory_pool_start &= ~((ALIGN_TYPE)UX_ALIGN_MIN); - + int_memory_pool_start = (ALIGN_TYPE) (((UCHAR *) regular_memory_pool_start) + memory_pool_offset); + int_memory_pool_start += UX_ALIGN_MIN; + int_memory_pool_start &= ~((ALIGN_TYPE)UX_ALIGN_MIN); + /* Set the end of the regular memory pool. */ regular_memory_pool_end = (void *) (((UCHAR *) regular_memory_pool_start) + regular_memory_size); @@ -194,53 +216,48 @@ UINT status; return(UX_MEMORY_INSUFFICIENT); } - /* Now, we have a project structure allocated, save the regular memory allocation details */ - _ux_system -> ux_system_regular_memory_pool_size = (ULONG) (((ALIGN_TYPE) regular_memory_pool_end) - int_memory_pool_start); - _ux_system -> ux_system_regular_memory_pool_free = _ux_system -> ux_system_regular_memory_pool_size; - _ux_system -> ux_system_regular_memory_pool_start = (UX_MEMORY_BLOCK *) int_memory_pool_start; + /* get the regular memory pool size. */ + pool_size = (ULONG) (((ALIGN_TYPE) regular_memory_pool_end) - int_memory_pool_start); - /* Build the first free memory block */ - memory_block = _ux_system -> ux_system_regular_memory_pool_start; - memory_block -> ux_memory_block_size = _ux_system -> ux_system_regular_memory_pool_size - (ULONG)sizeof(UX_MEMORY_BLOCK); - memory_block -> ux_memory_block_status = UX_MEMORY_UNUSED; + /* Create the regular memory pool. */ + _ux_utility_memory_byte_pool_create(_ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_REGULAR], + (UX_MEMORY_BYTE_POOL *)int_memory_pool_start, + pool_size); /* Check the definition of the cache safe pool. If the application or controller do not require any cache safe memory, define the cached safe memory region as the regular memory region. */ - if (cache_safe_memory_pool_start == UX_NULL) + if ((cache_safe_memory_pool_start != UX_NULL) && (cache_safe_memory_size != 0)) { - /* Cache safe memory is the same as regular memory. */ - _ux_system -> ux_system_cache_safe_memory_pool_size = _ux_system -> ux_system_regular_memory_pool_size; - _ux_system -> ux_system_cache_safe_memory_pool_free = _ux_system -> ux_system_regular_memory_pool_free; - _ux_system -> ux_system_cache_safe_memory_pool_start = _ux_system -> ux_system_regular_memory_pool_start; - } - else - { - + /* Reset this memory block */ + _ux_utility_memory_set(cache_safe_memory_pool_start, 0, cache_safe_memory_size); /* Use case of memset is verified. */ + /* Make sure the cache safe memory pool is aligned properly */ int_memory_pool_start = (ALIGN_TYPE) cache_safe_memory_pool_start; int_memory_pool_start += UX_ALIGN_MIN; int_memory_pool_start &= ~((ALIGN_TYPE)UX_ALIGN_MIN); - - /* Save the cache safe memory allocation details */ - _ux_system -> ux_system_cache_safe_memory_pool_size = cache_safe_memory_size - UX_ALIGN_MIN; - _ux_system -> ux_system_cache_safe_memory_pool_free = _ux_system -> ux_system_cache_safe_memory_pool_size; - _ux_system -> ux_system_cache_safe_memory_pool_start = (UX_MEMORY_BLOCK *) int_memory_pool_start; - - /* Reset this memory block */ - _ux_utility_memory_set(_ux_system -> ux_system_cache_safe_memory_pool_start, 0, _ux_system -> ux_system_cache_safe_memory_pool_size); /* Use case of memset is verified. */ - - /* Build the first free memory block */ - memory_block = _ux_system -> ux_system_cache_safe_memory_pool_start; - memory_block -> ux_memory_block_size = _ux_system -> ux_system_cache_safe_memory_pool_size - (ULONG)sizeof(UX_MEMORY_BLOCK); - memory_block -> ux_memory_block_status = UX_MEMORY_UNUSED; + + cache_safe_memory_pool_end = (void *) (((UCHAR *) cache_safe_memory_pool_start) + cache_safe_memory_size); + + /* Check if we have memory available. */ + if (int_memory_pool_start >= (ALIGN_TYPE) cache_safe_memory_pool_end) + { + + /* No memory available. */ + return(UX_MEMORY_INSUFFICIENT); + } + + pool_size = (ULONG) (((ALIGN_TYPE) cache_safe_memory_pool_end) - int_memory_pool_start); + + _ux_utility_memory_byte_pool_create(_ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_CACHE_SAFE], + (UX_MEMORY_BYTE_POOL *)int_memory_pool_start, pool_size); } #ifdef UX_ENABLE_MEMORY_STATISTICS - _ux_system -> ux_system_regular_memory_pool_base = (UCHAR *) _ux_system -> ux_system_regular_memory_pool_start; - _ux_system -> ux_system_regular_memory_pool_min_free = _ux_system -> ux_system_regular_memory_pool_free; - _ux_system -> ux_system_cache_safe_memory_pool_base = (UCHAR *) _ux_system -> ux_system_cache_safe_memory_pool_start; - _ux_system -> ux_system_cache_safe_memory_pool_min_free = _ux_system -> ux_system_cache_safe_memory_pool_free; + _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_REGULAR] -> ux_byte_pool_min_free = + _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_REGULAR] -> ux_byte_pool_available; + _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_CACHE_SAFE] -> ux_byte_pool_min_free = + _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_CACHE_SAFE] -> ux_byte_pool_available; /* Other fields are kept zero. */ #endif @@ -255,10 +272,10 @@ UINT status; /* Setup the head and tail pointers. */ _ux_system -> ux_system_debug_log_head = _ux_system -> ux_system_debug_log_buffer; _ux_system -> ux_system_debug_log_tail = _ux_system -> ux_system_debug_log_buffer; - + /* Keep the size in system structure variable. */ _ux_system -> ux_system_debug_log_size = UX_DEBUG_LOG_SIZE; - + #endif #if !defined(UX_STANDALONE) @@ -278,7 +295,7 @@ UINT status; /* FUNCTION RELEASE */ /* */ /* _uxe_system_initialize PORTABLE C */ -/* 6.x */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -310,10 +327,10 @@ UINT status; /* */ /* DATE NAME DESCRIPTION */ /* */ -/* xx-xx-xxxx Chaoqiong Xiao Initial Version 6.x */ +/* 10-31-2023 Chaoqiong Xiao Initial Version 6.3.0 */ /* */ /**************************************************************************/ -UINT _uxe_system_initialize(VOID *regular_memory_pool_start, ULONG regular_memory_size, +UINT _uxe_system_initialize(VOID *regular_memory_pool_start, ULONG regular_memory_size, VOID *cache_safe_memory_pool_start, ULONG cache_safe_memory_size) { @@ -333,8 +350,8 @@ UINT _uxe_system_initialize(VOID *regular_memory_pool_start, ULONG regular_memo /* Sanity check. */ if ((regular_memory_pool_start == UX_NULL) || (regular_memory_size == 0)) return(UX_INVALID_PARAMETER); - + /* Invoke system initialization function. */ - return(_ux_system_initialize(regular_memory_pool_start, regular_memory_size, + return(_ux_system_initialize(regular_memory_pool_start, regular_memory_size, cache_safe_memory_pool_start, cache_safe_memory_size)); } diff --git a/common/core/src/ux_utility_descriptor_pack.c b/common/core/src/ux_utility_descriptor_pack.c index bc85c55..292d8de 100644 --- a/common/core/src/ux_utility_descriptor_pack.c +++ b/common/core/src/ux_utility_descriptor_pack.c @@ -33,7 +33,7 @@ /* FUNCTION RELEASE */ /* */ /* _ux_utility_descriptor_pack PORTABLE C */ -/* 6.x */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -72,9 +72,9 @@ /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ /* resulting in version 6.1 */ -/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), */ +/* 10-31-2023 Chaoqiong Xiao Modified comment(s), */ /* optimized USB descriptors, */ -/* resulting in version 6.x */ +/* resulting in version 6.3.0 */ /* */ /**************************************************************************/ VOID _ux_utility_descriptor_pack(UCHAR * descriptor, UCHAR * descriptor_structure, diff --git a/common/core/src/ux_utility_descriptor_parse.c b/common/core/src/ux_utility_descriptor_parse.c index 86bbd85..827db24 100644 --- a/common/core/src/ux_utility_descriptor_parse.c +++ b/common/core/src/ux_utility_descriptor_parse.c @@ -33,7 +33,7 @@ /* FUNCTION RELEASE */ /* */ /* _ux_utility_descriptor_parse PORTABLE C */ -/* 6.x */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -72,9 +72,9 @@ /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ /* resulting in version 6.1 */ -/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), */ +/* 10-31-2023 Chaoqiong Xiao Modified comment(s), */ /* optimized USB descriptors, */ -/* resulting in version 6.x */ +/* resulting in version 6.3.0 */ /* */ /**************************************************************************/ VOID _ux_utility_descriptor_parse(UCHAR * raw_descriptor, UCHAR * descriptor_structure, @@ -133,7 +133,7 @@ VOID _ux_utility_descriptor_parse(UCHAR * raw_descriptor, UCHAR * descriptor_st /* FUNCTION RELEASE */ /* */ /* _ux_utility_descriptor_parse_size PORTABLE C */ -/* 6.x */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -165,7 +165,7 @@ VOID _ux_utility_descriptor_parse(UCHAR * raw_descriptor, UCHAR * descriptor_st /* */ /* DATE NAME DESCRIPTION */ /* */ -/* xx-xx-xxxx Chaoqiong Xiao Initial Version 6.x */ +/* 10-31-2023 Chaoqiong Xiao Initial Version 6.3.0 */ /* */ /**************************************************************************/ ULONG _ux_utility_descriptor_parse_size(UCHAR * descriptor_structure, UINT descriptor_entries, UINT size_align_mask) diff --git a/common/core/src/ux_utility_memory_allocate.c b/common/core/src/ux_utility_memory_allocate.c index 547b03d..37a46bf 100644 --- a/common/core/src/ux_utility_memory_allocate.c +++ b/common/core/src/ux_utility_memory_allocate.c @@ -12,8 +12,8 @@ /**************************************************************************/ /**************************************************************************/ -/** */ -/** USBX Component */ +/** */ +/** USBX Component */ /** */ /** Utility */ /** */ @@ -27,45 +27,44 @@ #include "ux_api.h" - -/**************************************************************************/ -/* */ -/* FUNCTION RELEASE */ -/* */ -/* _ux_utility_memory_allocate PORTABLE C */ -/* 6.x */ +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _ux_utility_memory_allocate PORTABLE C */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ /* */ /* DESCRIPTION */ -/* */ -/* This function allocates a block of memory for the specified size */ +/* */ +/* This function allocates a block of memory for the specified size */ /* and alignment. */ -/* */ -/* INPUT */ -/* */ -/* memory_alignment Memory alignment required */ -/* memory_cache_flag Memory pool source */ -/* memory_size_requested Number of bytes required */ -/* */ -/* OUTPUT */ -/* */ -/* Pointer to block of memory */ -/* */ -/* CALLS */ -/* */ -/* _ux_utility_memory_free_block_best_get Get best fit block of memory */ -/* _ux_utility_memory_set Set block of memory */ -/* */ -/* CALLED BY */ -/* */ -/* USBX Components */ -/* */ -/* RELEASE HISTORY */ -/* */ -/* DATE NAME DESCRIPTION */ -/* */ +/* */ +/* INPUT */ +/* */ +/* memory_alignment Memory alignment required */ +/* memory_cache_flag Memory pool source */ +/* memory_size_requested Number of bytes required */ +/* */ +/* OUTPUT */ +/* */ +/* Pointer to block of memory */ +/* */ +/* CALLS */ +/* */ +/* _ux_utility_memory_free_block_best_get Get best fit block of memory */ +/* _ux_utility_memory_set Set block of memory */ +/* */ +/* CALLED BY */ +/* */ +/* USBX Components */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ /* verified memset and memcpy */ @@ -77,24 +76,54 @@ /* 04-25-2022 Chaoqiong Xiao Modified comment(s), */ /* internal clean up, */ /* resulting in version 6.1.11 */ -/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), */ +/* 10-31-2023 Chaoqiong Xiao Modified comment(s), */ +/* refined memory management, */ /* fixed issue in 64-bit env, */ -/* resulting in version 6.x */ +/* resulting in version 6.3.0 */ /* */ /**************************************************************************/ VOID *_ux_utility_memory_allocate(ULONG memory_alignment, ULONG memory_cache_flag, ULONG memory_size_requested) { +UX_MEMORY_BYTE_POOL *pool_ptr; +UCHAR *current_ptr; +UCHAR *work_ptr; +UCHAR *next_ptr; +ALIGN_TYPE *free_ptr; +UCHAR **this_block_link_ptr; +UCHAR **next_block_link_ptr; +ULONG available_bytes; -UX_MEMORY_BLOCK *memory_block; -UX_MEMORY_BLOCK *new_memory_block; -UX_MEMORY_BLOCK *leftover_memory_block; -ULONG memory_for_alignment; -ULONG memory_removed_from_pool; -ULONG leftover; -UCHAR *memory_buffer; ALIGN_TYPE int_memory_buffer; +#ifdef UX_ENABLE_MEMORY_STATISTICS +UINT index; +#endif + /* Get the pool ptr */ + if (memory_cache_flag == UX_REGULAR_MEMORY) + { + pool_ptr = _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_REGULAR]; + } + else if (memory_cache_flag == UX_CACHE_SAFE_MEMORY) + { + pool_ptr = _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_CACHE_SAFE]; + } + else + { + return(UX_NULL); + } + + /* Check if pool_ptr is NX_NULL */ + if (pool_ptr == UX_NULL) + { + return(UX_NULL); + } + + /* Check if the memory size requested is 0. */ + if (memory_size_requested == 0) + { + return(UX_NULL); + } /* Get the mutex as this is a critical section. */ _ux_system_mutex_on(&_ux_system -> ux_system_mutex); @@ -105,99 +134,58 @@ ALIGN_TYPE int_memory_buffer; if (memory_alignment == UX_SAFE_ALIGN) { - /* We will use the memory_size_requested for the alignment. + /* We will use the memory_size_requested for the alignment. But we check to see if we have a minimum or maximum alignment. */ if (memory_size_requested < UX_ALIGN_MIN) - + /* No need to bother about alignment for small packets sizes. */ memory_alignment = UX_NO_ALIGN; - - else - { - - /* Check if we are over the maximum. */ - if (memory_size_requested > UX_MAX_SCATTER_GATHER_ALIGNMENT) - - /* We are over the max alignment required. Use the maximum instead. */ - memory_alignment = UX_MAX_SCATTER_GATHER_ALIGNMENT - 1; - else - { - /* We are not over the maximum, so approximate the alignment according to the size of the memory. - Check range for alignment on 4096 bytes. */ - if (memory_size_requested >= UX_ALIGN_2048 + 1) - memory_alignment = UX_ALIGN_4096; + /* Check if we are over the maximum. */ + else if (memory_size_requested > UX_MAX_SCATTER_GATHER_ALIGNMENT) + + /* We are over the max alignment required. Use the maximum instead. */ + memory_alignment = UX_MAX_SCATTER_GATHER_ALIGNMENT - 1; + + /* We are not over the maximum, so approximate the alignment according to the size of the memory. + Check range for alignment on 4096 bytes. */ + else if (memory_size_requested >= UX_ALIGN_2048 + 1) + memory_alignment = UX_ALIGN_4096; + + /* Check range for alignment on 2048 bytes. */ + else if (memory_size_requested >= UX_ALIGN_1024 + 1) + memory_alignment = UX_ALIGN_2048; + + /* Check range for alignment on 1024 bytes. */ + else if (memory_size_requested >= UX_ALIGN_512 + 1) + memory_alignment = UX_ALIGN_1024; + + /* Check range for alignment on 512 bytes. */ + else if (memory_size_requested >= UX_ALIGN_256 + 1) + memory_alignment = UX_ALIGN_512; - else - { + /* Check range for alignment on 256 bytes. */ + else if (memory_size_requested >= UX_ALIGN_128 + 1) + memory_alignment = UX_ALIGN_256; - /* Check range for alignment on 2048 bytes. */ - if (memory_size_requested >= UX_ALIGN_1024 + 1) - memory_alignment = UX_ALIGN_2048; - - else - { + /* Check range for alignment on 128 bytes. */ + else if (memory_size_requested >= UX_ALIGN_64 + 1) + memory_alignment = UX_ALIGN_128; - /* Check range for alignment on 1024 bytes. */ - if (memory_size_requested >= UX_ALIGN_512 + 1) - memory_alignment = UX_ALIGN_1024; - - else - { + /* Check range for alignment on 64 bytes. */ + else if (memory_size_requested >= UX_ALIGN_32 + 1) + memory_alignment = UX_ALIGN_64; - /* Check range for alignment on 512 bytes. */ - if (memory_size_requested >= UX_ALIGN_256 + 1) - memory_alignment = UX_ALIGN_512; - - else - { + /* Check range for alignment on 32 bytes. */ + else if (memory_size_requested >= UX_ALIGN_16 + 1) + memory_alignment = UX_ALIGN_32; - /* Check range for alignment on 256 bytes. */ - if (memory_size_requested >= UX_ALIGN_128 + 1) - memory_alignment = UX_ALIGN_256; - - else - { - - /* Check range for alignment on 128 bytes. */ - if (memory_size_requested >= UX_ALIGN_64 + 1) - memory_alignment = UX_ALIGN_128; - - else - { - - /* Check range for alignment on 128 bytes. */ - if (memory_size_requested >= UX_ALIGN_64 + 1) - memory_alignment = UX_ALIGN_128; - - else - { - - /* Check range for alignment on 64 bytes. */ - if (memory_size_requested >= UX_ALIGN_32 + 1) - memory_alignment = UX_ALIGN_64; - - else - { - - /* Check range for alignment on 32 bytes. */ - if (memory_size_requested >= UX_ALIGN_16 + 1) - memory_alignment = UX_ALIGN_32; - - else - memory_alignment = UX_ALIGN_MIN; - + /* Check range for alignment on 16 bytes. */ + else if (memory_size_requested >= UX_ALIGN_8 + 1) + memory_alignment = UX_ALIGN_16; - } - } - } - } - } - } - } - } - } - } + else + memory_alignment = UX_ALIGN_MIN; } #else @@ -205,204 +193,161 @@ ALIGN_TYPE int_memory_buffer; /* Check if safe alignment requested, in this case switch to UX_NO_ALIGN. */ if (memory_alignment == UX_SAFE_ALIGN) memory_alignment = UX_NO_ALIGN; - + #endif /* Ensure the alignment meats the minimum. */ if (memory_alignment < UX_ALIGN_MIN) memory_alignment = UX_ALIGN_MIN; - /* Adjust the memory alignment since our macros are one minus the desired alignment. - Also determine the amount of extra memory we need for the alignment, which is one - minus the actual alignment. */ - memory_for_alignment = memory_alignment; - memory_alignment++; + /* We need to make sure that the next memory block buffer is 8-byte aligned too. We + do this by first adjusting the requested memory to be 8-byte aligned. One problem + now is that the memory block might not be a size that is a multiple of 8, so we need + to add the amount of memory required such that the memory buffer after the block has + the correct alignment. For example, if the memory block has a size of 12, then we need + to make sure it is placed on an 8-byte alignment that is after a 8-byte alignment so + that the memory right after the memory block is 8-byte aligned (16). */ + memory_size_requested = (memory_size_requested + UX_ALIGN_MIN) & (~(ULONG)UX_ALIGN_MIN); + memory_size_requested += (((ULONG)(UX_MEMORY_BLOCK_HEADER_SIZE + UX_ALIGN_MIN) & (~(ULONG)UX_ALIGN_MIN)) - (ULONG)UX_MEMORY_BLOCK_HEADER_SIZE); - /* We need to make sure that the next memory block buffer is 16-byte aligned too. We - do this by first adjusting the requested memory to be 16-byte aligned. One problem - now is that the memory block might not be a size that is a multiple of 16, so we need - to add the amount of memory required such that the memory buffer after the block has - the correct alignment. For example, if the memory block has a size of 24, then we need - to make sure it is placed on an 8-byte alignment that is after a 16-byte alignment so - that the memory right after the memory block is 16-byte aligned (8 + 24 = 32). */ - memory_size_requested = (memory_size_requested + UX_ALIGN_MIN) & (~(ULONG)UX_ALIGN_MIN); - memory_size_requested += (((ULONG)sizeof(UX_MEMORY_BLOCK) + UX_ALIGN_MIN) & (~(ULONG)UX_ALIGN_MIN)) - (ULONG)sizeof(UX_MEMORY_BLOCK); - - /* Try to find the best block for this memory by requesting the maximum amount of - memory we'll need which is calculated as follows: the amount memory requested by - the caller plus the maximum amount of memory wasted due to alignment plus 2 memory - blocks structs - one for the new memory block we'll create for the user block and one - that we might create if there is extra memory after doing the alignment. */ - memory_block = _ux_utility_memory_free_block_best_get(memory_cache_flag, memory_size_requested + memory_for_alignment + (ULONG)sizeof(UX_MEMORY_BLOCK)); + if (memory_alignment <= UX_ALIGN_MIN) + current_ptr = _ux_utility_memory_byte_pool_search(pool_ptr, memory_size_requested); + else + current_ptr = _ux_utility_memory_byte_pool_search(pool_ptr, memory_size_requested + memory_alignment); - /* If the block returned is NULL, there is no free memory in the pool - for that size. */ - if (memory_block == UX_NULL) + /* Check if we found a memory block. */ + if (current_ptr == UX_NULL) { - /* Release the protection. */ + /* We could not find a memory block. */ _ux_system_mutex_off(&_ux_system -> ux_system_mutex); - /* If trace is enabled, insert this event into the trace buffer. */ UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_MEMORY_INSUFFICIENT, memory_size_requested, 0, 0, UX_TRACE_ERRORS, 0, 0) /* Error trap. */ _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_UTILITY, UX_MEMORY_INSUFFICIENT); - /* Return NULL to indicate no block was found. */ return(UX_NULL); } + /* Pickup the next block's pointer. */ + this_block_link_ptr = UX_UCHAR_TO_INDIRECT_UCHAR_POINTER_CONVERT(current_ptr); + next_ptr = *this_block_link_ptr; + + /* Calculate the number of bytes available in this block. */ + available_bytes = UX_UCHAR_POINTER_DIF(next_ptr, current_ptr); + available_bytes = available_bytes - UX_MEMORY_BLOCK_HEADER_SIZE; + /* Get the memory buffer for this block. */ - int_memory_buffer = (ALIGN_TYPE) ((UCHAR *) memory_block + sizeof(UX_MEMORY_BLOCK)); + int_memory_buffer = (ALIGN_TYPE) (UX_UCHAR_POINTER_ADD(current_ptr, UX_MEMORY_BLOCK_HEADER_SIZE)); - /* Are we already aligned? */ - if ((int_memory_buffer & (memory_alignment - 1)) == 0) + /* In case we are not aligned */ + if ((int_memory_buffer & memory_alignment) != 0) { - /* Setup the new memory block. */ - new_memory_block = (UX_MEMORY_BLOCK *) ((UCHAR *) memory_block + sizeof(UX_MEMORY_BLOCK) + memory_size_requested); - new_memory_block -> ux_memory_block_next = memory_block -> ux_memory_block_next; - new_memory_block -> ux_memory_block_previous = memory_block; - new_memory_block -> ux_memory_block_size = memory_block -> ux_memory_block_size - memory_size_requested - (ULONG)sizeof(UX_MEMORY_BLOCK); - new_memory_block -> ux_memory_block_status = UX_MEMORY_UNUSED; + /* No, we need to align the memory buffer. */ + int_memory_buffer += (ALIGN_TYPE)UX_MEMORY_BLOCK_HEADER_SIZE; + int_memory_buffer += memory_alignment; + int_memory_buffer &= ~((ALIGN_TYPE) memory_alignment); + int_memory_buffer -= (ALIGN_TYPE)UX_MEMORY_BLOCK_HEADER_SIZE; - /* Update the current memory block. */ - memory_block -> ux_memory_block_size = memory_size_requested; - memory_block -> ux_memory_block_next = new_memory_block; - memory_block -> ux_memory_block_status = UX_MEMORY_USED | memory_cache_flag; + /* Setup the new free block. */ + next_ptr = (UCHAR *)int_memory_buffer; - /* Declare how much memory we removed from the pool. */ - memory_removed_from_pool = memory_block -> ux_memory_block_size + (ULONG)sizeof(UX_MEMORY_BLOCK); - } - else - { + /* Setup the new free block. */ + next_block_link_ptr = UX_UCHAR_TO_INDIRECT_UCHAR_POINTER_CONVERT(next_ptr); + *next_block_link_ptr = *this_block_link_ptr; + work_ptr = UX_UCHAR_POINTER_ADD(next_ptr, (sizeof(UCHAR *))); + free_ptr = UX_UCHAR_TO_ALIGN_TYPE_POINTER_CONVERT(work_ptr); + *free_ptr = UX_BYTE_BLOCK_FREE; - /* Align the buffer. The first thing we do is increment by the size of a - memory block because we have to make sure we have enough memory for at - least that. */ - int_memory_buffer += (ULONG)sizeof(UX_MEMORY_BLOCK); - int_memory_buffer += memory_alignment - 1; - int_memory_buffer &= ~(((ALIGN_TYPE) memory_alignment) - 1); + /* Increase the total fragment counter. */ + pool_ptr -> ux_byte_pool_fragments++; - /* Setup the new memory block. Note that its size is updated again later. */ - new_memory_block = (UX_MEMORY_BLOCK *) (int_memory_buffer - (ULONG)sizeof(UX_MEMORY_BLOCK)); - new_memory_block -> ux_memory_block_previous = memory_block; - new_memory_block -> ux_memory_block_next = memory_block -> ux_memory_block_next; - new_memory_block -> ux_memory_block_size = memory_block -> ux_memory_block_size; - new_memory_block -> ux_memory_block_status = UX_MEMORY_USED | memory_cache_flag; + /* Update the current pointer to point at the newly created block. */ + *this_block_link_ptr = next_ptr; - /* Update the current memory block. */ - int_memory_buffer = (ALIGN_TYPE) ((UCHAR *) memory_block + sizeof(UX_MEMORY_BLOCK)); - memory_block -> ux_memory_block_next = new_memory_block; - memory_block -> ux_memory_block_size = (ULONG) ((ALIGN_TYPE) new_memory_block - int_memory_buffer); + /* Calculate the available bytes. */ + available_bytes -= UX_UCHAR_POINTER_DIF(next_ptr, current_ptr); - /* Update the new memory block's size. */ - new_memory_block -> ux_memory_block_size -= (memory_block -> ux_memory_block_size + (ULONG)sizeof(UX_MEMORY_BLOCK)); + /* Set Current pointer to the aligned memory buffer. */ + current_ptr = next_ptr; + } - /* Calculate how much memory is leftover in the new memory block after doing - the alignment. */ - leftover = new_memory_block -> ux_memory_block_size - memory_size_requested; + /* Now we are aligned, determine if we need to split this block. */ + if ((available_bytes - memory_size_requested) >= ((ULONG) UX_BYTE_BLOCK_MIN)) + { - /* Can we fit another block after the new block? */ - if (leftover > sizeof(UX_MEMORY_BLOCK)) - { + /* Split the block. */ + next_ptr = UX_UCHAR_POINTER_ADD(current_ptr, (memory_size_requested + UX_MEMORY_BLOCK_HEADER_SIZE)); - /* Setup the leftover memory block. */ - leftover_memory_block = (UX_MEMORY_BLOCK *) (((ALIGN_TYPE) new_memory_block + sizeof(UX_MEMORY_BLOCK) + memory_size_requested)); - leftover_memory_block -> ux_memory_block_next = new_memory_block -> ux_memory_block_next; - leftover_memory_block -> ux_memory_block_previous = new_memory_block; - leftover_memory_block -> ux_memory_block_size = leftover - (ULONG)sizeof(UX_MEMORY_BLOCK); - leftover_memory_block -> ux_memory_block_status = UX_MEMORY_UNUSED; + /* Setup the new free block. */ + next_block_link_ptr = UX_UCHAR_TO_INDIRECT_UCHAR_POINTER_CONVERT(next_ptr); + this_block_link_ptr = UX_UCHAR_TO_INDIRECT_UCHAR_POINTER_CONVERT(current_ptr); + *next_block_link_ptr = *this_block_link_ptr; + work_ptr = UX_UCHAR_POINTER_ADD(next_ptr, (sizeof(UCHAR *))); + free_ptr = UX_UCHAR_TO_ALIGN_TYPE_POINTER_CONVERT(work_ptr); + *free_ptr = UX_BYTE_BLOCK_FREE; - new_memory_block -> ux_memory_block_next = leftover_memory_block; - new_memory_block -> ux_memory_block_size -= leftover; - } + /* Increase the total fragment counter. */ + pool_ptr -> ux_byte_pool_fragments++; - /* Declare how much memory we removed from the pool. */ - memory_removed_from_pool = new_memory_block -> ux_memory_block_size + (ULONG)sizeof(UX_MEMORY_BLOCK); + /* Update the current pointer to point at the newly created block. */ + *this_block_link_ptr = next_ptr; - /* The new memory block is the one we give to the user. */ - memory_block = new_memory_block; + /* Set available equal to memory size for subsequent calculation. */ + available_bytes = memory_size_requested; } - /* The memory to be returned is after the block header. */ - memory_buffer = ((UCHAR *) memory_block) + sizeof(UX_MEMORY_BLOCK); + /* In any case, mark the current block as allocated. */ + work_ptr = UX_UCHAR_POINTER_ADD(current_ptr, (sizeof(UCHAR *))); + this_block_link_ptr = UX_UCHAR_TO_INDIRECT_UCHAR_POINTER_CONVERT(work_ptr); + *this_block_link_ptr = UX_BYTE_POOL_TO_UCHAR_POINTER_CONVERT(pool_ptr); - /* Clear the memory block. */ - _ux_utility_memory_set(memory_buffer, 0, memory_size_requested); /* Use case of memset is verified. */ + /* Reduce the number of available bytes in the pool. */ + pool_ptr -> ux_byte_pool_available = pool_ptr -> ux_byte_pool_available - (available_bytes + UX_MEMORY_BLOCK_HEADER_SIZE); - /* Update the memory free in the pool. */ - if (_ux_system -> ux_system_cache_safe_memory_pool_start == _ux_system -> ux_system_regular_memory_pool_start) + /* Determine if the search pointer needs to be updated. This is only done + if the search pointer matches the block to be returned. */ + if (current_ptr == pool_ptr -> ux_byte_pool_search) { - /* There is only one memory pool. */ - _ux_system -> ux_system_regular_memory_pool_free -= memory_removed_from_pool; + /* Yes, update the search pointer to the next block. */ + this_block_link_ptr = UX_UCHAR_TO_INDIRECT_UCHAR_POINTER_CONVERT(current_ptr); + pool_ptr -> ux_byte_pool_search = *this_block_link_ptr; } - else - { - - switch (memory_cache_flag) - { - - case UX_CACHE_SAFE_MEMORY: - /* Update the amount of free memory in the cache safe memory pool. */ - _ux_system -> ux_system_cache_safe_memory_pool_free -= memory_removed_from_pool; - - break; - default: - /* Update the amount of free memory in the regular memory pool. */ - _ux_system -> ux_system_regular_memory_pool_free -= memory_removed_from_pool; - break; + /* Adjust the pointer for the application. */ + work_ptr = UX_UCHAR_POINTER_ADD(current_ptr, UX_MEMORY_BLOCK_HEADER_SIZE); - } - } + /* Clear the memory block. */ + _ux_utility_memory_set(work_ptr, 0, available_bytes); /* Use case of memset is verified. */ #ifdef UX_ENABLE_MEMORY_STATISTICS /* Update allocate count, total size. */ if (memory_cache_flag == UX_REGULAR_MEMORY) - { - _ux_system -> ux_system_regular_memory_pool_alloc_count ++; - _ux_system -> ux_system_regular_memory_pool_alloc_total += memory_size_requested; - if (_ux_system -> ux_system_regular_memory_pool_alloc_max_count < _ux_system -> ux_system_regular_memory_pool_alloc_count) - _ux_system -> ux_system_regular_memory_pool_alloc_max_count = _ux_system -> ux_system_regular_memory_pool_alloc_count; - if (_ux_system -> ux_system_regular_memory_pool_alloc_max_total < _ux_system -> ux_system_regular_memory_pool_alloc_total) - _ux_system -> ux_system_regular_memory_pool_alloc_max_total = _ux_system -> ux_system_regular_memory_pool_alloc_total; - } + index = UX_MEMORY_BYTE_POOL_REGULAR; else - { - _ux_system -> ux_system_cache_safe_memory_pool_alloc_count ++; - _ux_system -> ux_system_cache_safe_memory_pool_alloc_total += memory_size_requested; - if (_ux_system -> ux_system_cache_safe_memory_pool_alloc_max_count < _ux_system -> ux_system_cache_safe_memory_pool_alloc_count) - _ux_system -> ux_system_cache_safe_memory_pool_alloc_max_count = _ux_system -> ux_system_cache_safe_memory_pool_alloc_count; - if (_ux_system -> ux_system_cache_safe_memory_pool_alloc_max_total < _ux_system -> ux_system_cache_safe_memory_pool_alloc_total) - _ux_system -> ux_system_cache_safe_memory_pool_alloc_max_total = _ux_system -> ux_system_cache_safe_memory_pool_alloc_total; - } + index = UX_MEMORY_BYTE_POOL_CACHE_SAFE; + + /* Update allocate count, total size. */ + _ux_system -> ux_system_memory_byte_pool[index] -> ux_byte_pool_alloc_count ++; + _ux_system -> ux_system_memory_byte_pool[index] -> ux_byte_pool_alloc_total += (available_bytes + UX_MEMORY_BLOCK_HEADER_SIZE); - /* Log max usage of regular memory pool. */ - memory_removed_from_pool = (ALIGN_TYPE)_ux_system -> ux_system_regular_memory_pool_start - - (ALIGN_TYPE)_ux_system -> ux_system_regular_memory_pool_base; - if (memory_removed_from_pool > _ux_system -> ux_system_regular_memory_pool_max_start_offset) - _ux_system -> ux_system_regular_memory_pool_max_start_offset = memory_removed_from_pool; - if (_ux_system -> ux_system_regular_memory_pool_min_free > _ux_system -> ux_system_regular_memory_pool_free) - _ux_system -> ux_system_regular_memory_pool_min_free = _ux_system -> ux_system_regular_memory_pool_free; + if (_ux_system -> ux_system_memory_byte_pool[index] -> ux_byte_pool_alloc_max_count < _ux_system -> ux_system_memory_byte_pool[index] -> ux_byte_pool_alloc_count) + _ux_system -> ux_system_memory_byte_pool[index] -> ux_byte_pool_alloc_max_count = _ux_system -> ux_system_memory_byte_pool[index] -> ux_byte_pool_alloc_count; - /* Log max usage of cache safe memory pool. */ - memory_removed_from_pool = (ALIGN_TYPE)_ux_system -> ux_system_cache_safe_memory_pool_start - - (ALIGN_TYPE)_ux_system -> ux_system_cache_safe_memory_pool_base; - if (memory_removed_from_pool > _ux_system -> ux_system_cache_safe_memory_pool_max_start_offset) - _ux_system -> ux_system_cache_safe_memory_pool_max_start_offset = memory_removed_from_pool; - if (_ux_system -> ux_system_cache_safe_memory_pool_min_free > _ux_system -> ux_system_cache_safe_memory_pool_free) - _ux_system -> ux_system_cache_safe_memory_pool_min_free = _ux_system -> ux_system_cache_safe_memory_pool_free; + if (_ux_system -> ux_system_memory_byte_pool[index] -> ux_byte_pool_alloc_max_total < _ux_system -> ux_system_memory_byte_pool[index] -> ux_byte_pool_alloc_total) + _ux_system -> ux_system_memory_byte_pool[index] -> ux_byte_pool_alloc_max_total = _ux_system -> ux_system_memory_byte_pool[index] -> ux_byte_pool_alloc_total; + /* Log max usage of memory pool. */ + if (_ux_system -> ux_system_memory_byte_pool[index] -> ux_byte_pool_min_free > _ux_system -> ux_system_memory_byte_pool[index] -> ux_byte_pool_available) + _ux_system -> ux_system_memory_byte_pool[index] -> ux_byte_pool_min_free = _ux_system -> ux_system_memory_byte_pool[index] -> ux_byte_pool_available; #endif /* Release the protection. */ _ux_system_mutex_off(&_ux_system -> ux_system_mutex); - /* The memory block pointer contains a memory area properly - aligned. */ - return(memory_buffer); -} + return(work_ptr); +} diff --git a/common/core/src/ux_utility_memory_byte_pool_create.c b/common/core/src/ux_utility_memory_byte_pool_create.c new file mode 100644 index 0000000..2d36225 --- /dev/null +++ b/common/core/src/ux_utility_memory_byte_pool_create.c @@ -0,0 +1,130 @@ +/**************************************************************************/ +/* */ +/* 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 */ +/** */ +/** USBX main stack */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/* Include necessary system files. */ + +#define UX_SOURCE_CODE + +#include "ux_api.h" + + +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _ux_utility_memory_byte_pool_create PORTABLE C */ +/* 6.3.0 */ +/* AUTHOR */ +/* */ +/* Yajun Xia, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function creates a pool of memory bytes in the specified */ +/* memory area. */ +/* */ +/* INPUT */ +/* */ +/* pool_ptr Pointer to pool control block */ +/* pool_start Address of beginning of pool area */ +/* pool_size Number of bytes in the byte pool */ +/* */ +/* OUTPUT */ +/* */ +/* UX_SUCCESS Successful completion status */ +/* */ +/* CALLS */ +/* */ +/* None */ +/* */ +/* CALLED BY */ +/* */ +/* USBX Components */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 10-31-2023 Yajun Xia Initial Version 6.3.0 */ +/* */ +/**************************************************************************/ +UINT _ux_utility_memory_byte_pool_create(UX_MEMORY_BYTE_POOL *pool_ptr, VOID *pool_start, ULONG pool_size) +{ + +UCHAR *block_ptr; +UCHAR **block_indirect_ptr; +UCHAR *temp_ptr; +ALIGN_TYPE *free_ptr; + + + /* Initialize the byte pool control block to all zeros. */ + _ux_utility_memory_set((UCHAR *)pool_ptr, 0, sizeof(UX_MEMORY_BYTE_POOL)); /* Use case of memset is verified. */ + + /* Round the pool size down to something that is evenly divisible by + an ULONG. */ + pool_size = (pool_size/(sizeof(ALIGN_TYPE))) * (sizeof(ALIGN_TYPE)); + + /* Save the start and size of the pool. */ + pool_ptr -> ux_byte_pool_start = UX_VOID_TO_UCHAR_POINTER_CONVERT(pool_start); + pool_ptr -> ux_byte_pool_size = pool_size; + pool_ptr -> ux_byte_pool_search = UX_VOID_TO_UCHAR_POINTER_CONVERT(pool_start); + + /* Initially, the pool will have two blocks. One large block at the + beginning that is available and a small allocated block at the end + of the pool that is there just for the algorithm. Be sure to count + the available block's header in the available bytes count. */ + pool_ptr -> ux_byte_pool_available = pool_size - ((sizeof(VOID *)) + (sizeof(ALIGN_TYPE))); + pool_ptr -> ux_byte_pool_fragments = ((UINT) 2); + + /* Each block contains a "next" pointer that points to the next block in the pool followed by a ALIGN_TYPE + field that contains either the constant UX_BYTE_BLOCK_FREE (if the block is free) or a pointer to the + owning pool (if the block is allocated). */ + + /* Calculate the end of the pool's memory area. */ + block_ptr = UX_VOID_TO_UCHAR_POINTER_CONVERT(pool_start); + block_ptr = UX_UCHAR_POINTER_ADD(block_ptr, pool_size); + + /* Backup the end of the pool pointer and build the pre-allocated block. */ + block_ptr = UX_UCHAR_POINTER_SUB(block_ptr, (sizeof(ALIGN_TYPE))); + + /* Cast the pool pointer into a ULONG. */ + temp_ptr = UX_BYTE_POOL_TO_UCHAR_POINTER_CONVERT(pool_ptr); + block_indirect_ptr = UX_UCHAR_TO_INDIRECT_UCHAR_POINTER_CONVERT(block_ptr); + *block_indirect_ptr = temp_ptr; + + block_ptr = UX_UCHAR_POINTER_SUB(block_ptr, (sizeof(UCHAR *))); + block_indirect_ptr = UX_UCHAR_TO_INDIRECT_UCHAR_POINTER_CONVERT(block_ptr); + *block_indirect_ptr = UX_VOID_TO_UCHAR_POINTER_CONVERT(pool_start); + + /* Now setup the large available block in the pool. */ + temp_ptr = UX_VOID_TO_UCHAR_POINTER_CONVERT(pool_start); + block_indirect_ptr = UX_UCHAR_TO_INDIRECT_UCHAR_POINTER_CONVERT(temp_ptr); + *block_indirect_ptr = block_ptr; + block_ptr = UX_VOID_TO_UCHAR_POINTER_CONVERT(pool_start); + block_ptr = UX_UCHAR_POINTER_ADD(block_ptr, (sizeof(UCHAR *))); + free_ptr = UX_UCHAR_TO_ALIGN_TYPE_POINTER_CONVERT(block_ptr); + *free_ptr = UX_BYTE_BLOCK_FREE; + + /* Return UX_SUCCESS. */ + return(UX_SUCCESS); +} diff --git a/common/core/src/ux_utility_memory_byte_pool_search.c b/common/core/src/ux_utility_memory_byte_pool_search.c new file mode 100644 index 0000000..b688d01 --- /dev/null +++ b/common/core/src/ux_utility_memory_byte_pool_search.c @@ -0,0 +1,215 @@ +/**************************************************************************/ +/* */ +/* 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 */ +/** */ +/** USBX main stack */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/* Include necessary system files. */ + +#define UX_SOURCE_CODE + +#include "ux_api.h" + + +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _ux_utility_memory_byte_pool_search PORTABLE C */ +/* 6.3.0 */ +/* AUTHOR */ +/* */ +/* Yajun Xia, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function searches a byte pool for a memory block to satisfy */ +/* the requested number of bytes. Merging of adjacent free blocks */ +/* takes place during the search. */ +/* */ +/* INPUT */ +/* */ +/* pool_ptr Pointer to pool control block */ +/* memory_size Number of bytes required */ +/* */ +/* OUTPUT */ +/* */ +/* UCHAR * Pointer to the allocated memory, */ +/* if successful. Otherwise, a */ +/* NULL is returned */ +/* */ +/* CALLS */ +/* */ +/* None */ +/* */ +/* CALLED BY */ +/* */ +/* USBX Components */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 10-31-2023 Yajun Xia Initial Version 6.3.0 */ +/* */ +/**************************************************************************/ +UCHAR *_ux_utility_memory_byte_pool_search(UX_MEMORY_BYTE_POOL *pool_ptr, ULONG memory_size) +{ +UCHAR *current_ptr; +UCHAR *next_ptr; +UCHAR **this_block_link_ptr; +UCHAR **next_block_link_ptr; +ULONG available_bytes; +UINT examine_blocks; +UINT first_free_block_found = UX_FALSE; +ALIGN_TYPE *free_ptr; +UCHAR *work_ptr; +ULONG total_theoretical_available; + + /* First, determine if there are enough bytes in the pool. */ + /* Theoretical bytes available = free bytes + ((fragments-2) * overhead of each block) */ + total_theoretical_available = pool_ptr -> ux_byte_pool_available + ((pool_ptr -> ux_byte_pool_fragments - 2) * UX_MEMORY_BLOCK_HEADER_SIZE); + if (memory_size >= total_theoretical_available) + { + + /* Not enough memory, return a NULL pointer. */ + return(UX_NULL); + } + + /* Check if the search pointer is valid. */ + if ((pool_ptr -> ux_byte_pool_search < pool_ptr -> ux_byte_pool_start) || + (pool_ptr -> ux_byte_pool_search > pool_ptr -> ux_byte_pool_start + pool_ptr -> ux_byte_pool_size)) + { + + /* Return a NULL pointer. */ + return(UX_NULL); + } + + /* Walk through the memory pool in search for a large enough block. */ + current_ptr = pool_ptr -> ux_byte_pool_search; + examine_blocks = pool_ptr -> ux_byte_pool_fragments + ((UINT) 1); + available_bytes = ((ULONG) 0); + do + { + /* Check to see if this block is free. */ + work_ptr = UX_UCHAR_POINTER_ADD(current_ptr, (sizeof(UCHAR *))); + free_ptr = UX_UCHAR_TO_ALIGN_TYPE_POINTER_CONVERT(work_ptr); + if ((*free_ptr) == UX_BYTE_BLOCK_FREE) + { + + /* Determine if this is the first free block. */ + if (first_free_block_found == UX_FALSE) + { + /* This is the first free block. */ + pool_ptr->ux_byte_pool_search = current_ptr; + + /* Set the flag to indicate we have found the first free + block. */ + first_free_block_found = UX_TRUE; + } + + /* Block is free, see if it is large enough. */ + + /* Pickup the next block's pointer. */ + this_block_link_ptr = UX_UCHAR_TO_INDIRECT_UCHAR_POINTER_CONVERT(current_ptr); + next_ptr = *this_block_link_ptr; + + /* Calculate the number of bytes available in this block. */ + available_bytes = UX_UCHAR_POINTER_DIF(next_ptr, current_ptr); + available_bytes = available_bytes - UX_MEMORY_BLOCK_HEADER_SIZE; + + /* If this is large enough, we are done because our first-fit algorithm + has been satisfied! */ + if (available_bytes >= memory_size) + { + + /* Get out of the search loop! */ + break; + } + else + { + + /* Clear the available bytes variable. */ + available_bytes = ((ULONG) 0); + + /* Not enough memory, check to see if the neighbor is + free and can be merged. */ + work_ptr = UX_UCHAR_POINTER_ADD(next_ptr, (sizeof(UCHAR *))); + free_ptr = UX_UCHAR_TO_ALIGN_TYPE_POINTER_CONVERT(work_ptr); + if ((*free_ptr) == UX_BYTE_BLOCK_FREE) + { + + /* Yes, neighbor block can be merged! This is quickly accomplished + by updating the current block with the next blocks pointer. */ + next_block_link_ptr = UX_UCHAR_TO_INDIRECT_UCHAR_POINTER_CONVERT(next_ptr); + *this_block_link_ptr = *next_block_link_ptr; + + /* Reduce the fragment total. We don't need to increase the bytes + available because all free headers are also included in the available + count. */ + pool_ptr -> ux_byte_pool_fragments--; + + /* See if the search pointer is affected. */ + if (pool_ptr -> ux_byte_pool_search == next_ptr) + { + /* Yes, update the search pointer. */ + pool_ptr -> ux_byte_pool_search = current_ptr; + } + } + else + { + /* Neighbor is not free so we can skip over it! */ + next_block_link_ptr = UX_UCHAR_TO_INDIRECT_UCHAR_POINTER_CONVERT(next_ptr); + current_ptr = *next_block_link_ptr; + + /* Decrement the examined block count to account for this one. */ + if (examine_blocks != ((UINT) 0)) + { + examine_blocks--; + } + } + } + } + else + { + + /* Block is not free, move to next block. */ + this_block_link_ptr = UX_UCHAR_TO_INDIRECT_UCHAR_POINTER_CONVERT(current_ptr); + current_ptr = *this_block_link_ptr; + } + + /* Another block has been searched... decrement counter. */ + if (examine_blocks != ((UINT) 0)) + { + + examine_blocks--; + } + + } while(examine_blocks != ((UINT) 0)); + + /* If a block was found, just return. */ + if (available_bytes == ((ULONG) 0)) + { + return(UX_NULL); + } + + /* Return the search pointer. */ + return(current_ptr); +} diff --git a/common/core/src/ux_utility_memory_free.c b/common/core/src/ux_utility_memory_free.c index bbab0e9..cbd38e3 100644 --- a/common/core/src/ux_utility_memory_free.c +++ b/common/core/src/ux_utility_memory_free.c @@ -12,8 +12,8 @@ /**************************************************************************/ /**************************************************************************/ -/** */ -/** USBX Component */ +/** */ +/** USBX Component */ /** */ /** Utility */ /** */ @@ -28,60 +28,71 @@ #include "ux_api.h" -/**************************************************************************/ -/* */ -/* FUNCTION RELEASE */ -/* */ -/* _ux_utility_memory_free PORTABLE C */ -/* 6.1.10 */ +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _ux_utility_memory_free PORTABLE C */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ /* */ /* DESCRIPTION */ -/* */ -/* This function frees a previously allocated memory block. */ -/* */ -/* INPUT */ -/* */ -/* memory Pointer to memory block */ -/* */ -/* OUTPUT */ -/* */ -/* None */ -/* */ -/* CALLS */ -/* */ -/* _ux_utility_mutex_on Start system protection */ -/* _ux_utility_mutex_off End system protection */ -/* */ -/* CALLED BY */ -/* */ -/* USBX Components */ -/* */ -/* RELEASE HISTORY */ -/* */ -/* DATE NAME DESCRIPTION */ -/* */ +/* */ +/* This function frees a previously allocated memory block. */ +/* */ +/* INPUT */ +/* */ +/* memory Pointer to memory block */ +/* */ +/* OUTPUT */ +/* */ +/* None */ +/* */ +/* CALLS */ +/* */ +/* _ux_utility_mutex_on Start system protection */ +/* _ux_utility_mutex_off End system protection */ +/* */ +/* CALLED BY */ +/* */ +/* USBX Components */ +/* */ +/* 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 */ /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */ /* added standalone support, */ /* resulting in version 6.1.10 */ +/* 10-31-2023 Yajun Xia, CQ Xiao Modified comment(s), */ +/* added some error traps, */ +/* refined memory management, */ +/* resulting in version 6.3.0 */ /* */ /**************************************************************************/ VOID _ux_utility_memory_free(VOID *memory) { +UX_MEMORY_BYTE_POOL *pool_ptr; +UCHAR *work_ptr; +UCHAR *temp_ptr; +UCHAR *next_block_ptr; -UX_MEMORY_BLOCK *memory_block; -UX_MEMORY_BLOCK *next_block; -ULONG memory_size_returned; -UCHAR *memory_address; +ALIGN_TYPE *free_ptr; +UX_MEMORY_BYTE_POOL **byte_pool_ptr; +UCHAR **block_link_ptr; #ifdef UX_ENABLE_MEMORY_POOL_SANITY_CHECK +UCHAR *memory_address; UCHAR *regular_start, *regular_end; UCHAR *cache_safe_start, *cache_safe_end; #endif +#ifdef UX_ENABLE_MEMORY_STATISTICS +UINT index; +#endif /* Get the mutex as this is a critical section. */ _ux_system_mutex_on(&_ux_system -> ux_system_mutex); @@ -89,12 +100,13 @@ UCHAR *cache_safe_start, *cache_safe_end; #ifdef UX_ENABLE_MEMORY_POOL_SANITY_CHECK /* Sanity check, check if the memory is in memory pool. */ - regular_start = (UCHAR *)_ux_system -> ux_system_regular_memory_pool_start; - regular_end = regular_start + _ux_system -> ux_system_regular_memory_pool_size; - regular_start += sizeof(UX_MEMORY_BLOCK); - cache_safe_start = (UCHAR *)_ux_system -> ux_system_cache_safe_memory_pool_start; - cache_safe_end = cache_safe_start + _ux_system -> ux_system_cache_safe_memory_pool_size; - cache_safe_start += sizeof(UX_MEMORY_BLOCK); + regular_start = (UCHAR *)_ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_REGULAR] -> ux_byte_pool_start; + regular_end = regular_start + _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_REGULAR] -> ux_byte_pool_size; + regular_start += UX_MEMORY_BLOCK_HEADER_SIZE; + cache_safe_start = (UCHAR *)_ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_CACHE_SAFE] -> ux_byte_pool_start; + cache_safe_end = cache_safe_start + _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_CACHE_SAFE] -> ux_byte_pool_size; + cache_safe_start += UX_MEMORY_BLOCK_HEADER_SIZE; + memory_address = (UCHAR *)memory; if (!((memory_address >= regular_start && memory_address < regular_end) || (memory_address >= cache_safe_start && memory_address < cache_safe_end))) @@ -112,117 +124,103 @@ UCHAR *cache_safe_start, *cache_safe_end; } #endif - /* The memory block for this memory pointer is located right before the - memory. */ - memory_block = (UX_MEMORY_BLOCK *) (((UCHAR *) memory) - sizeof(UX_MEMORY_BLOCK)); - - /* Keep track of the memory returned to the pool. */ - memory_size_returned = memory_block -> ux_memory_block_size + (ULONG)sizeof(UX_MEMORY_BLOCK); + /* Set the pool pointer to NULL. */ + pool_ptr = UX_NULL; - /* Check this memory block to see if it valid. */ - if (memory_block -> ux_memory_block_status != (UX_MEMORY_USED | UX_REGULAR_MEMORY) && - memory_block -> ux_memory_block_status != (UX_MEMORY_USED | UX_CACHE_SAFE_MEMORY)) + /* Determine if the memory pointer is valid. */ + work_ptr = UX_VOID_TO_UCHAR_POINTER_CONVERT(memory); + if (work_ptr != UX_NULL) { - /* Not valid. Release the protection. */ - _ux_system_mutex_off(&_ux_system -> ux_system_mutex); + /* Back off the memory pointer to pickup its header. */ + work_ptr = UX_UCHAR_POINTER_SUB(work_ptr, UX_MEMORY_BLOCK_HEADER_SIZE); - /* Error trap. */ - _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_UTILITY, UX_MEMORY_CORRUPTED); + /* There is a pointer, pickup the pool pointer address. */ + temp_ptr = UX_UCHAR_POINTER_ADD(work_ptr, (sizeof(UCHAR *))); + free_ptr = UX_UCHAR_TO_ALIGN_TYPE_POINTER_CONVERT(temp_ptr); + if ((*free_ptr) != UX_BYTE_BLOCK_FREE) + { - /* If trace is enabled, insert this event into the trace buffer. */ - UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_MEMORY_CORRUPTED, memory, 0, 0, UX_TRACE_ERRORS, 0, 0) + /* Pickup the pool pointer. */ + temp_ptr = UX_UCHAR_POINTER_ADD(work_ptr, (sizeof(UCHAR *))); + byte_pool_ptr = UX_UCHAR_TO_INDIRECT_BYTE_POOL_POINTER(temp_ptr); + pool_ptr = *byte_pool_ptr; - /* Return to caller. */ - return; - } + /* See if we have a valid pool pointer. */ + if ((pool_ptr == UX_NULL) || + ((pool_ptr != _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_REGULAR]) && + (pool_ptr != _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_CACHE_SAFE]))) + { -#ifdef UX_ENABLE_MEMORY_STATISTICS + /* Release the protection. */ + _ux_system_mutex_off(&_ux_system -> ux_system_mutex); - /* Update allocate count, total size. */ - if (memory_block -> ux_memory_block_status == (UX_MEMORY_USED | UX_REGULAR_MEMORY)) - { - _ux_system -> ux_system_regular_memory_pool_alloc_count --; - _ux_system -> ux_system_regular_memory_pool_alloc_total -= memory_block -> ux_memory_block_size; - } - else - { - _ux_system -> ux_system_cache_safe_memory_pool_alloc_count --; - _ux_system -> ux_system_cache_safe_memory_pool_alloc_total -= memory_block -> ux_memory_block_size; - } -#endif + /* Error trap: maybe double free/memory issue here! */ + _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, + UX_SYSTEM_CONTEXT_UTILITY, UX_MEMORY_CORRUPTED); - /* We mark this memory block as being unused. */ - memory_block -> ux_memory_block_status = UX_MEMORY_UNUSED; - - /* Now we must concatenate as many free blocks as possible, - that include the blocks before and the blocks after the current - block. Scan memory backwards. */ + /* Return to caller. */ + return; + } + } + else + { + /* Release the protection. */ + _ux_system_mutex_off(&_ux_system -> ux_system_mutex); - while (memory_block -> ux_memory_block_previous !=UX_NULL) - { + /* Error trap: maybe double free/memory issue here! */ + _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, + UX_SYSTEM_CONTEXT_UTILITY, UX_MEMORY_CORRUPTED); - /* Check if the block is free. */ - if (memory_block -> ux_memory_block_previous -> ux_memory_block_status == UX_MEMORY_UNUSED) + /* Return to caller. */ + return; + } + } + else + { - /* The memory block before is free. This will be our starting point to - concatenate memory. */ - memory_block = memory_block -> ux_memory_block_previous; + /* Release the protection. */ + _ux_system_mutex_off(&_ux_system -> ux_system_mutex); - else + /* Error trap: maybe double free/bad flow here! */ + _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, + UX_SYSTEM_CONTEXT_UTILITY, UX_MEMORY_CORRUPTED); - /* The previous memory block is not free. */ - break; + /* Return to caller. */ + return; } - /* The pointer to the memory block is now our first free block. We use this - starting address to concatenate all the contiguous memory block. */ - next_block = memory_block -> ux_memory_block_next; - while (next_block != UX_NULL) - { + /* At this point, we know that the pool pointer is valid. */ - /* Determine if the memory block is used. */ - if (next_block -> ux_memory_block_status != UX_MEMORY_UNUSED) - { + /* Release the memory. */ + temp_ptr = UX_UCHAR_POINTER_ADD(work_ptr, (sizeof(UCHAR *))); + free_ptr = UX_UCHAR_TO_ALIGN_TYPE_POINTER_CONVERT(temp_ptr); + *free_ptr = UX_BYTE_BLOCK_FREE; - /* Yes, move to next block. */ - memory_block -> ux_memory_block_next = next_block; - next_block -> ux_memory_block_previous = memory_block; - break; - } + /* Update the number of available bytes in the pool. */ + block_link_ptr = UX_UCHAR_TO_INDIRECT_UCHAR_POINTER_CONVERT(work_ptr); + next_block_ptr = *block_link_ptr; + pool_ptr -> ux_byte_pool_available = + pool_ptr -> ux_byte_pool_available + UX_UCHAR_POINTER_DIF(next_block_ptr, work_ptr); - memory_block -> ux_memory_block_next = next_block -> ux_memory_block_next; - memory_block -> ux_memory_block_size += next_block -> ux_memory_block_size + (ULONG)sizeof(UX_MEMORY_BLOCK); - next_block = next_block -> ux_memory_block_next; - } - - /* Update the memory free in the appropriate pool. We need to know if this - block is in regular memory or cache safe memory. */ - if(_ux_system -> ux_system_cache_safe_memory_pool_start == _ux_system -> ux_system_regular_memory_pool_start) + /* Determine if the free block is prior to current search pointer. */ + if (work_ptr < (pool_ptr -> ux_byte_pool_search)) { - /* There is only one regular memory pool. */ - _ux_system -> ux_system_regular_memory_pool_free += memory_size_returned; - + /* Yes, update the search pointer to the released block. */ + pool_ptr -> ux_byte_pool_search = work_ptr; } - else - { - - /* Which pool is this memory in ? */ - memory_address = (UCHAR *) _ux_system -> ux_system_regular_memory_pool_start; - - /* If the memory address is in this range, we are in the regular memory pool. */ - if ((UCHAR *) memory_block >= memory_address && (UCHAR *) memory_block < (memory_address + _ux_system -> ux_system_regular_memory_pool_size)) - /* Update the regular memory pool. */ - _ux_system -> ux_system_regular_memory_pool_free += memory_size_returned; +#ifdef UX_ENABLE_MEMORY_STATISTICS + if (((UCHAR*)memory >= _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_REGULAR] -> ux_byte_pool_start) && + ((UCHAR*)memory < (_ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_REGULAR] -> ux_byte_pool_start + _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_REGULAR] -> ux_byte_pool_size))) + index = UX_MEMORY_BYTE_POOL_REGULAR; + else + index = UX_MEMORY_BYTE_POOL_CACHE_SAFE; - else - - /* Update the cache safe memory pool. */ - _ux_system -> ux_system_cache_safe_memory_pool_free += memory_size_returned; - - } + _ux_system -> ux_system_memory_byte_pool[index] -> ux_byte_pool_alloc_count --; + _ux_system -> ux_system_memory_byte_pool[index] -> ux_byte_pool_alloc_total -= UX_UCHAR_POINTER_DIF(next_block_ptr, work_ptr); +#endif /* Release the protection. */ _ux_system_mutex_off(&_ux_system -> ux_system_mutex); diff --git a/common/core/src/ux_utility_memory_free_block_best_get.c b/common/core/src/ux_utility_memory_free_block_best_get.c index 87179f3..b7203bd 100644 --- a/common/core/src/ux_utility_memory_free_block_best_get.c +++ b/common/core/src/ux_utility_memory_free_block_best_get.c @@ -12,8 +12,8 @@ /**************************************************************************/ /**************************************************************************/ -/** */ -/** USBX Component */ +/** */ +/** USBX Component */ /** */ /** USBX main stack */ /** */ @@ -28,57 +28,64 @@ #include "ux_api.h" -/**************************************************************************/ -/* */ -/* FUNCTION RELEASE */ -/* */ -/* _ux_utility_memory_free_block_best_get PORTABLE C */ -/* 6.1 */ +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _ux_utility_memory_free_block_best_get PORTABLE C */ +/* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ /* */ /* DESCRIPTION */ -/* */ -/* This function returns the best free memory block. */ -/* */ -/* INPUT */ -/* */ -/* memory_cache_flag Memory pool source */ -/* memory_size_requested Size of memory requested */ -/* */ -/* OUTPUT */ -/* */ -/* Pointer to best free block */ -/* */ -/* CALLS */ -/* */ +/* */ +/* This function returns the best free memory block. */ +/* */ +/* It's deprecated. */ +/* */ +/* INPUT */ +/* */ +/* memory_cache_flag Memory pool source */ +/* memory_size_requested Size of memory requested */ +/* */ +/* OUTPUT */ +/* */ +/* Pointer to best free block */ +/* */ +/* CALLS */ +/* */ /* None */ -/* */ -/* CALLED BY */ -/* */ -/* USBX Components */ -/* */ -/* RELEASE HISTORY */ -/* */ -/* DATE NAME DESCRIPTION */ -/* */ +/* */ +/* CALLED BY */ +/* */ +/* USBX Components */ +/* */ +/* 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 */ +/* 10-31-2023 Yajun Xia Modified comment(s), */ +/* deprecated for memory */ +/* footprint optimization, */ +/* resulting in version 6.3.0 */ /* */ /**************************************************************************/ -UX_MEMORY_BLOCK *_ux_utility_memory_free_block_best_get(ULONG memory_cache_flag, +#if 0 +UX_MEMORY_BLOCK *_ux_utility_memory_free_block_best_get(ULONG memory_cache_flag, ULONG memory_size_requested) { UX_MEMORY_BLOCK *memory_block; UX_MEMORY_BLOCK *best_memory_block; - + /* Reset the free memory block. */ best_memory_block = UX_NULL; - + /* Check the type of memory we need. */ switch (memory_cache_flag) { @@ -88,15 +95,15 @@ UX_MEMORY_BLOCK *best_memory_block; /* Start at the beginning of the regular memory pool. */ memory_block = _ux_system -> ux_system_regular_memory_pool_start; break; - + case UX_CACHE_SAFE_MEMORY : /* Start at the beginning of the cache safe memory pool. */ memory_block = _ux_system -> ux_system_cache_safe_memory_pool_start; break; - + default : - + /* Wrong memory type. */ return(UX_NULL); @@ -110,11 +117,11 @@ UX_MEMORY_BLOCK *best_memory_block; if (memory_block -> ux_memory_block_status == UX_MEMORY_UNUSED) { - /* Check the size of this free block and see if it will + /* Check the size of this free block and see if it will fit the memory requirement. */ if (memory_block -> ux_memory_block_size > memory_size_requested) { - + /* This memory block will do. Now see if it is the best. The best memory block is the one whose memory is closest to the memory requested. */ @@ -129,15 +136,15 @@ UX_MEMORY_BLOCK *best_memory_block; /* We have discovered a better fit block. */ best_memory_block = memory_block; - } + } } } - /* Search the next free block until the end. */ + /* Search the next free block until the end. */ memory_block = memory_block -> ux_memory_block_next; } /* If no free memory block was found, the return value will be NULL. */ - return(best_memory_block); -} - + return(best_memory_block); +} +#endif |
