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 /** EHCI Controller Driver */ 19 /** */ 20 /**************************************************************************/ 21 /**************************************************************************/ 22 23 24 /* Include necessary system files. */ 25 26 #define UX_SOURCE_CODE 27 28 #include "ux_api.h" 29 #include "ux_hcd_ehci.h" 30 #include "ux_host_stack.h" 31 32 33 /**************************************************************************/ 34 /* */ 35 /* FUNCTION RELEASE */ 36 /* */ 37 /* _ux_hcd_ehci_ed_obtain PORTABLE C */ 38 /* 6.1 */ 39 /* AUTHOR */ 40 /* */ 41 /* Chaoqiong Xiao, Microsoft Corporation */ 42 /* */ 43 /* DESCRIPTION */ 44 /* */ 45 /* This function obtains a free ED from the ED list. */ 46 /* */ 47 /* INPUT */ 48 /* */ 49 /* hcd_ehci Pointer to EHCI controller */ 50 /* */ 51 /* OUTPUT */ 52 /* */ 53 /* UX_EHCI_ED * Pointer to ED */ 54 /* */ 55 /* CALLS */ 56 /* */ 57 /* _ux_utility_memory_set Set memory block */ 58 /* */ 59 /* CALLED BY */ 60 /* */ 61 /* EHCI Controller Driver */ 62 /* */ 63 /* RELEASE HISTORY */ 64 /* */ 65 /* DATE NAME DESCRIPTION */ 66 /* */ 67 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ 68 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ 69 /* verified memset and memcpy */ 70 /* cases, */ 71 /* resulting in version 6.1 */ 72 /* */ 73 /**************************************************************************/ _ux_hcd_ehci_ed_obtain(UX_HCD_EHCI * hcd_ehci)74UX_EHCI_ED *_ux_hcd_ehci_ed_obtain(UX_HCD_EHCI *hcd_ehci) 75 { 76 77 UX_EHCI_ED *ed; 78 ULONG ed_index; 79 80 81 /* Start the search from the beginning of the list. */ 82 ed = hcd_ehci -> ux_hcd_ehci_ed_list; 83 for (ed_index = 0; ed_index < _ux_system_host -> ux_system_host_max_ed; ed_index++) 84 { 85 86 /* Check the ED status, a free ED is marked with the UNUSED flag. */ 87 if (ed -> ux_ehci_ed_status == UX_UNUSED) 88 { 89 90 /* The ED may have been used, so we reset all fields. */ 91 _ux_utility_memory_set(ed, 0, sizeof(UX_EHCI_ED)); /* Use case of memset is verified. */ 92 93 /* This ED is now marked as USED. */ 94 ed -> ux_ehci_ed_status = UX_USED; 95 96 /* We initialize the type of ED and mark its TD terminator to be safe. */ 97 ed -> ux_ehci_ed_queue_head = (UX_EHCI_ED *) UX_EHCI_QH_TYP_QH; 98 ed -> ux_ehci_ed_queue_element = (UX_EHCI_TD *) UX_EHCI_TD_T; 99 100 /* Success, return ED pointer. */ 101 return(ed); 102 } 103 104 /* Point to the next ED. */ 105 ed++; 106 } 107 108 /* There is no available ED in the ED list. */ 109 return(UX_NULL); 110 } 111 112