1 /*************************************************************************** 2 * Copyright (c) 2024 Microsoft Corporation 3 * 4 * This program and the accompanying materials are made available under the 5 * terms of the MIT License which is available at 6 * https://opensource.org/licenses/MIT. 7 * 8 * SPDX-License-Identifier: MIT 9 **************************************************************************/ 10 11 12 /**************************************************************************/ 13 /**************************************************************************/ 14 /** */ 15 /** USBX Component */ 16 /** */ 17 /** Host Simulator Controller Driver */ 18 /** */ 19 /**************************************************************************/ 20 /**************************************************************************/ 21 22 #define UX_SOURCE_CODE 23 24 25 /* Include necessary system files. */ 26 27 #include "ux_api.h" 28 #include "ux_hcd_sim_host.h" 29 30 31 /**************************************************************************/ 32 /* */ 33 /* FUNCTION RELEASE */ 34 /* */ 35 /* _ux_hcd_sim_host_asynchronous_endpoint_create PORTABLE C */ 36 /* 6.1 */ 37 /* AUTHOR */ 38 /* */ 39 /* Chaoqiong Xiao, Microsoft Corporation */ 40 /* */ 41 /* DESCRIPTION */ 42 /* */ 43 /* This function will create an asynchronous endpoint. The control */ 44 /* and bulk endpoints fall into this category. */ 45 /* */ 46 /* INPUT */ 47 /* */ 48 /* hcd_sim_host Pointer to host controller */ 49 /* endpoint Pointer to endpoint */ 50 /* */ 51 /* OUTPUT */ 52 /* */ 53 /* Completion Status */ 54 /* */ 55 /* CALLS */ 56 /* */ 57 /* _ux_hcd_sim_host_ed_obtain Obtain host ED */ 58 /* _ux_hcd_sim_host_regular_td_obtain Obtain host regular TD */ 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_create(UX_HCD_SIM_HOST * hcd_sim_host,UX_ENDPOINT * endpoint)73UINT _ux_hcd_sim_host_asynchronous_endpoint_create(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 *head_ed; 78 UX_HCD_SIM_HOST_TD *td; 79 80 81 /* We need to take into account the nature of the HCD to define the max size 82 of any transfer in the transfer request. */ 83 endpoint -> ux_endpoint_transfer_request.ux_transfer_request_maximum_length = UX_HCD_SIM_HOST_MAX_PAYLOAD; 84 85 /* Obtain a ED for this new endpoint. This ED will live as long as the endpoint is active 86 and will be the container for the TDs. */ 87 ed = _ux_hcd_sim_host_ed_obtain(hcd_sim_host); 88 if (ed == UX_NULL) 89 return(UX_NO_ED_AVAILABLE); 90 91 /* Obtain a dummy TD for terminating the ED transfer chain. */ 92 td = _ux_hcd_sim_host_regular_td_obtain(hcd_sim_host); 93 if (td == UX_NULL) 94 { 95 96 ed -> ux_sim_host_ed_status = UX_UNUSED; 97 return(UX_NO_TD_AVAILABLE); 98 } 99 100 /* Attach the ED to the endpoint container. */ 101 endpoint -> ux_endpoint_ed = (VOID *) ed; 102 103 /* Now do the opposite, attach the ED container to the physical ED. */ 104 ed -> ux_sim_host_ed_endpoint = endpoint; 105 106 /* Hook the TD to both the tail and head of the ED. */ 107 ed -> ux_sim_host_ed_tail_td = td; 108 ed -> ux_sim_host_ed_head_td = td; 109 110 /* Attach this ED to the asynch list. */ 111 head_ed = hcd_sim_host -> ux_hcd_sim_host_asynch_head_ed; 112 ed -> ux_sim_host_ed_next_ed = head_ed; 113 hcd_sim_host -> ux_hcd_sim_host_asynch_head_ed = ed; 114 115 /* Build the back chaining pointer. The previous head ED needs to know about the 116 inserted ED. */ 117 if (head_ed != UX_NULL) 118 head_ed -> ux_sim_host_ed_previous_ed = ed; 119 120 /* Return successful completion. */ 121 return(UX_SUCCESS); 122 } 123 124