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 Simulator Controller Driver */ 19 /** */ 20 /**************************************************************************/ 21 /**************************************************************************/ 22 23 #define UX_SOURCE_CODE 24 25 26 /* Include necessary system files. */ 27 28 #include "ux_api.h" 29 #include "ux_hcd_sim_host.h" 30 31 32 /**************************************************************************/ 33 /* */ 34 /* FUNCTION RELEASE */ 35 /* */ 36 /* _ux_hcd_sim_host_uninitialize PORTABLE C */ 37 /* 6.1.10 */ 38 /* AUTHOR */ 39 /* */ 40 /* Chaoqiong Xiao, Microsoft Corporation */ 41 /* */ 42 /* DESCRIPTION */ 43 /* */ 44 /* This function will uninitialize the simulated host controller. */ 45 /* The controller will release all its resources (memory, IO ...). */ 46 /* After this, the controller will not send SOF any longer. */ 47 /* */ 48 /* INPUT */ 49 /* */ 50 /* hcd_sim_host Pointer to host controller */ 51 /* */ 52 /* OUTPUT */ 53 /* */ 54 /* Completion Status */ 55 /* */ 56 /* CALLS */ 57 /* */ 58 /* _ux_utility_memory_free Free memory block */ 59 /* _ux_utility_timer_delete Delete timer */ 60 /* */ 61 /* CALLED BY */ 62 /* */ 63 /* Host Simulator Controller Driver */ 64 /* */ 65 /* RELEASE HISTORY */ 66 /* */ 67 /* DATE NAME DESCRIPTION */ 68 /* */ 69 /* 11-09-2020 Chaoqiong Xiao Initial Version 6.1.2 */ 70 /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */ 71 /* added standalone support, */ 72 /* resulting in version 6.1.10 */ 73 /* */ 74 /**************************************************************************/ _ux_hcd_sim_host_uninitialize(UX_HCD_SIM_HOST * hcd_sim_host)75UINT _ux_hcd_sim_host_uninitialize(UX_HCD_SIM_HOST *hcd_sim_host) 76 { 77 78 UX_HCD *hcd = hcd_sim_host -> ux_hcd_sim_host_hcd_owner; 79 #if defined(UX_HOST_STANDALONE) 80 UX_HCD_SIM_HOST_TD *td; 81 UINT td_index; 82 #endif 83 84 /* Set the state of the controller to HALTED first. */ 85 hcd -> ux_hcd_status = UX_HCD_STATUS_HALTED; 86 87 /* Get simulated host controller. */ 88 hcd_sim_host = (UX_HCD_SIM_HOST *)hcd -> ux_hcd_controller_hardware; 89 90 /* Delete timer. */ 91 _ux_host_timer_delete(&hcd_sim_host -> ux_hcd_sim_host_timer); 92 93 #if defined(UX_HOST_STANDALONE) 94 95 /* Check if there is pending SETUP TD, free buffers of them. */ 96 for (td_index = 0; td_index < _ux_system_host -> ux_system_host_max_td; td_index++) 97 { 98 td = &hcd_sim_host -> ux_hcd_sim_host_td_list[td_index]; 99 100 /* Skip free TDs. */ 101 if (td -> ux_sim_host_td_status == UX_UNUSED) 102 continue; 103 104 /* Skip TDs not for setup. */ 105 if ((td -> ux_sim_host_td_status & UX_HCD_SIM_HOST_TD_SETUP_PHASE) == 0) 106 continue; 107 108 /* Skip TDs already freed. */ 109 if (td -> ux_sim_host_td_buffer == UX_NULL) 110 continue; 111 112 /* Free the TD buffer. */ 113 _ux_utility_memory_free(td -> ux_sim_host_td_buffer); 114 } 115 #endif 116 117 /* Free TD/ED memories. */ 118 _ux_utility_memory_free(hcd_sim_host -> ux_hcd_sim_host_iso_td_list); 119 _ux_utility_memory_free(hcd_sim_host -> ux_hcd_sim_host_td_list); 120 _ux_utility_memory_free(hcd_sim_host -> ux_hcd_sim_host_ed_list); 121 122 /* Free simulated host controller memory. */ 123 _ux_utility_memory_free(hcd_sim_host); 124 hcd -> ux_hcd_controller_hardware = UX_NULL; 125 126 /* Set the state of the controller to UNUSED first. */ 127 hcd -> ux_hcd_status = UX_UNUSED; 128 129 /* Return successful completion. */ 130 return(UX_SUCCESS); 131 } 132