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_request_interrupt_transfer PORTABLE C */ 37 /* 6.1 */ 38 /* AUTHOR */ 39 /* */ 40 /* Chaoqiong Xiao, Microsoft Corporation */ 41 /* */ 42 /* DESCRIPTION */ 43 /* */ 44 /* This function performs an interrupt transfer request. An interrupt */ 45 /* transfer can only be as large as the Maxpacket Field in the */ 46 /* endpoint descriptor. This was verified at the USB layer and does */ 47 /* not need to be reverified here. */ 48 /* */ 49 /* INPUT */ 50 /* */ 51 /* hcd_sim_host Pointer to host controller */ 52 /* transfer_request Pointer to transfer request */ 53 /* */ 54 /* OUTPUT */ 55 /* */ 56 /* Completion Status */ 57 /* */ 58 /* CALLS */ 59 /* */ 60 /* _ux_hcd_sim_host_regular_td_obtain Obtain regular TD */ 61 /* */ 62 /* CALLED BY */ 63 /* */ 64 /* Host Simulator Controller Driver */ 65 /* */ 66 /* RELEASE HISTORY */ 67 /* */ 68 /* DATE NAME DESCRIPTION */ 69 /* */ 70 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ 71 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ 72 /* resulting in version 6.1 */ 73 /* */ 74 /**************************************************************************/ _ux_hcd_sim_host_request_interrupt_transfer(UX_HCD_SIM_HOST * hcd_sim_host,UX_TRANSFER * transfer_request)75UINT _ux_hcd_sim_host_request_interrupt_transfer(UX_HCD_SIM_HOST *hcd_sim_host, UX_TRANSFER *transfer_request) 76 { 77 78 UX_ENDPOINT *endpoint; 79 UX_HCD_SIM_HOST_ED *ed; 80 UX_HCD_SIM_HOST_TD *data_td; 81 UX_HCD_SIM_HOST_TD *tail_td; 82 83 84 /* Get the pointer to the Endpoint. */ 85 endpoint = (UX_ENDPOINT *) transfer_request -> ux_transfer_request_endpoint; 86 87 /* Now get the physical ED attached to this endpoint. */ 88 ed = endpoint -> ux_endpoint_ed; 89 90 /* Use the TD pointer by ed -> tail for the first TD of this transfer 91 and chain from this one on. */ 92 data_td = ed -> ux_sim_host_ed_tail_td; 93 94 /* Set the direction of the transfer. */ 95 if ((transfer_request -> ux_transfer_request_type & UX_REQUEST_DIRECTION) == UX_REQUEST_IN) 96 data_td -> ux_sim_host_td_direction = UX_HCD_SIM_HOST_TD_IN; 97 else 98 data_td -> ux_sim_host_td_direction = UX_HCD_SIM_HOST_TD_OUT; 99 100 /* Mark the TD with the DATA phase. */ 101 data_td -> ux_sim_host_td_status |= UX_HCD_SIM_HOST_TD_DATA_PHASE; 102 103 /* The Toggle value is in the ED. */ 104 data_td -> ux_sim_host_td_toggle = UX_HCD_SIM_HOST_TD_TOGGLE_FROM_ED; 105 106 /* Store the beginning of the buffer address in the TD. */ 107 data_td -> ux_sim_host_td_buffer = transfer_request -> ux_transfer_request_data_pointer; 108 109 /* Update the length of the transfer for this TD. */ 110 data_td -> ux_sim_host_td_length = transfer_request -> ux_transfer_request_requested_length; 111 112 /* Attach the endpoint and transfer request to the TD. */ 113 data_td -> ux_sim_host_td_transfer_request = transfer_request; 114 data_td -> ux_sim_host_td_ed = ed; 115 116 /* At this stage, the Head and Tail in the ED are still the same and 117 the host simulator controller will skip this ED until we have hooked the new 118 tail TD. */ 119 tail_td = _ux_hcd_sim_host_regular_td_obtain(hcd_sim_host); 120 if (tail_td == UX_NULL) 121 return(UX_NO_TD_AVAILABLE); 122 123 /* Attach the tail TD to the last data TD. */ 124 data_td -> ux_sim_host_td_next_td = tail_td; 125 126 /* Store the new tail TD. */ 127 ed -> ux_sim_host_ed_tail_td = tail_td; 128 129 /* Now we can tell the scheduler to wake up. */ 130 hcd_sim_host -> ux_hcd_sim_host_queue_empty = UX_FALSE; 131 132 /* There is no need to wake up the sim_host controller on this transfer 133 since periodic transactions will be picked up when the interrupt 134 tree is scanned. */ 135 return(UX_SUCCESS); 136 } 137 138