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_asynchronous_endpoint_destroy PORTABLE C */ 37 /* 6.1 */ 38 /* AUTHOR */ 39 /* */ 40 /* Chaoqiong Xiao, Microsoft Corporation */ 41 /* */ 42 /* DESCRIPTION */ 43 /* */ 44 /* This function will destroy an asynchronous endpoint. The control */ 45 /* and bulk endpoints fall into this category. */ 46 /* */ 47 /* INPUT */ 48 /* */ 49 /* hcd_sim_host Pointer to host controller */ 50 /* endpoint Pointer to endpoint */ 51 /* */ 52 /* OUTPUT */ 53 /* */ 54 /* Completion Status */ 55 /* */ 56 /* CALLS */ 57 /* */ 58 /* None */ 59 /* */ 60 /* CALLED BY */ 61 /* */ 62 /* Host Simulator Controller Driver */ 63 /* */ 64 /* RELEASE HISTORY */ 65 /* */ 66 /* DATE NAME DESCRIPTION */ 67 /* */ 68 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ 69 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ 70 /* resulting in version 6.1 */ 71 /* */ 72 /**************************************************************************/ _ux_hcd_sim_host_asynchronous_endpoint_destroy(UX_HCD_SIM_HOST * hcd_sim_host,UX_ENDPOINT * endpoint)73UINT _ux_hcd_sim_host_asynchronous_endpoint_destroy(UX_HCD_SIM_HOST *hcd_sim_host, UX_ENDPOINT *endpoint) 74 { 75 76 UX_HCD_SIM_HOST_ED *ed; 77 UX_HCD_SIM_HOST_ED *previous_ed; 78 UX_HCD_SIM_HOST_ED *next_ed; 79 UX_HCD_SIM_HOST_TD *td; 80 81 82 /* From the endpoint container fetch the host simulator ED descriptor. */ 83 ed = (UX_HCD_SIM_HOST_ED *) endpoint -> ux_endpoint_ed; 84 85 /* Get the previous ED in the list for this ED. */ 86 previous_ed = ed -> ux_sim_host_ed_previous_ed; 87 88 /* Get the next ED in the list for this ED. */ 89 next_ed = ed -> ux_sim_host_ed_next_ed; 90 91 /* If the previous ED is NULL, we are at trying to remove the head ED. */ 92 if (previous_ed == UX_NULL) 93 94 /* Store the new endpoint in the control list. */ 95 hcd_sim_host -> ux_hcd_sim_host_asynch_head_ed = next_ed; 96 else 97 98 /* The previous ED points now to the ED after the ED we are removing. */ 99 previous_ed -> ux_sim_host_ed_next_ed = next_ed; 100 101 /* Update the previous ED pointer in the next ED if exists. */ 102 if (next_ed != UX_NULL) 103 next_ed -> ux_sim_host_ed_previous_ed = previous_ed; 104 105 /* Determine if we need to adjust the current ED. */ 106 if (hcd_sim_host -> ux_hcd_sim_host_asynch_current_ed == ed) 107 { 108 109 /* Move the current to the next. */ 110 hcd_sim_host -> ux_hcd_sim_host_asynch_current_ed = next_ed; 111 } 112 113 /* We need to free the dummy TD that was attached to the ED. */ 114 td = ed -> ux_sim_host_ed_tail_td; 115 td -> ux_sim_host_td_status = UX_UNUSED; 116 117 /* Now we can safely make the ED free. */ 118 ed -> ux_sim_host_ed_status = UX_UNUSED; 119 120 /* Return successful completion. */ 121 return(UX_SUCCESS); 122 } 123 124