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_create PORTABLE C */ 37 /* 6.1 */ 38 /* AUTHOR */ 39 /* */ 40 /* Chaoqiong Xiao, Microsoft Corporation */ 41 /* */ 42 /* DESCRIPTION */ 43 /* */ 44 /* This function will create 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 /* _ux_hcd_sim_host_ed_obtain Obtain host ED */ 59 /* _ux_hcd_sim_host_regular_td_obtain Obtain host regular TD */ 60 /* */ 61 /* CALLED BY */ 62 /* */ 63 /* Host Simulator Controller Driver */ 64 /* */ 65 /* RELEASE HISTORY */ 66 /* */ 67 /* DATE NAME DESCRIPTION */ 68 /* */ 69 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ 70 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ 71 /* resulting in version 6.1 */ 72 /* */ 73 /**************************************************************************/ _ux_hcd_sim_host_asynchronous_endpoint_create(UX_HCD_SIM_HOST * hcd_sim_host,UX_ENDPOINT * endpoint)74UINT _ux_hcd_sim_host_asynchronous_endpoint_create(UX_HCD_SIM_HOST *hcd_sim_host, UX_ENDPOINT *endpoint) 75 { 76 77 UX_HCD_SIM_HOST_ED *ed; 78 UX_HCD_SIM_HOST_ED *head_ed; 79 UX_HCD_SIM_HOST_TD *td; 80 81 82 /* We need to take into account the nature of the HCD to define the max size 83 of any transfer in the transfer request. */ 84 endpoint -> ux_endpoint_transfer_request.ux_transfer_request_maximum_length = UX_HCD_SIM_HOST_MAX_PAYLOAD; 85 86 /* Obtain a ED for this new endpoint. This ED will live as long as the endpoint is active 87 and will be the container for the TDs. */ 88 ed = _ux_hcd_sim_host_ed_obtain(hcd_sim_host); 89 if (ed == UX_NULL) 90 return(UX_NO_ED_AVAILABLE); 91 92 /* Obtain a dummy TD for terminating the ED transfer chain. */ 93 td = _ux_hcd_sim_host_regular_td_obtain(hcd_sim_host); 94 if (td == UX_NULL) 95 { 96 97 ed -> ux_sim_host_ed_status = UX_UNUSED; 98 return(UX_NO_TD_AVAILABLE); 99 } 100 101 /* Attach the ED to the endpoint container. */ 102 endpoint -> ux_endpoint_ed = (VOID *) ed; 103 104 /* Now do the opposite, attach the ED container to the physical ED. */ 105 ed -> ux_sim_host_ed_endpoint = endpoint; 106 107 /* Hook the TD to both the tail and head of the ED. */ 108 ed -> ux_sim_host_ed_tail_td = td; 109 ed -> ux_sim_host_ed_head_td = td; 110 111 /* Attach this ED to the asynch list. */ 112 head_ed = hcd_sim_host -> ux_hcd_sim_host_asynch_head_ed; 113 ed -> ux_sim_host_ed_next_ed = head_ed; 114 hcd_sim_host -> ux_hcd_sim_host_asynch_head_ed = ed; 115 116 /* Build the back chaining pointer. The previous head ED needs to know about the 117 inserted ED. */ 118 if (head_ed != UX_NULL) 119 head_ed -> ux_sim_host_ed_previous_ed = ed; 120 121 /* Return successful completion. */ 122 return(UX_SUCCESS); 123 } 124 125