1 /**************************************************************************/ 2 /* */ 3 /* Copyright (c) Microsoft Corporation. All rights reserved. */ 4 /* */ 5 /* This software is licensed under the Microsoft Software License */ 6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */ 7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ 8 /* and in the root directory of this software. */ 9 /* */ 10 /**************************************************************************/ 11 12 13 /**************************************************************************/ 14 /**************************************************************************/ 15 /** */ 16 /** USBX Component */ 17 /** */ 18 /** Host Stack */ 19 /** */ 20 /**************************************************************************/ 21 /**************************************************************************/ 22 23 24 /* Include necessary system files. */ 25 26 #define UX_SOURCE_CODE 27 28 #include "ux_api.h" 29 #include "ux_host_stack.h" 30 31 32 /**************************************************************************/ 33 /* */ 34 /* FUNCTION RELEASE */ 35 /* */ 36 /* _ux_host_stack_class_unregister PORTABLE C */ 37 /* 6.1 */ 38 /* AUTHOR */ 39 /* */ 40 /* Chaoqiong Xiao, Microsoft Corporation */ 41 /* */ 42 /* DESCRIPTION */ 43 /* */ 44 /* This function unregisters a USB class from the USB stack. */ 45 /* */ 46 /* Note following steps must be done before host class unregister: */ 47 /* All devices related to the class must be removed. */ 48 /* */ 49 /* INPUT */ 50 /* */ 51 /* class_name Name of class */ 52 /* class_entry_function Entry function of the class */ 53 /* */ 54 /* OUTPUT */ 55 /* */ 56 /* Completion Status */ 57 /* UX_SUCCESS Class unregistered */ 58 /* UX_NO_CLASS_MATCH Class not found */ 59 /* */ 60 /* CALLS */ 61 /* */ 62 /* (class_entry_function) Entry function of the class */ 63 /* */ 64 /* CALLED BY */ 65 /* */ 66 /* Application */ 67 /* USBX Components */ 68 /* */ 69 /* RELEASE HISTORY */ 70 /* */ 71 /* DATE NAME DESCRIPTION */ 72 /* */ 73 /* 09-30-2020 Chaoqiong Xiao Initial Version 6.1 */ 74 /* */ 75 /**************************************************************************/ _ux_host_stack_class_unregister(UINT (* class_entry_function)(struct UX_HOST_CLASS_COMMAND_STRUCT *))76UINT _ux_host_stack_class_unregister(UINT (*class_entry_function)(struct UX_HOST_CLASS_COMMAND_STRUCT *)) 77 { 78 79 UX_HOST_CLASS *class_inst; 80 UX_HOST_CLASS_COMMAND class_command; 81 #if UX_MAX_CLASS_DRIVER > 1 82 ULONG class_index; 83 #endif 84 85 86 /* If trace is enabled, insert this event into the trace buffer. */ 87 UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_STACK_CLASS_UNREGISTER, class_entry_function, 0, 0, 0, UX_TRACE_HOST_STACK_EVENTS, 0, 0) 88 89 /* Get first class. */ 90 class_inst = _ux_system_host -> ux_system_host_class_array; 91 92 #if UX_MAX_CLASS_DRIVER > 1 93 /* We need to parse the class table to find right class instance. */ 94 for (class_index = 0; class_index < _ux_system_host -> ux_system_host_max_class; class_index++) 95 { 96 #endif 97 98 /* Check if the class is expected. */ 99 if (class_inst -> ux_host_class_entry_function == class_entry_function) 100 { 101 102 /* Initialize the class command with the generic parameters. */ 103 class_command.ux_host_class_command_request = UX_HOST_CLASS_COMMAND_DESTROY; 104 class_command.ux_host_class_command_class_ptr = (VOID *)class_inst; 105 106 /* Invoke command for class destroy. */ 107 class_inst -> ux_host_class_entry_function(&class_command); 108 109 /* Mark as free. */ 110 class_inst -> ux_host_class_entry_function = UX_NULL; 111 class_inst -> ux_host_class_status = UX_UNUSED; 112 113 /* Class unregistered success. */ 114 return(UX_SUCCESS); 115 } 116 117 #if UX_MAX_CLASS_DRIVER > 1 118 /* Move to the next class. */ 119 class_inst ++; 120 } 121 #endif 122 123 /* No more entries in the class table. */ 124 return(UX_NO_CLASS_MATCH); 125 } 126