diff --git a/common/core/inc/ux_api.h b/common/core/inc/ux_api.h index 87b6b9c0..748d5881 100644 --- a/common/core/inc/ux_api.h +++ b/common/core/inc/ux_api.h @@ -441,7 +441,9 @@ typedef signed char SCHAR; /* Map the error log macros to internal USBX function. */ -#define UX_DEBUG_LOG(debug_location, debug_message, debug_code, debug_parameter_1, debug_parameter_2) _ux_utility_debug_log((UCHAR *) debug_location, (UCHAR *) debug_message, (ULONG) debug_code, (ULONG) debug_parameter_1, (ULONG) debug_parameter_2); +#define UX_DEBUG_LOG(debug_location, debug_message, debug_code, debug_parameter_1, debug_parameter_2) \ + _ux_utility_debug_log((UCHAR *) debug_location, (UCHAR *) debug_message, (ULONG) debug_code, \ + (ULONG) debug_parameter_1, (ULONG) debug_parameter_2); VOID _ux_utility_debug_log(UCHAR *debug_location, UCHAR *debug_message, ULONG debug_code, ULONG debug_parameter_1, ULONG debug_parameter_2); @@ -449,7 +451,6 @@ VOID _ux_utility_debug_log(UCHAR *debug_location, UCHAR *debug_message, ULONG de /* If error log is enabled, insert this error message into the log buffer. */ /* UX_DEBUG_LOG("_ux_host_stack_rh_device_insertion", "Device insertion", port_index, port_index, 0) */ - #else /* If Log is not defined, map it to nothing so that debug messages can stay in the code. */ diff --git a/common/core/inc/ux_user_sample.h b/common/core/inc/ux_user_sample.h index 1cd62c1c..1246bbaa 100644 --- a/common/core/inc/ux_user_sample.h +++ b/common/core/inc/ux_user_sample.h @@ -1,17 +1,17 @@ /*************************************************************************** - * Copyright (c) 2024 Microsoft Corporation - * + * Copyright (c) 2024 Microsoft Corporation + * * This program and the accompanying materials are made available under the * terms of the MIT License which is available at * https://opensource.org/licenses/MIT. - * + * * SPDX-License-Identifier: MIT **************************************************************************/ /**************************************************************************/ /**************************************************************************/ -/** */ +/** */ /** USBX Component */ /** */ /** User Specific */ @@ -20,11 +20,11 @@ /**************************************************************************/ -/**************************************************************************/ -/* */ -/* PORT SPECIFIC C INFORMATION RELEASE */ -/* */ -/* ux_user.h PORTABLE C */ +/**************************************************************************/ +/* */ +/* PORT SPECIFIC C INFORMATION RELEASE */ +/* */ +/* ux_user.h PORTABLE C */ /* 6.3.0 */ /* */ /* AUTHOR */ @@ -32,17 +32,17 @@ /* Chaoqiong Xiao, Microsoft Corporation */ /* */ /* DESCRIPTION */ -/* */ -/* This file contains user defines for configuring USBX in specific */ -/* ways. This file will have an effect only if the application and */ -/* USBX library are built with UX_INCLUDE_USER_DEFINE_FILE defined. */ -/* Note that all the defines in this file may also be made on the */ -/* command line when building USBX library and application objects. */ -/* */ -/* RELEASE HISTORY */ -/* */ -/* DATE NAME DESCRIPTION */ -/* */ +/* */ +/* This file contains user defines for configuring USBX in specific */ +/* ways. This file will have an effect only if the application and */ +/* USBX library are built with UX_INCLUDE_USER_DEFINE_FILE defined. */ +/* Note that all the defines in this file may also be made on the */ +/* command line when building USBX library and application objects. */ +/* */ +/* 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 */ @@ -115,15 +115,15 @@ /* Define various build options for the USBX port. The application should either make changes - here by commenting or un-commenting the conditional compilation defined OR supply the defines + here by commenting or un-commenting the conditional compilation defined OR supply the defines though the compiler's equivalent of the -D option. */ /* Define USBX Generic Thread Stack Size. */ /* #define UX_THREAD_STACK_SIZE (2 * 1024) */ /* Define USBX Host Enum Thread Stack Size. The default is to use UX_THREAD_STACK_SIZE */ -/* -#define UX_HOST_ENUM_THREAD_STACK_SIZE UX_THREAD_STACK_SIZE +/* +#define UX_HOST_ENUM_THREAD_STACK_SIZE UX_THREAD_STACK_SIZE */ @@ -137,14 +137,14 @@ #define UX_HOST_HNP_POLLING_THREAD_STACK UX_THREAD_STACK_SIZE */ -/* Override various options with default values already assigned in ux_api.h or ux_port.h. Please +/* Override various options with default values already assigned in ux_api.h or ux_port.h. Please also refer to ux_port.h for descriptions on each of these options. */ /* Defined, this value represents minimal allocated memory alignment in number of bytes. The default is UX_ALIGN_8 (0x07) to align allocated memory to 8 bytes. */ /* #define UX_ALIGN_MIN UX_ALIGN_8 */ -/* Defined, this value represents how many ticks per seconds for a specific hardware platform. +/* Defined, this value represents how many ticks per seconds for a specific hardware platform. The default is 1000 indicating 1 tick per millisecond. */ /* #define UX_PERIODIC_RATE 1000 @@ -167,7 +167,7 @@ /* Defined, this value is the maximum number of classes that can be loaded by USBX. This value represents the class container and not the number of instances of a class. For instance, if a particular implementation of USBX needs the hub class, the printer class, and the storage - class, then the UX_MAX_CLASSES value can be set to 3 regardless of the number of devices + class, then the UX_MAX_CLASSES value can be set to 3 regardless of the number of devices that belong to these classes. */ /* #define UX_MAX_CLASSES 3 @@ -185,9 +185,9 @@ /* #define UX_MAX_SLAVE_INTERFACES 16 */ -/* Defined, this value represents the number of different host controllers available in the system. - For USB 1.1 support, this value will usually be 1. For USB 2.0 support, this value can be more - than 1. This value represents the number of concurrent host controllers running at the same time. +/* Defined, this value represents the number of different host controllers available in the system. + For USB 1.1 support, this value will usually be 1. For USB 2.0 support, this value can be more + than 1. This value represents the number of concurrent host controllers running at the same time. If for instance there are two instances of OHCI running, or one EHCI and one OHCI controller running, the UX_MAX_HCD should be set to 2. */ @@ -196,8 +196,8 @@ /* Defined, this value represents the maximum number of devices that can be attached to the USB. - Normally, the theoretical maximum number on a single USB is 127 devices. This value can be - scaled down to conserve memory. Note that this value represents the total number of devices + Normally, the theoretical maximum number on a single USB is 127 devices. This value can be + scaled down to conserve memory. Note that this value represents the total number of devices regardless of the number of USB buses in the system. */ /* #define UX_MAX_DEVICES 127 @@ -213,7 +213,7 @@ /* Defined, this value represents the maximum number of SCSI logical units represented in the host storage class driver. */ - + /* #define UX_MAX_HOST_LUN 1 */ @@ -274,13 +274,13 @@ /* Defined, this value represents the maximum number of bytes that can be received or transmitted - on any endpoint. This value cannot be less than the maximum packet size of any endpoint. The default - is 4096 bytes but can be reduced in memory constrained environments. For cd-rom support in the storage + on any endpoint. This value cannot be less than the maximum packet size of any endpoint. The default + is 4096 bytes but can be reduced in memory constrained environments. For cd-rom support in the storage class, this value cannot be less than 2048. */ #define UX_SLAVE_REQUEST_DATA_MAX_LENGTH (1024 * 2) -/* Defined, this enables processing of Get String Descriptor requests with zero Language ID. +/* Defined, this enables processing of Get String Descriptor requests with zero Language ID. The first language ID in the language ID framwork will be used if the request has a zero Language ID. */ /* #define UX_DEVICE_ENABLE_GET_STRING_WITH_ZERO_LANGUAGE_ID */ @@ -297,7 +297,7 @@ /* Define USBX Mass Storage Thread Stack Size. The default is to use UX_THREAD_STACK_SIZE. */ -/* #define UX_HOST_CLASS_STORAGE_THREAD_STACK_SIZE UX_THREAD_STACK_SIZE +/* #define UX_HOST_CLASS_STORAGE_THREAD_STACK_SIZE UX_THREAD_STACK_SIZE */ /* Defined, this value represents the maximum number of Ed, regular TDs and Isochronous TDs. These values @@ -313,13 +313,13 @@ #define UX_HOST_CLASS_HID_DECOMPRESSION_BUFFER 4096 -/* Defined, this value represents the maximum number of HID usages for a HID device. +/* Defined, this value represents the maximum number of HID usages for a HID device. Default is 2048 but for simple HID devices like keyboard and mouse it can be reduced a lot. */ #define UX_HOST_CLASS_HID_USAGES 2048 -/* By default, each key in each HID report from the device is reported by ux_host_class_hid_keyboard_key_get +/* By default, each key in each HID report from the device is reported by ux_host_class_hid_keyboard_key_get (a HID report from the device is received whenever there is a change in a key state i.e. when a key is pressed or released. The report contains every key that is down). There are limitations to this method such as not being able to determine when a key has been released. @@ -352,13 +352,13 @@ /* #define UX_HOST_CLASS_HID_KEYBOARD_EVENTS_KEY_CHANGES_MODE_REPORT_MODIFIER_KEYS */ -/* Defined, this value represents the maximum number of media for the host storage class. +/* Defined, this value represents the maximum number of media for the host storage class. Default is 8 but for memory constrained resource systems this can ne reduced to 1. */ #define UX_HOST_CLASS_STORAGE_MAX_MEDIA 2 /* Defined, this value includes code to handle storage devices that use the CB - or CBI protocol (such as floppy disks). It is off by default because these + or CBI protocol (such as floppy disks). It is off by default because these protocols are obsolete, being superseded by the Bulk Only Transport (BOT) protocol which virtually all modern storage devices use. */ @@ -415,8 +415,8 @@ /* #define UX_DEVICE_CLASS_HID_EVENT_BUFFER_LENGTH 64 */ -/* Defined, this value represents the the maximum number of HID events/reports - that can be queued at once. +/* Defined, this value represents the the maximum number of HID events/reports + that can be queued at once. */ /* #define UX_DEVICE_CLASS_HID_MAX_EVENTS_QUEUE 8 */ @@ -485,7 +485,7 @@ /* #define UX_DEVICE_BIDIRECTIONAL_ENDPOINT_SUPPORT */ /* Defined, this macro disables interface alternate setting support. - Device stalls + Device stalls */ /* UX_DEVICE_ALTERNATE_SETTING_SUPPORT_DISABLE */ @@ -563,13 +563,13 @@ /* Defined, this value will include the OTG polling thread. OTG can only be active if both host/device are present. */ -#ifndef UX_HOST_SIDE_ONLY -#ifndef UX_DEVICE_SIDE_ONLY +#ifndef UX_HOST_SIDE_ONLY +#ifndef UX_DEVICE_SIDE_ONLY /* #define UX_OTG_SUPPORT */ -#endif -#endif +#endif +#endif /* Defined, this macro will enable the standalone mode of usbx. */ /* #define UX_STANDALONE */ @@ -592,6 +592,10 @@ #define UX_HOST_CLASS_STORAGE_MAX_TRANSFER_SIZE (1024 * 1) +/* Defined, this option enables error log. */ + +/* #define UX_ENABLE_DEBUG_LOG */ + /* Defined, this value represents the size of the log pool. */ #define UX_DEBUG_LOG_SIZE (1024 * 16) @@ -641,7 +645,7 @@ #include "usbh_hcs.h" #include "usbh_stdreq.h" #include "usbh_core.h" -#endif +#endif -#endif +#endif diff --git a/common/core/inc/ux_utility.h b/common/core/inc/ux_utility.h index c2fd8f4b..555bf635 100644 --- a/common/core/inc/ux_utility.h +++ b/common/core/inc/ux_utility.h @@ -451,6 +451,7 @@ VOID* _ux_utility_memory_allocate_add_safe(ULONG align,ULONG cache,UL #define ux_utility_event_flags_set _ux_utility_event_flags_set #define ux_utility_unicode_to_string _ux_utility_unicode_to_string #define ux_utility_string_to_unicode _ux_utility_string_to_unicode +#define ux_utility_debug_callback_register _ux_utility_debug_callback_register #define ux_utility_delay_ms _ux_utility_delay_ms #define ux_utility_error_callback_register _ux_utility_error_callback_register #define ux_system_error_handler _ux_system_error_handler diff --git a/common/core/src/ux_system_uninitialize.c b/common/core/src/ux_system_uninitialize.c index 3a80b24a..46873ee7 100644 --- a/common/core/src/ux_system_uninitialize.c +++ b/common/core/src/ux_system_uninitialize.c @@ -1,18 +1,18 @@ /*************************************************************************** - * Copyright (c) 2024 Microsoft Corporation - * + * Copyright (c) 2024 Microsoft Corporation + * * This program and the accompanying materials are made available under the * terms of the MIT License which is available at * https://opensource.org/licenses/MIT. - * + * * SPDX-License-Identifier: MIT **************************************************************************/ /**************************************************************************/ /**************************************************************************/ -/** */ -/** USBX Component */ +/** */ +/** USBX Component */ /** */ /** System */ /** */ @@ -29,39 +29,39 @@ #include "ux_utility.h" -/**************************************************************************/ -/* */ -/* FUNCTION RELEASE */ -/* */ -/* _ux_system_uninitialize PORTABLE C */ +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _ux_system_uninitialize PORTABLE C */ /* 6.1.10 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ /* */ /* DESCRIPTION */ -/* */ -/* This function uninitializes the various control data structures for */ -/* the USBX system. */ -/* */ -/* INPUT */ -/* */ -/* OUTPUT */ -/* */ +/* */ +/* This function uninitializes the various control data structures for */ +/* the USBX system. */ +/* */ +/* INPUT */ +/* */ +/* OUTPUT */ +/* */ /* None */ -/* */ -/* CALLS */ -/* */ -/* _ux_utility_mutex_delete ThreadX delete mutex */ -/* */ -/* CALLED BY */ -/* */ -/* Application */ -/* */ -/* RELEASE HISTORY */ -/* */ -/* DATE NAME DESCRIPTION */ -/* */ +/* */ +/* CALLS */ +/* */ +/* _ux_utility_mutex_delete ThreadX delete mutex */ +/* */ +/* 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), */ /* resulting in version 6.1 */ @@ -73,10 +73,15 @@ UINT _ux_system_uninitialize(VOID) { +#ifdef UX_ENABLE_DEBUG_LOG + + /* Free memory for debug log buffer. */ + if ( _ux_system -> ux_system_debug_log_buffer != UX_NULL) + _ux_utility_memory_free( _ux_system -> ux_system_debug_log_buffer); +#endif /* UX_ENABLE_DEBUG_LOG */ + /* Delete the Mutex object used by USBX to control critical sections. */ _ux_system_mutex_delete(&_ux_system -> ux_system_mutex); return(UX_SUCCESS); } - - diff --git a/common/core/src/ux_utility_debug_log.c b/common/core/src/ux_utility_debug_log.c index 7d5f27e6..c72d02b7 100644 --- a/common/core/src/ux_utility_debug_log.c +++ b/common/core/src/ux_utility_debug_log.c @@ -1,18 +1,18 @@ /*************************************************************************** - * Copyright (c) 2024 Microsoft Corporation - * + * Copyright (c) 2024 Microsoft Corporation + * * This program and the accompanying materials are made available under the * terms of the MIT License which is available at * https://opensource.org/licenses/MIT. - * + * * SPDX-License-Identifier: MIT **************************************************************************/ /**************************************************************************/ /**************************************************************************/ -/** */ -/** USBX Component */ +/** */ +/** USBX Component */ /** */ /** Utility */ /** */ @@ -28,50 +28,50 @@ #ifdef UX_ENABLE_DEBUG_LOG -/**************************************************************************/ -/* */ -/* FUNCTION RELEASE */ -/* */ -/* _ux_utility_debug_log PORTABLE C */ +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _ux_utility_debug_log PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ /* */ /* DESCRIPTION */ -/* */ -/* This function logs a debug msg in a circular queue. The queue */ -/* must be initialized during the init of USBX. */ -/* */ -/* */ -/* INPUT */ -/* */ +/* */ +/* This function logs a debug msg in a circular queue. The queue */ +/* must be initialized during the init of USBX. */ +/* */ +/* */ +/* INPUT */ +/* */ /* debug_location C string to locate the debug, */ /* for example source file name. */ /* debug_message C string of message */ /* debug_code Debug code */ /* debug_parameter_1 First parameter */ /* debug_parameter_2 Second parameter */ -/* */ -/* */ -/* OUTPUT */ -/* */ +/* */ +/* */ +/* OUTPUT */ +/* */ /* None */ -/* */ -/* CALLS */ -/* */ +/* */ +/* CALLS */ +/* */ /* _ux_utility_string_length_check Check C string and return */ /* its length if null-terminated */ /* _tx_time_get Return system clock time */ -/* */ -/* 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 */ @@ -97,13 +97,13 @@ UX_INTERRUPT_SAVE_AREA /* Is USBX system completely initialized ? */ if (_ux_system -> ux_system_debug_log_size == 0) - + /* Not yet. */ return; /* Entering critical area. Disable interrupts. */ UX_DISABLE - + /* Store the debug value as the last debug value recorded. */ _ux_system -> ux_system_debug_code = debug_code; @@ -112,20 +112,20 @@ UX_INTERRUPT_SAVE_AREA /* Calculate the string length. */ debug_location_string_length = UX_DEBUG_LOG_SIZE; - _ux_utility_string_length_check(source, &debug_location_string_length, UX_DEBUG_LOG_SIZE); + _ux_utility_string_length_check(debug_location, &debug_location_string_length, UX_DEBUG_LOG_SIZE); debug_message_string_length = UX_DEBUG_LOG_SIZE; - _ux_utility_string_length_check(source, &debug_message_string_length, UX_DEBUG_LOG_SIZE); - + _ux_utility_string_length_check(debug_message, &debug_message_string_length, UX_DEBUG_LOG_SIZE); + /* Calculate the length of the entire message string. 1 fixed string, then 1 hexa - decimal, then 2 strings then 2 hexa decimal numbers in the format 0x00000000 + decimal, then 2 strings then 2 hexa decimal numbers in the format 0x00000000 separated by commas and . at the end, zero terminated. */ total_debug_message_length = debug_location_string_length + debug_message_string_length + 10 + 10 + 10 + 10 + 5; /* Can we accommodate this debug value message at the current location ? */ if (total_debug_message_length >= _ux_system -> ux_system_debug_log_size) return; - if (_ux_system -> ux_system_debug_log_head + total_debug_message_length > - ux_system -> ux_system_debug_log_buffer + _ux_system -> ux_system_debug_log_size) + if (_ux_system -> ux_system_debug_log_head + total_debug_message_length > + _ux_system -> ux_system_debug_log_buffer + _ux_system -> ux_system_debug_log_size) { /* The debug value log to insert goes beyond the end of the log buffer, rewind to the beginning. */ @@ -137,7 +137,7 @@ UX_INTERRUPT_SAVE_AREA _ux_system -> ux_system_debug_log_head += 10; /* Get the time value from TX. */ - current_time = _tx_time_get(); + current_time = _tx_time_get(); /* Reset the value of the length.*/ parameter_length = 0; @@ -148,33 +148,33 @@ UX_INTERRUPT_SAVE_AREA /* We parse the hexa value parameter and build the hexa value one byte at a type. */ while(parameter_length < 8) { - + /* Shift the 4 bit value we are interested in. We keep the lowest nibble. */ local_parameter_value = (current_time >> parameter_shift) & 0x0f; - + /* See if this value is from 0-9 or A to F. */ if (local_parameter_value <= 9) - + /* We have a digit. */ parameter_hexa = (UCHAR) (local_parameter_value + '0'); - + else /* We have 'A' to 'F' value. */ parameter_hexa = (UCHAR) (local_parameter_value - 10 + 'A'); - + /* Store the converted hexa value. */ *_ux_system -> ux_system_debug_log_head = parameter_hexa; /* Next position. */ _ux_system -> ux_system_debug_log_head++; - + /* Update length. */ parameter_length++; /* Continue shifting by one nibble. */ - parameter_shift = parameter_shift - 4; - } + parameter_shift = parameter_shift - 4; + } /* Add the comma after the time. */ *_ux_system -> ux_system_debug_log_head = ','; @@ -205,33 +205,33 @@ UX_INTERRUPT_SAVE_AREA /* We parse the hexa value parameter and build the hexa value one byte at a type. */ while(parameter_length < 8) { - + /* Shift the 4 bit value we are interested in. We keep the lowest nibble. */ local_parameter_value = (debug_parameter_1 >> parameter_shift) & 0x0f; - + /* See if this value is from 0-9 or A to F. */ if (local_parameter_value <= 9) - + /* We have a digit. */ parameter_hexa = (UCHAR) (local_parameter_value + '0'); - + else /* We have 'A' to 'F' value. */ parameter_hexa = (UCHAR) (local_parameter_value - 10 + 'A'); - + /* Store the converted hexa value. */ *_ux_system -> ux_system_debug_log_head = parameter_hexa; /* Next position. */ _ux_system -> ux_system_debug_log_head++; - + /* Update length. */ parameter_length++; /* Continue shifting by one nibble. */ - parameter_shift = parameter_shift - 4; - } + parameter_shift = parameter_shift - 4; + } /* Add the comma between the 2 hexa values. */ *_ux_system -> ux_system_debug_log_head = ','; @@ -252,33 +252,33 @@ UX_INTERRUPT_SAVE_AREA /* We parse the hexa value parameter and build the hexa value one byte at a type. */ while(parameter_length < 8) { - + /* Shift the 4 bit value we are interested in. We keep the lowest nibble. */ local_parameter_value = (debug_parameter_2 >> parameter_shift) & 0x0f; - + /* See if this value is from 0-9 or A to F. */ if (local_parameter_value <= 9) - + /* We have a digit. */ parameter_hexa = (UCHAR) (local_parameter_value + '0'); - + else /* We have 'A' to 'F' value. */ parameter_hexa = (UCHAR) (local_parameter_value - 10 + 'A'); - + /* Store the converted hexa value. */ *_ux_system -> ux_system_debug_log_head = parameter_hexa; /* Next position. */ _ux_system -> ux_system_debug_log_head++; - + /* Update length. */ parameter_length++; /* Continue shifting by one nibble. */ - parameter_shift = parameter_shift - 4; - } + parameter_shift = parameter_shift - 4; + } /* Add the termination dot at the end. */ *_ux_system -> ux_system_debug_log_head = '.'; @@ -294,11 +294,11 @@ UX_INTERRUPT_SAVE_AREA *_ux_system -> ux_system_debug_log_head = 0x00; _ux_system -> ux_system_debug_log_head++; - /* The log string is put into the log buffer. It can stay here until + /* The log string is put into the log buffer. It can stay here until a break into debugger by the developer or be passed to a callback registered by the application. */ if (_ux_system -> ux_system_debug_callback_function != UX_NULL) - { + { /* The callback function is defined, call it. */ _ux_system -> ux_system_debug_callback_function(_ux_system -> ux_system_debug_log_tail, debug_code);