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 /** HID Class */ 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_class_hid.h" 30 #include "ux_host_stack.h" 31 32 33 /**************************************************************************/ 34 /* */ 35 /* FUNCTION RELEASE */ 36 /* */ 37 /* _ux_host_class_hid_instance_clean PORTABLE C */ 38 /* 6.1 */ 39 /* AUTHOR */ 40 /* */ 41 /* Chaoqiong Xiao, Microsoft Corporation */ 42 /* */ 43 /* DESCRIPTION */ 44 /* */ 45 /* This function cleans all the components of a HID instance. */ 46 /* */ 47 /* INPUT */ 48 /* */ 49 /* hid Pointer to HID class */ 50 /* */ 51 /* OUTPUT */ 52 /* */ 53 /* Completion Status */ 54 /* */ 55 /* CALLS */ 56 /* */ 57 /* _ux_utility_memory_free Release memory block */ 58 /* */ 59 /* CALLED BY */ 60 /* */ 61 /* HID Class */ 62 /* */ 63 /* RELEASE HISTORY */ 64 /* */ 65 /* DATE NAME DESCRIPTION */ 66 /* */ 67 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ 68 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ 69 /* resulting in version 6.1 */ 70 /* */ 71 /**************************************************************************/ _ux_host_class_hid_instance_clean(UX_HOST_CLASS_HID * hid)72UINT _ux_host_class_hid_instance_clean(UX_HOST_CLASS_HID *hid) 73 { 74 75 UX_HOST_CLASS_HID_PARSER *hid_parser; 76 UX_HOST_CLASS_HID_REPORT *hid_report; 77 UX_HOST_CLASS_HID_REPORT *hid_next_report; 78 UX_HOST_CLASS_HID_FIELD *hid_field; 79 UX_HOST_CLASS_HID_FIELD *hid_next_field; 80 81 82 /* Get the parser structure pointer. */ 83 hid_parser = &hid -> ux_host_class_hid_parser; 84 85 /* Each report list of the parser should be cleaned: Input report. */ 86 hid_report = hid_parser -> ux_host_class_hid_parser_input_report; 87 while (hid_report != UX_NULL) 88 { 89 90 /* Get the next report before we clean the current report. */ 91 hid_next_report = hid_report -> ux_host_class_hid_report_next_report; 92 93 /* Get the first field in the report. */ 94 hid_field = hid_report -> ux_host_class_hid_report_field; 95 96 /* Clean all the fields attached. */ 97 while (hid_field != UX_NULL) 98 { 99 100 /* Get the next field before we clean the current field. */ 101 hid_next_field = hid_field -> ux_host_class_hid_field_next_field; 102 103 /* Free the usage table. */ 104 if (hid_field -> ux_host_class_hid_field_usages != UX_NULL) 105 _ux_utility_memory_free(hid_field -> ux_host_class_hid_field_usages); 106 107 /* Free the value table. */ 108 if (hid_field -> ux_host_class_hid_field_values != UX_NULL) 109 _ux_utility_memory_free(hid_field -> ux_host_class_hid_field_values); 110 111 /* Now free the field memory. */ 112 _ux_utility_memory_free(hid_field); 113 114 /* Next field. */ 115 hid_field = hid_next_field; 116 } 117 118 /* Free the report. */ 119 _ux_utility_memory_free(hid_report); 120 121 /* Next report. */ 122 hid_report = hid_next_report; 123 } 124 125 /* Each report list of the parser should be cleaned: Output report. */ 126 hid_report = hid_parser -> ux_host_class_hid_parser_output_report; 127 while (hid_report != UX_NULL) 128 { 129 130 /* Get the next report before we clean the current report. */ 131 hid_next_report = hid_report -> ux_host_class_hid_report_next_report; 132 133 /* Get the first field in the report. */ 134 hid_field = hid_report -> ux_host_class_hid_report_field; 135 136 /* Clean all the fields attached. */ 137 while (hid_field != UX_NULL) 138 { 139 140 /* Get the next field before we clean the current field. */ 141 hid_next_field = hid_field -> ux_host_class_hid_field_next_field; 142 143 /* Free the usage table. */ 144 if (hid_field -> ux_host_class_hid_field_usages != UX_NULL) 145 _ux_utility_memory_free(hid_field -> ux_host_class_hid_field_usages); 146 147 /* Free the value table. */ 148 if (hid_field -> ux_host_class_hid_field_values != UX_NULL) 149 _ux_utility_memory_free(hid_field -> ux_host_class_hid_field_values); 150 151 /* Now free the field memory. */ 152 _ux_utility_memory_free(hid_field); 153 154 /* Next field. */ 155 hid_field = hid_next_field; 156 } 157 158 /* Free the report. */ 159 _ux_utility_memory_free(hid_report); 160 161 /* Next report. */ 162 hid_report = hid_next_report; 163 } 164 165 /* Each report list of the parser should be cleaned: Feature report. */ 166 hid_report = hid_parser -> ux_host_class_hid_parser_feature_report; 167 while (hid_report != UX_NULL) 168 { 169 170 /* Get the next report before we clean the current report. */ 171 hid_next_report = hid_report -> ux_host_class_hid_report_next_report; 172 173 /* Get the first field in the report. */ 174 hid_field = hid_report -> ux_host_class_hid_report_field; 175 176 /* Clean all the fields attached. */ 177 while (hid_field != UX_NULL) 178 { 179 180 /* Get the next field before we clean the current field. */ 181 hid_next_field = hid_field -> ux_host_class_hid_field_next_field; 182 183 /* Free the usage table. */ 184 if (hid_field -> ux_host_class_hid_field_usages != UX_NULL) 185 _ux_utility_memory_free(hid_field -> ux_host_class_hid_field_usages); 186 187 /* Free the value table. */ 188 if (hid_field -> ux_host_class_hid_field_values != UX_NULL) 189 _ux_utility_memory_free(hid_field -> ux_host_class_hid_field_values); 190 191 /* Now free the field memory. */ 192 _ux_utility_memory_free(hid_field); 193 194 /* Next field. */ 195 hid_field = hid_next_field; 196 } 197 198 /* Free the report. */ 199 _ux_utility_memory_free(hid_report); 200 201 /* Next report. */ 202 hid_report = hid_next_report; 203 } 204 205 /* Return successful completion. */ 206 return(UX_SUCCESS); 207 } 208 209